problem_id
stringlengths
3
7
contestId
stringclasses
660 values
problem_index
stringclasses
27 values
programmingLanguage
stringclasses
3 values
testset
stringclasses
5 values
incorrect_passedTestCount
float64
0
146
incorrect_timeConsumedMillis
float64
15
4.26k
incorrect_memoryConsumedBytes
float64
0
271M
incorrect_submission_id
stringlengths
7
9
incorrect_source
stringlengths
10
27.7k
correct_passedTestCount
float64
2
360
correct_timeConsumedMillis
int64
30
8.06k
correct_memoryConsumedBytes
int64
0
475M
correct_submission_id
stringlengths
7
9
correct_source
stringlengths
28
21.2k
contest_name
stringclasses
664 values
contest_type
stringclasses
3 values
contest_start_year
int64
2.01k
2.02k
time_limit
float64
0.5
15
memory_limit
float64
64
1.02k
title
stringlengths
2
54
description
stringlengths
35
3.16k
input_format
stringlengths
67
1.76k
output_format
stringlengths
18
1.06k
interaction_format
null
note
stringclasses
840 values
examples
stringlengths
34
1.16k
rating
int64
800
3.4k
tags
stringclasses
533 values
testset_size
int64
2
360
official_tests
stringlengths
44
19.7M
official_tests_complete
bool
1 class
input_mode
stringclasses
1 value
generated_checker
stringclasses
231 values
executable
bool
1 class
15/C
15
C
PyPy 3
TESTS
3
218
102,400
199123001
import sys from math import * from collections import Counter,defaultdict,deque input=sys.stdin.readline mod=10**9+7 def get_ints():return map(int,input().split()) def get_int():return int(input()) def get_array():return list(map(int,input().split())) def input():return sys.stdin.readline().strip() def getxor(a): ...
25
652
0
176449246
def f(x): if x%4==0: return x elif x%4==1: return 1 elif x%4==2: return x+1 return 0 n = int(input()) res = 0 for i in range(n): x,m = input().split() x,m = int(x),int(m) res ^= f(x-1)^f(x+m-1) if res == 0: print("bolik") else: print("tolik")
Codeforces Beta Round 15
ICPC
2,010
2
64
Industrial Nim
There are n stone quarries in Petrograd. Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last for the i-th quarry) has xi + mi - 1 stones in it. Two oligarchs p...
The first line of the input contains one integer number n (1 ≤ n ≤ 105) — the amount of quarries. Then there follow n lines, each of them contains two space-separated integers xi and mi (1 ≤ xi, mi ≤ 1016) — the amount of stones in the first dumper of the i-th quarry and the number of dumpers at the i-th quarry.
Output «tolik» if the oligarch who takes a stone first wins, and «bolik» otherwise.
null
null
[{"input": "2\n2 1\n3 2", "output": "tolik"}, {"input": "4\n1 1\n1 1\n1 1\n1 1", "output": "bolik"}]
2,000
["games"]
25
[{"input": "2\r\n2 1\r\n3 2\r\n", "output": "tolik\r\n"}, {"input": "4\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n", "output": "bolik\r\n"}, {"input": "10\r\n2 3\r\n1 4\r\n5 8\r\n4 10\r\n10 8\r\n7 2\r\n1 2\r\n1 7\r\n4 10\r\n5 3\r\n", "output": "tolik\r\n"}, {"input": "20\r\n8 6\r\n6 3\r\n2 9\r\n7 8\r\n9 1\r\n2 4\r\n3 6\r\n6 3\r\n5...
false
stdio
null
true
245/A
245
A
Python 3
TESTS
4
186
0
57317151
n=int(input()) t1=0 t2=0 s1=0 s2=0 for i in range(n): a=list(map(int,input().split())) if a[0]==1: t1=t2+1 s1=s1+a[1] else: t2=t2+1 s2=s2+a[1] if 2*s1>=t1*10: print("LIVE") else: print("DEAD") if 2*s2>=t2*10: print("LIVE") else: print("DEAD")
13
62
0
153017830
n = int(input()) a_suc = 0 a_fai = 0 b_suc = 0 b_fai = 0 for i in range(n): s = list(map(int, input().split())) if s[0] == 1: a_suc+=s[1] a_fai+=s[2] else: b_suc+=s[1] b_fai+=s[2] if a_suc>=a_fai: print("LIVE") else: print("DEAD") if b_suc>=b_fai: print("...
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
ICPC
2,012
2
256
System Administrator
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program re...
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti =...
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
null
Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this ...
[{"input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE"}, {"input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD"}]
800
["implementation"]
23
[{"input": "2\r\n1 5 5\r\n2 6 4\r\n", "output": "LIVE\r\nLIVE\r\n"}, {"input": "3\r\n1 0 10\r\n2 0 10\r\n1 10 0\r\n", "output": "LIVE\r\nDEAD\r\n"}, {"input": "10\r\n1 3 7\r\n2 4 6\r\n1 2 8\r\n2 5 5\r\n2 10 0\r\n2 10 0\r\n1 8 2\r\n2 2 8\r\n2 10 0\r\n1 1 9\r\n", "output": "DEAD\r\nLIVE\r\n"}, {"input": "11\r\n1 8 2\r\n1...
false
stdio
null
true
245/A
245
A
PyPy 3
TESTS
5
186
0
128193309
T=int(input()) a=sa=0 b=sb=0 for z in range(T): t,x,y=[int(v) for v in input().split()] if t==1: a+=x sa+=5 elif t==2: b+=x sb+=5 if a<sa: print("DEAD") elif a>=sb: print("LIVE") if b<sb: print("DEAD") elif b>=sb: print("LIVE")
13
62
0
153794509
n = int(input()) x1, y1, x2, y2 = 0, 0, 0, 0 for i in [0]*n: t,x,y = list(map(int, input().split())) if t == 1: x1 += x y1 += y else: x2 += x y2 += y if x1 >= y1: print("LIVE") else: print("DEAD") if x2 >= y2: print("LIVE") else: print("DEAD")
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
ICPC
2,012
2
256
System Administrator
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program re...
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti =...
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
null
Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this ...
[{"input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE"}, {"input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD"}]
800
["implementation"]
23
[{"input": "2\r\n1 5 5\r\n2 6 4\r\n", "output": "LIVE\r\nLIVE\r\n"}, {"input": "3\r\n1 0 10\r\n2 0 10\r\n1 10 0\r\n", "output": "LIVE\r\nDEAD\r\n"}, {"input": "10\r\n1 3 7\r\n2 4 6\r\n1 2 8\r\n2 5 5\r\n2 10 0\r\n2 10 0\r\n1 8 2\r\n2 2 8\r\n2 10 0\r\n1 1 9\r\n", "output": "DEAD\r\nLIVE\r\n"}, {"input": "11\r\n1 8 2\r\n1...
false
stdio
null
true
408/A
408
A
PyPy 3
TESTS
4
92
20,172,800
115758687
n=int(input()) l=[] mini=1e9 for i in range(n): l.append(list(map(int,input().split(' ')))) mini=min(mini,sum(l[i])*5+len(l[i])*15) print(mini)
20
31
102,400
215725327
n=int(input()) k=list(map(int,input().split())) b=[] for i in range(n): m=list(map(int,input().split())) t = sum(m)*5 + len(m)*15 b.append(t) print(min(b))
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Line to Cashier
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has ki p...
The first line contains integer n (1 ≤ n ≤ 100) — the number of cashes in the shop. The second line contains n space-separated integers: k1, k2, ..., kn (1 ≤ ki ≤ 100), where ki is the number of people in the queue to the i-th cashier. The i-th of the next n lines contains ki space-separated integers: mi, 1, mi, 2, .....
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
null
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
[{"input": "1\n1\n1", "output": "20"}, {"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100"}]
900
["implementation"]
20
[{"input": "1\r\n1\r\n1\r\n", "output": "20\r\n"}, {"input": "4\r\n1 4 3 2\r\n100\r\n1 2 2 3\r\n1 9 1\r\n7 8\r\n", "output": "100\r\n"}, {"input": "4\r\n5 4 5 5\r\n3 1 3 1 2\r\n3 1 1 3\r\n1 1 1 2 2\r\n2 2 1 1 3\r\n", "output": "100\r\n"}, {"input": "5\r\n5 3 6 6 4\r\n7 5 3 3 9\r\n6 8 2\r\n1 10 8 5 9 2\r\n9 7 8 5 9 10\r...
false
stdio
null
true
245/A
245
A
Python 3
TESTS
4
216
0
50897702
s1,r1=0,0 s2,r2=0,0 for _ in range(int(input())): t,s,l=map(int,input().split()) if t==1: s1+=10 r1+=s else: s2+=10 r2+=s if 2*r1>=s1: print('LIVE') else: print('DEAD') if 2*r2>=s1: print('LIVE') else: print('DEAD')
13
62
0
174286772
n_pings = int(input()) packets = [[0, 0], [0, 0]] # ((a_success, a_total), (b_success, b_total)) for _ in range(n_pings): t, x, y = map(int, input().split()) packets[t - 1][0] += x packets[t - 1][1] += x + y if packets[0][1] == 0 or packets[0][0] / packets[0][1] >= 0.5: print("LIVE") else: print("...
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
ICPC
2,012
2
256
System Administrator
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program re...
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti =...
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
null
Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this ...
[{"input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE"}, {"input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD"}]
800
["implementation"]
23
[{"input": "2\r\n1 5 5\r\n2 6 4\r\n", "output": "LIVE\r\nLIVE\r\n"}, {"input": "3\r\n1 0 10\r\n2 0 10\r\n1 10 0\r\n", "output": "LIVE\r\nDEAD\r\n"}, {"input": "10\r\n1 3 7\r\n2 4 6\r\n1 2 8\r\n2 5 5\r\n2 10 0\r\n2 10 0\r\n1 8 2\r\n2 2 8\r\n2 10 0\r\n1 1 9\r\n", "output": "DEAD\r\nLIVE\r\n"}, {"input": "11\r\n1 8 2\r\n1...
false
stdio
null
true
245/A
245
A
Python 3
TESTS
4
216
0
51288414
n=int(input()) a,b=0,0 sa,sb=0,0 for i in range(n): t,x,y=map(int,input().split()) if t==1: a+=x sa+=10 else: b+=x sb+=10 if a>=sa//2: print("LIVE") else: print("DEAD") if b>=sa//2: print("LIVE") else: print("DEAD")
13
78
102,400
3686050
n=int(input()) ta,tb,da,db=[0]*4 for i in range (n): t,x,y=map(int,input().split()) if t==1: ta+=(x+y) da+=y if (t==2): tb+=(x+y) db+=y if (ta-da>=0.5*ta): print ('LIVE') else : print ('DEAD') if (tb-db>=0.5*tb): print ('LIVE') else : print ('DEAD')
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
ICPC
2,012
2
256
System Administrator
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program re...
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti =...
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
null
Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this ...
[{"input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE"}, {"input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD"}]
800
["implementation"]
23
[{"input": "2\r\n1 5 5\r\n2 6 4\r\n", "output": "LIVE\r\nLIVE\r\n"}, {"input": "3\r\n1 0 10\r\n2 0 10\r\n1 10 0\r\n", "output": "LIVE\r\nDEAD\r\n"}, {"input": "10\r\n1 3 7\r\n2 4 6\r\n1 2 8\r\n2 5 5\r\n2 10 0\r\n2 10 0\r\n1 8 2\r\n2 2 8\r\n2 10 0\r\n1 1 9\r\n", "output": "DEAD\r\nLIVE\r\n"}, {"input": "11\r\n1 8 2\r\n1...
false
stdio
null
true
900/E
900
E
Python 3
TESTS
3
62
5,529,600
33391583
n = int(input()) s = list(input()) t = int(input()) re = s.copy() kras = 'ab' kras *= t kras = kras[:t] col = s.count('?') c = 0 v = 0 q = 0 h = 0 for i in range(2 ** col): shable = bin(i)[2:] priv = '0' * (col - len(shable)) priv += shable shable = priv for el in range(n): if s[el] == '?': ...
96
202
18,022,400
218078541
n = int(input()) s = input() m = int(input()) dp = [[0, 0] for _ in range(n+1)] c = [[0, 0] for _ in range(n+1)] q = [0] * (n+1) for i in range(1, n+1): q[i] = q[i-1] + (s[i-1] == '?') if s[i-1] != 'b': c[i][1] = c[i-1][0] + 1 if s[i-1] != 'a': c[i][0] = c[i-1][1] + 1 if c[i][m&1] >= m...
Codeforces Round 450 (Div. 2)
CF
2,017
2
256
Maximum Questions
Vasya wrote down two strings s of length n and t of length m consisting of small English letters 'a' and 'b'. What is more, he knows that string t has a form "abab...", namely there are letters 'a' on odd positions and letters 'b' on even positions. Suddenly in the morning, Vasya found that somebody spoiled his string...
The first line contains a single integer n (1 ≤ n ≤ 105) — the length of s. The second line contains the string s of length n. It contains small English letters 'a', 'b' and characters '?' only. The third line contains a single integer m (1 ≤ m ≤ 105) — the length of t. The string t contains letters 'a' on odd positi...
Print the only integer — the minimum number of replacements Vasya has to perform to make the beauty of string s the maximum possible.
null
In the first sample string t has a form 'a'. The only optimal option is to replace all characters '?' by 'a'. In the second sample using two replacements we can make string equal to "aba?aba??". It is impossible to get more than two occurrences.
[{"input": "5\nbb?a?\n1", "output": "2"}, {"input": "9\nab??ab???\n3", "output": "2"}]
2,100
["data structures", "dp", "strings"]
96
[{"input": "5\r\nbb?a?\r\n1\r\n", "output": "2\r\n"}, {"input": "9\r\nab??ab???\r\n3\r\n", "output": "2\r\n"}, {"input": "6\r\nab??ab\r\n4\r\n", "output": "2\r\n"}, {"input": "14\r\n?abaa?abb?b?a?\r\n3\r\n", "output": "3\r\n"}, {"input": "17\r\nb??a?abbbaaababba\r\n4\r\n", "output": "1\r\n"}, {"input": "1\r\nb\r\n1\r\n...
false
stdio
null
true
56/C
56
C
Python 3
TESTS
2
218
0
118316634
s = list(input()) tp = [] result = 0 for i in range(len(s) - 1, 0, -1): if '.' == s[i] and '.' != s[i - 1]: st = 0 for j in range(i - 1, 0, -1): if ':' == s[j] or ',' == s[j]: st = j + 1 break name = ''.join(s[st:i]) for j in range(i - 1,...
37
124
4,608,000
21246786
def P(): n=a[0];a.pop(0);d={n:1};r=0 while a[0]!='.': a.pop(0);l,t=P();r+=l for k in t.keys(): d[k]=d.get(k,0)+t[k] if k==n:r+=t[k] a.pop(0) return r,d a=[] x='' for i in input(): if i in ':.,': if x:a+=[x] a+=[i];x='' else:x+=i print(P()[0])
Codeforces Beta Round 52 (Div. 2)
CF
2,011
2
256
Corporation Mail
The Beroil corporation structure is hierarchical, that is it can be represented as a tree. Let's examine the presentation of this structure as follows: - employee ::= name. | name:employee1,employee2, ... ,employeek. - name ::= name of an employee That is, the description of each employee consists of his name, a colo...
The first and single line contains the corporation structure which is a string of length from 1 to 1000 characters. It is guaranteed that the description is correct. Every name is a string consisting of capital Latin letters from 1 to 10 symbols in length.
Print a single number — the number of uncomfortable situations in the company.
null
null
[{"input": "MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY...", "output": "3"}, {"input": "A:A..", "output": "1"}, {"input": "A:C:C:C:C.....", "output": "6"}]
1,700
["data structures", "expression parsing", "implementation"]
37
[{"input": "MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY...\r\n", "output": "3\r\n"}, {"input": "A:A..\r\n", "output": "1\r\n"}, {"input": "A:C:C:C:C.....\r\n", "output": "6\r\n"}, {"input": "CK:CK.,CK.,CK..\r\n", "output": "3\r\n"}, {"input": "FHMULVSDP:FHMULVSDP:FHMULVSDP:FHMULVSDP..,FHMULVSDP...\r\n", "output": "8\r...
false
stdio
null
true
68/B
68
B
PyPy 3-64
TESTS
2
92
0
206981059
n,k=map(int,input().split()) arr=list(map(int,input().split())) low=0 up=1000 ans=0 while low<=up: mid=(low+up)/2 extra=0 needed=0 for i in range(n): if arr[i]>=mid: extra+=(arr[i]-mid) else: needed+=(mid-arr[i]) if abs((extra-((k*extra)/100))-needed)<0.00...
42
124
4,915,200
132894228
(n, k), t = map(int, input().split()), sorted(map(int, input().split())) i, d, s = 1, t[0], sum(t) while i < n and (100 * s - k * (s - d)) > t[i] * (100 * n - k * (n - i)): d += t[i]; i += 1 print((100 * s - k * (s - d)) / (100 * n - k * (n - i)))
Codeforces Beta Round 62
CF
2,011
2
256
Energy exchange
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be...
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers. Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy. The absolute or relative error in the answer should not exceed 10 - 6.
null
null
[{"input": "3 50\n4 2 1", "output": "2.000000000"}, {"input": "2 90\n1 11", "output": "1.909090909"}]
1,600
["binary search"]
42
[{"input": "3 50\r\n4 2 1\r\n", "output": "2.000000000\r\n"}, {"input": "2 90\r\n1 11\r\n", "output": "1.909090909\r\n"}, {"input": "5 26\r\n42 65 23 43 64\r\n", "output": "45.415178571\r\n"}, {"input": "5 45\r\n964 515 454 623 594\r\n", "output": "594.109756098\r\n"}, {"input": "1 20\r\n784\r\n", "output": "784.000000...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read reference output with open(output_path, 'r') as f: ref_line = f.readline().strip() try: E_ref = float(ref_line) except: print(0) ...
true
629/A
629
A
Python 3
TESTS
2
31
0
169620810
n=int(input()) lst=[] total=0 for i in range(n): lst.append(input().lower()) def combination(count): if count>1: num=1 for k in range(3,count+1): num*=k else: num=0 return num for i in lst: count=0 for j in i: if j=='c': count+=1 total+...
48
46
0
136336208
def gkd(x): if x == 2: return 1 else: return x * (x - 1) / 2 n = int(input()) s = [input() for i in range(n)] sum_C = 0 for i in range(n): row_C = 0 # 行内C rank_C = 0 # 列内C for j in range(n): if s[i][j] == 'C': row_C += 1 if s[j][i] == 'C': r...
Codeforces Round 343 (Div. 2)
CF
2,016
1
256
Far Relative’s Birthday Cake
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started t...
In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
null
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3)
[{"input": "3\n.CC\nC..\nC.C", "output": "4"}, {"input": "4\nCC..\nC..C\n.CC.\n.CC.", "output": "9"}]
800
["brute force", "combinatorics", "constructive algorithms", "implementation"]
48
[{"input": "3\r\n.CC\r\nC..\r\nC.C\r\n", "output": "4\r\n"}, {"input": "4\r\nCC..\r\nC..C\r\n.CC.\r\n.CC.\r\n", "output": "9\r\n"}, {"input": "5\r\n.CCCC\r\nCCCCC\r\n.CCC.\r\nCC...\r\n.CC.C\r\n", "output": "46\r\n"}, {"input": "6\r\nC.CC.C\r\n..C..C\r\nC..C.C\r\n.CCC.C\r\nCC....\r\nCC....\r\n", "output": "39\r\n"}, {"i...
false
stdio
null
true
629/A
629
A
Python 3
TESTS
2
31
0
171530909
def fact(n): r = 1 for i in range(n): r *= (i + 1) return r n = int(input().strip()) c = [0] * n l = [0] * n for i in range(n): a = list(input().strip()) for j in range(n): if a[j] == 'C': l[i] += 1 c[j] += 1 r = 0 for i in range(n): r += fact(c[i]) // 2...
48
46
0
136336782
a=int(input()) s=[] n=0 sum=0 for i in range(a): m=input() s.append(m) for i in range(a): b=0 p=0 for j in range(a): if s[i][j]=='C': b=b+1 if s[j][i]=='C': p=p+1 sum=sum+((b-1)*b)/2 sum=sum+((p-1)*p)/2 print(int(sum))
Codeforces Round 343 (Div. 2)
CF
2,016
1
256
Far Relative’s Birthday Cake
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started t...
In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
null
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3)
[{"input": "3\n.CC\nC..\nC.C", "output": "4"}, {"input": "4\nCC..\nC..C\n.CC.\n.CC.", "output": "9"}]
800
["brute force", "combinatorics", "constructive algorithms", "implementation"]
48
[{"input": "3\r\n.CC\r\nC..\r\nC.C\r\n", "output": "4\r\n"}, {"input": "4\r\nCC..\r\nC..C\r\n.CC.\r\n.CC.\r\n", "output": "9\r\n"}, {"input": "5\r\n.CCCC\r\nCCCCC\r\n.CCC.\r\nCC...\r\n.CC.C\r\n", "output": "46\r\n"}, {"input": "6\r\nC.CC.C\r\n..C..C\r\nC..C.C\r\n.CCC.C\r\nCC....\r\nCC....\r\n", "output": "39\r\n"}, {"i...
false
stdio
null
true
629/A
629
A
Python 3
TESTS
2
31
0
171537347
def bolo(matriz, n): res = 0 for i in range(n): count = 0 for j in range(n): if matriz[i][j] == 'C': count += 1 if count >= 2: if count % 2 == 0: res += count // 2 else: res += count + 2 ...
48
46
0
136732796
n=int(input()) lst=[] m=0 s=0 for i in range(n): lst.append(list(input())) for i in range(n): for j in range(n): if lst[i][j]=='C': m+=1 s+=int(m*(m-1)/2) m=0 continue for i in range(n): for j in range(n): if lst[j][i]=='C': m+=1 s+=int(m*(m-1)/2) ...
Codeforces Round 343 (Div. 2)
CF
2,016
1
256
Far Relative’s Birthday Cake
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started t...
In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
null
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3)
[{"input": "3\n.CC\nC..\nC.C", "output": "4"}, {"input": "4\nCC..\nC..C\n.CC.\n.CC.", "output": "9"}]
800
["brute force", "combinatorics", "constructive algorithms", "implementation"]
48
[{"input": "3\r\n.CC\r\nC..\r\nC.C\r\n", "output": "4\r\n"}, {"input": "4\r\nCC..\r\nC..C\r\n.CC.\r\n.CC.\r\n", "output": "9\r\n"}, {"input": "5\r\n.CCCC\r\nCCCCC\r\n.CCC.\r\nCC...\r\n.CC.C\r\n", "output": "46\r\n"}, {"input": "6\r\nC.CC.C\r\n..C..C\r\nC..C.C\r\n.CCC.C\r\nCC....\r\nCC....\r\n", "output": "39\r\n"}, {"i...
false
stdio
null
true
558/D
558
D
Python 3
TESTS
4
233
2,150,400
31050327
# -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random """ created by shhuan at 2017/10/6 09:03 """ H, Q = map(int, input().split()) M1 = [] M2 = [] for i in range(Q): i, l, r, a = map(int, input().split()) if a: M1.append((i, l, r)) else: ...
90
779
50,688,000
155784759
import sys input = sys.stdin.buffer.readline def process(h, Q): L1, R1 = 2**(h-1), 2**h-1 Q1 = [] n = 0 for i, L, R, ans in Q: L2, R2 = 2**(h-i)*L, 2**(h-i)*R+2**(h-i)-1 if ans==0: Q1.append([L2, 0, n]) Q1.append([R2, 1, n]) n+=1 else: ...
Codeforces Round 312 (Div. 2)
CF
2,015
2
256
Guess Your Way Out! II
Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the nodes of the tree such tha...
The first line contains two integers h, q (1 ≤ h ≤ 50, 0 ≤ q ≤ 105), the height of the tree and the number of questions respectively. The next q lines will contain four integers each i, L, R, ans (1 ≤ i ≤ h, 2i - 1 ≤ L ≤ R ≤ 2i - 1, $$ans \in \{0, 1\}$$), representing a question as described in the statement with its ...
If the information provided by the game is contradictory output "Game cheated!" without the quotes. Else if you can uniquely identify the exit to the maze output its index. Otherwise output "Data not sufficient!" without the quotes.
null
Node u is an ancestor of node v if and only if - u is the same node as v, - u is the parent of node v, - or u is an ancestor of the parent of node v. In the first sample test there are 4 leaf nodes 4, 5, 6, 7. The first question says that the node isn't in the range [4, 6] so the exit is node number 7. In the second...
[{"input": "3 1\n3 4 6 0", "output": "7"}, {"input": "4 3\n4 10 14 1\n3 6 6 0\n2 3 3 1", "output": "14"}, {"input": "4 2\n3 4 6 1\n4 12 15 1", "output": "Data not sufficient!"}, {"input": "4 2\n3 4 5 1\n2 3 3 1", "output": "Game cheated!"}]
2,300
["data structures", "implementation", "sortings"]
90
[{"input": "3 1\r\n3 4 6 0\r\n", "output": "7"}, {"input": "4 3\r\n4 10 14 1\r\n3 6 6 0\r\n2 3 3 1\r\n", "output": "14"}, {"input": "4 2\r\n3 4 6 1\r\n4 12 15 1\r\n", "output": "Data not sufficient!"}, {"input": "4 2\r\n3 4 5 1\r\n2 3 3 1\r\n", "output": "Game cheated!"}, {"input": "1 0\r\n", "output": "1"}, {"input": ...
false
stdio
null
true
558/D
558
D
Python 3
TESTS
9
654
10,342,400
31102809
# -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random """ created by shhuan at 2017/10/6 09:03 """ H, Q = map(int, input().split()) LL = [2**(i-1) for i in range(H+1)] LR = [2**i-1 for i in range(H+1)] M1 = [] M2 = [] for i in range(Q): i, l, r, a = map(...
90
1,076
16,998,400
12062622
h,q=map(int,input().split()) d=[(2**h,0),(2**(h-1),0)] for _ in range(q): i,l,r,a=map(int,input().split()) l,r=l*2**(h-i),(r+1)*2**(h-i) d.extend([[(l,1),(r,-1)],[(0,1),(l,-1),(r,1)]][a]) s=0 l=0 d=sorted(d) for (a,x),(b,_) in zip(d,d[1:]): s+=x if a!=b and s==0:q=a;l+=b-a print(("Game cheated!",q,"Data not suffic...
Codeforces Round 312 (Div. 2)
CF
2,015
2
256
Guess Your Way Out! II
Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the nodes of the tree such tha...
The first line contains two integers h, q (1 ≤ h ≤ 50, 0 ≤ q ≤ 105), the height of the tree and the number of questions respectively. The next q lines will contain four integers each i, L, R, ans (1 ≤ i ≤ h, 2i - 1 ≤ L ≤ R ≤ 2i - 1, $$ans \in \{0, 1\}$$), representing a question as described in the statement with its ...
If the information provided by the game is contradictory output "Game cheated!" without the quotes. Else if you can uniquely identify the exit to the maze output its index. Otherwise output "Data not sufficient!" without the quotes.
null
Node u is an ancestor of node v if and only if - u is the same node as v, - u is the parent of node v, - or u is an ancestor of the parent of node v. In the first sample test there are 4 leaf nodes 4, 5, 6, 7. The first question says that the node isn't in the range [4, 6] so the exit is node number 7. In the second...
[{"input": "3 1\n3 4 6 0", "output": "7"}, {"input": "4 3\n4 10 14 1\n3 6 6 0\n2 3 3 1", "output": "14"}, {"input": "4 2\n3 4 6 1\n4 12 15 1", "output": "Data not sufficient!"}, {"input": "4 2\n3 4 5 1\n2 3 3 1", "output": "Game cheated!"}]
2,300
["data structures", "implementation", "sortings"]
90
[{"input": "3 1\r\n3 4 6 0\r\n", "output": "7"}, {"input": "4 3\r\n4 10 14 1\r\n3 6 6 0\r\n2 3 3 1\r\n", "output": "14"}, {"input": "4 2\r\n3 4 6 1\r\n4 12 15 1\r\n", "output": "Data not sufficient!"}, {"input": "4 2\r\n3 4 5 1\r\n2 3 3 1\r\n", "output": "Game cheated!"}, {"input": "1 0\r\n", "output": "1"}, {"input": ...
false
stdio
null
true
557/D
557
D
Python 3
PRETESTS
2
62
204,800
11865621
__author__ = 'Andrey' import sys sys.setrecursionlimit(100500) n, m = map(int, input().split()) g = dict() for i in range(1, n + 1): g[i] = set() for i in range(m): a, b = map(int, input().split()) g[a].add(b) g[b].add(a) bad_graph = False color = [0] * (n + 1) def dfs(u): global bad_graph for...
50
686
15,769,600
15261645
n, m = [int(x) for x in input().split()] E = {i:[] for i in range(n)} for i in range(m): u, v = [int(x)-1 for x in input().split()] E[v].append(u) E[u].append(v) def dfs(): visited = [False for i in range(n)] colour = [0 for i in range(n)] ans = 0 for v in range(n): if visited[v]: c...
Codeforces Round 311 (Div. 2)
CF
2,015
1
256
Vitaly and Cycle
After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once. Vitaly was wondering how to solve the following problem. You are given an undirected graph consisting of n vertices and m edges, not ne...
The first line of the input contains two integers n and m ($$3 \leq n \leq 10^5, 0 \leq m \leq \min\left(\frac{n(n-1)}{2}, 10^5\right)$$ — the number of vertices in the graph and the number of edges in the graph. Next m lines contain the descriptions of the edges of the graph, one edge per line. Each edge is given by ...
Print in the first line of the output two space-separated integers t and w — the minimum number of edges that should be added to the graph to form a simple cycle of an odd length consisting of more than one vertex where each vertex occurs at most once, and the number of ways to do this.
null
The simple cycle is a cycle that doesn't contain any vertex twice.
[{"input": "4 4\n1 2\n1 3\n4 2\n4 3", "output": "1 2"}, {"input": "3 3\n1 2\n2 3\n3 1", "output": "0 1"}, {"input": "3 0", "output": "3 1"}]
2,000
["combinatorics", "dfs and similar", "graphs", "math"]
50
[{"input": "4 4\r\n1 2\r\n1 3\r\n4 2\r\n4 3\r\n", "output": "1 2\r\n"}, {"input": "3 3\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "0 1\r\n"}, {"input": "3 0\r\n", "output": "3 1\r\n"}, {"input": "6 3\r\n1 2\r\n4 3\r\n6 5\r\n", "output": "2 12\r\n"}, {"input": "100000 0\r\n", "output": "3 166661666700000\r\n"}, {"input": "5 4...
false
stdio
null
true
69/C
69
C
Python 3
TESTS
3
186
307,200
52240941
k, n, m, q = [int(i) for i in input().split()] basic = [input() for i in range(n)] composite = {} for i in range(m): name, items = input().split(":") composite[name] = {} for item in items.split(","): component, cnt = item.split() composite[name][component] = int(cnt) friends = {} for i in range(1, k+1): fri...
47
154
5,324,800
16947235
k,m,n,q = map(int, input().split()) basic = [input() for _ in range(m)] from collections import Counter, defaultdict recipes, accounts = defaultdict(Counter), defaultdict(Counter) for _ in range(n): composite, components = input().split(': ') for unit in components.split(', '): x, y = unit.split() ...
Codeforces Beta Round 63 (Div. 2)
CF
2,011
2
256
Game
In one school with Vasya there is a student Kostya. Kostya does not like physics, he likes different online games. Every day, having come home, Kostya throws his bag in the farthest corner and sits down at his beloved computer. Kostya even eats glued to the game. A few days ago Kostya bought a new RPG game "HaresButtle...
The first line has 4 natural numbers: k (1 ≤ k ≤ 100) — the number of Kostya's allies, n (1 ≤ n ≤ 50) — the number of basic artifacts, m (0 ≤ m ≤ 50) — the number of composite artifacts, q (1 ≤ q ≤ 500) — the number of his friends' purchases. The following n lines contain the names of basic artifacts. After them m line...
The output file should consist of k blocks. The first line should contain number bi — the number of different artifacts the i-th ally has. Then the block should contain bi lines with the names of these artifacts and the number of these artifacts. At that the lines should be printed in accordance with the lexicographica...
null
null
[{"input": "2 3 2 5\ndesolator\nrefresher\nperseverance\nvanguard: desolator 1, refresher 1\nmaelstorm: perseverance 2\n1 desolator\n2 perseverance\n1 refresher\n2 desolator\n2 perseverance", "output": "1\nvanguard 1\n2\ndesolator 1\nmaelstorm 1"}]
2,000
["implementation"]
47
[{"input": "2 3 2 5\r\ndesolator\r\nrefresher\r\nperseverance\r\nvanguard: desolator 1, refresher 1\r\nmaelstorm: perseverance 2\r\n1 desolator\r\n2 perseverance\r\n1 refresher\r\n2 desolator\r\n2 perseverance\r\n", "output": "1\r\nvanguard 1\r\n2\r\ndesolator 1\r\nmaelstorm 1\r\n"}, {"input": "2 3 2 5\r\na\r\nb\r\nc\r...
false
stdio
null
true
689/D
689
D
PyPy 3
TESTS
3
217
30,515,200
129883529
#!/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) # _INPUT = """3 # 1 1 1 # 1 1 1 # """ # sys.stdin = io.StringIO(_INPUT) I...
94
780
29,798,400
159329328
import bisect import copy import gc import itertools from array import array from fractions import Fraction import heapq import math import operator import os, sys import profile import cProfile import random import re import string from bisect import bisect_left, bisect_right from collections import defaultdict, deque...
Codeforces Round 361 (Div. 2)
CF
2,016
2
512
Friends and Subsequences
Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows? Every one of them has an integer sequences a and b of length n. Being given a query of the form of pair of integers (l, r)...
The first line contains only integer n (1 ≤ n ≤ 200 000). The second line contains n integer numbers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the sequence a. The third line contains n integer numbers b1, b2, ..., bn ( - 109 ≤ bi ≤ 109) — the sequence b.
Print the only integer number — the number of occasions the robot will count, thus for how many pairs $$\max_{i=l}^{r}a_i = \min_{i=l}^{r}b_i$$ is satisfied.
null
The occasions in the first sample case are: 1.l = 4,r = 4 since max{2} = min{2}. 2.l = 4,r = 5 since max{2, 1} = min{2, 3}. There are no occasions in the second sample case since Mike will answer 3 to any query pair, but !Mike will always answer 1.
[{"input": "6\n1 2 3 2 1 4\n6 7 1 2 3 2", "output": "2"}, {"input": "3\n3 3 3\n1 1 1", "output": "0"}]
2,100
["binary search", "data structures"]
94
[{"input": "6\r\n1 2 3 2 1 4\r\n6 7 1 2 3 2\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 3\r\n1 1 1\r\n", "output": "0\r\n"}, {"input": "17\r\n714413739 -959271262 714413739 -745891378 926207665 -404845105 -404845105 -959271262 -189641729 -670860364 714413739 -189641729 192457837 -745891378 -670860364 536388097 -95927...
false
stdio
null
true
689/D
689
D
Python 3
TESTS
3
109
0
58705779
def solve(): n=int(input()) a=[int(x) for x in input().split()] b=[int(x) for x in input().split()] maxi=a[0] mini=b[0] count=0 mxi=0 mni=0 if maxi==mini: count+=1 flag=0 for i in range(1,n): if flag==1: maxi=a[i] mini=b[i] ...
94
982
456,908,800
159169002
dx=[[0]*(1<<20) for _ in range(20)] dy=[[0]*(1<<20) for _ in range(20)] lg=[0]*(1<<20) def mx(l,r): p=lg[r-l+1] return max(dx[p][l],dx[p][r-(1<<p)+1]) def mn(l,r): p=lg[r-l+1] return min(dy[p][l],dy[p][r-(1<<p)+1]) if __name__ == '__main__': n=int(input()) dx[0][1:n]=[int(x) for x in input()...
Codeforces Round 361 (Div. 2)
CF
2,016
2
512
Friends and Subsequences
Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows? Every one of them has an integer sequences a and b of length n. Being given a query of the form of pair of integers (l, r)...
The first line contains only integer n (1 ≤ n ≤ 200 000). The second line contains n integer numbers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the sequence a. The third line contains n integer numbers b1, b2, ..., bn ( - 109 ≤ bi ≤ 109) — the sequence b.
Print the only integer number — the number of occasions the robot will count, thus for how many pairs $$\max_{i=l}^{r}a_i = \min_{i=l}^{r}b_i$$ is satisfied.
null
The occasions in the first sample case are: 1.l = 4,r = 4 since max{2} = min{2}. 2.l = 4,r = 5 since max{2, 1} = min{2, 3}. There are no occasions in the second sample case since Mike will answer 3 to any query pair, but !Mike will always answer 1.
[{"input": "6\n1 2 3 2 1 4\n6 7 1 2 3 2", "output": "2"}, {"input": "3\n3 3 3\n1 1 1", "output": "0"}]
2,100
["binary search", "data structures"]
94
[{"input": "6\r\n1 2 3 2 1 4\r\n6 7 1 2 3 2\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 3\r\n1 1 1\r\n", "output": "0\r\n"}, {"input": "17\r\n714413739 -959271262 714413739 -745891378 926207665 -404845105 -404845105 -959271262 -189641729 -670860364 714413739 -189641729 192457837 -745891378 -670860364 536388097 -95927...
false
stdio
null
true
455/B
455
B
Python 3
TESTS
4
31
0
221607145
n, k = map(int, input().split()) if k % 2 == 0: print('Second') else: print('First')
75
920
6,451,200
7386129
""" Codeforces Contest 260 Div 1 Problem B Author : chaotic_iak Language: Python 3.3.4 """ def main(): n,k = read() s = set() for i in range(n): s.add(read(0)) s = list(s) s.sort() s = treeify(s) res = solve(s) if res == 0: # neither: second player win print("Second") if r...
Codeforces Round 260 (Div. 1)
CF
2,014
1
256
A Lot of Games
Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players. Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his step player must add a single letter in the end of the word, the re...
The first line contains two integers, n and k (1 ≤ n ≤ 105; 1 ≤ k ≤ 109). Each of the next n lines contains a single non-empty string from the given group. The total length of all strings from the group doesn't exceed 105. Each string of the group consists only of lowercase English letters.
If the player who moves first wins, print "First", otherwise print "Second" (without the quotes).
null
null
[{"input": "2 3\na\nb", "output": "First"}, {"input": "3 1\na\nb\nc", "output": "First"}, {"input": "1 2\nab", "output": "Second"}]
1,900
["dfs and similar", "dp", "games", "implementation", "strings", "trees"]
75
[{"input": "2 3\r\na\r\nb\r\n", "output": "First\r\n"}, {"input": "3 1\r\na\r\nb\r\nc\r\n", "output": "First\r\n"}, {"input": "1 2\r\nab\r\n", "output": "Second\r\n"}, {"input": "5 6\r\nabas\r\ndsfdf\r\nabacaba\r\ndartsidius\r\nkolobok\r\n", "output": "Second\r\n"}, {"input": "4 2\r\naaaa\r\nbbbb\r\nccccc\r\ndumbavumba...
false
stdio
null
true
22/D
22
D
Python 3
TESTS
1
31
0
149816631
n = int(input()) intervale = [] for _ in range(n): x, y = input().split() intervale.append((int(x), int(y))) # Inversarea capetelor for i, interval in enumerate(intervale): st, dr = interval if st > dr: interval = (dr, st) intervale[i] = interval # Sortare dupa capatul din dreapta interva...
40
78
0
203572165
def main(): n = int(input()) segments = [] for _ in range(n): segments.append(tuple(sorted(map(int, input().split())))) nails = [] segments.sort(key=lambda x: x[1]) while segments: nail = segments[0][1] nails.append(nail) segments = [segment for segment in segmen...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
1
256
Segments
You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails need...
The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points.
The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.
null
null
[{"input": "2\n0 2\n2 5", "output": "1\n2"}, {"input": "5\n0 3\n4 2\n4 8\n8 10\n7 7", "output": "3\n7 10 3"}]
1,900
["greedy", "sortings"]
40
[{"input": "2\r\n0 2\r\n2 5\r\n", "output": "1\r\n2 "}, {"input": "5\r\n0 3\r\n4 2\r\n4 8\r\n8 10\r\n7 7\r\n", "output": "3\r\n3 7 10 "}, {"input": "3\r\n40 -83\r\n52 -80\r\n-21 -4\r\n", "output": "1\r\n-4 "}, {"input": "4\r\n67 -88\r\n37 -62\r\n-26 91\r\n-99 -50\r\n", "output": "2\r\n-50 91 "}, {"input": "5\r\n45 58\r...
false
stdio
null
true
802/B
802
B
PyPy 3
TESTS
3
92
102,400
106896922
import sys input = sys.stdin.readline from collections import deque, defaultdict from heapq import heappush, heappop n, k = map(int, input().split()) A = list(map(int, input().split())) dic = defaultdict(deque) for i, a in enumerate(A): dic[a].append(i) S = set() ans = 0 hp = [] for d in dic: heappush(hp, (-dic...
50
2,744
91,443,200
60347194
# https://codeforces.com/problemset/problem/802/B import heapq n, k = map(int, input().split()) a = list(map(int, input().split())) d = {} pos = {} Q = [] cnt = 0 for i, x in enumerate(a): if x not in pos: pos[x] = [] pos[x].append(i) for i, x in enumerate(a): if x not in...
Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
ICPC
2,017
10
256
Heidi and Library (medium)
Whereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences.
Same as the easy version, but the limits have changed: 1 ≤ n, k ≤ 400 000.
Same as the easy version.
null
null
[{"input": "4 100\n1 2 2 1", "output": "2"}, {"input": "4 1\n1 2 2 1", "output": "3"}, {"input": "4 2\n1 2 3 1", "output": "3"}]
1,800
["data structures", "greedy"]
50
[{"input": "4 100\r\n1 2 2 1\r\n", "output": "2\r\n"}, {"input": "4 1\r\n1 2 2 1\r\n", "output": "3\r\n"}, {"input": "4 2\r\n1 2 3 1\r\n", "output": "3\r\n"}, {"input": "11 1\r\n1 2 3 5 1 10 10 1 1 3 5\r\n", "output": "9\r\n"}, {"input": "5 2\r\n1 2 3 1 2\r\n", "output": "4\r\n"}, {"input": "4 2\r\n1 2 3 2\r\n", "outpu...
false
stdio
null
true
799/C
799
C
PyPy 3
TESTS
3
124
0
97239176
inven = str(input()).split(" ") coins = [] diamonds = [] smuk = [] for x in range(int(inven[0])): tain = input().split(" ") if str(tain[2]) == "C": coins.append(tain) if str(tain[2]) == "D": diamonds.append(tain) coinsAvai = [] diamondsAvai = [] for x in coins: if int(x[1]) <= int(inven...
79
748
13,107,200
212867129
import operator fc = [] fd = [] n, c, d = map(int,input().split()) for _ in range(n): b, p, m = input().split() b, p = int(b), int(p) if m == 'C': if p <= c: fc.append((b, p)) else: if p <= d: fd.append((b, p)) fc.sort(key=operator.itemgetter(0), reverse=True) fd...
Playrix Codescapes Cup (Codeforces Round 413, rated, Div. 1 + Div. 2)
CF
2,017
2
256
Fountains
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allow...
The first line contains three integers n, c and d (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 000) — the number of fountains, the number of coins and diamonds Arkady has. The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 ≤ bi, pi ≤ 100 000) — the beauty and the cost of the i-th fountain, ...
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
null
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9. In the second example t...
[{"input": "3 7 6\n10 8 C\n4 3 C\n5 6 D", "output": "9"}, {"input": "2 4 5\n2 5 C\n2 1 D", "output": "0"}, {"input": "3 10 10\n5 5 C\n5 5 C\n10 11 D", "output": "10"}]
1,800
["binary search", "data structures", "implementation"]
79
[{"input": "3 7 6\r\n10 8 C\r\n4 3 C\r\n5 6 D\r\n", "output": "9\r\n"}, {"input": "2 4 5\r\n2 5 C\r\n2 1 D\r\n", "output": "0\r\n"}, {"input": "3 10 10\r\n5 5 C\r\n5 5 C\r\n10 11 D\r\n", "output": "10\r\n"}, {"input": "6 68 40\r\n1 18 D\r\n6 16 D\r\n11 16 D\r\n7 23 D\r\n16 30 D\r\n2 20 D\r\n", "output": "18\r\n"}, {"in...
false
stdio
null
true
689/E
689
E
PyPy 3
TESTS
6
140
33,587,200
129502134
p = int(1e9+7) N = 200000 fact= [1]*(N+1) for i in range(2,N+1): fact[i]=(fact[i-1]*i)%p def bpow(a,b): global p c = 1 while b>0: if b&1: c=(c*a)%p a = (a*a)%p b = b>>1 return c def inv(a): global p return bpow(a,p-2) def bino(n,k): global fact,p ret...
69
810
80,281,600
197273749
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def comb(n, r): return fact[n] * inv[r] % mod * inv[n - r] % mod if n >= r >= 0 else 0 n, k = map(int, input().split()) mod = pow(10, 9) + 7 l = n + 5 fact = [1] * (l + 1) for i in range(1, l + 1): fact[i] = i * fact[i - 1] % mod ...
Codeforces Round 361 (Div. 2)
CF
2,016
3
256
Mike and Geometry Problem
Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that $$f(\varnothing) = 0$$). You are given two integers n and k and n closed intervals [li, ri...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 200 000) — the number of segments and the number of segments in intersection groups respectively. Then n lines follow, the i-th line contains two integers li, ri ( - 109 ≤ li ≤ ri ≤ 109), describing i-th segment bounds.
Print one integer number — the answer to Mike's problem modulo 1000000007 (109 + 7) in the only line.
null
In the first example: $$f([1,2]\cap[1,3])=f([1,2])=2$$; $$f([1,2]\cap[2,3])=f([2,2])=1$$; $$f([1,3]\cap[2,3])=f([2,3])=2$$. So the answer is 2 + 1 + 2 = 5.
[{"input": "3 2\n1 2\n1 3\n2 3", "output": "5"}, {"input": "3 3\n1 3\n1 3\n1 3", "output": "3"}, {"input": "3 1\n1 2\n2 3\n3 4", "output": "6"}]
2,000
["combinatorics", "data structures", "dp", "geometry", "implementation"]
69
[{"input": "3 2\r\n1 2\r\n1 3\r\n2 3\r\n", "output": "5\r\n"}, {"input": "3 3\r\n1 3\r\n1 3\r\n1 3\r\n", "output": "3\r\n"}, {"input": "3 1\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "6\r\n"}, {"input": "1 1\r\n45 70\r\n", "output": "26\r\n"}, {"input": "1 1\r\n-35 -8\r\n", "output": "28\r\n"}, {"input": "1 1\r\n-79 -51\r\n"...
false
stdio
null
true
802/J
802
J
PyPy 3-64
TESTS
29
61
1,638,400
211584191
from sys import stdin,stdout # from bisect import bisect_left,bisect # from heapq import heapify,heappop,heappush # from sys import setrecursionlimit # from collections import defaultdict,Counter # from itertools import permutations # from math import gcd,ceil,sqrt,factorial # setrecursionlimit(int(1e5)) input,print = ...
32
46
0
196223605
def solve(): n = int(input()) a = [0] * n for i in range(n - 1): a[i] = list(map(int, input().split())) p = [-2] * n ct = [0] * n p[0] = -1 for j in range(n - 1): for i in range(n - 1): u, v, c = a[i] if p[u] != -2 and p[v] == -2: p[v]...
Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
ICPC
2,017
1
256
Send the Fool Further! (easy)
Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to d...
The first line of the input contains the number of friends n (3 ≤ n ≤ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≤ u, v ≤ n - 1, 1 ≤ c ≤ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that th...
Output a single integer – the maximum sum of costs.
null
In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2).
[{"input": "4\n0 1 4\n0 2 2\n2 3 3", "output": "5"}, {"input": "6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10", "output": "105"}, {"input": "11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378", "output": "5551"}]
1,400
["dfs and similar", "graphs", "trees"]
32
[{"input": "4\r\n0 1 4\r\n0 2 2\r\n2 3 3\r\n", "output": "5\r\n"}, {"input": "3\r\n1 0 5987\r\n2 0 8891\r\n", "output": "8891\r\n"}, {"input": "10\r\n1 0 518\r\n2 0 4071\r\n3 1 121\r\n4 2 3967\r\n5 3 9138\r\n6 2 9513\r\n7 3 3499\r\n8 2 2337\r\n9 4 7647\r\n", "output": "15685\r\n"}, {"input": "11\r\n1 0 6646\r\n2 0 8816...
false
stdio
null
true
22/D
22
D
PyPy 3-64
TESTS
1
46
0
223732007
arr=[] n=int(input()) for _ in range(n): l,r=map(int,input().split()) arr.append([l,r]) arr.sort(key=lambda x:(x[1])) ans=0 p=-float("inf") res=[] for el in arr: l,r=el[0],el[1] l,r=min(l,r),max(l,r) if l>p: ans+=1 res.append(r) p=max(p,r) print(ans) print(*res)
40
93
1,945,600
145964552
from collections import defaultdict import sys input = sys.stdin.readline n = int(input()) x = defaultdict(lambda : []) for _ in range(n): l, r = map(int, input().split()) if l > r: l, r = r, l x[r].append(l) ans = [] u = -10005 for r in sorted(x.keys()): for l in x[r]: if u < l: ...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
1
256
Segments
You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails need...
The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points.
The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.
null
null
[{"input": "2\n0 2\n2 5", "output": "1\n2"}, {"input": "5\n0 3\n4 2\n4 8\n8 10\n7 7", "output": "3\n7 10 3"}]
1,900
["greedy", "sortings"]
40
[{"input": "2\r\n0 2\r\n2 5\r\n", "output": "1\r\n2 "}, {"input": "5\r\n0 3\r\n4 2\r\n4 8\r\n8 10\r\n7 7\r\n", "output": "3\r\n3 7 10 "}, {"input": "3\r\n40 -83\r\n52 -80\r\n-21 -4\r\n", "output": "1\r\n-4 "}, {"input": "4\r\n67 -88\r\n37 -62\r\n-26 91\r\n-99 -50\r\n", "output": "2\r\n-50 91 "}, {"input": "5\r\n45 58\r...
false
stdio
null
true
22/D
22
D
Python 3
TESTS
1
46
0
150060011
n = int(input()) ls = [] batut = [] cuie = 0 for i in range(n): ls.append(list(map(int,input().split()))) for x in ls: if x[0]>x[1]: (x[0],x[1])=(x[1],x[0]) ls_sorted = sorted(ls,key=lambda x: (int(x[0]),int(x[1]))) intersection = list(ls_sorted[0]) if n>1: for i in range(1,n): if intersec...
40
93
3,174,400
195774981
intervals = [] n = int(input()) for x in range(n): a,b = [int(x) for x in input().split()] if a > b: intervals.append([b,a]) else: intervals.append([a,b]) intervals.sort() st = intervals[0][0] ed = intervals[0][1] ans = [] for x in range(1, n): if intervals[x][0] <= ed: st = inte...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
1
256
Segments
You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails need...
The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points.
The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.
null
null
[{"input": "2\n0 2\n2 5", "output": "1\n2"}, {"input": "5\n0 3\n4 2\n4 8\n8 10\n7 7", "output": "3\n7 10 3"}]
1,900
["greedy", "sortings"]
40
[{"input": "2\r\n0 2\r\n2 5\r\n", "output": "1\r\n2 "}, {"input": "5\r\n0 3\r\n4 2\r\n4 8\r\n8 10\r\n7 7\r\n", "output": "3\r\n3 7 10 "}, {"input": "3\r\n40 -83\r\n52 -80\r\n-21 -4\r\n", "output": "1\r\n-4 "}, {"input": "4\r\n67 -88\r\n37 -62\r\n-26 91\r\n-99 -50\r\n", "output": "2\r\n-50 91 "}, {"input": "5\r\n45 58\r...
false
stdio
null
true
898/C
898
C
PyPy 3
TESTS
6
156
1,331,200
81941643
d={} for _ in range(int(input())): v=list(map(str,input().split())) ss=v[0] d[ss]=d.get(ss,set()) d[ss]|=set(v[2:]) print(len(d)) for ss in d: l2=list(d[ss]) for i in range(len(l2)): for j in range(len(l2)): s=str(l2[j]) if len(l2[j])>len(l2[i]) and s[-len(l...
59
62
0
177467140
""" Prositka 10.10.2022""" n=int(input()) d=dict() for i in range(n): a=input().split() if a[0] not in d: d[a[0]]=[] for j in range(2, len(a)): a[j]=a[j][::-1] d[a[0]]+=a[2:] print(len(d)) for x in d: a=d[x] a.sort(reverse=True) b=[a[0]] for i in range(1, len(a)): ...
Codeforces Round 451 (Div. 2)
CF
2,017
2
256
Phone Numbers
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a fri...
First line contains the integer n (1 ≤ n ≤ 20) — number of entries in Vasya's phone books. The following n lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English lett...
Print out the ordered information about the phone numbers of Vasya's friends. First output m — number of friends that are found in Vasya's phone books. The following m lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each rec...
null
null
[{"input": "2\nivan 1 00123\nmasha 1 00123", "output": "2\nmasha 1 00123\nivan 1 00123"}, {"input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "output": "3\nkatya 1 612\npetr 1 12\nkarl 1 612"}, {"input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789", "output": "2\ndasha 2 23 789...
1,400
["implementation", "strings"]
59
[{"input": "2\r\nivan 1 00123\r\nmasha 1 00123\r\n", "output": "2\r\nmasha 1 00123 \r\nivan 1 00123 \r\n"}, {"input": "3\r\nkarl 2 612 12\r\npetr 1 12\r\nkatya 1 612\r\n", "output": "3\r\nkatya 1 612 \r\npetr 1 12 \r\nkarl 1 612 \r\n"}, {"input": "4\r\nivan 3 123 123 456\r\nivan 2 456 456\r\nivan 8 789 3 23 6 56 9 89 2...
false
stdio
import sys from collections import defaultdict def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input and build friends data friends = defaultdict(set) with open(input_path, 'r') as f: n = int(f.readline()) for _ in range(n): ...
true
898/C
898
C
PyPy 3
TESTS
17
108
1,945,600
120272370
n = int(input()) d = {} for i in range(n): name, t, *ages = list(map(str, input().split())) for i in ages: if name not in d: d[name] = [i] else: d[name] += [i] k = {} for i in d: for j in range(1,len(d[i])): for z in d[i]: if(len(d[i][j]) < len(z...
59
62
1,638,400
205044505
n = int(input()) my_dict = {} for _ in range(n): mix = input() lis = [] name, nop, *lis = mix.split(" ") if name in my_dict: my_dict[name].extend(lis) else: my_dict[name] = lis print(len(my_dict)) for name, lis in my_dict.items(): lis.sort(key=len) i = 0 f = 0 while...
Codeforces Round 451 (Div. 2)
CF
2,017
2
256
Phone Numbers
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a fri...
First line contains the integer n (1 ≤ n ≤ 20) — number of entries in Vasya's phone books. The following n lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English lett...
Print out the ordered information about the phone numbers of Vasya's friends. First output m — number of friends that are found in Vasya's phone books. The following m lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each rec...
null
null
[{"input": "2\nivan 1 00123\nmasha 1 00123", "output": "2\nmasha 1 00123\nivan 1 00123"}, {"input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "output": "3\nkatya 1 612\npetr 1 12\nkarl 1 612"}, {"input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789", "output": "2\ndasha 2 23 789...
1,400
["implementation", "strings"]
59
[{"input": "2\r\nivan 1 00123\r\nmasha 1 00123\r\n", "output": "2\r\nmasha 1 00123 \r\nivan 1 00123 \r\n"}, {"input": "3\r\nkarl 2 612 12\r\npetr 1 12\r\nkatya 1 612\r\n", "output": "3\r\nkatya 1 612 \r\npetr 1 12 \r\nkarl 1 612 \r\n"}, {"input": "4\r\nivan 3 123 123 456\r\nivan 2 456 456\r\nivan 8 789 3 23 6 56 9 89 2...
false
stdio
import sys from collections import defaultdict def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input and build friends data friends = defaultdict(set) with open(input_path, 'r') as f: n = int(f.readline()) for _ in range(n): ...
true
261/A
261
A
Python 3
TESTS
3
218
0
56447570
class CodeforcesTask261ASolution: def __init__(self): self.result = '' self.discounts = [] self.items_count = 0 self.prices = [] def read_input(self): input() self.discounts = [int(x) for x in input().split(" ")] self.items_count = int(input()) se...
45
248
19,046,400
180432352
m = int(input()) q = list(map(int, input().split())) n = int(input()) l = sorted(list(map(int, input().split()))) cost, mini = 0, min(q) while len(l)!=0: for i in range(min(len(l), mini)): cost+=l.pop() #Buy Items for i in range(min(len(l), 2)): l.pop() # get Items in discount print(cost)
Codeforces Round 160 (Div. 1)
CF
2,013
2
256
Maxim and Discounts
Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems. There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a special basket, where he puts exactly qi items he buys. Under the term...
The first line contains integer m (1 ≤ m ≤ 105) — the number of discount types. The second line contains m integers: q1, q2, ..., qm (1 ≤ qi ≤ 105). The third line contains integer n (1 ≤ n ≤ 105) — the number of items Maxim needs. The fourth line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ 104) — the items' prices...
In a single line print a single integer — the answer to the problem.
null
In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200. In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150.
[{"input": "1\n2\n4\n50 50 100 100", "output": "200"}, {"input": "2\n2 3\n5\n50 50 50 50 50", "output": "150"}, {"input": "1\n1\n7\n1 1 1 1 1 1 1", "output": "3"}]
1,400
["greedy", "sortings"]
45
[{"input": "1\r\n2\r\n4\r\n50 50 100 100\r\n", "output": "200\r\n"}, {"input": "2\r\n2 3\r\n5\r\n50 50 50 50 50\r\n", "output": "150\r\n"}, {"input": "1\r\n1\r\n7\r\n1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "18\r\n16 16 20 12 13 10 14 15 4 5 6 8 4 11 12 11 16 7\r\n15\r\n371 2453 905 1366 6471 4331 4106 2570 46...
false
stdio
null
true
689/D
689
D
Python 3
TESTS
6
1,638
38,092,800
19186358
from bisect import bisect HISENTINEL = 10**9 + 1 LOSENTINEL = -HISENTINEL def main(): length = int(input()) a = [int(fld) for fld in input().strip().split()] b = [int(fld) for fld in input().strip().split()] print(countmaxminsubseq(a, b)) def countmaxminsubseq(a, b): leq, lgt = getleftbounds(...
94
780
29,798,400
159329328
import bisect import copy import gc import itertools from array import array from fractions import Fraction import heapq import math import operator import os, sys import profile import cProfile import random import re import string from bisect import bisect_left, bisect_right from collections import defaultdict, deque...
Codeforces Round 361 (Div. 2)
CF
2,016
2
512
Friends and Subsequences
Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows? Every one of them has an integer sequences a and b of length n. Being given a query of the form of pair of integers (l, r)...
The first line contains only integer n (1 ≤ n ≤ 200 000). The second line contains n integer numbers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the sequence a. The third line contains n integer numbers b1, b2, ..., bn ( - 109 ≤ bi ≤ 109) — the sequence b.
Print the only integer number — the number of occasions the robot will count, thus for how many pairs $$\max_{i=l}^{r}a_i = \min_{i=l}^{r}b_i$$ is satisfied.
null
The occasions in the first sample case are: 1.l = 4,r = 4 since max{2} = min{2}. 2.l = 4,r = 5 since max{2, 1} = min{2, 3}. There are no occasions in the second sample case since Mike will answer 3 to any query pair, but !Mike will always answer 1.
[{"input": "6\n1 2 3 2 1 4\n6 7 1 2 3 2", "output": "2"}, {"input": "3\n3 3 3\n1 1 1", "output": "0"}]
2,100
["binary search", "data structures"]
94
[{"input": "6\r\n1 2 3 2 1 4\r\n6 7 1 2 3 2\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 3\r\n1 1 1\r\n", "output": "0\r\n"}, {"input": "17\r\n714413739 -959271262 714413739 -745891378 926207665 -404845105 -404845105 -959271262 -189641729 -670860364 714413739 -189641729 192457837 -745891378 -670860364 536388097 -95927...
false
stdio
null
true
545/E
545
E
PyPy 3-64
TESTS
7
2,261
139,059,200
228111453
from collections import deque from heapq import * mod = 1000000007 time = 0 def solve(): n,m = map(int,input().split()) adj = [[]for i in range(n+1)] edges = [] for i in range(m): a,b,c = map(int,input().split()) edges.append((a,b,c)) adj[a].append((b,c)) adj[b].append((a,c)) u = int(input()) pq = [] di...
62
2,635
76,288,000
184261586
import heapq n, m = map(int, input().split()) g = [[] for _ in range(n + 1)] for i in range(1, m + 1): u, v, w = map(int, input().split()) g[u].append((i, v, w)) g[v].append((i, u, w)) src = int(input()) pq = [(0, 0, src, -1)] mk = [0] * (n + 1) t = [] s = 0 while pq: d, w, u, e = heapq.heappop(pq) ...
Codeforces Round 303 (Div. 2)
CF
2,015
3
256
Paths and Trees
Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to ask you about it. So, the problem statement is as follows. Let's assume that we are given a c...
The first line contains two numbers, n and m (1 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of vertices and edges of the graph, respectively. Next m lines contain three integers each, representing an edge — ui, vi, wi — the numbers of vertices connected by an edge and the weight of the edge (ui ≠ vi, 1 ≤ wi ≤ 109). It is...
In the first line print the minimum total weight of the edges of the tree. In the next line print the indices of the edges that are included in the tree, separated by spaces. The edges are numbered starting from 1 in the order they follow in the input. You may print the numbers of the edges in any order. If there are...
null
In the first sample there are two possible shortest path trees: - with edges 1 – 3 and 2 – 3 (the total weight is 3); - with edges 1 – 2 and 2 – 3 (the total weight is 2); And, for example, a tree with edges 1 – 2 and 1 – 3 won't be a shortest path tree for vertex 3, because the distance from vertex 3 to vertex 2 in ...
[{"input": "3 3\n1 2 1\n2 3 1\n1 3 2\n3", "output": "2\n1 2"}, {"input": "4 4\n1 2 1\n2 3 1\n3 4 1\n4 1 2\n4", "output": "4\n2 3 4"}]
2,000
["graphs", "greedy", "shortest paths"]
62
[{"input": "3 3\r\n1 2 1\r\n2 3 1\r\n1 3 2\r\n3\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "4 4\r\n1 2 1\r\n2 3 1\r\n3 4 1\r\n4 1 2\r\n4\r\n", "output": "4\r\n2 3 4 \r\n"}, {"input": "4 5\r\n1 2 1\r\n1 3 1\r\n2 4 1\r\n3 4 1\r\n2 3 10\r\n1\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "6 8\r\n1 2 30\r\n1 3 20\r\n2 3 50...
false
stdio
import sys import heapq def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path, 'r') as f: n, m = map(int, f.readline().split()) edges = [] adj = [[] for _ in range(n+1)] for idx in range(m): ...
true
545/E
545
E
Python 3
TESTS
7
2,058
100,966,400
198526083
import sys, heapq input=sys.stdin.readline print=sys.stdout.write class C: INF = 2**30 class E: def __init__(self, v, w, idx): self.v = v self.w = w self.idx = idx def __lt__(self, other): return self.w < other.w def solve(): def dijkstra(): heap = [] ...
62
2,635
76,288,000
184261586
import heapq n, m = map(int, input().split()) g = [[] for _ in range(n + 1)] for i in range(1, m + 1): u, v, w = map(int, input().split()) g[u].append((i, v, w)) g[v].append((i, u, w)) src = int(input()) pq = [(0, 0, src, -1)] mk = [0] * (n + 1) t = [] s = 0 while pq: d, w, u, e = heapq.heappop(pq) ...
Codeforces Round 303 (Div. 2)
CF
2,015
3
256
Paths and Trees
Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to ask you about it. So, the problem statement is as follows. Let's assume that we are given a c...
The first line contains two numbers, n and m (1 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of vertices and edges of the graph, respectively. Next m lines contain three integers each, representing an edge — ui, vi, wi — the numbers of vertices connected by an edge and the weight of the edge (ui ≠ vi, 1 ≤ wi ≤ 109). It is...
In the first line print the minimum total weight of the edges of the tree. In the next line print the indices of the edges that are included in the tree, separated by spaces. The edges are numbered starting from 1 in the order they follow in the input. You may print the numbers of the edges in any order. If there are...
null
In the first sample there are two possible shortest path trees: - with edges 1 – 3 and 2 – 3 (the total weight is 3); - with edges 1 – 2 and 2 – 3 (the total weight is 2); And, for example, a tree with edges 1 – 2 and 1 – 3 won't be a shortest path tree for vertex 3, because the distance from vertex 3 to vertex 2 in ...
[{"input": "3 3\n1 2 1\n2 3 1\n1 3 2\n3", "output": "2\n1 2"}, {"input": "4 4\n1 2 1\n2 3 1\n3 4 1\n4 1 2\n4", "output": "4\n2 3 4"}]
2,000
["graphs", "greedy", "shortest paths"]
62
[{"input": "3 3\r\n1 2 1\r\n2 3 1\r\n1 3 2\r\n3\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "4 4\r\n1 2 1\r\n2 3 1\r\n3 4 1\r\n4 1 2\r\n4\r\n", "output": "4\r\n2 3 4 \r\n"}, {"input": "4 5\r\n1 2 1\r\n1 3 1\r\n2 4 1\r\n3 4 1\r\n2 3 10\r\n1\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "6 8\r\n1 2 30\r\n1 3 20\r\n2 3 50...
false
stdio
import sys import heapq def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path, 'r') as f: n, m = map(int, f.readline().split()) edges = [] adj = [[] for _ in range(n+1)] for idx in range(m): ...
true
629/C
629
C
Python 3
PRETESTS
3
31
0
16242807
n,m = map(int,input().split()) s = input() if n % 2 == 0: p = 0 q = 0 p2 = -10000000 for i in range(m): if s[i] == "(": p -= 1 q += 1 else: p += 1 q -= 1 if p > p2: p2 = p num = 0 if p2 > 0: num += p2 ...
60
171
39,014,400
174350635
import sys,os,io input = sys.stdin.readline # for strings # input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline # for non-strings from collections import defaultdict import bisect import random INF = float('inf') MOD = 1000000007 # MOD = 998244353 def bin32(num): return '{0:032b}'.format(num) def gcd(...
Codeforces Round 343 (Div. 2)
CF
2,016
2
256
Famil Door and Brackets
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings! The sequence of round brackets is called valid if and only if: 1. t...
First line contains n and m (1 ≤ m ≤ n ≤ 100 000, n - m ≤ 2000) — the desired length of the string and the length of the string bought by Gabi, respectively. The second line contains string s of length m consisting of characters '(' and ')' only.
Print the number of pairs of string p and q such that p + s + q is a valid sequence of round brackets modulo 109 + 7.
null
In the first sample there are four different valid pairs: 1. p = "(", q = "))" 2. p = "()", q = ")" 3. p = "", q = "())" 4. p = "", q = ")()" In the second sample the only way to obtain a desired string is choose empty p and q. In the third sample there is no way to get a valid sequence of brackets.
[{"input": "4 1\n(", "output": "4"}, {"input": "4 4\n(())", "output": "1"}, {"input": "4 3\n(((", "output": "0"}]
2,000
["dp", "strings"]
60
[{"input": "4 1\r\n(\r\n", "output": "4\r\n"}, {"input": "4 4\r\n(())\r\n", "output": "1\r\n"}, {"input": "4 3\r\n(((\r\n", "output": "0\r\n"}, {"input": "875 50\r\n)))((())()))((()(())))))())))((((((()))))))()(((((\r\n", "output": "0\r\n"}, {"input": "1980 464\r\n))(()()))(((((((((()))))))(()(((()((()))()()())()))()))...
false
stdio
null
true
22/D
22
D
Python 3
TESTS
2
30
0
198716298
import heapq n = int(input()) l = [] for _ in range(n): linie = input() start = int(linie.split()[0]) end = int(linie.split()[1]) if end < start: start, end = end, start l.append( (end, start) ) heapq.heapify(l) cuie = [] nrcuie = 0 while l: minim = heapq.heappop(l)[0] cuie.app...
40
93
3,174,400
219256708
n = int(input()) segments = [] for _ in range(n): l, r = sorted(map(int, input().split())) segments.append([l, r]) segments.sort(key = lambda s: s[1]) must_pined = False pins = [] for l, r in segments: if len(pins) == 0 or l > pins[-1]: pins.append(r) print(len(pins)) print(*pins)
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
1
256
Segments
You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails need...
The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points.
The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.
null
null
[{"input": "2\n0 2\n2 5", "output": "1\n2"}, {"input": "5\n0 3\n4 2\n4 8\n8 10\n7 7", "output": "3\n7 10 3"}]
1,900
["greedy", "sortings"]
40
[{"input": "2\r\n0 2\r\n2 5\r\n", "output": "1\r\n2 "}, {"input": "5\r\n0 3\r\n4 2\r\n4 8\r\n8 10\r\n7 7\r\n", "output": "3\r\n3 7 10 "}, {"input": "3\r\n40 -83\r\n52 -80\r\n-21 -4\r\n", "output": "1\r\n-4 "}, {"input": "4\r\n67 -88\r\n37 -62\r\n-26 91\r\n-99 -50\r\n", "output": "2\r\n-50 91 "}, {"input": "5\r\n45 58\r...
false
stdio
null
true
22/D
22
D
PyPy 3-64
TESTS
2
46
0
215623628
def find_smallest_number_of_nails(segments): segments.sort(key=lambda x: x[1]) # Sort segments based on the right endpoint nails = [] last_nail = -10001 # Initialize the last driven nail position for segment in segments: start, end = segment if start > last_nail: nails.ap...
40
108
2,969,600
176881828
array = [] n = int(input()) for x in range(n): e1, e2 = map(int, input().split()) less = min(e1, e2) great = max(e1, e2) array.append([less, great]) array.sort() points = [array[0][1]] range = array[0] for i in array: if i[0] <= points[-1] and i[1] >= points[-1]: continue elif i[1] <= ra...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
1
256
Segments
You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails need...
The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points.
The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.
null
null
[{"input": "2\n0 2\n2 5", "output": "1\n2"}, {"input": "5\n0 3\n4 2\n4 8\n8 10\n7 7", "output": "3\n7 10 3"}]
1,900
["greedy", "sortings"]
40
[{"input": "2\r\n0 2\r\n2 5\r\n", "output": "1\r\n2 "}, {"input": "5\r\n0 3\r\n4 2\r\n4 8\r\n8 10\r\n7 7\r\n", "output": "3\r\n3 7 10 "}, {"input": "3\r\n40 -83\r\n52 -80\r\n-21 -4\r\n", "output": "1\r\n-4 "}, {"input": "4\r\n67 -88\r\n37 -62\r\n-26 91\r\n-99 -50\r\n", "output": "2\r\n-50 91 "}, {"input": "5\r\n45 58\r...
false
stdio
null
true
22/D
22
D
PyPy 3
TESTS
2
93
307,200
203003997
from collections import deque n = int(input()) segs = [tuple(map(int, input().split())) for _ in range(n)] segs.sort(key=lambda x: x[1]) min_end = None nails = 0 loc = deque() for s in segs: if min_end == None: min_end = s[1] elif s[0] > min_end: loc.append(min_end) min_end = s[1] ...
40
109
307,200
74792082
n=int(input()) c=[] for i in range(n): x,y=map(int,input().split()) if x>y: x,y=y,x c.append([x,0,i]) c.append([y,1,i]) c.sort() ans=0 stack=[] b=[] for z in c: if z[1]==0: stack.append(z[2]) else: if z[2] in stack: ans+=1 b.append(z[0]) stack=...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
1
256
Segments
You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails need...
The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points.
The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.
null
null
[{"input": "2\n0 2\n2 5", "output": "1\n2"}, {"input": "5\n0 3\n4 2\n4 8\n8 10\n7 7", "output": "3\n7 10 3"}]
1,900
["greedy", "sortings"]
40
[{"input": "2\r\n0 2\r\n2 5\r\n", "output": "1\r\n2 "}, {"input": "5\r\n0 3\r\n4 2\r\n4 8\r\n8 10\r\n7 7\r\n", "output": "3\r\n3 7 10 "}, {"input": "3\r\n40 -83\r\n52 -80\r\n-21 -4\r\n", "output": "1\r\n-4 "}, {"input": "4\r\n67 -88\r\n37 -62\r\n-26 91\r\n-99 -50\r\n", "output": "2\r\n-50 91 "}, {"input": "5\r\n45 58\r...
false
stdio
null
true
257/D
257
D
Python 3
TESTS
2
186
0
62387955
if __name__ == "__main__": n = int(input()) array = input() print('+'*(n-1) + '-')
38
622
11,878,400
77732187
n=int(input()) a=list(map(int,input().split(' '))) temp_sgn=1 sgns=[] curr_sum=0 for i in range(n): if(curr_sum>=a[n-i-1]): sgns.append(1) sgns.append(-1) curr_sum-=a[n-i-1] else: sgns.append(-1) sgns.append(1) curr_sum-=a[n-i-1] curr_sum*=-1 sgns.reverse() ans=[] for i in range(2*n): if(i%2==0): an...
Codeforces Round 159 (Div. 2)
CF
2,013
2
256
Sum
Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai ≤ ai + 1 ≤ 2·ai for any positive integer i (i < n). Vasya wants to add either a "+" or a "-" before each number of array. Thus, Vasya will ge...
The first line contains integer n (1 ≤ n ≤ 105) — the size of the array. The second line contains space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the original array. It is guaranteed that the condition ai ≤ ai + 1 ≤ 2·ai fulfills for any positive integer i (i < n).
In a single line print the sequence of n characters "+" and "-", where the i-th character is the sign that is placed in front of number ai. The value of the resulting expression s must fit into the limits 0 ≤ s ≤ a1. If there are multiple solutions, you are allowed to print any of them.
null
null
[{"input": "4\n1 2 3 5", "output": "+++-"}, {"input": "3\n3 3 5", "output": "++-"}]
1,900
["greedy", "math"]
38
[{"input": "4\r\n1 2 3 5\r\n", "output": "+++-"}, {"input": "3\r\n3 3 5\r\n", "output": "++-"}, {"input": "4\r\n2 4 5 6\r\n", "output": "-++-"}, {"input": "6\r\n3 5 10 11 12 20\r\n", "output": "++-++-"}, {"input": "10\r\n10 14 17 22 43 72 74 84 88 93\r\n", "output": "++---++--+"}, {"input": "11\r\n3 6 7 11 13 16 26 52 ...
false
stdio
import sys def main(input_path, output_path, sub_path): with open(input_path) as f: lines = f.readlines() n = int(lines[0].strip()) a = list(map(int, lines[1].strip().split())) assert len(a) == n, "Input array length mismatch" with open(sub_path) as f: sub = f.read().strip() i...
true
257/D
257
D
Python 3
TESTS
2
92
0
206800882
def get_expression(n, arr): expression = [] current_sum = 0 for i in range(n - 1, -1, -1): if arr[i] >= current_sum: expression.append('-') else: expression.append('+') current_sum += arr[i] expression.reverse() return expression n = int(input()) ar...
38
248
9,728,000
5475356
n = int(input()) t = list(map(int, input().split())) t.reverse() s, p = 0, [0] * n for i, j in enumerate(t): if s > 0: p[i] = 1 s -= j else: s += j p.reverse() if s < 0: print(''.join('-+'[i] for i in p)) else: print(''.join('+-'[i] for i in p))
Codeforces Round 159 (Div. 2)
CF
2,013
2
256
Sum
Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai ≤ ai + 1 ≤ 2·ai for any positive integer i (i < n). Vasya wants to add either a "+" or a "-" before each number of array. Thus, Vasya will ge...
The first line contains integer n (1 ≤ n ≤ 105) — the size of the array. The second line contains space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the original array. It is guaranteed that the condition ai ≤ ai + 1 ≤ 2·ai fulfills for any positive integer i (i < n).
In a single line print the sequence of n characters "+" and "-", where the i-th character is the sign that is placed in front of number ai. The value of the resulting expression s must fit into the limits 0 ≤ s ≤ a1. If there are multiple solutions, you are allowed to print any of them.
null
null
[{"input": "4\n1 2 3 5", "output": "+++-"}, {"input": "3\n3 3 5", "output": "++-"}]
1,900
["greedy", "math"]
38
[{"input": "4\r\n1 2 3 5\r\n", "output": "+++-"}, {"input": "3\r\n3 3 5\r\n", "output": "++-"}, {"input": "4\r\n2 4 5 6\r\n", "output": "-++-"}, {"input": "6\r\n3 5 10 11 12 20\r\n", "output": "++-++-"}, {"input": "10\r\n10 14 17 22 43 72 74 84 88 93\r\n", "output": "++---++--+"}, {"input": "11\r\n3 6 7 11 13 16 26 52 ...
false
stdio
import sys def main(input_path, output_path, sub_path): with open(input_path) as f: lines = f.readlines() n = int(lines[0].strip()) a = list(map(int, lines[1].strip().split())) assert len(a) == n, "Input array length mismatch" with open(sub_path) as f: sub = f.read().strip() i...
true
261/A
261
A
Python 3
TESTS
3
186
307,200
90405130
m=int(input()) q=list(map(int,input().split())) n=int(input()) a=list(map(int,input().split())) q.sort() a.sort() j=n-1 i=0 ans=0 while j>=0: if j==n-1: for i in range(q[0]): ans=ans+a[j] j=j-1 if j<0: break j=j-2 else: ans=ans+a[j] ...
45
278
7,372,800
177939891
rd = lambda: list(map(int, input().split())) input() z = min(rd()) input() a = sorted(rd(), reverse=True) print(sum(v for i, v in enumerate(a) if i%(z+2)<z))
Codeforces Round 160 (Div. 1)
CF
2,013
2
256
Maxim and Discounts
Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems. There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a special basket, where he puts exactly qi items he buys. Under the term...
The first line contains integer m (1 ≤ m ≤ 105) — the number of discount types. The second line contains m integers: q1, q2, ..., qm (1 ≤ qi ≤ 105). The third line contains integer n (1 ≤ n ≤ 105) — the number of items Maxim needs. The fourth line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ 104) — the items' prices...
In a single line print a single integer — the answer to the problem.
null
In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200. In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150.
[{"input": "1\n2\n4\n50 50 100 100", "output": "200"}, {"input": "2\n2 3\n5\n50 50 50 50 50", "output": "150"}, {"input": "1\n1\n7\n1 1 1 1 1 1 1", "output": "3"}]
1,400
["greedy", "sortings"]
45
[{"input": "1\r\n2\r\n4\r\n50 50 100 100\r\n", "output": "200\r\n"}, {"input": "2\r\n2 3\r\n5\r\n50 50 50 50 50\r\n", "output": "150\r\n"}, {"input": "1\r\n1\r\n7\r\n1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "18\r\n16 16 20 12 13 10 14 15 4 5 6 8 4 11 12 11 16 7\r\n15\r\n371 2453 905 1366 6471 4331 4106 2570 46...
false
stdio
null
true
261/A
261
A
Python 3
TESTS
3
124
204,800
21916773
import math def sort(arr): swap=True i=0 while swap==True or i>len(arr): swap=False for j in range(len(arr)-i-1): if arr[j]>arr[j+1]: temp=arr[j] arr[j]=arr[j+1] arr[j+1]=temp swap=True i+=1 need=[] items=[]...
45
278
142,233,600
187108306
from collections import defaultdict, Counter, deque from math import inf from functools import lru_cache from heapq import heappop, heappush import sys #input=sys.stdin.readline def solution(): # use the minimam one you will be m = int(input()) ln = min(map(int, input().split())) n = int(input()) ...
Codeforces Round 160 (Div. 1)
CF
2,013
2
256
Maxim and Discounts
Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems. There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a special basket, where he puts exactly qi items he buys. Under the term...
The first line contains integer m (1 ≤ m ≤ 105) — the number of discount types. The second line contains m integers: q1, q2, ..., qm (1 ≤ qi ≤ 105). The third line contains integer n (1 ≤ n ≤ 105) — the number of items Maxim needs. The fourth line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ 104) — the items' prices...
In a single line print a single integer — the answer to the problem.
null
In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200. In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150.
[{"input": "1\n2\n4\n50 50 100 100", "output": "200"}, {"input": "2\n2 3\n5\n50 50 50 50 50", "output": "150"}, {"input": "1\n1\n7\n1 1 1 1 1 1 1", "output": "3"}]
1,400
["greedy", "sortings"]
45
[{"input": "1\r\n2\r\n4\r\n50 50 100 100\r\n", "output": "200\r\n"}, {"input": "2\r\n2 3\r\n5\r\n50 50 50 50 50\r\n", "output": "150\r\n"}, {"input": "1\r\n1\r\n7\r\n1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "18\r\n16 16 20 12 13 10 14 15 4 5 6 8 4 11 12 11 16 7\r\n15\r\n371 2453 905 1366 6471 4331 4106 2570 46...
false
stdio
null
true
690/B1
690
B1
Python 3
TESTS
2
77
7,065,600
37352791
n = int(input()) big = 0 while(n): row = input() for i in row: big = max(big, int(i)) n-=1 print('Yes')
21
62
0
19580571
def check_cell(i, j, n): k = 0 if i > 1 and field[i-1][j]: k += 1 if i < n-1 and field[i+1][j]: k += 1 if j > 1 and field[i][j-1]: k += 1 if j < n-1 and field[i][j+1]: k += 1 if k < 2: return 0 elif k < 4: return k-1 else: return 4 n = int(input()) field = [] for i in range(n): temp = [int(x) for x in ...
Helvetic Coding Contest 2016 online mirror (teams, unrated)
ICPC
2,016
2
256
Recover Polygon (easy)
The zombies are gathering in their secret lair! Heidi will strike hard to destroy them once and for all. But there is a little problem... Before she can strike, she needs to know where the lair is. And the intel she has is not very good. Heidi knows that the lair can be represented as a rectangle on a lattice, with si...
The first line of each test case contains one integer N, the size of the lattice grid (5 ≤ N ≤ 50). The next N lines each contain N characters, describing the level of Zombie Contamination of each cell in the lattice. Every character of every line is a digit between 0 and 4. Cells are given in the same order as they a...
The first line of the output should contain Yes if there exists a single non-zero area rectangular lair with corners on the grid for which checking the levels of Zombie Contamination gives the results given in the input, and No otherwise.
null
The lair, if it exists, has to be rectangular (that is, have corners at some grid points with coordinates (x1, y1), (x1, y2), (x2, y1), (x2, y2)), has a non-zero area and be contained inside of the grid (that is, 0 ≤ x1 < x2 ≤ N, 0 ≤ y1 < y2 ≤ N), and result in the levels of Zombie Contamination as reported in the inpu...
[{"input": "6\n000000\n000000\n012100\n024200\n012100\n000000", "output": "Yes"}]
1,700
[]
21
[{"input": "6\r\n000000\r\n000000\r\n012100\r\n024200\r\n012100\r\n000000\r\n", "output": "Yes\r\n"}, {"input": "6\r\n000000\r\n012210\r\n024420\r\n012210\r\n000000\r\n000000\r\n", "output": "Yes\r\n"}, {"input": "6\r\n000100\r\n001210\r\n002420\r\n001210\r\n000000\r\n000000\r\n", "output": "No\r\n"}, {"input": "10\r\n...
false
stdio
null
true
261/A
261
A
PyPy 3-64
TESTS
3
92
0
180424082
m = int(input()) l1 = list(map(int, input().split())) l1 = sorted(l1, reverse = True) n = int(input()) l = list(map(int, input().split())) l = sorted(l, reverse = True) basket = 0 i = 0 pickedup = 0 cost = 0 while pickedup <n: if n-(i+l1[basket]) <2 and basket+1<m: while basket+1<m and n-(i+l1[basket])<2: basket+...
45
310
7,680,000
21184899
def main(): input() q = min(map(int, input().split())) input() aa = sorted(map(int, input().split()), reverse=True) print(sum(aa) - sum(aa[q::q + 2]) - sum(aa[q + 1::q + 2])) if __name__ == "__main__": main()
Codeforces Round 160 (Div. 1)
CF
2,013
2
256
Maxim and Discounts
Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems. There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a special basket, where he puts exactly qi items he buys. Under the term...
The first line contains integer m (1 ≤ m ≤ 105) — the number of discount types. The second line contains m integers: q1, q2, ..., qm (1 ≤ qi ≤ 105). The third line contains integer n (1 ≤ n ≤ 105) — the number of items Maxim needs. The fourth line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ 104) — the items' prices...
In a single line print a single integer — the answer to the problem.
null
In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200. In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150.
[{"input": "1\n2\n4\n50 50 100 100", "output": "200"}, {"input": "2\n2 3\n5\n50 50 50 50 50", "output": "150"}, {"input": "1\n1\n7\n1 1 1 1 1 1 1", "output": "3"}]
1,400
["greedy", "sortings"]
45
[{"input": "1\r\n2\r\n4\r\n50 50 100 100\r\n", "output": "200\r\n"}, {"input": "2\r\n2 3\r\n5\r\n50 50 50 50 50\r\n", "output": "150\r\n"}, {"input": "1\r\n1\r\n7\r\n1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "18\r\n16 16 20 12 13 10 14 15 4 5 6 8 4 11 12 11 16 7\r\n15\r\n371 2453 905 1366 6471 4331 4106 2570 46...
false
stdio
null
true
175/B
175
B
Python 3
TESTS
11
92
102,400
214309783
def f(temp): if (k-temp)/k < 0.5: return "noob" elif 0.8>(k-temp)/k >= 0.5: return "random" elif 0.9>(k-temp)/k >= 0.8: return "average" elif 0.99>(k-temp)/k >= 0.9: return "hardcore" elif (k-temp)/k >= 0.99: return "pro" n = int(input()) hashtable = {} for ...
46
184
409,600
14904733
def t(g, n): for x, y in ((50, 'noob'), (20, 'random'), (10, 'average'), (1, 'hardcore')): if g > x * n // 100: return y return 'pro' p, st = {}, {} for i in range(int(input())): n, s = input().split() if n not in p or int(s) > p[n]: p[n] = int(s) for i, si in enumerate(sorte...
Codeforces Round 115
CF
2,012
2
256
Plane of Tanks: Pro
Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has...
The first line contains the only integer number n (1 ≤ n ≤ 1000) — a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. T...
Print on the first line the number m — the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). Th...
null
In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has bes...
[{"input": "5\nvasya 100\nvasya 200\nartem 100\nkolya 200\nigor 250", "output": "4\nartem noob\nigor pro\nkolya random\nvasya random"}, {"input": "3\nvasya 200\nkolya 1000\nvasya 1000", "output": "2\nkolya pro\nvasya pro"}]
1,400
["implementation"]
78
[{"input": "5\r\nvasya 100\r\nvasya 200\r\nartem 100\r\nkolya 200\r\nigor 250\r\n", "output": "4\r\nartem noob\r\nigor pro\r\nkolya random\r\nvasya random\r\n"}, {"input": "3\r\nvasya 200\r\nkolya 1000\r\nvasya 1000\r\n", "output": "2\r\nkolya pro\r\nvasya pro\r\n"}, {"input": "1\r\nvasya 1000\r\n", "output": "1\r\nvas...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input data with open(input_path) as f: n = int(f.readline()) players = {} for _ in range(n): name, points = f.readline().strip().split() points = int(points) if name not in players ...
true
629/C
629
C
PyPy 3
TESTS
3
217
18,636,800
43877512
from sys import stdin n,m=map(int, stdin.readline().strip().split()) s=stdin.readline().strip() dp=[[0 for i in range(2004)] for j in range(2004)] mod=10**9+7 d=n-m ans=0 b=0 d1=0 for i in s: if i=='(': b+=1 else: b-=1 if b<d1: d1=b d1=-d1 dp[0][0]=1 d+=1 for i in range(1,d): dp...
60
186
19,558,400
199862678
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v): return u * (l + 1) + v n, m = map(int, input().split()) mod = pow(10, 9) + 7 s = list(input().rstrip()) l = n - m dp = [0] * ((l + 1) * (l + 1)) dp[0] = 1 for i in range(l): for j in range(i % 2, i + 1, 2): fo...
Codeforces Round 343 (Div. 2)
CF
2,016
2
256
Famil Door and Brackets
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings! The sequence of round brackets is called valid if and only if: 1. t...
First line contains n and m (1 ≤ m ≤ n ≤ 100 000, n - m ≤ 2000) — the desired length of the string and the length of the string bought by Gabi, respectively. The second line contains string s of length m consisting of characters '(' and ')' only.
Print the number of pairs of string p and q such that p + s + q is a valid sequence of round brackets modulo 109 + 7.
null
In the first sample there are four different valid pairs: 1. p = "(", q = "))" 2. p = "()", q = ")" 3. p = "", q = "())" 4. p = "", q = ")()" In the second sample the only way to obtain a desired string is choose empty p and q. In the third sample there is no way to get a valid sequence of brackets.
[{"input": "4 1\n(", "output": "4"}, {"input": "4 4\n(())", "output": "1"}, {"input": "4 3\n(((", "output": "0"}]
2,000
["dp", "strings"]
60
[{"input": "4 1\r\n(\r\n", "output": "4\r\n"}, {"input": "4 4\r\n(())\r\n", "output": "1\r\n"}, {"input": "4 3\r\n(((\r\n", "output": "0\r\n"}, {"input": "875 50\r\n)))((())()))((()(())))))())))((((((()))))))()(((((\r\n", "output": "0\r\n"}, {"input": "1980 464\r\n))(()()))(((((((((()))))))(()(((()((()))()()())()))()))...
false
stdio
null
true
629/C
629
C
Python 3
TESTS
3
171
6,246,400
16250626
from _collections import defaultdict n, m = input().split() n, m = int(n), int(m) dp = [None] * (n-m+1) for _ in range(n-m+1): dp[_] = defaultdict(int) dp[0][0] = 1 for i in range(n-m): for k, v in dp[i].items(): if k > 0: dp[i+1][k-1] += dp[i][k] dp[i+1][k+1] += dp[i][k] balance...
60
218
10,137,600
16250216
n, m = map(int, input().split()) s = input() mod = 10 ** 9 + 7 c = b = 0 for x in s: c += (x == '(') * 2 - 1 b = min(c, b) d = [[1]] for i in range(n - m): nd = d[-1][1:] + [0] * 2 for j in range(1, i + 2): nd[j] = (nd[j] + d[-1][j-1]) % mod d.append(nd) ans = 0 for i in range(n - m + 1): ...
Codeforces Round 343 (Div. 2)
CF
2,016
2
256
Famil Door and Brackets
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings! The sequence of round brackets is called valid if and only if: 1. t...
First line contains n and m (1 ≤ m ≤ n ≤ 100 000, n - m ≤ 2000) — the desired length of the string and the length of the string bought by Gabi, respectively. The second line contains string s of length m consisting of characters '(' and ')' only.
Print the number of pairs of string p and q such that p + s + q is a valid sequence of round brackets modulo 109 + 7.
null
In the first sample there are four different valid pairs: 1. p = "(", q = "))" 2. p = "()", q = ")" 3. p = "", q = "())" 4. p = "", q = ")()" In the second sample the only way to obtain a desired string is choose empty p and q. In the third sample there is no way to get a valid sequence of brackets.
[{"input": "4 1\n(", "output": "4"}, {"input": "4 4\n(())", "output": "1"}, {"input": "4 3\n(((", "output": "0"}]
2,000
["dp", "strings"]
60
[{"input": "4 1\r\n(\r\n", "output": "4\r\n"}, {"input": "4 4\r\n(())\r\n", "output": "1\r\n"}, {"input": "4 3\r\n(((\r\n", "output": "0\r\n"}, {"input": "875 50\r\n)))((())()))((()(())))))())))((((((()))))))()(((((\r\n", "output": "0\r\n"}, {"input": "1980 464\r\n))(()()))(((((((((()))))))(()(((()((()))()()())()))()))...
false
stdio
null
true
629/C
629
C
Python 3
TESTS
3
514
7,168,000
16967898
n, m = list(map(int, input().split())) s = input() f = [ [0 for i in range(n - m + 1)] for i in range(n - m + 1)] f[0][0] = 1 mod = 1000000007 for i in range(1, n - m + 1): for j in range(0, n - m + 1): if j < n - m: f[i][j] = (f[i][j] + f[i - 1][j + 1]) % mod if j > 0: f[i][j] = (f[i][j] + f[i - 1][j - 1]) ...
60
234
10,137,600
16250282
n, m = map(int, input().split()) s = input() mod = 10 ** 9 + 7 c, b, ans, d, k = 0, 0, 0, [[1]], n - m for i in s: c += (i == '(') * 2 - 1 b = min(c, b) for i in range(n - m): nd = d[-1][1:] + [0] * 2 for j in range(1, i + 2): nd[j] = (nd[j] + d[-1][j - 1]) % mod d.append(nd) for i in range(...
Codeforces Round 343 (Div. 2)
CF
2,016
2
256
Famil Door and Brackets
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings! The sequence of round brackets is called valid if and only if: 1. t...
First line contains n and m (1 ≤ m ≤ n ≤ 100 000, n - m ≤ 2000) — the desired length of the string and the length of the string bought by Gabi, respectively. The second line contains string s of length m consisting of characters '(' and ')' only.
Print the number of pairs of string p and q such that p + s + q is a valid sequence of round brackets modulo 109 + 7.
null
In the first sample there are four different valid pairs: 1. p = "(", q = "))" 2. p = "()", q = ")" 3. p = "", q = "())" 4. p = "", q = ")()" In the second sample the only way to obtain a desired string is choose empty p and q. In the third sample there is no way to get a valid sequence of brackets.
[{"input": "4 1\n(", "output": "4"}, {"input": "4 4\n(())", "output": "1"}, {"input": "4 3\n(((", "output": "0"}]
2,000
["dp", "strings"]
60
[{"input": "4 1\r\n(\r\n", "output": "4\r\n"}, {"input": "4 4\r\n(())\r\n", "output": "1\r\n"}, {"input": "4 3\r\n(((\r\n", "output": "0\r\n"}, {"input": "875 50\r\n)))((())()))((()(())))))())))((((((()))))))()(((((\r\n", "output": "0\r\n"}, {"input": "1980 464\r\n))(()()))(((((((((()))))))(()(((()((()))()()())()))()))...
false
stdio
null
true
629/C
629
C
Python 3
TESTS
3
467
4,300,800
17296115
def mp(): return map(int,input().split()) def lt(): return list(map(int,input().split())) def pt(x): print(x) def ip(): return input() def it(): return int(input()) def sl(x): return [t for t in x] def spl(x): return x.split() def aj(liste, item): liste.append(item) def bin(x): return "{0:b}".format(x) def listr...
60
280
41,676,800
125105127
import sys input=sys.stdin.readline n,m=map(int,input().split()) d=n-m s=list(input().rstrip()) cnt=0 min_c=0 for i in range(m): if s[i]=="(": cnt+=1 else: cnt-=1 min_c=min(min_c,cnt) mod=10**9+7 dp=[[0]*(d+1) for i in range(d+1)] dp[0][0]=1 for i in range(1,d+1): for j in range(d+1): ...
Codeforces Round 343 (Div. 2)
CF
2,016
2
256
Famil Door and Brackets
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings! The sequence of round brackets is called valid if and only if: 1. t...
First line contains n and m (1 ≤ m ≤ n ≤ 100 000, n - m ≤ 2000) — the desired length of the string and the length of the string bought by Gabi, respectively. The second line contains string s of length m consisting of characters '(' and ')' only.
Print the number of pairs of string p and q such that p + s + q is a valid sequence of round brackets modulo 109 + 7.
null
In the first sample there are four different valid pairs: 1. p = "(", q = "))" 2. p = "()", q = ")" 3. p = "", q = "())" 4. p = "", q = ")()" In the second sample the only way to obtain a desired string is choose empty p and q. In the third sample there is no way to get a valid sequence of brackets.
[{"input": "4 1\n(", "output": "4"}, {"input": "4 4\n(())", "output": "1"}, {"input": "4 3\n(((", "output": "0"}]
2,000
["dp", "strings"]
60
[{"input": "4 1\r\n(\r\n", "output": "4\r\n"}, {"input": "4 4\r\n(())\r\n", "output": "1\r\n"}, {"input": "4 3\r\n(((\r\n", "output": "0\r\n"}, {"input": "875 50\r\n)))((())()))((()(())))))())))((((((()))))))()(((((\r\n", "output": "0\r\n"}, {"input": "1980 464\r\n))(()()))(((((((((()))))))(()(((()((()))()()())()))()))...
false
stdio
null
true
629/C
629
C
PyPy 3-64
TESTS
3
327
37,273,600
209058799
# if you win, you live. you cannot win unless you fight. import string import sys from sys import stdin, setrecursionlimit # fd=open("cses.txt") # sys.stdin=fd input = stdin.readline rd = lambda: map(lambda s: int(s), input().strip().split()) rdone = lambda: map(lambda s: int(s) - 1, input().strip().split()) ri = lamb...
60
171
39,014,400
174350635
import sys,os,io input = sys.stdin.readline # for strings # input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline # for non-strings from collections import defaultdict import bisect import random INF = float('inf') MOD = 1000000007 # MOD = 998244353 def bin32(num): return '{0:032b}'.format(num) def gcd(...
Codeforces Round 343 (Div. 2)
CF
2,016
2
256
Famil Door and Brackets
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings! The sequence of round brackets is called valid if and only if: 1. t...
First line contains n and m (1 ≤ m ≤ n ≤ 100 000, n - m ≤ 2000) — the desired length of the string and the length of the string bought by Gabi, respectively. The second line contains string s of length m consisting of characters '(' and ')' only.
Print the number of pairs of string p and q such that p + s + q is a valid sequence of round brackets modulo 109 + 7.
null
In the first sample there are four different valid pairs: 1. p = "(", q = "))" 2. p = "()", q = ")" 3. p = "", q = "())" 4. p = "", q = ")()" In the second sample the only way to obtain a desired string is choose empty p and q. In the third sample there is no way to get a valid sequence of brackets.
[{"input": "4 1\n(", "output": "4"}, {"input": "4 4\n(())", "output": "1"}, {"input": "4 3\n(((", "output": "0"}]
2,000
["dp", "strings"]
60
[{"input": "4 1\r\n(\r\n", "output": "4\r\n"}, {"input": "4 4\r\n(())\r\n", "output": "1\r\n"}, {"input": "4 3\r\n(((\r\n", "output": "0\r\n"}, {"input": "875 50\r\n)))((())()))((()(())))))())))((((((()))))))()(((((\r\n", "output": "0\r\n"}, {"input": "1980 464\r\n))(()()))(((((((((()))))))(()(((()((()))()()())()))()))...
false
stdio
null
true
629/C
629
C
PyPy 3-64
TESTS
3
280
37,990,400
209058426
# if you win, you live. you cannot win unless you fight. import string import sys from sys import stdin, setrecursionlimit # fd=open("cses.txt") # sys.stdin=fd input = stdin.readline rd = lambda: map(lambda s: int(s), input().strip().split()) rdone = lambda: map(lambda s: int(s) - 1, input().strip().split()) ri = lamb...
60
186
19,558,400
199862678
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v): return u * (l + 1) + v n, m = map(int, input().split()) mod = pow(10, 9) + 7 s = list(input().rstrip()) l = n - m dp = [0] * ((l + 1) * (l + 1)) dp[0] = 1 for i in range(l): for j in range(i % 2, i + 1, 2): fo...
Codeforces Round 343 (Div. 2)
CF
2,016
2
256
Famil Door and Brackets
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings! The sequence of round brackets is called valid if and only if: 1. t...
First line contains n and m (1 ≤ m ≤ n ≤ 100 000, n - m ≤ 2000) — the desired length of the string and the length of the string bought by Gabi, respectively. The second line contains string s of length m consisting of characters '(' and ')' only.
Print the number of pairs of string p and q such that p + s + q is a valid sequence of round brackets modulo 109 + 7.
null
In the first sample there are four different valid pairs: 1. p = "(", q = "))" 2. p = "()", q = ")" 3. p = "", q = "())" 4. p = "", q = ")()" In the second sample the only way to obtain a desired string is choose empty p and q. In the third sample there is no way to get a valid sequence of brackets.
[{"input": "4 1\n(", "output": "4"}, {"input": "4 4\n(())", "output": "1"}, {"input": "4 3\n(((", "output": "0"}]
2,000
["dp", "strings"]
60
[{"input": "4 1\r\n(\r\n", "output": "4\r\n"}, {"input": "4 4\r\n(())\r\n", "output": "1\r\n"}, {"input": "4 3\r\n(((\r\n", "output": "0\r\n"}, {"input": "875 50\r\n)))((())()))((()(())))))())))((((((()))))))()(((((\r\n", "output": "0\r\n"}, {"input": "1980 464\r\n))(()()))(((((((((()))))))(()(((()((()))()()())()))()))...
false
stdio
null
true
629/C
629
C
Python 3
TESTS
3
218
307,200
16622254
def ij(s): i = 0 j = 0 for c in s: if c == ')': if j > 0: j -= 1 else: i += 1 else: j += 1 return i, j def ways(n, s): I, J = ij(s) f = n - len(s) - I - J if f < 0 or f%2: return 0 E = f//2 ...
60
218
10,137,600
16250216
n, m = map(int, input().split()) s = input() mod = 10 ** 9 + 7 c = b = 0 for x in s: c += (x == '(') * 2 - 1 b = min(c, b) d = [[1]] for i in range(n - m): nd = d[-1][1:] + [0] * 2 for j in range(1, i + 2): nd[j] = (nd[j] + d[-1][j-1]) % mod d.append(nd) ans = 0 for i in range(n - m + 1): ...
Codeforces Round 343 (Div. 2)
CF
2,016
2
256
Famil Door and Brackets
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings! The sequence of round brackets is called valid if and only if: 1. t...
First line contains n and m (1 ≤ m ≤ n ≤ 100 000, n - m ≤ 2000) — the desired length of the string and the length of the string bought by Gabi, respectively. The second line contains string s of length m consisting of characters '(' and ')' only.
Print the number of pairs of string p and q such that p + s + q is a valid sequence of round brackets modulo 109 + 7.
null
In the first sample there are four different valid pairs: 1. p = "(", q = "))" 2. p = "()", q = ")" 3. p = "", q = "())" 4. p = "", q = ")()" In the second sample the only way to obtain a desired string is choose empty p and q. In the third sample there is no way to get a valid sequence of brackets.
[{"input": "4 1\n(", "output": "4"}, {"input": "4 4\n(())", "output": "1"}, {"input": "4 3\n(((", "output": "0"}]
2,000
["dp", "strings"]
60
[{"input": "4 1\r\n(\r\n", "output": "4\r\n"}, {"input": "4 4\r\n(())\r\n", "output": "1\r\n"}, {"input": "4 3\r\n(((\r\n", "output": "0\r\n"}, {"input": "875 50\r\n)))((())()))((()(())))))())))((((((()))))))()(((((\r\n", "output": "0\r\n"}, {"input": "1980 464\r\n))(()()))(((((((((()))))))(()(((()((()))()()())()))()))...
false
stdio
null
true
178/A1
178
A3
PyPy 3-64
TESTS3
13
218
4,403,200
168439563
n = int(input()) a = list(map(int, input().split())) max_power = 9 while n - 1 - 2 ** max_power < 0: max_power -= 1 for i in range(1, n): steps = 0 nums = a[:i] for num_index, num in enumerate(nums): power = max_power times = 0 step = 2 ** power while num_index < i: ...
12
62
0
165771559
n=int(input()) a=[*map(int,input().split())] s=0 for i in range(n-1): p=1 while i+(p<<1)<n:p<<=1 a[i+p]+=a[i] print(s+a[i]) s+=a[i]
ABBYY Cup 2.0 - Hard
ICPC
2,012
2
256
Educational Game
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequenc...
The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are: - 1 ≤ n ≤ 300 The input limitations for getting 50 points are: - 1 ≤ n ≤ 2000 The input limitations for getting 100 points are: - 1 ...
Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier.
null
null
[{"input": "4\n1 0 1 2", "output": "1\n1\n3"}, {"input": "8\n1 2 3 4 5 6 7 8", "output": "1\n3\n6\n10\n16\n24\n40"}]
1,000
[]
12
[{"input": "4\r\n1 0 1 2\r\n", "output": "1\r\n1\r\n3\r\n"}, {"input": "8\r\n1 2 3 4 5 6 7 8\r\n", "output": "1\r\n3\r\n6\r\n10\r\n16\r\n24\r\n40\r\n"}, {"input": "5\r\n4 1 4 7 6\r\n", "output": "4\r\n5\r\n9\r\n17\r\n"}, {"input": "9\r\n13 13 7 11 3 9 3 5 5\r\n", "output": "13\r\n26\r\n33\r\n44\r\n47\r\n69\r\n79\r\n117...
false
stdio
null
true
460/C
460
C
PyPy 3-64
TESTS
4
62
614,400
218070291
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb alph = 'abcdefghijklmnopqrstuvwxyz' #pow(x,mod-2,mod) def find(height): l = [...
43
124
18,534,400
208845663
import sys input = lambda: sys.stdin.readline().strip() n, m, w = list(map(int, input().split())) a = list(map(int, input().split())) l, r = 1, 1000100001 # [) while l < r - 1: mid = (l + r) // 2 diff = [0] * n cnt = 0 tmp = 0 for i in range(n): tmp += diff[i] need = mid - tmp - a...
Codeforces Round 262 (Div. 2)
CF
2,014
2
256
Present
Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noti...
The first line contains space-separated integers n, m and w (1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print a single integer — the maximum final height of the smallest flower.
null
In the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It's impossible to get height 3 in this test.
[{"input": "6 2 3\n2 2 2 2 1 1", "output": "2"}, {"input": "2 5 1\n5 8", "output": "9"}]
1,700
["binary search", "data structures", "greedy"]
43
[{"input": "6 2 3\r\n2 2 2 2 1 1\r\n", "output": "2\r\n"}, {"input": "2 5 1\r\n5 8\r\n", "output": "9\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "2\r\n"}, {"input": "3 2 3\r\n999999998 999999998 999999998\r\n", "output": "1000000000\r\n"}, {"input": "10 8 3\r\n499 498 497 497 497 497 497 497 498 499\r\n", "output": "...
false
stdio
null
true
460/C
460
C
PyPy 3-64
TESTS
3
61
0
196540734
# author: cholebhature lover from collections import * from bisect import * from heapq import * from math import * import sys def input(): return sys.stdin.readline().rstrip('\r\n') def maximizeMinHeight(n, k, w, a): i = 1 j = 10**6 ans = 10**9 while i <= j: mid = i+(j-i)//2 arr ...
43
140
18,534,400
208854903
n,m,w = list(map(int,input().strip().split())) a = list(map(int,input().strip().split())) left = 0 right = 10**10 def check(x): sub = [0]*(n + 1) cnt = 0 for i in range(n): sub[i] += sub[i - 1] if a[i] + sub[i] < x: diff = x - a[i] - sub[i] cnt += diff sub...
Codeforces Round 262 (Div. 2)
CF
2,014
2
256
Present
Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noti...
The first line contains space-separated integers n, m and w (1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print a single integer — the maximum final height of the smallest flower.
null
In the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It's impossible to get height 3 in this test.
[{"input": "6 2 3\n2 2 2 2 1 1", "output": "2"}, {"input": "2 5 1\n5 8", "output": "9"}]
1,700
["binary search", "data structures", "greedy"]
43
[{"input": "6 2 3\r\n2 2 2 2 1 1\r\n", "output": "2\r\n"}, {"input": "2 5 1\r\n5 8\r\n", "output": "9\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "2\r\n"}, {"input": "3 2 3\r\n999999998 999999998 999999998\r\n", "output": "1000000000\r\n"}, {"input": "10 8 3\r\n499 498 497 497 497 497 497 497 498 499\r\n", "output": "...
false
stdio
null
true
789/A
789
A
Python 3
PRETESTS
6
108
11,673,600
25902847
n,k=[int(i)for i in input().split()] w=[int(i)for i in input().split()] i=0 x=0 for i in w: if i%k==0: x+=i//k else : x+=i//k+1 print(x//2 if x%k==0 else x//2+1)
31
92
7,372,800
195015992
n, k = map(int, input().split()) a = list(map(int, input().split())) ans = 0 for x in a: ans += x // k + (1 if x % k != 0 else 0) print(ans // 2 + ans % 2)
Codeforces Round 407 (Div. 2)
CF
2,017
1
256
Anastasia and pebbles
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most k pebbles in each pocket at the same time....
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
null
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she co...
[{"input": "3 2\n2 3 4", "output": "3"}, {"input": "5 4\n3 1 8 9 7", "output": "5"}]
1,100
["implementation", "math"]
31
[{"input": "3 2\r\n2 3 4\r\n", "output": "3\r\n"}, {"input": "5 4\r\n3 1 8 9 7\r\n", "output": "5\r\n"}, {"input": "1 22\r\n1\r\n", "output": "1\r\n"}, {"input": "3 57\r\n78 165 54\r\n", "output": "3\r\n"}, {"input": "5 72\r\n74 10 146 189 184\r\n", "output": "6\r\n"}, {"input": "9 13\r\n132 87 200 62 168 51 185 192 11...
false
stdio
null
true
789/A
789
A
PyPy 3-64
TESTS
5
61
14,028,800
184479098
from sys import stdin; inp = stdin.readline from math import dist, ceil, floor, sqrt, log def IA(): return list(map(int, inp().split())) def FA(): return list(map(float, inp().split())) def SA(): return inp().split() def I(): return int(inp()) def F(): return float(inp()) def S(): return inp() def main(): n,k = IA...
31
92
11,161,600
212566831
import math n,k = (int(x) for x in input().split()) w = [int(x) for x in input().split()] d = 0 for x in w: d += math.ceil(x/k) print(math.ceil(d/2))
Codeforces Round 407 (Div. 2)
CF
2,017
1
256
Anastasia and pebbles
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most k pebbles in each pocket at the same time....
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
null
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she co...
[{"input": "3 2\n2 3 4", "output": "3"}, {"input": "5 4\n3 1 8 9 7", "output": "5"}]
1,100
["implementation", "math"]
31
[{"input": "3 2\r\n2 3 4\r\n", "output": "3\r\n"}, {"input": "5 4\r\n3 1 8 9 7\r\n", "output": "5\r\n"}, {"input": "1 22\r\n1\r\n", "output": "1\r\n"}, {"input": "3 57\r\n78 165 54\r\n", "output": "3\r\n"}, {"input": "5 72\r\n74 10 146 189 184\r\n", "output": "6\r\n"}, {"input": "9 13\r\n132 87 200 62 168 51 185 192 11...
false
stdio
null
true
38/D
38
D
Python 3
TESTS
3
216
0
59274172
n = int(input()) a = list(map(int,input().split())) k = 1 ob = r = 0 for i in range(n-1): b = list(map(int,input().split())) if b[1]==a[1]: if a[0]<b[0] and a[2]<b[2]: if a[2]-b[0]>=b[2]-a[2]: k+=1 else: break else: if b[2]-a[0]>=a[0]-b[0]: ...
64
342
22,220,800
86059864
n = int(input()) l = [] m = [] for i in range(n): X1, Y1, X2, Y2 = map(int, input().split()) m1 = (abs(X2 - X1)) ** 3 l.append([X1, Y1, X2, Y2]) m.append(m1) X1, Y1, X2, Y2 = l[0][0], l[0][1], l[0][2], l[0][3] if X1 > X2: X2, X1 = X1, X2 if Y1 > Y2: Y1, Y2 = Y2, Y1 ans = n for i in range(1, n): for ...
School Personal Contest #1 (Winter Computer School 2010/11) - Codeforces Beta Round 38 (ACM-ICPC Rules)
ICPC
2,010
2
256
Vasya the Architect
Once Vasya played bricks. All the bricks in the set had regular cubical shape. Vasya vas a talented architect, however the tower he built kept falling apart. Let us consider the building process. Vasya takes a brick and puts it on top of the already built tower so that the sides of the brick are parallel to the sides ...
The first input file contains an integer n (1 ≤ n ≤ 100) which is the number of bricks. Each of the next n lines contains four numbers xi, 1, yi, 1, xi, 2, yi, 2 (xi, 1 ≠ xi, 2, |xi, 1 - xi, 2| = |yi, 1 - yi, 2|) which are the coordinates of the opposite angles of the base of the brick number i. The coordinates are int...
Print the number of bricks in the maximal stable tower.
null
null
[{"input": "2\n0 0 3 3\n1 0 4 3", "output": "2"}, {"input": "2\n0 0 3 3\n2 0 5 3", "output": "1"}, {"input": "3\n0 0 3 3\n1 0 4 3\n2 0 5 3", "output": "3"}]
1,900
["implementation"]
64
[{"input": "2\r\n0 0 3 3\r\n1 0 4 3\r\n", "output": "2\r\n"}, {"input": "2\r\n0 0 3 3\r\n2 0 5 3\r\n", "output": "1\r\n"}, {"input": "3\r\n0 0 3 3\r\n1 0 4 3\r\n2 0 5 3\r\n", "output": "3\r\n"}, {"input": "5\r\n7 -10 -8 5\r\n4 -7 -5 2\r\n2 -5 -3 0\r\n-9 48 50 -11\r\n50 -4 -2 48\r\n", "output": "3\r\n"}, {"input": "5\r\...
false
stdio
null
true
952/E
952
E
PyPy 3
TESTS
2
124
0
70402735
n = int(input()) ans = 0 for _ in range(n): name = input().split(" ")[0] for ch in name: if ch == "m": ans += 1 print(ans)
40
78
7,065,600
36828940
def main(): n = int(input()) b, w = 0, 0 for x in range(n): s = input().split()[1] if s == 'soft': b += 1 else: w += 1 for x in range(1, 100): a = x ** 2 a1 = a // 2 a2 = a - a1 if max(b, w) <= a2 and min(b, w) <= a1: ...
April Fools Contest 2018
ICPC
2,018
1
256
Cheese Board
Not to be confused with chessboard.
The first line of input contains a single integer N (1 ≤ N ≤ 100) — the number of cheeses you have. The next N lines describe the cheeses you have. Each line contains two space-separated strings: the name of the cheese and its type. The name is a string of lowercase English letters between 1 and 10 characters long. Th...
Output a single number.
null
null
[{"input": "9\nbrie soft\ncamembert soft\nfeta soft\ngoat soft\nmuenster soft\nasiago hard\ncheddar hard\ngouda hard\nswiss hard", "output": "3"}, {"input": "6\nparmesan hard\nemmental hard\nedam hard\ncolby hard\ngruyere hard\nasiago hard", "output": "4"}]
2,000
[]
40
[{"input": "9\r\nbrie soft\r\ncamembert soft\r\nfeta soft\r\ngoat soft\r\nmuenster soft\r\nasiago hard\r\ncheddar hard\r\ngouda hard\r\nswiss hard\r\n", "output": "3\r\n"}, {"input": "6\r\nparmesan hard\r\nemmental hard\r\nedam hard\r\ncolby hard\r\ngruyere hard\r\nasiago hard\r\n", "output": "4\r\n"}, {"input": "9\r\n...
false
stdio
null
true
952/E
952
E
PyPy 3
TESTS
2
124
0
74886692
def count(string): x = 0 for char in string: if char == 'm': x += 1 return x x = int(input()) final = "" while x > 0: data = input().split() final += data[0] x -= 1 print(count(final))
40
78
7,065,600
36840633
N = int(input()) # n, m = map(int, input().split()) hard = 0 soft = 0 for _ in range(N): _, tp = input().split() if tp == 'hard': hard += 1 else: soft += 1 top = max(soft, hard) total = soft + hard i = 1 while True: size = i * i val = size // 2 if (i % 2) != 0: val += 1...
April Fools Contest 2018
ICPC
2,018
1
256
Cheese Board
Not to be confused with chessboard.
The first line of input contains a single integer N (1 ≤ N ≤ 100) — the number of cheeses you have. The next N lines describe the cheeses you have. Each line contains two space-separated strings: the name of the cheese and its type. The name is a string of lowercase English letters between 1 and 10 characters long. Th...
Output a single number.
null
null
[{"input": "9\nbrie soft\ncamembert soft\nfeta soft\ngoat soft\nmuenster soft\nasiago hard\ncheddar hard\ngouda hard\nswiss hard", "output": "3"}, {"input": "6\nparmesan hard\nemmental hard\nedam hard\ncolby hard\ngruyere hard\nasiago hard", "output": "4"}]
2,000
[]
40
[{"input": "9\r\nbrie soft\r\ncamembert soft\r\nfeta soft\r\ngoat soft\r\nmuenster soft\r\nasiago hard\r\ncheddar hard\r\ngouda hard\r\nswiss hard\r\n", "output": "3\r\n"}, {"input": "6\r\nparmesan hard\r\nemmental hard\r\nedam hard\r\ncolby hard\r\ngruyere hard\r\nasiago hard\r\n", "output": "4\r\n"}, {"input": "9\r\n...
false
stdio
null
true
326/A
335
A
Python 3
TESTS
10
92
0
164601029
s = input() n = int(input()) import math my_dict = {} for l in s: if l in my_dict: my_dict[l] += 1 else: my_dict[l] = 1 for i in range(1, 1000): good = 0 for key, num in my_dict.items(): good += math.ceil(num/i) if good <= n: print(i) s = '' for key, n...
55
154
2,150,400
170897071
import sys import math import collections import random from heapq import heappush, heappop from functools import reduce input = sys.stdin.readline ints = lambda: list(map(int, input().split())) s = input().strip() n = int(input()) occ = collections.defaultdict(int) for c in s: occ[c] += 1 def works(x): an...
MemSQL start[c]up Round 2
CF
2,013
2
256
Banana
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets ...
The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n (1 ≤ n ≤ 1000).
On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print ...
null
In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".
[{"input": "banana\n4", "output": "2\nbaan"}, {"input": "banana\n3", "output": "3\nnab"}, {"input": "banana\n2", "output": "-1"}]
1,400
[]
55
[{"input": "banana\r\n4\r\n", "output": "2\r\nbaan\r\n"}, {"input": "banana\r\n3\r\n", "output": "3\r\nnab\r\n"}, {"input": "banana\r\n2\r\n", "output": "-1\r\n"}, {"input": "p\r\n1000\r\n", "output": "1\npaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
false
stdio
import sys from math import ceil from collections import defaultdict def main(input_path, output_path, submission_path): with open(input_path) as f: s = f.readline().strip() n = int(f.readline().strip()) s_counts = defaultdict(int) for c in s: s_counts[c] += 1 def is_possible(...
true
53/D
53
D
PyPy 3
TESTS
0
216
0
63969774
n = int(input()) *a, = map(int, input().split()) *b, = map(int, input().split()) ans, s, k = [], 0, 0 while a: x = a.index(b[k]) a.remove(b[k]) ans.append((x + k + 1, k + 1)) s += x k += 1 print(s) for i in ans: for j in range(i[0], i[1], -1): print(j, j - 1)
30
186
8,499,200
208562183
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) l = [] i1 = -1 for i in range(n): if a[i] == b[i]: continue else: for j in range(i+1, n): if a[i] == b[j]: i1 = j break # print('i->', i, ' i1->', i1) ...
Codeforces Beta Round 49 (Div. 2)
CF
2,011
2
256
Physical Education
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line...
The first line contains an integer n (1 ≤ n ≤ 300) which is the number of students. The second line contains n space-separated integers ai (1 ≤ ai ≤ 109) which represent the height of the student occupying the i-th place must possess. The third line contains n space-separated integers bi (1 ≤ bi ≤ 109) which represent ...
In the first line print an integer k (0 ≤ k ≤ 106) which is the number of moves. It is not required to minimize k but it must not exceed 106. Then print k lines each containing two space-separated integers. Line pi, pi + 1 (1 ≤ pi ≤ n - 1) means that Vasya should swap students occupying places pi and pi + 1.
null
null
[{"input": "4\n1 2 3 2\n3 2 1 2", "output": "4\n2 3\n1 2\n3 4\n2 3"}, {"input": "2\n1 100500\n1 100500", "output": "0"}]
1,500
["sortings"]
30
[{"input": "4\r\n1 2 3 2\r\n3 2 1 2\r\n", "output": "4\r\n2 3\r\n1 2\r\n3 4\r\n2 3\r\n"}, {"input": "2\r\n1 100500\r\n1 100500\r\n", "output": "0\r\n"}, {"input": "3\r\n652586118 652586118 652586118\r\n652586118 652586118 652586118\r\n", "output": "3\r\n2 3\r\n1 2\r\n2 3\r\n"}, {"input": "4\r\n681106577 681106577 67507...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path, 'r') as f_input: n = int(f_input.readline().strip()) a = list(map(int, f_input.readline().split())) initial_b = list(map(int, f_input.readline().split())) with open(submission_path, 'r') as f_submi...
true
952/E
952
E
Python 3
TESTS
2
108
0
75699460
n = int(input()) ans = 0 for _ in range(n): name = input().split()[0] for c in name: if c=='m': ans += 1 print(ans)
40
78
7,065,600
36845632
N = int(input()) w, b = 0, 0 for n in range(N): cheese, color = input().split() if color == 'hard': b += 1 else: w += 1 for k in range(1, 16): if b <= k**2 // 2 and w <= k**2 // 2 or \ k % 2 == 1 and max(b, w) <= (k**2 + 1) // 2 and b + w <= k**2: print(k) break
April Fools Contest 2018
ICPC
2,018
1
256
Cheese Board
Not to be confused with chessboard.
The first line of input contains a single integer N (1 ≤ N ≤ 100) — the number of cheeses you have. The next N lines describe the cheeses you have. Each line contains two space-separated strings: the name of the cheese and its type. The name is a string of lowercase English letters between 1 and 10 characters long. Th...
Output a single number.
null
null
[{"input": "9\nbrie soft\ncamembert soft\nfeta soft\ngoat soft\nmuenster soft\nasiago hard\ncheddar hard\ngouda hard\nswiss hard", "output": "3"}, {"input": "6\nparmesan hard\nemmental hard\nedam hard\ncolby hard\ngruyere hard\nasiago hard", "output": "4"}]
2,000
[]
40
[{"input": "9\r\nbrie soft\r\ncamembert soft\r\nfeta soft\r\ngoat soft\r\nmuenster soft\r\nasiago hard\r\ncheddar hard\r\ngouda hard\r\nswiss hard\r\n", "output": "3\r\n"}, {"input": "6\r\nparmesan hard\r\nemmental hard\r\nedam hard\r\ncolby hard\r\ngruyere hard\r\nasiago hard\r\n", "output": "4\r\n"}, {"input": "9\r\n...
false
stdio
null
true
792/F
792
F
Python 3
TESTS
34
966
5,529,600
26344675
def check_battle(t, h, m, spell_1, spell_2): x1, y1 = spell_1 x2, y2 = spell_2 if y1 * h <= x1 * m and h <= x1 * t: return True if y2 * h <= x2 * m and h <= x2 * t: return True return False def main(): q, m = map(int, input().split()) spell_1 = None spell_2 = None ...
36
873
15,564,800
37535361
#!/usr/bin/env python3 # solution after hint # (instead of best hit/mana spell store convex hull of spells) # O(n^2) instead of O(n log n) [q, m] = map(int, input().strip().split()) qis = [tuple(map(int, input().strip().split())) for _ in range(q)] mod = 10**6 j = 0 spell_chull = [(0, 0)] # lower hull _/ def is_...
Educational Codeforces Round 18
ICPC
2,017
2
256
Mages and Monsters
Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells. Vova's character can learn new spells during the game. Every spell is characterized by two values xi and yi — damage per second and mana cost per second, respectively. Vova ...
The first line contains two integer numbers q and m (2 ≤ q ≤ 105, 1 ≤ m ≤ 1012) — the number of queries and the amount of mana at the beginning of every fight. i-th of each next q lines contains three numbers ki, ai and bi (1 ≤ ki ≤ 2, 1 ≤ ai, bi ≤ 106). Using them you can restore queries this way: let j be the index...
For every query of second type print YES if Vova is able to win the fight with corresponding monster and NO otherwise.
null
In first example Vova's character at first learns the spell with 5 damage and 10 mana cost per second. Next query is a fight with monster which can kill character in 20 seconds and has 50 health points. Vova kills it in 10 seconds (spending 100 mana). Next monster has 52 health, so Vova can't deal that much damage with...
[{"input": "3 100\n1 4 9\n2 19 49\n2 19 49", "output": "YES\nNO"}]
3,100
["data structures", "geometry"]
36
[{"input": "3 100\r\n1 4 9\r\n2 19 49\r\n2 19 49\r\n", "output": "YES\r\nNO\r\n"}, {"input": "10 442006988299\r\n2 10 47\r\n1 9 83\r\n1 15 24\r\n2 19 47\r\n2 75 99\r\n2 85 23\r\n2 8 33\r\n2 9 82\r\n1 86 49\r\n2 71 49\r\n", "output": "NO\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\n"}, {"input": "2 424978864039\r\n2 7 3...
false
stdio
null
true
53/D
53
D
PyPy 3
TESTS
0
216
0
46990074
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) num = 0 swap = [] for i in range(n - 1, -1, -1): if b[i] != a[i]: num += 1 right = a[i] ind = b.index(right) s = b[i] b[i] = a[i] b[ind] = s li = [str(ind + 1),str(i + 1)]...
30
216
8,908,800
177776370
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) d = [] for i in range(n): x = b.index(a[i]) for j in range(x+i, i, -1): d.append((j, j+1)) b = b[:x] + b[x+1:] print(len(d)) for i in d: print(*i)
Codeforces Beta Round 49 (Div. 2)
CF
2,011
2
256
Physical Education
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line...
The first line contains an integer n (1 ≤ n ≤ 300) which is the number of students. The second line contains n space-separated integers ai (1 ≤ ai ≤ 109) which represent the height of the student occupying the i-th place must possess. The third line contains n space-separated integers bi (1 ≤ bi ≤ 109) which represent ...
In the first line print an integer k (0 ≤ k ≤ 106) which is the number of moves. It is not required to minimize k but it must not exceed 106. Then print k lines each containing two space-separated integers. Line pi, pi + 1 (1 ≤ pi ≤ n - 1) means that Vasya should swap students occupying places pi and pi + 1.
null
null
[{"input": "4\n1 2 3 2\n3 2 1 2", "output": "4\n2 3\n1 2\n3 4\n2 3"}, {"input": "2\n1 100500\n1 100500", "output": "0"}]
1,500
["sortings"]
30
[{"input": "4\r\n1 2 3 2\r\n3 2 1 2\r\n", "output": "4\r\n2 3\r\n1 2\r\n3 4\r\n2 3\r\n"}, {"input": "2\r\n1 100500\r\n1 100500\r\n", "output": "0\r\n"}, {"input": "3\r\n652586118 652586118 652586118\r\n652586118 652586118 652586118\r\n", "output": "3\r\n2 3\r\n1 2\r\n2 3\r\n"}, {"input": "4\r\n681106577 681106577 67507...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path, 'r') as f_input: n = int(f_input.readline().strip()) a = list(map(int, f_input.readline().split())) initial_b = list(map(int, f_input.readline().split())) with open(submission_path, 'r') as f_submi...
true
326/A
335
A
Python 3
TESTS
10
92
102,400
168198338
from collections import Counter from math import ceil # one list = many stickers s = input() n = int(input()) counter_str = Counter(s) def get_sticker_len(list_num, counter: dict): alpha_per_sticker = [ceil(count / list_num) for alpha, count in counter.items()] sticker_len = sum(alpha_per_sticker) retur...
55
186
0
197610547
s = input() n = int(input()) d = {} r = 0 for a in s: d.setdefault(a, 0) d[a] += 1 if(d[a] > r): r = d[a] if (len(d) > n): print(-1) else: l = 0 while r - l > 1: k = (l + r) // 2 cur = 0 for x in d.values(): cur += (x+k-1) // k if cur > n: ...
MemSQL start[c]up Round 2
CF
2,013
2
256
Banana
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets ...
The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n (1 ≤ n ≤ 1000).
On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print ...
null
In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".
[{"input": "banana\n4", "output": "2\nbaan"}, {"input": "banana\n3", "output": "3\nnab"}, {"input": "banana\n2", "output": "-1"}]
1,400
[]
55
[{"input": "banana\r\n4\r\n", "output": "2\r\nbaan\r\n"}, {"input": "banana\r\n3\r\n", "output": "3\r\nnab\r\n"}, {"input": "banana\r\n2\r\n", "output": "-1\r\n"}, {"input": "p\r\n1000\r\n", "output": "1\npaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
false
stdio
import sys from math import ceil from collections import defaultdict def main(input_path, output_path, submission_path): with open(input_path) as f: s = f.readline().strip() n = int(f.readline().strip()) s_counts = defaultdict(int) for c in s: s_counts[c] += 1 def is_possible(...
true
785/A
785
A
Python 3
TESTS
1
30
0
230913379
n=int(input()) s=[] b=0 for i in range(n): a=input() s.append(a) if "Icosahedron" in s: b=b+20 if "Cube" in s: b=b+6 if "Tetrahedron" in s: b=b+4 if "Dodecahedron" in s: b=b+12 if "Octahedron" in s: b=b+8 print(b)
30
78
0
219701900
from sys import stdin input() count =0 s = {"T":4, "C":6, "O":8, "D":12, "I":20} for x in stdin: count += s[x[0]] print(count)
Codeforces Round 404 (Div. 2)
CF
2,017
2
256
Anton and Polyhedrons
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. I...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of polyhedrons in Anton's collection. Each of the following n lines of the input contains a string si — the name of the i-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (without quotes), if the ...
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
null
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
[{"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42"}, {"input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28"}]
800
["implementation", "strings"]
30
[{"input": "4\r\nIcosahedron\r\nCube\r\nTetrahedron\r\nDodecahedron\r\n", "output": "42\r\n"}, {"input": "3\r\nDodecahedron\r\nOctahedron\r\nOctahedron\r\n", "output": "28\r\n"}, {"input": "25\r\nIcosahedron\r\nOctahedron\r\nTetrahedron\r\nDodecahedron\r\nCube\r\nIcosahedron\r\nOctahedron\r\nCube\r\nTetrahedron\r\nIcos...
false
stdio
null
true
326/A
335
A
PyPy 3
TESTS
10
154
20,172,800
130019868
def check(x): cnt=0 for i in range(26): cnt+=(ltrs[i] + x - 1) // x if(cnt > n): return False return True a = input() ltrs = [0] * 26 for i in a: ltrs[ord(i) - ord('a')]+=1 n = int(input()) s = 0 for j in ltrs: s+=int(j != 0) if(s > n): print(-1) exit(0) l = 0 r ...
55
218
0
41984211
s = input() n = int(input()) d = {} for c in s: if c not in d: d[c] = 0 d[c] += 1 dcl = d.values() found = False for x in range(1,1001): if sum([(dc-1)//x+1 for dc in dcl]) <= n: found = True print(x) s = ''.join([key*((d[key]-1)//x+1) for key in sorted(d.keys()...
MemSQL start[c]up Round 2
CF
2,013
2
256
Banana
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets ...
The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n (1 ≤ n ≤ 1000).
On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print ...
null
In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".
[{"input": "banana\n4", "output": "2\nbaan"}, {"input": "banana\n3", "output": "3\nnab"}, {"input": "banana\n2", "output": "-1"}]
1,400
[]
55
[{"input": "banana\r\n4\r\n", "output": "2\r\nbaan\r\n"}, {"input": "banana\r\n3\r\n", "output": "3\r\nnab\r\n"}, {"input": "banana\r\n2\r\n", "output": "-1\r\n"}, {"input": "p\r\n1000\r\n", "output": "1\npaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
false
stdio
import sys from math import ceil from collections import defaultdict def main(input_path, output_path, submission_path): with open(input_path) as f: s = f.readline().strip() n = int(f.readline().strip()) s_counts = defaultdict(int) for c in s: s_counts[c] += 1 def is_possible(...
true
326/A
335
A
Python 3
TESTS
10
280
409,600
93626775
from math import ceil from collections import Counter s = input(); n = int(input()) c = Counter(s) def f(x): m = n for i in c: m -= ceil(c[i]/x) if m < 0: return(False) return(True) if n < len(c):print(-1);exit() ans = 1 while not f(ans): ans += 1 # ans -= 1 prin...
55
218
0
48184018
s = input() n = int(input()) cnt = {} for c in s: if cnt.get(c) == None: cnt[c] = 1 else: cnt[c] += 1 if (n < len(cnt)): print(-1) else: ansNum = 0; while(True): ansNum+=1 l = 0; char = [] for c, v in cnt.items(): need = (v + ansNum -1)//a...
MemSQL start[c]up Round 2
CF
2,013
2
256
Banana
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets ...
The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n (1 ≤ n ≤ 1000).
On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print ...
null
In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".
[{"input": "banana\n4", "output": "2\nbaan"}, {"input": "banana\n3", "output": "3\nnab"}, {"input": "banana\n2", "output": "-1"}]
1,400
[]
55
[{"input": "banana\r\n4\r\n", "output": "2\r\nbaan\r\n"}, {"input": "banana\r\n3\r\n", "output": "3\r\nnab\r\n"}, {"input": "banana\r\n2\r\n", "output": "-1\r\n"}, {"input": "p\r\n1000\r\n", "output": "1\npaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
false
stdio
import sys from math import ceil from collections import defaultdict def main(input_path, output_path, submission_path): with open(input_path) as f: s = f.readline().strip() n = int(f.readline().strip()) s_counts = defaultdict(int) for c in s: s_counts[c] += 1 def is_possible(...
true
326/A
335
A
PyPy 3
TESTS
10
248
1,638,400
105237797
from collections import defaultdict s = input() n = int(input()) if len(set(s)) > n: print(-1) else: hist = defaultdict(int) for c in s: hist[c] += 1 for ans in range(1, 2000): cur_need = 0 for c in hist: # ans * t >= hist[c] # t >= hist[c]...
55
248
5,222,400
4223318
import math from fractions import Decimal S=input() N=int(input()) Srep={} ansrep={} for item in "abcdefghijklmnopqrstuvwxyz": Srep[item]=0 ansrep[item]=0 for item in S: Srep[item]+=1 ansrep[item]+=1 Q=list(set(S)) if(len(Q)>N): print(-1) else: n=len(Q) ans=list(S) num=1 req=1 ...
MemSQL start[c]up Round 2
CF
2,013
2
256
Banana
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets ...
The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n (1 ≤ n ≤ 1000).
On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print ...
null
In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".
[{"input": "banana\n4", "output": "2\nbaan"}, {"input": "banana\n3", "output": "3\nnab"}, {"input": "banana\n2", "output": "-1"}]
1,400
[]
55
[{"input": "banana\r\n4\r\n", "output": "2\r\nbaan\r\n"}, {"input": "banana\r\n3\r\n", "output": "3\r\nnab\r\n"}, {"input": "banana\r\n2\r\n", "output": "-1\r\n"}, {"input": "p\r\n1000\r\n", "output": "1\npaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
false
stdio
import sys from math import ceil from collections import defaultdict def main(input_path, output_path, submission_path): with open(input_path) as f: s = f.readline().strip() n = int(f.readline().strip()) s_counts = defaultdict(int) for c in s: s_counts[c] += 1 def is_possible(...
true
785/A
785
A
PyPy 3-64
TESTS
1
46
0
208853226
x=int(input()) c=0 L=[] d={"Tetrahedron":4,"Cube":6,"Octahedron":8,"Dodecahedron":12,"Icosahedron":20} for i in range(x): a=input() L.append(a) for i in d: if i in L: c+=d[i] print(c)
30
93
0
206068158
from sys import stdin def solve1(): s = {"T":4, "C":6, "O":8, "D":12, "I":20} c = 0 for i in range(int(input())): c += s[stdin.readline().strip()[0]] print(c) solve1()
Codeforces Round 404 (Div. 2)
CF
2,017
2
256
Anton and Polyhedrons
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. I...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of polyhedrons in Anton's collection. Each of the following n lines of the input contains a string si — the name of the i-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (without quotes), if the ...
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
null
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
[{"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42"}, {"input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28"}]
800
["implementation", "strings"]
30
[{"input": "4\r\nIcosahedron\r\nCube\r\nTetrahedron\r\nDodecahedron\r\n", "output": "42\r\n"}, {"input": "3\r\nDodecahedron\r\nOctahedron\r\nOctahedron\r\n", "output": "28\r\n"}, {"input": "25\r\nIcosahedron\r\nOctahedron\r\nTetrahedron\r\nDodecahedron\r\nCube\r\nIcosahedron\r\nOctahedron\r\nCube\r\nTetrahedron\r\nIcos...
false
stdio
null
true
180/A
180
A
Python 3
TESTS
3
124
5,632,000
35485996
""" Brandt Smith, Peter Haddad and Lemuel Gorion codeforces.com Problem 180A """ c, f = input().split(' ') hd = [0] * int(c) total_count = 0 zeros = [] moves = [] for i in range(int(f)): file = input().split() for x in range(1,len(file)): hd[int(file[x]) - 1] = [i + 1,x] for x in range(len(h...
24
248
512,000
73525986
import sys n, m, *inp = map(int, sys.stdin.read().split()) inp.reverse() f = [[0 for x in range(201)] for y in range(201)] #2D Array c = [(0,0)]*201 f_size = [0]*201 def putData(f_id, s_id, c_id): global f, c f[f_id][s_id] = c_id c[c_id] = (f_id, s_id) for f_id in range(1, m+1): f_size[f_id] = in...
Codeforces Round 116 (Div. 2, ACM-ICPC Rules)
ICPC
2,012
1
256
Defragmentation
In this problem you have to implement an algorithm to defragment your hard disk. The hard disk consists of a sequence of clusters, numbered by integers from 1 to n. The disk has m recorded files, the i-th file occupies clusters with numbers ai, 1, ai, 2, ..., ai, ni. These clusters are not necessarily located consecuti...
The first line contains two integers n and m (1 ≤ n, m ≤ 200) — the number of clusters and the number of files, correspondingly. Next m lines contain descriptions of the files. The first number in the line is ni (ni ≥ 1), the number of clusters occupied by the i-th file. Then follow ni numbers ai, 1, ai, 2, ..., ai, ni...
In the first line print a single integer k (0 ≤ k ≤ 2n) — the number of operations needed to defragment the disk. Next k lines should contain the operations' descriptions as "i j" (copy the contents of the cluster number i to the cluster number j).
null
Let's say that a disk consists of 8 clusters and contains two files. The first file occupies two clusters and the second file occupies three clusters. Let's look at examples of correct and incorrect positions of files after defragmentation. $$$$ Example 2: each file must occupy a contiguous area of memory. Example 3...
[{"input": "7 2\n2 1 2\n3 3 4 5", "output": "0"}, {"input": "7 2\n2 1 3\n3 2 4 5", "output": "3\n2 6\n3 2\n6 3"}]
1,800
["implementation"]
24
[{"input": "7 2\r\n2 1 2\r\n3 3 4 5\r\n", "output": "0\r\n"}, {"input": "7 2\r\n2 1 3\r\n3 2 4 5\r\n", "output": "3\r\n2 6\r\n3 2\r\n6 3\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "1\r\n2 1\r\n"}, {"input": "3 1\r\n2 3 1\r\n", "output": "2\r\n1 2\r\n3 1\r\n"}, {"input": "3 2\r\n1 3\r\n1 2\r\n", "output": "1\r\n3 1\r\...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path, 'r') as f: lines = f.readlines() n, m = map(int, lines[0].split()) files = [] S = set() for line in lines[1:m+1]: parts = list(...
true
463/B
463
B
PyPy 3-64
TESTS
7
62
1,843,200
197665107
n = int(input()) a = list(map(int , input().split())) s = 0 c = 0 x = 0 for el in range(0, n-1) : y = a[el] s += x - y if(s < 0): c += -s s = 0 x = y print(c)
49
62
7,270,400
176981889
l=int(input()) pylon=list(map(int,(input().split()))) print(max(pylon))
Codeforces Round 264 (Div. 2)
CF
2,014
1
256
Caisa and Pylons
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,...
The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 105) representing the heights of the pylons.
Print a single number representing the minimum number of dollars paid by Caisa.
null
In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
[{"input": "5\n3 4 3 2 4", "output": "4"}, {"input": "3\n4 4 4", "output": "4"}]
1,100
["brute force", "implementation", "math"]
49
[{"input": "5\r\n3 4 3 2 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 4 4\r\n", "output": "4\r\n"}, {"input": "99\r\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...
false
stdio
null
true
785/A
785
A
Python 3
TESTS
3
46
0
226594718
polyhedrons = int(input()) shape = 0 count = 0 for a in range(polyhedrons): shape = input() if 'u' in shape: count += 6 elif 'i' in shape: count += 20 elif shape == 'Tetrahedon': count += 4 elif shape == 'Octahedron': count += 8 else: count += 12 print(cou...
30
93
3,379,200
201229057
from sys import stdin input = stdin.readline def main(): n = int(input()) res = 0 for _ in range(0, n): s = input()[:-1] if s == "Tetrahedron": res += 4 elif s == "Cube": res += 6 elif s == "Octahedron": res += 8 elif s == "Dodecah...
Codeforces Round 404 (Div. 2)
CF
2,017
2
256
Anton and Polyhedrons
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. I...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of polyhedrons in Anton's collection. Each of the following n lines of the input contains a string si — the name of the i-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (without quotes), if the ...
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
null
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
[{"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42"}, {"input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28"}]
800
["implementation", "strings"]
30
[{"input": "4\r\nIcosahedron\r\nCube\r\nTetrahedron\r\nDodecahedron\r\n", "output": "42\r\n"}, {"input": "3\r\nDodecahedron\r\nOctahedron\r\nOctahedron\r\n", "output": "28\r\n"}, {"input": "25\r\nIcosahedron\r\nOctahedron\r\nTetrahedron\r\nDodecahedron\r\nCube\r\nIcosahedron\r\nOctahedron\r\nCube\r\nTetrahedron\r\nIcos...
false
stdio
null
true
785/A
785
A
Python 3
TESTS
1
31
0
207761223
n = int(input()) d = {};c=0 r={"Tetrahedron":4,"Cube":6,"Octahedron":8,"Dodecahedron":12} for i in range(n): x = input() d[x] = d.get(x,0) + 1 c = 0 for k,v in d.items(): c += r.get(k,20) print(c)
30
93
3,481,600
224754672
import sys #f=open("C:/Users/MAHAMUD MATIN/Desktop/input.txt", "r") f=sys.stdin n=int(f.readline()) total=0 for i in range(n): s=f.readline() if s[0]=="T": total+=4 elif s[0]=="C": total+=6 elif s[0]=="O": total+=8 elif s[0]=="D": total+=12 else: total+=20...
Codeforces Round 404 (Div. 2)
CF
2,017
2
256
Anton and Polyhedrons
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. I...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of polyhedrons in Anton's collection. Each of the following n lines of the input contains a string si — the name of the i-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (without quotes), if the ...
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
null
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
[{"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42"}, {"input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28"}]
800
["implementation", "strings"]
30
[{"input": "4\r\nIcosahedron\r\nCube\r\nTetrahedron\r\nDodecahedron\r\n", "output": "42\r\n"}, {"input": "3\r\nDodecahedron\r\nOctahedron\r\nOctahedron\r\n", "output": "28\r\n"}, {"input": "25\r\nIcosahedron\r\nOctahedron\r\nTetrahedron\r\nDodecahedron\r\nCube\r\nIcosahedron\r\nOctahedron\r\nCube\r\nTetrahedron\r\nIcos...
false
stdio
null
true
785/A
785
A
Python 3
TESTS
1
31
0
225039134
n = int(input()) t = 0 c = 0 o = 0 d = 0 ic = 0 for i in range(n): s = input() if s== "Tetrahedron": t = 4 elif s == "Cube": c = 6 elif s == "Octahedron": o = 8 elif s == "Dodecahedron": d = 12 elif s == "Icosahedron": ic = 20 print(t+c+o+d+ic)
30
93
3,584,000
230657126
import sys input = sys.stdin.readline n = int(input()) count = 0 for _ in range(n): string = str(input())[:-1] # Eliminating the newline character if string == "Tetrahedron": count += 4 elif string == "Cube": count += 6 elif string == "Octahedron": count += 8 elif stri...
Codeforces Round 404 (Div. 2)
CF
2,017
2
256
Anton and Polyhedrons
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. I...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of polyhedrons in Anton's collection. Each of the following n lines of the input contains a string si — the name of the i-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (without quotes), if the ...
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
null
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
[{"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42"}, {"input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28"}]
800
["implementation", "strings"]
30
[{"input": "4\r\nIcosahedron\r\nCube\r\nTetrahedron\r\nDodecahedron\r\n", "output": "42\r\n"}, {"input": "3\r\nDodecahedron\r\nOctahedron\r\nOctahedron\r\n", "output": "28\r\n"}, {"input": "25\r\nIcosahedron\r\nOctahedron\r\nTetrahedron\r\nDodecahedron\r\nCube\r\nIcosahedron\r\nOctahedron\r\nCube\r\nTetrahedron\r\nIcos...
false
stdio
null
true
463/B
463
B
Python 3
TESTS
7
109
614,400
85656454
n=int(input()) l=list(map(int,input().split())) k=-l[0] t=0 for i in range(1,n): if k<=0: t+=k k=0 k+=(l[i-1]-l[i]) print(abs(t))
49
62
7,372,800
138479829
n = int(input()) list1 = list(map(int, input().strip().split())) print(max(list1))
Codeforces Round 264 (Div. 2)
CF
2,014
1
256
Caisa and Pylons
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,...
The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 105) representing the heights of the pylons.
Print a single number representing the minimum number of dollars paid by Caisa.
null
In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
[{"input": "5\n3 4 3 2 4", "output": "4"}, {"input": "3\n4 4 4", "output": "4"}]
1,100
["brute force", "implementation", "math"]
49
[{"input": "5\r\n3 4 3 2 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 4 4\r\n", "output": "4\r\n"}, {"input": "99\r\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...
false
stdio
null
true
526/B
526
B
Python 3
TESTS
1
62
0
10623894
def balance(node): if node >= (2 ** n): return 0 else: c1 = balance(2*node) c2 = balance(2*node+1) #print(node) a = abs(c1 - c2) b = abs(tree[2*node - 2] - tree[2*node - 1]) global count count += (a+b) if c1 > c2: tree[2*node - ...
38
46
0
11142882
# 526B __author__ = 'artyom' n = int(input()) a = [0, 0] + list(map(int, input().split())) comp = 0 for i in range(2 ** (n + 1) - 1, 1, -2): diff = abs(a[i] - a[i - 1]) comp += diff a[i // 2] += max(a[i], a[i - 1]) print(comp)
ZeptoLab Code Rush 2015
CF
2,015
1
256
Om Nom and Dark Park
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him. The park consists of 2n + 1 - 1 squares connected by roads so that ...
The first line contains integer n (1 ≤ n ≤ 10) — the number of roads on the path from the entrance to any exit. The next line contains 2n + 1 - 2 numbers a2, a3, ... a2n + 1 - 1 — the initial numbers of street lights on each road of the park. Here ai is the number of street lights on the road between squares i and $$\...
Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe.
null
Picture for the sample test. Green color denotes the additional street lights.
[{"input": "2\n1 2 3 4 5 6", "output": "5"}]
1,400
["dfs and similar", "greedy", "implementation"]
38
[{"input": "2\r\n1 2 3 4 5 6\r\n", "output": "5\r\n"}, {"input": "2\r\n1 2 3 3 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n39 52\r\n", "output": "13\r\n"}, {"input": "2\r\n59 96 34 48 8 72\r\n", "output": "139\r\n"}, {"input": "3\r\n87 37 91 29 58 45 51 74 70 71 47 38 91 89\r\n", "output": "210\r\n"}, {"input": "5\r\...
false
stdio
null
true
53/D
53
D
PyPy 3-64
TESTS
0
60
0
209350101
n=int(input()) l=list(map(int,input().split())) l1=list(map(int,input().split())) ans=[] for i in range(n): if(l[i]==l1[i]): continue for j in range(i,n): if(l[j]==l1[i]): break for k in range(j,i,-1): ans.append([k,k-1]) l[k-1],l[k]=l[k],l[k-1] print(len(ans)) fo...
30
216
9,113,600
208526211
n = int(input()) ls1 = list(map(int,input().split())) ls2 = list(map(int,input().split())) out = [] i, j = 0, 0 while i < n : while j < n and ls2[j] != ls1[i] : j += 1 while j != i : temp = ls2[j] ls2[j] = ls2[j-1] ls2[j-1] = temp out.append([j,j+1]) j -= 1 i ...
Codeforces Beta Round 49 (Div. 2)
CF
2,011
2
256
Physical Education
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line...
The first line contains an integer n (1 ≤ n ≤ 300) which is the number of students. The second line contains n space-separated integers ai (1 ≤ ai ≤ 109) which represent the height of the student occupying the i-th place must possess. The third line contains n space-separated integers bi (1 ≤ bi ≤ 109) which represent ...
In the first line print an integer k (0 ≤ k ≤ 106) which is the number of moves. It is not required to minimize k but it must not exceed 106. Then print k lines each containing two space-separated integers. Line pi, pi + 1 (1 ≤ pi ≤ n - 1) means that Vasya should swap students occupying places pi and pi + 1.
null
null
[{"input": "4\n1 2 3 2\n3 2 1 2", "output": "4\n2 3\n1 2\n3 4\n2 3"}, {"input": "2\n1 100500\n1 100500", "output": "0"}]
1,500
["sortings"]
30
[{"input": "4\r\n1 2 3 2\r\n3 2 1 2\r\n", "output": "4\r\n2 3\r\n1 2\r\n3 4\r\n2 3\r\n"}, {"input": "2\r\n1 100500\r\n1 100500\r\n", "output": "0\r\n"}, {"input": "3\r\n652586118 652586118 652586118\r\n652586118 652586118 652586118\r\n", "output": "3\r\n2 3\r\n1 2\r\n2 3\r\n"}, {"input": "4\r\n681106577 681106577 67507...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path, 'r') as f_input: n = int(f_input.readline().strip()) a = list(map(int, f_input.readline().split())) initial_b = list(map(int, f_input.readline().split())) with open(submission_path, 'r') as f_submi...
true
53/D
53
D
Python 3
TESTS
0
62
0
136226434
_ = input() a = list(map(int, input().split())) b = list(map(int, input().split())) c = 0 res = [] for i, item in enumerate(b): ii = i+a[i:].index(item) if i == ii: continue for shift in range(ii-i): res.append(f'{i+(ii-i)-shift+1} {i+(ii-i)-shift}') c += 1 a1 = a[i+(ii-i)-shift] a2 = a[i+(ii-i)-shift-...
30
218
512,000
105056041
n = int(input()) original = list(input().split()) given = list(input().split()) pre = [] last = [] result = 0 for i in range(n): if original[i] == given[i]: continue else: j = i + 1 index = len(pre) for j in range(i + 1, n): pre.insert(index, j + 1) las...
Codeforces Beta Round 49 (Div. 2)
CF
2,011
2
256
Physical Education
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line...
The first line contains an integer n (1 ≤ n ≤ 300) which is the number of students. The second line contains n space-separated integers ai (1 ≤ ai ≤ 109) which represent the height of the student occupying the i-th place must possess. The third line contains n space-separated integers bi (1 ≤ bi ≤ 109) which represent ...
In the first line print an integer k (0 ≤ k ≤ 106) which is the number of moves. It is not required to minimize k but it must not exceed 106. Then print k lines each containing two space-separated integers. Line pi, pi + 1 (1 ≤ pi ≤ n - 1) means that Vasya should swap students occupying places pi and pi + 1.
null
null
[{"input": "4\n1 2 3 2\n3 2 1 2", "output": "4\n2 3\n1 2\n3 4\n2 3"}, {"input": "2\n1 100500\n1 100500", "output": "0"}]
1,500
["sortings"]
30
[{"input": "4\r\n1 2 3 2\r\n3 2 1 2\r\n", "output": "4\r\n2 3\r\n1 2\r\n3 4\r\n2 3\r\n"}, {"input": "2\r\n1 100500\r\n1 100500\r\n", "output": "0\r\n"}, {"input": "3\r\n652586118 652586118 652586118\r\n652586118 652586118 652586118\r\n", "output": "3\r\n2 3\r\n1 2\r\n2 3\r\n"}, {"input": "4\r\n681106577 681106577 67507...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path, 'r') as f_input: n = int(f_input.readline().strip()) a = list(map(int, f_input.readline().split())) initial_b = list(map(int, f_input.readline().split())) with open(submission_path, 'r') as f_submi...
true
393/B
393
B
Python 3
TESTS
2
140
7,884,800
115450187
import sys from os import path from collections import Counter if(path.exists("inp.txt")): sys.stdin = open("inp.txt",'r') sys.stdout = open("out.txt",'w') import math n=int(input()) w=[] li=[0]*((2*n)-1) for i in range(n): temp=list(map(int,input().split())) w.append(temp) c=0 for i in range(n): for j in range(n)...
40
140
2,048,000
180742857
n = int(input()) W = [] for j in range(n): k = input().split() for i in range(n): k[i] = int(k[i]) W.append(k) A = [] for j in range(n): A.append([]) for i in range(n): a = (W[j][i]+W[i][j])/2 A[j].append(a) B = [] for j in range(n): B.append([]) for i in ran...
Codeforces Round 230 (Div. 2)
CF
2,014
1
256
Three matrices
Chubby Yang is studying linear equations right now. He came up with a nice problem. In the problem you are given an n × n matrix W, consisting of integers, and you should find two n × n matrices A and B, all the following conditions must hold: - Aij = Aji, for all i, j (1 ≤ i, j ≤ n); - Bij =  - Bji, for all i, j (1 ≤...
The first line contains an integer n (1 ≤ n ≤ 170). Each of the following n lines contains n integers. The j-th integer in the i-th line is Wij (0 ≤ |Wij| < 1717).
The first n lines must contain matrix A. The next n lines must contain matrix B. Print the matrices in the format equal to format of matrix W in input. It is guaranteed that the answer exists. If there are multiple answers, you are allowed to print any of them. The answer will be considered correct if the absolute or ...
null
null
[{"input": "2\n1 4\n3 2", "output": "1.00000000 3.50000000\n3.50000000 2.00000000\n0.00000000 0.50000000\n-0.50000000 0.00000000"}, {"input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "1.00000000 3.00000000 5.00000000\n3.00000000 5.00000000 7.00000000\n5.00000000 7.00000000 9.00000000\n0.00000000 -1.00000000 -2.00000000\n1.0...
null
[]
40
[{"input": "2\r\n1 4\r\n3 2\r\n", "output": "1.00000000 3.50000000\r\n3.50000000 2.00000000\r\n0.00000000 0.50000000\r\n-0.50000000 0.00000000\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "1.00000000 3.00000000 5.00000000\r\n3.00000000 5.00000000 7.00000000\r\n5.00000000 7.00000000 9.00000000\r\n0.000...
false
stdio
import sys def is_close(a, b): abs_tol = 1e-4 rel_tol = 1e-4 diff = abs(a - b) if diff <= abs_tol: return True max_val = max(abs(a), abs(b)) return diff <= rel_tol * max_val def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.read().spl...
true
526/B
526
B
Python 3
TESTS
2
109
307,200
97854958
n=int(input()) a=list(map(int,input().split())) if n==1: print(0) else: dp=[a[0],a[1]] m=(2**(n+1))-2 for j in range(2,m): dp.append(a[j]+dp[(j//2)-1]) c=0 k=2**n+1 m=0 for j in range(1,k,2): m=max(dp[-j],dp[-j-1],m) mi=min(dp[-j],dp[-j-1]) c=c+mi k-=1...
38
46
0
147599018
a = [] n = 0 ans = 0 def DFS(x, h): global a, n, ans if h < n: DFS(2*x+1, h+1) DFS(2*x+2, h+1) a[2*x] += max(a[2*(2*x+1)],a[2*(2*x+1)+1]) a[2*x+1] += max(a[2*(2*x+2)],a[2*(2*x+2)+1]) ans += abs(a[2*x]-a[x*2+1]) n = int(input()) s = input() s = s.split() for i in s: a.app...
ZeptoLab Code Rush 2015
CF
2,015
1
256
Om Nom and Dark Park
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him. The park consists of 2n + 1 - 1 squares connected by roads so that ...
The first line contains integer n (1 ≤ n ≤ 10) — the number of roads on the path from the entrance to any exit. The next line contains 2n + 1 - 2 numbers a2, a3, ... a2n + 1 - 1 — the initial numbers of street lights on each road of the park. Here ai is the number of street lights on the road between squares i and $$\...
Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe.
null
Picture for the sample test. Green color denotes the additional street lights.
[{"input": "2\n1 2 3 4 5 6", "output": "5"}]
1,400
["dfs and similar", "greedy", "implementation"]
38
[{"input": "2\r\n1 2 3 4 5 6\r\n", "output": "5\r\n"}, {"input": "2\r\n1 2 3 3 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n39 52\r\n", "output": "13\r\n"}, {"input": "2\r\n59 96 34 48 8 72\r\n", "output": "139\r\n"}, {"input": "3\r\n87 37 91 29 58 45 51 74 70 71 47 38 91 89\r\n", "output": "210\r\n"}, {"input": "5\r\...
false
stdio
null
true
961/E
961
E
PyPy 3
TESTS
4
93
0
109471890
n = int(input()) a = list(map(int, input().split())) cnt = 0 tmp = 0 L = [0]*(n+1) if a[0] <= n: L[a[0]] = 1 tmp = 1 for i in range(1, n): tmp -= L[i] cnt += tmp if a[i] <= n: L[a[i]] += 1 tmp += 1 print(cnt)
30
732
24,268,800
58653185
from sys import stdin from sys import setrecursionlimit as SRL; SRL(10**7) rd = stdin.readline rrd = lambda: map(int, rd().strip().split()) n = int(input()) a = list(rrd()) bit = [0]*(n+100) def ins(x): while x<=n: bit[x] += 1 x += x&(-x) def get(l): tot = 0 while l: tot += bit[l...
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
2
256
Tufurama
One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the ...
The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of seasons. The second line contains n integers separated by space a1, a2, ..., an (1 ≤ ai ≤ 109) — number of episodes in each season.
Print one integer — the number of pairs x and y (x < y) such that there exist both season x episode y and season y episode x.
null
Possible pairs in the second example: 1. x = 1, y = 2 (season 1 episode 2 $$\text{The formula used to produce the text is not provided in the image.}$$ season 2 episode 1); 2. x = 2, y = 3 (season 2 episode 3 $$\text{The formula used to produce the text is not provided in the image.}$$ season 3 episode 2); 3. x = 1, y...
[{"input": "5\n1 2 3 4 5", "output": "0"}, {"input": "3\n8 12 7", "output": "3"}, {"input": "3\n3 2 1", "output": "2"}]
1,900
["data structures"]
30
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n"}, {"input": "3\r\n8 12 7\r\n", "output": "3\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "5\r\n2 3 4 5 6\r\n", "output": "4\r\n"}, {"input": "8\r\n7 2 6 6 5 1 4 9\r\n", "output": "9\r\n"}, {"input": "10\r\n1000000000 1000000000 1000000000 1000000000...
false
stdio
null
true
959/D
959
D
PyPy 3
TESTS
5
249
32,665,600
123057752
m=2*10**5 prime=[0 for i in range(m)] n=int(input()) arr=list(map(int,input().split())) s=set(arr) i=0 for i in range(n): jump =arr[i] if prime[jump] ==1: for k in range(jump,m): if prime[k] ==0: arr[i] = k for l in range(k,m,k): prime[l] =...
55
951
52,633,600
208257020
# https://codeforces.com/contest/959 import sys input = lambda: sys.stdin.readline().rstrip() # faster! class PrimesUtil: def __init__(self, mx): assert 1 <= mx self.mx = mx self.prime_numbers = [] self.prime = [False] * 2 + [True] * (mx - 1) self.factor = [0] * (mx + 1)...
Codeforces Round 473 (Div. 2)
CF
2,018
3
256
Mahmoud and Ehab and another array construction task
Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same length such that: - b is lexicographically greater than or equal to a. - bi ≥ 2. - b is pairwise coprime: for every 1 ≤ i < j ≤ n, bi and bj are coprime, i. e. GCD(bi, bj) = 1, where GCD(w, z) is the greatest common divi...
The first line contains an integer n (1 ≤ n ≤ 105), the number of elements in a and b. The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 105), the elements of a.
Output n space-separated integers, the i-th of them representing bi.
null
Note that in the second sample, the array is already pairwise coprime so we printed it.
[{"input": "5\n2 3 5 4 13", "output": "2 3 5 7 11"}, {"input": "3\n10 3 7", "output": "10 3 7"}]
1,900
["constructive algorithms", "greedy", "math", "number theory"]
55
[{"input": "5\r\n2 3 5 4 13\r\n", "output": "2 3 5 7 11 "}, {"input": "3\r\n10 3 7\r\n", "output": "10 3 7 "}, {"input": "5\r\n7 10 2 5 5\r\n", "output": "7 10 3 11 13 "}, {"input": "7\r\n20 9 7 6 7 9 15\r\n", "output": "20 9 7 11 13 17 19 "}, {"input": "10\r\n5 3 2 2 3 3 3 4 2 5\r\n", "output": "5 3 2 7 11 13 17 19 23...
false
stdio
null
true
103/A
103
A
Python 3
TESTS
3
92
0
186348050
n = int(input()) x = [int(i) for i in input().split()] c = 0 for i in range(n): c += x[i] if x[i] != 1: c += i print(c)
25
92
0
150953602
n=int(input()) c=0 a=[int(x) for x in input().split()] for i in range(n-1,-1,-1): if c==0: c+=a[i] prev=a[i] else: x=a[i]-1+prev prev=x c+=x print(c)
Codeforces Beta Round 80 (Div. 1 Only)
CF
2,011
2
256
Testing Pants for Sadness
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ...
The first line contains a positive integer n (1 ≤ n ≤ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 ≤ ai ≤ 109), the number of answer variants to question i.
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the thir...
[{"input": "2\n1 1", "output": "2"}, {"input": "2\n2 2", "output": "5"}, {"input": "1\n10", "output": "10"}]
1,100
["greedy", "implementation", "math"]
25
[{"input": "2\r\n1 1\r\n", "output": "2"}, {"input": "2\r\n2 2\r\n", "output": "5"}, {"input": "1\r\n10\r\n", "output": "10"}, {"input": "3\r\n2 4 1\r\n", "output": "10"}, {"input": "4\r\n5 5 3 1\r\n", "output": "22"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "2999999999"}, {"input": "10\r\n5 7 8 1 10 3 6 ...
false
stdio
null
true
327/C
327
C
PyPy 3-64
TESTS
4
124
0
175012679
import sys n = input(); m = 1000000007 ans = 0; r = pow(2,len(n),m); c = len(n); d = int(sys.stdin.readline()); u = pow(r,d,m) for x in range(c) : if not int(n[x])%5 : ans = (ans + (1-(u)) // (1-r) * pow(2,x)) print(ans%m)
33
124
102,400
219438060
t, k = input(), int(input()) s, n, d = 0, 1, 1000000007 for i in t: if i in '05': s += n n = (n << 1) % d p = (pow(n, k, d) - 1) * pow(n - 1, d - 2, d) print(((p % d) * (s % d)) % d)
Codeforces Round 191 (Div. 2)
CF
2,013
1
256
Magic Five
There is a long plate s containing n digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting number may contain leading zeros. Now Iahub wants to count the number of ways...
In the first line you're given a string a (1 ≤ |a| ≤ 105), containing digits only. In the second line you're given an integer k (1 ≤ k ≤ 109). The plate s is formed by concatenating k copies of a together. That is n = |a|·k.
Print a single integer — the required number of ways modulo 1000000007 (109 + 7).
null
In the first case, there are four possible ways to make a number that is divisible by 5: 5, 15, 25 and 125. In the second case, remember to concatenate the copies of a. The actual plate is 1399013990. In the third case, except deleting all digits, any choice will do. Therefore there are 26 - 1 = 63 possible ways to d...
[{"input": "1256\n1", "output": "4"}, {"input": "13990\n2", "output": "528"}, {"input": "555\n2", "output": "63"}]
1,700
["combinatorics", "math"]
33
[{"input": "1256\r\n1\r\n", "output": "4\r\n"}, {"input": "13990\r\n2\r\n", "output": "528\r\n"}, {"input": "555\r\n2\r\n", "output": "63\r\n"}, {"input": "14\r\n178\r\n", "output": "0\r\n"}, {"input": "277557766562106078327886194146355351781887756238383139670139581436190170050799912854698535037185625049275351767138797...
false
stdio
null
true
621/C
621
C
PyPy 3
TESTS
3
62
0
138280238
def countDivisibles(A, B, M): if (A % M == 0): return ((B // M) - (A // M)) + 1 return ((B // M) - (A // M)) n,p = map(int,input().split()) A = [] B = [] tot = 1 for i in range(n): l,r = map(int,input().split()) x = countDivisibles(l,r,p) B.append(x) A.append(r-l+1) tot*=(r-l+1) re...
94
171
11,059,200
174827688
import collections import heapq import sys import math import itertools import bisect from io import BytesIO, IOBase import os ###################################################################################### #--------------------------------------funs here-------------------------------------# ###################...
Codeforces Round 341 (Div. 2)
CF
2,016
2
256
Wet Shark and Flowers
There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too. Each shark will grow some number of flowers si. For i-th shark value si is random integer equiprobably chosen in range from...
The first line of the input contains two space-separated integers n and p (3 ≤ n ≤ 100 000, 2 ≤ p ≤ 109) — the number of sharks and Wet Shark's favourite prime number. It is guaranteed that p is prime. The i-th of the following n lines contains information about i-th shark — two space-separated integers li and ri (1 ≤...
Print a single real number — the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correc...
null
A prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime. Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of ...
[{"input": "3 2\n1 2\n420 421\n420420 420421", "output": "4500.0"}, {"input": "3 5\n1 4\n2 3\n11 14", "output": "0.0"}]
1,700
["combinatorics", "math", "number theory", "probabilities"]
94
[{"input": "3 2\r\n1 2\r\n420 421\r\n420420 420421\r\n", "output": "4500.0\r\n"}, {"input": "3 5\r\n1 4\r\n2 3\r\n11 14\r\n", "output": "0.0\r\n"}, {"input": "3 3\r\n3 3\r\n2 4\r\n1 1\r\n", "output": "4666.666666666667\r\n"}, {"input": "5 5\r\n5 204\r\n420 469\r\n417 480\r\n442 443\r\n44 46\r\n", "output": "3451.25\r\n...
false
stdio
import sys def read_number(path): with open(path, 'r') as f: lines = [line.strip() for line in f.readlines() if line.strip()] if len(lines) != 1: return None try: return float(lines[0]) except ValueError: return None def main(): input_path = ...
true
28/A
28
A
Python 3
TESTS
6
92
0
12998854
def main(): n, m = map(int, input().split()) if m * 2 < n: print("NO") return tmp = list(tuple(map(int, input().split())) for _ in range(n)) tmp += tmp[:2] nails = [abs(a - c) + abs(b - d) for (a, b), (c, d) in zip(tmp, tmp[2:])] segments = list(map(int, input().split())) ise...
51
216
307,200
68238752
n,m = map(int,input().split()) s = [] for i in range(n): a = map(int,input().split()) a = list(a) s.append(a) s_chet = [] for i in range(1,n-1,2): #Проход по четным гвоздям q = abs((s[i][0]-s[i-1][0])+(s[i][1]-s[i-1][1])) + abs((s[i][0]-s[i+1][0])+(s[i][1]-s[i+1][1])) s_chet.append((...
Codeforces Beta Round 28 (Codeforces format)
CF
2,010
2
256
Bender Problem
Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate ...
The first line contains two positive integers n and m (4 ≤ n ≤ 500, 2 ≤ m ≤ 500, n is even) — the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The ...
If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers — i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod. If there are multiple solutions, print any of them.
null
null
[{"input": "4 2\n0 0\n0 2\n2 2\n2 0\n4 4", "output": "YES\n1 -1 2 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n3 2 3", "output": "YES\n1 -1 2 -1 3 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n2 2 3", "output": "NO"}]
1,600
["implementation"]
51
[{"input": "4 2\r\n0 0\r\n0 2\r\n2 2\r\n2 0\r\n4 4\r\n", "output": "YES\r\n1 -1 2 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n3 2 3\r\n", "output": "YES\r\n1 -1 2 -1 3 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n2 2 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n, m = map(int, f.readline().split()) nails = [tuple(map(int, f.readline().split())) for _ in range(n)] rods = list(map(int, f.readline().split())...
true
313/D
313
D
PyPy 3-64
TESTS
3
154
3,788,800
216826114
from collections import deque import math mod = 10**9 + 7 fact = [1] * (2*10**5+10) inf = 10**18 def gcd(a, b): while a > 0 and b > 0: if a >= b: a %= b else: b %= a return max(a, b) def nok(a, b): return a * b // gcd(a, b) def is_prime(a): for i in range(2, i...
77
1,932
10,240,000
232738001
INF = 10**18 n, m, k = map(int, input().split()) cost = [[INF]*(n+1) for i in range(n+1)] dp = [[INF]*(n+1) for i in range(n+1)] for i in range(m): l, r, c = map(int, input().split()) for j in range(l, r+1): cost[j][r] = min(cost[j][r], c) dp[0][0] = 0 for i in range(n): for j in range(k+1): ...
Codeforces Round 186 (Div. 2)
CF
2,013
3
256
Ilya and Roads
Everything is great about Ilya's city, except the roads. The thing is, the only ZooVille road is represented as n holes in a row. We will consider the holes numbered from 1 to n, from left to right. Ilya is really keep on helping his city. So, he wants to fix at least k holes (perharps he can fix more) on a single Zoo...
The first line contains three integers n, m, k (1 ≤ n ≤ 300, 1 ≤ m ≤ 105, 1 ≤ k ≤ n). The next m lines contain the companies' description. The i-th line contains three integers li, ri, ci (1 ≤ li ≤ ri ≤ n, 1 ≤ ci ≤ 109).
Print a single integer — the minimum money Ilya needs to fix at least k holes. If it is impossible to fix at least k holes, print -1. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
null
null
[{"input": "10 4 6\n7 9 11\n6 9 13\n7 7 7\n3 5 6", "output": "17"}, {"input": "10 7 1\n3 4 15\n8 9 8\n5 6 8\n9 10 6\n1 4 2\n1 4 10\n8 10 13", "output": "2"}, {"input": "10 1 9\n5 10 14", "output": "-1"}]
2,100
["dp"]
77
[{"input": "10 4 6\r\n7 9 11\r\n6 9 13\r\n7 7 7\r\n3 5 6\r\n", "output": "17\r\n"}, {"input": "10 7 1\r\n3 4 15\r\n8 9 8\r\n5 6 8\r\n9 10 6\r\n1 4 2\r\n1 4 10\r\n8 10 13\r\n", "output": "2\r\n"}, {"input": "10 1 9\r\n5 10 14\r\n", "output": "-1\r\n"}, {"input": "10 6 9\r\n6 8 7\r\n2 8 11\r\n2 6 10\r\n8 10 9\r\n2 5 8\r\...
false
stdio
null
true
523/A
523
A
Python 3
TESTS
0
78
0
92510844
w,h=map(int,input().split()) q,r=[],[[]for i in range(w)] for i in range(h): q.append(list(input())) for i in range(w): for j in range(h): r[i].append(q[j][i]*2) for i in r: print(*i) print(*i)
24
61
0
13001492
def main(): w, h = map(int, input().split()) h *= 2 l = [None] * h for i in range(0, h, 2): l[i] = l[i + 1] = input() l = [''.join(_) for _ in zip(*l)] for s in l: print(s) print(s) if __name__ == '__main__': main()
VK Cup 2015 - Qualification Round 2
CF
2,015
2
256
Rotate, Flip and Zoom
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice ...
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is mono...
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
null
null
[{"input": "3 2\n.*.\n.*.", "output": "....\n....\n****\n****\n....\n...."}, {"input": "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*", "outp...
1,200
["*special", "implementation"]
24
[{"input": "3 2\r\n.*.\r\n.*.\r\n", "output": "....\r\n....\r\n****\r\n****\r\n....\r\n....\r\n"}, {"input": "9 20\r\n**.......\r\n****.....\r\n******...\r\n*******..\r\n..******.\r\n....****.\r\n......***\r\n*.....***\r\n*********\r\n*********\r\n*********\r\n*********\r\n....**...\r\n...****..\r\n..******.\r\n.******...
false
stdio
null
true
961/E
961
E
PyPy 3
TESTS
4
140
102,400
93962819
import sys from collections import defaultdict class BIT_RSQ(object): __slots__ = ['nodes', 'size'] def __init__(self, size: int): self.nodes = [0]*(size+1) self.size = size+1 def add(self, index: int, value: int): while index < self.size: self.nodes[index] += value ...
30
1,465
77,004,800
36972134
import sys class RangeBit: def __init__(self, n): sz = 1 while n >= sz: sz *= 2 self.size = sz self.dataAdd = [0 for _ in range(sz)] self.dataMul = [0 for _ in range(sz)] def sum(self, i): assert i > 0 add, mul, start = 0, 0, i while ...
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
2
256
Tufurama
One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the ...
The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of seasons. The second line contains n integers separated by space a1, a2, ..., an (1 ≤ ai ≤ 109) — number of episodes in each season.
Print one integer — the number of pairs x and y (x < y) such that there exist both season x episode y and season y episode x.
null
Possible pairs in the second example: 1. x = 1, y = 2 (season 1 episode 2 $$\text{The formula used to produce the text is not provided in the image.}$$ season 2 episode 1); 2. x = 2, y = 3 (season 2 episode 3 $$\text{The formula used to produce the text is not provided in the image.}$$ season 3 episode 2); 3. x = 1, y...
[{"input": "5\n1 2 3 4 5", "output": "0"}, {"input": "3\n8 12 7", "output": "3"}, {"input": "3\n3 2 1", "output": "2"}]
1,900
["data structures"]
30
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n"}, {"input": "3\r\n8 12 7\r\n", "output": "3\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "5\r\n2 3 4 5 6\r\n", "output": "4\r\n"}, {"input": "8\r\n7 2 6 6 5 1 4 9\r\n", "output": "9\r\n"}, {"input": "10\r\n1000000000 1000000000 1000000000 1000000000...
false
stdio
null
true
961/E
961
E
PyPy 3
TESTS
4
108
20,275,200
128478540
from collections import defaultdict import sys input = sys.stdin.readline def make_tree(n): tree = [0] * (n + 1) return tree def get_sum(i): s = 0 while i > 0: s += tree[i] i -= i & -i return s def add(i, x): while i <= n: tree[i] += x i += i & -i n = int(inpu...
30
498
44,236,800
128480912
from collections import defaultdict import sys input = sys.stdin.readline def make_tree(n): tree = [0] * (n + 1) return tree def get_sum(i): s = 0 while i > 0: s += tree[i] i -= i & -i return s def get_sum_segment(s, t): if s > t: return 0 ans = get_sum(t) - get_su...
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
2
256
Tufurama
One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the ...
The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of seasons. The second line contains n integers separated by space a1, a2, ..., an (1 ≤ ai ≤ 109) — number of episodes in each season.
Print one integer — the number of pairs x and y (x < y) such that there exist both season x episode y and season y episode x.
null
Possible pairs in the second example: 1. x = 1, y = 2 (season 1 episode 2 $$\text{The formula used to produce the text is not provided in the image.}$$ season 2 episode 1); 2. x = 2, y = 3 (season 2 episode 3 $$\text{The formula used to produce the text is not provided in the image.}$$ season 3 episode 2); 3. x = 1, y...
[{"input": "5\n1 2 3 4 5", "output": "0"}, {"input": "3\n8 12 7", "output": "3"}, {"input": "3\n3 2 1", "output": "2"}]
1,900
["data structures"]
30
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n"}, {"input": "3\r\n8 12 7\r\n", "output": "3\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "5\r\n2 3 4 5 6\r\n", "output": "4\r\n"}, {"input": "8\r\n7 2 6 6 5 1 4 9\r\n", "output": "9\r\n"}, {"input": "10\r\n1000000000 1000000000 1000000000 1000000000...
false
stdio
null
true
961/E
961
E
PyPy 3
TESTS
4
93
20,172,800
123026758
def queries(indx1,indx2): count =0 while indx1 <=indx2: if indx1 %2==1: count +=sgn_tree[indx1] indx1 +=1 if indx2 %2==0: count +=sgn_tree[indx2] indx2 -=1 indx1 =indx1 >>1 indx2 =indx2 >>1 return count def update(indx): sg...
30
655
22,528,000
100875670
from bisect import bisect_left, bisect_right n = int(input()) a = list(map(int, input().split())) ans = 0 #ans = slow_test() class fenwick(): """ This Tree Data Structure speeds up caliculating summations of partial sum and also updating subsets of sequences. Both queries finish in logarithmic times. ...
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
2
256
Tufurama
One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the ...
The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of seasons. The second line contains n integers separated by space a1, a2, ..., an (1 ≤ ai ≤ 109) — number of episodes in each season.
Print one integer — the number of pairs x and y (x < y) such that there exist both season x episode y and season y episode x.
null
Possible pairs in the second example: 1. x = 1, y = 2 (season 1 episode 2 $$\text{The formula used to produce the text is not provided in the image.}$$ season 2 episode 1); 2. x = 2, y = 3 (season 2 episode 3 $$\text{The formula used to produce the text is not provided in the image.}$$ season 3 episode 2); 3. x = 1, y...
[{"input": "5\n1 2 3 4 5", "output": "0"}, {"input": "3\n8 12 7", "output": "3"}, {"input": "3\n3 2 1", "output": "2"}]
1,900
["data structures"]
30
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n"}, {"input": "3\r\n8 12 7\r\n", "output": "3\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "5\r\n2 3 4 5 6\r\n", "output": "4\r\n"}, {"input": "8\r\n7 2 6 6 5 1 4 9\r\n", "output": "9\r\n"}, {"input": "10\r\n1000000000 1000000000 1000000000 1000000000...
false
stdio
null
true
963/B
963
B
Python 3
TESTS
6
108
7,577,600
37630613
from collections import defaultdict class DesOfTree: def main(self): n = int(input()) tree = [int(x) for x in input().split()] tree.insert(0,0) self.graph = defaultdict(list) for i in range(1, n+1): dot.add_edge(i, tree[i]) for i in range(1, n+1): ...
95
826
48,742,400
101823725
from collections import defaultdict,deque import sys import bisect import math input=sys.stdin.readline mod=1000000007 def bfs(root,count): q=deque([root]) vis.add(root) while q: vertex=q.popleft() for child in graph[vertex]: if ans[child]==0: ans[child]=count+1 ...
Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 1)
CF
2,018
1
256
Destruction of a Tree
You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted. Destroy all vertices in the given tree or...
The first line contains integer n (1 ≤ n ≤ 2·105) — number of vertices in a tree. The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ n). If pi ≠ 0 there is an edge between vertices i and pi. It is guaranteed that the given graph is a tree.
If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes). If it's possible to destroy all vertices, in the next n lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any.
null
In the first example at first you have to remove the vertex with index 1 (after that, the edges (1, 2) and (1, 4) are removed), then the vertex with index 2 (and edges (2, 3) and (2, 5) are removed). After that there are no edges in the tree, so you can remove remaining vertices in any order.
[{"input": "5\n0 1 2 1 2", "output": "YES\n1\n2\n3\n5\n4"}, {"input": "4\n0 1 2 3", "output": "NO"}]
2,000
["constructive algorithms", "dfs and similar", "dp", "greedy", "trees"]
95
[{"input": "5\r\n0 1 2 1 2\r\n", "output": "YES\r\n1\r\n2\r\n3\r\n5\r\n4\r\n"}, {"input": "4\r\n0 1 2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n1\r\n"}, {"input": "8\r\n3 1 4 0 4 2 4 5\r\n", "output": "NO\r\n"}, {"input": "100\r\n81 96 65 28 4 40 5 49 5 89 48 70 94 70 17 58 58 1 61 19 45 33...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n = int(f.readline()) p = list(map(int, f.readline().split())) # Read reference output with open(output_path) as f_ref: ...
true
965/E
965
E
PyPy 3
TESTS
4
93
21,401,600
37889385
import sys line=lambda:sys.stdin.buffer.readline() n=int(line()) t=[None]*26 def dfs(p,d,x): ans=0;m=None;j=-1 if len(p)==28: ans+=d if p[26]==x+1: return ans x-=p[27] for i in range(26): if p[i]: k=dfs(p[i],d+1,x)-(p[i][26]-x) if m==None or k>m: j,m=i,k for i in range(26): if p[i]: ans+=dfs(p[i...
24
156
22,937,600
177672519
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def trie(): G, cnt = [[-1] * 26], [0] return G, cnt def insert(s): j = 0 for i in s: if not G[j][i - 97] ^ -1: G[j][i - 97] = len(cnt) G.append([-1] * 26) cnt.append(0) ...
Codeforces Round 476 (Div. 2) [Thanks, Telegram!]
CF
2,018
1
256
Short Code
Arkady's code contains $$$n$$$ variables. Each variable has a unique name consisting of lowercase English letters only. One day Arkady decided to shorten his code. He wants to replace each variable name with its non-empty prefix so that these new names are still unique (however, a new name of some variable can coincid...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of variables. The next $$$n$$$ lines contain variable names, one per line. Each name is non-empty and contains only lowercase English letters. The total length of these strings is not greater than $$$10^5$$$. The variable names are ...
Print a single integer — the minimum possible total length of new variable names.
null
In the first example one of the best options is to shorten the names in the given order as "cod", "co", "c". In the second example we can shorten the last name to "aac" and the first name to "a" without changing the other names.
[{"input": "3\ncodeforces\ncodehorses\ncode", "output": "6"}, {"input": "5\nabba\nabb\nab\naa\naacada", "output": "11"}, {"input": "3\ntelegram\ndigital\nresistance", "output": "3"}]
2,200
["data structures", "dp", "greedy", "strings", "trees"]
24
[{"input": "3\r\ncodeforces\r\ncodehorses\r\ncode\r\n", "output": "6\r\n"}, {"input": "5\r\nabba\r\nabb\r\nab\r\naa\r\naacada\r\n", "output": "11\r\n"}, {"input": "3\r\ntelegram\r\ndigital\r\nresistance\r\n", "output": "3\r\n"}, {"input": "1\r\na\r\n", "output": "1\r\n"}, {"input": "10\r\naaaba\r\nbabba\r\nbbba\r\naaab...
false
stdio
null
true
767/E
767
E
PyPy 3
TESTS
0
77
0
121567378
from heapq import * DEBUG = 0 if DEBUG==1: data = open('sample3.in', 'r') def readline(): if DEBUG == 1: return data.readline().strip('\n') else: try: return input() except EOFError: return '' def readi(): return [int(t) for t in readline().split()] n...
53
421
35,328,000
164359819
from heapq import * import sys input = sys.stdin.buffer.readline def sol(n, m, money_per_day, dissatisfaction): # insatisfacción que resulta de los pagos que se realicen cada día payments = [[0, 0] for _ in range(n)] # heap donde se insertarán los pagos que se realizaron sin necesitar cambio h = []...
Codeforces Round 398 (Div. 2)
CF
2,017
1
256
Change-free
Student Arseny likes to plan his life for n days ahead. He visits a canteen every day and he has already decided what he will order in each of the following n days. Prices in the canteen do not change and that means Arseny will spend ci rubles during the i-th day. There are 1-ruble coins and 100-ruble notes in circula...
The first line contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 109) — the amount of days Arseny planned his actions for and the amount of coins he currently has. The second line contains a sequence of integers c1, c2, ..., cn (1 ≤ ci ≤ 105) — the amounts of money in rubles which Arseny is going to spend for each o...
In the first line print one integer — minimum possible total dissatisfaction of the cashier. Then print n lines, the i-th of then should contain two numbers — the amount of notes and the amount of coins which Arseny should use to pay in the canteen on the i-th day. Of course, the total amount of money Arseny gives to...
null
null
[{"input": "5 42\n117 71 150 243 200\n1 1 1 1 1", "output": "79\n1 17\n1 0\n2 0\n2 43\n2 0"}, {"input": "3 0\n100 50 50\n1 3 2", "output": "150\n1 0\n1 0\n0 50"}, {"input": "5 42\n117 71 150 243 200\n5 4 3 2 1", "output": "230\n1 17\n1 0\n1 50\n3 0\n2 0"}]
2,400
["greedy"]
53
[{"input": "5 42\r\n117 71 150 243 200\r\n1 1 1 1 1\r\n", "output": "79\r\n1 17\r\n1 0\r\n2 0\r\n2 43\r\n2 0\r\n"}, {"input": "3 0\r\n100 50 50\r\n1 3 2\r\n", "output": "150\r\n1 0\r\n1 0\r\n0 50\r\n"}, {"input": "5 42\r\n117 71 150 243 200\r\n5 4 3 2 1\r\n", "output": "230\r\n1 17\r\n1 0\r\n1 50\r\n3 0\r\n2 0\r\n"}, {...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: input_lines = f.readlines() n, m = map(int, input_lines[0].split()) c = list(map(int, input_lines[1].split())) w = list(map(int, inpu...
true
963/B
963
B
PyPy 3
TESTS
6
77
20,172,800
126190123
import sys input = sys.stdin.readline n = int(input()) if n%2 == 0: print("NO") exit() parent = list(map(int,input().split())) print("YES") parity = [0]*n G = [[] for _ in range(n)] for i in range(n): parent[i] -= 1 if parent[i] != -1: G[parent[i]].append(i) parity[parent[i]] += 1 ...
95
701
45,670,400
126191783
import sys input = sys.stdin.readline n = int(input()) if n%2 == 0: print("NO") exit() parent = list(map(int,input().split())) print("YES") s = [0]*n G = [[] for _ in range(n)] root = -1 for i in range(n): parent[i] -= 1 if parent[i] != -1: G[parent[i]].append(i) else: root = i st...
Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 1)
CF
2,018
1
256
Destruction of a Tree
You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted. Destroy all vertices in the given tree or...
The first line contains integer n (1 ≤ n ≤ 2·105) — number of vertices in a tree. The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ n). If pi ≠ 0 there is an edge between vertices i and pi. It is guaranteed that the given graph is a tree.
If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes). If it's possible to destroy all vertices, in the next n lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any.
null
In the first example at first you have to remove the vertex with index 1 (after that, the edges (1, 2) and (1, 4) are removed), then the vertex with index 2 (and edges (2, 3) and (2, 5) are removed). After that there are no edges in the tree, so you can remove remaining vertices in any order.
[{"input": "5\n0 1 2 1 2", "output": "YES\n1\n2\n3\n5\n4"}, {"input": "4\n0 1 2 3", "output": "NO"}]
2,000
["constructive algorithms", "dfs and similar", "dp", "greedy", "trees"]
95
[{"input": "5\r\n0 1 2 1 2\r\n", "output": "YES\r\n1\r\n2\r\n3\r\n5\r\n4\r\n"}, {"input": "4\r\n0 1 2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n1\r\n"}, {"input": "8\r\n3 1 4 0 4 2 4 5\r\n", "output": "NO\r\n"}, {"input": "100\r\n81 96 65 28 4 40 5 49 5 89 48 70 94 70 17 58 58 1 61 19 45 33...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n = int(f.readline()) p = list(map(int, f.readline().split())) # Read reference output with open(output_path) as f_ref: ...
true
103/A
103
A
Python 3
TESTS
3
92
0
12771556
N = int(input()) A = list(int(i) for i in input().split()) total = 0 for i in range(N): clicksToReach = i if(A[i]>1): total+=A[i]-1+clicksToReach total+=N print(total)
25
92
0
157957695
import sys input = sys.stdin.readline n = int(input()) w = list(map(int, input().split())) s, c = 1, 0 for i in range(n): c += s*(w[i]-1) s += 1 c += n print(c)
Codeforces Beta Round 80 (Div. 1 Only)
CF
2,011
2
256
Testing Pants for Sadness
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ...
The first line contains a positive integer n (1 ≤ n ≤ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 ≤ ai ≤ 109), the number of answer variants to question i.
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the thir...
[{"input": "2\n1 1", "output": "2"}, {"input": "2\n2 2", "output": "5"}, {"input": "1\n10", "output": "10"}]
1,100
["greedy", "implementation", "math"]
25
[{"input": "2\r\n1 1\r\n", "output": "2"}, {"input": "2\r\n2 2\r\n", "output": "5"}, {"input": "1\r\n10\r\n", "output": "10"}, {"input": "3\r\n2 4 1\r\n", "output": "10"}, {"input": "4\r\n5 5 3 1\r\n", "output": "22"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "2999999999"}, {"input": "10\r\n5 7 8 1 10 3 6 ...
false
stdio
null
true
103/A
103
A
PyPy 3-64
TESTS
3
92
0
218699002
n=int(input()) l=list(map(int,input().split())) ans=0 for i in range(len(l)): if l[i]==1: ans=ans+1 else: ans=ans+l[i]+i print(ans)
25
92
0
158977181
n = int(input()) lis = list(map(int,input().split())) ans = 0 for i in range(n): if i == 0: ans += lis[i] else: ans += (i-0)*(lis[i]-1) + lis[i] print(ans)
Codeforces Beta Round 80 (Div. 1 Only)
CF
2,011
2
256
Testing Pants for Sadness
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ...
The first line contains a positive integer n (1 ≤ n ≤ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 ≤ ai ≤ 109), the number of answer variants to question i.
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the thir...
[{"input": "2\n1 1", "output": "2"}, {"input": "2\n2 2", "output": "5"}, {"input": "1\n10", "output": "10"}]
1,100
["greedy", "implementation", "math"]
25
[{"input": "2\r\n1 1\r\n", "output": "2"}, {"input": "2\r\n2 2\r\n", "output": "5"}, {"input": "1\r\n10\r\n", "output": "10"}, {"input": "3\r\n2 4 1\r\n", "output": "10"}, {"input": "4\r\n5 5 3 1\r\n", "output": "22"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "2999999999"}, {"input": "10\r\n5 7 8 1 10 3 6 ...
false
stdio
null
true
963/B
963
B
PyPy 3
TESTS
6
109
151,449,600
126190927
import sys sys.setrecursionlimit(200005) input = sys.stdin.readline n = int(input()) if n%2 == 0: print("NO") exit() parent = list(map(int,input().split())) print("YES") parity = [0]*n G = [[] for _ in range(n)] for i in range(n): parent[i] -= 1 if parent[i] != -1: G[parent[i]].append(i) ...
95
826
48,742,400
101823725
from collections import defaultdict,deque import sys import bisect import math input=sys.stdin.readline mod=1000000007 def bfs(root,count): q=deque([root]) vis.add(root) while q: vertex=q.popleft() for child in graph[vertex]: if ans[child]==0: ans[child]=count+1 ...
Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 1)
CF
2,018
1
256
Destruction of a Tree
You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted. Destroy all vertices in the given tree or...
The first line contains integer n (1 ≤ n ≤ 2·105) — number of vertices in a tree. The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ n). If pi ≠ 0 there is an edge between vertices i and pi. It is guaranteed that the given graph is a tree.
If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes). If it's possible to destroy all vertices, in the next n lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any.
null
In the first example at first you have to remove the vertex with index 1 (after that, the edges (1, 2) and (1, 4) are removed), then the vertex with index 2 (and edges (2, 3) and (2, 5) are removed). After that there are no edges in the tree, so you can remove remaining vertices in any order.
[{"input": "5\n0 1 2 1 2", "output": "YES\n1\n2\n3\n5\n4"}, {"input": "4\n0 1 2 3", "output": "NO"}]
2,000
["constructive algorithms", "dfs and similar", "dp", "greedy", "trees"]
95
[{"input": "5\r\n0 1 2 1 2\r\n", "output": "YES\r\n1\r\n2\r\n3\r\n5\r\n4\r\n"}, {"input": "4\r\n0 1 2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n1\r\n"}, {"input": "8\r\n3 1 4 0 4 2 4 5\r\n", "output": "NO\r\n"}, {"input": "100\r\n81 96 65 28 4 40 5 49 5 89 48 70 94 70 17 58 58 1 61 19 45 33...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n = int(f.readline()) p = list(map(int, f.readline().split())) # Read reference output with open(output_path) as f_ref: ...
true
103/A
103
A
Python 3
TESTS
4
156
6,656,000
86223128
n=int(input()) l=list(map(int,input().split())) i=0 x=0 for j in l: x=x+j+i if(j>1): i=i+1 print(x)
25
92
0
183690622
a=int(input());b=[int(x) for x in input().split()];c=b[0] for i in range(1,a): c+=b[i]+i*(b[i]-1) print(c)
Codeforces Beta Round 80 (Div. 1 Only)
CF
2,011
2
256
Testing Pants for Sadness
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ...
The first line contains a positive integer n (1 ≤ n ≤ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 ≤ ai ≤ 109), the number of answer variants to question i.
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the thir...
[{"input": "2\n1 1", "output": "2"}, {"input": "2\n2 2", "output": "5"}, {"input": "1\n10", "output": "10"}]
1,100
["greedy", "implementation", "math"]
25
[{"input": "2\r\n1 1\r\n", "output": "2"}, {"input": "2\r\n2 2\r\n", "output": "5"}, {"input": "1\r\n10\r\n", "output": "10"}, {"input": "3\r\n2 4 1\r\n", "output": "10"}, {"input": "4\r\n5 5 3 1\r\n", "output": "22"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "2999999999"}, {"input": "10\r\n5 7 8 1 10 3 6 ...
false
stdio
null
true
103/A
103
A
PyPy 3
TESTS
4
186
0
108099327
n = int(input()) c = list(map(int, input().split())) k = 1 for i in range(len(c)): k *= c[i] k += (n-1) print(k)
25
92
0
190986998
n = int(input()) l = [int(i) for i in input().split()] c = len(l) for index, i in enumerate(l): c += (i-1)*(index+1) print(c)
Codeforces Beta Round 80 (Div. 1 Only)
CF
2,011
2
256
Testing Pants for Sadness
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ...
The first line contains a positive integer n (1 ≤ n ≤ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 ≤ ai ≤ 109), the number of answer variants to question i.
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the thir...
[{"input": "2\n1 1", "output": "2"}, {"input": "2\n2 2", "output": "5"}, {"input": "1\n10", "output": "10"}]
1,100
["greedy", "implementation", "math"]
25
[{"input": "2\r\n1 1\r\n", "output": "2"}, {"input": "2\r\n2 2\r\n", "output": "5"}, {"input": "1\r\n10\r\n", "output": "10"}, {"input": "3\r\n2 4 1\r\n", "output": "10"}, {"input": "4\r\n5 5 3 1\r\n", "output": "22"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "2999999999"}, {"input": "10\r\n5 7 8 1 10 3 6 ...
false
stdio
null
true