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
1143_A. The Doors_29737
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house. There are ex...
def the_doors(arr,n): count_1 = 0 count_0 = 0 for i in arr: if i == 0:count_0 += 1 else:count_1 += 1 check_1 = 0 check_0 = 0 for i in range(n): if arr[i] == 0: check_0 += 1 else: check_1 += 1 if count_0 == check_0: retur...
{ "input": [ "4\n1 0 0 1\n", "5\n0 0 1 0 0\n", "3\n0 1 0\n", "2\n0 1\n", "3\n0 1 1\n", "3\n1 1 0\n", "3\n1 0 0\n", "3\n0 0 1\n", "3\n1 0 1\n", "2\n1 0\n", "250\n1 0 1 1 0 1 0 1 1 1 1 1 1 0 0 1 1 1 0 1 0 0 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 0 0 1 1 0 1 1 0 1 1 0...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black b...
1163_B1. Cat Party (Easy Edition)_29741
This problem is same as the next one, but has smaller constraints. Shiro's just moved to the new house. She wants to invite all friends of her to the house so they can play monopoly. However, her house is too small, so she can only invite one friend at a time. For each of the n days since the day Shiro moved to the n...
'''input 5 10 2 5 4 1 ''' n = int(input()) arr = list(map(int,input().split())) count = [0]*10 ans = 1 for i in range(n): count[arr[i]-1]+=1 cp_count = list.copy(count) cp_count.sort() r =0 for j in range(1,10): if cp_count[j]!=cp_count[j-1]: r+=1 if (r==0 and cp_count[0]==1): ans = i+1 elif (r==1): li ...
{ "input": [ "6\n1 1 1 2 2 2\n", "7\n3 2 1 1 4 5 1\n", "1\n10\n", "5\n10 2 5 4 1\n", "13\n1 1 1 2 2 2 3 3 3 4 4 4 5\n", "1\n100000\n", "6\n6 1 2 1 6 2\n", "5\n10 100 20 200 1\n", "10\n30518 30518 30518 30518 30518 30518 30518 30518 30518 30518\n", "10\n30518 96518 74071 59971 5...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This problem is same as the next one, but has smaller constraints. Shiro's just moved to the new house. She wants to invite all friends of her to the house so they can play monopoly....
1183_G. Candy Box (hard version)_29745
This problem is a version of problem D from the same contest with some additional constraints and tasks. There are n candies in a candy box. The type of the i-th candy is a_i (1 ≤ a_i ≤ n). You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type pres...
from collections import defaultdict from sys import stdin, stdout q = int(stdin.readline()) for it in range(q): n = int(stdin.readline()) d = [0]*n f = [0]*n for i in range(n): t, b = map(int, stdin.readline().split()) d[t-1]+=1 if b == 1: f[t-1] += 1 d = [(x, ...
{ "input": [ "3\n8\n1 0\n4 1\n2 0\n4 1\n5 1\n6 1\n3 0\n2 0\n4\n1 1\n1 1\n2 1\n2 1\n9\n2 0\n2 0\n4 1\n4 1\n4 1\n7 0\n7 1\n7 0\n7 1\n", "3\n8\n1 0\n4 1\n2 0\n4 1\n5 1\n6 1\n3 0\n2 0\n4\n1 1\n1 1\n2 1\n2 1\n9\n2 0\n2 0\n4 1\n4 1\n4 1\n7 0\n9 1\n7 0\n7 1\n", "3\n8\n1 0\n4 1\n2 0\n4 1\n5 1\n6 1\n3 0\n2 0\n4\n1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This problem is a version of problem D from the same contest with some additional constraints and tasks. There are n candies in a candy box. The type of the i-th candy is a_i (1 ≤ a_...
1201_B. Zero Array_29749
You are given an array a_1, a_2, …, a_n. In one operation you can choose two elements a_i and a_j (i ≠ j) and decrease each of them by one. You need to check whether it is possible to make all the elements equal to zero or not. Input The first line contains a single integer n (2 ≤ n ≤ 10^5) — the size of the array....
n=int(input()) a=list(map(int, input().split())) if(sum(a)<2*max(a) or sum(a)%2==1): print("NO") else: print("YES")
{ "input": [ "6\n1 2 3 4 5 6\n", "4\n1 1 2 2\n", "3\n10407 5987 4237\n", "8\n3343 33870 9537 1563 709 8515 5451 4713\n", "3\n319728747 773363571 580543238\n", "3\n772674020 797853944 81685387\n", "3\n10225 4237 5987\n", "2\n1 2\n", "2\n999999954 999999992\n", "2\n1 1\n", "6...
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. In one operation you can choose two elements a_i and a_j (i ≠ j) and decrease each of them by one. You need to check whether it is possible ...
1243_B1. Character Swap (Easy Version)_29754
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems. After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first. Ujan has two distinct str...
t=int(input()) for ti in range(t): n=int(input()) lia=[] lib=[] a=list(input()) b=list(input()) ctr=0 for i in range(n): if a[i]!=b[i]: lia.append(a[i]) lib.append(b[i]) ctr+=1 if ctr>2: print("No") break if ctr=...
{ "input": [ "4\n5\nsouse\nhouhe\n3\ncat\ndog\n2\naa\naz\n3\nabc\nbca\n", "10\n11\nartiovnldnp\nartiovsldsp\n2\naa\nzz\n2\naa\nxy\n2\nab\nba\n2\nza\nzz\n3\nabc\nbca\n16\naajjhdsjfdsfkadf\naajjhjsjfdsfkajf\n2\nix\nii\n2\noo\nqo\n2\npp\npa\n", "1\n2\nab\ncc\n", "1\n4\naacd\nbbdc\n", "1\n2\nab\ncd\n"...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems. After struggling and fail...
1284_C. New Year and Permutation_29759
Recall that the permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array). A sequence a is a subsegment of a...
n, m = map(int, input().split()) fac = [1] for i in range(1, n + 1): fac.append(i * fac[i - 1] % m) ans = 0 for i in range(1, n+1): ans += (n - i + 1) * fac[i] * fac[n - i + 1] ans %= m print(ans)
{ "input": [ "2 993244853\n", "2020 437122297\n", "1 993244853\n", "3 993244853\n", "2019 993244853\n", "250000 996140731\n", "244435 994838543\n", "8 848339069\n", "9 298827211\n", "200422 984828937\n", "12 273157301\n", "100000 100000921\n", "14 353847517\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Recall that the permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (...
1303_E. Erase Subsequences_29763
You are given a string s. You can build new string p from s using the following operation no more than two times: 1. choose any subsequence s_{i_1}, s_{i_2}, ..., s_{i_k} where 1 ≤ i_1 < i_2 < ... < i_k ≤ |s|; 2. erase the chosen subsequence from s (s can become empty); 3. concatenate chosen subsequence to th...
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO,IOBase from math import inf,isinf def solve(s,t): if len(t) == 1: if s.count(t[0]): return 'YES' return 'NO' for i in range(1,len(t)): dp = [[-inf]*(i+1) for _ in range(len(s)+...
{ "input": [ "4\nababcd\nabcba\na\nb\ndefi\nfed\nxyz\nx\n", "3\nababc\nabcba\nfeded\ndefed\nababcfeded\nabcdebafed\n", "1\nbbbaaaaabbabaabbbbaabbbbabbaabbaababbbbbbababbababbbaaaaaaabaababbbaababbbbababbbabbbbbabaabbaaaabaa\nbbbababbaabbbbbaabaaabaababaaaabaabbbabbababaaabba\n", "3\nababc\nabcba\nfede...
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. You can build new string p from s using the following operation no more than two times: 1. choose any subsequence s_{i_1}, s_{i_2}, ..., s_{i_k} where 1 ...
1327_F. AND Segments_29767
You are given three integers n, k, m and m conditions (l_1, r_1, x_1), (l_2, r_2, x_2), ..., (l_m, r_m, x_m). Calculate the number of distinct arrays a, consisting of n integers such that: * 0 ≤ a_i < 2^k for each 1 ≤ i ≤ n; * bitwise AND of numbers a[l_i] \& a[l_i + 1] \& ... \& a[r_i] = x_i for each 1 ≤ i ≤ m...
def main(): import sys input = sys.stdin.buffer.readline mod = 998244353 N, K, M = map(int, input().split()) cond = [] for _ in range(M): cond.append(tuple(map(int, input().split()))) ans = 1 for k in range(K): one = [0] * (N+1) zero_cond = [0] * (N+1) fo...
{ "input": [ "5 2 3\n1 3 2\n2 5 0\n3 3 3\n", "4 3 2\n1 3 3\n3 4 6\n", "1 30 2\n1 1 32443264\n1 1 1337\n", "20 10 20\n9 12 48\n13 14 527\n6 6 343\n13 15 5\n12 14 515\n8 11 0\n10 14 0\n6 9 256\n16 16 767\n8 12 0\n12 14 515\n16 17 630\n6 8 324\n15 15 101\n8 9 904\n5 6 85\n19 20 22\n17 17 886\n1 5 0\n18 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given three integers n, k, m and m conditions (l_1, r_1, x_1), (l_2, r_2, x_2), ..., (l_m, r_m, x_m). Calculate the number of distinct arrays a, consisting of n integers such...
1368_F. Lamps on a Circle_29770
This is an interactive problem. John and his imaginary friend play a game. There are n lamps arranged in a circle. Lamps are numbered 1 through n in clockwise order, that is, lamps i and i + 1 are adjacent for any i = 1, …, n - 1, and also lamps n and 1 are adjacent. Initially all lamps are turned off. John and his f...
from sys import stdout, exit from traceback import format_exc def main(): n = int(input()) on = [False] * n def query(ll): res = 0 pvals = [i+1 for i in ll] print(len(ll), ' '.join(map(str,pvals))) stdout.flush() for i in ll: if not on[i]: ...
{ "input": [ "3\n", "4\n\n1", "6 0\n", "7 0\n", "5 0\n", "4 0\n", "3 0\n", "2 0\n", "1 0\n", "8 0\n", "99 0\n", "256 0\n", "66 0\n", "16 0\n", "123 0\n", "143 0\n", "36 0\n", "10 0\n", "256 1\n", "272 0\n", "13 0\n", "143 1\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This is an interactive problem. John and his imaginary friend play a game. There are n lamps arranged in a circle. Lamps are numbered 1 through n in clockwise order, that is, lamps i...
138_A. Literature Lesson_29774
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels. Two lines rhyme if their ...
n,k=list(map(int,input().split())) def z(a,b): global k c=0 d='' for i in range(len(a)-1,-1,-1): d+=a[i] if a[i] in ['a','e','i','o','u']: c+=1 if c==k: break f=c==k c=0 e='' for i in range(len(b)-1,-1,-1): e+=b[i] if b[i] i...
{ "input": [ "1 1\nday\nmay\ngray\nway\n", "2 1\na\na\na\na\na\na\ne\ne\n", "2 1\nday\nmay\nsun\nfun\ntest\nhill\nfest\nthrill\n", "1 1\nday\nmay\nsun\nfun\n", "25 1\nw\ni\nv\nx\nh\ns\nz\ny\no\nn\nh\ni\nf\nf\ny\nr\nb\nu\no\np\nz\nh\nt\no\nw\nx\nh\no\nj\ny\nw\nj\ny\nh\nh\nr\ns\nb\ny\nr\nw\no\nl\nl\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poe...
1454_E. Number of Simple Paths_29780
You are given an undirected graph consisting of n vertices and n edges. It is guaranteed that the given graph is connected (i. e. it is possible to reach any vertex from any other vertex) and there are no self-loops and multiple edges in the graph. Your task is to calculate the number of simple paths of length at leas...
import sys input=sys.stdin.readline from collections import defaultdict,deque t=int(input()) for _ in range(t): n=int(input()) ct=[1]*(n+1) deg=[0]*(n+1) d=defaultdict(set) for _ in range(n): u,v=map(int,input().split()) d[u].add(v) d[v].add(u) deg[u]+=1 deg[v...
{ "input": [ "3\n3\n1 2\n2 3\n1 3\n4\n1 2\n2 3\n3 4\n4 2\n5\n1 2\n2 3\n1 3\n2 5\n4 3\n", "3\n3\n1 2\n2 3\n1 3\n4\n1 4\n2 3\n3 4\n4 2\n5\n1 2\n2 3\n1 3\n2 5\n4 3\n", "3\n3\n1 2\n2 3\n1 3\n4\n1 2\n1 3\n3 4\n4 2\n5\n1 2\n2 3\n1 3\n2 5\n4 3\n", "3\n3\n1 2\n2 3\n1 3\n4\n1 2\n2 3\n3 4\n4 2\n5\n1 2\n2 3\n1 5...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given an undirected graph consisting of n vertices and n edges. It is guaranteed that the given graph is connected (i. e. it is possible to reach any vertex from any other ver...
1478_C. Nezzar and Symmetric Array_29784
Long time ago there was a symmetric array a_1,a_2,…,a_{2n} consisting of 2n distinct integers. Array a_1,a_2,…,a_{2n} is called symmetric if for each integer 1 ≤ i ≤ 2n, there exists an integer 1 ≤ j ≤ 2n such that a_i = -a_j. For each integer 1 ≤ i ≤ 2n, Nezzar wrote down an integer d_i equal to the sum of absolute d...
# ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode...
{ "input": [ "6\n2\n8 12 8 12\n2\n7 7 9 11\n2\n7 11 7 11\n1\n1 1\n4\n40 56 48 40 80 56 80 48\n6\n240 154 210 162 174 154 186 240 174 186 162 210\n", "1\n2\n8 12 12 12\n", "1\n2\n10 12 12 12\n", "6\n2\n3 12 8 12\n2\n7 7 9 11\n2\n7 11 7 11\n1\n1 1\n4\n40 56 48 40 80 56 80 48\n6\n240 154 210 162 174 154 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Long time ago there was a symmetric array a_1,a_2,…,a_{2n} consisting of 2n distinct integers. Array a_1,a_2,…,a_{2n} is called symmetric if for each integer 1 ≤ i ≤ 2n, there exists ...
1505_F. Math_29788
<image> <image> *The two images are equivalent, feel free to use either one. Input The input contains a single integer a (-100 ≤ a ≤ 100). Output Output the result – an integer number. Example Input 1 Output 1
s=int(input()) print(2-s**2)
{ "input": [ "1\n", "0\n", "-1\n", "-2\n", "4\n", "-3\n", "5\n", "-8\n", "-11\n", "-7\n", "-13\n", "-17\n", "-29\n", "-52\n", "-9\n", "-6\n", "-10\n", "-19\n", "-35\n", "-57\n", "-113\n", "-53\n", "-33\n", "-12\n", "-1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: <image> <image> *The two images are equivalent, feel free to use either one. Input The input contains a single integer a (-100 ≤ a ≤ 100). Output Output the result – an integer n...
15_E. Triangles_29793
Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but by a strange, in his opinion, pattern of the forest that has n levels,...
a,b,c,m=1,2,4,10**9+9 n=int(input()) for i in range(1,n//2): c=c*a%m b=(b+c)%m a=(2*a+3)%m print((b*b+1)*2%m)
{ "input": [ "4\n", "2\n", "972408\n", "956022\n", "54\n", "448\n", "68\n", "941322\n", "6\n", "160\n", "908550\n", "635758\n", "966\n", "992164\n", "924936\n", "24\n", "180\n", "1000000\n", "38\n", "10\n", "921566\n", "999998\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get o...
17_B. Hierarchy_29797
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi...
import sys import math import collections import heapq input=sys.stdin.readline n=int(input()) l=[int(i) for i in input().split()] m=int(input()) s=0 d={} for i in range(m): a,b,c=(int(i) for i in input().split()) if(b in d): d[b]=min(d[b],c) else: d[b]=c c1=0 for i in range(1,n+1): if(i...
{ "input": [ "3\n1 2 3\n2\n3 1 2\n3 1 3\n", "4\n7 2 3 1\n4\n1 2 5\n2 4 1\n3 4 1\n1 3 5\n", "2\n5 3\n4\n1 2 0\n1 2 5\n1 2 0\n1 2 7\n", "5\n6 10 7 8 5\n10\n3 1 5\n2 4 1\n2 3 2\n4 5 9\n3 5 0\n4 1 9\n4 5 2\n1 5 8\n2 3 7\n1 5 1\n", "2\n1000000 999999\n1\n1 2 1000000\n", "5\n3 9 2 1 8\n9\n2 5 10\n1 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exa...
202_C. Clear Symmetry_29801
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j. L...
'''input 3 ''' from sys import stdin import math def make_dp(): dp = [0] * 1001 dp[1] = 1 dp[3] = 5 for i in range(5, 100, 2): dp[i] = dp[i - 2] + i + i - 2 return dp # main starts x = int(stdin.readline().strip()) if x == 3: print(5) exit() dp = make_dp() for i in range(1, len(dp)): if x <= dp[i]: pr...
{ "input": [ "4\n", "9\n", "61\n", "13\n", "38\n", "98\n", "84\n", "43\n", "60\n", "53\n", "10\n", "12\n", "7\n", "88\n", "21\n", "8\n", "89\n", "64\n", "97\n", "28\n", "87\n", "14\n", "55\n", "81\n", "76\n", "30\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right ...
227_B. Effective Approach_29805
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ...
def editorial(n, a, m, b): c = [None] * n for i, x in enumerate(a): c[x - 1] = i + 1 vasya = 0 petya = 0 for x in b: i = c[x - 1] vasya += i petya += n - i + 1 return (vasya, petya) if __name__ == '__main__': n = int(input()) a = [int(x) for x in input()...
{ "input": [ "3\n3 1 2\n3\n1 2 3\n", "2\n2 1\n1\n1\n", "2\n1 2\n1\n1\n", "3\n1 2 3\n8\n3 2 1 1 2 3 1 2\n", "4\n1 3 2 4\n4\n3 1 2 3\n", "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2\n", "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1\n", "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5\n", "10\n5 2 10 8 3 1 9 7 6 4...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a...
250_E. Mad Joe_29809
Joe has been hurt on the Internet. Now he is storming around the house, destroying everything in his path. Joe's house has n floors, each floor is a segment of m cells. Each cell either contains nothing (it is an empty cell), or has a brick or a concrete wall (always something one of three). It is believed that each f...
n, m = [int(i) for i in input().split()] current_floor = list(input()) x, t, direction = 0, 0, 1 for i in range(n-1): floor = list(input()) l, r = x, x wall = 0 while True: t += 1 if floor[x] == '.': break if (x + direction == m) or (x + direction < 0) or (current_f...
{ "input": [ "3 5\n..+.#\n#+..+\n+.#+.\n", "4 10\n...+.##+.+\n+#++..+++#\n++.#++++..\n.+##.++#.+\n", "2 2\n..\n++\n", "10 10\n.+++++++++\n+++++++++.\n.+++++++++\n+++++++++.\n.+++++++++\n+++++++++.\n.+++++++++\n+++++++++.\n.+++++++++\n+++++++++.\n", "4 100\n.++++.+++++..+++.++++.+++++++++++.+++++++...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Joe has been hurt on the Internet. Now he is storming around the house, destroying everything in his path. Joe's house has n floors, each floor is a segment of m cells. Each cell eit...
276_A. Lunch Rush_29813
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break. The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch...
n, k = map(int,input().split()) f = t = 0 maxf = -1000000000 for i in range(n): f, t = map(int,input().split()) if t > k: f -= (t - k) if f > maxf: maxf = f print(maxf)
{ "input": [ "2 5\n3 3\n4 5\n", "1 5\n1 7\n", "4 6\n5 8\n3 6\n2 3\n2 2\n", "2 5\n1 7\n1 1000000000\n", "2 3\n1000000000 1\n2 2\n", "4 9\n10 13\n4 18\n13 3\n10 6\n", "1 1\n1000000000 1\n", "1 1\n1000000000 1000000000\n", "1 1\n1 1000000000\n", "2 5\n1 7\n1 0000000000\n", "2 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break. The Rabbits have a list of n r...
299_C. Weird Game_29817
Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves fir...
#!/usr/bin/python3 n = int(input()) s = list(input()) l = list(input()) a = len([_ for _ in zip(s, l) if _ == ('1', '1')]) b = len([_ for _ in zip(s, l) if _ == ('1', '0')]) c = len([_ for _ in zip(s, l) if _ == ('0', '1')]) f = b + (a + 1) // 2 s = c + a // 2 if f > s: print('First') elif f + 1 < s: print('Se...
{ "input": [ "4\n01100000\n10010011\n", "4\n01010110\n00101101\n", "3\n111000\n000111\n", "2\n0111\n0001\n", "3\n110110\n001001\n", "4\n01011011\n10101110\n", "2\n0000\n1110\n", "4\n10110011\n01011111\n", "4\n01011011\n01010010\n", "4\n01010100\n10011111\n", "4\n01111011\n0...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word f...
322_A. Ciel and Dancing_29821
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: * either the boy in the dancing pair must dance for the first time (so...
n, m = map(int, input().split()) print(n + m - 1) for i in range (1, n + 1): print(i, 1) for i in range (1, m): print(1, i + 1)
{ "input": [ "2 1\n", "2 2\n", "4 4\n", "42 17\n", "2 3\n", "12 1\n", "35 55\n", "32 87\n", "20 95\n", "19 93\n", "19 93\n", "1 77\n", "35 21\n", "99 99\n", "24 6\n", "26 75\n", "7 83\n", "7 59\n", "35 55\n", "7 59\n", "35 21\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one ...
441_A. Valera and Antique Items_29833
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if h...
r = lambda: list(map(int, input().split()))[1:] n,c = map(int, input().split()) d = [] for _ in range(n): for i in r(): if i<c: d.append(str(_+1)) break print (len(d)) print (' '.join(d))
{ "input": [ "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n", "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n", "1 1000000\n1 1000000\n", "2 100001\n1 895737\n1 541571\n", "3 999999\n7 1000000 1000000 1000000 999999 1000000 999999 1000000\n6 999999 1000000 999999 1000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the a...
463_B. Caisa and Pylons_29837
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon...
n=int(input()) s=list(map(int,input().split())) m,h,d=0,0,0 for i in range(n): m+=h-s[i] if(m<0): d-=m m=0 h=s[i] print(d)
{ "input": [ "5\n3 4 3 2 4\n", "3\n4 4 4\n", "3\n3 2 1\n", "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269 671 2986 942 758 1146 77 1545 3745 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this ...
487_A. Fight the Monster_29841
A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF). During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases by max(0,...
from math import * #from bisect import * #from collections import * #from random import * #from decimal import *""" #from heapq import * #from random import * import sys input=sys.stdin.readline #sys.setrecursionlimit(3*(10**5)) global flag def inp(): return int(input()) def st(): return input().rstrip('\n') de...
{ "input": [ "100 100 100\n1 1 1\n1 1 1\n", "1 2 1\n1 100 1\n1 100 100\n", "11 82 51\n90 84 72\n98 98 43\n", "100 100 100\n100 100 100\n100 100 100\n", "100 100 1\n100 100 100\n1 100 100\n", "76 63 14\n89 87 35\n20 15 56\n", "72 16 49\n5 21 84\n48 51 88\n", "1 1 1\n1 1 1\n1 1 1\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defe...
535_A. Tavas and Nafas_29847
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. <image> He ate coffee mi...
l=['','-one','-two','-three','-four','-five','-six','-seven','-eight','-nine'] l1=['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen'] l2=['twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety'] l3=['zero','one','two','three','four','five','six','seven','e...
{ "input": [ "6\n", "20\n", "99\n", "27\n", "35\n", "12\n", "56\n", "61\n", "38\n", "24\n", "22\n", "15\n", "55\n", "8\n", "2\n", "72\n", "62\n", "51\n", "7\n", "34\n", "82\n", "49\n", "32\n", "0\n", "19\n", "95\n"...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any dig...
55_B. Smallest number_29851
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them wi...
import math,sys from itertools import permutations from collections import defaultdict,deque import bisect as bi def yes():print('YES') def no():print('NO') #sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w'); def I():return (int(sys.stdin.readline())) def In():return(map(int,sys.stdin.readline().split()...
{ "input": [ "2 2 2 2\n* * +\n", "1 1 1 1\n+ + *\n", "1 2 3 4\n* + +\n", "482 842 982 902\n+ * +\n", "243 386 431 35\n* + *\n", "105 238 316 265\n+ + +\n", "631 149 496 892\n* * +\n", "622 919 896 120\n* * +\n", "7 17 3 25\n+ * +\n", "922 145 883 357\n+ + *\n", "666 884 772...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the ...
629_D. Babaei and Birthday Cake_29859
As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake. Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special ca...
# ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq,bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys import threading from collections import defaultdict threading.stack_size(10**8) mod ...
{ "input": [ "4\n1 1\n9 7\n1 4\n10 7\n", "2\n100 30\n40 10\n", "4\n1 1\n2 2\n3 3\n4 4\n", "15\n36 75\n45 48\n6 2700\n9 1200\n30 108\n18 300\n12 675\n20 243\n5 3888\n4 6075\n60 27\n90 12\n10 972\n180 3\n15 432\n", "4\n2 2\n4 4\n1 1\n3 3\n", "5\n8 3\n6 3\n4 2\n7 3\n6 3\n", "14\n3 9408\n12 58...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake. Simple cake is a cylinder of some radius and height. The v...
653_E. Bear and Forgotten Tree 2_29863
A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear. He once had a tree with n vertices but he lost it. He still remembers something about the lost tree though. You are given m pairs of vertices (a1, b1), (a2, b2), ..., (am, ...
import sys import math from heapq import *; input = sys.stdin.readline from functools import cmp_to_key; def pi(): return(int(input())) def pl(): return(int(input(), 16)) def ti(): return(list(map(int,input().split()))) def ts(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(i...
{ "input": [ "5 4 2\n1 2\n2 3\n4 2\n4 1\n", "6 5 3\n1 2\n1 3\n1 4\n1 5\n1 6\n", "5 4 3\n5 1\n5 3\n3 1\n4 2\n", "4 2 2\n1 2\n1 3\n", "5 6 2\n3 5\n2 1\n2 5\n1 5\n1 3\n2 4\n", "5 6 1\n3 1\n4 5\n3 5\n4 3\n1 2\n2 4\n", "5 4 2\n2 1\n4 1\n4 2\n3 5\n", "5 3 3\n5 4\n2 4\n2 1\n", "2 1 1\n2 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear. He once had a tree with n vertices b...
701_D. As Fast As Possible_29869
On vacations n pupils decided to go on excursion and gather all together. They need to overcome the path with the length l meters. Each of the pupils will go with the speed equal to v1. To get to the excursion quickly, it was decided to rent a bus, which has seats for k people (it means that it can't fit more than k pe...
n, l, v1, v2, k=map(int,input().split()) n=(n+k-1)//k t0=l/v1 t1=l/v2 if n==1: print(t1) else: for k in range(50): t=(t0+t1)/2 d2=v2*t x2=(d2-l)/(n-1)/2 u2=(d2-(n-1)*x2)/n tt=u2/v2+(l-u2)/v1 if tt>t: t1=t else: t0=t print(t)
{ "input": [ "3 6 1 2 1\n", "5 10 1 2 5\n", "1 1000000000 1 2 1\n", "10000 1 999999999 1000000000 1\n", "11 81 31 90 1\n", "1 1 999999999 1000000000 1\n", "10000 1 1 1000000000 10000\n", "10000 1 1 2 1\n", "59 96 75 98 9\n", "8861 990217735 49933 64765 6526\n", "9538 765513...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: On vacations n pupils decided to go on excursion and gather all together. They need to overcome the path with the length l meters. Each of the pupils will go with the speed equal to v...
723_E. One-Way Reform_29873
There are n cities and m two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and there is no road which connects the city with itself. It is possible that there is no way to get from one city to some other city using only these roads. ...
import sys from collections import defaultdict rlines = sys.stdin.readlines() lines = (l.strip() for l in rlines) def eucycle(n,m,adj): dir_edges = [] us = list(adj.keys()) for u in us: while adj[u]: v0 = u v1 = adj[v0].pop() adj[v1].remove(v0) dir_edges.append((v0, v1)) while v1 != u: v0 = ...
{ "input": [ "2\n5 5\n2 1\n4 5\n2 3\n1 3\n3 5\n7 2\n3 7\n4 2\n", "1\n13 9\n13 12\n3 11\n12 10\n12 9\n2 11\n3 8\n1 3\n2 13\n13 11\n", "1\n4 6\n1 3\n4 1\n3 2\n1 2\n4 3\n4 2\n", "1\n200 0\n", "4\n9 17\n3 6\n2 6\n6 9\n4 1\n2 8\n1 9\n7 9\n8 5\n1 7\n4 9\n6 7\n3 4\n9 3\n8 4\n2 1\n3 8\n2 7\n5 6\n2 5\n3 4\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n cities and m two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and there is no road ...
745_D. Hongcow's Game_29877
This is an interactive problem. In the interaction section below you will see the information about flushing the output. In this problem, you will be playing a game with Hongcow. How lucky of you! Hongcow has a hidden n by n matrix M. Let Mi, j denote the entry i-th row and j-th column of the matrix. The rows and col...
import sys n = int(input()) MAX = 2000 * 1000 * 1000 res = [MAX] * n k = 1 while k < n: x = [0] * n output = [] sz = 0 for i in range(0, n, 2 * k): for j in range(0, min(n - i, k)): output.append(i + j + 1) sz += 1 #print(i + j + 1, end = ' ') ...
{ "input": [ "2\n0 0\n0 0", "3\n0 0 0\n2 7 0\n0 0 4\n3 0 8\n0 5 4", "3\n0 3 2\n5 0 7\n4 8 0\n", "2\n0 238487454\n54154238 0\n", "3\n0 0 0\n0 0 0\n0 0 0\n", "2\n0 0\n0 0\n", "3\n0 3 2\n4 0 7\n4 8 0\n", "2\n0 389450013\n54154238 0\n", "2\n0 389450013\n54154238 -1\n", "3\n0 0 0\n0...
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. In the interaction section below you will see the information about flushing the output. In this problem, you will be playing a game with Hongcow. How...
768_F. Barrels and boxes_29881
Tarly has two different type of items, food boxes and wine barrels. There are f food boxes and w wine barrels. Tarly stores them in various stacks and each stack can consist of either food boxes or wine barrels but not both. The stacks are placed in a line such that no two stacks of food boxes are together and no two s...
import sys def factorial(): global mod fac = [1] * int(3e5 + 1) for i in range(1, int(3e5)): fac[i] = i*fac[i-1] % mod return fac def inverse(x): global mod return pow(x, mod-2, mod) def C(n, r): global fac if n < 0 or n < r: return 0 return fac[n]*inverse(fac[r])*inv...
{ "input": [ "1 1 1\n", "1 2 1\n", "1000 1000 1000\n", "4346 1611 880\n", "100 100000 100000\n", "2626 6150 9532\n", "2390 4197 2086\n", "4138 4245 30\n", "3414 2092 6298\n", "40000 40000 4000\n", "20 12 32\n", "6232 1674 3837\n", "0 1 1\n", "100000 100000 10\n"...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Tarly has two different type of items, food boxes and wine barrels. There are f food boxes and w wine barrels. Tarly stores them in various stacks and each stack can consist of either...
792_E. Colored Balls_29885
There are n boxes with colored balls on the table. Colors are numbered from 1 to n. i-th box contains ai balls, all of which have color i. You have to write a program that will divide all balls into sets such that: * each ball belongs to exactly one of the sets, * there are no empty sets, * there is no set con...
import time import sys from math import sqrt n = int(input()) a = list(map(int, input().split())) sq = int(sqrt(a[0]))+2 s = set() for box in range(1, sq): if a[0] % box == 0: s.add(a[0] // box) s.add(a[0] // box - 1) else: s.add(a[0] // box) for balls in range(1, sq): if a[0] % ...
{ "input": [ "2\n2 7\n", "3\n4 7 8\n", "1\n1000000000\n", "2\n948507270 461613425\n", "200\n1 2 4 10 5 8 1 10 9 10 1 9 5 5 3 10 4 7 7 1 5 10 1 6 7 3 9 3 5 8 8 9 7 3 1 5 6 7 3 3 1 4 9 2 8 7 2 10 2 1 10 9 6 1 9 5 3 5 9 3 3 2 4 9 5 9 4 8 5 6 10 1 3 10 8 6 10 10 4 6 8 4 10 7 5 2 6 6 8 8 8 10 3 2 4 5 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n boxes with colored balls on the table. Colors are numbered from 1 to n. i-th box contains ai balls, all of which have color i. You have to write a program that will divide...
813_B. The Golden Age_29889
Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 20 + 31, 17 = 23 + 32 = 24 + 30) and year 18 isn't unlucky as there is no such representation for it. Su...
x, y, l, r = map(int, input().split()) def gen_list(var): cur = 1 while cur <= r: yield cur cur *= var x_list = list(gen_list(x)) # print(x_list) y_list = list(gen_list(y)) # print(y_list) numbers = [l-1, r+1] for _x in x_list: for _y in y_list: n = _x + _y if n < l or n ...
{ "input": [ "3 5 10 22\n", "2 3 1 10\n", "2 3 3 5\n", "2 3 1 1000000\n", "459168731438725410 459955118458373596 410157890472128901 669197645706452507\n", "97958277744315833 443452631396066615 33878596673318768 306383421710156519\n", "370083000139673112 230227213530985315 47675024162373731...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the ...
839_A. Arya and Bran_29893
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her cand...
n, k = map(int, input().split()) a = list(map(int, input().split())) aria = 0 bran = 0 for i in range(n): aria += a[i] if aria > 8: bran += 8 aria -= 8 else: bran += aria aria = 0 if bran >= k: print(i + 1) break if bran < k: print(-1)
{ "input": [ "1 9\n10\n", "2 3\n1 2\n", "3 17\n10 10 10\n", "2 8\n7 8\n", "37 30\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "3 10\n10 1 1\n", "100 189\n15 14 32 65 28 96 33 93 48 28 57 20 32 20 90 42 57 53 18 58 94 21 27 29 37 22 94 45 67 60 83 23 20 23 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are n days...
859_D. Third Month Insanity_29897
The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2N teams participating in the tournament, numbered from 1 to 2N. The tournament lasts N rounds, with each round eliminating half the teams. The first round consists of 2N - ...
n = int(input()) # Using the same index I would for a tree m = 2**n points = [0]*(2*m) points[1] = 2**(n-1) for i in range(1,m): x = points[i]//2 points[2*i] = x points[2*i+1] = x P = [[int(x)/100.0 for x in input().split()] for _ in range(m)] state = [[0.0]*64 for _ in range(2*m)] for i in range(m): ...
{ "input": [ "3\n0 0 100 0 100 0 0 0\n100 0 100 0 0 0 100 100\n0 0 0 100 100 0 0 0\n100 100 0 0 0 0 100 100\n0 100 0 100 0 0 100 0\n100 100 100 100 100 0 0 0\n100 0 100 0 0 100 0 0\n100 0 100 0 100 100 100 0\n", "2\n0 21 41 26\n79 0 97 33\n59 3 0 91\n74 67 9 0\n", "2\n0 40 100 100\n60 0 40 40\n0 60 0 45\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2N teams participating in the tourna...
884_C. Bertown Subway_29901
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are n stations in the subway. It was built according to the Bertown Transport Law: 1. For each station i there exists exactly one train that goes from this station. I...
input() l = [[int(x)-1,False] for x in input().split()] loop = [] for begin in l: if begin[1]: continue count = 0; nextI = begin[0]; while not l[nextI][1]: l[nextI][1]=True nextI = l[nextI][0] count += 1 loop.append(count) s = sorted(loop,reverse=True) total = sum(map...
{ "input": [ "3\n2 1 3\n", "5\n1 5 4 3 2\n", "10\n5 1 6 2 8 3 4 10 9 7\n", "3\n1 2 3\n", "20\n1 6 15 9 18 17 7 8 3 19 2 13 11 12 14 4 5 20 16 10\n", "2\n1 2\n", "1\n1\n", "6\n5 3 6 1 4 2\n", "5\n1 4 2 3 5\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are n stations in the subway. It...
908_E. New Year and Entity Enumeration_29905
You are given an integer m. Let M = 2m - 1. You are also given a set of n integers denoted as the set T. The integers will be provided in base 2 as n binary strings of length m. A set of integers S is called "good" if the following hold. 1. If <image>, then <image>. 2. If <image>, then <image> 3. <image> ...
from collections import defaultdict as di MOD = int(1e9+7) bells = di(int) bells[0,0] = 1 K=1000 for j in range(1,K): bells[0,j] = bells[j-1,j-1] for i in range(j): bells[i+1,j] = (bells[i,j] + bells[i,j-1])%MOD def bellman(n): return bells[n-1,n-1] m,n = [int(x) for x in input().split()] Tli...
{ "input": [ "5 3\n11010\n00101\n11000\n", "30 2\n010101010101010010101010101010\n110110110110110011011011011011\n", "30 10\n001000000011000111000010010000\n000001100001010000000000000100\n000110100010100000000000101000\n110000010000000001000000000000\n100001000000000010010101000101\n001001000000000100000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given an integer m. Let M = 2m - 1. You are also given a set of n integers denoted as the set T. The integers will be provided in base 2 as n binary strings of length m. A ...
92_D. Queue_29909
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai. The i-th walrus becomes displeased if there's a younger walrus stan...
from bisect import bisect_left n = int(input()) a = list(map(int, input().split())) b = [0] * n for i in range(n - 1, -1, -1): b[i] = bisect_left(a, a[i], i + 1, len(a)) - i - 2 a[i] = min(a[i + 1], a[i]) if i != n - 1 else a[i] print (*b) # Made By Mostafa_Khaled
{ "input": [ "6\n10 8 5 3 50 45\n", "7\n10 4 6 3 2 8 15\n", "5\n10 3 1 10 11\n", "15\n18 6 18 21 14 20 13 9 18 20 28 13 19 25 21\n", "2\n1000000000 1\n", "10\n15 21 17 22 27 21 31 26 32 30\n", "13\n16 14 12 9 11 28 30 21 35 30 32 31 43\n", "13\n18 9 8 9 23 20 18 18 33 25 31 37 36\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at ...
958_B2. Maximum Control (medium)_29912
The Resistance is trying to take control over as many planets of a particular solar system as possible. Princess Heidi is in charge of the fleet, and she must send ships to some planets in order to maximize the number of controlled planets. The Galaxy contains N planets, connected by bidirectional hyperspace tunnels i...
from sys import stdin from collections import defaultdict import heapq n = int(stdin.readline()) a = [[] for _ in range(n)] for _ in range(n-1): e = stdin.readline().split(' ') u, v = int(e[0]), int(e[1]) a[u-1].append(v-1) a[v-1].append(u-1) leaves = [i for i in range(n) if len(a[i]) == 1] def dfs...
{ "input": [ "3\n1 2\n2 3\n", "4\n1 2\n3 2\n4 2\n", "19\n2 19\n7 15\n8 10\n16 1\n12 5\n11 5\n6 18\n12 14\n14 15\n2 6\n9 14\n4 17\n16 10\n4 2\n7 18\n3 2\n9 13\n11 10\n", "24\n19 14\n8 15\n13 4\n18 16\n1 17\n10 3\n22 21\n10 14\n6 11\n9 12\n15 22\n11 3\n21 7\n2 12\n7 4\n4 19\n16 9\n24 17\n5 15\n8 2\n23 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The Resistance is trying to take control over as many planets of a particular solar system as possible. Princess Heidi is in charge of the fleet, and she must send ships to some plane...
p02567 AtCoder Library Practice Contest - Segment Tree_29926
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types. The type of i-th query is represented by T_i. * T_i=1: You are given two integers X_i,V_i. Replace the value of A_{X_i} with V_i. * T_i=2: You are given two integers L_i,R_i. Calculate the maximum value among A_{L_i},...
class segtree: ## define what you want to do ,(min, max) sta = -1 func = max def __init__(self,n): self.n = n self.size = 1 << n.bit_length() self.tree = [self.sta]*(2*self.size) def build(self, list): for i,x in enumerate(list,self.size): self.tree[i] =...
{ "input": [ "5 5\n1 2 3 2 1\n2 1 5\n3 2 3\n1 3 1\n2 2 4\n3 1 3", "5 5\n1 2 3 2 1\n2 1 5\n3 2 3\n1 3 1\n2 2 4\n3 1 0", "5 3\n1 2 3 2 1\n2 1 5\n3 2 3\n1 3 1\n2 2 4\n3 1 0", "5 1\n1 2 3 2 1\n2 0 5\n3 2 3\n1 1 2\n2 2 4\n3 1 0", "5 5\n1 2 1 2 1\n2 1 5\n3 2 3\n1 3 1\n2 2 4\n3 1 0", "8 3\n1 2 3 2 1\...
5ATCODER
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_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types. The type of i-th query is represented by T_i. * T_i=1: You are given two integer...
p02698 AtCoder Beginner Contest 165 - LIS on Tree_29930
We have a tree with N vertices, whose i-th edge connects Vertex u_i and Vertex v_i. Vertex i has an integer a_i written on it. For every integer k from 1 through N, solve the following problem: * We will make a sequence by lining up the integers written on the vertices along the shortest path from Vertex 1 to Vertex k...
from bisect import bisect_left n = int(input()) A = [0] + list(map(int, input().split())) graph = [[] for _ in range(n + 1)] for _ in range(n - 1): u, v = map(int, input().split()) graph[v].append(u) graph[u].append(v) start = 1 stack = [1] par = [-1] * (n + 1) ans = [0] * (n + 1) used = [False] * (n + 1...
{ "input": [ "10\n1 2 5 3 4 6 7 3 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10", "10\n1 2 5 3 4 6 7 6 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10", "10\n1 2 5 2 7 6 7 3 0 4\n1 2\n2 3\n3 4\n4 5\n2 6\n6 7\n1 8\n8 9\n9 10", "10\n0 2 5 2 7 6 7 3 0 4\n1 3\n2 3\n3 4\n4 5\n2 6\n6 7\n1 8\n8 9\n9 10...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We have a tree with N vertices, whose i-th edge connects Vertex u_i and Vertex v_i. Vertex i has an integer a_i written on it. For every integer k from 1 through N, solve the followin...
p02964 AtCoder Grand Contest 036 - Do Not Duplicate_29936
We have a sequence of N \times K integers: X=(X_0,X_1,\cdots,X_{N \times K-1}). Its elements are represented by another sequence of N integers: A=(A_0,A_1,\cdots,A_{N-1}). For each pair i, j (0 \leq i \leq K-1,\ 0 \leq j \leq N-1), X_{i \times N + j}=A_j holds. Snuke has an integer sequence s, which is initially empty...
from bisect import bisect_right from collections import defaultdict N, K = map(int, input().split()) As = list(map(int, input().split())) indices_of_elem = defaultdict(list) for i, A in enumerate(As): indices_of_elem[A].append(i) empty_index = [0] while True: cur_index = empty_index[-1] look_for_elem = A...
{ "input": [ "11 97\n3 1 4 1 5 9 2 6 5 3 5", "5 10\n1 2 3 2 3", "6 1000000000000\n1 1 2 2 3 3", "3 2\n1 2 3", "5 10\n1 3 3 2 3", "6 1000000000000\n1 2 2 2 3 3", "6 1000000000000\n1 2 2 4 3 3", "11 97\n3 2 4 1 5 9 2 6 5 3 5", "6 1000000000000\n1 1 2 4 3 3", "11 97\n0 2 4 1 5 9 2...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We have a sequence of N \times K integers: X=(X_0,X_1,\cdots,X_{N \times K-1}). Its elements are represented by another sequence of N integers: A=(A_0,A_1,\cdots,A_{N-1}). For each pa...
p03099 AtCoder Grand Contest 031 - Snuke the Phantom Thief_29939
A museum exhibits N jewels, Jewel 1, 2, ..., N. The coordinates of Jewel i are (x_i, y_i) (the museum can be regarded as a two-dimensional plane), and the value of that jewel is v_i. Snuke the thief will steal some of these jewels. There are M conditions, Condition 1, 2, ..., M, that must be met when stealing jewels,...
import sys input=sys.stdin.readline sys.setrecursionlimit(10**9) from bisect import bisect_left,bisect_right class MinCostFlow: def __init__(self,n): self.n=n self.edges=[[] for i in range(n)] def add_edge(self,fr,to,cap,cost): self.edges[fr].append([to,cap,cost,len(self.edges[to])]) ...
{ "input": [ "10\n66 47 71040136000\n65 77 74799603000\n80 53 91192869000\n24 34 24931901000\n91 78 49867703000\n68 71 46108236000\n46 73 74799603000\n56 63 93122668000\n32 51 71030136000\n51 26 70912345000\n21\nL 51 1\nL 7 0\nU 47 4\nR 92 0\nR 91 1\nD 53 2\nR 65 3\nD 13 0\nU 63 3\nL 68 3\nD 47 1\nL 91 5\nR 32 4\...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A museum exhibits N jewels, Jewel 1, 2, ..., N. The coordinates of Jewel i are (x_i, y_i) (the museum can be regarded as a two-dimensional plane), and the value of that jewel is v_i. ...
p03245 AtCoder Beginner Contest 111 - Robot Arms_29942
Snuke is introducing a robot arm with the following properties to his factory: * The robot arm consists of m sections and m+1 joints. The sections are numbered 1, 2, ..., m, and the joints are numbered 0, 1, ..., m. Section i connects Joint i-1 and Joint i. The length of Section i is d_i. * For each section, its mode ...
N = int(input()) point = [tuple(map(int, input().split())) for i in range(N)] point_farthest = max(point, key=lambda p: abs(p[0]) + abs(p[1])) mod = sum(point_farthest) % 2 D = [1, 1] if mod == 0 else [1] while sum(D) < abs(point_farthest[0]) + abs(point_farthest[1]): D.append(D[-1] * 2) D.reverse() W = [] for x, y...
{ "input": [ "2\n1 1\n1 1", "5\n0 0\n1 0\n2 0\n3 0\n4 0", "3\n-7 -3\n7 3\n-3 -7", "3\n-1 0\n0 3\n2 -1", "2\n2 1\n1 1", "2\n2 1\n1 0", "3\n-8 -4\n7 3\n-3 -7", "3\n-8 -4\n13 3\n-3 -7", "3\n0 0\n0 0\n2 0", "2\n2 2\n1 -1", "3\n0 0\n0 0\n4 0", "2\n2 1\n2 -1", "3\n1 -1\n0...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Snuke is introducing a robot arm with the following properties to his factory: * The robot arm consists of m sections and m+1 joints. The sections are numbered 1, 2, ..., m, and the ...
p03563 AtCoder Beginner Contest 076 - Rating Goal_29949
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the rating of the user (not necessarily an integer) changes according to the performance of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. ...
r=float(input()) g=float(input()) print(int(2*g-r))
{ "input": [ "4500\n0", "2002\n2017", "4500\n-1", "2002\n1006", "4500\n-2", "2002\n416", "4500\n1", "2002\n468", "4500\n2", "2002\n87", "4500\n-4", "2002\n33", "4500\n-8", "2002\n2", "4500\n-15", "2002\n3", "4500\n-14", "2002\n0", "4500\n-27"...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the rating of the user (not necessarily an integer) changes according to the performa...
p03718 AtCoder Regular Contest 074 - Lotus Leaves_29953
There is a pond with a rectangular shape. The pond is divided into a grid with H rows and W columns of squares. We will denote the square at the i-th row from the top and j-th column from the left by (i,\ j). Some of the squares in the pond contains a lotus leaf floating on the water. On one of those leaves, S, there ...
""" https://atcoder.jp/contests/arc074/tasks/arc074_d 適当に最小カットを求めればいい →縦横を別ノードで持っておいてつなぐ 0~99 列 100~199 横 200 = start 201 = goal """ from collections import defaultdict from collections import deque def Ford_Fulkerson_Func(s,g,lines,cost): N = len(cost) ans = 0 queue = deque([ [s,float("inf")] ]) ...
{ "input": [ "4 3\n.S.\n.o.\n.o.\n.T.", "3 4\nS...\n.oo.\n...T", "3 3\nS.o\n.o.\no.T", "10 10\n.o...o..o.\n....o.....\n....oo.oo.\n..oooo..o.\n....oo....\n..o..o....\no..o....So\no....T....\n....o.....\n........oo", "2 3\nS.o\n.o.\no.T", "4 3\n.S.\no..\n.o.\n.T.", "9 10\n.o...o..o.\n....o....
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a pond with a rectangular shape. The pond is divided into a grid with H rows and W columns of squares. We will denote the square at the i-th row from the top and j-th column ...
p03878 CODE FESTIVAL 2016 Grand Final(Parallel) - 1D Matching_29957
There are N computers and N sockets in a one-dimensional world. The coordinate of the i-th computer is a_i, and the coordinate of the i-th socket is b_i. It is guaranteed that these 2N coordinates are pairwise distinct. Snuke wants to connect each computer to a socket using a cable. Each socket can be connected to onl...
mod = 10 ** 9 + 7 N, *E = map(int, open(0).read().split()) E = sorted((e, 2 * (i < N) - 1) for i, e in enumerate(E)) res = 1 cnt = 0 for _, delta in E: if cnt * delta < 0: res *= abs(cnt) res %= mod cnt += delta print(res)
{ "input": [ "2\n0\n10\n20\n30", "3\n3\n10\n8\n7\n12\n5", "2\n0\n10\n20\n34", "3\n3\n10\n8\n7\n0\n10", "3\n3\n10\n8\n7\n0\n0", "3\n3\n10\n8\n7\n2\n5", "2\n0\n10\n20\n68", "3\n3\n10\n8\n7\n1\n5", "2\n1\n10\n20\n68", "3\n3\n10\n8\n7\n0\n5", "2\n0\n10\n20\n135", "2\n0\n10\...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N computers and N sockets in a one-dimensional world. The coordinate of the i-th computer is a_i, and the coordinate of the i-th socket is b_i. It is guaranteed that these 2...
p04039 AtCoder Regular Contest 058 - Iroha's Obsession_29961
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very ...
n, k = map(int, input().split()) checker = list(map(str, input().split())) cont = True while cont: keep = True for nn in str(n): if nn in checker: keep = False break if keep: break n += 1 print(n)
{ "input": [ "1000 8\n1 3 4 5 6 7 8 9", "9999 1\n0", "67 1\n0", "34 1\n0", "3 1\n0", "6 1\n0", "10 1\n0", "5 1\n0", "39 1\n0", "10 1\n1", "4 1\n1", "56 1\n0", "12 1\n0", "8 1\n0", "2 1\n0", "0 1\n-1", "1001 8\n1 3 4 5 6 7 8 9", "9999 1\n-1", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of ...
p00120 Patisserie_29965
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box. The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes...
from collections import deque def calcwidth(cks): if len(cks) == 1: return cks[0]*2 width = cks[0] + cks[-1] for ck1,ck2 in zip(cks[:-1],cks[1:]): width += ((ck1+ck2)**2-(ck1-ck2)**2)**0.5 return width while True: try: W, *rs = list(map(float,input().split())) except: break rs = de...
{ "input": [ "30 4 5 6\n30 5 5 5\n50 3 3 3 10 10\n49 3 3 3 10 10", "30 4 5 6\n8 5 5 5\n50 3 3 3 10 10\n49 3 3 3 10 10", "30 3 5 6\n6 5 5 5\n50 3 3 3 13 10\n49 3 3 3 10 10", "3 3 5 6\n5 5 5 5\n37 3 3 3 4 10\n4 1 3 3 10 10", "3 3 5 2\n5 10 5 5\n37 3 3 3 4 3\n4 1 3 3 10 10", "30 4 5 6\n30 5 5 5\n...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box. The roll cake is so soft that it will collapse if another roll cake i...
p00253 Kitchen Garden_29969
I decided to plant vegetables in the vegetable garden. There were n seeds, so I sown n seeds one by one a day over n days. All seeds sprout and grow quickly. I can't wait for the harvest time. One day, when I was watering the seedlings as usual, I noticed something strange. There should be n vegetable seedlings, but o...
from sys import exit while(True): N = int(input()) # print(N) if N == 0: break h = list(map(int, input().split())) for i in range(N+1): targ = h[:i] + h[i+1:] diff = targ[1] - targ[0] OK = True for j in range(1, N): if diff != targ[j] - targ[j-1]: ...
{ "input": [ "5\n1 2 3 6 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 12\n0", "5\n1 2 3 6 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 6\n0", "5\n1 2 3 2 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 6\n0", "5\n1 2 3 2 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 7\n0", "5\n1 2 3 6 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 8\n0",...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: I decided to plant vegetables in the vegetable garden. There were n seeds, so I sown n seeds one by one a day over n days. All seeds sprout and grow quickly. I can't wait for the harv...
p00439 Maximum Sum_29973
problem Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1). input The input consists of multiple datasets. Each dataset is given in the f...
while True: n , k = map(int,input().split()) if (n,k) == (0,0): break a = [int(input()) for _ in range(n)] s = sum(a[0:k]) l = [s] for i in range(k,n): s = s + a[i] - a[i-k] l.append(s) print(max(l))
{ "input": [ "5 3\n2\n5\n-4\n10\n3\n0 0", "5 3\n2\n5\n-4\n8\n3\n0 0", "5 3\n2\n5\n-4\n12\n3\n0 0", "5 3\n2\n5\n-4\n14\n3\n0 0", "5 3\n2\n9\n-4\n14\n1\n0 0", "5 3\n1\n9\n-4\n2\n1\n0 0", "5 3\n2\n8\n-4\n12\n3\n0 0", "5 1\n2\n9\n-4\n14\n1\n0 0", "5 3\n1\n9\n-4\n13\n1\n0 0", "5 3\n...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: problem Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the m...
p00630 CamelCase_29977
When naming identifiers (variables and functions) in programming, compound words that concatenate words are used. However, if you concatenate them as they are, you will not be able to understand the word breaks, so in general, select and apply the one that is unified from the following naming conventions: * Set to Upp...
while True: name,typ = input().split() if typ=="X": break ans = [] if "_" in name: ans = name.split("_") else: j = 0 for i in range(1,len(name)): if name[i].isupper(): ans.append(name[j:i]) j = i ans.append(name[j:]) ...
{ "input": [ "get_user_name L\ngetUserName U\nGetUserName D\nEndOfInput X", "get_user_name L\ngetUserOame U\nGetUserName D\nEndOfInput X", "get_user_name L\ngetUserName U\nGrtUseeName D\nEndOfInput X", "get_user_nbme L\ngetUserOame U\nGetUserName D\nEndOfInput X", "embn_resu_teg L\ngetUserOame U\n...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: When naming identifiers (variables and functions) in programming, compound words that concatenate words are used. However, if you concatenate them as they are, you will not be able to...
p00774 Chain Disappearance Puzzle_29981
Chain Disappearance Puzzle We are playing a puzzle. An upright board with H rows by 5 columns of cells, as shown in the figure below, is used in this puzzle. A stone engraved with a digit, one of 1 through 9, is placed in each of the cells. When three or more stones in horizontally adjacent cells are engraved with the...
from functools import lru_cache def DEBUG(*args): pass # print('@', *args) @lru_cache(maxsize=None) def pat(s, n): return ' '.join([s] * n) DEBUG(pat('1', 3)) def removeAll(xs, s): while s in xs: xs.remove(s) xs.append('#') return xs def lmap(f, s): return list(map(f, s)) digits ...
{ "input": [ "1\n6 9 9 9 9\n5\n5 9 5 5 9\n5 5 6 9 9\n4 6 3 6 9\n3 3 2 9 9\n2 2 1 1 1\n10\n3 5 6 5 6\n2 2 2 8 3\n6 2 5 9 2\n7 7 7 6 1\n4 6 6 4 9\n8 9 1 1 8\n5 6 1 8 1\n6 8 2 1 2\n9 6 3 3 5\n5 3 8 8 8\n5\n1 2 3 4 5\n6 7 8 9 1\n2 3 4 5 6\n7 8 9 1 2\n3 4 5 6 7\n3\n2 2 8 7 4\n6 5 7 7 7\n8 8 9 9 9\n0", "1\n6 9 9 9 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Chain Disappearance Puzzle We are playing a puzzle. An upright board with H rows by 5 columns of cells, as shown in the figure below, is used in this puzzle. A stone engraved with a ...
p00905 Stylish_29984
Stylish is a programming language whose syntax comprises names, that are sequences of Latin alphabet letters, three types of grouping symbols, periods ('.'), and newlines. Grouping symbols, namely round brackets ('(' and ')'), curly brackets ('{' and '}'), and square brackets ('[' and ']'), must match and be nested pro...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(0,-1),(1,0),(0,1),(-1,0)] ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return [int(x) for x in sys.stdin....
{ "input": [ "5 4\n(Follow.my.style\n.........starting.from.round.brackets)\n{then.curly.brackets\n.....[.and.finally\n.......square.brackets.]}\n(Thank.you\n{for.showing.me\n[all\nthe.secrets]})\n4 2\n(This.time.I.will.show.you\n.........(how.to.use.round.brackets)\n.........[but.not.about.square.brackets]\n.......
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Stylish is a programming language whose syntax comprises names, that are sequences of Latin alphabet letters, three types of grouping symbols, periods ('.'), and newlines. Grouping sy...
p01172 Headstrong Student_29989
You are a teacher at a cram school for elementary school pupils. One day, you showed your students how to calculate division of fraction in a class of mathematics. Your lesson was kind and fluent, and it seemed everything was going so well - except for one thing. After some experiences, a student Max got so curious ab...
def gcd(a,b): while b:a,b=b,a%b return a def f(n,m): if m==1:return 0 x=1 for i in range(m): x=(x*n)%m if x==1:return i+1 while 1: a,b=map(int,input().split()) if a==0:break c=gcd(a,b) a//=c;b//=c cnt=0;d=gcd(b,10) while d!=1: b//=d c...
{ "input": [ "1 3\n1 6\n3 5\n2 200\n25 99\n0 0", "2 3\n1 6\n3 5\n2 200\n25 99\n0 0", "2 6\n1 5\n3 5\n2 200\n25 99\n0 0", "1 6\n1 5\n3 5\n2 200\n34 99\n0 0", "1 6\n1 5\n3 9\n2 200\n34 99\n0 0", "1 6\n1 8\n3 9\n2 200\n34 99\n0 0", "1 6\n1 8\n3 9\n2 200\n34 62\n0 0", "2 6\n1 8\n3 9\n2 200...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are a teacher at a cram school for elementary school pupils. One day, you showed your students how to calculate division of fraction in a class of mathematics. Your lesson was ki...
p01308 Angel Stairs_29992
An angel lives in the clouds above the city where Natsume lives. The angel, like Natsume, loves cats and often comes down to the ground to play with cats. To get down to the ground, the angel made a long, long staircase leading from the clouds to the ground. However, the angel thought that it would be boring to just go...
dic = {"C":0, "C#":1, "D":2, "D#":3, "E":4, "F":5, "F#":6, "G":7, "G#":8, "A":9, "A#":10, "B":11} t = int(input()) for _ in range(t): n, m = map(int, input().split()) t_lst = [-100] + list(map(lambda x:dic[x],input().split())) s_lst = list(map(lambda x:dic[x],input().split())) s_lst.reverse() ...
{ "input": [ "4\n6 4\nC E D# F G A\nC E F G\n6 4\nC E D# F G A\nC D# F G\n3 6\nC D D\nD# B D B D# C#\n8 8\nC B B B B B F F\nC B B B B B B B", "4\n6 4\nC E D# E G A\nC E F G\n6 4\nC E D# F G A\nC D# F G\n3 6\nC D D\nD# B D B D# C#\n8 8\nC B B B B B F F\nC B B B B B B B", "4\n6 4\nC E D# G G A\nC E F G\n6 4...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: An angel lives in the clouds above the city where Natsume lives. The angel, like Natsume, loves cats and often comes down to the ground to play with cats. To get down to the ground, t...
p01789 Unfair Game_29999
Example Input 3 5 4 3 6 12 Output Hanako
import sys readline = sys.stdin.readline write = sys.stdout.write def check(N, A, B, S): K = min(A, B) g = 0 for s in S: g ^= s % (K+1) if A == B: return g != 0 if A > B: if g != 0: return 1 for s in S: if s > B: return 1 ...
{ "input": [ "3 5 4\n3\n6\n12", "3 5 4\n3\n6\n3", "3 5 4\n1\n2\n3", "3 5 5\n3\n6\n12", "3 5 4\n3\n4\n3", "3 5 5\n3\n6\n4", "3 5 4\n3\n2\n3", "3 8 5\n3\n6\n4", "3 5 4\n6\n2\n3", "3 8 5\n3\n6\n8", "3 1 5\n3\n6\n8", "3 5 4\n1\n1\n3", "3 1 5\n3\n6\n9", "3 4 4\n1\n1\...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Example Input 3 5 4 3 6 12 Output Hanako ### Input: 3 5 4 3 6 12 ### Output: Hanako ### Input: 3 5 4 3 6 3 ### Output: Hanako ### Code: import sys readline = sys.stdin.readli...
p01924 Coastline_30002
coastline Waves rush to the beach every second. There is data that observes and records how many meters the wave rushed beyond the reference point P every second for only T seconds. The data consists of T integers x1, ..., xT, and for each i (1 ≤ i ≤ T), a wave from point P to the point exactly xi m rushes in i second...
while True: t,d,l=map(int,input().split()) if t==0: break ls=[] for i in range(t): ls.append(int(input())) ans=0 r=0 for j in range(t): if ls[j]>=l: ans+=1 if r<d: r=d-1 else: if r>0: ...
{ "input": [ "5 2 3\n3\n5\n1\n2\n3\n3 100 100\n3\n3\n4\n20 3 8\n3\n2\n6\n1\n9\n1\n8\n4\n2\n2\n8\n1\n8\n8\n2\n5\n3\n4\n3\n8\n7 2 2\n0\n2\n5\n2\n5\n2\n1\n0 0 0", "5 2 3\n3\n5\n1\n2\n3\n3 100 100\n3\n3\n4\n20 3 8\n3\n2\n6\n1\n9\n1\n8\n4\n2\n2\n8\n1\n8\n8\n2\n6\n3\n4\n3\n8\n7 2 2\n0\n2\n5\n2\n5\n2\n1\n0 0 0", ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: coastline Waves rush to the beach every second. There is data that observes and records how many meters the wave rushed beyond the reference point P every second for only T seconds. ...
p02062 Short Circuit Evaluation_30005
C: Short-circuit evaluation problem Naodai-kun and Hokkaido University-kun are playing games. Hokkaido University first generates the following logical formula represented by BNF. <formula> :: = <or-expr> <or-expr> :: = <and-expr> | <or-expr> "|" <and-expr> <and-expr> :: = <term> | <and-expr> "&" <term> <term> :: =...
# from inspect import currentframe # from sys import exit, stderr # debug function # def debug(*args): # names = {id(v):k for k,v in currentframe().f_back.f_locals.items()} # print(', '.join(names.get(id(arg),'???') + str(id(arg)) +' = '+repr(arg) for arg in args), file=stderr) src = list(str(input())) toke...
{ "input": [ "?&?|?&?|?&?", "?&?&?|?|?&?", "?|?&?|?&?&?", "?&?&?|?&?|?", "?&?|?|?&?&?", "?|?|?&?&?&?", "?&?&?&?|?|?", "?|?&?&?|?&?", "?&?|?&?&?|?", "?|?|?&?&??&", "?|?&?&?&?|?", "?|?&?|?&??&", "?&?|?|?&??&", "?|?|?&??&?&", "?|?|?&?&?&?", "?&?&?&?|?|?", ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: C: Short-circuit evaluation problem Naodai-kun and Hokkaido University-kun are playing games. Hokkaido University first generates the following logical formula represented by BNF. ...
p02204 Contest T-shirts_30008
Contest T-shirts Segtree has $ M $ contest T-shirts. He decided to spend $ N $ days on the contest T-shirt alone, and told $ i = 1, 2, 3, \ dots, N $ "$ A_i $ T-shirt on the $ i $ day." I made a plan for $ N $ to wear. However, if you keep the current plan, you may not be able to do the laundry in time, so I would l...
m,n = map(int,input().split()) a = list(map(int,input().split())) if m == 2: ans = n for i in range(2): t = 0 for j in range(n): idx = (i+j)%2 + 1 if idx != a[j]: t += 1 ans = min(ans, t) else: ans = 0 prev = a[0] for i in range(1,n): ...
{ "input": [ "2 3\n2 2 1", "2 0\n2 2 1", "-2 2\n2 2 1", "2 0\n2 0 1", "2 0\n2 0 0", "2 0\n1 0 0", "4 0\n1 0 0", "0 0\n2 2 1", "2 1\n2 0 1", "3 0\n2 0 0", "2 1\n1 0 0", "0 0\n2 2 0", "1 1\n2 0 1", "6 0\n2 0 0", "1 1\n1 0 0", "0 0\n2 3 0", "1 1\n2 1 1"...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Contest T-shirts Segtree has $ M $ contest T-shirts. He decided to spend $ N $ days on the contest T-shirt alone, and told $ i = 1, 2, 3, \ dots, N $ "$ A_i $ T-shirt on the $ i $ d...
p02358 Union of Rectangles_30011
Given a set of $N$ axis-aligned rectangles in the plane, find the area of regions which are covered by at least one rectangle. Constraints * $ 1 \leq N \leq 2000 $ * $ −10^9 \leq x1_i < x2_i\leq 10^9 $ * $ −10^9 \leq y1_i < y2_i\leq 10^9 $ Input The input is given in the following format. $N$ $x1_1$ $y1_1$ $x2_1$ ...
from itertools import accumulate import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) def main(): N = int(input()) xs = set() ys = set() rect = [] for _ in range(N): x1, y1, x2, y2 = map(int, input().split()) xs.add(x1) xs.add(x2) ys.add(y1) ...
{ "input": [ "4\n0 0 3 1\n0 0 1 3\n0 2 3 3\n2 0 3 3", "3\n1 1 2 5\n2 1 5 2\n1 2 2 5", "2\n0 0 3 4\n1 2 4 3", "4\n0 0 3 1\n0 0 1 3\n0 2 4 3\n2 0 3 3", "3\n1 1 2 5\n2 1 5 3\n1 2 2 5", "3\n1 1 3 5\n2 1 5 3\n1 2 2 5", "2\n1 0 3 6\n1 2 4 3", "3\n1 1 3 10\n2 1 5 3\n1 2 2 5", "2\n1 0 3 6\...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Given a set of $N$ axis-aligned rectangles in the plane, find the area of regions which are covered by at least one rectangle. Constraints * $ 1 \leq N \leq 2000 $ * $ −10^9 \leq x1...
1013_B. And_30021
There is an array with n elements a1, a2, ..., an and the number x. In one operation you can select some i (1 ≤ i ≤ n) and replace element ai with ai & x, where & denotes the [bitwise and](https://en.wikipedia.org/wiki/Bitwise_operation#AND) operation. You want the array to have at least two equal elements after appl...
from sys import stdin,stdout a,b=map(int,stdin.readline().split()) z=set(map(int,stdin.readline().split())) if len(z)!=a:stdout.write("0");exit() r=set() for i in z: if i&b in z and i&b!=i:stdout.write("1");exit() r.add(i&b) if len(r)!=a:stdout.write("2");exit() stdout.write("-1")
{ "input": [ "2 228\n1 1\n", "4 3\n1 2 3 7\n", "3 7\n1 2 3\n", "2 4\n1 2\n", "6 4\n1 4 3 4 2 4\n", "4 22\n17 49 1028 4\n", "4 1\n2 4 8 16\n", "4 12\n13 14 8 10\n", "4 3\n5 9 3 7\n", "4 3\n9999 9999 3 7\n", "5 132\n10060 81912 13624 40413 19012\n", "4 12\n15 13 9 8\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is an array with n elements a1, a2, ..., an and the number x. In one operation you can select some i (1 ≤ i ≤ n) and replace element ai with ai & x, where & denotes the [bitwis...
1060_D. Social Circles_30027
You invited n guests to dinner! You plan to arrange one or more circles of chairs. Each chair is going to be either occupied by one guest, or be empty. You can make any number of circles. Your guests happen to be a little bit shy, so the i-th guest wants to have a least l_i free chairs to the left of his chair, and a...
import heapq n=int(input()) fa=[i for i in range(n)] ls=[] rs=[] for i in range(n): l,r=[int(x) for x in input().split()] ls.append((l,i)) rs.append((r,i)) ls.sort() rs.sort() ans=n for i in range(n): ans+=max(ls[i][0],rs[i][0]) # heapq.heapify(ls) # heapq.heapify(rs) # # ans=n # if n==1: # print(ma...
{ "input": [ "1\n5 6\n", "4\n1 2\n2 1\n3 5\n5 3\n", "3\n1 1\n1 1\n1 1\n", "10\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000\n1000000000 10000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You invited n guests to dinner! You plan to arrange one or more circles of chairs. Each chair is going to be either occupied by one guest, or be empty. You can make any number of circ...
1082_B. Vova and Trophies_30031
Vova has won n trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wants to swap two trophies (not necessarily adjacent ones) to make the arrangement as ...
from sys import stdin input=stdin.readline n=int(input()) s="a"+input().rstrip() l=[0]*(n+1) r=[0]*(n+1) cnt_g=0 for i in range(len(s)): if s[i]=="G": cnt_g+=1 if n==cnt_g: print(n) exit() for i in range(1,n+1): if s[i]=="G": l[i]=r[i]=1 for i in range(1,n+1): if s[i]=="G" and s[i-1]=="G": l[i]+=l...
{ "input": [ "4\nGGGG\n", "10\nGGGSGGGSGG\n", "3\nSSS\n", "11\nSSGSSGGGSSG\n", "10\nSGGGSSGGSS\n", "10\nGSGSGSGSGG\n", "6\nGSSGGG\n", "32\nGSGSSGGSGGSGGSGGSGGSGSGGSSSGGGGG\n", "11\nGSSSGGGGGGG\n", "4\nGGGS\n", "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vova has won n trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the length of the long...
1101_D. GCD Counting_30034
You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i. Let's denote the function g(x, y) as the greatest common divisor of the numbers written on the vertices belonging to the simple path from vertex x to vertex y (including these two vertices). Also ...
from sys import stdin, stdout from math import * from heapq import * from collections import * dv=list(range(200002)) for i in range(2,200002): if ((i*i)>=200002): break if (dv[i]==i): j=i while ((i*j)<200002): dv[i*j]=i j=j+1 def loPr(x): global dv if (...
{ "input": [ "3\n2 3 4\n1 2\n2 3\n", "3\n2 3 4\n1 3\n2 3\n", "3\n1 1 1\n1 2\n2 3\n", "3\n1601 1601 1601\n1 2\n2 3\n", "4\n4 9 19 20\n2 4\n2 3\n4 1\n", "4\n3 6 2 2\n1 2\n2 3\n3 4\n", "1\n1\n", "1\n7\n", "3\n1601 2970 1601\n1 2\n2 3\n", "3\n3 3 4\n1 2\n2 3\n", "3\n6 3 6\n1 3\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i. Let's denote the function g(x, y) as the greatest common di...
112_B. Petya and Square_30038
Little Petya loves playing with squares. Mum bought him a square 2n × 2n in size. Petya marked a cell inside the square and now he is solving the following task. The task is to draw a broken line that would go along the grid lines and that would cut the square into two equal parts. The cutting line should not have any...
n,x,y=map(int,input().split()) a=[(n//2),(n//2)+1] print(['YES','NO'][x in a and y in a])
{ "input": [ "4 1 1\n", "2 2 2\n", "6 3 1\n", "100 1 2\n", "6 3 2\n", "60 34 30\n", "8 4 1\n", "100 100 100\n", "100 51 100\n", "60 31 29\n", "100 18 82\n", "100 52 50\n", "100 51 51\n", "8 4 4\n", "4 2 2\n", "100 19 99\n", "2 1 1\n", "6 3 3\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little Petya loves playing with squares. Mum bought him a square 2n × 2n in size. Petya marked a cell inside the square and now he is solving the following task. The task is to draw ...
114_C. Grammar Lessons_30042
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of sp...
import re def f(x): if x.endswith("lios"): return 1 elif x.endswith("liala"): return -1 elif x.endswith("etr"): return 2 elif x.endswith("etra"): return -2 elif x.endswith("initis"):return 3 elif x.endswith("inites"): return -3 else: return 0 a,b=input().strip().split(),[] for s in a:b.app...
{ "input": [ "etis atis animatis etis atis amatis\n", "nataliala kataliala vetra feinites\n", "petr\n", "liala etr etra\n", "etr etra lios\n", "etra liala initis\n", "petra petra petra\n", "pliala plios\n", "initis etra lios\n", "inites etr etra\n", "etr lios liala\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to ch...
1189_F. Array Beauty_30045
Let's call beauty of an array b_1, b_2, …, b_n (n > 1) — min_{1 ≤ i < j ≤ n} |b_i - b_j|. You're given an array a_1, a_2, … a_n and a number k. Calculate the sum of beauty over all subsequences of the array of length exactly k. As this number can be very large, output it modulo 998244353. A sequence a is a subsequenc...
from collections import defaultdict import sys input = sys.stdin.readline ''' for CASES in range(int(input())): n, m = map(int, input().split()) n = int(input()) A = list(map(int, input().split())) S = input().strip() sys.stdout.write(" ".join(map(str,ans))+"\n") ''' inf = 100000000000000000 # 1e17 mod = 998244353 n,...
{ "input": [ "5 5\n1 10 100 1000 10000\n", "4 3\n1 7 3 5\n", "52 52\n19752 66708 73109 84463 95683 96876 98503 98812 99766 99778 99913 99975 99977 99997 99997 99997 99998 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 10...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Let's call beauty of an array b_1, b_2, …, b_n (n > 1) — min_{1 ≤ i < j ≤ n} |b_i - b_j|. You're given an array a_1, a_2, … a_n and a number k. Calculate the sum of beauty over all s...
1227_F1. Wrong Answer on test 233 (Easy Version)_30050
Your program fails again. This time it gets "Wrong answer on test 233" . This is the easier version of the problem. In this version 1 ≤ n ≤ 2000. You can hack this problem only if you solve and lock both problems. The problem is about a test containing n one-choice-questions. Each of the questions contains k options...
n,k=[int(kk) for kk in input().strip().split(" ")] h=[int(kk) for kk in input().strip().split(" ")] fact=[1]*(n+1) mod=998244353 for i in range(1,n+1): fact[i]=(fact[i-1]*i)%mod def inv(x): return pow(x,mod-2,mod) def C(n,k): return (fact[n]*inv(fact[k])*inv(fact[n-k]))%mod ng=0 for i in range(n):...
{ "input": [ "3 3\n1 3 1\n", "5 5\n1 1 4 2 2\n", "6 2\n1 1 2 2 1 1\n", "1 1\n1\n", "15 12\n11 4 12 7 5 8 11 1 1 3 3 1 6 10 7\n", "10 999321\n726644 726644 454707 454707 454707 454707 454707 454707 454707 726644\n", "98 102\n79 30 51 87 80 91 32 16 21 54 79 14 48 24 8 66 9 94 45 50 85 82 54...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Your program fails again. This time it gets "Wrong answer on test 233" . This is the easier version of the problem. In this version 1 ≤ n ≤ 2000. You can hack this problem only if y...
1292_B. Aroma's Search_30056
[THE SxPLAY & KIVΛ - 漂流](https://soundcloud.com/kivawu/hyouryu) [KIVΛ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives) With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space. The space can be considered a 2D plane,...
""" Satwik_Tiwari ;) . 12th july , 2020 - Sunday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, I...
{ "input": [ "1 1 2 3 1 0\n2 2 1\n", "1 1 2 3 1 0\n15 27 26\n", "1 1 2 3 1 0\n2 4 20\n", "1953417899042943 1 2 2 31 86\n1953417899042940 5 5860253697129194\n", "9678412710617879 5501638861371579 2 2 95 12\n4209774865484088 2296505519592538 6040008676069765\n", "923 247 2 2 1 1\n1000000000 1000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: [THE SxPLAY & KIVΛ - 漂流](https://soundcloud.com/kivawu/hyouryu) [KIVΛ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives) With a new body, our idol Aroma Whi...
1312_C. Adding Powers_30060
Suppose you are performing the following algorithm. There is an array v_1, v_2, ..., v_n filled with zeroes at start. The following operation is applied to the array several times — at i-th step (0-indexed) you can: * either choose position pos (1 ≤ pos ≤ n) and increase v_{pos} by k^i; * or not choose any posit...
def convert(n, base): a = "01" if n < base: if n % base >= 2: return False return a[n % base] else: if n % base >= 2: return False x = convert(n // base, base) if x: return x + a[n % base] return False t = int(input()) for...
{ "input": [ "5\n4 100\n0 0 0 0\n1 2\n1\n3 4\n1 4 1\n3 2\n0 1 3\n3 9\n0 59049 810\n", "1\n1 12\n11\n", "1\n2 3\n18 3\n", "1\n1 16\n100\n", "1\n3 2\n1 1 1\n", "1\n4 3\n2 6 18 54\n", "1\n2 2\n10000000000000000 9007199254740992\n", "1\n30 2\n16777216 33554432 67108864 134217728 268435456 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Suppose you are performing the following algorithm. There is an array v_1, v_2, ..., v_n filled with zeroes at start. The following operation is applied to the array several times — a...
1355_B. Young Explorers_30066
Young wilderness explorers set off to their first expedition led by senior explorer Russell. Explorers went into a forest, set up a camp and decided to split into groups to explore as much interesting locations as possible. Russell was trying to form groups, but ran into some difficulties... Most of the young explorer...
for i in range(int(input())): n=int(input()) l=list(map(int,input().split())) l.sort() i1,i2=1,0 for j in l: if j==i1: i2+=1 i1=0 i1+=1 print(i2)
{ "input": [ "2\n3\n1 1 1\n5\n2 3 1 2 2\n", "2\n3\n1 1 1\n5\n2 3 1 2 4\n", "2\n3\n1 1 1\n5\n2 3 1 1 2\n", "2\n3\n1 2 2\n5\n2 3 1 2 2\n", "2\n3\n1 2 2\n5\n2 1 1 2 2\n", "2\n3\n1 1 1\n5\n2 4 2 2 4\n", "2\n3\n1 1 1\n5\n1 1 1 1 2\n", "2\n3\n1 1 1\n5\n2 3 1 2 1\n", "2\n3\n1 1 1\n5\n2 3 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Young wilderness explorers set off to their first expedition led by senior explorer Russell. Explorers went into a forest, set up a camp and decided to split into groups to explore as...
1375_A. Sign Flipping_30070
You are given n integers a_1, a_2, ..., a_n, where n is odd. You are allowed to flip the sign of some (possibly all or none) of them. You wish to perform these flips in such a way that the following conditions hold: 1. At least (n - 1)/(2) of the adjacent differences a_{i + 1} - a_i for i = 1, 2, ..., n - 1 are grea...
#!/usr/bin/env python3 def ans(A): A = [abs(a) for a in A] for i in range(1, len(A), 2): if i+1 < len(A): [p, q, r] = A[i-1:i+2] if p <= q <= r: A[i] = -A[i] elif p >= q >= r: A[i] = -A[i] return ' '.join([str(a) for a in A]) T = int(input()) for _ in range(T):...
{ "input": [ "5\n3\n-2 4 3\n5\n1 1 1 1 1\n5\n-2 4 7 -6 4\n9\n9 7 -4 -2 1 -3 9 -4 -5\n9\n-4 1 9 4 8 9 5 1 -9\n", "5\n3\n-2 4 3\n5\n1 1 1 1 1\n5\n-2 4 7 -6 4\n9\n9 7 -4 -2 2 -3 9 -4 -5\n9\n-4 1 9 4 8 9 5 1 -9\n", "5\n3\n-2 4 3\n5\n1 1 1 1 1\n5\n-2 4 7 -6 4\n9\n9 7 -4 -2 2 -3 9 -4 -5\n9\n-4 1 9 4 8 9 5 1 -15...
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 a_1, a_2, ..., a_n, where n is odd. You are allowed to flip the sign of some (possibly all or none) of them. You wish to perform these flips in such a way tha...
1398_D. Colored Rectangles_30074
You are given three multisets of pairs of colored sticks: * R pairs of red sticks, the first pair has length r_1, the second pair has length r_2, ..., the R-th pair has length r_R; * G pairs of green sticks, the first pair has length g_1, the second pair has length g_2, ..., the G-th pair has length g_G; * B ...
#!/usr/bin/env python from __future__ import division, print_function import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def main(): from functools import lru_cache r, ...
{ "input": [ "2 1 3\n9 5\n1\n2 8 5\n", "1 1 1\n3\n5\n4\n", "10 1 1\n11 7 20 15 19 14 2 4 13 14\n8\n11\n", "2 2 2\n3 10\n6 9\n10 9\n", "9 4 7\n17 19 19 9 20 6 1 14 11\n15 12 10 20\n15 10 3 20 1 16 7\n", "16 26 8\n44 13 2 24 56 74 72 4 87 98 43 4 17 30 82 8\n31 6 76 32 88 37 19 64 44 55 18 67 72...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given three multisets of pairs of colored sticks: * R pairs of red sticks, the first pair has length r_1, the second pair has length r_2, ..., the R-th pair has length r_R...
1421_E. Swedish Heroes_30077
While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to ...
n = int(input()) a = list(map(int,input().split())) INF = 10 ** 20 DP = [-INF] * 12 DP[1] = a[0] DP[5] = -a[0] for elem in a[1:]: newDP = [] newDP.append(DP[5] + elem) newDP.append(DP[3] + elem) newDP.append(DP[4] + elem) newDP.append(DP[1] - elem) newDP.append(DP[2] - elem) newDP.append(DP[...
{ "input": [ "5\n4 -5 9 -2 1\n", "4\n5 6 7 8\n", "5\n-56 101 87 0 -24\n", "6\n72 91 46 -72 -36 -25\n", "9\n286474128 -767346318 14465977 -736068092 594841463 -281215614 214724210 -313802706 43797330\n", "5\n9 3 7 4 6\n", "10\n41 6 -34 98 -68 108 -109 -32 -30 33\n", "5\n2 -86 61 -3 -50\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfo...
143_D. Help General_30081
Once upon a time in the Kingdom of Far Far Away lived Sir Lancelot, the chief Royal General. He was very proud of his men and he liked to invite the King to come and watch drill exercises which demonstrated the fighting techniques and tactics of the squad he was in charge of. But time went by and one day Sir Lancelot h...
n, m = map(int, input().split()) if n > m: n, m = m, n if n > 2 and m > 2: print(((n * m) + 1) // 2) elif n == 1: print(m) else: print(2 * (((m // 4) * 2) + min(m % 4, 2))) # Made By Mostafa_Khaled
{ "input": [ "2 4\n", "3 4\n", "1 393\n", "1 995\n", "999 1000\n", "1000 997\n", "728 174\n", "961 61\n", "997 1000\n", "998 998\n", "675 710\n", "449 838\n", "1 865\n", "1 1\n", "635 458\n", "755 458\n", "995 1\n", "999 997\n", "936 759\n", ...
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 Kingdom of Far Far Away lived Sir Lancelot, the chief Royal General. He was very proud of his men and he liked to invite the King to come and watch drill exerc...
1491_C. Pekora and Trampoline_30087
There is a trampoline park with n trampolines in a line. The i-th of which has strength S_i. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline i, the trampoline will launch her to position i + S_i, and S_i wi...
#region Header #!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools import bisect import heapq def input(): return sys.stdin.readline()[:-1] # sys.setrecursionlimit(1000000) #endregion # _INPUT = """4 # 18 # 6 6 5 4 3 3 3 2 3 5 2 10 ...
{ "input": [ "3\n7\n1 4 2 2 2 2 2\n2\n2 3\n5\n1 1 1 1 1\n", "1\n1\n69\n", "1\n1\n67\n", "3\n7\n2 4 2 2 2 2 2\n2\n2 3\n5\n1 1 1 1 1\n", "1\n1\n12\n", "3\n7\n2 4 2 2 2 2 2\n2\n2 3\n5\n1 1 1 2 1\n", "1\n1\n9\n", "1\n1\n14\n", "1\n1\n26\n", "1\n1\n108\n", "1\n1\n80\n", "3\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a trampoline park with n trampolines in a line. The i-th of which has strength S_i. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any ...
1513_F. Swapping Problem_30090
You are given 2 arrays a and b, both of size n. You can swap two elements in b at most once (or leave it as it is), and you are required to minimize the value $$$∑_{i}|a_{i}-b_{i}|.$$$ Find the minimum possible value of this sum. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5). The second line c...
# Codeforces - 1513-F (https://codeforces.com/problemset/problem/1513/F) n = int(input()) a = [int(val) for val in input().split()] b = [int(val) for val in input().split()] # step 1: partition s = [] t = [] for i in range(n): if a[i] < b[i]: s.append((a[i], b[i])) elif a[i] > b[i]: t.append((b[i], a[i])...
{ "input": [ "2\n1 3\n4 2\n", "5\n5 4 3 2 1\n1 2 3 4 5\n", "6\n6 2 4 7 11 10\n8 1 7 12 4 2\n", "4\n4 6 1 9\n2 5 3 2\n", "5\n6 6 6 9 6\n5 6 2 1 8\n", "5\n4 10 7 7 6\n1 9 5 6 6\n", "64\n46 45 45 81 93 17 34 35 34 27 80 29 80 93 43 41 41 57 32 63 44 9 78 44 66 28 51 68 12 59 85 9 56 29 89 48 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given 2 arrays a and b, both of size n. You can swap two elements in b at most once (or leave it as it is), and you are required to minimize the value $$$∑_{i}|a_{i}-b_{i}|.$$...
189_B. Counting Rhombi_30098
You have two positive integers w and h. Your task is to count the number of rhombi which have the following properties: * Have positive area. * With vertices at integer points. * All vertices of the rhombi are located inside or on the border of the rectangle with vertices at points (0, 0), (w, 0), (w, h), (0,...
w,h=map(int,input().split()) ans=0 for i in range(2,w+1,2): for j in range(2,h+1,2): ans+=(w+1-i)*(h+1-j) print(ans)
{ "input": [ "2 2\n", "1 2\n", "13 1402\n", "14 2\n", "1913 3980\n", "1665 27\n", "1499 2172\n", "1 1\n", "7 13\n", "14 1274\n", "9 14\n", "3671 19\n", "3727 2044\n", "4000 4000\n", "25 2986\n", "7 9\n", "18 2858\n", "4 6\n", "3 10\n", "2...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You have two positive integers w and h. Your task is to count the number of rhombi which have the following properties: * Have positive area. * With vertices at integer points....
236_B. Easy Number Challenge_30104
Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum: <image> Find the sum modulo 1073741824 (230). Input The first line contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 100). Output Print a singl...
a,b,c=map(int,input().split()) M=1073741824 n=a*b*c d=[1]*(n+1) for i in range(2,n+1): for j in range(i,n+1,i): d[j]+=1 r=0 for i in range(1,a+1): for j in range(1,b+1): for k in range(1,c+1): r+=(d[i*j*k])%M print(r%M)
{ "input": [ "2 2 2\n", "5 6 7\n", "55 45 45\n", "21 16 9\n", "91 96 36\n", "44 18 24\n", "60 8 35\n", "4 9 20\n", "100 9 88\n", "4 21 45\n", "18 86 27\n", "76 12 17\n", "63 90 23\n", "64 12 36\n", "82 29 45\n", "13 31 33\n", "36 3 32\n", "68 14 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum: <image> Find the sum modul...
355_C. Vasya and Robot_30116
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms. Vasya needs to collect all these items, however he won't do it by himself. He us...
path = list(map(int, input().split())) n, L, R, QL, QR = path[0], path[1], path[2], path[3], path[4] w = list(map(int, input().split())) sumpref = [0] for i in range(1, n + 1) : sumpref.append(w[i - 1] + sumpref[i - 1]) answer = QR * (n - 1) + sumpref[n] * R for i in range(1, n + 1) : energy = L * sumpref[i]...
{ "input": [ "4 7 2 3 9\n1 2 3 4\n", "3 4 4 19 1\n42 3 99\n", "5 1 100 10000 1\n1 2 3 4 5\n", "1 78 94 369 10000\n93\n", "5 100 1 1 10000\n1 2 3 4 5\n", "1 94 78 369 10000\n93\n", "2 3 4 5 6\n1 2\n", "7 3 13 30 978\n1 2 3 4 5 1 7\n", "5 100 1 10000 1\n1 2 3 4 5\n", "5 1 100 1 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each...
379_D. New Year Letter_30120
Many countries have such a New Year or Christmas tradition as writing a letter to Santa including a wish list for presents. Vasya is an ordinary programmer boy. Like all ordinary boys, he is going to write the letter to Santa on the New Year Eve (we Russians actually expect Santa for the New Year, not for Christmas). ...
def main(): k, x, n, m = map(int, input().split()) def f(s, e, n, cnt): ret = [""] * n ret[0] = s ret[-1] = e sa = 0 if s == 'A' else 1 for i in range(cnt): ret[sa] = 'A' ret[sa + 1] = 'C' sa += 2 for j in range(sa, n - 1):...
{ "input": [ "3 2 2 2\n", "3 3 2 2\n", "3 0 2 2\n", "4 2 2 1\n", "4 3 2 1\n", "6 3 1 1\n", "6 1 2 2\n", "7 12 2 2\n", "3 1 1 1\n", "8 664 100 100\n", "10 189 44 100\n", "7 4 1 2\n", "5 4 3 2\n", "5 2 1 1\n", "3 2 3 1\n", "48 512559680 100 100\n", "5 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Many countries have such a New Year or Christmas tradition as writing a letter to Santa including a wish list for presents. Vasya is an ordinary programmer boy. Like all ordinary boys...
426_B. Sereja and Mirroring_30126
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: * the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; * the lower half of matrix c (rows with n...
string_input = input().split(" ") n, m = int(string_input[0]), int(string_input[1]) matrix = [] row = n for i in range(0, n): matrix.append(input()) while True: if n % 2 == 1: break else: row_flag = 1 n = n//2 for i in range(0, n): if matrix[i] != matrix[2*n-1-i]:...
{ "input": [ "3 3\n0 0 0\n0 0 0\n0 0 0\n", "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1\n", "8 1\n0\n1\n1\n0\n0\n1\n1\n0\n", "6 3\n1 1 1\n0 0 0\n1 1 1\n1 1 1\n0 0 0\n1 1 1\n", "1 100\n0 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 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: Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following pr...
44_E. Anfisa the Monkey_30130
Anfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be great to divide what she has written into k lines not shorter than a and not longer than b, for the text to resemble human s...
k,a,b=map(int,input().split()) ss=input() h=len(ss) q,r=divmod(h,k) if q<a or q>b or (q==b and r>0): print('No solution') else: i=0 while r>0: print(ss[i:i+q+1]) r-=1 i=i+q+1 while i<h: print(ss[i:i+q]) i=i+q
{ "input": [ "3 2 5\nabrakadabra\n", "4 1 2\nabrakadabra\n", "10 1 200\nolahgjusovchbowjxtwzvjakrktyjqcgkqmcxknjchzxcvbnkbakwnxdouebomyhjsrfsicmzsgdweabbuipbzrhuqfpynybaohzquqbbsqpoaskccszzsmnfleevtasmjuwqgcqtvysohvyutqipnvuhjumwwyytkeuebbncxsnpavwdkoxyycqrhcidf\n", "15 2 5\nkddainaviqrjsesrhhdnbuisen...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Anfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that...
471_A. MUH and Sticks_30134
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: ...
a = list(map(int,input().split())) for i in range(6): if a.count(a[i])>=4: v = a[i] break else: print("Alien") exit() for i in range(4): a.remove(v) a.sort() if a[0]<a[1]: print("Bear") elif a[0]==a[1]: print("Elephant") else: print("Alien")
{ "input": [ "1 2 3 4 5 6\n", "4 4 5 4 4 5\n", "4 2 5 4 4 4\n", "5 5 5 5 5 5\n", "4 4 4 4 2 2\n", "1 1 2 2 3 4\n", "1 3 3 3 4 5\n", "4 4 5 6 7 8\n", "4 4 4 4 4 5\n", "5 5 5 6 6 6\n", "4 4 2 2 2 2\n", "1 1 3 3 3 5\n", "1 8 9 1 1 1\n", "9 9 9 1 9 9\n", "4 4 4 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada...
495_B. Modular Equations_30138
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define i modulo j as the remainder of division of i by j and denote it by <image>. A Modular Equation, as Hamed's teacher described, is an equation of the form <image> in which a and b are two non-negative integers a...
a, b = map(int, input().split()) if a == b: print ('infinity') elif b > a: print (0) else: a -= b i = 1 cont = 0 while (i*i) <= a: if (a % i) == 0: if i > b: cont += 1 if (a/i) > b and (i*i) != a: cont += 1 i += 1 print (cont)
{ "input": [ "9435152 272\n", "21 5\n", "10 10\n", "325508499 119510657\n", "233758336 10665466\n", "124 24\n", "2 0\n", "49106 46\n", "77 75\n", "257424 24\n", "944387968 700818251\n", "121 0\n", "89768760 885778845\n", "5 2\n", "1 10\n", "997920 0\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define i modulo j as the remainder of division of i by j and denote it by <imag...
519_E. A and B and Lecture Rooms_30142
A and B are preparing themselves for programming contests. The University where A and B study is a set of rooms connected by corridors. Overall, the University has n rooms connected by n - 1 corridors so that you can get from any room to any other one by moving along the corridors. The rooms are numbered from 1 to n. ...
from collections import defaultdict as df from collections import deque import os import sys from io import BytesIO, IOBase _str = str str = lambda x=b"": x if type(x) is bytes else _str(x).encode() BUFSIZE = 8192 from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): ...
{ "input": [ "4\n1 2\n1 3\n2 4\n1\n2 3\n", "4\n1 2\n2 3\n2 4\n2\n1 2\n1 3\n", "8\n1 2\n2 3\n2 4\n2 5\n5 6\n6 7\n6 8\n6\n3 5\n3 6\n3 8\n5 8\n7 3\n5 7\n", "8\n1 2\n2 3\n2 4\n2 5\n5 6\n6 7\n6 8\n7\n3 5\n3 6\n3 8\n5 8\n7 3\n5 7\n5 5\n", "5\n1 2\n1 3\n2 5\n2 4\n1\n5 4\n", "15\n1 2\n1 3\n1 4\n2 5\n2...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A and B are preparing themselves for programming contests. The University where A and B study is a set of rooms connected by corridors. Overall, the University has n rooms connected ...
546_A. Soldier and Bananas_30146
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana). He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas? Input The first lin...
price = 0 iter = 1 k,n,w = list(map(int,input().split())) for i in range (w): price += k*iter iter += 1 if price <= n: print(0) else: output = price - n print(output)
{ "input": [ "3 17 4\n", "111 111111111 111\n", "432 10000 241\n", "1 5 6\n", "20 43 3\n", "634 87973 214\n", "1000 500500000 1000\n", "1 1000000000 1\n", "1000 1000000000 1000\n", "1000 500500001 1000\n", "1 2 1\n", "1000 500499999 1000\n", "859 453892 543\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the ...
572_C. Lengthening Sticks_30150
You are given three sticks with positive integer lengths of a, b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most l centimeters. In particular, it is allowed not to increase the l...
a, b, c, l = map(int, input().split()) ans = (l + 3) * (l + 2) * (l + 1) // 3 for z in (a, b, c): s = 2 * z - a - b - c for x in range(max(0, -s), l + 1): m = min(s + x, l - x) ans -= (m + 1) * (m + 2) print(ans // 2) # Made By Mostafa_Khaled
{ "input": [ "10 2 1 7\n", "1 1 1 2\n", "1 2 3 1\n", "1 1 300000 300000\n", "300000 200000 100000 1\n", "2958 4133 233463 259655\n", "100000 300000 200001 0\n", "63 5 52 78\n", "61 100 3 8502\n", "300000 200000 100000 0\n", "300000 300000 1 300000\n", "552 250082 77579 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given three sticks with positive integer lengths of a, b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different ...
594_A. Warrior and Archer_30154
In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest. V...
n = int(input()) x = sorted(list(map(int, input().split()))) print(min([x[i + n // 2] - x[i] for i in range(n // 2)]))
{ "input": [ "2\n73 37\n", "6\n0 1 3 7 15 31\n", "8\n729541013 135019377 88372488 319157478 682081360 558614617 258129110 790518782\n", "2\n0 1\n", "2\n0 1000000000\n", "20\n54 50000046 100000041 150000049 200000061 250000039 300000043 350000054 400000042 450000045 500000076 550000052 60000006...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake h...
615_D. Multipliers_30158
Ayrat has number n, represented as it's prime factorization pi of size m, i.e. n = p1·p2·...·pm. Ayrat got secret information that that the product of all divisors of n taken modulo 109 + 7 is the password to the secret data base. Now he wants to calculate this value. Input The first line of the input contains a sing...
MD = 1000000007 m = int(input()) p = list(map(int, input().split())) q = {} for el in p: if el in q: q[el] += 1 else: q[el] = 2 sum1 = 1 sum2 = 1 for el in q: sum1=sum1*q[el] sum2=sum2*pow(el,(q[el]-1),MD) sum=pow(sum2,sum1//2,MD) if sum1 % 2 == 1: for el in q: sum = (sum * p...
{ "input": [ "3\n2 3 2\n", "2\n2 3\n", "5\n7 5 2 3 13\n", "5\n11 7 11 7 11\n", "10\n3 3 3 3 3 3 3 3 3 3\n", "4\n3 3 3 5\n", "67\n98929 19079 160079 181891 17599 91807 19079 98929 182233 92647 77477 98929 98639 182233 181891 182233 160079 98929 19079 98639 114941 98929 161341 91807 160079 2...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ayrat has number n, represented as it's prime factorization pi of size m, i.e. n = p1·p2·...·pm. Ayrat got secret information that that the product of all divisors of n taken modulo 1...
634_F. Orchestra_30162
Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul can take a picture of any axis-parallel rectangle in the orchestra. Count ...
r, c, n, k = map(int, input().split()) board = [[0 for col in range(c)] for row in range(r)] for i in range(n): x, y = map(lambda x: int(x)-1, input().split()) board[x][y] = 1 photos = 0 for x1 in range(r): for y1 in range(c): for x2 in range(x1, r): for y2 in range(y1, c): ...
{ "input": [ "3 2 3 2\n1 1\n3 1\n2 2\n", "3 2 3 3\n1 1\n3 1\n2 2\n", "2 2 1 1\n1 2\n", "7 5 3 1\n5 5\n4 5\n1 4\n", "6 4 10 2\n2 3\n2 1\n1 2\n6 1\n1 4\n4 4\n2 4\n1 1\n6 3\n4 2\n", "10 10 10 10\n5 6\n4 4\n8 9\n5 7\n9 2\n6 4\n7 3\n6 10\n10 3\n3 8\n", "10 10 10 1\n4 5\n9 6\n3 6\n6 10\n5 2\n1 7...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he w...
688_B. Lovely Palindromes_30168
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro...
n = input() print(n + "".join(reversed(list(n))))
{ "input": [ "10\n", "1\n", "6\n", "3\n", "4\n", "18\n", "7\n", "1321\n", "123451\n", "2\n", "91471\n", "8\n", "41242\n", "11\n", "19\n", "26550\n", "100\n", "16137\n", "15\n", "9\n", "2244399823612183124978103773977739948197709395321...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while ...
710_A. King Moves_30172
The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the posi...
import sys from collections import Counter from math import factorial input = sys.stdin output = sys.stdout # input = open('input.txt') def read_int(): return [int(x) for x in input.readline().rstrip().split()] line = input.readline().rstrip() x = ord(line[0]) - ord('a') y = ord(line[1]) - ord('1') answer = 0 ...
{ "input": [ "e4\n", "h2\n", "h5\n", "f2\n", "b1\n", "h1\n", "h4\n", "d8\n", "h3\n", "h6\n", "a4\n", "c7\n", "e8\n", "a2\n", "g8\n", "b8\n", "g7\n", "e1\n", "f8\n", "b2\n", "c8\n", "a8\n", "h8\n", "a1\n", "e2\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of...
731_A. Night at the Museum_30176
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character...
import sys from math import ceil,log RI = lambda : [int(x) for x in sys.stdin.readline().split()] ri = lambda : sys.stdin.readline().strip() 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 ra...
{ "input": [ "ares\n", "zeus\n", "map\n", "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx\n", "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro\n", "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhu...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole expositi...
755_C. PolandBall and Forest_30180
PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree. There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to n. For e...
n = int(input()) a = [0] + list(map(int, input().split())) was = set() for i in range(1, n + 1): if a[a[i]] == i: was.add(min(i, a[i])) print(len(was))
{ "input": [ "1\n1\n", "5\n2 1 5 3 3", "3 1\n2 3\n", "2 0\n", "3 0\n", "4 3\n3 1\n1 2\n2 4\n", "1 0\n", "18 2\n9 17\n1 18\n", "3 2\n1 2\n2 3\n", "5 4\n1 2\n1 3\n1 4\n3 5\n", "10000 1\n1725 10000\n", "5 1\n4 5\n", "5 4\n1 3\n1 4\n4 2\n5 2\n", "2 1\n1 2\n", "1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note th...
776_D. The Door Problem_30183
Moriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlocked. But, there is a condition that the people in the hotel can only escape when all the doors are unlocked at the same time. There are m switches. Each switch control doors of some rooms, but each door is controlled by...
import sys from math import inf time = 0 cc = 0 l = {} d = {} f = {} conn_comp = {} on_stack = {} stack = [] color = [] def tarjan(graph): global l global d global f global pi global stack global on_stack l = {key : inf for key in graph} d = {key : -1 for key in graph} f = {key : ...
{ "input": [ "3 3\n1 0 1\n3 1 2 3\n1 2\n2 1 3\n", "3 3\n1 0 1\n3 1 2 3\n2 1 2\n1 3\n", "3 3\n1 0 1\n2 1 3\n2 1 2\n2 2 3\n", "3 3\n0 1 0\n2 1 3\n2 2 3\n2 1 2\n", "3 6\n0 0 0\n0\n0\n0\n2 1 2\n2 2 3\n2 1 3\n", "2 2\n1 0\n2 1 2\n2 1 2\n", "3 3\n0 0 0\n2 1 2\n2 2 3\n2 1 3\n", "4 4\n1 1 1 0\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Moriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlocked. But, there is a condition that the people in the hotel can only escape when a...
7_E. Defining Macros_30187
Most C/C++ programmers know about excellent opportunities that preprocessor #define directives give; but many know as well about the problems that can arise because of their careless use. In this problem we consider the following model of #define constructions (also called macros). Each macro has its name and value. T...
P, A, S, M, D = 1, 2, 4, 8, 16 ADD = A | S ANY = A | S | M | D OP_BIT = {"+": A, "-": S, "*": M, "/": D, ")": 0} UNSAFE_BEFORE = {P: 0, A: 0, S: ADD, M: ADD, D: ANY} UNSAFE_AFTER = {P: 0, A: 0, S: 0, M: ADD, D: ADD} macro = dict() def expr(chars, pseudo=P, expand=macro.get, op_bit=OP_BIT, ...
{ "input": [ "1\n#define sum x + y\n1 * sum\n", "4\n#define sum x + y\n#define mul a * b\n#define div a / b\n#define expr sum + mul * div * mul\nexpr\n", "1\n#define sum (x + y)\nsum - sum\n", "3\n#define SumSafe (a+b)\n#define DivUnsafe a/b\n#define DenominatorUnsafe a*b\n((SumSafe) + DivUnsa...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Most C/C++ programmers know about excellent opportunities that preprocessor #define directives give; but many know as well about the problems that can arise because of their careless ...
821_B. Okabe and Banana Trees_30191
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees. Consider the point (x, y) in the 2D plane such that x and y are integers and 0 ≤ x, y. There is a tree in such a point, and it has x + y bananas. There are no trees nor bananas in other point...
m,b=map(int,input().split()) f=lambda n: n*(n+1)//2 def g(y): x=m*(b-y) return f(x)*(y+1)+f(y)*(x+1) print(max(g(y) for y in range(b+1)))
{ "input": [ "1 5\n", "2 3\n", "987 4237\n", "417 1045\n", "817 3719\n", "22 3481\n", "939 407\n", "841 7185\n", "446 5030\n", "1000 10000\n", "4 6\n", "494 6155\n", "10 1\n", "969 6030\n", "918 7704\n", "393 4874\n", "20 10\n", "174 2688\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees. Consider the point (x, y) in the 2D plane such that x ...