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
898_A. Rounding_18462
Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded. For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 or to 10. Both ways are correct. For given n find out to which integer will Vasy...
n=int(input()) if(n%10==0): print(n) elif(n%10>5): print(n+(10-(n%10))) else: print(n-(n%10))
{ "input": [ "5\n", "5432359\n", "1000000000\n", "113\n", "234234\n", "3\n", "0\n", "999\n", "307910310\n", "9\n", "4\n", "46\n", "100000\n", "48851642\n", "3245526\n", "1397\n", "23451218\n", "1923140\n", "150272868\n", "1000010\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded. For example, if n ...
919_B. Perfect Number_18466
We consider a positive integer perfect, if and only if the sum of its digits is exactly 10. Given a positive integer k, your task is to find the k-th smallest perfect positive integer. Input A single line with a positive integer k (1 ≤ k ≤ 10 000). Output A single number, denoting the k-th smallest perfect integer....
rpta = [] def solve(pos, sum, arr): # if len(rpta) > 30: # return # # print(sum) if sum > 10 or pos >= 9: return else: if sum == 10: # print(sum, arr) rpta.append(arr) inicio = 0 if pos > 0 else 1 for i in range(inicio, min(10,10-sum+1) )...
{ "input": [ "1\n", "2\n", "6259\n", "5987\n", "99\n", "1234\n", "15\n", "51\n", "13\n", "9411\n", "7\n", "2387\n", "7777\n", "3567\n", "5539\n", "8888\n", "4\n", "101\n", "6666\n", "3\n", "9999\n", "666\n", "5689\n", "233...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We consider a positive integer perfect, if and only if the sum of its digits is exactly 10. Given a positive integer k, your task is to find the k-th smallest perfect positive integer...
946_A. Partition_18470
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences. Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, the...
n = int(input()) a = list(map(int, input().split())) res = 0 for i in range(n): if a[i] > 0: res += a[i] else: res -= a[i] print(res)
{ "input": [ "3\n1 -2 0\n", "6\n16 23 16 15 42 8\n", "2\n-2 1\n", "76\n57 -38 -48 -81 93 -32 96 55 -44 2 38 -46 42 64 71 -73 95 31 -39 -62 -1 75 -17 57 28 52 12 -11 82 -84 59 -86 73 -97 34 97 -57 -85 -6 39 -5 -54 95 24 -44 35 -18 9 91 7 -22 -61 -80 54 -40 74 -90 15 -97 66 -52 -49 -24 65 21 -93 -29 -24...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequen...
96_D. Volleyball_18473
Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has n junctions, some of which are connected by two-way roads. The length of each road is defined by some positive integer number of meters; the roads can...
import os import sys from io import BytesIO, IOBase # region fastio 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.wr...
{ "input": [ "4 4\n1 3\n1 2 3\n1 4 1\n2 4 1\n2 3 5\n2 7\n7 2\n1 2\n7 7\n", "5 7\n1 3\n1 2 1\n1 3 3\n1 5 1\n1 4 2\n5 4 3\n3 5 2\n2 3 8\n2 7\n10 3\n4 7\n2 1\n1 1\n", "3 2\n3 3\n1 2 2\n1 3 3\n2 7\n2 7\n3 7\n", "7 15\n5 5\n3 4 6\n7 4 3\n7 2 8\n2 5 2\n7 2 8\n5 2 9\n3 1 7\n1 2 4\n7 1 8\n7 5 7\n2 4 2\n4 3 9\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has n junctions, ...
994_D. Open Communication_18477
Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set ...
n, m = map(int, input().split()) p1 = list(map(int, input().split())) p2 = list(map(int, input().split())) cand = set() cc = [set() for i in range(n)] dd = [set() for i in range(m)] for i in range(n): for j in range(m): a, b = p1[2 * i], p1[2 * i + 1] c, d = p2[2 * j], p2[2 * j + 1] if a not...
{ "input": [ "2 2\n1 2 3 4\n1 5 3 4\n", "2 2\n1 2 3 4\n1 5 6 4\n", "2 3\n1 2 4 5\n1 2 1 3 2 3\n", "4 3\n1 2 4 5 6 7 8 9\n1 2 8 9 3 1\n", "4 12\n2 8 3 1 2 1 9 4\n9 5 5 3 1 6 3 7 7 1 8 5 6 5 4 6 1 9 1 4 2 5 9 8\n", "12 12\n1 6 2 6 8 3 6 4 4 8 7 2 7 5 9 4 2 4 9 5 8 5 3 6\n2 8 6 9 2 6 7 4 6 5 6 3 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matc...
p02636 AtCoder Grand Contest 046 - Secret Passage_18490
Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S zero or more times: * Remove the two characters at the beginning of S, erase one of them, and reinsert the other somewhere in S. This operation can be applied only whe...
def cmb(n, r, mod):#コンビネーションの高速計算  if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 998244353 N = 2*10**3 g1 = [1]*(N+1) # 元テーブル g2 = [1]*(N+1) #逆元テーブル inverse = [1]*(N+1) #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1[i]=( ( g1[i-1] * i ) % mod ) inver...
{ "input": [ "110001", "11101111011111000000000110000001111100011111000000001111111110000000111111111", "0001", "110011", "11101111011111000000000110000001111100011111000000001101111110000000111111111", "0000", "110010", "1110111101110100000000011000000111110001111100000000110111111000...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S zero or more times: * Remove t...
p02767 AtCoder Beginner Contest 156 - Rally_18494
There are N people living on a number line. The i-th person lives at coordinate X_i. You are going to hold a meeting that all N people have to attend. The meeting can be held at any integer coordinate. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to atte...
n=int(input()) x=tuple(map(int,input().split())) s=sum(x) ave=s//n+(1 if s/n>s//n+0.5 else 0) print(sum([pow(ave-i,2) for i in x]))
{ "input": [ "7\n14 14 2 13 56 2 37", "2\n1 4", "7\n14 14 3 13 56 2 37", "2\n0 4", "7\n14 14 3 13 56 2 0", "2\n0 1", "7\n14 14 3 12 56 2 0", "7\n19 14 3 12 56 2 0", "7\n19 14 3 24 56 2 0", "7\n11 14 3 24 56 2 0", "7\n11 14 3 24 56 1 0", "7\n11 14 3 33 56 1 0", "7\n1...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N people living on a number line. The i-th person lives at coordinate X_i. You are going to hold a meeting that all N people have to attend. The meeting can be held at an...
p02902 AtCoder Beginner Contest 142 - Pure_18498
Given is a directed graph G with N vertices and M edges. The vertices are numbered 1 to N, and the i-th edge is directed from Vertex A_i to Vertex B_i. It is guaranteed that the graph contains no self-loops or multiple edges. Determine whether there exists an induced subgraph (see Notes) of G such that the in-degree a...
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): n,m=map(int,input().split()) E=[[] for _ in range(n)] for _ in range(m): a,b=map(lambda x:int(x)-1,input().split()) E[a].append(b) # bfs def bfs(sv): ...
{ "input": [ "6 9\n1 2\n2 3\n3 4\n4 5\n5 6\n5 1\n5 2\n6 1\n6 2", "4 5\n1 2\n2 3\n2 4\n4 1\n4 3", "4 5\n1 2\n2 3\n2 4\n1 4\n4 3", "4 5\n1 2\n2 3\n2 4\n4 1\n8 3", "6 0\n1 2\n1 2\n4 4\n7 3\n0 0\n9 2\n5 2\n6 1\n6 2", "6 9\n1 2\n2 3\n3 4\n6 5\n5 6\n5 1\n5 2\n6 1\n6 2", "6 9\n1 2\n2 3\n4 4\n6 5\...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Given is a directed graph G with N vertices and M edges. The vertices are numbered 1 to N, and the i-th edge is directed from Vertex A_i to Vertex B_i. It is guaranteed that the graph...
p03037 AtCoder Beginner Contest 127 - Prison_18502
We have N ID cards, and there are M gates. We can pass the i-th gate if we have one of the following ID cards: the L_i-th, (L_i+1)-th, ..., and R_i-th ID cards. How many of the ID cards allow us to pass all the gates alone? Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq M \leq 10^5 * ...
N, M = map(int, input().split()) l, r = 1, N for m in range(M): L, R = map(int, input().split()) l = max(l,L) r = min(r,R) print(max(0,r-l+1))
{ "input": [ "100000 1\n1 100000", "4 2\n1 3\n2 4", "10 3\n3 6\n5 7\n6 9", "101000 1\n1 100000", "4 2\n1 6\n2 4", "10 3\n3 6\n7 7\n6 9", "101000 1\n1 100100", "101000 1\n1 100110", "101000 1\n1 100010", "101100 1\n2 100110", "8 3\n1 7\n7 7\n1 11", "8 1\n1 7\n7 7\n2 11",...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We have N ID cards, and there are M gates. We can pass the i-th gate if we have one of the following ID cards: the L_i-th, (L_i+1)-th, ..., and R_i-th ID cards. How many of the ID c...
p03178 Educational DP Contest - Digit Sum_18506
Find the number of integers between 1 and K (inclusive) satisfying the following condition, modulo 10^9 + 7: * The sum of the digits in base ten is a multiple of D. Constraints * All values in input are integers. * 1 \leq K < 10^{10000} * 1 \leq D \leq 100 Input Input is given from Standard Input in the following ...
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a...
{ "input": [ "98765432109876543210\n58", "30\n4", "1000000009\n1", "98765432109876543210\n66", "30\n1", "1000000009\n2", "98765432109876543210\n18", "1000000009\n4", "98765432109876543210\n11", "1000000009\n5", "98765432109876543210\n12", "1000000009\n9", "987654321...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Find the number of integers between 1 and K (inclusive) satisfying the following condition, modulo 10^9 + 7: * The sum of the digits in base ten is a multiple of D. Constraints * A...
p03326 AtCoder Beginner Contest 100 - Patisserie ABC_18510
Takahashi became a pastry chef and opened a shop La Confiserie d'ABC to celebrate AtCoder Beginner Contest 100. The shop sells N kinds of cakes. Each kind of cake has three parameters "beauty", "tastiness" and "popularity". The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the popularity of z_i. Th...
N, M = map(int, input().split()) List = [list(map(int, input().split())) for _ in range(N)] from itertools import product ans = 0 for a, b, c in product([1, -1], repeat=3): tmp = [] for x, y, z in List: tmp.append(a*x+b*y+c*z) tmp.sort(reverse=True) ans = max(ans, sum(tmp[:M])) print(ans)
{ "input": [ "5 3\n1 -2 3\n-4 5 -6\n7 -8 -9\n-10 11 -12\n13 -14 15", "10 5\n10 -80 21\n23 8 38\n-94 28 11\n-26 -2 18\n-69 72 79\n-26 -86 -54\n-72 -50 59\n21 65 -32\n40 -94 87\n-62 18 82", "5 3\n3 1 4\n1 5 9\n2 6 5\n3 5 8\n9 7 9", "3 2\n2000000000 -9000000000 4000000000\n7000000000 -5000000000 30000000...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Takahashi became a pastry chef and opened a shop La Confiserie d'ABC to celebrate AtCoder Beginner Contest 100. The shop sells N kinds of cakes. Each kind of cake has three parameter...
p03480 AtCoder Beginner Contest 083 - Wide Flip_18514
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times. * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfi...
s = input() tmp = [] for i in range(len(s)-1): if s[i] != s[i+1]: tmp.append(max(i+1,len(s)-(i+1))) if len(tmp) == 0: #元から全部同じ print(len(s)) else: print(min(tmp))
{ "input": [ "100000000", "010", "00001111", "100000010", "011", "00001101", "111", "00011101", "100000101", "11111111", "000000000", "100000011", "100001011", "101", "10011101", "100101011", "001", "00011001", "100001111", "000", "10...
5ATCODER
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 of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following o...
p03647 AtCoder Regular Contest 079 - Cat Snuke and a Voyage_18518
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuk...
n,m = input().split() n = int(n) m = int(m) l = [[] for i in range(n)] for i in range(m): a,b = input().split() a = int(a) b = int(b) l[a-1].append(b-1) l[b-1].append(a-1) f = False for i in l[0]: for j in l[i]: if j == n-1: f = True break if f: print("POSSIB...
{ "input": [ "5 5\n1 3\n4 5\n2 3\n2 4\n1 4", "100000 1\n1 99999", "4 3\n1 2\n2 3\n3 4", "3 2\n1 2\n2 3", "5 5\n1 1\n4 5\n2 3\n2 4\n1 4", "100000 1\n0 99999", "4 3\n1 3\n2 3\n3 4", "5 5\n1 1\n4 5\n1 3\n2 4\n1 4", "100100 1\n0 99999", "4 3\n1 3\n3 3\n3 4", "5 5\n2 3\n4 5\n2 3...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regul...
p03803 AtCoder Beginner Contest 054 - One Card Poker_18522
Alice and Bob are playing One Card Poker. One Card Poker is a two-player game using playing cards. Each card in this game shows an integer between `1` and `13`, inclusive. The strength of a card is determined by the number written on it, as follows: Weak `2` < `3` < `4` < `5` < `6` < `7` < `8` < `9` < `10` < `11` < `...
a,b=map(int,input().split()) a=(a-2)%13 b=(b-2)%13 if a<b:print('Bob') elif a>b:print('Alice') else:print('Draw')
{ "input": [ "8 6", "1 1", "13 1", "8 7", "2 1", "0 0", "8 3", "3 1", "7 3", "4 1", "7 1", "7 2", "5 6", "1 0", "0 1", "12 3", "1 3", "10 1", "7 4", "5 10", "1 5", "13 4", "1 10", "1 8", "9 4", "1 9", "9 3", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Alice and Bob are playing One Card Poker. One Card Poker is a two-player game using playing cards. Each card in this game shows an integer between `1` and `13`, inclusive. The streng...
p03971 CODE FESTIVAL 2016 qual B - Qualification simulator_18526
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from t...
N,A,B = map(int,input().split()) S = input() countA = 0 countB = 0 for i in range(len(S)): if S[i] == 'a' and countA + countB < A + B: countA += 1 print('Yes') elif S[i] == 'b' and countA + countB < A + B and countB < B: countB += 1 print('Yes') else: print('No')
{ "input": [ "12 5 2\ncabbabaacaba", "5 2 2\nccccc", "10 2 3\nabccabaabb", "12 5 0\ncabbabaacaba", "12 5 1\ncacbabaacaba", "12 5 1\ncaababaccaba", "12 7 1\ncaababaccaba", "12 7 2\ncaababaccaba", "12 14 0\ncaababaccaba", "12 6 2\ncabbabaacaba", "10 2 0\nabccabaabb", "12 ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese s...
p00060 Card Game_18530
There is one card each with the numbers from "1" to "10", for a total of 10 cards. This card has numbers on the front and nothing on the back. Using this card, you and your opponent will play the game according to the following rules. 1. You and your opponent are dealt a total of two cards, one face up and one back up...
while 1: a=[i+1 for i in range(10)] try:b=list(map(int,input().split())) except:break for i in b:a.remove(i) print('YES' if sum([1 for i in a if i<=20-sum(b[:2])])/7>=0.5 else 'NO')
{ "input": [ "1 2 3\n5 6 9\n8 9 10", "1 2 3\n5 6 8\n8 9 10", "1 2 3\n5 2 9\n8 1 10", "1 2 3\n5 2 9\n8 9 10", "1 2 3\n5 2 8\n8 1 10", "1 2 3\n5 2 8\n5 1 10", "1 4 3\n5 2 9\n8 9 10", "1 2 3\n5 2 9\n8 2 10", "1 2 3\n5 2 8\n8 1 5", "1 2 3\n5 1 8\n5 1 10", "1 4 3\n5 1 9\n8 9 10"...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is one card each with the numbers from "1" to "10", for a total of 10 cards. This card has numbers on the front and nothing on the back. Using this card, you and your opponent w...
p00191 Baby Tree_18534
Dr. Sato, a botanist, invented a number of special fertilizers for seedlings. When you give the fertilizer to the seedlings, the size of the seedlings changes in a blink of an eye. However, it was found that fertilizer has the following side effects. * The size of the seedlings does not change with the fertilizer give...
# AOJ 0191: Baby Tree # Python3 2018.6.20 bal4u while True: n, m = list(map(int, input().split())) if n == 0: break d = [[0.0 for j in range(n)] for i in range(n)] for i in range(n): d[i] = list(map(float, input().split())) dp = [[0.0 for j in range(n)] for k in range(m)] for i in range(n): dp[0][i] = 1 for k...
{ "input": [ "3 3\n1.3 3.0 0.5\n2.4 2.1 1.0\n3.0 0.8 1.2\n2 2\n1.0 1.0\n1.0 1.0\n0 0", "3 3\n1.3 3.0 0.5\n2.4 2.1 1.0\n3.0 0.8 1.2\n2 2\n1.0 1.953209014063742\n1.0 1.0\n0 0", "3 3\n1.3 3.0 0.5\n2.9487871182122434 2.1 1.0\n3.0 0.8 1.2\n2 2\n1.0 1.0\n1.0 1.0\n0 0", "3 3\n1.3 3.0 0.5\n2.9487871182122434 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Dr. Sato, a botanist, invented a number of special fertilizers for seedlings. When you give the fertilizer to the seedlings, the size of the seedlings changes in a blink of an eye. Ho...
p00346 Quiet Town_18537
Ekiden competitions are held every year in Aizukuni. The country of Aiz is dotted with N towns, each numbered from 1 to N. Several towns are connected by roads that allow them to come and go directly to each other. You can also follow several roads between any town. The course of the tournament is decided as follows. ...
from heapq import heappush, heappop from collections import deque n, r = map(int, input().split()) G = [[] for i in range(n)] for i in range(r): s, t, d = map(int, input().split()) G[s-1].append((t-1, d)) G[t-1].append((s-1, d)) INF = 10**18 def dijkstra(s): dist = [INF]*n dist[s] = 0 que = [(0...
{ "input": [ "7 11\n1 2 2\n1 3 1\n2 4 2\n2 5 2\n2 6 1\n3 4 1\n3 5 1\n3 6 1\n4 7 2\n5 7 2\n6 7 1", "4 5\n1 2 2\n1 3 2\n2 3 1\n2 4 2\n3 4 1", "7 11\n1 2 2\n1 3 1\n2 4 2\n2 5 2\n2 6 1\n6 4 1\n3 5 1\n3 6 1\n4 7 2\n5 7 2\n6 7 1", "7 11\n2 2 2\n1 3 1\n2 4 2\n2 5 2\n2 6 1\n6 4 1\n3 5 1\n3 6 1\n4 7 2\n5 7 2\n...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ekiden competitions are held every year in Aizukuni. The country of Aiz is dotted with N towns, each numbered from 1 to N. Several towns are connected by roads that allow them to come...
p00542 Selecting Subjects_18540
problem JOI took six subjects: physics, chemistry, biology, earth science, history, and geography. Each test was scored on a 100-point scale. JOI chooses 3 subjects from 4 subjects of physics, chemistry, biology, and earth science, and 1 subject from 2 subjects of history and geography. When choosing a subject so th...
lst=[] for i in range(6): n=int(input()) lst.append(n) lst1=lst[0:4] lst2=lst[4:6] lst1.sort(reverse=True) lst3=lst1[0:3] a=sum(lst3) b=max(lst2) print(a+b)
{ "input": [ "100\n34\n76\n42\n10\n0", "100\n34\n76\n67\n10\n0", "100\n34\n76\n96\n10\n0", "100\n34\n93\n96\n10\n0", "100\n34\n41\n96\n10\n0", "100\n4\n41\n96\n17\n0", "100\n4\n41\n96\n1\n0", "100\n4\n68\n96\n1\n0", "100\n4\n68\n73\n1\n-1", "100\n4\n66\n73\n1\n-1", "100\n4\...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: problem JOI took six subjects: physics, chemistry, biology, earth science, history, and geography. Each test was scored on a 100-point scale. JOI chooses 3 subjects from 4 subjects ...
p00706 Get Many Persimmon Trees_18544
Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Ai...
def main(): while True: N = int(input()) if N==0: exit() (W, H) = [int(x) for x in input().split()] persimmon = [[0 for j in range(100)] for i in range(100)] for _ in range(N): (x, y) = [int(x) for x in input().split()] persimmon[x][y] = 1...
{ "input": [ "16\n10 8\n2 2\n2 5\n2 7\n3 3\n3 8\n4 2\n4 5\n4 8\n6 4\n6 7\n7 5\n7 8\n8 1\n8 4\n9 6\n10 3\n4 3\n8\n6 4\n1 2\n2 1\n2 4\n3 4\n4 2\n5 3\n6 1\n6 2\n3 2\n0", "16\n10 8\n2 2\n2 5\n2 7\n3 3\n3 8\n4 2\n4 5\n4 8\n6 4\n6 7\n7 5\n7 8\n8 1\n8 4\n9 6\n10 3\n4 3\n8\n6 4\n1 2\n2 1\n2 4\n3 4\n4 2\n5 3\n6 1\n3 2...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in edu...
p00845 How I Wonder What You Are!_18547
One of the questions children often ask is "How many stars are there in the sky?" Under ideal conditions, even with the naked eye, nearly eight thousands are observable in the northern hemisphere. With a decent telescope, you may find many more, but, as the sight field will be limited, you may find much less at a time....
import math while True: n = int(input()) if not n: break stars = [list(map(float, input().split())) for i in range(n)] is_watch_star = [False for i in range(n)] scope = [list(map(float, input().split())) for j in range(int(input()))] for i in scope: a = (i[0] ** 2 + i[1] ** 2 ...
{ "input": [ "3\n100 0 500\n-500.243 -200.1 -300.5\n0 300 200\n2\n1 1 1 0.65\n-1 0 0 1.57\n3\n1 0 0\n0 1 0\n0 0 1\n4\n1 -1 -1 0.9553\n-1 1 -1 0.9554\n-1 -1 1 0.9553\n-1 1 -1 0.9554\n3\n1 0 0\n0 1 0\n0 0 1\n4\n1 -1 -1 0.9553\n-1 1 -1 0.9553\n-1 -1 1 0.9553\n-1 1 -1 0.9553\n0", "3\n100 0 500\n-500.243 -199.7339...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: One of the questions children often ask is "How many stars are there in the sky?" Under ideal conditions, even with the naked eye, nearly eight thousands are observable in the norther...
p01109 Income Inequality_18551
Income Inequality We often compute the average as the first step in processing statistical data. Yes, the average is a good tendency measure of data, but it is not always the best. In some cases, the average may hinder the understanding of the data. For example, consider the national income of a country. As the term ...
while True: n=int(input()) if n==0: break lst=list(map(int,input().split())) x=sum(lst)/n ans=0 for i in lst: if x>=i: ans+=1 print(ans)
{ "input": [ "7\n15 15 15 15 15 15 15\n4\n10 20 30 60\n10\n1 1 1 1 1 1 1 1 1 100\n7\n90 90 90 90 90 90 10\n7\n2 7 1 8 2 8 4\n0", "7\n15 15 15 15 15 23 15\n4\n10 20 30 60\n10\n1 1 1 1 1 1 1 1 1 100\n7\n90 90 90 90 90 90 10\n7\n2 7 1 8 2 8 4\n0", "7\n15 15 1 15 15 23 15\n4\n10 20 30 60\n10\n1 1 1 1 1 1 1 1 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Income Inequality We often compute the average as the first step in processing statistical data. Yes, the average is a good tendency measure of data, but it is not always the best. I...
p01724 Phutball_18558
Ikta, who hates to lose, has recently been enthusiastic about playing games using the Go board. However, neither Go nor Gomoku can beat my friends at all, so I decided to give a special training to the lesser-known game Phutball. This game is a difficult game, so I decided to give special training so that I could win ...
def main(): N = 20; M = 15 MP = [[-1]*M for i in range(N)] L = 0 for i in range(N-1): s = input() for j in range(M): c = s[j] if c == 'O': sx = j; sy = i elif c == 'X': MP[i][j] = L L += 1 dd = ((-1,...
{ "input": [ "...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n.....XX........\n.....XXXO.....
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ikta, who hates to lose, has recently been enthusiastic about playing games using the Go board. However, neither Go nor Gomoku can beat my friends at all, so I decided to give a speci...
p01997 Right triangle_18562
problem Given the lengths of $ 2 $ sides that are not the hypotenuse of a right triangle, $ A $ and $ B $. The side of length $ A $ overlaps the $ x $ axis, and the side of length $ B $ overlaps the $ y $ axis. Do the following: 1. Rotate the triangle around the $ x $ axis. 2. Rotate the shape created by performing ...
import math a,b=map(int,input().split()) print(b**3*math.pi*(4/3))
{ "input": [ "1 2", "2 2", "1 3", "0 6", "1 10", "1 1", "0 9", "2 5", "0 4", "-1 11", "-1 0", "-1 8", "-1 7", "-1 12", "-2 -1", "-4 -2", "-8 -3", "-11 -4", "-13 -5", "-8 -6", "-23 -12", "-9 -7", "-26 -9", "-74 -8", "2 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: problem Given the lengths of $ 2 $ sides that are not the hypotenuse of a right triangle, $ A $ and $ B $. The side of length $ A $ overlaps the $ x $ axis, and the side of length $ ...
p02284 Binary Search Tree II_18567
Write a program which performs the following operations to a binary search tree $T$ by adding the find operation to A: Binary Search Tree I. * insert $k$: Insert a node containing $k$ as key into $T$. * find $k$: Report whether $T$ has a node containing $k$. * print: Print the keys of the binary search tree by inorde...
class Node(object): root = None def __init__(self, key, parent=None, left=None, right=None): self.key = key self.parent = parent self.left = left self.right = right self.height = None @classmethod def insert(cls, z): y = None x = cls.root ...
{ "input": [ "10\ninsert 30\ninsert 88\ninsert 12\ninsert 1\ninsert 20\nfind 12\ninsert 17\ninsert 25\nfind 16\nprint", "10\ninsert 30\ninsert 88\ninsert 12\ninsert 1\ninsert 29\nfind 12\ninsert 17\ninsert 25\nfind 16\nprint", "10\ninsert 30\ninsert 88\ninsert 12\ninsert 2\ninsert 20\nfind 12\ninsert 17\n...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Write a program which performs the following operations to a binary search tree $T$ by adding the find operation to A: Binary Search Tree I. * insert $k$: Insert a node containing $...
p02431 Vector_18571
For a dynamic array $A = \\{a_0, a_1, ...\\}$ of integers, perform a sequence of the following operations: * pushBack($x$): add element $x$ at the end of $A$ * randomAccess($p$):print element $a_p$ * popBack(): delete the last element of $A$ $A$ is a 0-origin array and it is empty in the initial state. Constraints...
q = int(input()) A = [] ans = [] for i in range(q): q = str(input()) if q[0] == "0": #pushBack A.append(int(q[2:])) elif q[0] == "1": #randamAccess # ans.append(A[int(q[2:])]) print(A[int(q[2:])]) else: #popBack A.pop()
{ "input": [ "8\n0 1\n0 2\n0 3\n2\n0 4\n1 0\n1 1\n1 2", "8\n0 0\n0 2\n0 3\n2\n0 4\n1 0\n1 1\n1 2", "8\n0 0\n0 2\n0 3\n2\n0 4\n1 0\n1 1\n1 1", "8\n0 0\n0 2\n0 3\n2\n1 0\n1 0\n1 1\n1 1", "8\n0 1\n0 2\n0 4\n2\n0 4\n1 0\n1 1\n1 2", "8\n0 0\n0 2\n0 3\n2\n0 4\n1 0\n1 1\n0 2", "8\n0 0\n0 2\n0 3\n...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: For a dynamic array $A = \\{a_0, a_1, ...\\}$ of integers, perform a sequence of the following operations: * pushBack($x$): add element $x$ at the end of $A$ * randomAccess($p$):prin...
1043_B. Lost Array_18583
Bajtek, known for his unusual gifts, recently got an integer array x_0, x_1, …, x_{k-1}. Unfortunately, after a huge array-party with his extraordinary friends, he realized that he'd lost it. After hours spent on searching for a new toy, Bajtek found on the arrays producer's website another array a of length n + 1. As...
arr_len = int(input()) a = [0] + [int(x) for x in input().split(" ")] x = [0] * arr_len res = [] for i in range(1, arr_len + 1): x[i-1] = a[i]-a[i-1] def ok(k, x ,a): for i in range(0, arr_len): tmp = x[i%k] + a[i] if tmp != a[i + 1]: return False return True for k in ...
{ "input": [ "5\n1 2 3 4 5\n", "5\n1 3 5 6 8\n", "3\n1 5 3\n", "4\n5 4 9 11\n", "5\n5 7 12 14 19\n", "10\n2 2 4 4 3 1 1 2 3 2\n", "4\n2 2 4 6\n", "6\n2 1 3 2 4 100\n", "5\n1 2 5 6 7\n", "4\n3 2 5 7\n", "1\n5\n", "9\n1 2 3 4 5 6 7 9 10\n", "10\n1 3 6 6 11 12 14 17 18...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Bajtek, known for his unusual gifts, recently got an integer array x_0, x_1, …, x_{k-1}. Unfortunately, after a huge array-party with his extraordinary friends, he realized that he'd...
1107_E. Vasya and Binary String_18590
Vasya has a string s of length n consisting only of digits 0 and 1. Also he has an array a of length n. Vasya performs the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from the string and glue together the remaining parts (any of them can be empty...
n = int(input()) s = input() ai = [0] + list(map(int,input().split())) ar = [ai[i] for i in range(n+1)] for i in range(1,n): num = 0 for j in range(0,(i+1) // 2 + 1): ar[i] = max(ar[i],ar[j] + ar[i-j]) ar2 = [] num = 1 for i in range(1,n): if s[i] == s[i-1]: num += 1 else: ar2 ...
{ "input": [ "7\n1101001\n3 4 9 100 1 2 3\n", "5\n10101\n3 10 15 15 15\n", "30\n010010010010010010010010010010\n1 1 1000000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "1\n1\n1337\n", "99\n10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya has a string s of length n consisting only of digits 0 and 1. Also he has an array a of length n. Vasya performs the following operation until the string becomes empty: choose...
1155_B. Game with Telephone Numbers_18596
A telephone number is a sequence of exactly 11 digits such that its first digit is 8. Vasya and Petya are playing a game. Initially they have a string s of length n (n is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a character and erase it fro...
n=int(input()) s=input() # for i in range(n-10) : # if s['i']!='8' # if s[:n-10].count('8')%2==0: # print(s[:n-10]) # print("YES") # else: print("NO") c=n-10-(s[:n-10].count('8')) if c<s[:n-10].count('8'): print("YES") else: print("NO")
{ "input": [ "15\n807345619350641\n", "13\n8380011223344\n", "15\n961618782888818\n", "13\n2828222222222\n", "23\n79818882846090973951051\n", "17\n83130469783251338\n", "19\n8881328076293351500\n", "15\n778887777777777\n", "21\n888888888888888888888\n", "15\n200080200228220\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A telephone number is a sequence of exactly 11 digits such that its first digit is 8. Vasya and Petya are playing a game. Initially they have a string s of length n (n is odd) consis...
1177_A. Digits Sequence (Easy Edition)_18600
Let's write all the positive integer numbers one after another from 1 without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the k-th digit of this sequence. Input The first and only lin...
x = ''.join(str(i) for i in range(1, 5000)) k = int(input()) print(x[k-1])
{ "input": [ "21\n", "7\n", "2887\n", "100000000\n", "68888886\n", "2886\n", "68888885\n", "68888892\n", "1000000000000\n", "10\n", "8888888891\n", "197\n", "68888891\n", "2899\n", "200\n", "68888895\n", "68888884\n", "9900\n", "1000000\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Let's write all the positive integer numbers one after another from 1 without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 1234567891011121...
1195_E. OpenStreetMap_18603
Seryozha conducts a course dedicated to building a map of heights of Stepanovo recreation center. He laid a rectangle grid of size n × m cells on a map (rows of grid are numbered from 1 to n from north to south, and columns are numbered from 1 to m from west to east). After that he measured the average height of each c...
def slide_min(tl,ql,val): res=[0]*(tl-ql+1) q=[0]*tl s=0 t=0 for i in range(0,tl): while s<t and val[q[t-1]]>=val[i]: t-=1 q[t]=i t+=1 if (i-ql+1)>=0: res[i-ql+1]=val[q[s]] if q[s]==(i-ql+1): s+=1 return res def slide_min2(tl,ql,val): res=0 q=[0]*tl s=0 t...
{ "input": [ "3 4 2 1\n1 2 3 59\n", "2 1000 1 239\n49877647 333519319 741438898 999999937\n", "2 10 2 6\n270734527 308969128 389524142 999999937\n", "3000 10 2 6\n597162980 777111977 891095879 999999937\n", "2 10 1 6\n792838703 367871277 74193612 999999937\n", "3000 10 1 6\n709202316 281605678...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Seryozha conducts a course dedicated to building a map of heights of Stepanovo recreation center. He laid a rectangle grid of size n × m cells on a map (rows of grid are numbered from...
1213_A. Chips Moving_18607
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates. You can perform each of the two following types of moves any (possibly, zero) number of times on any chip: * Move the chip i by 2 to the left or 2 to the right for free (i.e. replace...
n = int(input()) v = list(map(int, input().split())) a = [] b = [] for x in v: a.append(x) if x & 1 else b.append(x) print(min(len(a), len(b)))
{ "input": [ "5\n2 2 2 3 3\n", "3\n1 2 3\n", "1\n64366\n", "1\n2\n", "7\n2 2 2 2 2 2 2\n", "1\n5\n", "3\n1 2 2\n", "2\n1 1\n", "1\n4306\n", "2\n3 2\n", "8\n2 2 2 2 2 2 1 1\n", "7\n2 2 2 2 2 1 1\n", "5\n2 2 1 1 1\n", "66\n17474 17509 20550 10873 31311 10156 24680...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates. You can perform each of the two following types ...
1236_B. Alice and the List of Presents_18611
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends. There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different ki...
'''Author- Akshit Monga''' from sys import stdin, stdout input = stdin.readline mod=10**9+7 t = 1 for _ in range(t): n,m=map(int,input().split()) print(pow((pow(2,m,mod)-1),n,mod))
{ "input": [ "1 3\n", "2 2\n", "7 6\n", "311 619805019\n", "14 469\n", "294440070 297\n", "428 71\n", "1 1000000000\n", "534571158 222043261\n", "362 1464\n", "922338645 900544285\n", "393454015 42675288\n", "204 697134196\n", "188186551 379116090\n", "958 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Alice got many presents these days. So she decided to pack them into boxes and send them to her friends. There are n kinds of presents. Presents of one kind are identical (i.e. there...
1254_A. Feeding Chicken_18615
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
def distribute(n, person): q, m = divmod(n, person) if m==0: return [q] * person else: return [q]*(person-m)+[q+1]*m import sys input = sys.stdin.readline T = int(input()) CHAR = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" for _ in range(T): R, C, K = map(int, input...
{ "input": [ "4\n3 5 3\n..R..\n...R.\n....R\n6 4 6\nR..R\nR..R\nRRRR\nRRRR\nR..R\nR..R\n5 5 4\nRRR..\nR.R..\nRRR..\nR..R.\nR...R\n2 31 62\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\n", "4\n3 5 3\n..R..\n...R.\n....R\n6 4 6\nR..R\nR..R\nRRRR\nRRRR\nR..R\nR..R\n5 5 4\nRRR..\nR.R..\nRRR..\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle gri...
1277_F. Beautiful Rectangle_18619
You are given n integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the n numbers may not be chosen. A rectangle (rectangular matrix)...
def play(arr): n = len(arr) number2Count = {} for p in arr: number2Count[p] = number2Count.get(p, 0) + 1 count2Numbers = {} maxCnt = 0 for num in number2Count: cnt = number2Count[num] if not cnt in count2Numbers: count2Numbers[cnt] = [] count2Numb...
{ "input": [ "5\n1 1 1 1 1\n", "12\n3 1 4 1 5 9 2 6 5 3 5 8\n", "13\n16 18 5 17 11 12 4 11 3 16 17 2 3\n", "7\n2 1 3 3 2 3 3\n", "12\n3 1 4 1 5 9 2 6 5 3 5 8\n", "11\n19 22 18 22 21 21 19 13 21 21 16\n", "15\n6 7 11 8 13 11 4 20 17 12 9 15 18 13 9\n", "1\n1000000000\n", "5\n1 5 5 4...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given n integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle c...
1321_A. Contest for Robots_18623
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each prob...
n = int(input()) r = list(map(int,input().split())) b = list(map(int,input().split())) f = 0 s = 0 for i in range(n): if r[i] > b[i]: f += 1 elif r[i] < b[i]: s += 1 if f == 0: print(-1) else: print((s + f) // f)
{ "input": [ "5\n1 1 1 0 0\n0 1 1 1 1\n", "4\n1 1 1 1\n1 1 1 1\n", "3\n0 0 0\n0 0 0\n", "9\n1 0 0 0 0 0 0 0 1\n0 1 1 0 1 1 1 1 0\n", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p...
133_E. Logo Turtle_18627
A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward"). You are given a list of commands that will be given to the turtle. You have to change exactly n commands from the lis...
import sys import math INF = -100000000 memo = dict() def func(line, r): if line in memo and r in memo[line]: return memo[line][r] if len(line) == 1: which = line[0] == 'T' if r % 2 == 1: which = not which if which: return [INF, INF, 0, 0] else: ...
{ "input": [ "FT\n1\n", "FFFTFFF\n2\n", "FTFTFTFFFFTFTFTTTTTTFFTTTTFFTFFFTFTFTFFTFTFTFFFTTTFTTFTTTTTFFFFTTT\n12\n", "FTTFTFFTFTTTFTTFTFFTTFFFFFTFFFFTTFTFFFFFFTFFTTTFTTFTTTFFFTFTFTFFFFTFFTFTTTTTTTTFTTTTTTFFTTFTTT\n35\n", "FTTFTTTFTTFFFTFFTTFTFTTTFFFTFTFTFFTTTFFFFFFTFTTFFTFFFFTFTTFFFTFFTTTTTFFTFTTFF...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move...
1382_B. Sequential Nim_18633
There are n piles of stones, where the i-th pile has a_i stones. Two people play a game, where they take alternating turns removing stones. In a move, a player may remove a positive number of stones from the first non-empty pile (the pile with the minimal index, that has at least one stone). The first player who canno...
t=int(input()) for _ in range(t): n=int(input()) a=list(map(lambda x:int(x),input().split())) first_nonforced_index=-1 for i in range(0,len(a)): if a[i]!=1: first_nonforced_index=i break if first_nonforced_index==-1: if len(a)%2==0: print("Second")...
{ "input": [ "7\n3\n2 5 4\n8\n1 1 1 1 1 1 1 1\n6\n1 2 3 4 5 6\n6\n1 1 2 1 2 2\n1\n1000000000\n5\n1 2 2 1 1\n3\n1 1 1\n", "1\n6\n1 1 2 2 1 1\n", "1\n6\n1 2 2 2 1 1\n", "7\n3\n2 5 4\n8\n1 2 1 1 1 1 1 1\n6\n1 2 3 4 5 6\n6\n1 1 2 1 2 2\n1\n1000000000\n5\n1 2 2 1 1\n3\n1 1 1\n", "7\n3\n2 5 5\n8\n1 2 1 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n piles of stones, where the i-th pile has a_i stones. Two people play a game, where they take alternating turns removing stones. In a move, a player may remove a positive ...
1425_A. Arena of Greed_18637
Lately, Mr. Chanek frequently plays the game Arena of Greed. As the name implies, the game's goal is to find the greediest of them all, who will then be crowned king of Compfestnesia. The game is played by two people taking turns, where Mr. Chanek takes the first turn. Initially, there is a treasure chest containing N...
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase def main(): pass # region fastio 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" no...
{ "input": [ "2\n5\n6\n", "2\n6\n6\n", "2\n12\n6\n", "2\n24\n6\n", "2\n45\n6\n", "2\n34\n6\n", "2\n58\n6\n", "2\n48\n6\n", "2\n3\n6\n", "2\n4\n6\n", "2\n1\n6\n", "2\n1\n12\n", "2\n1\n16\n", "2\n1\n10\n", "2\n4\n10\n", "2\n4\n20\n", "2\n2\n20\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Lately, Mr. Chanek frequently plays the game Arena of Greed. As the name implies, the game's goal is to find the greediest of them all, who will then be crowned king of Compfestnesia....
1497_E1. Square-free division (easy version)_18643
This is the easy version of the problem. The only difference is that in this version k = 0. There is an array a_1, a_2, …, a_n of n positive integers. You should divide it into a minimal number of continuous segments, such that in each segment there are no two numbers (on different positions), whose product is a perfe...
import sys input = sys.stdin.readline def is_Prime(i): if i == 2: return True if i % 2 == 0 or i == 1: return False s = int(i ** (1 / 2)) while True: if s == 1: return True if i % s == 0: return False s -= 1 t = int(input()) sq = [pow(2, ...
{ "input": [ "3\n5 0\n18 6 2 4 1\n5 0\n6 8 1 24 8\n1 0\n1\n", "2\n14 0\n1 16 1 81 1 36 1 1024 1 1000000 1 1048576 1 4194304\n14 0\n1 16 1 81 1 36 1 1024 1 1000000 1 1048576 1 4194304\n", "1\n2 0\n1 16\n", "2\n14 0\n1 16 1 81 1 36 1 1024 1 1000000 1 1048576 1 4194304\n14 0\n1 16 1 112 1 36 1 1024 1 100...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This is the easy version of the problem. The only difference is that in this version k = 0. There is an array a_1, a_2, …, a_n of n positive integers. You should divide it into a min...
151_D. Quantity of Strings_18647
Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with length equal to k is a palindrome. How many such strings exist? Your task is to ...
import math def pow(a,b,p): res = 1 while(b > 0): if b%2 == 1: res = (res*a)%p a = (a*a)%p b = int(b/2) return res n,m,k = list(map(int,input().strip().split())) p = 10 ** 9 + 7 if k > n or k == 1: print(pow(m, n, p)) elif k == n: print(pow(m, math.ceil(k/...
{ "input": [ "1 1 1\n", "5 2 4\n", "5 2 5\n", "3 1000 3\n", "239 123 239\n", "5 4 5\n", "1769 849 1000\n", "1230 987 1\n", "2000 2000 1\n", "13 13 13\n", "2000 1000 3\n", "15 1 15\n", "3 5 3\n", "1501 893 1501\n", "3 3 3\n", "7 2 7\n", "5 5 5\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly n,...
1547_D. Co-growing Sequence_18651
A sequence of non-negative integers a_1, a_2, ..., a_n is called growing if for all i from 1 to n - 1 all ones (of binary representation) in a_i are in the places of ones (of binary representation) in a_{i + 1} (in other words, a_i \:\&\: a_{i + 1} = a_i, where \& denotes [bitwise AND](http://tiny.cc/xpy9uz)). If n = 1...
# _ ##################################################################################################################### def minCo_growingSequenceWith(array): sequence, prevValue = [], 0 for value in array: n = prevValue&(prevValue^value) prevValue = value^n sequence.append(n) ret...
{ "input": [ "5\n4\n1 3 7 15\n4\n1 2 4 8\n5\n1 2 3 4 5\n4\n11 13 15 1\n1\n0\n", "5\n4\n1 3 7 15\n4\n1 2 4 5\n5\n1 2 3 4 5\n4\n11 13 15 1\n1\n0\n", "5\n4\n1 3 7 15\n4\n1 2 4 5\n5\n1 2 0 4 5\n4\n11 13 15 1\n1\n0\n", "5\n4\n1 3 7 15\n4\n1 2 4 5\n5\n1 0 0 4 5\n4\n11 13 15 1\n1\n0\n", "5\n4\n1 3 7 15\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A sequence of non-negative integers a_1, a_2, ..., a_n is called growing if for all i from 1 to n - 1 all ones (of binary representation) in a_i are in the places of ones (of binary r...
175_A. Robot Bicorn Attack_18655
Vasya plays Robot Bicorn Attack. The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string s. Vasya decided to...
def f(t, k, s): if k == 1: if t[0] == '0' and len(t) > 1: return -1 d = int(t) if d > 1000000: return -1 return s + d if t[0] == '0': return f(t[1: ], k - 1, s) p = [(t[i: ], int(t[: i])) for i in range(1, len(t) + 2 - k)] return max(f(a, k - 1, s + ...
{ "input": [ "9000\n", "1234\n", "0009\n", "001000000\n", "15533274860535679\n", "428595000000042345353\n", "4073734152\n", "000009000000\n", "000000999\n", "97862382\n", "6061357\n", "010\n", "5000000000\n", "1234567891012131416123222443\n", "1000000011\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya plays Robot Bicorn Attack. The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained point...
195_B. After Training_18659
After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has n balls and m baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to m, correspondingly. The ...
n,m = map(int,input().split()) l = [] if m%2 == 1: l = [(m+1)//2] for i in range((m-1)//2,0,-1): l.append(i) l.append(m-i+1) else: l = [] for i in range(m//2,0,-1): l.append(i) l.append(m-i+1) for i in range(n): print(l[i%len(l)])
{ "input": [ "3 1\n", "4 3\n", "2 1\n", "2 6\n", "45 88\n", "90 544\n", "8 87\n", "1 2\n", "9 2\n", "6 5\n", "5 2\n", "85 60\n", "17 812\n", "165 374\n", "1 100000\n", "10 3\n", "21 57\n", "61 51\n", "4 3\n\nSAMPLE", "37 849\n", "6 35...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has n balls an...
219_B. Special Offer! Super Price 999 Bourles!_18663
Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors. Polycaprus calculated that the optimal celling price for such scissors would be p bourles. However, he...
p, d = input().split() p = int(p); d = int(d) ans = p = p + 1 i = 10 while i <= 1000000000000000000: if p % i <= d: ans = p - p % i i *= 10 print(ans - 1)
{ "input": [ "27191 17\n", "1029 102\n", "393776794010351632 4138311260892\n", "559198116944738707 0\n", "159171676706847083 28512592184962\n", "199 198\n", "20 1\n", "621306590487786841 47851896849379\n", "925835698451819219 232827103605000\n", "559198116944738707 8\n", "2...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start pro...
242_D. Dispute_18667
Valera has n counters numbered from 1 to n. Some of them are connected by wires, and each of the counters has a special button. Initially, all the counters contain number 0. When you press a button on a certain counter, the value it has increases by one. Also, the values recorded in all the counters, directly connecte...
from queue import Queue n,m = map(int,input().split()) e = [[]for i in range(n+1)] b = [0]*n for i in range(m): u,v = map(int,input().split()) e[u-1].append(v-1) e[v-1].append(u-1) ans = 0 q = Queue() a = input().split() ai = [-1]*n c=0 mask = [False]*n for i in a: inti = int(i) ai[c] = inti if ...
{ "input": [ "4 2\n1 2\n3 4\n0 0 0 0\n", "5 5\n2 3\n4 1\n1 5\n5 3\n2 1\n1 1 2 0 2\n", "7 10\n5 4\n1 4\n7 4\n1 2\n6 2\n7 3\n7 2\n5 7\n6 1\n5 1\n3 3 0 3 4 1 4\n", "10 4\n8 7\n1 5\n7 4\n8 9\n0 1 0 1 0 0 3 1 2 1\n", "2 1\n1 2\n0 1\n", "3 3\n2 3\n1 3\n1 2\n1 1 3\n", "20 11\n12 5\n16 8\n2 9\n4 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Valera has n counters numbered from 1 to n. Some of them are connected by wires, and each of the counters has a special button. Initially, all the counters contain number 0. When you...
268_B. Buttons_18671
Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequenc...
#mahade.......... n=int(input()) print((n**3+5*n)//6)
{ "input": [ "2\n", "3\n", "1241\n", "1500\n", "1747\n", "4\n", "17\n", "2000\n", "889\n", "1837\n", "1\n", "91\n", "1999\n", "996\n", "256\n", "92\n", "666\n", "50\n", "1000\n", "914\n", "512\n", "10\n", "667\n", "314\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some bu...
290_E. HQ_18675
The famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its subset — a language called HQ... Input The only line of the input is a string between 1 and 106 characters long. Output Output "Yes" or "No". Examples Input HHHH Output Yes Input HQHQH Output No Input H...
import sys s = input() qc = s.count('Q') qs = int(qc ** 0.5) hc = s.count('H') if qs == 0: print('Yes') sys.exit(0) if not qc == qs ** 2: print('No') sys.exit(0) if not hc % (qs + 1) == 0: print('No') sys.exit(0) t = s.split('Q') pre = len(t[0]) // 2 suf = 0 if len(t) == 1 else len(t[-1]) // 2...
{ "input": [ "HHQHHQH\n", "HHQQHHQQHH\n", "HHHH\n", "HQHQH\n", "QHQHHQQQQQQQQQQQHQQHQHQQQQQQHQHQQQQQQQQQQQHQQQQQQQHQQHQQHQQQQQQQQQQQQQQQQQQQQHHQQQQQQQQQQHQQQQHHQHQQHQQQQQHQQQQQQQHQQQQQHQ\n", "QQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQHQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its subset — a language called HQ... Input The only line of the input is a string betw...
339_B. Xenia and Ringroad_18681
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise. Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i...
def main(n, m, lst): count = 0 lst = [1] + lst for i in range(1, len(lst)): if lst[i] >= lst[i-1]: count += lst[i] - lst[i-1] else: count += n - lst[i-1] + lst[i] return count n, m = [int(x) for x in input().split()] lst = list(map(int, input().split())) print(ma...
{ "input": [ "4 3\n2 3 3\n", "4 3\n3 2 3\n", "78 58\n23 14 73 45 47 14 27 59 65 39 15 23 5 1 50 37 3 51 46 69 75 65 45 68 48 59 77 39 53 21 72 33 46 32 34 5 69 55 56 53 47 31 32 5 42 23 76 15 2 77 65 24 16 68 61 28 55 10\n", "10 100\n7 6 2 10 7 2 3 8 10 4 6 1 4 5 7 10 1 2 3 5 4 10 8 2 3 3 6 8 3 9 4 1 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is...
385_B. Bear and Strings_18687
The bear has a string s = s1s2... s|s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (1 ≤ i ≤ j ≤ |s|), that string x(i, j) = sisi + 1... sj contains at least one string "bear" as a substring. String x(i, j) contains strin...
a=input() ans=0 for i in range(0,len(a)-3): b=a.find("bear",i) if b>=0: ans+=len(a)-3-b print(ans)
{ "input": [ "bearaabearc\n", "bearbtear\n", "be\n", "bear\n", "pbearbearhbearzqbearjkterasjhy\n", "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb\n", "a\n", "ce\n", "pbearbearhbearzqbearjktdrasjhy\n", "pbearjbearbebfarnbabc...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The bear has a string s = s1s2... s|s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (...
406_A. Unusual Product_18691
Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix. The dot product of two integer number vectors x and y of size n is the sum of the products of the corresponding components of the vectors. The unusual square of an n × n square matrix A is ...
from sys import stdin n = int(stdin.readline()) dot = 0 j = 0 for i in range(n): line = stdin.readline() if line[j] == '1': dot ^= 1 j += 2 out = [] stdin.readline() for query in stdin: if len(query) < 3: out.append('1' if dot else '0') else: dot ^= 1 print(''.join(out))
{ "input": [ "3\n1 1 1\n0 1 1\n1 0 0\n12\n3\n2 3\n3\n2 2\n2 2\n1 3\n3\n3\n1 2\n2 1\n1 1\n3\n", "2\n0 0\n0 0\n9\n3\n1 2\n2 2\n1 1\n2 1\n3\n1 2\n1 1\n3\n", "1\n0\n5\n1 1\n3\n1 1\n1 1\n3\n", "5\n1 0 1 0 1\n0 1 0 1 0\n1 0 1 0 1\n0 1 0 1 0\n1 0 1 0 1\n7\n3\n2 4\n1 3\n3\n2 5\n1 5\n3\n", "2\n0 0\n0 0\n2\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix. The dot product of two integer number vectors x and ...
433_B. Kuriyama Mirai's Stones_18695
Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should...
t = int(input()) lst = list(map(int,input().split())) x = lst[:] x.sort() l_st = [0] lst1 = [0] k = 0 k1 = 0 for i in range(t): k += lst[i] l_st.append(k) k1 += x[i] lst1.append(k1) n = int(input()) for i in range(n): t_pe , l , r = map(int,input().split()) if(t_pe == 1): print(l_st[r] -...
{ "input": [ "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n", "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n", "1\n2\n10\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1\n", "5\n8 8 1 10 7\n5\n1 2 2\n1 1 4\n1 3 3\n1 2 2\n1 2 5\n", "10\n10 3 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is vi. Kuriyama Mirai wants to know something ab...
478_B. Random Teams_18701
n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could ha...
#code n,m = map(int,input().split()) k = n//m z = n - m print(m*k*(k-1)//2+k*(n%m),(z+1)*z//2)
{ "input": [ "3 2\n", "6 3\n", "5 1\n", "10 2\n", "1000000 1000\n", "38447 383\n", "1000000000 1\n", "1000000000 32170\n", "5000000 12\n", "1833 195\n", "1000000000 999999999\n", "999999999 500000000\n", "599222887 298488\n", "10 6\n", "1 1\n", "10000000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same ...
500_D. New Year Santa Network_18705
New Year is coming in Tree World! In this world, as the name implies, there are n cities connected by n - 1 roads, and for any two distinct cities there always exists a path between them. The cities are numbered by integers from 1 to n, and the roads are numbered by integers from 1 to n - 1. Let's define d(u, v) as tot...
from queue import Queue import sys cost = [] def readarray(): return map(int, input().split(' ')) n = int(input()) graph = [[] for i in range(n)] for i in range(n - 1): u, v, c = readarray() u, v = u - 1, v - 1 cost.append(c) graph[u].append((v, i)) graph[v].append((u, i)) order = [] used = [0] * n q = [0]...
{ "input": [ "6\n1 5 3\n5 3 2\n6 1 7\n1 4 4\n5 2 3\n5\n1 2\n2 1\n3 5\n4 1\n5 2\n", "3\n2 3 5\n1 3 3\n5\n1 4\n2 2\n1 2\n2 1\n1 1\n", "3\n1 3 925\n2 1 778\n3\n2 482\n2 206\n1 512\n", "10\n1 2 938\n1 6 23\n1 10 727\n1 9 814\n9 5 644\n8 5 39\n2 7 999\n1 3 666\n5 4 577\n10\n9 556\n5 64\n9 318\n3 373\n4 548...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: New Year is coming in Tree World! In this world, as the name implies, there are n cities connected by n - 1 roads, and for any two distinct cities there always exists a path between t...
526_B. Om Nom and Dark Park_18709
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him. <image> The park consists of 2n + 1 - 1 squares connected by roads...
# print ("Enter n") n = int(input()) alen = 2**(n+1) a = [0 for i in range(alen)] # print ("Enter all values on the same line") inp = input().split() for i in range(len(inp)): a[i+2] = int(inp[i]) answer = 0 while (n > 0): index = 2**n for i in range(index, index*2, 2): left = a[i] right ...
{ "input": [ "2\n1 2 3 4 5 6\n", "3\n87 37 91 29 58 45 51 74 70 71 47 38 91 89\n", "1\n49 36\n", "3\n86 12 92 91 3 68 57 56 76 27 33 62 71 84\n", "4\n25 42 71 29 50 30 99 79 77 24 76 66 68 23 97 99 65 17 75 62 66 46 48 4 40 71 98 57 21 92\n", "5\n64 72 35 68 92 95 45 15 77 16 26 74 61 65 18 22...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can sc...
551_C. GukiZ hates Boxes_18713
Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way. In total there are n piles of boxes, arranged in a line, from left to right, i-th pile (1 ≤ i ≤ n) containing ai boxes. Luckily, m students are willing to help GukiZ by removing all the boxes from his way...
# -*- coding: utf-8 -*- # @Time : 2021/1/15 5:25 下午 # @Author : qu # @Email : quzhenqing@zju.edu.cn # @File : C. GukiZ hates Boxes.py from sys import stdin # n, m = map(int, stdin.buffer.readline().split()) a = list(map(int, stdin.buffer.readline().split())) max_not_zero = 0 for index, value in enumerate(a):...
{ "input": [ "3 2\n1 0 2\n", "2 1\n1 1\n", "4 100\n3 4 5 4\n", "5 8\n121351 0 13513 0 165454\n", "9 5\n0 0 0 0 0 0 0 0 6\n", "6 6\n0 10 0 0 10 0\n", "6 2\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "19 100000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n", "1 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way. In total there are n piles of boxes, arranged in a line, from left ...
578_D. LCS Again_18716
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 ...
n, m = map(int, input().split()) s = input() p = c = 0 for i in range(1, n): if s[i] == s[i - 1]: c += n * (m - 1) p = i elif s[i] != s[i - 2]: p = i - 1 c += i - p ans = n * n * (m - 1) - c print(ans)
{ "input": [ "10 9\nabacadefgh\n", "1 2\na\n", "3 3\naaa\n", "3 3\naab\n", "100 26\njysrixyptvsesnapfljeqkytlpeepjopspmkviqdqbdkylvfiawhdjjdvqqvcjmmsgfdmpjwahuwhgsyfcgnefzmqlvtvqqfbfsf\n", "1 26\nz\n", "15 3\nabababababababa\n", "1 26\ny\n", "15 3\naaababababababa\n", "3 3\nbab...
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...
5_B. Center Alignment_18720
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product. You are to implement the alignment in the shortest possible time. Good luck! Input The input file c...
import sys; lines = []; m = 0; for s in sys.stdin: lines.append(s.rstrip()); for s in lines: m = max(m, len(s)); turn_is_left = 1; sys.stdout.write('*' * (m + 2) + '\n'); for s in lines: l = len(s); p = q = (m - l) // 2; if ((m - l) % 2): if turn_is_left: q += 1; else: p += 1; tur...
{ "input": [ "This is\n\nCodeforces\nBeta\nRound\n5\n", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n", "8\n\n\n\ny\nW\n\n\n\n3B\n\nw\nV\n\n\n\nL\nSr\n\n\nV\n\n5\n\nAq\n\n\n\nJ\nR\n\n04\nJ\nv\nhU\n\n\n\nY\nG\n4\n\nG\nb\n\n\n9\n\n6\nd\n\n2\n\n\nE\n7\n\nr\n\n\n\n\nKC\ns\nE\n\nab\n4\nx\n\n\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into ...
621_E. Wet Shark and Blocks_18724
There are b blocks of digits. Each one consisting of the same n digits, which are given to you in the input. Wet Shark must choose exactly one digit from each block and concatenate all of those digits together to form one large integer. For example, if he chooses digit 1 from the first block and digit 2 from the second...
import os from io import BytesIO #input = BytesIO(os.read(0, os.fstat(0).st_size)).readline def main(): mod = 10**9 + 7 n,b,k,x = map(int,input().split()) x2 = x + 1 ai = list(map(int,input().split())) ai2 = [0]*x2 for i in range(n): ai2[ai[i] % x] += 1 ai2[-1] = 1 def power2(n...
{ "input": [ "3 2 1 2\n3 1 2\n", "3 2 1 2\n6 2 2\n", "12 1 5 10\n3 5 6 7 8 9 5 1 1 1 1 5\n", "6 5 12 23\n5 8 2 6 5 5\n", "3 2 0 2\n3 3 9\n", "100 1000000000 42 97\n2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 1 8 8 1 5 2 1 2 5 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are b blocks of digits. Each one consisting of the same n digits, which are given to you in the input. Wet Shark must choose exactly one digit from each block and concatenate al...
670_C. Cinema_18730
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109. In the evening after the conference, all n scientists decided to go to...
n = int(input()) d = {} for i in list(map(int, input().split())): if i in d: d[i] += 1 else: d[i] = 1 m = int(input()) res = [(0, 0)] * m b = list(map(int, input().split())) c = list(map(int, input().split())) for i in range(m): if b[i] not in d: d[b[i]] = 0 if c[i] not in d: d[c[i]] = 0 res[i] = (d...
{ "input": [ "6\n6 3 1 1 3 7\n5\n1 2 3 4 5\n2 3 4 5 1\n", "3\n2 3 2\n2\n3 2\n2 3\n", "2\n4 4\n2\n4 7\n7 5\n", "3\n1 3 2\n2\n1 3\n2 4\n", "12\n3 2 1 1 4 4 5 1 6 6 7 7\n4\n3 2 4 7\n2 1 5 6\n", "2\n10 8\n10\n8 3 10 8 8 8 3 8 8 8\n10 10 8 3 10 3 8 3 10 10\n", "5\n9 9 2 4 2\n5\n4 1 1 1 2\n2 4 4...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we ...
737_B. Sea Battle_18738
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other. Galya doesn't know the ships location. She can shoot to some cells and after each shot ...
n,a,b,k=map(int,input().split()) A=input() B=A.split('1') C=[] l=1 for i in B: if len(i)>=b: for j in range(b-1,len(i),b): C.append(j+l) l+=len(i)+1 C=C[:len(C)-a+1] print(len(C)) print(' '.join(list(map(str,C)))) # Made By Mostafa_Khaled
{ "input": [ "13 3 2 3\n1000000010001\n", "5 1 2 1\n00100\n", "10 2 2 0\n0000000000\n", "20 1 3 5\n01001010000000010010\n", "100 17 4 11\n0100000100000000000000001000000000010001100000000000101000000000000000000000001000001000010000000000\n", "5 4 1 0\n00000\n", "1 1 1 0\n0\n", "5 1 2 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two...
761_A. Dasha and Stairs_18742
On her way to programming school tiger Dasha faced her first test — a huge staircase! <image> The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — th...
string=input() a,b=map(int,string.split(' ')) if a==0 and b==0: print('NO') elif a-b==1 or b-a==1: print('YES') elif a==b: print('YES') else: print('NO')
{ "input": [ "3 1\n", "2 3\n", "0 0\n", "1 0\n", "0 5\n", "100 98\n", "62 39\n", "100 99\n", "99 100\n", "100 100\n", "57 57\n", "74 73\n", "0 100\n", "89 25\n", "0 1\n", "100 0\n", "98 100\n", "9 9\n", "85 95\n", "5 4\n", "2 2\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: On her way to programming school tiger Dasha faced her first test — a huge staircase! <image> The steps were numbered from one to infinity. As we know, tigers are very fond of all s...
784_C. INTERCALC_18746
DO YOU EXPECT ME TO FIND THIS OUT? WHAT BASE AND/XOR LANGUAGE INCLUDES string? DON'T BYTE OF MORE THAN YOU CAN CHEW YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT! I HAVE NO ARRAY AND I M...
input() a = list(map(int, input().split())) print(max(a) ^ a[-1])
{ "input": [ "4\n2 5 3 1\n", "7\n1 6 5 3 9 5 9\n", "3\n4 10 3\n", "8\n7 2 6 3 6 4 1 8\n", "8\n3 5 8 10 3 4 2 10\n", "3\n1 1 5\n", "7\n11 1 2 8 10 5 9\n", "6\n1 5 2 1 7 11\n", "6\n1 1 1 3 2 9\n", "10\n5 6 4 8 11 4 10 4 8 4\n", "5\n4 5 5 2 11\n", "2\n1 5\n", "7\n4 5 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: DO YOU EXPECT ME TO FIND THIS OUT? WHAT BASE AND/XOR LANGUAGE INCLUDES string? DON'T BYTE OF MORE THAN YOU CAN CHEW YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR SAYING "...
805_B. 3-palindrome_18750
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substr...
def check(s): for i in range(len(s)//2): if s[i] != s[-(i+1)]: return(True) return(False) n = int(input()) sub = "aabb" ans = "" mod = n //4 ans += sub*mod for i in range(n%4): ans += sub[i] print(ans) # print(check(ans))
{ "input": [ "2\n", "3\n", "6\n", "1\n", "77859\n", "140873\n", "146883\n", "59\n", "182801\n", "183758\n", "100000\n", "109\n", "64905\n", "12802\n", "60131\n", "17879\n", "3\n", "153022\n", "104217\n", "120289\n", "160397\n", "1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given n he wants to obta...
830_B. Cards Sorting_18754
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", "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 5...
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...
851_C. Five Dimensional Points_18758
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide. We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise,...
d = lambda i, j, k: sum((a - c) * (b - c) for a, b, c in zip(p[i], p[j], p[k])) * (i != j) n = int(input()) r = range(n) p = [list(map(int, input().split())) for i in r] t = [k + 1 for k in r if all(d(i, j, k) <= 0 for i in r for j in r)] if n < 12 else [] for q in [len(t)] + t: print(q)
{ "input": [ "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0\n", "6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1\n", "10\n0 -110 68 -51 -155\n-85 -110 68 -51 -155\n85 -70 51 68 -230\n0 -40 51 68 75\n0 5 -51 -68 -190\n85 0 0 0 0\n85 -115 -68 51 35\n85 -75 -187 34 -40\n-85 -110 -136 102 -155\n85 -1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide. We will call point a bad if there are different points b and c, not ...
89_D. Space mines_18764
Once upon a time in the galaxy of far, far away... Darth Wader found out the location of a rebels' base. Now he is going to destroy the base (and the whole planet that the base is located at), using the Death Star. When the rebels learnt that the Death Star was coming, they decided to use their new secret weapon — sp...
import sys, math def dist(a,b): return pow((a[0] - b[0])**2 + (a[1] - b[1])**2 + (a[2] - b[2])**2,0.5) def vxv(v1,v2): x = -v1[2] * v2[1] + v1[1] * v2[2] y = -v1[0] * v2[2] + v1[2] * v2[0] z = -v1[1] * v2[0] + v1[0] * v2[1] return (x,y,z) readline = sys.stdin.readline s1,s2,s3,v1,v2,v3,R = map(int,...
{ "input": [ "30 30 2 1 2 1 20\n3\n0 0 40 5 1\n1 4 4\n-10 -40 -5 7 0\n100 200 95 8 1\n-10 0 0\n", "8 8 4 4 4 2 6\n1\n-2 -2 -1 3 0\n", "0 0 0 1 0 0 5\n2\n10 8 0 2 2\n0 -3 0\n2 2 0\n20 0 0 4 3\n2 4 0\n-4 3 0\n1 -5 0\n", "-10000 0 0 1 0 0 3\n1\n10000 6 0 2 1\n-3 0 0\n", "100 99 30 -1 -5 -3 100\n1\n10...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Once upon a time in the galaxy of far, far away... Darth Wader found out the location of a rebels' base. Now he is going to destroy the base (and the whole planet that the base is lo...
949_D. Curfew_18770
Instructors of Some Informatics School make students go to bed. The house contains n rooms, in each room exactly b students were supposed to sleep. However, at the time of curfew it happened that many students are not located in their assigned rooms. The rooms are arranged in a row and numbered from 1 to n. Initially,...
read = lambda: map(int, input().split()) n, d, b = read() d += 1 t, a = 0, [0] * (n + 1) for i, x in enumerate(read()): t += x a[i + 1] = t print(max(i - min(a[min(n, i * d)], (a[n] - a[max(0, n - i * d)])) // b for i in range(n + 3 >> 1)))
{ "input": [ "6 1 2\n3 8 0 1 0 0\n", "5 1 1\n1 0 0 0 4\n", "50 2 1\n0 1 1 1 1 1 1 0 2 2 0 0 1 1 2 0 1 0 1 2 0 1 1 0 1 2 3 0 0 1 0 3 1 1 1 1 1 1 3 0 0 0 2 0 2 2 0 3 2 0\n", "100 1 24\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 151 150 159 159 147 121 143 143 138 138 127 127 128 123 159 159 128 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: Instructors of Some Informatics School make students go to bed. The house contains n rooms, in each room exactly b students were supposed to sleep. However, at the time of curfew it ...
977_C. Less or Equal_18774
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x. Note that the sequence can contain equal elements. If there is no such x, print "-1" (w...
# import sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') t = 1 # t = int(input()) while t: t -= 1 n, k = list(map(int, input().split())) a = list(map(int, input().split())) # s = input() a.sort() if k == 0: ans = a[0]-1 else: ans = a[k...
{ "input": [ "7 4\n3 7 5 1 10 3 20\n", "7 2\n3 7 5 1 10 3 20\n", "7 2\n2 7 5 1 10 2 20\n", "1 0\n1\n", "2 2\n1000000000 1000000000\n", "3 0\n2 2 3\n", "5 3\n1 3 3 4 5\n", "7 4\n3 7 5 1 10 3 20\n", "4 0\n2 3 4 5\n", "2 1\n1 1\n", "5 0\n3 4 5 6 7\n", "3 0\n3 3 3\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements...
997_A. Convert to Ones_18778
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones. Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a. You can apply the following operations any number of times: * Choose some substring of string a (for example, you can choose entire strin...
n, x, y = [int(s) for s in input().split(' ')] a = input() z = len([t for t in a.split('1') if t]) ans = max(min(z * y, y + (z - 1) * x), 0) print(ans)
{ "input": [ "5 10 1\n01000\n", "7 2 3\n1111111\n", "5 1 10\n01000\n", "4 684444619 722440661\n1001\n", "1 60754033 959739508\n0\n", "4 991751283 202031630\n1110\n", "5 2 3\n10101\n", "4 480505300 892025118\n0111\n", "1 1 0\n1\n", "4 908958584 523522825\n0101\n", "5 1 1000\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones. Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a. You...
p02653 AtCoder Grand Contest 045 - Range Set_18791
Snuke has a string x of length N. Initially, every character in x is `0`. Snuke can do the following two operations any number of times in any order: * Choose A consecutive characters in x and replace each of them with `0`. * Choose B consecutive characters in x and replace each of them with `1`. Find the number o...
MOD = 10 ** 9 + 7 n, a, b = map(int, input().split()) if a > b: a, b = b, a dp_1s = [0] * b for l in range(a + 2, b): dp = [[0, 0] for _ in range(l + 1)] # at i, 0/1 precedes dp[1][1] = 1 for i in range(1, l): dp[i + 1][0] = (dp[i + 1][0] + dp[i][0]) % MOD dp[i + 1][1] = (dp[i + 1][1] ...
{ "input": [ "4 2 3", "10 7 2", "1000 100 10", "15 7 2", "1000 101 10", "1100 101 10", "1100 111 10", "7 2 3", "20 7 2", "15 3 2", "1000 101 3", "1100 100 10", "1100 101 19", "7 1 3", "20 13 2", "17 3 2", "1000 111 3", "11 2 3", "20 8 2", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Snuke has a string x of length N. Initially, every character in x is `0`. Snuke can do the following two operations any number of times in any order: * Choose A consecutive characte...
p02782 AtCoder Beginner Contest 154 - Many Many Paths_18795
Snuke is standing on a two-dimensional plane. In one operation, he can move by 1 in the positive x-direction, or move by 1 in the positive y-direction. Let us define a function f(r, c) as follows: * f(r,c) := (The number of paths from the point (0, 0) to the point (r, c) that Snuke can trace by repeating the operati...
r1, c1, r2, c2 = map(int, input().split()) mod = int(1e+9) + 7 def inved(x): a, b, c, d, k, l = 1, 0, 0, 1, x, mod while l != 0: a, b, c, d = c, d, a - c * (k // l), b - d * (k // l) k, l = l, k % l return a % mod frac = [1] for i in range(r2 + c2 + 2): frac.append(((i+1) * frac[i]) % mod) fracr2c2 = fr...
{ "input": [ "314 159 2653 589", "1 1 2 2", "314 159 2856 589", "1 1 4 2", "139 159 2856 589", "139 159 2699 589", "139 211 2699 589", "314 226 2653 589", "357 159 2856 589", "1 1 0 2", "139 39 2856 589", "139 159 2699 481", "139 211 4894 589", "314 20 2653 589"...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Snuke is standing on a two-dimensional plane. In one operation, he can move by 1 in the positive x-direction, or move by 1 in the positive y-direction. Let us define a function f(r, ...
p02917 AtCoder Beginner Contest 140 - Maximal Value_18799
There is an integer sequence A of length N whose values are unknown. Given is an integer sequence B of length N-1 which is known to satisfy the following: B_i \geq \max(A_i, A_{i+1}) Find the maximum possible sum of the elements of A. Constraints * All values in input are integers. * 2 \leq N \leq 100 * 0 \leq B_i...
n = int(input()) b = list(map(int,input().split())) sum = b[0]+b[n-2] for i in range(n-2): sum += min(b[i],b[i+1]) print(sum)
{ "input": [ "2\n3", "6\n0 153 10 10 23", "3\n2 5", "2\n5", "6\n0 153 10 14 23", "3\n2 9", "2\n4", "6\n0 153 10 14 17", "3\n2 12", "2\n1", "6\n0 153 10 14 26", "3\n1 12", "2\n0", "3\n4 12", "2\n2", "6\n0 164 10 7 26", "3\n7 12", "2\n-1", "6\n...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is an integer sequence A of length N whose values are unknown. Given is an integer sequence B of length N-1 which is known to satisfy the following: B_i \geq \max(A_i, A_{i+1}...
p03053 AtCoder Grand Contest 033 - Darker and Darker_18803
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if t...
from collections import deque from itertools import chain H, W = map(int, input().split()) G = chain.from_iterable([[s == '#' for s in input()] for _ in range(H)]) dist = [0]*(H*W) B = deque([i for i, g in enumerate(G) if g]) visited = set(B) while B: vij = B.pop() for dij in (W, -W, 1, -1): nij = vij +...
{ "input": [ "3 3\n...\n.#.\n...", "6 6\n..#..#\n......\n..#..\n......\n.#....\n....#.", "2 3\n...\n.#.\n...", "6 6\n..#..#\n......\n..#..\n......\n.#....\n-...#.", "2 6\n#.#...\n......\n..#0.\n......\n.#.-..\n--..#-", "2 3\n...\n.#.\n..-", "2 3\n/..\n.#.\n..-", "2 3\n/..\n.#.\n..,", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of...
p03197 CADDi 2018 - Harlequin_18807
There is an apple tree that bears apples of N colors. The N colors of these apples are numbered 1 to N, and there are a_i apples of Color i. You and Lunlun the dachshund alternately perform the following operation (starting from you): * Choose one or more apples from the tree and eat them. Here, the apples chosen at ...
N = int(input()) A = [int(input()) for i in range(N)] for a in A: if a%2: print('first') exit() print('second')
{ "input": [ "3\n100000\n30000\n20000", "2\n1\n2", "3\n100000\n30000\n29639", "2\n0\n2", "2\n1\n0", "3\n000000\n30000\n29639", "2\n1\n1", "3\n000001\n30000\n29639", "2\n2\n1", "3\n000011\n30000\n29639", "3\n000010\n30000\n29639", "2\n2\n2", "3\n100010\n30000\n29639"...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is an apple tree that bears apples of N colors. The N colors of these apples are numbered 1 to N, and there are a_i apples of Color i. You and Lunlun the dachshund alternately ...
p03344 AtCoder Regular Contest 098 - Donation_18810
There is a simple undirected graph with N vertices and M edges. The vertices are numbered 1 through N, and the edges are numbered 1 through M. Edge i connects Vertex U_i and V_i. Also, Vertex i has two predetermined integers A_i and B_i. You will play the following game on this graph. First, choose one vertex and stan...
class dsu: def __init__(self, n=0): self._n = n self.parent_or_size = [-1] * n def merge(self, a: int, b: int) -> int: x = self.leader(a) y = self.leader(b) if x == y: return x if self.parent_or_size[x] > self.parent_or_size[y]: x, y =...
{ "input": [ "5 8\n6 4\n15 13\n15 19\n15 1\n20 7\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 5\n4 5", "9 10\n131 2\n98 79\n242 32\n231 38\n382 82\n224 22\n140 88\n209 70\n164 64\n6 8\n1 6\n1 4\n1 3\n4 7\n4 9\n3 7\n3 9\n5 9\n2 5", "4 5\n3 1\n1 2\n4 1\n6 2\n1 2\n2 3\n2 4\n1 4\n3 4", "5 8\n6 8\n15 13\n15 19\n15 1\n...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a simple undirected graph with N vertices and M edges. The vertices are numbered 1 through N, and the edges are numbered 1 through M. Edge i connects Vertex U_i and V_i. Also...
p03504 AtCoder Beginner Contest 080 - Recording_18814
Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on ...
import sys def MI(): return map(int,sys.stdin.readline().rstrip().split()) N,C = MI() A = [[0]*(10**5+2) for i in range(C+1)] for i in range(N): s,t,c = MI() A[c][s] += 1 A[c][t+1] -= 1 from itertools import accumulate for i in range(1,C+1): A[i] = list(accumulate(A[i])) # A[i][j] が正 ⇔ チャンネル i が時刻 j...
{ "input": [ "9 4\n56 60 4\n33 37 2\n89 90 3\n32 43 1\n67 68 3\n49 51 3\n31 32 3\n70 71 1\n11 12 3", "3 2\n1 7 2\n7 8 1\n8 12 1", "3 4\n1 3 2\n3 4 4\n1 4 3", "9 4\n56 60 4\n33 37 2\n89 90 3\n32 43 1\n67 68 3\n71 51 3\n31 32 3\n70 71 1\n11 12 3", "3 4\n1 3 2\n2 4 4\n1 4 3", "2 4\n56 60 4\n33 37...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time...
p03665 AtCoder Grand Contest 017 - Biscuits_18818
There are N bags of biscuits. The i-th bag contains A_i biscuits. Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags. He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such wa...
N, P = map(int, input().split()) O = sum([int(a) % 2 for a in input().split()]) E = N - O fa = [1] for i in range(1, 51): fa.append(fa[-1] * i) ans = 0 for i in range(P, O+1, 2): ans += fa[O] // (fa[i] * fa[O-i]) print(ans * 2**E)
{ "input": [ "3 0\n1 1 1", "1 1\n50", "2 0\n1 3", "45 1\n17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26", "1 1\n67", "45 1\n17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 68 25 9 89 71 41 16 53 13 61...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N bags of biscuits. The i-th bag contains A_i biscuits. Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or...
p03820 AtCoder Regular Contest 068 - Solitaire_18821
Snuke has decided to play with N cards and a deque (that is, a double-ended queue). Each card shows an integer from 1 through N, and the deque is initially empty. Snuke will insert the cards at the beginning or the end of the deque one at a time, in order from 1 to N. Then, he will perform the following action N times...
def cmb(n, r, mod):#コンビネーションの高速計算  if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 N = 5000 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.ap...
{ "input": [ "2 1", "2000 1000", "17 2", "2000 1100", "4 2", "4 1", "1 1", "3 1", "13 2", "5 2", "5 1", "10 1", "9 2", "19 1", "9 1", "38 1", "25 1", "2000 1001", "12 1", "13 3", "5 4", "10 2", "9 4", "19 2", "38 2", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Snuke has decided to play with N cards and a deque (that is, a double-ended queue). Each card shows an integer from 1 through N, and the deque is initially empty. Snuke will insert t...
p03987 AtCoder Grand Contest 005 - Minimum Sum_18825
One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend. Find the following: <image> Constraints * 1 ≦ N ≦ 200,000 * (a_1, a_2, ..., a_N) is a permutation of (1, 2, ..., N). Input The input is given from Standard Input in the following format: N a_1 a_2 ... a_N Output Print th...
import sys input = sys.stdin.readline import bisect n = int(input()) A = list(map(int,input().split())) class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i ...
{ "input": [ "3\n2 1 3", "4\n1 3 2 4", "8\n5 4 8 1 2 6 7 3", "3\n3 1 2", "3\n1 2 3", "4\n2 3 1 4", "4\n1 3 4 2", "8\n5 3 8 1 2 6 7 4", "4\n3 2 4 1", "8\n4 5 8 1 2 6 7 3", "3\n1 3 2", "3\n2 3 1", "3\n3 2 1", "4\n2 3 4 1", "4\n1 2 3 4", "3\n3 1 2", "3\...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend. Find the following: <image> Constraints * 1 ≦ N ≦ 200,000 * (a_1, a_2, ..., a_N) is a perm...
p00075 BMI_18829
Obesity is cited as the cause of many adult diseases. In the past, with a few exceptions, it was unrelated to high school students. However, it is no longer unrealistic to suffer from lack of exercise due to excessive studying for entrance exams, or to become bulimia nervosa due to stress. It may be a problem that high...
try: while True: id,w,h = map(float,input().split(",")) bmi = w / (h*h) if bmi >= 25.0: print(int(id)) except: pass
{ "input": [ "1001,50.0,1.60\n1002,60.0,1.70\n1003,70.0,1.80\n1004,80.0,1.70\n1005,90.0,1.60", "1011,50.0,1.60\n1002,60.0,1.70\n1003,70.0,1.80\n1004,80.0,1.70\n1005,90.0,1.60", "1010,50.0,1.60\n1002,60.0,1.70\n1003,70.0,1.80\n1400,80.0,1.70\n1005,90.0,1.60", "1001,50.0,1.60\n1002,60.0,1.70\n1003,70.0,...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Obesity is cited as the cause of many adult diseases. In the past, with a few exceptions, it was unrelated to high school students. However, it is no longer unrealistic to suffer from...
p00207 Block_18833
Relative B came to Mr. A's house. He is 3 years old and loves blocks. The block he has is shaped like Figure 1. <image> Figure 1 Mr. B is laying blocks on the board. When I asked him, "What are you making?", He replied cheerfully, "Maze !!". The maze he says is the arrangement of blocks that are in contact with each...
import sys BLOCK_WIDTH = 4 BLOCK_HEIGHT = 2 field = [] dx = [-1, 0, 1, 0] dy = [0, 1, 0, -1] w = 0 h = 0 xg = 0 yg = 0 start_color = 0 def main(): global field, w, h, c, xg, yg, start_color while True: w, h = map(int, input().split()) if w == 0 and h == 0: break xs, ys = ma...
{ "input": [ "20 20\n1 1\n9 9\n7\n2 0 1 1\n5 1 1 3\n2 1 3 3\n1 1 5 2\n5 1 7 3\n2 0 2 7\n2 0 6 8\n20 20\n9 9\n1 1\n6\n2 0 1 1\n1 0 5 1\n2 1 1 3\n5 0 1 7\n3 1 5 5\n4 1 8 5\n0 0", "20 20\n1 1\n9 9\n7\n2 0 1 1\n5 1 1 3\n2 1 3 3\n1 1 5 2\n5 1 7 3\n2 0 2 7\n2 0 6 8\n20 20\n9 9\n1 1\n6\n2 0 1 1\n1 0 5 1\n2 1 1 3\n5 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Relative B came to Mr. A's house. He is 3 years old and loves blocks. The block he has is shaped like Figure 1. <image> Figure 1 Mr. B is laying blocks on the board. When I asked h...
p00366 Electronic Metronome_18836
A boy PCK is playing with N electric metronomes. The i-th metronome is set to tick every t_i seconds. He started all of them simultaneously. He noticed that, even though each metronome has its own ticking interval, all of them tick simultaneously from time to time in certain intervals. To explore this interesting phen...
n = int(input()) max_t = 0 timing = [] for i in range(n): timing.append(int(input())) if timing[i] > max_t : max_t = timing[i] divisor = [] for i in range(1,(max_t>>1)+1): if max_t%i == 0 : divisor.append(i) divisor.append(max_t) adj = 0 for t in timing : for d in divisor : if d >= t : ...
{ "input": [ "3\n3\n6\n8", "2\n10\n10", "3\n5\n6\n8", "2\n10\n4", "3\n5\n5\n8", "2\n10\n6", "3\n8\n5\n8", "2\n10\n2", "2\n18\n4", "2\n34\n4", "2\n34\n8", "2\n35\n15", "2\n4\n57", "2\n4\n43", "2\n5\n43", "2\n5\n62", "2\n5\n17", "2\n10\n31", "2...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A boy PCK is playing with N electric metronomes. The i-th metronome is set to tick every t_i seconds. He started all of them simultaneously. He noticed that, even though each metrono...
p00721 Cleaning Robot_18842
Here, we want to solve path planning for a mobile robot cleaning a rectangular room floor with furniture. Consider the room floor paved with square tiles whose size fits the cleaning robot (1 × 1). There are 'clean tiles' and 'dirty tiles', and the robot can change a 'dirty tile' to a 'clean tile' by visiting the tile...
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**13 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": [ "7 5\n.......\n.o...*.\n.......\n.*...*.\n.......\n15 13\n.......x.......\n...o...x....*..\n.......x.......\n.......x.......\n.......x.......\n...............\nxxxxx.....xxxxx\n...............\n.......x.......\n.......x.......\n.......x.......\n..*....x....*..\n.......x.......\n10 10\n..........\n..o...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Here, we want to solve path planning for a mobile robot cleaning a rectangular room floor with furniture. Consider the room floor paved with square tiles whose size fits the cleaning...
p00861 Bug Hunt_18846
In this problem, we consider a simple programming language that has only declarations of one- dimensional integer arrays and assignment statements. The problem is to find a bug in the given program. The syntax of this language is given in BNF as follows: <image> where <new line> denotes a new line character (LF). C...
import re def deref(d, expr): expr = expr.replace(']', '') symb = expr.split('[') symb[-1] = symb[-1] while len(symb) > 1: name, index = symb[-2:] if index not in d[name]: return None symb.pop() symb.pop() symb.append(d[name][index]) return symb[0] def check(s): d = {} dd = ...
{ "input": [ "a[3]\na[0]=a[1]\n.\nx[1]\nx[0]=x[0]\n.\na[0]\na[0]=1\n.\nb[2]\nb[0]=2\nb[1]=b[b[0]]\nb[0]=b[1]\n.\ng[2]\nG[10]\ng[0]=0\ng[1]=G[0]\n.\na[2147483647]\na[0]=1\nB[2]\nB[a[0]]=2\na[B[a[0]]]=3\na[2147483646]=a[2]\n.\n.", "a[3]\na[0]=a[1]\n.\nx[1]\nx[0]=x[0]\n.\na[0]\na[0]=1\n.\nb[2]\nb[0]=2\nb[1]=b[b[...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In this problem, we consider a simple programming language that has only declarations of one- dimensional integer arrays and assignment statements. The problem is to find a bug in the...
p00992 War_18849
Two countries, Country A and Country B, are at war. As a soldier in Country A, you will lead n soldiers to occupy the territory of Country B. The territory of Country B is represented by a two-dimensional grid. The first place you occupy is a square on the 2D grid. Each of the soldiers you lead has h_i health. Each so...
a=sorted([int(input()) for _ in [0]*int(input())]) c=b=0 for i in range(len(a)-1,-1,-1): if a[i]<c//4:continue else:b+=a[i]-c//4 c+=1 print(b+1)
{ "input": [ "10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10", "2\n5\n5", "5\n1\n2\n3\n4\n5", "10\n10\n10\n14\n10\n10\n10\n10\n10\n10\n10", "2\n3\n5", "5\n1\n2\n5\n4\n5", "10\n6\n10\n14\n10\n10\n10\n10\n10\n10\n10", "2\n3\n6", "5\n2\n2\n5\n4\n5", "10\n6\n10\n14\n10\n10\n10\n10\n10\...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Two countries, Country A and Country B, are at war. As a soldier in Country A, you will lead n soldiers to occupy the territory of Country B. The territory of Country B is represente...
p01423 Rabbit Party_18854
A rabbit Taro decided to hold a party and invite some friends as guests. He has n rabbit friends, and m pairs of rabbits are also friends with each other. Friendliness of each pair is expressed with a positive integer. If two rabbits are not friends, their friendliness is assumed to be 0. When a rabbit is invited to t...
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()]...
{ "input": [ "3 3\n1 2 3\n2 3 1\n3 1 2", "2 1\n1 2 5", "4 5\n1 2 4\n1 3 3\n2 3 7\n2 4 5\n3 4 6", "1 0", "3 3\n1 4 3\n2 3 1\n3 1 2", "2 2\n1 2 5", "4 5\n1 2 4\n1 3 3\n2 3 7\n2 4 3\n3 4 6", "2 0", "4 2\n1 2 10", "4 5\n2 2 6\n1 3 3\n2 2 7\n2 4 4\n3 4 6", "3 4\n1 2 3\n4 5 0\n3 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A rabbit Taro decided to hold a party and invite some friends as guests. He has n rabbit friends, and m pairs of rabbits are also friends with each other. Friendliness of each pair is...
p02016 Twins_18861
B: Twins One twin was angry that it was not well known which of them was the older brother and which was the younger brother. Create a program that outputs "square1001" when "ani" is entered and "e869120" when "otouto" is entered. input You will be given either the string "ani" or "otouto" as input. output Please...
if input()=="ani": print("square1001") else: print("e869120")
{ "input": [ "ani" ], "output": [ "square1001" ] }
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: B: Twins One twin was angry that it was not well known which of them was the older brother and which was the younger brother. Create a program that outputs "square1001" when "ani" i...
p02299 Polygon-Point Containment_18866
For a given polygon g and target points t, print "2" if g contains t, "1" if t is on a segment of g, "0" otherwise. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the poly...
def dot(c1, c2): return c1.real * c2.real + c1.imag * c2.imag def cross(c1, c2): return c1.real * c2.imag - c1.imag * c2.real def string_to_complex(s): x, y = map(int, s.split()) return x + y * 1j def contains(polygon, point): flag = False for v1, v2 in zip(polygon[0:], polygon[1:]): ...
{ "input": [ "4\n0 0\n3 1\n2 3\n0 3\n3\n2 1\n0 2\n3 2", "4\n0 0\n3 1\n2 3\n0 3\n3\n2 1\n0 2\n0 2", "4\n0 0\n3 0\n2 3\n0 1\n3\n2 1\n0 2\n0 2", "4\n0 -1\n3 1\n2 3\n0 3\n1\n2 1\n0 2\n3 1", "4\n0 -1\n2 1\n2 3\n0 3\n1\n2 1\n0 1\n3 1", "4\n0 -1\n3 0\n3 2\n1 3\n1\n0 2\n1 0\n0 1", "4\n0 -1\n6 -2\n...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: For a given polygon g and target points t, print "2" if g contains t, "1" if t is on a segment of g, "0" otherwise. g is represented by a sequence of points p1, p2,..., pn where line...
p02446 Unique_18870
For a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ which is sorted by ascending order, eliminate all equivalent elements. Constraints * $1 \leq n \leq 100,000$ * $-1000,000,000 \leq a_i \leq 1,000,000,000$ * $a_0 \leq a_1 \leq ... \leq a_{n-1}$ Input A sequence is given in the following format. $n$ $a_...
n = int(input()) s = { int(x) for x in input().split()} l = list(s) l.sort() print(*l)
{ "input": [ "4\n1 2 2 4", "4\n0 2 2 4", "4\n0 2 2 3", "4\n0 2 2 2", "4\n-1 2 2 2", "4\n0 1 2 2", "4\n0 0 0 4", "4\n-1 0 2 2", "4\n0 0 1 4", "4\n1 2 2 3", "4\n0 0 2 8", "4\n0 1 2 4", "4\n0 0 0 7", "4\n-1 0 1 2", "4\n0 0 0 8", "4\n0 0 1 7", "4\n-1 -1 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: For a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ which is sorted by ascending order, eliminate all equivalent elements. Constraints * $1 \leq n \leq 100,000$ * $-1000,0...
1041_D. Glider_18882
A plane is flying at a constant height of h meters above the ground surface. Let's consider that it is flying from the point (-10^9, h) to the point (10^9, h) parallel with Ox axis. A glider is inside the plane, ready to start his flight at any moment (for the sake of simplicity let's consider that he may start only w...
R = lambda: map(int, input().split()) n, h = R() ps = [] for _ in range(n): l, r = R() ps.append([l, r]) l, c, res = 0, 0, 0 for r in range(n): c += (ps[r][0] - ps[r - 1][1]) if r > 0 else 0 while c >= h: c -= (ps[l + 1][0] - ps[l][1]) l += 1 res = max(res, ps[r][1] - ps[l][0] + h - ...
{ "input": [ "3 4\n2 5\n7 9\n10 11\n", "1 1000000000\n1 1000000000\n", "5 10\n5 7\n11 12\n16 20\n25 26\n30 33\n", "5 10\n2 3\n4 5\n6 7\n10 14\n16 20\n", "5 10\n4 5\n6 8\n9 10\n11 13\n16 17\n", "5 10\n2 5\n6 8\n9 10\n12 14\n18 19\n", "2 3\n1 2\n3 4\n", "5 10\n1 6\n7 8\n11 13\n14 17\n18 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A plane is flying at a constant height of h meters above the ground surface. Let's consider that it is flying from the point (-10^9, h) to the point (10^9, h) parallel with Ox axis. ...
1064_C. Oh Those Palindromes_18886
A non-empty string is called palindrome, if it reads the same from the left to the right and from the right to the left. For example, "abcba", "a", and "abba" are palindromes, while "abab" and "xy" are not. A string is called a substring of another string, if it can be obtained from that string by dropping some (possi...
input() print("".join(sorted(input())))
{ "input": [ "16\ngagadbcgghhchbdf\n", "5\noolol\n", "6\nmsucmc\n", "2\naa\n", "15\nabacabadabacaba\n", "21\narozaupalanalapuazora\n", "4\nmems\n", "10\nmsunonames\n", "2\naz\n", "1\nz\n", "7\nlolikek\n", "9\nabcabcabc\n" ], "output": [ "aabbccddfgggghhh\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A non-empty string is called palindrome, if it reads the same from the left to the right and from the right to the left. For example, "abcba", "a", and "abba" are palindromes, while "...
1086_A. Connect Three_18890
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C i...
s = [[int(i)for i in input().split()]for j in range(3)] s.sort() a = s[0] b = s[1] c = s[2] print(c[0] - a[0] + max(a[1], b[1], c[1]) - min(a[1], b[1], c[1]) + 1) for i in range(a[0], b[0]): print('{} {}'.format(i, a[1])) for i in range(min(a[1], b[1], c[1]), max(a[1], b[1], c[1]) + 1): print('{} {}'.format(b...
{ "input": [ "0 0\n1 1\n2 2\n", "0 0\n2 0\n1 1\n", "1 0\n2 2\n1 1\n", "670 672\n593 626\n593 792\n", "0 1\n1 2\n2 1\n", "1 0\n0 1\n10 10\n", "163 36\n715 861\n715 711\n", "865 651\n504 482\n865 450\n", "982 852\n750 567\n18 681\n", "418 797\n765 188\n418 194\n", "0 0\n0 1\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coo...
1106_A. Lunar New Year and Cross Counting_18894
Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n × n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≤ i, j ≤ n. We define a cross appearing in the i-th row and the j-th column (1 < i...
n=int(input()) a=[] for i in range(n): s=input() a.append(s) ans=0 for i in range(1,n-1): for j in range(1,n-1): if(a[i][j]=='X' and a[i-1][j-1]=='X' and a[i-1][j+1]=='X' and a[i+1][j-1]=='X' and a[i+1][j+1]=='X'): ans+=1 print(ans)
{ "input": [ "5\n.....\n.XXX.\n.XXX.\n.XXX.\n.....\n", "6\n......\nX.X.X.\n.X.X.X\nX.X.X.\n.X.X.X\n......\n", "2\nXX\nXX\n", "2\n.X\nX.\n", "3\n...\n.X.\n...\n", "2\n..\n..\n", "1\n.\n", "1\nX\n", "14\nXXX.XXXXX..X.X\nX..XX..X...X..\n.....X.XX..XXX\n.X..X..XXX.XX.\n...XXXX.XX..XX\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n × n contains only 'X' and '.' (without quotes). The element in the i-th row and...
1133_B. Preparation for International Women's Day_18898
International Women's Day is coming soon! Polycarp is preparing for the holiday. There are n candy boxes in the shop for sale. The i-th box contains d_i candies. Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift ...
l=list(map(int,input().split())) n=l[0] k=l[1] l=[] b=[] for i in range (k): b.append(int(0)) l=list(map(int,input().split())) for i in l: b[i%k]+=1 sum=b[0]-b[0]%2 for i in range (1,(k+1)//2): sum+=(min(b[i],b[k-i])*2) if(k%2==0): sum+=b[k//2]-b[k//2]%2 print (sum)
{ "input": [ "7 3\n1 2 2 3 2 4 5\n", "8 2\n1 2 2 3 2 4 6 10\n", "7 2\n1 2 2 3 2 4 10\n", "2 9\n81 1\n", "1 2\n120\n", "2 9\n80 1\n", "3 1\n1 1 1\n", "2 9\n134 1\n", "1 2\n21\n", "7 3\n1 4 2 3 2 4 5\n", "8 2\n2 2 2 2 2 4 6 10\n", "7 3\n1 4 2 3 2 4 1\n", "2 7\n80 1\n"...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: International Women's Day is coming soon! Polycarp is preparing for the holiday. There are n candy boxes in the shop for sale. The i-th box contains d_i candies. Polycarp wants to p...
1153_E. Serval and Snake_18901
This is an interactive problem. Now Serval is a senior high school student in Japari Middle School. However, on the way to the school, he must go across a pond, in which there is a dangerous snake. The pond can be represented as a n × n grid. The snake has a head and a tail in different cells, and its body is a series...
# AC import sys class Main: def __init__(self): self.buff = None self.index = 0 def next(self): if self.buff is None or self.index == len(self.buff): self.buff = sys.stdin.readline().split() self.index = 0 val = self.buff[self.index] self.index ...
{ "input": [ "3\n\n2\n\n0\n", "2\n\n1\n\n0\n\n0\n", "2\n2\n2 1\n1 1\n", "3\n3\n2 1\n2 2\n2 3\n", "1000\n2\n222 332\n222 333\n", "1000\n2\n371 409\n372 409\n", "1000\n2\n998 999\n999 999\n", "1000\n2\n2 999\n3 999\n", "999\n2\n128 805\n129 805\n", "1000\n2\n971 461\n972 461\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. Now Serval is a senior high school student in Japari Middle School. However, on the way to the school, he must go across a pond, in which there is a d...
1175_D. Array Splitting_18905
You are given an array a_1, a_2, ..., a_n and an integer k. You are asked to divide this array into k non-empty consecutive subarrays. Every element in the array should be included in exactly one subarray. Let f(i) be the index of subarray the i-th element belongs to. Subarrays are numbered from left to right and from...
# AC import sys class Main: def __init__(self): self.buff = None self.index = 0 def next(self): if self.buff is None or self.index == len(self.buff): self.buff = self.next_line() self.index = 0 val = self.buff[self.index] self.index += 1 ...
{ "input": [ "4 1\n3 -1 6 0\n", "7 6\n-3 0 -1 -2 -2 -4 -1\n", "5 2\n-1 -2 5 -4 8\n", "4 1\n3 -2 6 0\n", "5 2\n-1 -2 5 -7 8\n", "4 1\n3 -2 1 0\n", "5 2\n0 -2 5 -7 8\n", "4 1\n2 -2 1 0\n", "5 2\n0 -2 1 -7 8\n", "5 2\n0 -2 2 -7 8\n", "5 2\n0 -2 2 -7 14\n", "5 2\n0 -2 4 -7 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given an array a_1, a_2, ..., a_n and an integer k. You are asked to divide this array into k non-empty consecutive subarrays. Every element in the array should be included i...
1194_C. From S To T_18909
You are given three strings s, t and p consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings. During each operation you choose any character from p, erase it from p and insert it into string s (you may insert this character anywhere you want: in the beginning of...
#import sys #input=sys.stdin.readline t=int(input()) for you in range(t): a=input() b=input() c=input() freqa=[0 for i in range(26)] freqb=[0 for i in range(26)] freqc=[0 for i in range(26)] for i in a: freqa[ord(i)-ord('a')]+=1 for i in b: freqb[ord(i)-ord('a')]+=1 f...
{ "input": [ "4\nab\nacxb\ncax\na\naaaa\naaabbcc\na\naaaa\naabbcc\nab\nbaaa\naaaaa\n", "1\naaaaaabbbbbbbbcccccccccccdddd\naaaaabbbbbbccccccccddddddddd\naaaaabbbbbbbbbcccccccccddddd\n", "1\naaaaaabbbbbbbbcccccccccccdddd\naaaaabbbbbbccccccccddddddddd\ndddddcccccccccbbbbbbbbbaaaaa\n", "4\nab\nacxb\ncax\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given three strings s, t and p consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings. During each operation you choos...
1276_B. Two Fairs_18915
There are n cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from 1 to n. Two fairs are currently taking place in Berland — they are held in two different cities a and b (1 ≤ a, b ≤ n; a ...
def main(): t=int(input()) allans=[] for _ in range(t): n,m,a,b=readIntArr() adj=[[] for __ in range(n+1)] for __ in range(m): u,v=readIntArr() adj[u].append(v) adj[v].append(u) def reachableFromAWOPassingB(a,b): s...
{ "input": [ "3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n4 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1...
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 and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are ...
1296_C. Yet Another Walking Robot_18919
There is a robot on a coordinate plane. Initially, the robot is located at the point (0, 0). Its path is described as a string s of length n consisting of characters 'L', 'R', 'U', 'D'. Each of these characters corresponds to some move: * 'L' (left): means that the robot moves from the point (x, y) to the point (x...
t = int(input()) for _ in range(t): n = int(input()) arr = list(input()) curr = [0, 0] visited = {tuple(curr):0} dist = float('inf') le = -1; re = -1 for i in range(n): x, y = curr if arr[i] == 'L': x -= 1 elif arr[i] == 'R': x += 1 eli...
{ "input": [ "4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR\n", "1\n23\nRUURRDDLLUUURRRDDDLLLUD\n", "1\n10\nRULLDRRULD\n", "4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nRDDLL\n", "4\n4\nLRUD\n4\nLURD\n5\nDRURU\n5\nRDDLL\n", "1\n23\nDULLLDDDRRRUUULLDDRRUUR\n", "4\n4\nLDUR\n4\nLURD\n5\nRRUDU\n5\nRDDLL\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a robot on a coordinate plane. Initially, the robot is located at the point (0, 0). Its path is described as a string s of length n consisting of characters 'L', 'R', 'U', 'D...