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
641/B
641
B
PyPy 3-64
TESTS
5
233
4,608,000
162558608
from collections import defaultdict n, m, q = map(int, input().split()) l = [[0 for i in range(m)] for i in range(n)] nn = defaultdict(int) mm = defaultdict(int) lll = [] flag = 1 for i in range(q): k = list(map(int, input().split())) if flag and k[0] == 3: lll.reverse() flag = 0 lll.append(k) for k in lll: if len(k) == 2: if k[0] == 1: nn[k[1]] += 1 else: mm[k[1]] += 1 else: k[1] -= nn[k[1]] k[1] %= n k[2] -= mm[k[2]] k[2] %= m l[k[1]][k[2]] = k[3] for i in l: print(*i)
26
93
6,348,800
167459412
import sys input = sys.stdin.readline n, m, q = map(int, input().split()) d = [[0]*m for i in range(n)] s = [list(map(int, input().split())) for _ in range(q)] for w in reversed(s): if w[0] == 1: a = w[1] - 1 d[a] = [d[a][-1]] + d[a][:-1] elif w[0] == 2: a = w[1] - 1 x = d[n-1][a] for i in range(n-1, 0, -1): d[i][a] = d[i-1][a] d[0][a] = x else: a, b, c = w[1]-1, w[2]-1, w[3] d[a][b] = c for i in d: print(' '.join(map(str, i)))
VK Cup 2016 - Round 2
CF
2,016
2
256
Little Artem and Matrix
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it. That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right. Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix. Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
null
null
[{"input": "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "output": "8 2\n1 8"}, {"input": "3 3 2\n1 2\n3 2 2 5", "output": "0 0 0\n0 0 5\n0 0 0"}]
1,400
["implementation"]
26
[{"input": "2 2 6\r\n2 1\r\n2 2\r\n3 1 1 1\r\n3 2 2 2\r\n3 1 2 8\r\n3 2 1 8\r\n", "output": "8 2 \r\n1 8 \r\n"}, {"input": "3 3 2\r\n1 2\r\n3 2 2 5\r\n", "output": "0 0 0 \r\n0 0 5 \r\n0 0 0 \r\n"}, {"input": "5 5 1\r\n1 5\r\n", "output": "0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n"}, {"input": "1 1 3\r\n1 1\r\n2 1\r\n3 1 1 1000000000\r\n", "output": "1000000000 \r\n"}, {"input": "1 1 3\r\n1 1\r\n2 1\r\n3 1 1 -1000000000\r\n", "output": "-1000000000 \r\n"}, {"input": "2 2 6\r\n2 1\r\n2 2\r\n3 1 1 -1\r\n3 2 2 -1\r\n3 1 2 -1\r\n3 2 1 -1\r\n", "output": "-1 -1 \r\n-1 -1 \r\n"}, {"input": "1 4 5\r\n1 1\r\n3 1 1 1\r\n3 1 2 2\r\n3 1 3 3\r\n3 1 4 4\r\n", "output": "4 1 2 3 \r\n"}, {"input": "4 2 5\r\n2 1\r\n3 1 1 5\r\n3 2 1 6\r\n3 3 1 7\r\n3 4 1 9\r\n", "output": "9 0 \r\n5 0 \r\n6 0 \r\n7 0 \r\n"}, {"input": "3 10 2\r\n1 2\r\n3 2 7 5\r\n", "output": "0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 5 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n"}, {"input": "1 2 2\r\n1 1\r\n3 1 2 15\r\n", "output": "15 0 \r\n"}]
false
stdio
null
true
641/B
641
B
PyPy 3-64
TESTS
5
264
5,222,400
162557865
from collections import defaultdict n, m, q = map(int, input().split()) l = [[0 for i in range(m)] for i in range(n)] nn = defaultdict(int) mm = defaultdict(int) for i in range(q): k = list(map(int, input().split())) if len(k) == 2: if k[0] == 1: nn[k[1]] += 1 else: mm[k[1]] += 1 else: k[1] -= nn[k[1]] k[1] %= n k[2] -= mm[k[2]] k[2] %= m l[k[1]][k[2]] = k[3] for i in l: print(*i)
26
186
512,000
158702123
f=lambda: map(int,input().split()) n,m,q=f() p=[[0]*m for j in range(n)] for t in [list(f()) for k in range(q)][::-1]: j=t[1]-1 if t[0]==1: p[j].insert(0,p[j].pop()) elif t[0]==2: s=p[-1][j] for i in range(n-1,0,-1): p[i][j]=p[i-1][j] p[0][j]=s else: p[j][t[2]-1]=t[3] for d in p: print(*d)
VK Cup 2016 - Round 2
CF
2,016
2
256
Little Artem and Matrix
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it. That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right. Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix. Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
null
null
[{"input": "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "output": "8 2\n1 8"}, {"input": "3 3 2\n1 2\n3 2 2 5", "output": "0 0 0\n0 0 5\n0 0 0"}]
1,400
["implementation"]
26
[{"input": "2 2 6\r\n2 1\r\n2 2\r\n3 1 1 1\r\n3 2 2 2\r\n3 1 2 8\r\n3 2 1 8\r\n", "output": "8 2 \r\n1 8 \r\n"}, {"input": "3 3 2\r\n1 2\r\n3 2 2 5\r\n", "output": "0 0 0 \r\n0 0 5 \r\n0 0 0 \r\n"}, {"input": "5 5 1\r\n1 5\r\n", "output": "0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n"}, {"input": "1 1 3\r\n1 1\r\n2 1\r\n3 1 1 1000000000\r\n", "output": "1000000000 \r\n"}, {"input": "1 1 3\r\n1 1\r\n2 1\r\n3 1 1 -1000000000\r\n", "output": "-1000000000 \r\n"}, {"input": "2 2 6\r\n2 1\r\n2 2\r\n3 1 1 -1\r\n3 2 2 -1\r\n3 1 2 -1\r\n3 2 1 -1\r\n", "output": "-1 -1 \r\n-1 -1 \r\n"}, {"input": "1 4 5\r\n1 1\r\n3 1 1 1\r\n3 1 2 2\r\n3 1 3 3\r\n3 1 4 4\r\n", "output": "4 1 2 3 \r\n"}, {"input": "4 2 5\r\n2 1\r\n3 1 1 5\r\n3 2 1 6\r\n3 3 1 7\r\n3 4 1 9\r\n", "output": "9 0 \r\n5 0 \r\n6 0 \r\n7 0 \r\n"}, {"input": "3 10 2\r\n1 2\r\n3 2 7 5\r\n", "output": "0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 5 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n"}, {"input": "1 2 2\r\n1 1\r\n3 1 2 15\r\n", "output": "15 0 \r\n"}]
false
stdio
null
true
372/A
372
A
Python 3
TESTS
11
997
12,595,200
78554842
import bisect m=int(input()) l=[] while m>0: t=int(input()) l.append(t) m-=1 l.sort() #print(l) k=l[m-1]//2 c=bisect.bisect_right(l,k) n=len(l) if c>len(l)//2: c=len(l)//2 print(len(l)-c)
45
249
11,673,600
214252777
from sys import stdin def lmap(function, iterable): return list(map(function, iterable)) def line(): return stdin.readline().strip() def rd(converter): return converter(line()) def rl(converter, delimeter = None): return lmap(converter, line().split(delimeter)) def rls(num_lines, converter): return [rd(converter) for i in range(num_lines)] def rg(num_lines, converter, delimeter = None): return [rl(converter,delimeter) for i in range(num_lines)] MULTIPLE_CASES = 0 def main(): N = rd(int) S = rls(N,int) S.sort() i2 = N//2 ans = N for i1 in range(N): if S[i1] == -1: continue while i2 < N and S[i2] < S[i1]*2: i2 += 1 if i2 < N: ans -= 1 S[i2] = -1 print(ans) for i in range(rd(int) if MULTIPLE_CASES else 1): main()
Codeforces Round 219 (Div. 1)
CF
2,013
1
256
Counting Kangaroos is Fun
There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible.
The first line contains a single integer — n (1 ≤ n ≤ 5·105). Each of the next n lines contains an integer si — the size of the i-th kangaroo (1 ≤ si ≤ 105).
Output a single integer — the optimal number of visible kangaroos.
null
null
[{"input": "8\n2\n5\n7\n6\n9\n8\n4\n2", "output": "5"}, {"input": "8\n9\n1\n6\n2\n6\n5\n8\n3", "output": "5"}]
1,600
["binary search", "greedy", "sortings", "two pointers"]
45
[{"input": "8\r\n2\r\n5\r\n7\r\n6\r\n9\r\n8\r\n4\r\n2\r\n", "output": "5\r\n"}, {"input": "8\r\n9\r\n1\r\n6\r\n2\r\n6\r\n5\r\n8\r\n3\r\n", "output": "5\r\n"}, {"input": "12\r\n3\r\n99\r\n24\r\n46\r\n75\r\n63\r\n57\r\n55\r\n10\r\n62\r\n34\r\n52\r\n", "output": "7\r\n"}, {"input": "12\r\n55\r\n75\r\n1\r\n98\r\n63\r\n64\r\n9\r\n39\r\n82\r\n18\r\n47\r\n9\r\n", "output": "6\r\n"}, {"input": "100\r\n678\r\n771\r\n96\r\n282\r\n135\r\n749\r\n168\r\n668\r\n17\r\n658\r\n979\r\n446\r\n998\r\n331\r\n606\r\n756\r\n37\r\n515\r\n538\r\n205\r\n647\r\n547\r\n904\r\n842\r\n647\r\n286\r\n774\r\n414\r\n267\r\n791\r\n595\r\n465\r\n8\r\n327\r\n855\r\n174\r\n339\r\n946\r\n184\r\n250\r\n807\r\n422\r\n679\r\n980\r\n64\r\n530\r\n312\r\n351\r\n676\r\n911\r\n803\r\n991\r\n669\r\n50\r\n293\r\n841\r\n545\r\n598\r\n737\r\n894\r\n231\r\n754\r\n588\r\n83\r\n873\r\n767\r\n833\r\n482\r\n905\r\n903\r\n970\r\n571\r\n715\r\n59\r\n777\r\n697\r\n537\r\n861\r\n339\r\n212\r\n149\r\n889\r\n905\r\n70\r\n970\r\n307\r\n830\r\n465\r\n968\r\n291\r\n430\r\n317\r\n942\r\n944\r\n330\r\n235\r\n814\r\n880\r\n415\r\n76\r\n", "output": "58\r\n"}, {"input": "100\r\n154\r\n60\r\n97\r\n638\r\n139\r\n150\r\n570\r\n579\r\n601\r\n647\r\n804\r\n237\r\n245\r\n549\r\n288\r\n347\r\n778\r\n282\r\n916\r\n441\r\n974\r\n145\r\n957\r\n886\r\n655\r\n702\r\n930\r\n618\r\n132\r\n520\r\n972\r\n48\r\n94\r\n54\r\n682\r\n433\r\n896\r\n134\r\n845\r\n636\r\n242\r\n842\r\n125\r\n141\r\n240\r\n130\r\n409\r\n666\r\n948\r\n938\r\n604\r\n110\r\n474\r\n484\r\n364\r\n40\r\n807\r\n271\r\n438\r\n288\r\n201\r\n814\r\n754\r\n589\r\n341\r\n576\r\n146\r\n952\r\n819\r\n923\r\n222\r\n535\r\n336\r\n83\r\n314\r\n911\r\n303\r\n911\r\n384\r\n601\r\n249\r\n330\r\n735\r\n271\r\n142\r\n204\r\n405\r\n783\r\n775\r\n449\r\n590\r\n139\r\n109\r\n276\r\n45\r\n205\r\n454\r\n836\r\n82\r\n841\r\n", "output": "50\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "4\r\n1\r\n1\r\n1\r\n2\r\n", "output": "3\r\n"}, {"input": "5\r\n1\r\n2\r\n4\r\n8\r\n16\r\n", "output": "3\r\n"}, {"input": "7\r\n1\r\n2\r\n4\r\n8\r\n16\r\n32\r\n64\r\n", "output": "4\r\n"}, {"input": "3\r\n1\r\n2\r\n4\r\n", "output": "2\r\n"}]
false
stdio
null
true
374/B
374
B
PyPy 3
TESTS
5
140
3,788,800
68477174
sas = list(map(int, input())) ass = sas.copy() g = 1 for i in range(1, len(sas)): if sas[i] + sas[i - 1] == 9 and ass[i - 1] != 9: ass[i] = 9 ass[i - 1] = 0 for i in range(1, len(sas)): if ass[i] != 9 and ass[i - 1] == 9 and ass[i] and sas[i] + sas[i - 1] == 9: g *= 2 print(g)
25
77
102,400
231128198
s,a,c=input(),1,1 for i in range(1,len(s)): if int(s[i])+int(s[i-1])==9:c+=1 elif c%2:a*=c//2+1;c=1 else:c=1 if(c%2):a*=c//2+1 print(a)
Codeforces Round 220 (Div. 2)
CF
2,013
1
256
Inna and Nine
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9. Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9. For instance, Inna can alter number 14545181 like this: 14545181 → 1945181 → 194519 → 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine. Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes.
In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 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
Notes to the samples In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979. In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.
[{"input": "369727", "output": "2"}, {"input": "123456789987654321", "output": "1"}, {"input": "1", "output": "1"}]
1,500
["combinatorics", "greedy"]
25
[{"input": "369727\r\n", "output": "2\r\n"}, {"input": "123456789987654321\r\n", "output": "1\r\n"}, {"input": "1\r\n", "output": "1\r\n"}, {"input": "3636363636363454545454543636363636454545452727272727218181818181999111777\r\n", "output": "1512\r\n"}, {"input": "1188\r\n", "output": "1\r\n"}, {"input": "121212912121291299129191219\r\n", "output": "1\r\n"}, {"input": "181818918181891918918181918189181818181891818191818191819189\r\n", "output": "54\r\n"}, {"input": "12191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219\r\n", "output": "1\r\n"}, {"input": "444444444444445444444444454444444444444444444444445544444444444444444444444444444444444444444554444444444444444444444444444444444444445454444444444444444444444444444444444444454444444444444444444444444444444444445444444444444444444444444444444444444444444445444444444444444444444444444444444456666666666666666666663555555555555555888888888882333333312567312389542179415242164512341234213443123412341293412341234123412746129342154796124123459123491238471234213451692341278451234125934\r\n", "output": "96\r\n"}, {"input": "123456789\r\n", "output": "1\r\n"}, {"input": "3639272918194549\r\n", "output": "16\r\n"}, {"input": "1121314151617181921222324252627282931323334353637383941424344454647484951525354556575859616263646566768697172737475767787981828384858687888991929394959696979899\r\n", "output": "256\r\n"}, {"input": "14545181\r\n", "output": "2\r\n"}, {"input": "272727272\r\n", "output": "5\r\n"}, {"input": "1212121217272727121\r\n", "output": "4\r\n"}, {"input": "1212172727\r\n", "output": "3\r\n"}, {"input": "181817272727\r\n", "output": "12\r\n"}]
false
stdio
null
true
281/A
281
A
Python 3
TESTS
6
62
0
228414318
word=input() first_letter=word[0].upper() new_word=word.replace(word[0], first_letter) print(new_word)
25
62
0
224149541
word=input() wordlist=[] for x in word: wordlist.append(x) wordlist[0]=wordlist[0].upper() for x in wordlist: print(x,end='')
Codeforces Round 172 (Div. 2)
CF
2,013
2
256
Word Capitalization
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
null
null
[{"input": "ApPLe", "output": "ApPLe"}, {"input": "konjac", "output": "Konjac"}]
800
["implementation", "strings"]
25
[{"input": "ApPLe\r\n", "output": "ApPLe\r\n"}, {"input": "konjac\r\n", "output": "Konjac\r\n"}, {"input": "a\r\n", "output": "A\r\n"}, {"input": "A\r\n", "output": "A\r\n"}, {"input": "z\r\n", "output": "Z\r\n"}, {"input": "ABACABA\r\n", "output": "ABACABA\r\n"}, {"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuL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aYbRiHzYuQyX\r\n"}, {"input": "lZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ\r\n", "output": "LZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ\r\n"}, {"input": "P\r\n", "output": "P\r\n"}, {"input": "Xyzzy\r\n", "output": "Xyzzy\r\n"}, {"input": "Zzz\r\n", "output": "Zzz\r\n"}, {"input": "Zp\r\n", "output": "Zp\r\n"}]
false
stdio
null
true
281/A
281
A
Python 3
TESTS
6
62
0
228152376
a=input() b=a[0].upper() c=a.replace(a[0],b) print(c)
25
62
0
224155430
a=input() d=a[0].upper() print(d,a[1:],sep="")
Codeforces Round 172 (Div. 2)
CF
2,013
2
256
Word Capitalization
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
null
null
[{"input": "ApPLe", "output": "ApPLe"}, {"input": "konjac", "output": "Konjac"}]
800
["implementation", "strings"]
25
[{"input": "ApPLe\r\n", "output": "ApPLe\r\n"}, {"input": "konjac\r\n", "output": "Konjac\r\n"}, {"input": "a\r\n", "output": "A\r\n"}, {"input": "A\r\n", "output": "A\r\n"}, {"input": "z\r\n", "output": "Z\r\n"}, {"input": "ABACABA\r\n", "output": "ABACABA\r\n"}, {"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX\r\n", "output": "XYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFk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TmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ\r\n", "output": "LZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ\r\n"}, {"input": "P\r\n", "output": "P\r\n"}, {"input": "Xyzzy\r\n", "output": "Xyzzy\r\n"}, {"input": "Zzz\r\n", "output": "Zzz\r\n"}, {"input": "Zp\r\n", "output": "Zp\r\n"}]
false
stdio
null
true
281/A
281
A
Python 3
TESTS
6
62
0
226420910
word=input() if word[0].isupper(): print(word) else: print(word.capitalize())
25
62
0
224564251
# -*- coding: utf-8 -*- """ Created on Fri Sep 22 13:12:11 2023 @author: 25419 """ str0=input() str1=('abcdefghijklmnopqrstuvwxyz') str2=('ABCDEFGHIJKLMNOPQRSTUVWXYZ') if str0[0] in str1: var0=str0[0].capitalize() print(var0 + str0[1:]) else: print(str0)
Codeforces Round 172 (Div. 2)
CF
2,013
2
256
Word Capitalization
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
null
null
[{"input": "ApPLe", "output": "ApPLe"}, {"input": "konjac", "output": "Konjac"}]
800
["implementation", "strings"]
25
[{"input": "ApPLe\r\n", "output": "ApPLe\r\n"}, {"input": "konjac\r\n", "output": "Konjac\r\n"}, {"input": "a\r\n", "output": "A\r\n"}, {"input": "A\r\n", "output": "A\r\n"}, {"input": "z\r\n", "output": "Z\r\n"}, {"input": "ABACABA\r\n", "output": "ABACABA\r\n"}, {"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX\r\n", "output": "XYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX\r\n"}, {"input": "rZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWk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kRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ\r\n"}, {"input": "P\r\n", "output": "P\r\n"}, {"input": "Xyzzy\r\n", "output": "Xyzzy\r\n"}, {"input": "Zzz\r\n", "output": "Zzz\r\n"}, {"input": "Zp\r\n", "output": "Zp\r\n"}]
false
stdio
null
true
281/A
281
A
Python 3
TESTS
6
62
0
225709835
my_word = input() if my_word[0].islower(): my_word = my_word.replace(my_word[0], my_word[0].upper()) print(my_word)
25
62
0
224687985
word=input() print(word[0].upper()+word[1:])
Codeforces Round 172 (Div. 2)
CF
2,013
2
256
Word Capitalization
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
null
null
[{"input": "ApPLe", "output": "ApPLe"}, {"input": "konjac", "output": "Konjac"}]
800
["implementation", "strings"]
25
[{"input": "ApPLe\r\n", "output": "ApPLe\r\n"}, {"input": "konjac\r\n", "output": "Konjac\r\n"}, {"input": "a\r\n", "output": "A\r\n"}, {"input": "A\r\n", "output": "A\r\n"}, {"input": "z\r\n", "output": "Z\r\n"}, {"input": "ABACABA\r\n", "output": "ABACABA\r\n"}, {"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhV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TESTS
3
61
614,400
167064135
import collections import os import sys from collections import Counter # print(sys.hexversion) # if os.getenv('LOCALCFTEST'): # sys.stdin = open('cfinput.txt') # else: # input = sys.stdin.readline if sys.hexversion == 50924784: sys.stdin = open('cfinput.txt') else: input = sys.stdin.readline MOD = 10 ** 9 + 7 class IntervalTree: def __init__(self, size, nums=None): self.size = size self.nums = nums self.interval_tree = [0] * (size * 4) if nums: self.build_tree(1, 1, size) def build_tree(self, p, l, r): interval_tree = self.interval_tree nums = self.nums if l == r: # print(l,r,p,nums) interval_tree[p] = nums[l - 1] return mid = (l + r) // 2 self.build_tree(p * 2, l, mid) self.build_tree(p * 2 + 1, mid + 1, r) interval_tree[p] = max(interval_tree[p * 2], interval_tree[p * 2 + 1]) def max_interval(self, p, l, r, x, y): if y < l or r < x or r < l: return 0 interval_tree = self.interval_tree if x <= l and r <= y: return interval_tree[p] mid = (l + r) // 2 return max(self.max_interval(p * 2, l, mid, x, y), self.max_interval(p * 2 + 1, mid + 1, r, x, y)) def solve(n, s): left = [-1] * n stack = [] for i, v in enumerate(s): while stack and s[stack[-1]] < v: stack.pop() if stack: left[i] = stack[-1] stack.append(i) right = [n] * n stack = [] for i in range(n - 1, -1, -1): v = s[i] while stack and s[stack[-1]] < v: stack.pop() if stack: right[i] = stack[-1] stack.append(i) size = len(s) tree = IntervalTree(size, s) ans = 0 for i, (l, r) in enumerate(zip(left, right)): if r - l > 2: first = s[i] second = max(tree.max_interval(1, 1, size, l + 2, i), tree.max_interval(1, 1, size, i + 2, r)) ans = max(ans, first ^ second) print(ans) if __name__ == '__main__': n = int(input()) s = list(map(int, input().split())) solve(n, s)
56
93
14,848,000
167070041
n, a = int(input()), list(map(int, input().split())) def f(arr): ret = 0 st = [] for v in arr: while st and st[-1] < v: ret = max(st.pop(-1) ^ v, ret) if st: ret=max(st[-1]^v,ret) st.append(v) return ret print(f(a))
Codeforces Round 172 (Div. 1)
CF
2,013
1
256
Maximum Xor Secondary
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: $$x_j \neq \max_{i=1}^{k} x_i$$. The lucky number of the sequence of distinct positive integers x1, x2, ..., xk (k > 1) is the number that is equal to the bitwise excluding OR of the maximum element of the sequence and the second maximum element of the sequence. You've got a sequence of distinct positive integers s1, s2, ..., sn (n > 1). Let's denote sequence sl, sl + 1, ..., sr as s[l..r] (1 ≤ l < r ≤ n). Your task is to find the maximum number among all lucky numbers of sequences s[l..r]. Note that as all numbers in sequence s are distinct, all the given definitions make sence.
The first line contains integer n (1 < n ≤ 105). The second line contains n distinct integers s1, s2, ..., sn (1 ≤ si ≤ 109).
Print a single integer — the maximum lucky number among all lucky numbers of sequences s[l..r].
null
For the first sample you can choose s[4..5] = {4, 3} and its lucky number is (4 xor 3) = 7. You can also choose s[1..2]. For the second sample you must choose s[2..5] = {8, 3, 5, 7}.
[{"input": "5\n5 2 1 4 3", "output": "7"}, {"input": "5\n9 8 3 5 7", "output": "15"}]
1,800
["data structures", "implementation", "two pointers"]
56
[{"input": "5\r\n5 2 1 4 3\r\n", "output": "7\r\n"}, {"input": "5\r\n9 8 3 5 7\r\n", "output": "15\r\n"}, {"input": "10\r\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446\r\n", "output": "128869996\r\n"}, {"input": "10\r\n4547989 39261040 94929326 38131456 26174500 7152864 71295827 77784626 89898294 68006331\r\n", "output": "134189790\r\n"}, {"input": "10\r\n30301275 19973434 63004643 54007648 93722492 91677384 58694045 41546981 15552151 5811338\r\n", "output": "112066588\r\n"}, {"input": "10\r\n47606126 65484553 142643 35352821 26622058 5603080 7296801 53938188 34750256 97196502\r\n", "output": "131671782\r\n"}, {"input": "10\r\n82942694 74816699 72957520 1634864 60842992 60103606 61079517 41624114 13932450 24035648\r\n", "output": "133874061\r\n"}, {"input": "10\r\n73622246 45316865 2066146 61168230 1258786 69603039 64470479 72811017 72683016 97992629\r\n", "output": "133280528\r\n"}, {"input": "10\r\n29272229 8752316 10025994 52398694 57994948 49609605 28150935 66061676 44865054 87041483\r\n", "output": "127710165\r\n"}, {"input": "10\r\n3106954 3413954 3854371 85952704 17834583 20954227 58810981 7460648 97908613 97965110\r\n", "output": "111078053\r\n"}, {"input": "3\r\n11 10 8\r\n", "output": "2\r\n"}, {"input": "2\r\n5 6\r\n", "output": "3\r\n"}, {"input": "2\r\n16 17\r\n", "output": "1\r\n"}, {"input": "3\r\n8 9 10\r\n", "output": "3\r\n"}]
false
stdio
null
true
282/A
282
A
Python 3
TESTS
3
46
0
226979062
n=int(input()) l=[] for i in range(n): s=input() l.append(s) i=l.count("X++") j=l.count("++X") k=l.count("X--") m=l.count("--X") u=i+j v=k+m if u>v: print(u-v) else: print(v-u)
36
31
0
227089213
n = int(input()) x = 0 for _ in range(n): statement = list(map(str, input().strip())) if statement[1] == "+": x += 1 elif statement[1] == "-": x -= 1 print(x)
Codeforces Round 173 (Div. 2)
CF
2,013
1
256
Bit++
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: - Operation ++ increases the value of variable x by 1. - Operation -- decreases the value of variable x by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme. Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Print a single integer — the final value of x.
null
null
[{"input": "1\n++X", "output": "1"}, {"input": "2\nX++\n--X", "output": "0"}]
800
["implementation"]
36
[{"input": "1\r\n++X\r\n", "output": "1\r\n"}, {"input": "2\r\nX++\r\n--X\r\n", "output": "0\r\n"}, {"input": "3\r\n++X\r\n++X\r\n++X\r\n", "output": "3\r\n"}, {"input": "2\r\n--X\r\n--X\r\n", "output": "-2\r\n"}, {"input": "5\r\n++X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "-1\r\n"}, {"input": "28\r\nX--\r\n++X\r\nX++\r\nX++\r\nX++\r\n--X\r\n--X\r\nX++\r\nX--\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\nX--\r\n++X\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n--X\r\n++X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX++\r\n", "output": "4\r\n"}, {"input": "94\r\nX++\r\nX++\r\n++X\r\n++X\r\nX--\r\n--X\r\nX++\r\n--X\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\nX++\r\n--X\r\nX--\r\nX--\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX++\r\n++X\r\n--X\r\nX--\r\n++X\r\n--X\r\n--X\r\nX--\r\nX--\r\nX++\r\nX++\r\nX--\r\nX++\r\nX--\r\nX--\r\nX--\r\n--X\r\nX--\r\nX--\r\nX--\r\nX++\r\n++X\r\nX--\r\n++X\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n++X\r\nX--\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\n--X\r\nX--\r\n++X\r\nX--\r\nX--\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\n++X\r\n--X\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX++\r\n", "output": "-10\r\n"}, {"input": "56\r\n--X\r\nX--\r\n--X\r\n--X\r\nX--\r\nX--\r\n--X\r\nX++\r\n++X\r\n--X\r\nX++\r\nX--\r\n--X\r\n++X\r\n--X\r\nX--\r\nX--\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n--X\r\n++X\r\nX++\r\nX++\r\n--X\r\nX++\r\nX--\r\n--X\r\nX--\r\n--X\r\nX++\r\n++X\r\n--X\r\n++X\r\nX++\r\nX--\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n--X\r\nX--\r\n--X\r\nX++\r\n--X\r\n++X\r\n--X\r\n", "output": "-14\r\n"}, {"input": "59\r\nX--\r\n--X\r\nX++\r\n++X\r\nX--\r\n--X\r\n--X\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\n++X\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\nX++\r\n--X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\nX++\r\nX--\r\nX--\r\n--X\r\nX++\r\nX--\r\nX--\r\n++X\r\nX--\r\nX++\r\n--X\r\nX++\r\nX--\r\nX--\r\nX--\r\nX--\r\n++X\r\n--X\r\nX++\r\nX++\r\nX--\r\nX++\r\n++X\r\nX--\r\nX++\r\nX--\r\nX--\r\n++X\r\n", "output": "3\r\n"}, {"input": "87\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\nX--\r\n++X\r\n--X\r\n--X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\n++X\r\n++X\r\n--X\r\n++X\r\n--X\r\nX--\r\n++X\r\n++X\r\nX--\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX--\r\n++X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX--\r\nX--\r\nX--\r\nX++\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\nX++\r\n++X\r\nX--\r\n--X\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX++\r\nX++\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX--\r\n--X\r\n++X\r\n++X\r\n", "output": "-5\r\n"}, {"input": "101\r\nX++\r\nX++\r\nX++\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX--\r\n--X\r\n--X\r\n++X\r\nX++\r\n++X\r\n++X\r\nX--\r\n--X\r\n++X\r\nX++\r\nX--\r\n++X\r\n--X\r\n--X\r\n--X\r\n++X\r\n--X\r\n++X\r\nX++\r\nX++\r\n++X\r\n--X\r\nX++\r\nX--\r\nX++\r\n++X\r\n++X\r\nX--\r\nX--\r\nX--\r\nX++\r\nX++\r\nX--\r\nX--\r\nX++\r\n++X\r\n++X\r\n++X\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\n++X\r\nX++\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX--\r\n++X\r\nX--\r\n++X\r\nX++\r\nX--\r\n++X\r\nX++\r\n--X\r\nX++\r\nX++\r\n++X\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\n++X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX--\r\nX--\r\n--X\r\n--X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "1\r\n"}, {"input": "63\r\n--X\r\nX--\r\n++X\r\n--X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX++\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX--\r\n++X\r\nX++\r\nX--\r\n--X\r\nX--\r\n++X\r\n++X\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\nX--\r\n++X\r\nX--\r\n--X\r\nX--\r\nX--\r\nX--\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\n++X\r\n++X\r\nX--\r\n++X\r\n++X\r\nX--\r\n", "output": "1\r\n"}, {"input": "45\r\n--X\r\n++X\r\nX--\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX++\r\n++X\r\nX--\r\n++X\r\n++X\r\nX--\r\nX++\r\nX--\r\n--X\r\nX--\r\n++X\r\n++X\r\n--X\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\n--X\r\n--X\r\nX--\r\n++X\r\n++X\r\nX++\r\nX++\r\n++X\r\n++X\r\nX++\r\n", "output": "-3\r\n"}, {"input": "21\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\nX--\r\n--X\r\nX++\r\n++X\r\n", "output": "1\r\n"}, {"input": "100\r\n--X\r\n++X\r\nX++\r\n++X\r\nX--\r\n++X\r\nX--\r\nX++\r\n--X\r\nX++\r\nX--\r\nX--\r\nX--\r\n++X\r\nX--\r\nX++\r\nX++\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\nX--\r\nX++\r\nX++\r\nX++\r\n++X\r\n--X\r\n++X\r\nX++\r\nX--\r\n++X\r\n++X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX--\r\nX++\r\nX--\r\nX--\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\n--X\r\n--X\r\n++X\r\nX++\r\nX--\r\nX++\r\nX--\r\nX++\r\nX++\r\n--X\r\nX--\r\nX--\r\n++X\r\nX--\r\n--X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX--\r\nX--\r\n++X\r\n++X\r\nX--\r\n++X\r\nX++\r\n--X\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\n", "output": "8\r\n"}, {"input": "17\r\nX++\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\n--X\r\n--X\r\nX--\r\n++X\r\nX--\r\nX++\r\n", "output": "-1\r\n"}, {"input": "77\r\n++X\r\nX++\r\n--X\r\nX--\r\n--X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX++\r\nX--\r\n++X\r\n--X\r\n--X\r\n--X\r\n--X\r\n++X\r\nX--\r\nX++\r\nX--\r\n--X\r\nX--\r\n--X\r\nX--\r\n++X\r\n--X\r\n++X\r\n++X\r\nX++\r\nX++\r\nX--\r\n--X\r\nX--\r\nX--\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n++X\r\nX++\r\nX--\r\n++X\r\n--X\r\nX++\r\nX--\r\n++X\r\n++X\r\n++X\r\nX--\r\nX--\r\nX--\r\n--X\r\n++X\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\nX++\r\n--X\r\nX++\r\nX--\r\n", "output": "-5\r\n"}, {"input": "21\r\nX--\r\n++X\r\n--X\r\nX--\r\n++X\r\nX--\r\n++X\r\nX--\r\n--X\r\n++X\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\n--X\r\nX++\r\nX++\r\nX--\r\n++X\r\nX--\r\n", "output": "1\r\n"}, {"input": "1\r\nX--\r\n", "output": "-1\r\n"}]
false
stdio
null
true
282/A
282
A
PyPy 3-64
TESTS
3
62
0
228464421
n = int(input()) positive = [] negative = [] for i in range(n): check = [] s = input().split() for i in s: for j in i: check.append(j) if check[0] == '+' or check[-1] == '+': positive.append(0) else: negative.append(0) print(abs(len(positive)-len(negative)))
36
31
0
227429063
n=int(input()) x=0 for i in range(n): a=input() if a.__contains__('+'): x+=1 else: x-=1 print(x)
Codeforces Round 173 (Div. 2)
CF
2,013
1
256
Bit++
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: - Operation ++ increases the value of variable x by 1. - Operation -- decreases the value of variable x by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme. Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Print a single integer — the final value of x.
null
null
[{"input": "1\n++X", "output": "1"}, {"input": "2\nX++\n--X", "output": "0"}]
800
["implementation"]
36
[{"input": "1\r\n++X\r\n", "output": "1\r\n"}, {"input": "2\r\nX++\r\n--X\r\n", "output": "0\r\n"}, {"input": "3\r\n++X\r\n++X\r\n++X\r\n", "output": "3\r\n"}, {"input": "2\r\n--X\r\n--X\r\n", "output": "-2\r\n"}, {"input": "5\r\n++X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "-1\r\n"}, {"input": "28\r\nX--\r\n++X\r\nX++\r\nX++\r\nX++\r\n--X\r\n--X\r\nX++\r\nX--\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\nX--\r\n++X\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n--X\r\n++X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX++\r\n", "output": "4\r\n"}, {"input": "94\r\nX++\r\nX++\r\n++X\r\n++X\r\nX--\r\n--X\r\nX++\r\n--X\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\nX++\r\n--X\r\nX--\r\nX--\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX++\r\n++X\r\n--X\r\nX--\r\n++X\r\n--X\r\n--X\r\nX--\r\nX--\r\nX++\r\nX++\r\nX--\r\nX++\r\nX--\r\nX--\r\nX--\r\n--X\r\nX--\r\nX--\r\nX--\r\nX++\r\n++X\r\nX--\r\n++X\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n++X\r\nX--\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\n--X\r\nX--\r\n++X\r\nX--\r\nX--\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\n++X\r\n--X\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX++\r\n", "output": "-10\r\n"}, {"input": "56\r\n--X\r\nX--\r\n--X\r\n--X\r\nX--\r\nX--\r\n--X\r\nX++\r\n++X\r\n--X\r\nX++\r\nX--\r\n--X\r\n++X\r\n--X\r\nX--\r\nX--\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n--X\r\n++X\r\nX++\r\nX++\r\n--X\r\nX++\r\nX--\r\n--X\r\nX--\r\n--X\r\nX++\r\n++X\r\n--X\r\n++X\r\nX++\r\nX--\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n--X\r\nX--\r\n--X\r\nX++\r\n--X\r\n++X\r\n--X\r\n", "output": "-14\r\n"}, {"input": "59\r\nX--\r\n--X\r\nX++\r\n++X\r\nX--\r\n--X\r\n--X\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\n++X\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\nX++\r\n--X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\nX++\r\nX--\r\nX--\r\n--X\r\nX++\r\nX--\r\nX--\r\n++X\r\nX--\r\nX++\r\n--X\r\nX++\r\nX--\r\nX--\r\nX--\r\nX--\r\n++X\r\n--X\r\nX++\r\nX++\r\nX--\r\nX++\r\n++X\r\nX--\r\nX++\r\nX--\r\nX--\r\n++X\r\n", "output": "3\r\n"}, {"input": "87\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\nX--\r\n++X\r\n--X\r\n--X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\n++X\r\n++X\r\n--X\r\n++X\r\n--X\r\nX--\r\n++X\r\n++X\r\nX--\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX--\r\n++X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX--\r\nX--\r\nX--\r\nX++\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\nX++\r\n++X\r\nX--\r\n--X\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX++\r\nX++\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX--\r\n--X\r\n++X\r\n++X\r\n", "output": "-5\r\n"}, {"input": "101\r\nX++\r\nX++\r\nX++\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX--\r\n--X\r\n--X\r\n++X\r\nX++\r\n++X\r\n++X\r\nX--\r\n--X\r\n++X\r\nX++\r\nX--\r\n++X\r\n--X\r\n--X\r\n--X\r\n++X\r\n--X\r\n++X\r\nX++\r\nX++\r\n++X\r\n--X\r\nX++\r\nX--\r\nX++\r\n++X\r\n++X\r\nX--\r\nX--\r\nX--\r\nX++\r\nX++\r\nX--\r\nX--\r\nX++\r\n++X\r\n++X\r\n++X\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\n++X\r\nX++\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX--\r\n++X\r\nX--\r\n++X\r\nX++\r\nX--\r\n++X\r\nX++\r\n--X\r\nX++\r\nX++\r\n++X\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\n++X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX--\r\nX--\r\n--X\r\n--X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "1\r\n"}, {"input": "63\r\n--X\r\nX--\r\n++X\r\n--X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX++\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX--\r\n++X\r\nX++\r\nX--\r\n--X\r\nX--\r\n++X\r\n++X\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\nX--\r\n++X\r\nX--\r\n--X\r\nX--\r\nX--\r\nX--\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\n++X\r\n++X\r\nX--\r\n++X\r\n++X\r\nX--\r\n", "output": "1\r\n"}, {"input": "45\r\n--X\r\n++X\r\nX--\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX++\r\n++X\r\nX--\r\n++X\r\n++X\r\nX--\r\nX++\r\nX--\r\n--X\r\nX--\r\n++X\r\n++X\r\n--X\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\n--X\r\n--X\r\nX--\r\n++X\r\n++X\r\nX++\r\nX++\r\n++X\r\n++X\r\nX++\r\n", "output": "-3\r\n"}, {"input": "21\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\nX--\r\n--X\r\nX++\r\n++X\r\n", "output": "1\r\n"}, {"input": "100\r\n--X\r\n++X\r\nX++\r\n++X\r\nX--\r\n++X\r\nX--\r\nX++\r\n--X\r\nX++\r\nX--\r\nX--\r\nX--\r\n++X\r\nX--\r\nX++\r\nX++\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\nX--\r\nX++\r\nX++\r\nX++\r\n++X\r\n--X\r\n++X\r\nX++\r\nX--\r\n++X\r\n++X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX--\r\nX++\r\nX--\r\nX--\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\n--X\r\n--X\r\n++X\r\nX++\r\nX--\r\nX++\r\nX--\r\nX++\r\nX++\r\n--X\r\nX--\r\nX--\r\n++X\r\nX--\r\n--X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX--\r\nX--\r\n++X\r\n++X\r\nX--\r\n++X\r\nX++\r\n--X\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\n", "output": "8\r\n"}, {"input": "17\r\nX++\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\n--X\r\n--X\r\nX--\r\n++X\r\nX--\r\nX++\r\n", "output": "-1\r\n"}, {"input": "77\r\n++X\r\nX++\r\n--X\r\nX--\r\n--X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX++\r\nX--\r\n++X\r\n--X\r\n--X\r\n--X\r\n--X\r\n++X\r\nX--\r\nX++\r\nX--\r\n--X\r\nX--\r\n--X\r\nX--\r\n++X\r\n--X\r\n++X\r\n++X\r\nX++\r\nX++\r\nX--\r\n--X\r\nX--\r\nX--\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n++X\r\nX++\r\nX--\r\n++X\r\n--X\r\nX++\r\nX--\r\n++X\r\n++X\r\n++X\r\nX--\r\nX--\r\nX--\r\n--X\r\n++X\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\nX++\r\n--X\r\nX++\r\nX--\r\n", "output": "-5\r\n"}, {"input": "21\r\nX--\r\n++X\r\n--X\r\nX--\r\n++X\r\nX--\r\n++X\r\nX--\r\n--X\r\n++X\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\n--X\r\nX++\r\nX++\r\nX--\r\n++X\r\nX--\r\n", "output": "1\r\n"}, {"input": "1\r\nX--\r\n", "output": "-1\r\n"}]
false
stdio
null
true
641/B
641
B
Python 3
PRETESTS
5
420
5,632,000
17491841
n, m, q = map(int, input().split()) a = [[0 for j in range(m)] for i in range(n)] query = [] for i in range(q): s = list(map(int, input().split())) if len(s) == 2: query.append((s[0], s[1] - 1)) else: a[s[1] - 1][s[2] - 1] = s[3] for k in reversed(range(len(query))): if query[k][0] == 1: temp = a[query[k][1]][-1] for i in reversed(range(1, m)): a[query[k][1]][i] = a[query[k][1]][i - 1] a[query[k][1]][0] = temp else: temp = a[-1][query[k][1]] for i in reversed(range(1, n)): a[i][query[k][1]] = a[i - 1][query[k][1]] a[0][query[k][1]] = temp for i in range(n): for j in range(m): print(a[i][j], end = ' ') print()
26
186
5,529,600
17491397
def rotate_r(ar, row, n): ar[row] = ar[row][-n:] + ar[row][:-n] return ar def rotate_c(ar, m, col): #c = ar[col][0] c = ar[m - 1][col] for i in range(m - 1, 0, -1): #for i in range(m - 1): ar[i][col] = ar[i - 1][col] #ar[col][m - 1] = c ar[0][col] = c return ar def print_matr(ar, n): for i in range(n): print(*ar[i]) ar2 = [] n, m, q = map(int, input().split()) #for i in range(n): # ar = list(map(int, input().split())) # ar2.append(ar) query = [0 for i in range(q)] rows = [0 for i in range(q)] cols = [0 for i in range(q)] nums = [0 for i in range(q)] for i in range(q): ar = list(map(int, input().split())) query[i] = ar[0] if ar[0] == 3: rows[i] = ar[1] - 1 cols[i] = ar[2] - 1 nums[i] = ar[3] elif ar[0] == 1: rows[i] = ar[1] - 1 else: cols[i] = ar[1] - 1 #print(query) ans = [[0] * m for i in range(n)] for i in range(q - 1, -1, -1): if query[i] == 3: ans[rows[i]][cols[i]] = nums[i] #print('\n') #print_matr(ans, n) #print("l", rows[i] + 1, cols[i] + 1) #print(i, nums[i]) elif query[i] == 1: ans = rotate_r(ans, rows[i], 1) #print('\n') #print_matr(ans, n) else: ans = rotate_c(ans, n, cols[i]) #print('\n') #print_matr(ans, n) #row, n = map(int, input().split()) #print(rotate_r(ar2, 0, n)) print_matr(ans, n) #ans = rotate_c(ans, n, 0) #print_matr(ans, n)
VK Cup 2016 - Round 2
CF
2,016
2
256
Little Artem and Matrix
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it. That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right. Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix. Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
null
null
[{"input": "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "output": "8 2\n1 8"}, {"input": "3 3 2\n1 2\n3 2 2 5", "output": "0 0 0\n0 0 5\n0 0 0"}]
1,400
["implementation"]
26
[{"input": "2 2 6\r\n2 1\r\n2 2\r\n3 1 1 1\r\n3 2 2 2\r\n3 1 2 8\r\n3 2 1 8\r\n", "output": "8 2 \r\n1 8 \r\n"}, {"input": "3 3 2\r\n1 2\r\n3 2 2 5\r\n", "output": "0 0 0 \r\n0 0 5 \r\n0 0 0 \r\n"}, {"input": "5 5 1\r\n1 5\r\n", "output": "0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n"}, {"input": "1 1 3\r\n1 1\r\n2 1\r\n3 1 1 1000000000\r\n", "output": "1000000000 \r\n"}, {"input": "1 1 3\r\n1 1\r\n2 1\r\n3 1 1 -1000000000\r\n", "output": "-1000000000 \r\n"}, {"input": "2 2 6\r\n2 1\r\n2 2\r\n3 1 1 -1\r\n3 2 2 -1\r\n3 1 2 -1\r\n3 2 1 -1\r\n", "output": "-1 -1 \r\n-1 -1 \r\n"}, {"input": "1 4 5\r\n1 1\r\n3 1 1 1\r\n3 1 2 2\r\n3 1 3 3\r\n3 1 4 4\r\n", "output": "4 1 2 3 \r\n"}, {"input": "4 2 5\r\n2 1\r\n3 1 1 5\r\n3 2 1 6\r\n3 3 1 7\r\n3 4 1 9\r\n", "output": "9 0 \r\n5 0 \r\n6 0 \r\n7 0 \r\n"}, {"input": "3 10 2\r\n1 2\r\n3 2 7 5\r\n", "output": "0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 5 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n"}, {"input": "1 2 2\r\n1 1\r\n3 1 2 15\r\n", "output": "15 0 \r\n"}]
false
stdio
null
true
847/A
847
A
Python 3
TESTS
4
62
0
30468530
n=int(input()) l1=[] l2=[] l3=[] l4=[] for i in range(0,n): a,b=input().split(' ') a,b=int(a),int(b) l1.append(a) l2.append(b) if a==0: l3.append(i) if b==0: l4.append(i) x=len(l3) for j in range(0,x-1): l2[l4[j]]=l3[x-j-1]+1 l1[l3[x-j-1]]=l4[j]+1 for i in range(0,n): print(str(l1[i])+" "+str(l2[i]))
23
46
0
232715808
n = int(input()) arr = [] for _ in range(n): arr.append(list(map(int,input().split()))) k = 0 for x in enumerate(arr,1): i = x[0] l = x[1][0] r = x[1][1] if l == 0: if k != 0: arr[k-1][1] = i arr[i-1][0] = k k = i while r: k = r r = arr[r-1][1] else: continue for x in arr: print(x[0],x[1])
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
2
256
Union of Doubly Linked Lists
Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e. each element except the first has exactly one previous element, each element except the last has exactly one next element. The list is not closed in a cycle. In this problem you are given n memory cells forming one or more doubly linked lists. Each cell contains information about element from some list. Memory cells are numbered from 1 to n. For each cell i you are given two values: - li — cell containing previous element for the element in the cell i; - ri — cell containing next element for the element in the cell i. If cell i contains information about the element which has no previous element then li = 0. Similarly, if cell i contains information about the element which has no next element then ri = 0. Three lists are shown on the picture. For example, for the picture above the values of l and r are the following: l1 = 4, r1 = 7; l2 = 5, r2 = 0; l3 = 0, r3 = 0; l4 = 6, r4 = 1; l5 = 0, r5 = 2; l6 = 0, r6 = 4; l7 = 1, r7 = 0. Your task is to unite all given lists in a single list, joining them to each other in any order. In particular, if the input data already contains a single list, then there is no need to perform any actions. Print the resulting list in the form of values li, ri. Any other action, other than joining the beginning of one list to the end of another, can not be performed.
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of memory cells where the doubly linked lists are located. Each of the following n lines contains two integers li, ri (0 ≤ li, ri ≤ n) — the cells of the previous and the next element of list for cell i. Value li = 0 if element in cell i has no previous element in its list. Value ri = 0 if element in cell i has no next element in its list. It is guaranteed that the input contains the correct description of a single or more doubly linked lists. All lists have linear structure: each element of list except the first has exactly one previous element; each element of list except the last has exactly one next element. Each memory cell contains information about one element from some list, each element of each list written in one of n given cells.
Print n lines, the i-th line must contain two integers li and ri — the cells of the previous and the next element of list for cell i after all lists from the input are united in a single list. If there are many solutions print any of them.
null
null
[{"input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0", "output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0"}]
1,500
["implementation"]
23
[{"input": "7\r\n4 7\r\n5 0\r\n0 0\r\n6 1\r\n0 2\r\n0 4\r\n1 0\r\n", "output": "4 7\r\n5 6\r\n0 5\r\n6 1\r\n3 2\r\n2 4\r\n1 0\r\n"}, {"input": "2\r\n2 0\r\n0 1\r\n", "output": "2 0\r\n0 1\r\n"}, {"input": "1\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "4\r\n0 2\r\n1 0\r\n0 4\r\n3 0\r\n", "output": "0 2\r\n1 3\r\n2 4\r\n3 0\r\n"}, {"input": "5\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\r\n1 3\r\n2 4\r\n3 5\r\n4 0\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "0 2\r\n1 0\r\n"}, {"input": "2\r\n0 2\r\n1 0\r\n", "output": "0 2\r\n1 0\r\n"}, {"input": "5\r\n5 3\r\n4 0\r\n1 4\r\n3 2\r\n0 1\r\n", "output": "5 3\r\n4 0\r\n1 4\r\n3 2\r\n0 1\r\n"}, {"input": "5\r\n2 0\r\n0 1\r\n0 4\r\n3 5\r\n4 0\r\n", "output": "2 3\r\n0 1\r\n1 4\r\n3 5\r\n4 0\r\n"}, {"input": "5\r\n3 4\r\n0 0\r\n0 1\r\n1 0\r\n0 0\r\n", "output": "3 4\r\n0 3\r\n2 1\r\n1 5\r\n4 0\r\n"}, {"input": "5\r\n3 0\r\n0 0\r\n0 1\r\n0 0\r\n0 0\r\n", "output": "3 4\r\n0 3\r\n2 1\r\n1 5\r\n4 0\r\n"}, {"input": "10\r\n7 5\r\n5 0\r\n4 7\r\n10 3\r\n1 2\r\n0 9\r\n3 1\r\n9 10\r\n6 8\r\n8 4\r\n", "output": "7 5\r\n5 0\r\n4 7\r\n10 3\r\n1 2\r\n0 9\r\n3 1\r\n9 10\r\n6 8\r\n8 4\r\n"}, {"input": "10\r\n6 2\r\n1 0\r\n9 4\r\n3 6\r\n10 8\r\n4 1\r\n0 10\r\n5 0\r\n0 3\r\n7 5\r\n", "output": "6 2\r\n1 0\r\n9 4\r\n3 6\r\n10 8\r\n4 1\r\n0 10\r\n5 9\r\n8 3\r\n7 5\r\n"}, {"input": "10\r\n0 9\r\n4 0\r\n5 0\r\n7 2\r\n0 3\r\n8 10\r\n0 4\r\n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r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 4\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\n1 3\n2 5\n97 98\n3 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 29\n29 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22\n21 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 30\n12 13\n28 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 51\n50 52\n51 53\n52 54\n53 55\n54 56\n55 57\n56 58\n57 59\n58 60\n59 61\n60 62\n61 63\n62 64\n63 65\n64 66\n65 67\n66 68\n67 69\n68 70\n69 71\n70 72\n71 73\n72 74\n73 75\n74 76\n75 77\n76 78\n77 79\n78 80\n79 81\n80 82\n81 83\n82 84\n83 85\n84 86\n85 87\n86 88\n87 89\n88 90\n89 91\n90 92\n91 93\n92 94\n93 95\n94 96\n95 97\n96 4\n4 99\n98 100\n99 0\n"}, {"input": "100\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 80\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n21 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 80\n80 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 29\n28 30\n29 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 51\n50 52\n51 53\n52 54\n53 55\n54 56\n55 57\n56 58\n57 59\n58 60\n59 61\n60 62\n61 63\n62 64\n63 65\n64 66\n65 67\n66 68\n67 69\n68 70\n69 71\n70 72\n71 73\n72 74\n73 75\n74 76\n75 77\n76 78\n77 79\n78 81\n21 22\n79 82\n81 83\n82 84\n83 85\n84 86\n85 87\n86 88\n87 89\n88 90\n89 91\n90 92\n91 93\n92 94\n93 95\n94 96\n95 97\n96 98\n97 99\n98 100\n99 0\n"}, {"input": "100\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22\n21 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 29\n28 30\n29 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 51\n50 52\n51 53\n52 54\n53 55\n54 56\n55 57\n56 58\n57 59\n58 60\n59 61\n60 62\n61 63\n62 64\n63 65\n64 66\n65 67\n66 68\n67 69\n68 70\n69 71\n70 72\n71 73\n72 74\n73 75\n74 76\n75 77\n76 78\n77 79\n78 80\n79 81\n80 82\n81 83\n82 84\n83 85\n84 86\n85 87\n86 88\n87 89\n88 90\n89 91\n90 92\n91 93\n92 94\n93 95\n94 96\n95 97\n96 98\n97 99\n98 100\n99 0\n"}]
false
stdio
null
true
374/B
374
B
PyPy 3-64
TESTS
5
61
1,433,600
175304293
import sys input = sys.stdin.readline s = input()[:-1] n = len(s) d = dict() f = 0 for i in range(1, 10): d[str(i)] = str(9-i) i = 0 while i < n-1: c = 0 while i < n-1 and d[s[i]] == s[i+1]: i += 1 c += 1 if c == 0 or c % 2: i += 1 else: f += 1 i += 1 print(2**f)
25
93
2,252,800
179034177
n=input() l=len(n) ans=1 i=0 while(i<l): x=1 while(i<l-1 and int(n[i])+int(n[i+1])==9): x+=1 i+=1 if x%2==1 and x>1: ans*=x//2+1 x=1 i+=1 print(ans)
Codeforces Round 220 (Div. 2)
CF
2,013
1
256
Inna and Nine
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9. Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9. For instance, Inna can alter number 14545181 like this: 14545181 → 1945181 → 194519 → 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine. Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes.
In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 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
Notes to the samples In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979. In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.
[{"input": "369727", "output": "2"}, {"input": "123456789987654321", "output": "1"}, {"input": "1", "output": "1"}]
1,500
["combinatorics", "greedy"]
25
[{"input": "369727\r\n", "output": "2\r\n"}, {"input": "123456789987654321\r\n", "output": "1\r\n"}, {"input": "1\r\n", "output": "1\r\n"}, {"input": "3636363636363454545454543636363636454545452727272727218181818181999111777\r\n", "output": "1512\r\n"}, {"input": "1188\r\n", "output": "1\r\n"}, {"input": "121212912121291299129191219\r\n", "output": "1\r\n"}, {"input": "181818918181891918918181918189181818181891818191818191819189\r\n", "output": "54\r\n"}, {"input": "12191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219\r\n", "output": "1\r\n"}, {"input": "444444444444445444444444454444444444444444444444445544444444444444444444444444444444444444444554444444444444444444444444444444444444445454444444444444444444444444444444444444454444444444444444444444444444444444445444444444444444444444444444444444444444444445444444444444444444444444444444444456666666666666666666663555555555555555888888888882333333312567312389542179415242164512341234213443123412341293412341234123412746129342154796124123459123491238471234213451692341278451234125934\r\n", "output": "96\r\n"}, {"input": "123456789\r\n", "output": "1\r\n"}, {"input": "3639272918194549\r\n", "output": "16\r\n"}, {"input": "1121314151617181921222324252627282931323334353637383941424344454647484951525354556575859616263646566768697172737475767787981828384858687888991929394959696979899\r\n", "output": "256\r\n"}, {"input": "14545181\r\n", "output": "2\r\n"}, {"input": "272727272\r\n", "output": "5\r\n"}, {"input": "1212121217272727121\r\n", "output": "4\r\n"}, {"input": "1212172727\r\n", "output": "3\r\n"}, {"input": "181817272727\r\n", "output": "12\r\n"}]
false
stdio
null
true
774/D
774
D
Python 3
TESTS
14
140
14,848,000
26151223
n=int,input().split() A = list(map(int, input().split())) B = list(map(int, input().split())) a=set() b=set() for i in range (int(n[1][1])-1,int(n[1][2])): a.add(A[i]) b.add(B[i]) flag=True for i in range (int(n[1][1])-1): if A[i]!=B[i]: flag=False for i in range (int(n[1][2]),int(n[1][1])): if A[i]!=B[i]: flag=False if a!=b: flag=False if flag==True: print("TRUTH") else: print ("LIE")
52
93
15,155,200
26150252
top = input().split() n = top[0] l = top[1] r = top[2] a = input().split() b = input().split() truth = True for i in range(0 , int(l)-1): if a[i] != b[i]: truth = False for i in range(int(r) , int(n)): if a[i] != b[i]: truth = False if(truth == True): print("TRUTH\n") else: print("LIE\n")
VK Cup 2017 - Wild Card Round 1
ICPC
2,017
2
256
Lie or Truth
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an. While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to b1, b2, ..., bn. Stepan said that he swapped only cubes which where on the positions between l and r, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions l and r, inclusive, in some way). Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.
The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ n) — the sequence of integers written on cubes after Stepan rearranged their order. It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
null
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]). In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother. In the third example for any values l and r there is a situation when Stepan said the truth.
[{"input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1", "output": "TRUTH"}, {"input": "3 1 2\n1 2 3\n3 1 2", "output": "LIE"}, {"input": "4 2 4\n1 1 1 1\n1 1 1 1", "output": "TRUTH"}]
1,500
["*special", "constructive algorithms", "implementation", "sortings"]
52
[{"input": "5 2 4\r\n3 4 2 3 1\r\n3 2 3 4 1\r\n", "output": "TRUTH\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n3 1 2\r\n", "output": "LIE\r\n"}, {"input": "4 2 4\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "TRUTH\r\n"}, {"input": "5 1 3\r\n2 2 2 1 2\r\n2 2 2 1 2\r\n", "output": "TRUTH\r\n"}, {"input": "7 1 4\r\n2 5 5 5 4 3 4\r\n2 5 5 5 4 3 4\r\n", "output": "TRUTH\r\n"}, {"input": "10 1 10\r\n6 7 6 1 10 10 9 5 3 9\r\n7 10 9 6 1 5 9 3 10 6\r\n", "output": "TRUTH\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "TRUTH\r\n"}, {"input": "4 3 4\r\n1 2 3 4\r\n2 1 3 4\r\n", "output": "LIE\r\n"}, {"input": "7 2 4\r\n1 2 3 4 5 7 6\r\n1 2 3 4 5 6 7\r\n", "output": "LIE\r\n"}, {"input": "5 1 2\r\n1 2 3 4 5\r\n1 2 3 5 4\r\n", "output": "LIE\r\n"}, {"input": "8 3 6\r\n5 3 1 1 1 1 3 5\r\n3 3 1 1 1 1 5 5\r\n", "output": "LIE\r\n"}, {"input": "4 2 2\r\n2 1 2 2\r\n1 2 2 2\r\n", "output": "LIE\r\n"}]
false
stdio
null
true
494/B
494
B
Python 3
TESTS
6
264
4,915,200
31723820
s, t = input(), input() n, m = len(t), len(s) p = [0] * (n + 1) i, j = 0, 1 while j < n: if t[i] == t[j]: j += 1 i += 1 p[j] = i elif i: i = p[i] else: j += 1 i = j = 0 f = [0] * (m + 1) while j < m: if t[i] == s[j]: i += 1 j += 1 if i == n: i = p[i] f[j - n] = 1 elif i: i = p[i] else: j += 1 s = [0] * (m + 1) k = m for j in range(m - 1, -1, -1): if f[j]: k = j if k < m: f[j] = f[j + 1] + s[k + n] + m - k - n + 1 s[j] = s[j + 1] + f[j] print(f[0])
51
264
4,198,400
231039994
s, t = input(), input() n, m = len(t), len(s) + 1 d = 1000000007 g = [1] * m f = k = 0 for i in range(1, m) : if s[i - n:i] == t : k = i if k : f = (f + g[k - n]) % d g[i] += (g[i - 1] + f) % d print(f)
Codeforces Round 282 (Div. 1)
CF
2,014
2
256
Obsessive String
Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k ≥ 1 non-overlapping substrings from it such that each of them contains string t as a substring? More formally, you need to calculate the number of ways to choose two sequences a1, a2, ..., ak and b1, b2, ..., bk satisfying the following requirements: - k ≥ 1 - $$$$ - $$\forall i \left( 1 \leq i \leq k \right) b_i \geq a_i$$ - $$\forall i \left( 2 \leq i \leq k \right) a_i > b_{i-1}$$ - $$\forall i \left( 1 \leq i \leq k \right)$$  t is a substring of string saisai + 1... sbi (string s is considered as 1-indexed). As the number of ways can be rather large print it modulo 109 + 7.
Input consists of two lines containing strings s and t (1 ≤ |s|, |t| ≤ 105). Each string consists of lowercase Latin letters.
Print the answer in a single line.
null
null
[{"input": "ababa\naba", "output": "5"}, {"input": "welcometoroundtwohundredandeightytwo\nd", "output": "274201"}, {"input": "ddd\nd", "output": "12"}]
2,000
["dp", "strings"]
51
[{"input": "ababa\r\naba\r\n", "output": "5\r\n"}, {"input": "welcometoroundtwohundredandeightytwo\r\nd\r\n", "output": "274201\r\n"}, {"input": "ddd\r\nd\r\n", "output": "12\r\n"}, {"input": "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\r\nnssnssns\r\n", "output": "943392\r\n"}, {"input": "kpjmawawawawawawawawawawawawawawawawawawawawawawaw\r\nwawawawa\r\n", "output": "834052\r\n"}, {"input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\r\nvvvvvvvv\r\n", "output": "2728075\r\n"}, {"input": "a\r\na\r\n", "output": "1\r\n"}, {"input": "a\r\naa\r\n", "output": "0\r\n"}, {"input": "a\r\nb\r\n", "output": "0\r\n"}, {"input": "ababababab\r\nabab\r\n", "output": "35\r\n"}]
false
stdio
null
true
374/B
374
B
PyPy 3
TESTS
5
139
4,915,200
57446038
class CodeforcesTask374BSolution: def __init__(self): self.result = '' self.number = [] def read_input(self): self.number = [int(c) for c in input()] def process_task(self): nums = 1 x = 0 while x + 1 < len(self.number): s = 1 while self.number[x] + self.number[x + 1] == 9: s += 1 x += 1 if x + 1 >= len(self.number): break if s > 2: if s % 2: nums *= s - 1 x += 1 self.result = str(nums) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask374BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result())
25
93
5,939,200
161522543
a=[int(i) for i in list(input())] i=0 cl=[] while True: if i>=len(a)-1: break if a[i]+a[i+1]==9: c=1 while True: if i>=len(a)-1: break if a[i]+a[i+1]==9: c+=1 else: i+=1 break i+=1 if c%2==0: cl.append(1) else: cl.append((c+1)//2) else: i+=1 t=1 for i in cl: t*=i print(t)
Codeforces Round 220 (Div. 2)
CF
2,013
1
256
Inna and Nine
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9. Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9. For instance, Inna can alter number 14545181 like this: 14545181 → 1945181 → 194519 → 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine. Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes.
In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 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
Notes to the samples In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979. In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.
[{"input": "369727", "output": "2"}, {"input": "123456789987654321", "output": "1"}, {"input": "1", "output": "1"}]
1,500
["combinatorics", "greedy"]
25
[{"input": "369727\r\n", "output": "2\r\n"}, {"input": "123456789987654321\r\n", "output": "1\r\n"}, {"input": "1\r\n", "output": "1\r\n"}, {"input": "3636363636363454545454543636363636454545452727272727218181818181999111777\r\n", "output": "1512\r\n"}, {"input": "1188\r\n", "output": "1\r\n"}, {"input": "121212912121291299129191219\r\n", "output": "1\r\n"}, {"input": "181818918181891918918181918189181818181891818191818191819189\r\n", "output": "54\r\n"}, {"input": "12191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219\r\n", "output": "1\r\n"}, {"input": "444444444444445444444444454444444444444444444444445544444444444444444444444444444444444444444554444444444444444444444444444444444444445454444444444444444444444444444444444444454444444444444444444444444444444444445444444444444444444444444444444444444444444445444444444444444444444444444444444456666666666666666666663555555555555555888888888882333333312567312389542179415242164512341234213443123412341293412341234123412746129342154796124123459123491238471234213451692341278451234125934\r\n", "output": "96\r\n"}, {"input": "123456789\r\n", "output": "1\r\n"}, {"input": "3639272918194549\r\n", "output": "16\r\n"}, {"input": "1121314151617181921222324252627282931323334353637383941424344454647484951525354556575859616263646566768697172737475767787981828384858687888991929394959696979899\r\n", "output": "256\r\n"}, {"input": "14545181\r\n", "output": "2\r\n"}, {"input": "272727272\r\n", "output": "5\r\n"}, {"input": "1212121217272727121\r\n", "output": "4\r\n"}, {"input": "1212172727\r\n", "output": "3\r\n"}, {"input": "181817272727\r\n", "output": "12\r\n"}]
false
stdio
null
true
374/B
374
B
PyPy 3
TESTS
5
155
1,843,200
79081761
import sys import math data = sys.stdin.read().split() data_ptr = 0 def data_next(): global data_ptr, data data_ptr += 1 return data[data_ptr - 1] S = data[0] N = len(S) ans = 1 block = 0 for i in range(N): if i == N - 1 or int(S[i]) + int(S[i + 1]) != 9: if block > 0 and block % 2 == 0: ans *= 2 block = 0 else: block += 1 print(ans)
25
124
1,945,600
120766172
s=input() ans=1 c=1 for i in range(1,len(s)): if int(s[i])+int(s[i-1])==9: c+=1 elif c%2==1: ans*=c//2+1;c=1 else: c=1 if c%2==1: ans*=c//2+1 print(ans)
Codeforces Round 220 (Div. 2)
CF
2,013
1
256
Inna and Nine
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9. Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9. For instance, Inna can alter number 14545181 like this: 14545181 → 1945181 → 194519 → 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine. Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes.
In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 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
Notes to the samples In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979. In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.
[{"input": "369727", "output": "2"}, {"input": "123456789987654321", "output": "1"}, {"input": "1", "output": "1"}]
1,500
["combinatorics", "greedy"]
25
[{"input": "369727\r\n", "output": "2\r\n"}, {"input": "123456789987654321\r\n", "output": "1\r\n"}, {"input": "1\r\n", "output": "1\r\n"}, {"input": "3636363636363454545454543636363636454545452727272727218181818181999111777\r\n", "output": "1512\r\n"}, {"input": "1188\r\n", "output": "1\r\n"}, {"input": "121212912121291299129191219\r\n", "output": "1\r\n"}, {"input": "181818918181891918918181918189181818181891818191818191819189\r\n", "output": "54\r\n"}, {"input": "12191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219\r\n", "output": "1\r\n"}, {"input": "444444444444445444444444454444444444444444444444445544444444444444444444444444444444444444444554444444444444444444444444444444444444445454444444444444444444444444444444444444454444444444444444444444444444444444445444444444444444444444444444444444444444444445444444444444444444444444444444444456666666666666666666663555555555555555888888888882333333312567312389542179415242164512341234213443123412341293412341234123412746129342154796124123459123491238471234213451692341278451234125934\r\n", "output": "96\r\n"}, {"input": "123456789\r\n", "output": "1\r\n"}, {"input": "3639272918194549\r\n", "output": "16\r\n"}, {"input": "1121314151617181921222324252627282931323334353637383941424344454647484951525354556575859616263646566768697172737475767787981828384858687888991929394959696979899\r\n", "output": "256\r\n"}, {"input": "14545181\r\n", "output": "2\r\n"}, {"input": "272727272\r\n", "output": "5\r\n"}, {"input": "1212121217272727121\r\n", "output": "4\r\n"}, {"input": "1212172727\r\n", "output": "3\r\n"}, {"input": "181817272727\r\n", "output": "12\r\n"}]
false
stdio
null
true
963/B
963
B
Python 3
TESTS
6
265
7,065,600
37689210
def tree(aim,x): for i in aim: if (line_num[i] % 2 == 0) and (not(i in ans)): wk1 = line_num[i] line_num[i] = 0 aim1 = [] for j in range(len(line[i])): if not(line[i][j] in ans): line_num[line[i][j]] -= 1 aim1.append(line[i][j]) ans[x] = i tree(aim1, x + 1) for j in range(x + 1, len(ans)): ans[j] = 0 line_num[i] = wk1 for j in range(len(line[i])): if not(line[i][j] in ans): line_num[line[i][j]] += 1 f = True count = x for i in range(1, n + 1): if (not (i in ans)): if line_num[i] > 0: f = False break else: ans[count] = i count += 1 if f: print("YES") for i in ans: print(i) quit() return False n = int(input()) p = [int(i) for i in input().split()] line_num = [0]*(n + 1) line = [] for i in range(n + 1): line.append([]) for i in range(n): if p[i] != 0: line_num[i + 1] += 1 line[i + 1].append(p[i]) line_num[p[i]] += 1 line[p[i]].append(i + 1) aim = [] for i in range(1, n + 1): aim.append(i) ans = [0] * n tree(aim,0) print("NO")
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 stk = [root] vis = [False]*n while stk: node = stk[-1] if not vis[node]: vis[node] = True for node0 in G[node]: stk.append(node0) else: stk.pop() s[node] += 1 for node0 in G[node]: s[node] += s[node0] stk = [root] while stk: node = stk[-1] if vis[node]: vis[node] = False for node0 in G[node]: if s[node0]%2 == 0: stk.append(node0) else: stk.pop() print(node+1) for node0 in G[node]: if s[node0]%2 == 1: stk.append(node0)
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 determine that it is impossible.
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 46 19 22 83 56 67 62 82 57 16 29 36 84 71 42 66 78 54 73 45 82 80 67 88 79 69 61 66 5 36 24 60 96 21 77 67 68 29 87 37 91 34 78 43 0 69 49 62 16 2 68 79 57 1 60 12 39 99 14 37 30 92 47 18 14 75 73 39 94 12 43 87 90 22 91 59 54 71\r\n", "output": "NO\r\n"}, {"input": "100\r\n57 85 27 81 41 27 73 10 73 95 91 90 89 41 86 44 6 20 9 13 46 73 56 19 37 32 40 42 79 76 96 5 6 8 76 52 14 86 33 69 100 95 58 87 43 47 17 39 48 28 77 65 100 100 41 39 87 5 61 67 94 64 61 88 32 23 79 44 0 67 44 23 48 96 48 56 86 75 90 2 17 46 4 75 42 90 17 77 5 33 87 91 27 28 58 95 58 47 33 6\r\n", "output": "NO\r\n"}, {"input": "21\r\n11 10 12 3 6 0 8 6 16 14 5 9 7 19 1 13 15 21 4 2 20\r\n", "output": "YES\r\n21\r\n18\r\n2\r\n20\r\n14\r\n10\r\n4\r\n19\r\n12\r\n3\r\n16\r\n9\r\n7\r\n13\r\n6\r\n8\r\n11\r\n5\r\n15\r\n17\r\n1\r\n"}, {"input": "61\r\n10 42 20 50 4 24 18 55 19 5 57 13 3 35 58 48 31 46 40 45 15 53 14 25 43 41 22 23 54 39 38 44 16 37 12 34 32 28 26 30 59 47 21 9 8 52 1 0 33 49 36 51 17 11 29 7 48 61 6 27 2\r\n", "output": "YES\r\n27\r\n60\r\n53\r\n22\r\n31\r\n17\r\n28\r\n38\r\n14\r\n23\r\n12\r\n35\r\n3\r\n13\r\n45\r\n20\r\n55\r\n8\r\n54\r\n29\r\n57\r\n11\r\n16\r\n48\r\n49\r\n33\r\n4\r\n50\r\n10\r\n5\r\n7\r\n56\r\n46\r\n18\r\n51\r\n52\r\n34\r\n36\r\n32\r\n37\r\n9\r\n44\r\n40\r\n19\r\n39\r\n30\r\n41\r\n26\r\n6\r\n59\r\n25\r\n24\r\n21\r\n43\r\n58\r\n15\r\n2\r\n61\r\n47\r\n42\r\n1\r\n"}, {"input": "21\r\n11 19 4 19 6 0 13 7 6 2 5 3 16 10 1 9 15 21 9 21 2\r\n", "output": "YES\r\n7\r\n8\r\n16\r\n13\r\n10\r\n14\r\n2\r\n21\r\n18\r\n20\r\n3\r\n12\r\n19\r\n4\r\n6\r\n9\r\n11\r\n5\r\n15\r\n17\r\n1\r\n"}, {"input": "61\r\n47 61 20 5 10 59 46 55 44 1 57 13 3 35 21 48 31 7 9 45 43 53 14 6 42 39 22 23 54 40 45 37 16 36 12 44 34 28 25 19 26 33 25 39 33 36 42 0 50 4 52 46 17 11 29 7 48 15 41 27 58\r\n", "output": "YES\r\n6\r\n24\r\n41\r\n59\r\n40\r\n30\r\n9\r\n19\r\n37\r\n32\r\n52\r\n51\r\n46\r\n7\r\n18\r\n56\r\n36\r\n34\r\n61\r\n2\r\n15\r\n58\r\n43\r\n21\r\n25\r\n39\r\n26\r\n44\r\n55\r\n8\r\n54\r\n29\r\n57\r\n11\r\n16\r\n48\r\n28\r\n38\r\n14\r\n23\r\n12\r\n35\r\n3\r\n13\r\n27\r\n60\r\n53\r\n22\r\n31\r\n17\r\n45\r\n20\r\n42\r\n33\r\n50\r\n49\r\n5\r\n4\r\n1\r\n47\r\n10\r\n"}, {"input": "79\r\n0 56 56 42 56 56 56 56 4 56 56 22 56 56 56 48 56 56 56 56 56 24 56 16 56 56 56 9 56 56 56 56 56 56 56 56 56 55 56 56 12 20 56 28 56 56 56 38 56 56 56 56 56 56 44 1 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56\r\n", "output": "YES\r\n12\r\n41\r\n24\r\n22\r\n48\r\n16\r\n55\r\n38\r\n28\r\n44\r\n4\r\n9\r\n20\r\n42\r\n56\r\n2\r\n3\r\n5\r\n6\r\n7\r\n8\r\n10\r\n11\r\n13\r\n14\r\n15\r\n17\r\n18\r\n19\r\n21\r\n23\r\n25\r\n26\r\n27\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n39\r\n40\r\n43\r\n45\r\n46\r\n47\r\n49\r\n50\r\n51\r\n52\r\n53\r\n54\r\n57\r\n58\r\n59\r\n60\r\n61\r\n62\r\n63\r\n64\r\n65\r\n66\r\n67\r\n68\r\n69\r\n70\r\n71\r\n72\r\n73\r\n74\r\n75\r\n76\r\n77\r\n78\r\n79\r\n1\r\n"}, {"input": "121\r\n110 31 57 33 45 33 33 33 91 102 79 33 61 72 107 101 117 10 118 33 33 64 24 94 117 76 33 23 33 49 5 52 95 78 33 39 33 92 17 33 25 33 56 33 3 88 33 108 62 15 28 111 67 33 33 11 96 33 36 70 46 98 80 104 33 19 60 33 112 51 33 2 33 33 121 59 33 41 50 81 105 33 115 34 33 18 84 32 33 33 87 13 86 103 16 119 33 63 30 43 83 53 26 100 69 33 14 38 33 75 66 120 33 33 9 99 0 93 1 48 116\r\n", "output": "YES\r\n33\r\n4\r\n6\r\n7\r\n8\r\n12\r\n20\r\n21\r\n27\r\n29\r\n35\r\n37\r\n40\r\n42\r\n44\r\n47\r\n54\r\n55\r\n58\r\n65\r\n68\r\n71\r\n73\r\n74\r\n77\r\n82\r\n85\r\n89\r\n90\r\n97\r\n106\r\n109\r\n113\r\n114\r\n16\r\n95\r\n83\r\n101\r\n9\r\n115\r\n87\r\n91\r\n34\r\n84\r\n41\r\n78\r\n117\r\n25\r\n39\r\n17\r\n59\r\n36\r\n26\r\n76\r\n94\r\n103\r\n23\r\n24\r\n51\r\n28\r\n60\r\n70\r\n53\r\n67\r\n10\r\n102\r\n86\r\n18\r\n118\r\n93\r\n66\r\n19\r\n52\r\n111\r\n88\r\n32\r\n61\r\n46\r\n92\r\n13\r\n108\r\n38\r\n120\r\n48\r\n69\r\n112\r\n81\r\n105\r\n63\r\n80\r\n62\r\n98\r\n30\r\n49\r\n116\r\n99\r\n75\r\n121\r\n64\r\n22\r\n100\r\n104\r\n56\r\n43\r\n79\r\n11\r\n15\r\n50\r\n14\r\n107\r\n2\r\n72\r\n5\r\n31\r\n3\r\n45\r\n96\r\n57\r\n1\r\n110\r\n119\r\n"}, {"input": "21\r\n5 20 9 19 8 0 13 6 13 19 5 3 8 10 1 9 1 20 3 10 18\r\n", "output": "YES\r\n18\r\n21\r\n20\r\n2\r\n10\r\n14\r\n19\r\n4\r\n3\r\n12\r\n9\r\n16\r\n13\r\n7\r\n8\r\n6\r\n5\r\n11\r\n1\r\n15\r\n17\r\n"}, {"input": "61\r\n5 61 20 5 50 59 56 29 44 1 48 13 20 35 61 33 38 52 30 8 43 17 35 43 24 59 22 23 11 26 38 37 48 36 13 37 44 23 30 19 26 1 15 19 8 18 42 0 50 33 52 36 17 11 29 18 48 15 24 22 42\r\n", "output": "YES\r\n56\r\n7\r\n18\r\n46\r\n52\r\n51\r\n36\r\n34\r\n37\r\n32\r\n44\r\n9\r\n19\r\n40\r\n30\r\n39\r\n26\r\n41\r\n59\r\n6\r\n24\r\n25\r\n43\r\n21\r\n15\r\n58\r\n61\r\n2\r\n42\r\n47\r\n1\r\n5\r\n4\r\n50\r\n49\r\n33\r\n16\r\n48\r\n11\r\n29\r\n8\r\n20\r\n3\r\n13\r\n12\r\n35\r\n14\r\n23\r\n28\r\n38\r\n17\r\n22\r\n27\r\n60\r\n53\r\n31\r\n45\r\n55\r\n54\r\n57\r\n10\r\n"}, {"input": "21\r\n18 18 18 18 18 0 18 18 18 18 18 18 18 18 18 18 18 6 18 18 18\r\n", "output": "YES\r\n18\r\n2\r\n3\r\n4\r\n5\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n6\r\n19\r\n20\r\n21\r\n1\r\n"}, {"input": "61\r\n56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 0 56 56 56 56 56 56 56 48 56 56 56 56 56\r\n", "output": "YES\r\n56\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38\r\n39\r\n40\r\n41\r\n42\r\n43\r\n44\r\n45\r\n46\r\n47\r\n49\r\n50\r\n51\r\n52\r\n53\r\n54\r\n55\r\n48\r\n57\r\n58\r\n59\r\n60\r\n61\r\n1\r\n"}, {"input": "21\r\n15 6 13 7 15 21 8 0 7 16 16 21 12 6 12 12 13 6 15 16 7\r\n", "output": "YES\r\n6\r\n2\r\n14\r\n18\r\n7\r\n4\r\n8\r\n9\r\n16\r\n10\r\n11\r\n20\r\n15\r\n5\r\n12\r\n21\r\n13\r\n3\r\n17\r\n19\r\n1\r\n"}, {"input": "61\r\n58 39 45 57 31 43 11 24 8 18 56 54 47 37 50 40 19 16 29 10 1 23 36 28 21 48 52 55 27 42 2 33 46 25 53 6 15 26 14 17 9 44 56 34 5 61 38 12 30 7 49 32 20 41 51 0 3 4 60 35 13\r\n", "output": "YES\r\n23\r\n22\r\n6\r\n36\r\n56\r\n43\r\n7\r\n11\r\n15\r\n50\r\n14\r\n37\r\n2\r\n39\r\n5\r\n31\r\n3\r\n45\r\n4\r\n57\r\n60\r\n59\r\n53\r\n35\r\n10\r\n20\r\n16\r\n18\r\n17\r\n40\r\n29\r\n19\r\n52\r\n27\r\n33\r\n32\r\n61\r\n46\r\n47\r\n13\r\n26\r\n38\r\n12\r\n48\r\n41\r\n54\r\n8\r\n9\r\n28\r\n24\r\n51\r\n55\r\n30\r\n49\r\n44\r\n42\r\n25\r\n34\r\n1\r\n58\r\n21\r\n"}, {"input": "21\r\n21 6 4 20 14 1 13 10 11 0 10 18 10 12 4 1 2 2 8 2 13\r\n", "output": "YES\r\n8\r\n19\r\n11\r\n9\r\n21\r\n13\r\n7\r\n10\r\n14\r\n5\r\n18\r\n12\r\n20\r\n4\r\n3\r\n15\r\n2\r\n17\r\n1\r\n6\r\n16\r\n"}, {"input": "61\r\n17 19 8 53 10 38 59 60 46 25 49 28 46 15 25 56 53 60 60 54 18 49 10 53 29 19 11 61 24 11 17 52 32 54 29 55 0 1 14 56 25 14 33 53 47 56 8 6 53 55 16 46 47 9 24 37 3 52 25 37 26\r\n", "output": "YES\r\n15\r\n14\r\n39\r\n42\r\n59\r\n7\r\n3\r\n57\r\n18\r\n21\r\n28\r\n12\r\n26\r\n61\r\n19\r\n2\r\n16\r\n51\r\n9\r\n54\r\n20\r\n34\r\n33\r\n43\r\n37\r\n56\r\n40\r\n46\r\n13\r\n52\r\n32\r\n58\r\n8\r\n60\r\n47\r\n45\r\n6\r\n48\r\n1\r\n17\r\n53\r\n4\r\n24\r\n29\r\n25\r\n10\r\n5\r\n23\r\n41\r\n35\r\n55\r\n36\r\n50\r\n44\r\n49\r\n11\r\n27\r\n30\r\n22\r\n31\r\n38\r\n"}, {"input": "21\r\n18 0 18 2 21 2 9 15 3 5 8 2 8 21 6 10 21 13 9 1 13\r\n", "output": "YES\r\n3\r\n9\r\n7\r\n19\r\n6\r\n2\r\n4\r\n12\r\n10\r\n16\r\n21\r\n5\r\n14\r\n17\r\n13\r\n8\r\n15\r\n11\r\n1\r\n18\r\n20\r\n"}, {"input": "61\r\n45 48 30 23 15 47 8 3 35 56 54 35 17 47 35 56 32 42 14 37 36 44 6 44 1 44 41 46 43 0 33 3 44 54 43 3 47 57 7 32 29 60 36 36 43 61 36 47 3 48 18 8 17 29 3 54 3 6 43 43 56\r\n", "output": "YES\r\n41\r\n27\r\n46\r\n28\r\n56\r\n10\r\n16\r\n61\r\n29\r\n54\r\n11\r\n34\r\n15\r\n5\r\n7\r\n39\r\n8\r\n52\r\n57\r\n38\r\n33\r\n31\r\n44\r\n22\r\n24\r\n26\r\n23\r\n4\r\n6\r\n58\r\n14\r\n19\r\n37\r\n20\r\n47\r\n48\r\n2\r\n50\r\n18\r\n51\r\n60\r\n42\r\n43\r\n35\r\n9\r\n12\r\n36\r\n21\r\n3\r\n30\r\n32\r\n17\r\n13\r\n53\r\n40\r\n49\r\n55\r\n59\r\n1\r\n45\r\n25\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: n = int(f.readline()) p = list(map(int, f.readline().split())) # Read reference output with open(output_path) as f_ref: ref_first_line = f_ref.readline().strip() # Read submission output with open(submission_path) as f_sub: lines = [line.strip() for line in f_sub.readlines()] # Check first line if not lines: print(0) return submission_first = lines[0] if submission_first != ref_first_line: print(0) return if ref_first_line == "NO": if len(lines) != 1: print(0) return else: print(1) return # Check YES case if len(lines) != n + 1: print(0) return sequence = lines[1:] if len(sequence) != n: print(0) return try: sequence = list(map(int, sequence)) except: print(0) return if any(x < 1 or x > n for x in sequence): print(0) return if len(set(sequence)) != n: print(0) return # Build adjacency list adj = [[] for _ in range(n + 1)] for i in range(1, n + 1): pi = p[i - 1] if pi != 0: adj[i].append(pi) adj[pi].append(i) current_degree = [0] * (n + 1) for i in range(1, n + 1): current_degree[i] = len(adj[i]) alive = [True] * (n + 1) # Simulate destruction for node in sequence: if not alive[node]: print(0) return if current_degree[node] % 2 != 0: print(0) return for neighbor in adj[node]: if alive[neighbor]: current_degree[neighbor] -= 1 alive[node] = False current_degree[node] = 0 if all(not alive[i] for i in range(1, n + 1)): print(1) else: print(0) if __name__ == "__main__": main()
true
372/A
372
A
Python 3
TESTS
11
763
19,353,600
88756366
from math import * from collections import * from random import * from decimal import Decimal from bisect import * import sys input=sys.stdin.readline def lis(): return list(map(int,input().split())) def ma(): return map(int,input().split()) def inp(): return int(input()) def fk(a,s,k): b=[] for i in range(len(a)): b.append(a[i]+(i+1)*k) b.sort() return sum(b[:k]) n=inp() r=[] for i in range(n): x=inp() r.append(x) r.sort() co=0 for i in range(n//2): if(r[i]*2<=r[-1]): co+=1 continue break print(n-(2*co)+co)
45
249
15,872,000
180536162
import sys input = sys.stdin.readline n = int(input()) q = sorted([int(input()) for _ in range(n)]) c = 0 i = (n-1)//2 j = n-1 while i >= 0: if q[i]*2 <= q[j]: i -= 1 j -= 1 c += 1 else: i -= 1 print(n-min(c, n//2))
Codeforces Round 219 (Div. 1)
CF
2,013
1
256
Counting Kangaroos is Fun
There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible.
The first line contains a single integer — n (1 ≤ n ≤ 5·105). Each of the next n lines contains an integer si — the size of the i-th kangaroo (1 ≤ si ≤ 105).
Output a single integer — the optimal number of visible kangaroos.
null
null
[{"input": "8\n2\n5\n7\n6\n9\n8\n4\n2", "output": "5"}, {"input": "8\n9\n1\n6\n2\n6\n5\n8\n3", "output": "5"}]
1,600
["binary search", "greedy", "sortings", "two pointers"]
45
[{"input": "8\r\n2\r\n5\r\n7\r\n6\r\n9\r\n8\r\n4\r\n2\r\n", "output": "5\r\n"}, {"input": "8\r\n9\r\n1\r\n6\r\n2\r\n6\r\n5\r\n8\r\n3\r\n", "output": "5\r\n"}, {"input": "12\r\n3\r\n99\r\n24\r\n46\r\n75\r\n63\r\n57\r\n55\r\n10\r\n62\r\n34\r\n52\r\n", "output": "7\r\n"}, {"input": "12\r\n55\r\n75\r\n1\r\n98\r\n63\r\n64\r\n9\r\n39\r\n82\r\n18\r\n47\r\n9\r\n", "output": "6\r\n"}, {"input": "100\r\n678\r\n771\r\n96\r\n282\r\n135\r\n749\r\n168\r\n668\r\n17\r\n658\r\n979\r\n446\r\n998\r\n331\r\n606\r\n756\r\n37\r\n515\r\n538\r\n205\r\n647\r\n547\r\n904\r\n842\r\n647\r\n286\r\n774\r\n414\r\n267\r\n791\r\n595\r\n465\r\n8\r\n327\r\n855\r\n174\r\n339\r\n946\r\n184\r\n250\r\n807\r\n422\r\n679\r\n980\r\n64\r\n530\r\n312\r\n351\r\n676\r\n911\r\n803\r\n991\r\n669\r\n50\r\n293\r\n841\r\n545\r\n598\r\n737\r\n894\r\n231\r\n754\r\n588\r\n83\r\n873\r\n767\r\n833\r\n482\r\n905\r\n903\r\n970\r\n571\r\n715\r\n59\r\n777\r\n697\r\n537\r\n861\r\n339\r\n212\r\n149\r\n889\r\n905\r\n70\r\n970\r\n307\r\n830\r\n465\r\n968\r\n291\r\n430\r\n317\r\n942\r\n944\r\n330\r\n235\r\n814\r\n880\r\n415\r\n76\r\n", "output": "58\r\n"}, {"input": "100\r\n154\r\n60\r\n97\r\n638\r\n139\r\n150\r\n570\r\n579\r\n601\r\n647\r\n804\r\n237\r\n245\r\n549\r\n288\r\n347\r\n778\r\n282\r\n916\r\n441\r\n974\r\n145\r\n957\r\n886\r\n655\r\n702\r\n930\r\n618\r\n132\r\n520\r\n972\r\n48\r\n94\r\n54\r\n682\r\n433\r\n896\r\n134\r\n845\r\n636\r\n242\r\n842\r\n125\r\n141\r\n240\r\n130\r\n409\r\n666\r\n948\r\n938\r\n604\r\n110\r\n474\r\n484\r\n364\r\n40\r\n807\r\n271\r\n438\r\n288\r\n201\r\n814\r\n754\r\n589\r\n341\r\n576\r\n146\r\n952\r\n819\r\n923\r\n222\r\n535\r\n336\r\n83\r\n314\r\n911\r\n303\r\n911\r\n384\r\n601\r\n249\r\n330\r\n735\r\n271\r\n142\r\n204\r\n405\r\n783\r\n775\r\n449\r\n590\r\n139\r\n109\r\n276\r\n45\r\n205\r\n454\r\n836\r\n82\r\n841\r\n", "output": "50\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "4\r\n1\r\n1\r\n1\r\n2\r\n", "output": "3\r\n"}, {"input": "5\r\n1\r\n2\r\n4\r\n8\r\n16\r\n", "output": "3\r\n"}, {"input": "7\r\n1\r\n2\r\n4\r\n8\r\n16\r\n32\r\n64\r\n", "output": "4\r\n"}, {"input": "3\r\n1\r\n2\r\n4\r\n", "output": "2\r\n"}]
false
stdio
null
true
374/B
374
B
Python 3
TESTS
5
124
4,812,800
23931065
a = input() ans = 1 lst = 0 for i in range(1, len(a)): sm = int(a[i]) + int(a[i - 1]) if sm != 9: if lst > 0 and lst % 2 == 0: ans *= 2 lst = 0 else: lst += 1 if lst > 0 and lst % 2 == 0: ans *= 2 print(ans)
25
124
6,963,200
127492936
s,a,c=input(),1,1 for i in range(1,len(s)): if int(s[i])+int(s[i-1])==9: c+=1 elif c%2: a*=c//2+1 c=1 else: c=1 if(c%2): a*=c//2+1 print(a)
Codeforces Round 220 (Div. 2)
CF
2,013
1
256
Inna and Nine
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9. Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9. For instance, Inna can alter number 14545181 like this: 14545181 → 1945181 → 194519 → 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine. Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes.
In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 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
Notes to the samples In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979. In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.
[{"input": "369727", "output": "2"}, {"input": "123456789987654321", "output": "1"}, {"input": "1", "output": "1"}]
1,500
["combinatorics", "greedy"]
25
[{"input": "369727\r\n", "output": "2\r\n"}, {"input": "123456789987654321\r\n", "output": "1\r\n"}, {"input": "1\r\n", "output": "1\r\n"}, {"input": "3636363636363454545454543636363636454545452727272727218181818181999111777\r\n", "output": "1512\r\n"}, {"input": "1188\r\n", "output": "1\r\n"}, {"input": "121212912121291299129191219\r\n", "output": "1\r\n"}, {"input": "181818918181891918918181918189181818181891818191818191819189\r\n", "output": "54\r\n"}, {"input": "12191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219\r\n", "output": "1\r\n"}, {"input": "444444444444445444444444454444444444444444444444445544444444444444444444444444444444444444444554444444444444444444444444444444444444445454444444444444444444444444444444444444454444444444444444444444444444444444445444444444444444444444444444444444444444444445444444444444444444444444444444444456666666666666666666663555555555555555888888888882333333312567312389542179415242164512341234213443123412341293412341234123412746129342154796124123459123491238471234213451692341278451234125934\r\n", "output": "96\r\n"}, {"input": "123456789\r\n", "output": "1\r\n"}, {"input": "3639272918194549\r\n", "output": "16\r\n"}, {"input": "1121314151617181921222324252627282931323334353637383941424344454647484951525354556575859616263646566768697172737475767787981828384858687888991929394959696979899\r\n", "output": "256\r\n"}, {"input": "14545181\r\n", "output": "2\r\n"}, {"input": "272727272\r\n", "output": "5\r\n"}, {"input": "1212121217272727121\r\n", "output": "4\r\n"}, {"input": "1212172727\r\n", "output": "3\r\n"}, {"input": "181817272727\r\n", "output": "12\r\n"}]
false
stdio
null
true
374/B
374
B
Python 3
TESTS
5
77
204,800
195377951
n = str(input()) contador = 0 res = 1 anterior = int(n[0]) for num in n: inum = int(num) if inum + anterior == 9: contador += 1 elif contador != 0: if contador % 2 == 0: res *= 2 contador = 0 anterior = inum if contador != 0: if contador % 2 == 0: res *= 2 print(res)
24
140
0
5463471
s=input() ans=0 i=1 past=int(s[0]) c=1 ans=1 while(i<len(s)): if(int(s[i])+past==9): c+=1 past=int(s[i]) else: if(c%2==1 and c!=1): ans*=(c//2+1) c=1 past=int(s[i]) i+=1 if(c!=1 and c%2==1): ans*=(c//2+1) print(ans)
Codeforces Round 220 (Div. 2)
CF
2,013
1
256
Inna and Nine
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9. Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9. For instance, Inna can alter number 14545181 like this: 14545181 → 1945181 → 194519 → 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine. Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes.
In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 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
Notes to the samples In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979. In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.
[{"input": "369727", "output": "2"}, {"input": "123456789987654321", "output": "1"}, {"input": "1", "output": "1"}]
1,500
["combinatorics", "greedy"]
25
[{"input": "369727\r\n", "output": "2\r\n"}, {"input": "123456789987654321\r\n", "output": "1\r\n"}, {"input": "1\r\n", "output": "1\r\n"}, {"input": "3636363636363454545454543636363636454545452727272727218181818181999111777\r\n", "output": "1512\r\n"}, {"input": "1188\r\n", "output": "1\r\n"}, {"input": "121212912121291299129191219\r\n", "output": "1\r\n"}, {"input": "181818918181891918918181918189181818181891818191818191819189\r\n", "output": "54\r\n"}, {"input": "12191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219\r\n", "output": "1\r\n"}, {"input": "444444444444445444444444454444444444444444444444445544444444444444444444444444444444444444444554444444444444444444444444444444444444445454444444444444444444444444444444444444454444444444444444444444444444444444445444444444444444444444444444444444444444444445444444444444444444444444444444444456666666666666666666663555555555555555888888888882333333312567312389542179415242164512341234213443123412341293412341234123412746129342154796124123459123491238471234213451692341278451234125934\r\n", "output": "96\r\n"}, {"input": "123456789\r\n", "output": "1\r\n"}, {"input": "3639272918194549\r\n", "output": "16\r\n"}, {"input": "1121314151617181921222324252627282931323334353637383941424344454647484951525354556575859616263646566768697172737475767787981828384858687888991929394959696979899\r\n", "output": "256\r\n"}, {"input": "14545181\r\n", "output": "2\r\n"}, {"input": "272727272\r\n", "output": "5\r\n"}, {"input": "1212121217272727121\r\n", "output": "4\r\n"}, {"input": "1212172727\r\n", "output": "3\r\n"}, {"input": "181817272727\r\n", "output": "12\r\n"}]
false
stdio
null
true
374/B
374
B
Python 3
TESTS
5
93
0
5660029
t = input() s = d = 0 p = {str(i): str(9 - i) for i in range(10)} for i in range(len(t) - 1): if p[t[i]] == t[i + 1]: s += 1 else: if s % 2 == 0: d += s s = 0 if s % 2 == 0: d += s print(1 << (d // 2))
25
155
1,433,600
47807615
s = input() nine = [] num = 0 ans = 1 for i in range(1, len(s)): if int(s[i - 1]) + int(s[i]) == 9: num += 1 else: if num > 0: nine.append(num + 1) num = 0 if num != 0: nine.append(num + 1) for i in range(len(nine)): x= nine[i] if x % 2 != 0: ans = ans * (int((x + 1)/2)) print(ans)
Codeforces Round 220 (Div. 2)
CF
2,013
1
256
Inna and Nine
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9. Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9. For instance, Inna can alter number 14545181 like this: 14545181 → 1945181 → 194519 → 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine. Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes.
In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 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
Notes to the samples In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979. In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.
[{"input": "369727", "output": "2"}, {"input": "123456789987654321", "output": "1"}, {"input": "1", "output": "1"}]
1,500
["combinatorics", "greedy"]
25
[{"input": "369727\r\n", "output": "2\r\n"}, {"input": "123456789987654321\r\n", "output": "1\r\n"}, {"input": "1\r\n", "output": "1\r\n"}, {"input": "3636363636363454545454543636363636454545452727272727218181818181999111777\r\n", "output": "1512\r\n"}, {"input": "1188\r\n", "output": "1\r\n"}, {"input": "121212912121291299129191219\r\n", "output": "1\r\n"}, {"input": "181818918181891918918181918189181818181891818191818191819189\r\n", "output": "54\r\n"}, {"input": "12191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219\r\n", "output": "1\r\n"}, {"input": "444444444444445444444444454444444444444444444444445544444444444444444444444444444444444444444554444444444444444444444444444444444444445454444444444444444444444444444444444444454444444444444444444444444444444444445444444444444444444444444444444444444444444445444444444444444444444444444444444456666666666666666666663555555555555555888888888882333333312567312389542179415242164512341234213443123412341293412341234123412746129342154796124123459123491238471234213451692341278451234125934\r\n", "output": "96\r\n"}, {"input": "123456789\r\n", "output": "1\r\n"}, {"input": "3639272918194549\r\n", "output": "16\r\n"}, {"input": "1121314151617181921222324252627282931323334353637383941424344454647484951525354556575859616263646566768697172737475767787981828384858687888991929394959696979899\r\n", "output": "256\r\n"}, {"input": "14545181\r\n", "output": "2\r\n"}, {"input": "272727272\r\n", "output": "5\r\n"}, {"input": "1212121217272727121\r\n", "output": "4\r\n"}, {"input": "1212172727\r\n", "output": "3\r\n"}, {"input": "181817272727\r\n", "output": "12\r\n"}]
false
stdio
null
true
629/B
629
B
Python 3
TESTS
8
155
307,200
16260223
n = (int)(input()) F1=[0]*n F2=[0]*n M1=[0]*n M2=[0]*n m=0 f=0 for i in range(n): c = (input().split()) if(c[0]=='M'): M1[m]=(int)(c[1]) M2[m]=(int)(c[2]) m=m+1 if(c[0]=='F'): F1[f]=(int)(c[1]) F2[f]=(int)(c[2]) f=f+1 F=[0]*3232 M=[0]*3266 for i in range(f): for j in range(F1[i], F2[i]+1): F[j]=F[j]+1 for i in range(m): for j in range(M1[i],M2[i]+1): M[j]=M[j]+1 max=0 for j in range(366): if((F[j]>max)and(M[j]>max)): max=F[j] if(max>M[j]): max=M[j] print(max*2)
76
62
0
16238652
n = int(input()) females = [0] * 366 males = [0] * 366 for _ in range(n): p, start, end = input().split() start = int(start) - 1 end = int(end) # end == 366 if p == "F": females[start] += 1 if end < 366: females[end] -= 1 elif p == "M": males[start] += 1 if end < 366: males[end] -= 1 cur_m_count = 0 cur_f_count = 0 max_count = 0 for day in range(366): cur_m_count += males[day] cur_f_count += females[day] max_count = max(max_count, 2*min(cur_f_count, cur_m_count)) print(max_count)
Codeforces Round 343 (Div. 2)
CF
2,016
2
256
Far Relative’s Problem
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≤ ai ≤ bi ≤ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive.
Print the maximum number of people that may come to Famil Door's party.
null
In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
[{"input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128", "output": "2"}, {"input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200", "output": "4"}]
1,100
["brute force"]
76
[{"input": "4\r\nM 151 307\r\nF 343 352\r\nF 117 145\r\nM 24 128\r\n", "output": "2\r\n"}, {"input": "6\r\nM 128 130\r\nF 128 131\r\nF 131 140\r\nF 131 141\r\nM 131 200\r\nM 140 200\r\n", "output": "4\r\n"}, {"input": "1\r\nF 68 307\r\n", "output": "0\r\n"}, {"input": "40\r\nM 55 363\r\nF 117 252\r\nM 157 282\r\nF 322 345\r\nM 330 363\r\nF 154 231\r\nF 216 352\r\nF 357 365\r\nM 279 292\r\nF 353 359\r\nF 82 183\r\nM 78 297\r\nM 231 314\r\nM 107 264\r\nF 34 318\r\nM 44 244\r\nF 42 339\r\nM 253 307\r\nM 128 192\r\nF 119 328\r\nM 135 249\r\nF 303 358\r\nF 348 352\r\nF 8 364\r\nF 126 303\r\nM 226 346\r\nF 110 300\r\nF 47 303\r\nF 201 311\r\nF 287 288\r\nM 270 352\r\nM 227 351\r\nF 8 111\r\nF 39 229\r\nM 163 315\r\nF 269 335\r\nF 147 351\r\nF 96 143\r\nM 97 99\r\nM 177 295\r\n", "output": "22\r\n"}, {"input": "2\r\nF 1 1\r\nM 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\nM 1 2\r\nM 2 3\r\nF 3 4\r\nF 4 5\r\n", "output": "2\r\n"}, {"input": "1\r\nF 1 2\r\n", "output": "0\r\n"}, {"input": "18\r\nF 3 4\r\nF 3 4\r\nF 3 4\r\nF 3 4\r\nF 5 6\r\nF 5 6\r\nM 3 4\r\nM 3 4\r\nM 5 6\r\nM 5 6\r\nM 5 6\r\nM 5 6\r\nF 7 8\r\nF 7 8\r\nF 7 8\r\nM 7 8\r\nM 7 8\r\nM 7 8\r\n", "output": "6\r\n"}, {"input": "2\r\nM 1 1\r\nF 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\nM 1 1\r\nF 1 1\r\nM 1 1\r\n", "output": "2\r\n"}]
false
stdio
null
true
847/A
847
A
Python 3
TESTS
7
109
0
43998625
n = int(input()) unit = [] for i in range(1,n+1): [l, r] = map(int, input().split()) find = -1 arrow = -1 for j in range(len(unit)): if r != 0 and ((unit[j][0] == r) or (i == unit[j][0] and r == unit[j][1])): find = j if unit[j][0] == r: arrow = 0 if i == unit[j][0] and r == unit[j][1]: arrow = 1 if l != 0 and ((unit[j][-1] == l) or (i == unit[j][-1] and l == unit[j][-2])): find = j if unit[j][-1] == l and arrow != 1: arrow = 2 if i == unit[j][-1] and l == unit[j][-2]: arrow = 3 if find != -1: break if find == -1: unit.append([l, i, r]) else: if arrow == 0: unit[find] = [l, i] + unit[find] elif arrow == 1: unit[find] = [l] + unit[find] elif arrow == 2: unit[find] = unit[find] + [i, r] else: unit[find] = unit[find] + [r] result = [] result += unit[0] for i in range(1, len(unit)): if result[-1] == 0: result.pop() if unit[i][0] == 0: result += unit[i][1:] else: result += unit[i] for i in range(1, n+1): k = result.index(i) p = len(result) print(result[(k-1+p) % p], result[(k+1+p)%p])
23
62
0
191773329
n = int(input().strip()) l = [0] * (n + 1) r = [0] * (n + 1) q = [] for i in range(1, n + 1): l[i], r[i] = map(int, input().split()) if not l[i]: q.append(i) mark = True ne = None while q: now = q.pop(0) if not mark: l[now] = ne r[ne] = now mark = False ne = now while r[ne]: ne = r[ne] for i in range(1, n + 1): print(l[i], r[i])
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
2
256
Union of Doubly Linked Lists
Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e. each element except the first has exactly one previous element, each element except the last has exactly one next element. The list is not closed in a cycle. In this problem you are given n memory cells forming one or more doubly linked lists. Each cell contains information about element from some list. Memory cells are numbered from 1 to n. For each cell i you are given two values: - li — cell containing previous element for the element in the cell i; - ri — cell containing next element for the element in the cell i. If cell i contains information about the element which has no previous element then li = 0. Similarly, if cell i contains information about the element which has no next element then ri = 0. Three lists are shown on the picture. For example, for the picture above the values of l and r are the following: l1 = 4, r1 = 7; l2 = 5, r2 = 0; l3 = 0, r3 = 0; l4 = 6, r4 = 1; l5 = 0, r5 = 2; l6 = 0, r6 = 4; l7 = 1, r7 = 0. Your task is to unite all given lists in a single list, joining them to each other in any order. In particular, if the input data already contains a single list, then there is no need to perform any actions. Print the resulting list in the form of values li, ri. Any other action, other than joining the beginning of one list to the end of another, can not be performed.
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of memory cells where the doubly linked lists are located. Each of the following n lines contains two integers li, ri (0 ≤ li, ri ≤ n) — the cells of the previous and the next element of list for cell i. Value li = 0 if element in cell i has no previous element in its list. Value ri = 0 if element in cell i has no next element in its list. It is guaranteed that the input contains the correct description of a single or more doubly linked lists. All lists have linear structure: each element of list except the first has exactly one previous element; each element of list except the last has exactly one next element. Each memory cell contains information about one element from some list, each element of each list written in one of n given cells.
Print n lines, the i-th line must contain two integers li and ri — the cells of the previous and the next element of list for cell i after all lists from the input are united in a single list. If there are many solutions print any of them.
null
null
[{"input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0", "output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0"}]
1,500
["implementation"]
23
[{"input": "7\r\n4 7\r\n5 0\r\n0 0\r\n6 1\r\n0 2\r\n0 4\r\n1 0\r\n", "output": "4 7\r\n5 6\r\n0 5\r\n6 1\r\n3 2\r\n2 4\r\n1 0\r\n"}, {"input": "2\r\n2 0\r\n0 1\r\n", "output": "2 0\r\n0 1\r\n"}, {"input": "1\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "4\r\n0 2\r\n1 0\r\n0 4\r\n3 0\r\n", "output": "0 2\r\n1 3\r\n2 4\r\n3 0\r\n"}, {"input": "5\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\r\n1 3\r\n2 4\r\n3 5\r\n4 0\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "0 2\r\n1 0\r\n"}, {"input": "2\r\n0 2\r\n1 0\r\n", "output": "0 2\r\n1 0\r\n"}, {"input": "5\r\n5 3\r\n4 0\r\n1 4\r\n3 2\r\n0 1\r\n", "output": "5 3\r\n4 0\r\n1 4\r\n3 2\r\n0 1\r\n"}, {"input": "5\r\n2 0\r\n0 1\r\n0 4\r\n3 5\r\n4 0\r\n", "output": "2 3\r\n0 1\r\n1 4\r\n3 5\r\n4 0\r\n"}, {"input": "5\r\n3 4\r\n0 0\r\n0 1\r\n1 0\r\n0 0\r\n", "output": "3 4\r\n0 3\r\n2 1\r\n1 5\r\n4 0\r\n"}, {"input": "5\r\n3 0\r\n0 0\r\n0 1\r\n0 0\r\n0 0\r\n", "output": "3 4\r\n0 3\r\n2 1\r\n1 5\r\n4 0\r\n"}, {"input": "10\r\n7 5\r\n5 0\r\n4 7\r\n10 3\r\n1 2\r\n0 9\r\n3 1\r\n9 10\r\n6 8\r\n8 4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n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 4\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\n1 3\n2 5\n97 98\n3 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 29\n29 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22\n21 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 30\n12 13\n28 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 51\n50 52\n51 53\n52 54\n53 55\n54 56\n55 57\n56 58\n57 59\n58 60\n59 61\n60 62\n61 63\n62 64\n63 65\n64 66\n65 67\n66 68\n67 69\n68 70\n69 71\n70 72\n71 73\n72 74\n73 75\n74 76\n75 77\n76 78\n77 79\n78 80\n79 81\n80 82\n81 83\n82 84\n83 85\n84 86\n85 87\n86 88\n87 89\n88 90\n89 91\n90 92\n91 93\n92 94\n93 95\n94 96\n95 97\n96 4\n4 99\n98 100\n99 0\n"}, {"input": "100\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 80\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n21 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 80\n80 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 29\n28 30\n29 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 51\n50 52\n51 53\n52 54\n53 55\n54 56\n55 57\n56 58\n57 59\n58 60\n59 61\n60 62\n61 63\n62 64\n63 65\n64 66\n65 67\n66 68\n67 69\n68 70\n69 71\n70 72\n71 73\n72 74\n73 75\n74 76\n75 77\n76 78\n77 79\n78 81\n21 22\n79 82\n81 83\n82 84\n83 85\n84 86\n85 87\n86 88\n87 89\n88 90\n89 91\n90 92\n91 93\n92 94\n93 95\n94 96\n95 97\n96 98\n97 99\n98 100\n99 0\n"}, {"input": "100\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22\n21 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 29\n28 30\n29 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 51\n50 52\n51 53\n52 54\n53 55\n54 56\n55 57\n56 58\n57 59\n58 60\n59 61\n60 62\n61 63\n62 64\n63 65\n64 66\n65 67\n66 68\n67 69\n68 70\n69 71\n70 72\n71 73\n72 74\n73 75\n74 76\n75 77\n76 78\n77 79\n78 80\n79 81\n80 82\n81 83\n82 84\n83 85\n84 86\n85 87\n86 88\n87 89\n88 90\n89 91\n90 92\n91 93\n92 94\n93 95\n94 96\n95 97\n96 98\n97 99\n98 100\n99 0\n"}]
false
stdio
null
true
847/A
847
A
PyPy 3-64
TESTS
9
77
0
190514304
n=int(input()) L,L2,lst=[],[],[] c=0 for _ in range(n): l,r=map(int,input().split()) L.append([l,r]) if r==0: c+=1 else: L2.append(r) for i in range(n): if n-i not in L2: lst.append(n-i) p=0 for i in range(n): if L[i][1]==0 and lst[p]!=L[i][0] and i+1!=lst[p] and i+1!= L[lst[p]-1][1] and c>1: L[i][1]=lst[p] L[lst[p]-1][0]=i+1 p+=1 c-=1 for i in range(n): print(*L[i],sep=" ")
23
62
0
219095258
n = int(input()) pr = [0] * n ne = [0] * n for i in range(n): pr[i], ne[i] = map(int, input().split()) pr[i] -= 1 ne[i] -= 1 lists = [] for i in range(n): if pr[i] == -1: p = i while ne[p] != -1: p = ne[p] lists.append((i, p)) for i in range(1, len(lists)): ne[lists[i - 1][1]] = lists[i][0] pr[lists[i][0]] = lists[i - 1][1] for i in range(n): print(pr[i] + 1, ne[i] + 1)# 1692181823.4526193
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
2
256
Union of Doubly Linked Lists
Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e. each element except the first has exactly one previous element, each element except the last has exactly one next element. The list is not closed in a cycle. In this problem you are given n memory cells forming one or more doubly linked lists. Each cell contains information about element from some list. Memory cells are numbered from 1 to n. For each cell i you are given two values: - li — cell containing previous element for the element in the cell i; - ri — cell containing next element for the element in the cell i. If cell i contains information about the element which has no previous element then li = 0. Similarly, if cell i contains information about the element which has no next element then ri = 0. Three lists are shown on the picture. For example, for the picture above the values of l and r are the following: l1 = 4, r1 = 7; l2 = 5, r2 = 0; l3 = 0, r3 = 0; l4 = 6, r4 = 1; l5 = 0, r5 = 2; l6 = 0, r6 = 4; l7 = 1, r7 = 0. Your task is to unite all given lists in a single list, joining them to each other in any order. In particular, if the input data already contains a single list, then there is no need to perform any actions. Print the resulting list in the form of values li, ri. Any other action, other than joining the beginning of one list to the end of another, can not be performed.
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of memory cells where the doubly linked lists are located. Each of the following n lines contains two integers li, ri (0 ≤ li, ri ≤ n) — the cells of the previous and the next element of list for cell i. Value li = 0 if element in cell i has no previous element in its list. Value ri = 0 if element in cell i has no next element in its list. It is guaranteed that the input contains the correct description of a single or more doubly linked lists. All lists have linear structure: each element of list except the first has exactly one previous element; each element of list except the last has exactly one next element. Each memory cell contains information about one element from some list, each element of each list written in one of n given cells.
Print n lines, the i-th line must contain two integers li and ri — the cells of the previous and the next element of list for cell i after all lists from the input are united in a single list. If there are many solutions print any of them.
null
null
[{"input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0", "output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0"}]
1,500
["implementation"]
23
[{"input": "7\r\n4 7\r\n5 0\r\n0 0\r\n6 1\r\n0 2\r\n0 4\r\n1 0\r\n", "output": "4 7\r\n5 6\r\n0 5\r\n6 1\r\n3 2\r\n2 4\r\n1 0\r\n"}, {"input": "2\r\n2 0\r\n0 1\r\n", "output": "2 0\r\n0 1\r\n"}, {"input": "1\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "4\r\n0 2\r\n1 0\r\n0 4\r\n3 0\r\n", "output": "0 2\r\n1 3\r\n2 4\r\n3 0\r\n"}, {"input": "5\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\r\n1 3\r\n2 4\r\n3 5\r\n4 0\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "0 2\r\n1 0\r\n"}, {"input": "2\r\n0 2\r\n1 0\r\n", "output": "0 2\r\n1 0\r\n"}, {"input": "5\r\n5 3\r\n4 0\r\n1 4\r\n3 2\r\n0 1\r\n", "output": "5 3\r\n4 0\r\n1 4\r\n3 2\r\n0 1\r\n"}, {"input": "5\r\n2 0\r\n0 1\r\n0 4\r\n3 5\r\n4 0\r\n", "output": "2 3\r\n0 1\r\n1 4\r\n3 5\r\n4 0\r\n"}, {"input": "5\r\n3 4\r\n0 0\r\n0 1\r\n1 0\r\n0 0\r\n", "output": "3 4\r\n0 3\r\n2 1\r\n1 5\r\n4 0\r\n"}, {"input": "5\r\n3 0\r\n0 0\r\n0 1\r\n0 0\r\n0 0\r\n", "output": "3 4\r\n0 3\r\n2 1\r\n1 5\r\n4 0\r\n"}, {"input": "10\r\n7 5\r\n5 0\r\n4 7\r\n10 3\r\n1 2\r\n0 9\r\n3 1\r\n9 10\r\n6 8\r\n8 4\r\n", "output": "7 5\r\n5 0\r\n4 7\r\n10 3\r\n1 2\r\n0 9\r\n3 1\r\n9 10\r\n6 8\r\n8 4\r\n"}, {"input": "10\r\n6 2\r\n1 0\r\n9 4\r\n3 6\r\n10 8\r\n4 1\r\n0 10\r\n5 0\r\n0 3\r\n7 5\r\n", "output": "6 2\r\n1 0\r\n9 4\r\n3 6\r\n10 8\r\n4 1\r\n0 10\r\n5 9\r\n8 3\r\n7 5\r\n"}, {"input": "10\r\n0 9\r\n4 0\r\n5 0\r\n7 2\r\n0 3\r\n8 10\r\n0 4\r\n0 6\r\n1 0\r\n6 0\r\n", "output": "0 9\r\n4 8\r\n5 7\r\n7 2\r\n9 3\r\n8 10\r\n3 4\r\n2 6\r\n1 5\r\n6 0\r\n"}, {"input": "10\r\n7 0\r\n0 0\r\n0 0\r\n0 0\r\n0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8\n7 9\n8 10\n9 11\n10 12\n11 29\n29 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22\n21 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 30\n12 13\n28 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 51\n50 52\n51 53\n52 54\n53 55\n54 56\n55 57\n56 58\n57 59\n58 60\n59 61\n60 62\n61 63\n62 64\n63 65\n64 66\n65 67\n66 68\n67 69\n68 70\n69 71\n70 72\n71 73\n72 74\n73 75\n74 76\n75 77\n76 78\n77 79\n78 80\n79 81\n80 82\n81 83\n82 84\n83 85\n84 86\n85 87\n86 88\n87 89\n88 90\n89 91\n90 92\n91 93\n92 94\n93 95\n94 96\n95 97\n96 4\n4 99\n98 100\n99 0\n"}, {"input": "100\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 80\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n21 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 80\n80 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 29\n28 30\n29 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 51\n50 52\n51 53\n52 54\n53 55\n54 56\n55 57\n56 58\n57 59\n58 60\n59 61\n60 62\n61 63\n62 64\n63 65\n64 66\n65 67\n66 68\n67 69\n68 70\n69 71\n70 72\n71 73\n72 74\n73 75\n74 76\n75 77\n76 78\n77 79\n78 81\n21 22\n79 82\n81 83\n82 84\n83 85\n84 86\n85 87\n86 88\n87 89\n88 90\n89 91\n90 92\n91 93\n92 94\n93 95\n94 96\n95 97\n96 98\n97 99\n98 100\n99 0\n"}, {"input": "100\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22\n21 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 29\n28 30\n29 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 51\n50 52\n51 53\n52 54\n53 55\n54 56\n55 57\n56 58\n57 59\n58 60\n59 61\n60 62\n61 63\n62 64\n63 65\n64 66\n65 67\n66 68\n67 69\n68 70\n69 71\n70 72\n71 73\n72 74\n73 75\n74 76\n75 77\n76 78\n77 79\n78 80\n79 81\n80 82\n81 83\n82 84\n83 85\n84 86\n85 87\n86 88\n87 89\n88 90\n89 91\n90 92\n91 93\n92 94\n93 95\n94 96\n95 97\n96 98\n97 99\n98 100\n99 0\n"}]
false
stdio
null
true
847/A
847
A
PyPy 3-64
TESTS
7
46
0
191313017
n = int(input()) M = [] N = [] B = [] for i in range(n): a, b = map(int, input().split()) L = [] if a != 0: L.append(a) L.append(i + 1) if b != 0: L.append(b) M.append(L) M.sort(key = len) for K in M: N += K for ele in N: if ele not in B: B.append(ele) for k in range(n): index = B.index(k + 1) if index != 0: print(B[index - 1], end = " ") else: print(0, end = " ") if index != n - 1: print(B[index + 1]) else: print(0)
23
62
307,200
106171058
if __name__=='__main__': n=int(input()) dl=[[0,0]] end=0 for i in range(n): dl.append(list(map(int,input().split()))) for i in range(1,n+1): if not dl[i][0]: dl[end][1]=i dl[i][0]=end j=i while(dl[j][1]): #print(dl[j]) #j+=1 j=dl[j][1] end=j for node in dl[1:]: print(*node)
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
2
256
Union of Doubly Linked Lists
Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e. each element except the first has exactly one previous element, each element except the last has exactly one next element. The list is not closed in a cycle. In this problem you are given n memory cells forming one or more doubly linked lists. Each cell contains information about element from some list. Memory cells are numbered from 1 to n. For each cell i you are given two values: - li — cell containing previous element for the element in the cell i; - ri — cell containing next element for the element in the cell i. If cell i contains information about the element which has no previous element then li = 0. Similarly, if cell i contains information about the element which has no next element then ri = 0. Three lists are shown on the picture. For example, for the picture above the values of l and r are the following: l1 = 4, r1 = 7; l2 = 5, r2 = 0; l3 = 0, r3 = 0; l4 = 6, r4 = 1; l5 = 0, r5 = 2; l6 = 0, r6 = 4; l7 = 1, r7 = 0. Your task is to unite all given lists in a single list, joining them to each other in any order. In particular, if the input data already contains a single list, then there is no need to perform any actions. Print the resulting list in the form of values li, ri. Any other action, other than joining the beginning of one list to the end of another, can not be performed.
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of memory cells where the doubly linked lists are located. Each of the following n lines contains two integers li, ri (0 ≤ li, ri ≤ n) — the cells of the previous and the next element of list for cell i. Value li = 0 if element in cell i has no previous element in its list. Value ri = 0 if element in cell i has no next element in its list. It is guaranteed that the input contains the correct description of a single or more doubly linked lists. All lists have linear structure: each element of list except the first has exactly one previous element; each element of list except the last has exactly one next element. Each memory cell contains information about one element from some list, each element of each list written in one of n given cells.
Print n lines, the i-th line must contain two integers li and ri — the cells of the previous and the next element of list for cell i after all lists from the input are united in a single list. If there are many solutions print any of them.
null
null
[{"input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0", "output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0"}]
1,500
["implementation"]
23
[{"input": "7\r\n4 7\r\n5 0\r\n0 0\r\n6 1\r\n0 2\r\n0 4\r\n1 0\r\n", "output": "4 7\r\n5 6\r\n0 5\r\n6 1\r\n3 2\r\n2 4\r\n1 0\r\n"}, {"input": "2\r\n2 0\r\n0 1\r\n", "output": "2 0\r\n0 1\r\n"}, {"input": "1\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "4\r\n0 2\r\n1 0\r\n0 4\r\n3 0\r\n", "output": "0 2\r\n1 3\r\n2 4\r\n3 0\r\n"}, {"input": "5\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\r\n1 3\r\n2 4\r\n3 5\r\n4 0\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "0 2\r\n1 0\r\n"}, {"input": "2\r\n0 2\r\n1 0\r\n", "output": "0 2\r\n1 0\r\n"}, {"input": "5\r\n5 3\r\n4 0\r\n1 4\r\n3 2\r\n0 1\r\n", "output": "5 3\r\n4 0\r\n1 4\r\n3 2\r\n0 1\r\n"}, {"input": "5\r\n2 0\r\n0 1\r\n0 4\r\n3 5\r\n4 0\r\n", "output": "2 3\r\n0 1\r\n1 4\r\n3 5\r\n4 0\r\n"}, {"input": "5\r\n3 4\r\n0 0\r\n0 1\r\n1 0\r\n0 0\r\n", "output": "3 4\r\n0 3\r\n2 1\r\n1 5\r\n4 0\r\n"}, {"input": "5\r\n3 0\r\n0 0\r\n0 1\r\n0 0\r\n0 0\r\n", "output": "3 4\r\n0 3\r\n2 1\r\n1 5\r\n4 0\r\n"}, {"input": "10\r\n7 5\r\n5 0\r\n4 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\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 4\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\n1 3\n2 5\n97 98\n3 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 29\n29 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22\n21 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 30\n12 13\n28 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 51\n50 52\n51 53\n52 54\n53 55\n54 56\n55 57\n56 58\n57 59\n58 60\n59 61\n60 62\n61 63\n62 64\n63 65\n64 66\n65 67\n66 68\n67 69\n68 70\n69 71\n70 72\n71 73\n72 74\n73 75\n74 76\n75 77\n76 78\n77 79\n78 80\n79 81\n80 82\n81 83\n82 84\n83 85\n84 86\n85 87\n86 88\n87 89\n88 90\n89 91\n90 92\n91 93\n92 94\n93 95\n94 96\n95 97\n96 4\n4 99\n98 100\n99 0\n"}, {"input": "100\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 80\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n21 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 80\n80 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 29\n28 30\n29 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 51\n50 52\n51 53\n52 54\n53 55\n54 56\n55 57\n56 58\n57 59\n58 60\n59 61\n60 62\n61 63\n62 64\n63 65\n64 66\n65 67\n66 68\n67 69\n68 70\n69 71\n70 72\n71 73\n72 74\n73 75\n74 76\n75 77\n76 78\n77 79\n78 81\n21 22\n79 82\n81 83\n82 84\n83 85\n84 86\n85 87\n86 88\n87 89\n88 90\n89 91\n90 92\n91 93\n92 94\n93 95\n94 96\n95 97\n96 98\n97 99\n98 100\n99 0\n"}, {"input": "100\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "0 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22\n21 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 29\n28 30\n29 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 51\n50 52\n51 53\n52 54\n53 55\n54 56\n55 57\n56 58\n57 59\n58 60\n59 61\n60 62\n61 63\n62 64\n63 65\n64 66\n65 67\n66 68\n67 69\n68 70\n69 71\n70 72\n71 73\n72 74\n73 75\n74 76\n75 77\n76 78\n77 79\n78 80\n79 81\n80 82\n81 83\n82 84\n83 85\n84 86\n85 87\n86 88\n87 89\n88 90\n89 91\n90 92\n91 93\n92 94\n93 95\n94 96\n95 97\n96 98\n97 99\n98 100\n99 0\n"}]
false
stdio
null
true
631/A
631
A
Python 3
TESTS
18
31
0
221238787
n=int(input()) array=list(map(int, input().split())) brray=list(map(int, input().split())) ora=array[0] orb=brray[0] for a in range(1,n-1): ora=ora|array[a] for b in range(1,n-1): orb=orb|brray[b] if n==2: print(2*(ora+orb)) else: print(ora+orb)
27
46
0
146703856
n = int(input()) a = map(int, input().split()) ta = 0 for i in a: ta |= i b = map(int, input().split()) tb = 0 for i in b: tb |= i print(ta + tb)
Codeforces Round 344 (Div. 2)
CF
2,016
1
256
Interview
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ..., xr, where xi is the i-th element of the array x. You are given two arrays a and b of length n. You need to determine the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays. The second line contains n integers ai (0 ≤ ai ≤ 109). The third line contains n integers bi (0 ≤ bi ≤ 109).
Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.
null
Bitwise OR of two non-negative integers a and b is the number c = a OR b, such that each of its digits in binary notation is 1 if and only if at least one of a or b have 1 in the corresponding position in binary notation. In the first sample, one of the optimal answers is l = 2 and r = 4, because f(a, 2, 4) + f(b, 2, 4) = (2 OR 4 OR 3) + (3 OR 3 OR 12) = 7 + 15 = 22. Other ways to get maximum value is to choose l = 1 and r = 4, l = 1 and r = 5, l = 2 and r = 4, l = 2 and r = 5, l = 3 and r = 4, or l = 3 and r = 5. In the second sample, the maximum value is obtained for l = 1 and r = 9.
[{"input": "5\n1 2 4 3 2\n2 3 3 12 1", "output": "22"}, {"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6", "output": "46"}]
900
["brute force", "implementation"]
27
[{"input": "5\r\n1 2 4 3 2\r\n2 3 3 12 1\r\n", "output": "22"}, {"input": "10\r\n13 2 7 11 8 4 9 8 5 1\r\n5 7 18 9 2 3 0 11 8 6\r\n", "output": "46"}, {"input": "25\r\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\r\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 95 124 18 28 79 125 106 116\r\n", "output": "254"}, {"input": "20\r\n64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64\r\n64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64\r\n", "output": "128"}, {"input": "1\r\n1000000000\r\n1000000000\r\n", "output": "2000000000"}, {"input": "1\r\n0\r\n0\r\n", "output": "0"}, {"input": "2\r\n7 16\r\n16 7\r\n", "output": "46"}, {"input": "4\r\n6 0 0 0\r\n0 0 0 1\r\n", "output": "7"}, {"input": "8\r\n1 2 4 8 16 32 64 128\r\n1 2 4 8 16 32 64 128\r\n", "output": "510"}, {"input": "1\r\n2\r\n3\r\n", "output": "5"}, {"input": "1\r\n4\r\n3\r\n", "output": "7"}, {"input": "1\r\n1\r\n1\r\n", "output": "2"}]
false
stdio
null
true
282/A
282
A
Python 3
TESTS
6
46
0
228672944
n=int(input()) A = [] m = 0 for i in range(n): a = input() A.append(a) for i in range(len(A)): if A[i] == "--X": m-=1 elif A[i] == "++X": m+=1 elif A[i] == "X++" and i != len(A)-1: m+=1 elif A[i] == "X--" and i != len(A)-1: m-=1 print(m)
36
31
0
227571097
n=int(input()) x=0 while n>0 : s=list(input()) if '+' in s : x+=1 else : x-=1 n-=1 print(x)
Codeforces Round 173 (Div. 2)
CF
2,013
1
256
Bit++
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: - Operation ++ increases the value of variable x by 1. - Operation -- decreases the value of variable x by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme. Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Print a single integer — the final value of x.
null
null
[{"input": "1\n++X", "output": "1"}, {"input": "2\nX++\n--X", "output": "0"}]
800
["implementation"]
36
[{"input": "1\r\n++X\r\n", "output": "1\r\n"}, {"input": "2\r\nX++\r\n--X\r\n", "output": "0\r\n"}, {"input": "3\r\n++X\r\n++X\r\n++X\r\n", "output": "3\r\n"}, {"input": "2\r\n--X\r\n--X\r\n", "output": "-2\r\n"}, {"input": "5\r\n++X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "-1\r\n"}, {"input": "28\r\nX--\r\n++X\r\nX++\r\nX++\r\nX++\r\n--X\r\n--X\r\nX++\r\nX--\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\nX--\r\n++X\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n--X\r\n++X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX++\r\n", "output": "4\r\n"}, {"input": "94\r\nX++\r\nX++\r\n++X\r\n++X\r\nX--\r\n--X\r\nX++\r\n--X\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\nX++\r\n--X\r\nX--\r\nX--\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX++\r\n++X\r\n--X\r\nX--\r\n++X\r\n--X\r\n--X\r\nX--\r\nX--\r\nX++\r\nX++\r\nX--\r\nX++\r\nX--\r\nX--\r\nX--\r\n--X\r\nX--\r\nX--\r\nX--\r\nX++\r\n++X\r\nX--\r\n++X\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n++X\r\nX--\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\n--X\r\nX--\r\n++X\r\nX--\r\nX--\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\n++X\r\n--X\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX++\r\n", "output": "-10\r\n"}, {"input": "56\r\n--X\r\nX--\r\n--X\r\n--X\r\nX--\r\nX--\r\n--X\r\nX++\r\n++X\r\n--X\r\nX++\r\nX--\r\n--X\r\n++X\r\n--X\r\nX--\r\nX--\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n--X\r\n++X\r\nX++\r\nX++\r\n--X\r\nX++\r\nX--\r\n--X\r\nX--\r\n--X\r\nX++\r\n++X\r\n--X\r\n++X\r\nX++\r\nX--\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n--X\r\nX--\r\n--X\r\nX++\r\n--X\r\n++X\r\n--X\r\n", "output": "-14\r\n"}, {"input": "59\r\nX--\r\n--X\r\nX++\r\n++X\r\nX--\r\n--X\r\n--X\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\n++X\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\nX++\r\n--X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\nX++\r\nX--\r\nX--\r\n--X\r\nX++\r\nX--\r\nX--\r\n++X\r\nX--\r\nX++\r\n--X\r\nX++\r\nX--\r\nX--\r\nX--\r\nX--\r\n++X\r\n--X\r\nX++\r\nX++\r\nX--\r\nX++\r\n++X\r\nX--\r\nX++\r\nX--\r\nX--\r\n++X\r\n", "output": "3\r\n"}, {"input": "87\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\nX--\r\n++X\r\n--X\r\n--X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\n++X\r\n++X\r\n--X\r\n++X\r\n--X\r\nX--\r\n++X\r\n++X\r\nX--\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX--\r\n++X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX--\r\nX--\r\nX--\r\nX++\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\nX++\r\n++X\r\nX--\r\n--X\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX++\r\nX++\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX--\r\n--X\r\n++X\r\n++X\r\n", "output": "-5\r\n"}, {"input": "101\r\nX++\r\nX++\r\nX++\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX--\r\n--X\r\n--X\r\n++X\r\nX++\r\n++X\r\n++X\r\nX--\r\n--X\r\n++X\r\nX++\r\nX--\r\n++X\r\n--X\r\n--X\r\n--X\r\n++X\r\n--X\r\n++X\r\nX++\r\nX++\r\n++X\r\n--X\r\nX++\r\nX--\r\nX++\r\n++X\r\n++X\r\nX--\r\nX--\r\nX--\r\nX++\r\nX++\r\nX--\r\nX--\r\nX++\r\n++X\r\n++X\r\n++X\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\n++X\r\nX++\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX--\r\n++X\r\nX--\r\n++X\r\nX++\r\nX--\r\n++X\r\nX++\r\n--X\r\nX++\r\nX++\r\n++X\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\n++X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX--\r\nX--\r\n--X\r\n--X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "1\r\n"}, {"input": "63\r\n--X\r\nX--\r\n++X\r\n--X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX++\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX--\r\n++X\r\nX++\r\nX--\r\n--X\r\nX--\r\n++X\r\n++X\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\nX--\r\n++X\r\nX--\r\n--X\r\nX--\r\nX--\r\nX--\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\n++X\r\n++X\r\nX--\r\n++X\r\n++X\r\nX--\r\n", "output": "1\r\n"}, {"input": "45\r\n--X\r\n++X\r\nX--\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX++\r\n++X\r\nX--\r\n++X\r\n++X\r\nX--\r\nX++\r\nX--\r\n--X\r\nX--\r\n++X\r\n++X\r\n--X\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\n--X\r\n--X\r\nX--\r\n++X\r\n++X\r\nX++\r\nX++\r\n++X\r\n++X\r\nX++\r\n", "output": "-3\r\n"}, {"input": "21\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\nX--\r\n--X\r\nX++\r\n++X\r\n", "output": "1\r\n"}, {"input": "100\r\n--X\r\n++X\r\nX++\r\n++X\r\nX--\r\n++X\r\nX--\r\nX++\r\n--X\r\nX++\r\nX--\r\nX--\r\nX--\r\n++X\r\nX--\r\nX++\r\nX++\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\nX--\r\nX++\r\nX++\r\nX++\r\n++X\r\n--X\r\n++X\r\nX++\r\nX--\r\n++X\r\n++X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX--\r\nX++\r\nX--\r\nX--\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\n--X\r\n--X\r\n++X\r\nX++\r\nX--\r\nX++\r\nX--\r\nX++\r\nX++\r\n--X\r\nX--\r\nX--\r\n++X\r\nX--\r\n--X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX--\r\nX--\r\n++X\r\n++X\r\nX--\r\n++X\r\nX++\r\n--X\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\n", "output": "8\r\n"}, {"input": "17\r\nX++\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\n--X\r\n--X\r\nX--\r\n++X\r\nX--\r\nX++\r\n", "output": "-1\r\n"}, {"input": "77\r\n++X\r\nX++\r\n--X\r\nX--\r\n--X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX++\r\nX--\r\n++X\r\n--X\r\n--X\r\n--X\r\n--X\r\n++X\r\nX--\r\nX++\r\nX--\r\n--X\r\nX--\r\n--X\r\nX--\r\n++X\r\n--X\r\n++X\r\n++X\r\nX++\r\nX++\r\nX--\r\n--X\r\nX--\r\nX--\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n++X\r\nX++\r\nX--\r\n++X\r\n--X\r\nX++\r\nX--\r\n++X\r\n++X\r\n++X\r\nX--\r\nX--\r\nX--\r\n--X\r\n++X\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\nX++\r\n--X\r\nX++\r\nX--\r\n", "output": "-5\r\n"}, {"input": "21\r\nX--\r\n++X\r\n--X\r\nX--\r\n++X\r\nX--\r\n++X\r\nX--\r\n--X\r\n++X\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\n--X\r\nX++\r\nX++\r\nX--\r\n++X\r\nX--\r\n", "output": "1\r\n"}, {"input": "1\r\nX--\r\n", "output": "-1\r\n"}]
false
stdio
null
true
776/A
776
A
Python 3
TESTS
6
155
1,126,400
60618311
import re sk=[input().split()] n=int(input()) for x in range(n): n1=input().split() if re.match(sk[x][0],n1[0]): sk.append([n1[1],sk[x][1]]) else: sk.append([sk[x][0],n1[1]]) for x in range(n+1): print(sk[x][0],sk[x][1])
57
46
0
145593385
import sys candidates = sys.stdin.readline().strip().split(' ', 2) n = int(sys.stdin.readline().strip()) killed = [] candidates_list = [candidates] for i in range(n): names = sys.stdin.readline().strip().split(' ', 2) new_candidates = list(candidates_list[-1]) new_candidates.remove(names[0]) new_candidates.append(names[1]) candidates_list.append(new_candidates) for candidates in candidates_list: print(f'{candidates[0]} {candidates[1]}')
ICM Technex 2017 and Codeforces Round 400 (Div. 1 + Div. 2, combined)
CF
2,017
2
256
A Serial Killer
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.
Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
null
In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
[{"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"}, {"input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex"}]
900
["brute force", "implementation", "strings"]
57
[{"input": "ross rachel\r\n4\r\nross joey\r\nrachel phoebe\r\nphoebe monica\r\nmonica chandler\r\n", "output": "ross rachel\r\njoey rachel\r\njoey phoebe\r\njoey monica\r\njoey chandler\r\n"}, {"input": "icm codeforces\r\n1\r\ncodeforces technex\r\n", "output": "icm codeforces\r\nicm technex\r\n"}, {"input": "a b\r\n3\r\na c\r\nb d\r\nd e\r\n", "output": "a b\r\nc b\r\nc d\r\nc e\r\n"}, {"input": "ze udggmyop\r\n4\r\nze szhrbmft\r\nudggmyop mjorab\r\nszhrbmft ojdtfnzxj\r\nojdtfnzxj yjlkg\r\n", "output": "ze udggmyop\r\nszhrbmft udggmyop\r\nszhrbmft mjorab\r\nojdtfnzxj mjorab\r\nyjlkg mjorab\r\n"}, {"input": "q s\r\n10\r\nq b\r\nb j\r\ns g\r\nj f\r\nf m\r\ng c\r\nc a\r\nm d\r\nd z\r\nz o\r\n", "output": "q s\r\nb s\r\nj s\r\nj g\r\nf g\r\nm g\r\nm c\r\nm a\r\nd a\r\nz a\r\no a\r\n"}, {"input": "iii iiiiii\r\n7\r\niii iiiiiiiiii\r\niiiiiiiiii iiii\r\niiii i\r\niiiiii iiiiiiii\r\niiiiiiii iiiiiiiii\r\ni iiiii\r\niiiii ii\r\n", "output": "iii iiiiii\r\niiiiiiiiii iiiiii\r\niiii iiiiii\r\ni iiiiii\r\ni iiiiiiii\r\ni iiiiiiiii\r\niiiii iiiiiiiii\r\nii iiiiiiiii\r\n"}, {"input": "bwyplnjn zkms\r\n26\r\nzkms nzmcsytxh\r\nnzmcsytxh yujsb\r\nbwyplnjn gtbzhudpb\r\ngtbzhudpb hpk\r\nyujsb xvy\r\nhpk wrwnfokml\r\nwrwnfokml ndouuikw\r\nndouuikw ucgrja\r\nucgrja tgfmpldz\r\nxvy nycrfphn\r\nnycrfphn quvs\r\nquvs htdy\r\nhtdy k\r\ntgfmpldz xtdpkxm\r\nxtdpkxm suwqxs\r\nk fv\r\nsuwqxs qckllwy\r\nqckllwy diun\r\nfv lefa\r\nlefa gdoqjysx\r\ndiun dhpz\r\ngdoqjysx bdmqdyt\r\ndhpz dgz\r\ndgz v\r\nbdmqdyt aswy\r\naswy ydkayhlrnm\r\n", "output": "bwyplnjn zkms\r\nbwyplnjn nzmcsytxh\r\nbwyplnjn yujsb\r\ngtbzhudpb yujsb\r\nhpk yujsb\r\nhpk xvy\r\nwrwnfokml xvy\r\nndouuikw xvy\r\nucgrja xvy\r\ntgfmpldz xvy\r\ntgfmpldz nycrfphn\r\ntgfmpldz quvs\r\ntgfmpldz htdy\r\ntgfmpldz k\r\nxtdpkxm k\r\nsuwqxs k\r\nsuwqxs fv\r\nqckllwy fv\r\ndiun fv\r\ndiun lefa\r\ndiun gdoqjysx\r\ndhpz gdoqjysx\r\ndhpz bdmqdyt\r\ndgz bdmqdyt\r\nv bdmqdyt\r\nv aswy\r\nv ydkayhlrnm\r\n"}, {"input": "wxz hbeqwqp\r\n7\r\nhbeqwqp cpieghnszh\r\ncpieghnszh tlqrpd\r\ntlqrpd ttwrtio\r\nttwrtio xapvds\r\nxapvds zk\r\nwxz yryk\r\nzk b\r\n", "output": "wxz hbeqwqp\r\nwxz cpieghnszh\r\nwxz tlqrpd\r\nwxz ttwrtio\r\nwxz xapvds\r\nwxz zk\r\nyryk zk\r\nyryk b\r\n"}, {"input": "wced gnsgv\r\n23\r\ngnsgv japawpaf\r\njapawpaf nnvpeu\r\nnnvpeu a\r\na ddupputljq\r\nddupputljq qyhnvbh\r\nqyhnvbh pqwijl\r\nwced khuvs\r\nkhuvs bjkh\r\npqwijl ysacmboc\r\nbjkh srf\r\nsrf jknoz\r\njknoz hodf\r\nysacmboc xqtkoyh\r\nhodf rfp\r\nxqtkoyh bivgnwqvoe\r\nbivgnwqvoe nknf\r\nnknf wuig\r\nrfp e\r\ne bqqknq\r\nwuig sznhhhu\r\nbqqknq dhrtdld\r\ndhrtdld n\r\nsznhhhu bguylf\r\n", "output": "wced gnsgv\r\nwced japawpaf\r\nwced nnvpeu\r\nwced a\r\nwced ddupputljq\r\nwced qyhnvbh\r\nwced pqwijl\r\nkhuvs pqwijl\r\nbjkh pqwijl\r\nbjkh ysacmboc\r\nsrf ysacmboc\r\njknoz ysacmboc\r\nhodf ysacmboc\r\nhodf xqtkoyh\r\nrfp xqtkoyh\r\nrfp bivgnwqvoe\r\nrfp nknf\r\nrfp wuig\r\ne wuig\r\nbqqknq wuig\r\nbqqknq sznhhhu\r\ndhrtdld sznhhhu\r\nn sznhhhu\r\nn bguylf\r\n"}, {"input": "qqqqqqqqqq qqqqqqqq\r\n3\r\nqqqqqqqq qqqqqqqqq\r\nqqqqqqqqq qqqqq\r\nqqqqq q\r\n", "output": "qqqqqqqqqq qqqqqqqq\r\nqqqqqqqqqq qqqqqqqqq\r\nqqqqqqqqqq qqqqq\r\nqqqqqqqqqq q\r\n"}, {"input": "wwwww w\r\n8\r\nwwwww wwwwwwww\r\nwwwwwwww wwwwwwwww\r\nwwwwwwwww wwwwwwwwww\r\nw www\r\nwwwwwwwwww wwww\r\nwwww ww\r\nwww wwwwww\r\nwwwwww wwwwwww\r\n", "output": "wwwww w\r\nwwwwwwww w\r\nwwwwwwwww w\r\nwwwwwwwwww w\r\nwwwwwwwwww www\r\nwwww www\r\nww www\r\nww wwwwww\r\nww wwwwwww\r\n"}, {"input": "k d\r\n17\r\nk l\r\nd v\r\nv z\r\nl r\r\nz i\r\nr s\r\ns p\r\np w\r\nw j\r\nj h\r\ni c\r\nh m\r\nm q\r\nc o\r\no g\r\nq x\r\nx n\r\n", "output": "k d\r\nl d\r\nl v\r\nl z\r\nr z\r\nr i\r\ns i\r\np i\r\nw i\r\nj i\r\nh i\r\nh c\r\nm c\r\nq c\r\nq o\r\nq g\r\nx g\r\nn g\r\n"}]
false
stdio
import sys def main(): input_path, output_path, submission_path = sys.argv[1:4] with open(output_path, 'r') as f: correct_lines = [line.strip() for line in f.readlines()] with open(submission_path, 'r') as f: submission_lines = [line.strip() for line in f.readlines()] if len(submission_lines) != len(correct_lines): print(0) return for sub_line, corr_line in zip(submission_lines, correct_lines): sub_parts = sub_line.split() corr_parts = corr_line.split() if len(sub_parts) != 2 or len(corr_parts) != 2: print(0) return if set(sub_parts) != set(corr_parts): print(0) return print(1) if __name__ == "__main__": main()
true
282/A
282
A
Python 3
TESTS
6
31
0
228528908
n = int(input()) x = 0 for i in range(n): op = input() if ((op == "X++") and (i != n-1)) or (op == "++X"): x += 1 elif ((op == "X--") and (i != n-1)) or (op == "--X"): x -= 1 print(x)
36
31
0
227584059
n = int(input("")) count = 0 for i in range(n): s = input("") if s[1] == "+": count = count + 1 if s[1] == "-": count = count - 1 print(count)
Codeforces Round 173 (Div. 2)
CF
2,013
1
256
Bit++
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: - Operation ++ increases the value of variable x by 1. - Operation -- decreases the value of variable x by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme. Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Print a single integer — the final value of x.
null
null
[{"input": "1\n++X", "output": "1"}, {"input": "2\nX++\n--X", "output": "0"}]
800
["implementation"]
36
[{"input": "1\r\n++X\r\n", "output": "1\r\n"}, {"input": "2\r\nX++\r\n--X\r\n", "output": "0\r\n"}, {"input": "3\r\n++X\r\n++X\r\n++X\r\n", "output": "3\r\n"}, {"input": "2\r\n--X\r\n--X\r\n", "output": "-2\r\n"}, {"input": "5\r\n++X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "-1\r\n"}, {"input": "28\r\nX--\r\n++X\r\nX++\r\nX++\r\nX++\r\n--X\r\n--X\r\nX++\r\nX--\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\nX--\r\n++X\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n--X\r\n++X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX++\r\n", "output": "4\r\n"}, {"input": "94\r\nX++\r\nX++\r\n++X\r\n++X\r\nX--\r\n--X\r\nX++\r\n--X\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\nX++\r\n--X\r\nX--\r\nX--\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX++\r\n++X\r\n--X\r\nX--\r\n++X\r\n--X\r\n--X\r\nX--\r\nX--\r\nX++\r\nX++\r\nX--\r\nX++\r\nX--\r\nX--\r\nX--\r\n--X\r\nX--\r\nX--\r\nX--\r\nX++\r\n++X\r\nX--\r\n++X\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n++X\r\nX--\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\n--X\r\nX--\r\n++X\r\nX--\r\nX--\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\n++X\r\n--X\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX++\r\n", "output": "-10\r\n"}, {"input": "56\r\n--X\r\nX--\r\n--X\r\n--X\r\nX--\r\nX--\r\n--X\r\nX++\r\n++X\r\n--X\r\nX++\r\nX--\r\n--X\r\n++X\r\n--X\r\nX--\r\nX--\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n--X\r\n++X\r\nX++\r\nX++\r\n--X\r\nX++\r\nX--\r\n--X\r\nX--\r\n--X\r\nX++\r\n++X\r\n--X\r\n++X\r\nX++\r\nX--\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n--X\r\nX--\r\n--X\r\nX++\r\n--X\r\n++X\r\n--X\r\n", "output": "-14\r\n"}, {"input": "59\r\nX--\r\n--X\r\nX++\r\n++X\r\nX--\r\n--X\r\n--X\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\n++X\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\nX++\r\n--X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\nX++\r\nX--\r\nX--\r\n--X\r\nX++\r\nX--\r\nX--\r\n++X\r\nX--\r\nX++\r\n--X\r\nX++\r\nX--\r\nX--\r\nX--\r\nX--\r\n++X\r\n--X\r\nX++\r\nX++\r\nX--\r\nX++\r\n++X\r\nX--\r\nX++\r\nX--\r\nX--\r\n++X\r\n", "output": "3\r\n"}, {"input": "87\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\nX--\r\n++X\r\n--X\r\n--X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\n++X\r\n++X\r\n--X\r\n++X\r\n--X\r\nX--\r\n++X\r\n++X\r\nX--\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX--\r\n++X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX--\r\nX--\r\nX--\r\nX++\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\nX++\r\n++X\r\nX--\r\n--X\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX++\r\nX++\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX--\r\n--X\r\n++X\r\n++X\r\n", "output": "-5\r\n"}, {"input": "101\r\nX++\r\nX++\r\nX++\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX--\r\n--X\r\n--X\r\n++X\r\nX++\r\n++X\r\n++X\r\nX--\r\n--X\r\n++X\r\nX++\r\nX--\r\n++X\r\n--X\r\n--X\r\n--X\r\n++X\r\n--X\r\n++X\r\nX++\r\nX++\r\n++X\r\n--X\r\nX++\r\nX--\r\nX++\r\n++X\r\n++X\r\nX--\r\nX--\r\nX--\r\nX++\r\nX++\r\nX--\r\nX--\r\nX++\r\n++X\r\n++X\r\n++X\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\n++X\r\nX++\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX--\r\n++X\r\nX--\r\n++X\r\nX++\r\nX--\r\n++X\r\nX++\r\n--X\r\nX++\r\nX++\r\n++X\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\n++X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX--\r\nX--\r\n--X\r\n--X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "1\r\n"}, {"input": "63\r\n--X\r\nX--\r\n++X\r\n--X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX++\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX--\r\n++X\r\nX++\r\nX--\r\n--X\r\nX--\r\n++X\r\n++X\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\nX--\r\n++X\r\nX--\r\n--X\r\nX--\r\nX--\r\nX--\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\n++X\r\n++X\r\nX--\r\n++X\r\n++X\r\nX--\r\n", "output": "1\r\n"}, {"input": "45\r\n--X\r\n++X\r\nX--\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX++\r\n++X\r\nX--\r\n++X\r\n++X\r\nX--\r\nX++\r\nX--\r\n--X\r\nX--\r\n++X\r\n++X\r\n--X\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\n--X\r\n--X\r\nX--\r\n++X\r\n++X\r\nX++\r\nX++\r\n++X\r\n++X\r\nX++\r\n", "output": "-3\r\n"}, {"input": "21\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\nX--\r\n--X\r\nX++\r\n++X\r\n", "output": "1\r\n"}, {"input": "100\r\n--X\r\n++X\r\nX++\r\n++X\r\nX--\r\n++X\r\nX--\r\nX++\r\n--X\r\nX++\r\nX--\r\nX--\r\nX--\r\n++X\r\nX--\r\nX++\r\nX++\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\nX--\r\nX++\r\nX++\r\nX++\r\n++X\r\n--X\r\n++X\r\nX++\r\nX--\r\n++X\r\n++X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX--\r\nX++\r\nX--\r\nX--\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\n--X\r\n--X\r\n++X\r\nX++\r\nX--\r\nX++\r\nX--\r\nX++\r\nX++\r\n--X\r\nX--\r\nX--\r\n++X\r\nX--\r\n--X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX--\r\nX--\r\n++X\r\n++X\r\nX--\r\n++X\r\nX++\r\n--X\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\n", "output": "8\r\n"}, {"input": "17\r\nX++\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\n--X\r\n--X\r\nX--\r\n++X\r\nX--\r\nX++\r\n", "output": "-1\r\n"}, {"input": "77\r\n++X\r\nX++\r\n--X\r\nX--\r\n--X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX++\r\nX--\r\n++X\r\n--X\r\n--X\r\n--X\r\n--X\r\n++X\r\nX--\r\nX++\r\nX--\r\n--X\r\nX--\r\n--X\r\nX--\r\n++X\r\n--X\r\n++X\r\n++X\r\nX++\r\nX++\r\nX--\r\n--X\r\nX--\r\nX--\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n++X\r\nX++\r\nX--\r\n++X\r\n--X\r\nX++\r\nX--\r\n++X\r\n++X\r\n++X\r\nX--\r\nX--\r\nX--\r\n--X\r\n++X\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\nX++\r\n--X\r\nX++\r\nX--\r\n", "output": "-5\r\n"}, {"input": "21\r\nX--\r\n++X\r\n--X\r\nX--\r\n++X\r\nX--\r\n++X\r\nX--\r\n--X\r\n++X\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\n--X\r\nX++\r\nX++\r\nX--\r\n++X\r\nX--\r\n", "output": "1\r\n"}, {"input": "1\r\nX--\r\n", "output": "-1\r\n"}]
false
stdio
null
true
282/A
282
A
Python 3
TESTS
6
31
0
228474718
n = input() x = 0 for i in range(int(n)): code = input() if i == (int(n) -1): if code == "++X": x += 1 elif code == "--X": x -= 1 else: if code == "++X" or code == "X++": x += 1 else: x -= 1 print(x)
36
31
0
227587238
def resta(x): x-=1 return x def suma(x): x+=1 return x n = int(input()) x = 0 for _ in range(n): a = input() if("-" in a): x = resta(x) else: x = suma(x) print(x)
Codeforces Round 173 (Div. 2)
CF
2,013
1
256
Bit++
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: - Operation ++ increases the value of variable x by 1. - Operation -- decreases the value of variable x by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme. Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Print a single integer — the final value of x.
null
null
[{"input": "1\n++X", "output": "1"}, {"input": "2\nX++\n--X", "output": "0"}]
800
["implementation"]
36
[{"input": "1\r\n++X\r\n", "output": "1\r\n"}, {"input": "2\r\nX++\r\n--X\r\n", "output": "0\r\n"}, {"input": "3\r\n++X\r\n++X\r\n++X\r\n", "output": "3\r\n"}, {"input": "2\r\n--X\r\n--X\r\n", "output": "-2\r\n"}, {"input": "5\r\n++X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "-1\r\n"}, {"input": "28\r\nX--\r\n++X\r\nX++\r\nX++\r\nX++\r\n--X\r\n--X\r\nX++\r\nX--\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\nX--\r\n++X\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n--X\r\n++X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX++\r\n", "output": "4\r\n"}, {"input": "94\r\nX++\r\nX++\r\n++X\r\n++X\r\nX--\r\n--X\r\nX++\r\n--X\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\nX++\r\n--X\r\nX--\r\nX--\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX++\r\n++X\r\n--X\r\nX--\r\n++X\r\n--X\r\n--X\r\nX--\r\nX--\r\nX++\r\nX++\r\nX--\r\nX++\r\nX--\r\nX--\r\nX--\r\n--X\r\nX--\r\nX--\r\nX--\r\nX++\r\n++X\r\nX--\r\n++X\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n++X\r\nX--\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\n--X\r\nX--\r\n++X\r\nX--\r\nX--\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\n++X\r\n--X\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX++\r\n", "output": "-10\r\n"}, {"input": "56\r\n--X\r\nX--\r\n--X\r\n--X\r\nX--\r\nX--\r\n--X\r\nX++\r\n++X\r\n--X\r\nX++\r\nX--\r\n--X\r\n++X\r\n--X\r\nX--\r\nX--\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n--X\r\n++X\r\nX++\r\nX++\r\n--X\r\nX++\r\nX--\r\n--X\r\nX--\r\n--X\r\nX++\r\n++X\r\n--X\r\n++X\r\nX++\r\nX--\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n--X\r\nX--\r\n--X\r\nX++\r\n--X\r\n++X\r\n--X\r\n", "output": "-14\r\n"}, {"input": "59\r\nX--\r\n--X\r\nX++\r\n++X\r\nX--\r\n--X\r\n--X\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\n++X\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\nX++\r\n--X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\nX++\r\nX--\r\nX--\r\n--X\r\nX++\r\nX--\r\nX--\r\n++X\r\nX--\r\nX++\r\n--X\r\nX++\r\nX--\r\nX--\r\nX--\r\nX--\r\n++X\r\n--X\r\nX++\r\nX++\r\nX--\r\nX++\r\n++X\r\nX--\r\nX++\r\nX--\r\nX--\r\n++X\r\n", "output": "3\r\n"}, {"input": "87\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\nX--\r\n++X\r\n--X\r\n--X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\n++X\r\n++X\r\n--X\r\n++X\r\n--X\r\nX--\r\n++X\r\n++X\r\nX--\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX--\r\n++X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX--\r\nX--\r\nX--\r\nX++\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\nX++\r\n++X\r\nX--\r\n--X\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX++\r\nX++\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX--\r\n--X\r\n++X\r\n++X\r\n", "output": "-5\r\n"}, {"input": "101\r\nX++\r\nX++\r\nX++\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX--\r\n--X\r\n--X\r\n++X\r\nX++\r\n++X\r\n++X\r\nX--\r\n--X\r\n++X\r\nX++\r\nX--\r\n++X\r\n--X\r\n--X\r\n--X\r\n++X\r\n--X\r\n++X\r\nX++\r\nX++\r\n++X\r\n--X\r\nX++\r\nX--\r\nX++\r\n++X\r\n++X\r\nX--\r\nX--\r\nX--\r\nX++\r\nX++\r\nX--\r\nX--\r\nX++\r\n++X\r\n++X\r\n++X\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\n++X\r\nX++\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX--\r\n++X\r\nX--\r\n++X\r\nX++\r\nX--\r\n++X\r\nX++\r\n--X\r\nX++\r\nX++\r\n++X\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\n++X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX--\r\nX--\r\n--X\r\n--X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "1\r\n"}, {"input": "63\r\n--X\r\nX--\r\n++X\r\n--X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX++\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX--\r\n++X\r\nX++\r\nX--\r\n--X\r\nX--\r\n++X\r\n++X\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\nX--\r\n++X\r\nX--\r\n--X\r\nX--\r\nX--\r\nX--\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\n++X\r\n++X\r\nX--\r\n++X\r\n++X\r\nX--\r\n", "output": "1\r\n"}, {"input": "45\r\n--X\r\n++X\r\nX--\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX++\r\n++X\r\nX--\r\n++X\r\n++X\r\nX--\r\nX++\r\nX--\r\n--X\r\nX--\r\n++X\r\n++X\r\n--X\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\n--X\r\n--X\r\nX--\r\n++X\r\n++X\r\nX++\r\nX++\r\n++X\r\n++X\r\nX++\r\n", "output": "-3\r\n"}, {"input": "21\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\nX--\r\n--X\r\nX++\r\n++X\r\n", "output": "1\r\n"}, {"input": "100\r\n--X\r\n++X\r\nX++\r\n++X\r\nX--\r\n++X\r\nX--\r\nX++\r\n--X\r\nX++\r\nX--\r\nX--\r\nX--\r\n++X\r\nX--\r\nX++\r\nX++\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\nX--\r\nX++\r\nX++\r\nX++\r\n++X\r\n--X\r\n++X\r\nX++\r\nX--\r\n++X\r\n++X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX--\r\nX++\r\nX--\r\nX--\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\n--X\r\n--X\r\n++X\r\nX++\r\nX--\r\nX++\r\nX--\r\nX++\r\nX++\r\n--X\r\nX--\r\nX--\r\n++X\r\nX--\r\n--X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX--\r\nX--\r\n++X\r\n++X\r\nX--\r\n++X\r\nX++\r\n--X\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\n", "output": "8\r\n"}, {"input": "17\r\nX++\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\n--X\r\n--X\r\nX--\r\n++X\r\nX--\r\nX++\r\n", "output": "-1\r\n"}, {"input": "77\r\n++X\r\nX++\r\n--X\r\nX--\r\n--X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX++\r\nX--\r\n++X\r\n--X\r\n--X\r\n--X\r\n--X\r\n++X\r\nX--\r\nX++\r\nX--\r\n--X\r\nX--\r\n--X\r\nX--\r\n++X\r\n--X\r\n++X\r\n++X\r\nX++\r\nX++\r\nX--\r\n--X\r\nX--\r\nX--\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n++X\r\nX++\r\nX--\r\n++X\r\n--X\r\nX++\r\nX--\r\n++X\r\n++X\r\n++X\r\nX--\r\nX--\r\nX--\r\n--X\r\n++X\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\nX++\r\n--X\r\nX++\r\nX--\r\n", "output": "-5\r\n"}, {"input": "21\r\nX--\r\n++X\r\n--X\r\nX--\r\n++X\r\nX--\r\n++X\r\nX--\r\n--X\r\n++X\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\n--X\r\nX++\r\nX++\r\nX--\r\n++X\r\nX--\r\n", "output": "1\r\n"}, {"input": "1\r\nX--\r\n", "output": "-1\r\n"}]
false
stdio
null
true
227/B
227
B
Python 3
TESTS
6
716
2,457,600
165327697
n=int(input()) arr=input() m=int(input()) goal=input() vasya=0 pyta=0 for i in goal: if i.isdigit(): x=arr.index(i)//2 vasya+=x+1 pyta+=n-x print(vasya,pyta)
34
186
16,076,800
214583225
k=int(input()) l=[0]*(k+1) ans=input().split() for i in range(k): l[int(ans[i])]=i+1 q=int(input()) q1=map(int,input().split()) sum=0 sum2=0 for i in q1: sum+=l[i] sum2+=(k-l[i]+1) print(sum,sum2)
Codeforces Round 140 (Div. 2)
CF
2,012
2
256
Effective Approach
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to n) and ending with the n-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the n-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to n, and generated m queries of the form: find element with value bi in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
The first line contains integer n (1 ≤ n ≤ 105) — the number of elements in the array. The second line contains n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the elements of array. The third line contains integer m (1 ≤ m ≤ 105) — the number of queries. The last line contains m space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n) — the search queries. Note that the queries can repeat.
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
null
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
[{"input": "2\n1 2\n1\n1", "output": "1 2"}, {"input": "2\n2 1\n1\n1", "output": "2 1"}, {"input": "3\n3 1 2\n3\n1 2 3", "output": "6 6"}]
1,100
["implementation"]
34
[{"input": "2\r\n1 2\r\n1\r\n1\r\n", "output": "1 2\r\n"}, {"input": "2\r\n2 1\r\n1\r\n1\r\n", "output": "2 1\r\n"}, {"input": "3\r\n3 1 2\r\n3\r\n1 2 3\r\n", "output": "6 6\r\n"}, {"input": "9\r\n2 9 3 1 6 4 7 8 5\r\n9\r\n5 1 5 2 8 4 4 4 5\r\n", "output": "58 32\r\n"}, {"input": "10\r\n3 10 9 2 7 6 5 8 4 1\r\n1\r\n4\r\n", "output": "9 2\r\n"}, {"input": "10\r\n5 2 10 8 3 1 9 7 6 4\r\n9\r\n2 5 9 2 3 2 5 9 8\r\n", "output": "31 68\r\n"}, {"input": "9\r\n3 8 4 7 1 2 5 6 9\r\n3\r\n2 7 1\r\n", "output": "15 15\r\n"}, {"input": "9\r\n5 3 8 4 2 6 1 7 9\r\n4\r\n6 1 9 2\r\n", "output": "27 13\r\n"}, {"input": "4\r\n1 3 2 4\r\n4\r\n3 1 2 3\r\n", "output": "8 12\r\n"}, {"input": "3\r\n1 2 3\r\n8\r\n3 2 1 1 2 3 1 2\r\n", "output": "15 17\r\n"}]
false
stdio
null
true
316/B1
316
B2
PyPy 3
TESTS2
8
109
512,000
113604155
from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i n,x=map(int,input().split()) a=list(map(int,input().split())) for i in range(n): a[i]-=1 y=x-1 cnt=0 while y!=-1: cnt+=1 y=a[y] p=x-1 uf=UnionFind(n) for i in range(n): if a[i]!=-1: uf.union(i,a[i]) l=[] for t in uf.roots(): if not uf.same(t,p): l.append(uf.size(t)) ans=1 m=len(l) fenwick=Bit(m+1) for i in range(m): fenwick.add(i+1,l[i]) s=set() for l in range(1,m+1): for r in range(l,m+1): s.add(fenwick.sum(r)-fenwick.sum(l-1)) ans=sorted(list(s)) for i in range(len(ans)): ans[i]+=cnt ans=[cnt]+ans print(*ans,sep="\n")
29
78
102,400
3864056
n, x = map(int, input().split()) link1 = list(map(int, input().split())) link2 = [0] * (n + 1) for i, v in enumerate(link1, 1): if v != 0: link2[v] = i table = [False] * n table[0] = True for i, v in enumerate(link1, 1): if v == 0: len = 0 flag = False now = i while now: len += 1 if now == x: flag = True pos = len now = link2[now] if not flag: for j in reversed(range(n - len)): if table[j]: table[j + len] = True for i in range(n): if table[i]: print(i + pos)
ABBYY Cup 3.0
ICPC
2,013
0.5
256
EKG
In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another. (Cultural note: standing in huge and disorganized queues for hours is a native tradition in Russia, dating back to the Soviet period. Queues can resemble crowds rather than lines. Not to get lost in such a queue, a person should follow a strict survival technique: you approach the queue and ask who the last person is, somebody answers and you join the crowd. Now you're the last person in the queue till somebody else shows up. You keep an eye on the one who was last before you as he is your only chance to get to your destination) I'm sure many people have had the problem when a stranger asks who the last person in the queue is and even dares to hint that he will be the last in the queue and then bolts away to some unknown destination. These are the representatives of the modern world, in which the ratio of lack of time is so great that they do not even watch foreign top-rated TV series. Such people often create problems in queues, because the newcomer does not see the last person in the queue and takes a place after the "virtual" link in this chain, wondering where this legendary figure has left. The Smart Beaver has been ill and he's made an appointment with a therapist. The doctor told the Beaver the sad news in a nutshell: it is necessary to do an electrocardiogram. The next day the Smart Beaver got up early, put on the famous TV series on download (three hours till the download's complete), clenched his teeth and bravely went to join a queue to the electrocardiogram room, which is notorious for the biggest queues at the clinic. Having stood for about three hours in the queue, the Smart Beaver realized that many beavers had not seen who was supposed to stand in the queue before them and there was a huge mess. He came up to each beaver in the ECG room queue and asked who should be in front of him in the queue. If the beaver did not know his correct position in the queue, then it might be his turn to go get an ECG, or maybe he should wait for a long, long time... As you've guessed, the Smart Beaver was in a hurry home, so he gave you all the necessary information for you to help him to determine what his number in the queue can be.
The first line contains two integers n (1 ≤ n ≤ 103) and x (1 ≤ x ≤ n) — the number of beavers that stand in the queue and the Smart Beaver's number, correspondingly. All willing to get to the doctor are numbered from 1 to n. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ n) — the number of the beaver followed by the i-th beaver. If ai = 0, then the i-th beaver doesn't know who is should be in front of him. It is guaranteed that values ai are correct. That is there is no cycles in the dependencies. And any beaver is followed by at most one beaver in the queue. The input limits for scoring 30 points are (subproblem B1): - It is guaranteed that the number of zero elements ai doesn't exceed 20. The input limits for scoring 100 points are (subproblems B1+B2): - The number of zero elements ai is arbitrary.
Print all possible positions of the Smart Beaver in the line in the increasing order.
null
Picture for the fourth test.
[{"input": "6 1\n2 0 4 0 6 0", "output": "2\n4\n6"}, {"input": "6 2\n2 3 0 5 6 0", "output": "2\n5"}, {"input": "4 1\n0 0 0 0", "output": "1\n2\n3\n4"}, {"input": "6 2\n0 0 1 0 4 5", "output": "1\n3\n4\n6"}]
1,500
["brute force", "dfs and similar"]
29
[{"input": "6 1\r\n2 0 4 0 6 0\r\n", "output": "2\r\n4\r\n6\r\n"}, {"input": "6 2\r\n2 3 0 5 6 0\r\n", "output": "2\r\n5\r\n"}, {"input": "4 1\r\n0 0 0 0\r\n", "output": "1\r\n2\r\n3\r\n4\r\n"}, {"input": "6 2\r\n0 0 1 0 4 5\r\n", "output": "1\r\n3\r\n4\r\n6\r\n"}, {"input": "10 7\r\n10 8 6 5 0 0 0 4 3 9\r\n", "output": "1\r\n5\r\n6\r\n10\r\n"}, {"input": "10 1\r\n8 7 0 2 0 10 0 0 3 5\r\n", "output": "2\r\n4\r\n5\r\n7\r\n8\r\n10\r\n"}, {"input": "10 4\r\n0 1 4 2 7 0 10 0 5 8\r\n", "output": "3\r\n4\r\n8\r\n9\r\n"}, {"input": "10 2\r\n0 7 0 10 8 0 4 2 3 0\r\n", "output": "4\r\n5\r\n6\r\n7\r\n8\r\n"}, {"input": "10 2\r\n10 0 9 0 0 4 2 6 8 0\r\n", "output": "1\r\n2\r\n3\r\n4\r\n6\r\n7\r\n8\r\n9\r\n"}, {"input": "10 7\r\n7 9 2 10 0 0 0 3 5 1\r\n", "output": "1\r\n2\r\n6\r\n7\r\n"}, {"input": "20 20\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n", "output": "1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n"}]
false
stdio
null
true
316/B1
316
B2
PyPy 3
TESTS2
5
155
512,000
47025435
import math import sys from bisect import bisect_right, bisect_left, insort_right from collections import Counter, defaultdict from heapq import heappop, heappush from itertools import accumulate, permutations from sys import stdout R = lambda: map(int, input().split()) n, s = R() seq = [0] + list(R()) incm = [0] * (n + 1) for x in seq: if x: incm[x] = 1 sz = [0] * (n + 1) st = [] bs = 1 x = s while seq[x]: bs += 1 x = seq[x] for i, x in enumerate(incm): foundx = False if not x: l = i while i: foundx = foundx or i == s sz[l] += 1 i = seq[i] if seq[l] and not foundx: st.append(sz[l]) nz = seq.count(0) - 1 - len(st) - 1 pos = [0] * (n + 1) for p in st: for i in range(n + 1): if bs + i + p < n + 1 and pos[bs + i]: pos[bs + i + p] = 1 pos[bs + p] = 1 rp = [0] * (n + 1) rp[bs] = 1 if bs + nz + 1 < n + 1: rp[bs + nz + 1] = -1 for i in range(n + 1): if pos[i]: rp[i] += 1 if i + nz + 1 < n + 1: rp[i + nz + 1] -= 1 for i in range(1, n + 1): rp[i] += rp[i - 1] for i in range(1, n + 1): if rp[i]: print(i)
29
93
3,788,800
183947154
import sys input = sys.stdin.readline from collections import Counter def f(t): global xx q = [t] c = 0 while q: a = q.pop() xx[a] = 1 c += 1 for i in d[a]: if xx[i] == 0: q.append(i) return c n, x = map(int, input().split()) w = list(map(int, input().split())) d = [[] for i in range(n)] for i in range(n): if w[i] != 0: d[w[i]-1].append(i) d[i].append(w[i]-1) if i == x-1: c1 = 1 while 1: if w[i] == 0: break i = w[i] - 1 c1 += 1 xx = [0]*n s = [] f(x-1) for i in range(n): if xx[i] == 0: s.append(f(i)) s = Counter(s) a = {c1} for i in s: b = a.copy() for j in b: for l in range(1, s[i]+1): a.add(l*i+j) for i in sorted(a): print(i)
ABBYY Cup 3.0
ICPC
2,013
0.5
256
EKG
In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another. (Cultural note: standing in huge and disorganized queues for hours is a native tradition in Russia, dating back to the Soviet period. Queues can resemble crowds rather than lines. Not to get lost in such a queue, a person should follow a strict survival technique: you approach the queue and ask who the last person is, somebody answers and you join the crowd. Now you're the last person in the queue till somebody else shows up. You keep an eye on the one who was last before you as he is your only chance to get to your destination) I'm sure many people have had the problem when a stranger asks who the last person in the queue is and even dares to hint that he will be the last in the queue and then bolts away to some unknown destination. These are the representatives of the modern world, in which the ratio of lack of time is so great that they do not even watch foreign top-rated TV series. Such people often create problems in queues, because the newcomer does not see the last person in the queue and takes a place after the "virtual" link in this chain, wondering where this legendary figure has left. The Smart Beaver has been ill and he's made an appointment with a therapist. The doctor told the Beaver the sad news in a nutshell: it is necessary to do an electrocardiogram. The next day the Smart Beaver got up early, put on the famous TV series on download (three hours till the download's complete), clenched his teeth and bravely went to join a queue to the electrocardiogram room, which is notorious for the biggest queues at the clinic. Having stood for about three hours in the queue, the Smart Beaver realized that many beavers had not seen who was supposed to stand in the queue before them and there was a huge mess. He came up to each beaver in the ECG room queue and asked who should be in front of him in the queue. If the beaver did not know his correct position in the queue, then it might be his turn to go get an ECG, or maybe he should wait for a long, long time... As you've guessed, the Smart Beaver was in a hurry home, so he gave you all the necessary information for you to help him to determine what his number in the queue can be.
The first line contains two integers n (1 ≤ n ≤ 103) and x (1 ≤ x ≤ n) — the number of beavers that stand in the queue and the Smart Beaver's number, correspondingly. All willing to get to the doctor are numbered from 1 to n. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ n) — the number of the beaver followed by the i-th beaver. If ai = 0, then the i-th beaver doesn't know who is should be in front of him. It is guaranteed that values ai are correct. That is there is no cycles in the dependencies. And any beaver is followed by at most one beaver in the queue. The input limits for scoring 30 points are (subproblem B1): - It is guaranteed that the number of zero elements ai doesn't exceed 20. The input limits for scoring 100 points are (subproblems B1+B2): - The number of zero elements ai is arbitrary.
Print all possible positions of the Smart Beaver in the line in the increasing order.
null
Picture for the fourth test.
[{"input": "6 1\n2 0 4 0 6 0", "output": "2\n4\n6"}, {"input": "6 2\n2 3 0 5 6 0", "output": "2\n5"}, {"input": "4 1\n0 0 0 0", "output": "1\n2\n3\n4"}, {"input": "6 2\n0 0 1 0 4 5", "output": "1\n3\n4\n6"}]
1,500
["brute force", "dfs and similar"]
29
[{"input": "6 1\r\n2 0 4 0 6 0\r\n", "output": "2\r\n4\r\n6\r\n"}, {"input": "6 2\r\n2 3 0 5 6 0\r\n", "output": "2\r\n5\r\n"}, {"input": "4 1\r\n0 0 0 0\r\n", "output": "1\r\n2\r\n3\r\n4\r\n"}, {"input": "6 2\r\n0 0 1 0 4 5\r\n", "output": "1\r\n3\r\n4\r\n6\r\n"}, {"input": "10 7\r\n10 8 6 5 0 0 0 4 3 9\r\n", "output": "1\r\n5\r\n6\r\n10\r\n"}, {"input": "10 1\r\n8 7 0 2 0 10 0 0 3 5\r\n", "output": "2\r\n4\r\n5\r\n7\r\n8\r\n10\r\n"}, {"input": "10 4\r\n0 1 4 2 7 0 10 0 5 8\r\n", "output": "3\r\n4\r\n8\r\n9\r\n"}, {"input": "10 2\r\n0 7 0 10 8 0 4 2 3 0\r\n", "output": "4\r\n5\r\n6\r\n7\r\n8\r\n"}, {"input": "10 2\r\n10 0 9 0 0 4 2 6 8 0\r\n", "output": "1\r\n2\r\n3\r\n4\r\n6\r\n7\r\n8\r\n9\r\n"}, {"input": "10 7\r\n7 9 2 10 0 0 0 3 5 1\r\n", "output": "1\r\n2\r\n6\r\n7\r\n"}, {"input": "20 20\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n", "output": "1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n"}]
false
stdio
null
true
629/B
629
B
Python 3
TESTS
2
46
5,120,000
18163604
from sys import * inp = lambda : stdin.readline() N = 368 def main(): n = int(inp()) m = [0 for i in range(N)] f = m[:] for i in range(n): s = inp().split() if s[0] == 'M': m[int(s[1])] = 1 m[int(s[2])+1] = -1 else: f[int(s[1])] = 1 f[int(s[2])+1] = -1 myet,fyet,ans = 0,0,0 for i in range(1,N): myet += m[i] fyet += f[i] if fyet == myet: ans = max(2*fyet,ans) print(ans) if __name__ == "__main__": main()
76
62
0
16239840
arrMa=[0]*367 arrFe=[0]*367 p=int(input()) for i in range(p): inf=list(map(str,input().split())) if inf[0]=='M': arrMa[int(inf[1])-1]+=1 arrMa[int(inf[2])]-=1 else: arrFe[int(inf[1])-1]+=1 arrFe[int(inf[2])]-=1 maxi=-1 curM=0 curF=0 for i in range(366): curM+=arrMa[i] curF+=arrFe[i] if min(curM,curF)>maxi: maxi=min(curM,curF) print(maxi*2)
Codeforces Round 343 (Div. 2)
CF
2,016
2
256
Far Relative’s Problem
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≤ ai ≤ bi ≤ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive.
Print the maximum number of people that may come to Famil Door's party.
null
In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
[{"input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128", "output": "2"}, {"input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200", "output": "4"}]
1,100
["brute force"]
76
[{"input": "4\r\nM 151 307\r\nF 343 352\r\nF 117 145\r\nM 24 128\r\n", "output": "2\r\n"}, {"input": "6\r\nM 128 130\r\nF 128 131\r\nF 131 140\r\nF 131 141\r\nM 131 200\r\nM 140 200\r\n", "output": "4\r\n"}, {"input": "1\r\nF 68 307\r\n", "output": "0\r\n"}, {"input": "40\r\nM 55 363\r\nF 117 252\r\nM 157 282\r\nF 322 345\r\nM 330 363\r\nF 154 231\r\nF 216 352\r\nF 357 365\r\nM 279 292\r\nF 353 359\r\nF 82 183\r\nM 78 297\r\nM 231 314\r\nM 107 264\r\nF 34 318\r\nM 44 244\r\nF 42 339\r\nM 253 307\r\nM 128 192\r\nF 119 328\r\nM 135 249\r\nF 303 358\r\nF 348 352\r\nF 8 364\r\nF 126 303\r\nM 226 346\r\nF 110 300\r\nF 47 303\r\nF 201 311\r\nF 287 288\r\nM 270 352\r\nM 227 351\r\nF 8 111\r\nF 39 229\r\nM 163 315\r\nF 269 335\r\nF 147 351\r\nF 96 143\r\nM 97 99\r\nM 177 295\r\n", "output": "22\r\n"}, {"input": "2\r\nF 1 1\r\nM 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\nM 1 2\r\nM 2 3\r\nF 3 4\r\nF 4 5\r\n", "output": "2\r\n"}, {"input": "1\r\nF 1 2\r\n", "output": "0\r\n"}, {"input": "18\r\nF 3 4\r\nF 3 4\r\nF 3 4\r\nF 3 4\r\nF 5 6\r\nF 5 6\r\nM 3 4\r\nM 3 4\r\nM 5 6\r\nM 5 6\r\nM 5 6\r\nM 5 6\r\nF 7 8\r\nF 7 8\r\nF 7 8\r\nM 7 8\r\nM 7 8\r\nM 7 8\r\n", "output": "6\r\n"}, {"input": "2\r\nM 1 1\r\nF 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\nM 1 1\r\nF 1 1\r\nM 1 1\r\n", "output": "2\r\n"}]
false
stdio
null
true
282/A
282
A
PyPy 3
TESTS
6
78
0
231316618
def calc(n, x, arr, i): if arr[i][0] == '+': x += 1 n -= 1 if n == 0: return x elif arr[i][-1] == '+': n -= 1 if n == 0: return x x += 1 elif arr[i][0] == '-': x -= 1 n -= 1 if n == 0: return x elif arr[i][-1] == '-': n -= 1 if n == 0: return x x -= 1 return calc(n, x, arr, i + 1) n = int(input()) arr = [] for _ in range(n): s = input() arr.append(s) print(calc(n, 0, arr, 0))
36
31
0
227592533
x = int(input()) cnt = 0 for i in range(x): s = input() if s.find('+') == -1: cnt = cnt-1 else: cnt = cnt + 1 print(cnt)
Codeforces Round 173 (Div. 2)
CF
2,013
1
256
Bit++
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: - Operation ++ increases the value of variable x by 1. - Operation -- decreases the value of variable x by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme. Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Print a single integer — the final value of x.
null
null
[{"input": "1\n++X", "output": "1"}, {"input": "2\nX++\n--X", "output": "0"}]
800
["implementation"]
36
[{"input": "1\r\n++X\r\n", "output": "1\r\n"}, {"input": "2\r\nX++\r\n--X\r\n", "output": "0\r\n"}, {"input": "3\r\n++X\r\n++X\r\n++X\r\n", "output": "3\r\n"}, {"input": "2\r\n--X\r\n--X\r\n", "output": "-2\r\n"}, {"input": "5\r\n++X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "-1\r\n"}, {"input": "28\r\nX--\r\n++X\r\nX++\r\nX++\r\nX++\r\n--X\r\n--X\r\nX++\r\nX--\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\nX--\r\n++X\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n--X\r\n++X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX++\r\n", "output": "4\r\n"}, {"input": "94\r\nX++\r\nX++\r\n++X\r\n++X\r\nX--\r\n--X\r\nX++\r\n--X\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\nX++\r\n--X\r\nX--\r\nX--\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX++\r\n++X\r\n--X\r\nX--\r\n++X\r\n--X\r\n--X\r\nX--\r\nX--\r\nX++\r\nX++\r\nX--\r\nX++\r\nX--\r\nX--\r\nX--\r\n--X\r\nX--\r\nX--\r\nX--\r\nX++\r\n++X\r\nX--\r\n++X\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n++X\r\nX--\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\n--X\r\nX--\r\n++X\r\nX--\r\nX--\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\n++X\r\n--X\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX++\r\n", "output": "-10\r\n"}, {"input": "56\r\n--X\r\nX--\r\n--X\r\n--X\r\nX--\r\nX--\r\n--X\r\nX++\r\n++X\r\n--X\r\nX++\r\nX--\r\n--X\r\n++X\r\n--X\r\nX--\r\nX--\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n--X\r\n++X\r\nX++\r\nX++\r\n--X\r\nX++\r\nX--\r\n--X\r\nX--\r\n--X\r\nX++\r\n++X\r\n--X\r\n++X\r\nX++\r\nX--\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n--X\r\nX--\r\n--X\r\nX++\r\n--X\r\n++X\r\n--X\r\n", "output": "-14\r\n"}, {"input": "59\r\nX--\r\n--X\r\nX++\r\n++X\r\nX--\r\n--X\r\n--X\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\n++X\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\nX++\r\n--X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\nX++\r\nX--\r\nX--\r\n--X\r\nX++\r\nX--\r\nX--\r\n++X\r\nX--\r\nX++\r\n--X\r\nX++\r\nX--\r\nX--\r\nX--\r\nX--\r\n++X\r\n--X\r\nX++\r\nX++\r\nX--\r\nX++\r\n++X\r\nX--\r\nX++\r\nX--\r\nX--\r\n++X\r\n", "output": "3\r\n"}, {"input": "87\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\nX--\r\n++X\r\n--X\r\n--X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\n++X\r\n++X\r\n--X\r\n++X\r\n--X\r\nX--\r\n++X\r\n++X\r\nX--\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX--\r\n++X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX--\r\nX--\r\nX--\r\nX++\r\n--X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\nX++\r\n++X\r\nX--\r\n--X\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX++\r\nX++\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX--\r\n--X\r\n++X\r\n++X\r\n", "output": "-5\r\n"}, {"input": "101\r\nX++\r\nX++\r\nX++\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX--\r\n--X\r\n--X\r\n++X\r\nX++\r\n++X\r\n++X\r\nX--\r\n--X\r\n++X\r\nX++\r\nX--\r\n++X\r\n--X\r\n--X\r\n--X\r\n++X\r\n--X\r\n++X\r\nX++\r\nX++\r\n++X\r\n--X\r\nX++\r\nX--\r\nX++\r\n++X\r\n++X\r\nX--\r\nX--\r\nX--\r\nX++\r\nX++\r\nX--\r\nX--\r\nX++\r\n++X\r\n++X\r\n++X\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\n++X\r\nX++\r\n++X\r\nX--\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n++X\r\n--X\r\nX++\r\n++X\r\nX--\r\n++X\r\nX--\r\n++X\r\nX++\r\nX--\r\n++X\r\nX++\r\n--X\r\nX++\r\nX++\r\n++X\r\n--X\r\n++X\r\n--X\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\n++X\r\n++X\r\n--X\r\nX--\r\nX--\r\nX--\r\nX--\r\n--X\r\n--X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "1\r\n"}, {"input": "63\r\n--X\r\nX--\r\n++X\r\n--X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX++\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX--\r\n++X\r\nX++\r\nX--\r\n--X\r\nX--\r\n++X\r\n++X\r\nX++\r\n++X\r\nX++\r\nX++\r\n--X\r\nX--\r\n++X\r\nX--\r\n--X\r\nX--\r\nX--\r\nX--\r\n++X\r\n++X\r\n++X\r\n++X\r\nX++\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\n++X\r\n++X\r\nX--\r\n++X\r\n++X\r\nX--\r\n", "output": "1\r\n"}, {"input": "45\r\n--X\r\n++X\r\nX--\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\n--X\r\nX++\r\n++X\r\nX--\r\n++X\r\n++X\r\nX--\r\nX++\r\nX--\r\n--X\r\nX--\r\n++X\r\n++X\r\n--X\r\n--X\r\nX--\r\nX--\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\n--X\r\n--X\r\nX--\r\n++X\r\n++X\r\nX++\r\nX++\r\n++X\r\n++X\r\nX++\r\n", "output": "-3\r\n"}, {"input": "21\r\n++X\r\nX++\r\n--X\r\nX--\r\nX++\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX--\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\n--X\r\nX--\r\n--X\r\nX++\r\n++X\r\n", "output": "1\r\n"}, {"input": "100\r\n--X\r\n++X\r\nX++\r\n++X\r\nX--\r\n++X\r\nX--\r\nX++\r\n--X\r\nX++\r\nX--\r\nX--\r\nX--\r\n++X\r\nX--\r\nX++\r\nX++\r\n++X\r\nX++\r\nX++\r\nX++\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\n--X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\nX--\r\nX++\r\nX++\r\nX++\r\n++X\r\n--X\r\n++X\r\nX++\r\nX--\r\n++X\r\n++X\r\n--X\r\n++X\r\nX--\r\nX--\r\nX--\r\nX++\r\nX--\r\nX--\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\n--X\r\nX--\r\n--X\r\n++X\r\n--X\r\n++X\r\n++X\r\nX--\r\n--X\r\n++X\r\n++X\r\n--X\r\n--X\r\n++X\r\nX++\r\nX--\r\nX++\r\nX--\r\nX++\r\nX++\r\n--X\r\nX--\r\nX--\r\n++X\r\nX--\r\n--X\r\n--X\r\nX++\r\n--X\r\n--X\r\nX--\r\nX--\r\n++X\r\n++X\r\nX--\r\n++X\r\nX++\r\n--X\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\nX++\r\n", "output": "8\r\n"}, {"input": "17\r\nX++\r\nX++\r\n++X\r\n--X\r\n--X\r\n++X\r\n++X\r\n--X\r\nX--\r\nX++\r\nX--\r\n--X\r\n--X\r\nX--\r\n++X\r\nX--\r\nX++\r\n", "output": "-1\r\n"}, {"input": "77\r\n++X\r\nX++\r\n--X\r\nX--\r\n--X\r\n--X\r\nX--\r\nX++\r\nX--\r\nX++\r\nX--\r\n++X\r\n--X\r\n--X\r\n--X\r\n--X\r\n++X\r\nX--\r\nX++\r\nX--\r\n--X\r\nX--\r\n--X\r\nX--\r\n++X\r\n--X\r\n++X\r\n++X\r\nX++\r\nX++\r\nX--\r\n--X\r\nX--\r\nX--\r\nX++\r\n--X\r\n--X\r\n++X\r\nX--\r\nX--\r\n++X\r\nX++\r\nX--\r\n++X\r\n--X\r\nX++\r\nX--\r\n++X\r\n++X\r\n++X\r\nX--\r\nX--\r\nX--\r\n--X\r\n++X\r\n++X\r\n++X\r\nX++\r\n--X\r\n--X\r\n++X\r\n--X\r\nX--\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\nX++\r\nX++\r\n--X\r\nX++\r\nX++\r\nX++\r\n--X\r\nX++\r\nX--\r\n", "output": "-5\r\n"}, {"input": "21\r\nX--\r\n++X\r\n--X\r\nX--\r\n++X\r\nX--\r\n++X\r\nX--\r\n--X\r\n++X\r\nX++\r\n++X\r\nX++\r\n++X\r\nX--\r\n--X\r\nX++\r\nX++\r\nX--\r\n++X\r\nX--\r\n", "output": "1\r\n"}, {"input": "1\r\nX--\r\n", "output": "-1\r\n"}]
false
stdio
null
true
22/D
22
D
Python 3
TESTS
39
46
0
149056782
n = int(input()) cuie = [] siruri = [] nr = 0 actual = [-0.5, -0.5] for k in range(n): i, j = input().split() if int(i)>int(j): i, j = j, i siruri.append([int(i), int(j)]) siruri.sort(key=lambda x: x[1]) for i in range(n): if actual[1] < siruri[i][0]: if actual[1] != -0.5: cuie.append(actual[1]) nr += 1 actual = siruri[i] else: actual[0] = max(actual[0], siruri[i][0]) actual[1] = min(actual[1],siruri[i][1]) if i == n-1: nr += 1 cuie.append(actual[1]) print(nr) print(*cuie)
40
46
0
198822549
n=int(input()) a=[] for i in range(n): s=input() a.append([int(x) for x in s.split()]) if a[i][0]>a[i][1]: x=a[i][0] a[i][0]=a[i][1] a[i][1]=x a.sort(key=lambda x:x[1]) s=[a[0][1]] i=0 for x in a[1:]: if s[i]>x[1] or s[i]<x[0]: s.append(x[1]) i+=1 print(len(s)," ".join([str(x) for x in s]),sep="\n")
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 needed to nail all the segments down?
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\n22 6\r\n-32 36\r\n49 -37\r\n43 62\r\n", "output": "2\r\n22 58 "}, {"input": "10\r\n47 -85\r\n71 40\r\n-87 64\r\n76 73\r\n52 -51\r\n-20 -57\r\n-14 -77\r\n-45 -11\r\n-56 -48\r\n81 20\r\n", "output": "4\r\n-48 -11 71 76 "}, {"input": "1\r\n0 0\r\n", "output": "1\r\n0 "}, {"input": "4\r\n1 1\r\n0 0\r\n10000 10000\r\n-10000 -10000\r\n", "output": "4\r\n-10000 0 1 10000 "}, {"input": "3\r\n55 55\r\n55 55\r\n55 55\r\n", "output": "1\r\n55 "}, {"input": "4\r\n55 55\r\n55 55\r\n55 55\r\n55 56\r\n", "output": "1\r\n55 "}, {"input": "1\r\n-2244 5023\r\n", "output": "1\r\n5023 "}]
false
stdio
null
true
651/B
651
B
Python 3
TESTS
11
46
7,065,600
130838845
from collections import defaultdict n = int(input()) values = sorted(list(map(int, input().split()))) counts = defaultdict(int) num_counts = defaultdict(int) res = 0 max_val = 0 for value in values: max_val = max(max_val, value) counts[value] += 1 num_counts[counts[value]] += 1 for i in range(1, max_val): if num_counts[i]: res += (num_counts[i] - 1) print(res)
31
46
0
132049611
n = int(input().strip()) a = list(map(int, input().strip().split())) d = {} for i in a: if i in d.keys(): d[i] += 1 else: d[i] = 1 lst = [] for i in d.keys(): lst.append(d[i]) print(n - max(lst))
Codeforces Round 345 (Div. 2)
CF
2,016
1
256
Beautiful Paintings
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one. We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1), such that ai + 1 > ai.
The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting.
Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
null
In the first sample, the optimal order is: 10, 20, 30, 40, 50. In the second sample, the optimal order is: 100, 200, 100, 200.
[{"input": "5\n20 30 10 50 40", "output": "4"}, {"input": "4\n200 100 100 200", "output": "2"}]
1,200
["greedy", "sortings"]
31
[{"input": "5\r\n20 30 10 50 40\r\n", "output": "4\r\n"}, {"input": "4\r\n200 100 100 200\r\n", "output": "2\r\n"}, {"input": "10\r\n2 2 2 2 2 2 2 2 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "2\r\n444 333\r\n", "output": "1\r\n"}, {"input": "100\r\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14\r\n", "output": "95\r\n"}, {"input": "1\r\n995\r\n", "output": "0\r\n"}, {"input": "10\r\n103 101 103 103 101 102 100 100 101 104\r\n", "output": "7\r\n"}, {"input": "20\r\n102 100 102 104 102 101 104 103 100 103 105 105 100 105 100 100 101 105 105 102\r\n", "output": "15\r\n"}, {"input": "20\r\n990 994 996 999 997 994 990 992 990 993 992 990 999 999 992 994 997 990 993 998\r\n", "output": "15\r\n"}, {"input": "100\r\n1 8 3 8 10 8 5 3 10 3 5 8 4 5 5 5 10 3 6 6 6 6 6 7 2 7 2 4 7 8 3 8 7 2 5 6 1 5 5 7 9 7 6 9 1 8 1 3 6 5 1 3 6 9 5 6 8 4 8 6 10 9 2 9 3 8 7 5 2 10 2 10 3 6 5 5 3 5 10 2 3 7 10 8 8 4 3 4 9 6 10 7 6 6 6 4 9 9 8 9\r\n", "output": "84\r\n"}]
false
stdio
null
true
65/D
65
D
PyPy 3-64
TESTS
0
31
0
219356581
N = int(input()) buf = input() TWO = (1 << 14) - 1 house = ["Gryffindor", "Hufflepuff", "Ravenclaw", "Slytherin"] a = [-1] * N for i in range(N): for j in range(4): if buf[i] == house[j][0]: a[i] = j dp = [set() for _ in range(N + 1)] ans = set() def func(st, pos): x = st a1 = (x & TWO); x >>= 14 a2 = (x & TWO); x >>= 14 a3 = (x & TWO); x >>= 14 a4 = (x & TWO); x >>= 14 if pos == N: if a1 <= a2 and a1 <= a3 and a1 <= a4: ans.add(house[0]) if a2 <= a1 and a2 <= a3 and a2 <= a4: ans.add(house[1]) if a3 <= a1 and a3 <= a2 and a3 <= a4: ans.add(house[2]) if a4 <= a1 and a4 <= a2 and a4 <= a3: ans.add(house[3]) return if a[pos] == -1: if a1 <= a2 and a1 <= a3 and a1 <= a4: dp[pos + 1].add(st + (1 << 0)) if a2 <= a1 and a2 <= a3 and a2 <= a4: dp[pos + 1].add(st + (1 << 14)) if a3 <= a1 and a3 <= a2 and a3 <= a4: dp[pos + 1].add(st + (1 << 28)) if a4 <= a1 and a4 <= a2 and a4 <= a3: dp[pos + 1].add(st + (1 << 42)) else: dp[pos + 1].add(st + (1 << (14 * a[pos]))) dp[0].add(0) for i in range(N + 1): for st in dp[i]: func(st, i) for house_name in ans: print(house_name)# 1692294126.2977755
66
139
7,782,400
173624984
n = input() inputs = input() first_letter_to_index = { 'G': 0, 'H': 1, 'R': 2, 'S': 3 } pos = {(0, 0, 0, 0)} # call possibilities for first_letter in inputs: size = len(pos) new_pos = [] if first_letter in first_letter_to_index: idx = first_letter_to_index[first_letter] for p in pos: clone = list(p) clone[idx] += 1 new_pos.append(tuple(clone)) else: for p in pos: least = min(p) index_least = [i for i, x in enumerate(p) if x == least] for index in index_least: clone = list(p) clone[index] += 1 new_pos.append(tuple(clone)) pos = set(new_pos) res = set() for p in pos: least = min(p) index_least = [i for i, x in enumerate(p) if x == least] res.update(index_least) full_houses = ['Gryffindor', 'Hufflepuff', 'Ravenclaw', 'Slytherin'] print('\n'.join([full_houses[idx] for idx in sorted(list(res))]))
Codeforces Beta Round 60
CF
2,011
2
256
Harry Potter and the Sorting Hat
As you know, Hogwarts has four houses: Gryffindor, Hufflepuff, Ravenclaw and Slytherin. The sorting of the first-years into houses is done by the Sorting Hat. The pupils are called one by one in the alphabetical order, each of them should put a hat on his head and, after some thought, the hat solemnly announces the name of the house the student should enter. At that the Hat is believed to base its considerations on the student's personal qualities: it sends the brave and noble ones to Gryffindor, the smart and shrewd ones — to Ravenclaw, the persistent and honest ones — to Hufflepuff and the clever and cunning ones — to Slytherin. However, a first year student Hermione Granger got very concerned about the forthcoming sorting. She studied all the literature on the Sorting Hat and came to the conclusion that it is much simpler than that. If the relatives of the student have already studied at Hogwarts, the hat puts the student to the same house, where his family used to study. In controversial situations, when the relatives studied in different houses or when they were all Muggles like Hermione's parents, then the Hat sorts the student to the house, to which the least number of first years has been sent at that moment. If there are several such houses, the choice is given to the student himself. Then the student can choose any of the houses, to which the least number of first years has been sent so far. Hermione has already asked the students that are on the list before her about their relatives. Now she and her new friends Harry Potter and Ron Weasley want to find out into what house the Hat will put Hermione.
The first input line contains an integer n (1 ≤ n ≤ 10000). It is the number of students who are in the list before Hermione. The next line contains n symbols. If all the relatives of a student used to study in the same house, then the i-th character in the string coincides with the first letter of the name of this house. Otherwise, the i-th symbol is equal to "?".
Print all the possible houses where Hermione can be sent. The names of the houses should be printed in the alphabetical order, one per line.
null
Consider the second example. There are only two students before Hermione. The first student is sent to Hufflepuff. The second disciple is given the choice between the houses where the least number of students has been sent, i.e. Gryffindor, Slytherin and Ravenclaw. If he chooses Gryffindor, Hermione is forced to choose between Ravenclaw and Slytherin, if he chooses Ravenclaw, Hermione will choose between Gryffindor and Slytherin, if he chooses Slytherin, Hermione will choose between Gryffindor and Ravenclaw. In the end, the following situation is possible (it depends on the choice of the second student and Hermione). Hermione will end up 1) in Gryffindor, 2) in Ravenclaw, 3) in Slytherin. Note that, despite the fact that in neither case Hermione will be given a choice between all the three options, they are all possible and they should all be printed in the answer. Hermione will not, under any circumstances, end up in Hufflepuff.
[{"input": "11\nG????SS???H", "output": "Gryffindor\nRavenclaw"}, {"input": "2\nH?", "output": "Gryffindor\nRavenclaw\nSlytherin"}]
2,200
["brute force", "dfs and similar", "hashing"]
66
[{"input": "11\r\nG????SS???H\r\n", "output": "Gryffindor\r\nRavenclaw\r\n"}, {"input": "2\r\nH?\r\n", "output": "Gryffindor\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "1\r\n?\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "1\r\nG\r\n", "output": "Hufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "3\r\nGHS\r\n", "output": "Ravenclaw\r\n"}, {"input": "4\r\n????\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "5\r\nGH??S\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\n"}, {"input": "5\r\nH?S?G\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "7\r\n???????\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "10\r\n??HS??HSGR\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "55\r\n??RS?HGH?S?GS?HRGHRHRR?G?GSGSSHGS?HRSHRSR?HGHGRH?GGGHHH\r\n", "output": "Ravenclaw\r\nSlytherin\r\n"}, {"input": "108\r\n??RS?HGH?S?GS?HRGHRHRR?G?GSGSSHGS?HRSHRSR?HGHGRH??????????????RS?HGH?S?GS?HRGHRHRR?G?GSGSSHGS?HRSHRSR?HGHGRH\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "20\r\n?HH?RH???HG??G?RG?H?\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "20\r\nGSGHGRHHGRHRSGRRRHGS\r\n", "output": "Slytherin\r\n"}, {"input": "50\r\nS?HRHSGHRHS?GRRG?GSHHR?RRRHG?S?S?G?GR????GG?HS?HRG\r\n", "output": "Hufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "50\r\n?SR?SRR?RGSH?R?RSHRSRR?GS?H??GH??????G?HG??G??RSRH\r\n", "output": "Gryffindor\r\nHufflepuff\r\nSlytherin\r\n"}, {"input": "50\r\n?GGGS???????????S?????G????H??SRG?????????G???????\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "50\r\n?????????S??????????????S?????????????????GS??????\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "50\r\n?SRSRRSRSHRRH?GHSHGGRSH?G?HRHH??RG?RHSGHRRGGHSGHHR\r\n", "output": "Slytherin\r\n"}, {"input": "50\r\n?SHGHRRGHGSGSR?G?HHHHHSHGGSRSSGHH?RHRRSRSRRGHS?HSS\r\n", "output": "Gryffindor\r\nRavenclaw\r\n"}, {"input": "100\r\nGSHRR?SRRRHGHGRGRGHGGHRHR?SSGGHRSGSGGGRRRRSSG?RRSRSGSGHSSGHRHRHSSRHSRSR??SRHSSHRGG?RRGHSSHSRGHSSRRHG\r\n", "output": "Gryffindor\r\nHufflepuff\r\n"}, {"input": "100\r\nGHHRHGS??H?GR?G?G?HHSR?SG?SR?SSSSS?G?G?RG?SHHHGR??SRHGGSRSHS?HR?HSGGSSHRR?G?RR?G?SRGGHSSSR?SGSGGS???\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\n"}, {"input": "100\r\n??RH?S?HH?RGHR?HS?RHH?GRGRRGSSRSG??S???HSSS?S?SH??RGGSSGRHGGG?SGR??HRGRGH?R?GSGHSRHHRHSS??S?HGHRHHSG\r\n", "output": "Gryffindor\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "100\r\n?RSGG??R?GGGRRGHHH?SGRGRSRHGGSRS??RS?GHSRRSRRGHH?HG?GRGSHS?GSHGSGRGRRHHGHRSRG?SSG?SRHS?S??RHS?HGH?SH\r\n", "output": "Gryffindor\r\nRavenclaw\r\n"}, {"input": "100\r\nRSS??RSGGH?RGHRG?SGSHSH?HRR?R?SSG?GRRSRR???SHRG??R?SG??GSR??HR?HSSRHHRGGR?G?GR??SH?R??SHHRS?HHHG??SH\r\n", "output": "Gryffindor\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "100\r\nR?H?GGGHG?H?RGSS?GS??S??HS?S??GRRH?HSGRHRS?GS??GRS?SGRHSGS?HHGS???HG?GG?HRGRRG?SSGH??R?GR?SR?GH?HHR?\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "100\r\nHGR?RHS?HSS?RRH?R?GS?GG??S????GG???GRR?HSGG?H?SS?RSG?G?H?RGH?RS?GRSHRH?SGH??G??H?G?H?G?GSH?SRRHSGRR?\r\n", "output": "Gryffindor\r\nHufflepuff\r\nSlytherin\r\n"}, {"input": "100\r\n??SRHG?R??????S????RHR?GHGHH??H?SSHRR??R?GR?S?HGGR?H??S??G???H???SSR?R??R??GSHSRS?H??SRS???????SR??R\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "100\r\nHR????G?HHRGH??S?R?HH?GH?GSG?R???GHH?HS?S?S?GR??R?HRHRGG?G?????S?H??HSSS??G??SG???S?S?S?RH?HR?HHHG??\r\n", "output": "Gryffindor\r\nRavenclaw\r\nSlytherin\r\n"}, {"input": "100\r\nSHRSR??SRGGGS???GRSRRSS??S??SH?GSSR?G?RHS?R?SRS??SS?G?G?H?S?GHR?GSGR?GRHR?H??SG???SSRH?GR??SSS?SS??H\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\n"}, {"input": "20\r\n?G?S???R?S??HRHH???R\r\n", "output": "Gryffindor\r\nHufflepuff\r\nRavenclaw\r\nSlytherin\r\n"}]
false
stdio
null
true
859/G
859
G
Python 3
PRETESTS
0
61
512,000
30402062
import random def f(): if (random.randint(1, 2) == 1): print("YES"); else: print("NO") n = int(input()) a = list(map(int, input().split())) f()
70
93
6,144,000
227486527
def factor(n): ps = [] for i in range(2, n): if i * i > n: break if n % i == 0: e = 0 while n % i == 0: e += 1 n //= i ps += [(i, e)] if n > 1: ps += [(n, 1)] return ps n = int(input()) a = list(map(int, input())) ps = factor(n) P = 1 for p, _ in ps: P *= p Q = n // P for p, _ in ps: k = (1 - pow(P // p, -1, p) * (P // p)) % P for r in range(Q): for i in range(0, P, p): for j in range(1, p): a[r + (i + j) * Q] -= a[r + ((i + j * k) % P) * Q] for i in range(0, P, p): a[r + i * Q] = 0 print("YES" if all(x == 0 for x in a) else "NO")
MemSQL Start[c]UP 3.0 - Round 1
CF
2,017
1
256
Circle of Numbers
n evenly spaced points have been marked around the edge of a circle. There is a number written at each point. You choose a positive real number k. Then you may repeatedly select a set of 2 or more points which are evenly spaced, and either increase all numbers at points in the set by k or decrease all numbers at points in the set by k. You would like to eventually end up with all numbers equal to 0. Is it possible? A set of 2 points is considered evenly spaced if they are diametrically opposed, and a set of 3 or more points is considered evenly spaced if they form a regular polygon.
The first line of input contains an integer n (3 ≤ n ≤ 100000), the number of points along the circle. The following line contains a string s with exactly n digits, indicating the numbers initially present at each of the points, in clockwise order.
Print "YES" (without quotes) if there is some sequence of operations that results in all numbers being 0, otherwise "NO" (without quotes). You can print each letter in any case (upper or lower).
null
If we label the points from 1 to n, then for the first test case we can set k = 1. Then we increase the numbers at points 7 and 22 by 1, then decrease the numbers at points 7, 17, and 27 by 1, then decrease the numbers at points 4, 10, 16, 22, and 28 by 1.
[{"input": "30\n000100000100000110000000001100", "output": "YES"}, {"input": "6\n314159", "output": "NO"}]
3,000
["math"]
70
[{"input": "30\r\n000100000100000110000000001100\r\n", "output": "YES\r\n"}, {"input": "6\r\n314159\r\n", "output": "NO\r\n"}, {"input": "3\r\n000\r\n", "output": "YES\r\n"}, {"input": "15\r\n522085220852208\r\n", "output": "YES\r\n"}, {"input": "300\r\n518499551238825328417663140237955446550596254299485115465325550413577584420893115025535675971808926451691055930219585997807344070011845434733526017118933548589759649920016568578201769564228210045739230664506968281414229830885120812000132083367912869773547090902954497697057079934454847714732943455588\r\n", "output": "NO\r\n"}, {"input": "16\r\n0110100110010110\r\n", "output": "NO\r\n"}, {"input": "6\r\n564837\r\n", "output": "YES\r\n"}, {"input": "9\r\n975975975\r\n", "output": "YES\r\n"}, {"input": "10\r\n0414240506\r\n", "output": "YES\r\n"}, {"input": "33\r\n459847811604598478116045984781160\r\n", "output": "YES\r\n"}, {"input": "54\r\n668822125317092836839407462257441103728473858428026440\r\n", "output": "YES\r\n"}, {"input": "147\r\n258714573455458660598376355525847569123841578643535970557335666766056747734652574877812381067963453587176633563586704774763586157484691337206786466\r\n", "output": "YES\r\n"}, {"input": "171\r\n570962255153238631524151841322466383830411184871666785642671862254254138630625051840423366382931311183972566784743571861355154137731525050941323365483831310284872565885643\r\n", "output": "YES\r\n"}, {"input": "256\r\n0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110\r\n", "output": "NO\r\n"}, {"input": "5\r\n66666\r\n", "output": "YES\r\n"}, {"input": "9\r\n735358934\r\n", "output": "NO\r\n"}, {"input": "18\r\n008697913853945708\r\n", "output": "NO\r\n"}, {"input": "32\r\n63227607169607744763319434680883\r\n", "output": "NO\r\n"}, {"input": "55\r\n3051191835797699222829630849704721747109367868763178250\r\n", "output": "NO\r\n"}, {"input": "124\r\n4087853659974995340862097721504457205060797709029986511524903183441846431857346142268549624240693503777827416946735887323115\r\n", "output": "NO\r\n"}, {"input": "191\r\n13749871615832352185918872672752947110954476837054206370341509698888491814630432290010512405256834335260576808366797121146435132126443422459679991449630693949793303863445042394342711401003212\r\n", "output": "NO\r\n"}, {"input": "488\r\n45334958248886256215245432812097462402188584275950565932256169435872815051620433766475524373331668138254775135319898212744118387896269009559223646980708720716169171410452756878161887568810441524371550690928477055425661664202050311645854048922622038301574832340035693673614973249646168547494526620934733803262859266238709131053471167257719634461068324341221207027892565402615143073772528401151209845684767396920588208903922337152277526342947329398157696709654980477214668927347471119604451\r\n", "output": "NO\r\n"}, {"input": "3\r\n007\r\n", "output": "NO\r\n"}, {"input": "4\r\n0500\r\n", "output": "NO\r\n"}, {"input": "6\r\n700000\r\n", "output": "NO\r\n"}]
false
stdio
null
true
514/D
514
D
PyPy 3-64
TESTS
3
46
0
209047341
def build_log(n): dp = [0] * (n + 1) dp[1] = 0 for i in range(2, n + 1): dp[i] = dp[i // 2] + 1 return dp class SparseTable: def __init__(self, lg, fn): self.lg = lg self.fn = fn def build(self, arr): dp = [dict() for _ in range(len(arr))] for i in range(len(arr)): dp[i][0] = arr[i] def helper(idx, l): if l in dp[idx]: return dp[idx][l] dp[idx][l] = self.fn( helper(idx, l - 1), helper(idx + (1 << (l - 1)), l - 1) ) return dp[idx][l] for i in range(len(arr)): helper(i, self.lg[len(arr) - i]) def query(l, r): k = self.lg[r - l + 1] return self.fn(dp[l][k], dp[r - 2**k + 1][k]) return query def solve(): n, m, k = map(int, input().split()) lg = build_log(n) arr = [[] for _ in range(m)] for _ in range(n): details = list(map(int, input().split())) for i in range(m): arr[i].append(details[i]) t = [] for lst in arr: t.append(SparseTable(lg, max).build(lst)) idx = -1 max_len = k l = 1 r = n + 1 while l < r: m = (l + r) // 2 can_shot = False for i in range(0, n - m + 1): s = sum([q(i, i + m - 1) for q in t]) if s <= k: can_shot = True idx = i max_len = m break if not can_shot: r = m else: l = m + 1 if idx == -1: return shots = [q(idx, idx + max_len - 1) for q in t] print(" ".join(map(str, shots))) solve()
35
1,996
120,217,600
192669643
def rl(): return list(map(int,input().split())) def ri(): return int(input()) def rs(): return input() def rm(): return map(int,input().split()) from math import log2,floor def main(): n,l,k=rm() rb=[] for i in range(n): rb.append(rl()) rb=[[rb[i][j] for i in range(len(rb))] for j in range(len(rb[0]))] m=floor(log2(n))+1 tbs=[] for ii in range(l): tb=[[0 for _ in range(m)]for _ in range(n)] for i in range(n): tb[i][0]=rb[ii][i] for j in range(1,m): for i in range(n): if i+(1<<j)>n: break tb[i][j]=max(tb[i][j-1],tb[i+(1<<(j-1))][j-1]) tbs.append(tb) def query(l,r,m): p=floor(log2(r+1-l)) return max(tbs[m][l][p],tbs[m][r-(1<<p)+1][p]) def ok(ln): for i in range(n-ln+1): rq=0 for j in range(l): rq+=query(i,i+ln-1,j) if rq<=k: return True return False rs=[] if ok(n): for i in range(l): rs.append(query(0,n-1,i)) return rs if not ok(1): return [0]*l lo,hi=1,n while lo<hi-1: md=(lo+hi)//2 if ok(md): lo=md else: hi=md # print(lo) for i in range(n-lo+1): rq=[] for j in range(l): rq.append(query(i,i+lo-1,j)) # print(rq) if sum(rq)<=k: return rq print(*main())
Codeforces Round 291 (Div. 2)
CF
2,015
2
256
R2D2 and Droid Army
An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, where ai is the number of details of the i-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has m weapons, the i-th weapon can affect all the droids in the army by destroying one detail of the i-th type (if the droid doesn't have details of this type, nothing happens to it). A droid is considered to be destroyed when all of its details are destroyed. R2-D2 can make at most k shots. How many shots from the weapon of what type should R2-D2 make to destroy the sequence of consecutive droids of maximum length?
The first line contains three integers n, m, k (1 ≤ n ≤ 105, 1 ≤ m ≤ 5, 0 ≤ k ≤ 109) — the number of droids, the number of detail types and the number of available shots, respectively. Next n lines follow describing the droids. Each line contains m integers a1, a2, ..., am (0 ≤ ai ≤ 108), where ai is the number of details of the i-th type for the respective robot.
Print m space-separated integers, where the i-th number is the number of shots from the weapon of the i-th type that the robot should make to destroy the subsequence of consecutive droids of the maximum length. If there are multiple optimal solutions, print any of them. It is not necessary to make exactly k shots, the number of shots can be less.
null
In the first test the second, third and fourth droids will be destroyed. In the second test the first and second droids will be destroyed.
[{"input": "5 2 4\n4 0\n1 2\n2 1\n0 2\n1 3", "output": "2 2"}, {"input": "3 2 4\n1 2\n1 3\n2 2", "output": "1 3"}]
2,000
["binary search", "data structures", "two pointers"]
35
[{"input": "5 2 4\r\n4 0\r\n1 2\r\n2 1\r\n0 2\r\n1 3\r\n", "output": "2 2\r\n"}, {"input": "3 2 4\r\n1 2\r\n1 3\r\n2 2\r\n", "output": "1 3\r\n"}, {"input": "1 1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n0\r\n", "output": "0\r\n"}, {"input": "4 5 33\r\n2 10 2 3 2\r\n10 6 4 5 0\r\n3 1 7 3 2\r\n4 4 2 1 5\r\n", "output": "10 6 7 5 5\r\n"}, {"input": "4 5 40\r\n0 10 9 0 4\r\n10 5 5 7 4\r\n9 9 5 5 2\r\n6 7 9 4 3\r\n", "output": "10 10 9 7 4\r\n"}, {"input": "31 2 1913\r\n845 576\r\n862 325\r\n914 283\r\n431 837\r\n193 171\r\n30 248\r\n290 488\r\n810 552\r\n463 74\r\n765 469\r\n785 119\r\n107 267\r\n528 761\r\n583 395\r\n359 45\r\n840 559\r\n147 510\r\n882 830\r\n267 390\r\n639 47\r\n849 312\r\n518 6\r\n643 828\r\n195 886\r\n377 948\r\n333 841\r\n484 99\r\n486 999\r\n134 342\r\n736 490\r\n624 677\r\n", "output": "914 999\r\n"}, {"input": "49 2 1971\r\n794 866\r\n401 575\r\n341 83\r\n103 208\r\n352 134\r\n260 878\r\n497 931\r\n630 570\r\n885 464\r\n23 663\r\n60 775\r\n416 870\r\n955 405\r\n392 961\r\n530 258\r\n73 404\r\n736 923\r\n44 436\r\n594 314\r\n904 138\r\n980 163\r\n76 720\r\n879 809\r\n81 838\r\n263 599\r\n218 139\r\n659 493\r\n848 754\r\n656 302\r\n490 7\r\n204 530\r\n184 758\r\n114 849\r\n80 649\r\n653 439\r\n961 350\r\n104 387\r\n482 441\r\n628 972\r\n451 503\r\n367 926\r\n50 332\r\n855 991\r\n528 261\r\n131 447\r\n551 841\r\n963 962\r\n253 979\r\n700 218\r\n", "output": "980 991\r\n"}, {"input": "1 5 264566327\r\n35969364 23665385 95351498 57005692 52574389\r\n", "output": "0 0 0 0 0\r\n"}, {"input": "1 5 240247522\r\n48772229 15259125 4834706 88633344 82748118\r\n", "output": "48772229 15259125 4834706 88633344 82748118\r\n"}, {"input": "1 5 211500111\r\n18123011 48739518 50372830 20177276 74087475\r\n", "output": "18123011 48739518 50372830 20177276 74087475\r\n"}]
false
stdio
null
true
53/A
53
A
PyPy 3
TESTS
15
310
20,172,800
87268071
s = str(input()) n = int(input()) T = [str(input()) for i in range(n)] T = [(len(t), t) for t in T] T.sort(key=lambda x: (x[0], x[1])) for _, t in T: if t.startswith(s): print(t) exit() else: print(s)
25
92
0
136649994
#!/usr/bin/env python # coding=utf-8 ''' Author: Deean Date: 2021-11-23 23:23:28 LastEditTime: 2021-11-23 23:27:49 Description: Autocomplete FilePath: CF53A.py ''' def func(): inputted = input().strip() n = int(input()) lst = [] for _ in range(n): visited = input().strip() if visited.startswith(inputted): lst.append(visited) if len(lst) == 0: print(inputted) else: print(sorted(lst)[0]) if __name__ == '__main__': func()
Codeforces Beta Round 49 (Div. 2)
CF
2,011
2
256
Autocomplete
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of n last visited by the user pages and the inputted part s are known. Your task is to complete s to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix s.
The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.
If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages.
null
null
[{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}]
1,100
["implementation"]
25
[{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r\nszjebdoad\r\nchz\r\na\r\n", "output": "kudljmxcse\r\n"}, {"input": "ntqwpa\r\n5\r\nvvepyowvn\r\nntqwpakay\r\nhh\r\nygiafasda\r\nntqwpadm\r\n", "output": "ntqwpadm\r\n"}, {"input": "aflb\r\n6\r\nsaej\r\nujxsiijg\r\npp\r\nhgoprw\r\ncp\r\nnt\r\n", "output": "aflb\r\n"}, {"input": "dzwzyj\r\n7\r\nwvixktp\r\ndzwzyjuhn\r\ndzwzyjqrbd\r\ndzwzyji\r\ndzwzyjyfys\r\ndzwzyjrcb\r\nxptb\r\n", "output": "dzwzyji\r\n"}, {"input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n1\r\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn\r\n", "output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n"}, {"input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\r\n1\r\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n", "output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n"}, {"input": "msjnqudojxtzvpc\r\n2\r\nvlxclsvqbucmbrkwwtoxek\r\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n", "output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n"}]
false
stdio
null
true
977/E
977
E
PyPy 3-64
TESTS
17
701
74,444,800
225900118
import sys from collections import defaultdict def set_bit(bitmap, index): bitmap[index >> 6] |= 1 << (index & 63) def clear_bit(bitmap, index): bitmap[index >> 6] &= ~(1 << (index & 63)) def get_bit(bitmap, index): return bitmap[index >> 6] & (1 << (index & 63)) def bit_scan_forward(bitmap): return bin(bitmap)[::-1].index('1') def choose_edge(graph, last_node, current_node): if graph[current_node][0] == last_node: return graph[current_node][1] else: return graph[current_node][0] def check_valid(graph, point1, point2): if (edges[point1][0] == -1 or edges[point1][1] == -1) and (edges[point2][0] == -1 or edges[point2][1] == -1): return True else: return False in_f = sys.stdin.read(-1).replace("\r\n", "\r") in_f = in_f.split() n, m = int(in_f[0]), int(in_f[1]) # valid_nodes = [0 for i in range(n)] valid_nodes = [0 for i in range((n + 63) // 64)] edges = defaultdict(lambda: [-1, -1]) cycles = 0 for edge in range(2, 2*m+2, 2): p1, p2 = int(in_f[edge]) - 1, int(in_f[edge + 1]) - 1 if check_valid(edges, p1, p2): edges[p1][edges[p1].index(-1)] = p2 edges[p2][edges[p2].index(-1)] = p1 if edges[p1].count(-1) == 0: set_bit(valid_nodes, p1) if edges[p2].count(-1) == 0: set_bit(valid_nodes, p2) else: clear_bit(valid_nodes, p1) clear_bit(valid_nodes, p2) i = 0 while i < n: if valid_nodes[i >> 6] == 0: i += 64 - (i & 63) continue i += bit_scan_forward(valid_nodes[i >> 6] >> (i & 63)) last_node = -1 current_node = i while True: clear_bit(valid_nodes, current_node) node = choose_edge(edges, last_node, current_node) last_node = current_node current_node = node if not get_bit(valid_nodes, current_node): if current_node == i: cycles += 1 break print(cycles)
35
655
74,444,800
225901870
import sys from collections import defaultdict # LOAD DATA IN LIST WITH 2 POINTS # IF THERE IS 3rd POINT IN EDGE TURN BOTH POINTS INVALID # node[a] = [c, b] + d # turn a and d invalid # keep check of invalid points in bitmap # 0 - 63 => 0 # 64 - 127 => 1 def set_bit(bitmap, index): bitmap[index >> 6] |= 1 << (index & 63) def clear_bit(bitmap, index): bitmap[index >> 6] &= ~(1 << (index & 63)) def get_bit(bitmap, index): return bitmap[index >> 6] & (1 << (index & 63)) def bit_scan_forward(bitmap): return bin(bitmap)[::-1].index('1') def choose_edge(graph, last_node, current_node): if graph[current_node][0] == last_node: return graph[current_node][1] else: return graph[current_node][0] in_f = sys.stdin.read(-1).replace("\r\n", "\r") in_f = in_f.split() n, m = int(in_f[0]), int(in_f[1]) # valid_nodes = [0 for i in range(n)] valid_nodes = [0 for i in range((n + 63) // 64)] edges = defaultdict(lambda: [-1, -1]) cycles = 0 for edge in range(2, 2*m+2, 2): p1, p2 = int(in_f[edge]) - 1, int(in_f[edge + 1]) - 1 if edges[p1][0] == -1: edges[p1][0] = p2 elif edges[p1][1] == -1: edges[p1][1] = p2 set_bit(valid_nodes, p1) else: clear_bit(valid_nodes, p1) if edges[p2][0] == -1: edges[p2][0] = p1 elif edges[p2][1] == -1: edges[p2][1] = p1 set_bit(valid_nodes, p2) else: clear_bit(valid_nodes, p2) i = 0 while i < n: if valid_nodes[i >> 6] == 0: i += 64 - (i & 63) continue i += bit_scan_forward(valid_nodes[i >> 6] >> (i & 63)) last_node = -1 current_node = i while True: clear_bit(valid_nodes, current_node) node = choose_edge(edges, last_node, current_node) last_node = current_node current_node = node if current_node == -1 or not get_bit(valid_nodes, current_node): if current_node == i: cycles += 1 break print(cycles)
Codeforces Round 479 (Div. 3)
ICPC
2,018
2
256
Cyclic Components
You are given an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. Your task is to find the number of connected components which are cycles. Here are some definitions of graph theory. An undirected graph consists of two sets: set of nodes (called vertices) and set of edges. Each edge connects a pair of vertices. All edges are bidirectional (i.e. if a vertex $$$a$$$ is connected with a vertex $$$b$$$, a vertex $$$b$$$ is also connected with a vertex $$$a$$$). An edge can't connect vertex with itself, there is at most one edge between a pair of vertices. Two vertices $$$u$$$ and $$$v$$$ belong to the same connected component if and only if there is at least one path along edges connecting $$$u$$$ and $$$v$$$. A connected component is a cycle if and only if its vertices can be reordered in such a way that: - the first vertex is connected with the second vertex by an edge, - the second vertex is connected with the third vertex by an edge, - ... - the last vertex is connected with the first vertex by an edge, - all the described edges of a cycle are distinct. A cycle doesn't contain any other edges except described above. By definition any cycle contains three or more vertices. There are $$$6$$$ connected components, $$$2$$$ of them are cycles: $$$[7, 10, 16]$$$ and $$$[5, 11, 9, 15]$$$.
The first line contains two integer numbers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) — number of vertices and edges. The following $$$m$$$ lines contains edges: edge $$$i$$$ is given as a pair of vertices $$$v_i$$$, $$$u_i$$$ ($$$1 \le v_i, u_i \le n$$$, $$$u_i \ne v_i$$$). There is no multiple edges in the given graph, i.e. for each pair ($$$v_i, u_i$$$) there no other pairs ($$$v_i, u_i$$$) and ($$$u_i, v_i$$$) in the list of edges.
Print one integer — the number of connected components which are also cycles.
null
In the first example only component $$$[3, 4, 5]$$$ is also a cycle. The illustration above corresponds to the second example.
[{"input": "5 4\n1 2\n3 4\n5 4\n3 5", "output": "1"}, {"input": "17 15\n1 8\n1 12\n5 11\n11 9\n9 15\n15 5\n4 13\n3 13\n4 3\n10 16\n7 10\n16 7\n14 3\n14 4\n17 6", "output": "2"}]
1,500
["dfs and similar", "dsu", "graphs"]
35
[{"input": "5 4\r\n1 2\r\n3 4\r\n5 4\r\n3 5\r\n", "output": "1\r\n"}, {"input": "17 15\r\n1 8\r\n1 12\r\n5 11\r\n11 9\r\n9 15\r\n15 5\r\n4 13\r\n3 13\r\n4 3\r\n10 16\r\n7 10\r\n16 7\r\n14 3\r\n14 4\r\n17 6\r\n", "output": "2\r\n"}, {"input": "4 4\r\n1 2\r\n2 3\r\n1 3\r\n1 4\r\n", "output": "0\r\n"}, {"input": "5 5\r\n1 2\r\n2 3\r\n3 4\r\n4 1\r\n3 5\r\n", "output": "0\r\n"}, {"input": "200000 0\r\n", "output": "0\r\n"}, {"input": "1 0\r\n", "output": "0\r\n"}, {"input": "5 10\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 1\r\n1 4\r\n2 4\r\n3 5\r\n3 1\r\n2 5\r\n", "output": "0\r\n"}, {"input": "5 10\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n2 3\r\n2 4\r\n2 5\r\n3 4\r\n3 5\r\n4 5\r\n", "output": "0\r\n"}, {"input": "6 9\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 1\r\n6 2\r\n2 4\r\n6 4\r\n", "output": "0\r\n"}, {"input": "4 6\r\n1 2\r\n2 3\r\n3 4\r\n4 1\r\n1 3\r\n2 4\r\n", "output": "0\r\n"}]
false
stdio
null
true
21/C
21
C
Python 3
TESTS
15
140
10,649,600
124425973
n = int(input()) s = input().split() a = [] total = 0 for i in range(0, n) : a.append(int(s[i])) total += a[i] if (total % 3 != 0) : print(0) x = y = ans = 0 total //= 3 for i in range(0, n - 1) : x += a[i] if (x == total * 2) : ans += y if (x == total) : y += 1 print(ans)
35
77
12,288,000
215989463
def solve(n, num): a = [int(k) for k in num.split()] a.insert(0, 0) s = [0] * (n + 1) for i in range(1, n + 1): s[i] = s[i - 1] + a[i] total = s[n] ans, cnt = 0, 0 q = total * 2 / 3 if total % 3 != 0: return 0 for i in range(1, n): if s[i] == q and s[n] - s[i] == total / 3: ans += cnt if s[i] == total / 3: cnt += 1 return ans n = int(input()) num = input() result = solve(n, num) print(result)
Codeforces Alpha Round 21 (Codeforces format)
CF
2,010
1
64
Stripe 2
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?
The first input line contains integer n (1 ≤ n ≤ 105) — amount of squares in the stripe. The second line contains n space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output the amount of ways to cut the stripe into three non-empty pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
null
null
[{"input": "4\n1 2 3 3", "output": "1"}, {"input": "5\n1 2 3 4 5", "output": "0"}]
2,000
["binary search", "dp", "sortings"]
35
[{"input": "1\r\n-3\r\n", "output": "0\r\n"}, {"input": "2\r\n0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "1\r\n"}, {"input": "4\r\n-2 3 3 2\r\n", "output": "0\r\n"}, {"input": "5\r\n-6 3 -1 2 -7\r\n", "output": "0\r\n"}, {"input": "6\r\n2 3 -3 0 -3 1\r\n", "output": "0\r\n"}, {"input": "7\r\n-1 1 -3 4 3 0 2\r\n", "output": "0\r\n"}, {"input": "8\r\n2 0 0 2 -1 3 4 5\r\n", "output": "0\r\n"}, {"input": "9\r\n-5 -2 1 1 5 0 -4 4 0\r\n", "output": "3\r\n"}, {"input": "10\r\n-1 5 2 3 1 5 0 2 2 5\r\n", "output": "0\r\n"}]
false
stdio
null
true
620/C
620
C
Python 3
TESTS
13
46
102,400
227208945
def check(pearls): dic = { } c = 0 indexes = [0] for ind, char in enumerate(pearls): if char not in dic: dic[char] = ind+1 elif char in dic: c += 1 x = check_last(pearls[ind::]) if x: indexes.append(indexes[-1]+1) indexes.append(ind+1) else: indexes.append(indexes[-1]+1) indexes.append(len(pearls)) dic.clear() if c > 0: print(c) for i in range(1, len(indexes), 2): print(indexes[i], indexes[i+1]) else: print(-1) def check_last(pearls): for e in pearls: if pearls.count(e) > 1: return True return False number_of_pearls = int(input()) pearls = list(map(int, input().split())) check(pearls)
51
249
47,513,600
195910030
# 7 # 1 2 1 3 1 2 1 n=int(input()) l=[*map(int,input().split())] ans=[] ss = set() p=0 for i,v in enumerate(l): if v in ss: ss.clear() ans.append((p+1,i+1)) p = i+1 else: ss.add(v) if ans: print(len(ans)) for t in ans[:-1]: print(*t) print(ans[-1][0], n) else: print(-1)
Educational Codeforces Round 6
ICPC
2,016
2
256
Pearls in a Row
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl.
On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1".
null
null
[{"input": "5\n1 2 3 4 1", "output": "1\n1 5"}, {"input": "5\n1 2 3 4 5", "output": "-1"}, {"input": "7\n1 2 1 3 1 2 1", "output": "2\n1 3\n4 7"}]
1,500
["greedy"]
51
[{"input": "5\r\n1 2 3 4 1\r\n", "output": "1\r\n1 5\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "7\r\n1 2 1 3 1 2 1\r\n", "output": "2\r\n1 3\r\n4 7\r\n"}, {"input": "9\r\n1 2 1 2 1 2 1 2 1\r\n", "output": "3\r\n1 3\r\n4 6\r\n7 9\r\n"}, {"input": "11\r\n1 1 2 1 2 1 2 1 2 1 1\r\n", "output": "4\r\n1 2\r\n3 5\r\n6 8\r\n9 11\r\n"}, {"input": "1\r\n576560149\r\n", "output": "-1\r\n"}, {"input": "10\r\n460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451\r\n", "output": "5\r\n1 2\r\n3 4\r\n5 6\r\n7 8\r\n9 10\r\n"}, {"input": "10\r\n933677171 80672280 80672280 933677171 933677171 933677171 933677171 80672280 80672280 933677171\r\n", "output": "4\r\n1 3\r\n4 5\r\n6 7\r\n8 10\r\n"}, {"input": "10\r\n522312461 21923894 21923894 544064902 488228616 329635457 522312461 488228616 654502493 598654597\r\n", "output": "2\r\n1 3\r\n4 10\r\n"}, {"input": "7\r\n13 9 19 13 3 13 12\r\n", "output": "1\r\n1 7\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n1 3\r\n"}, {"input": "5\r\n1 2 2 2 3\r\n", "output": "1\r\n1 5\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n", "output": "1\r\n1 5\r\n"}, {"input": "13\r\n1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "6\r\n1 2\r\n3 4\r\n5 6\r\n7 8\r\n9 10\r\n11 13\r\n"}, {"input": "4\r\n1 2 1 2\r\n", "output": "1\r\n1 4\r\n"}]
false
stdio
import sys def read_file(path): with open(path, 'r') as f: lines = [line.strip() for line in f.readlines() if line.strip()] return lines def main(): input_path = sys.argv[1] ref_path = sys.argv[2] sub_path = sys.argv[3] input_lines = read_file(input_path) ref_lines = read_file(ref_path) sub_lines = read_file(sub_path) # Parse input n = int(input_lines[0]) a = list(map(int, input_lines[1].split())) # Parse reference output if not ref_lines: print(0) return k_ref = ref_lines[0] if k_ref == '-1': # Check if submission is -1 if not sub_lines: print(0) return k_sub = sub_lines[0] if k_sub == '-1': print(1) return else: print(0) return else: # Reference's k is not -1 if not sub_lines: print(0) return k_sub = sub_lines[0] if k_sub == '-1': print(0) return try: k_ref = int(k_ref) k_sub = int(k_sub) except: print(0) return if k_ref != k_sub: print(0) return # Now check the submission's segments # Parse submission's segments try: k = int(sub_lines[0]) if k != k_ref: print(0) return if k <= 0: print(0) return segments = [] for line in sub_lines[1:]: l, r = map(int, line.split()) segments.append((l, r)) except: print(0) return # Check the segments form a valid partition # Sort by l segments.sort(key=lambda x: x[0]) current = 1 for (l, r) in segments: if l > current or r < l or r > n: print(0) return if l != current: print(0) return current = r + 1 if current != n + 1: print(0) return # Check each segment is good for (l, r) in segments: if r - l + 1 < 2: print(0) return subarray = a[l-1 : r] seen = set() has_duplicate = False for x in subarray: if x in seen: has_duplicate = True break seen.add(x) if not has_duplicate: print(0) return # All checks passed print(1) if __name__ == "__main__": main()
true
216/E
216
E
Python 3
TESTS
6
404
1,433,600
11926306
k, b, n = map(int, input().split()) digits = list(map(int, input().split())) def conv(t): if t == 0: return k - 1 return t if b == 0: j = -1 answer = 0 for i in range(n): if digits[i] != 0 or i < j: continue j = i while j < n and digits[j] == 0: j += 1 r = j - i answer += r * (r + 1) // 2 print(answer) else: count = dict() count[0] = 1 pref_sum = 0 answer = 0 while len(digits) > 0 and digits[0] == 0: digits.pop(0) zeroes = 0 for d in digits: pref_sum = (pref_sum + d) % (k - 1) real_val = conv(pref_sum) need = (real_val - b) % (k - 1) # print(pref_sum, need) answer += count.get(need, 0) if need == 0: answer -= zeroes if d == 0: zeroes += 1 count[pref_sum] = count.get(pref_sum, 0) + 1 print(answer)
41
404
33,587,200
124785044
Line1 = list(map(int,input().split())) #Lee de consola la primera linea que contiene tres enteros(separados por espacios) que #en orden representan la base en la que se representan los numeros, el "digito de la suerte" y #la cantidad de digitos de la lista y los guarda el la variable Line1 como una lista List = list(map(int,input().split())) #Lee de consola la segunda linea donde estan los digitos(separaados por espacio) y los #guarda en la lista List def MartianLuck(k,b,n,digit_list): if b == 0: #Si el digito de la suerte es cero buscamos los subarrays que solo contienen ceros puesto que si se suma cualquier otra cifra #nunca se obtiene cero como raiz digital return Zero(n,digit_list) Subarray = dict() #Se crea un diccionario donde sus llaves son los valores de las raices digitales hasta ahora obtenidas en los subarrays #y los values son la cantidad de veces que hemos encontrado esta raiz digital en distintos subarrays Subarray[0]=1 #Inicialmente podemos asumir que tenemos una raiz digital de valor cero ya que esto nos ayudara con el algoritmo LuckyNumbersCounter = 0 ActualNumber = 0 #Inicializo el valor de la raiz digital actual(Como inicia en cero concuerda con que en eldictionary subarray aparezca ) for Digit in digit_list : #Se recorre la lista de digitos ActualNumber = (ActualNumber + Digit) % (k-1) #Se determina el valor de la raiz digital -1 de el subarray que inicia en 0 #hasta la posicion Digit Diference = (ActualNumber - b) % (k-1) #Se determina cual es el valor de la raiz digital -1 del complemento(Valor #que hay que restar a la actual raiz digital para que sea igual al digito de la suerte) LuckyNumbersCounter += Subarray.get(Diference,0) #Si el complemento anteriormente hallado esta en alguno(s) de los subarrays #digit_list[0]....digit_list[i] 0<=i<Digit(Entonces su para la llave Diference #el value indica cuantos subarrays cumplen esta condicion) entonces en dependencia #del value asociado a este Key es la cantidad de subarrays de la forma digit_list[i]....digit_list[Digit] #con raiz digital igual al digito de la suerte (b) Subarray[ActualNumber] = Subarray.get(ActualNumber,0) + 1 #Se incrementa el value asociado a la llave ActualNumber(es decir de la raiz digital actual) #En señal de que encontramos un subarray desde digit_list[0]...digit_list[Digit] cuya raiz digital es #ActualNumber para asi en futuras iteraciones si el complemento de esa raiz digital es este valor #Hayar entonces la cantidad de subarrays correctas al sumarle la cantidad de ocurrencias de este valor if b == k-1: #En caso de que el numero de la suerte b sea igual a las base en que estan representados los digitos - 1 entonces #Por la forma en que determinamos el valor de la raiz digital utilizando el resto sucede que (n-1)%(n-1)= 0 = 0%(n-1) por lo que # Contariamos los subarrays de ceros como valores correctos por lo que debemos a la cuenta actual restarle las soluciones que son cero return LuckyNumbersCounter - Zero(n,digit_list) return LuckyNumbersCounter #En caso contrario sencillamente devolvemos la solucion def Zero(n,digit_list): Digit_index = 0 #Inicializo el indice LuckyZeroNumbersCounter =0 #Inicializo el contador while Digit_index < n: #Se recorre el array count = 0 while Digit_index + count <n and digit_list[Digit_index + count] == 0: #cuando se encuentra un cero se empieza a contar el numero de ceros consecutivos count += 1 #el numero de subarrays que se obtiene en un array de k ceros consecutivos LuckyZeroNumbersCounter += count*(count +1) //2 #se puede determinar con la formula de la sumatoria de los numeros naturales hasta k Digit_index += count + 1 #Como el ciclo anterior se detiene al encontrar el primer digito que sea distinto de cero podemos iniciar la #proxima iteracion saltando a la posicion siguiente a en la que terminan los k ceros consecutivos return LuckyZeroNumbersCounter #Se devuelve la cantidad total de subarrays de ceros print(MartianLuck(Line1[0],Line1[1],Line1[2],List)) #Se imprime la solucion
Codeforces Round 133 (Div. 2)
CF
2,012
2
256
Martian Luck
You know that the Martians use a number system with base k. Digit b (0 ≤ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology). A digital root d(x) of number x is a number that consists of a single digit, resulting after cascading summing of all digits of number x. Word "cascading" means that if the first summing gives us a number that consists of several digits, then we sum up all digits again, and again, until we get a one digit number. For example, d(35047) = d((3 + 5 + 0 + 4)7) = d(157) = d((1 + 5)7) = d(67) = 67. In this sample the calculations are performed in the 7-base notation. If a number's digital root equals b, the Martians also call this number lucky. You have string s, which consists of n digits in the k-base notation system. Your task is to find, how many distinct substrings of the given string are lucky numbers. Leading zeroes are permitted in the numbers. Note that substring s[i... j] of the string s = a1a2... an (1 ≤ i ≤ j ≤ n) is the string aiai + 1... aj. Two substrings s[i1... j1] and s[i2... j2] of the string s are different if either i1 ≠ i2 or j1 ≠ j2.
The first line contains three integers k, b and n (2 ≤ k ≤ 109, 0 ≤ b < k, 1 ≤ n ≤ 105). The second line contains string s as a sequence of n integers, representing digits in the k-base notation: the i-th integer equals ai (0 ≤ ai < k) — the i-th digit of string s. The numbers in the lines are space-separated.
Print a single integer — the number of substrings that are lucky numbers. 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
In the first sample the following substrings have the sought digital root: s[1... 2] = "3 2", s[1... 3] = "3 2 0", s[3... 4] = "0 5", s[4... 4] = "5" and s[2... 6] = "2 0 5 6 1".
[{"input": "10 5 6\n3 2 0 5 6 1", "output": "5"}, {"input": "7 6 4\n3 5 0 4", "output": "1"}, {"input": "257 0 3\n0 0 256", "output": "3"}]
2,000
["math", "number theory"]
41
[{"input": "10 5 6\r\n3 2 0 5 6 1\r\n", "output": "5"}, {"input": "7 6 4\r\n3 5 0 4\r\n", "output": "1"}, {"input": "257 0 3\r\n0 0 256\r\n", "output": "3"}, {"input": "2 1 1\r\n0\r\n", "output": "0"}, {"input": "2 0 20\r\n1 1 1 0 1 1 1 1 0 0 0 0 1 0 0 0 0 1 0 1\r\n", "output": "22"}, {"input": "100 29 33\r\n28 89 23 14 97 97 66 56 55 60 47 29 9 79 26 80 63 78 83 60 41 29 52 10 82 26 47 88 99 75 52 1 31\r\n", "output": "10"}, {"input": "3 2 100\r\n2 0 0 0 0 2 1 1 1 2 0 1 1 1 1 2 0 0 1 0 1 1 2 0 2 0 1 0 1 0 0 2 0 0 0 1 2 0 2 2 0 2 0 2 1 0 1 1 1 1 2 0 0 0 1 0 2 0 2 0 2 1 2 2 1 1 0 1 1 2 1 1 0 0 1 1 2 2 1 2 2 0 1 2 2 1 2 2 0 2 0 2 2 0 2 2 1 2 0 0\r\n", "output": "2451"}, {"input": "5 4 102\r\n3 2 2 3 3 2 2 0 3 1 2 4 0 1 3 4 3 2 3 0 4 1 0 0 0 0 4 4 1 2 3 3 4 0 1 2 2 3 3 1 3 1 0 0 3 0 4 0 2 4 2 3 0 1 4 3 0 2 3 3 2 2 1 0 1 3 0 3 4 4 4 1 0 1 2 1 4 2 4 4 4 4 4 2 3 3 0 3 0 0 0 4 1 3 0 4 2 1 2 0 3 0\r\n", "output": "1293"}, {"input": "7 4 104\r\n4 3 0 6 6 5 3 4 4 5 0 1 2 5 5 1 3 4 1 5 3 5 4 4 2 4 3 5 4 2 2 3 1 1 0 5 4 3 2 5 2 1 3 1 6 4 1 3 0 2 5 2 5 3 3 6 1 2 2 2 4 5 6 0 5 4 5 3 5 3 4 3 1 0 2 4 5 5 5 5 3 3 6 1 6 1 3 6 6 5 3 3 1 3 2 0 4 4 3 3 4 0 5 6\r\n", "output": "938"}, {"input": "20 15 1\r\n6\r\n", "output": "0"}, {"input": "20 19 2\r\n16 13\r\n", "output": "0"}, {"input": "30 24 30\r\n7 24 3 20 8 24 0 6 15 22 20 21 16 26 28 6 6 28 19 2 12 22 6 12 15 17 24 13 12 16\r\n", "output": "20"}, {"input": "2 0 100\r\n0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 1 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0\r\n", "output": "331"}]
false
stdio
null
true
22/B
22
B
PyPy 3
TESTS
6
124
1,331,200
152861284
n,m=map(int,input().split()) MAP=[input().strip() for i in range(n)] S=[[0]*m for i in range(n)] for i in range(n): for j in range(m): if MAP[i][j]=="1": S[i][j]=1 for i in range(1,n): for j in range(m): S[i][j]+=S[i-1][j] for i in range(n): for j in range(1,m): S[i][j]+=S[i][j-1] ANS=0 for i in range(n): for j in range(m): for k in range(i,n): for l in range(j,m): if S[i][j]==S[k][l]: ANS=max(ANS,((k-i)+(l-j)+2)*2) print(ANS)
23
184
5,017,600
180511159
def goDown(start, i, j, l): rowsFound = 0 while i<n and sum(l[i][start:j+1])==0: # print(l[i][start:j+1], end = " ") rowsFound+=1 i+=1 # print("Rows Found:", rowsFound, end = " ") return rowsFound def start(i, j, n, m, l): j1 = j # print((i, j)) perimeter = 0 while j < m: # print(j1, j, perimeter, "width =", j-j1+1, "height:", goDown(j1, i+1, j, l) + 1, end = " ") if l[i][j] ==0: width = j-j1+1 height = goDown(j1, i+1, j, l) + 1 perimeter = max(perimeter, (2* (width + height))) # print("MAXI:", perimeter) else: j1 = j+1 # print("Looping:", perimeter) j+=1 # print(perimeter) return perimeter def solve(n, m, l): perimeter = 0 # print(l) for i in range(n): for j in range(m): # print(i, j, n, m) if l[i][j] == 0: perimeter = max(start(i, j, n, m, l), perimeter) print(perimeter) n, m = map(int, input().split()) l = [] for _ in range(n): s = input() row = [] for i in range(len(s)): row.append(int(s[i])) l.append(row) # print(l) solve(n, m, l)
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
2
256
Bargaining Table
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that its sides are parallel to the office walls. Bob doesn't want to change or rearrange anything, that's why all the squares that will be occupied by the table should be initially free. Bob wants the new table to sit as many people as possible, thus its perimeter should be maximal. Help Bob find out the maximum possible perimeter of a bargaining table for his office.
The first line contains 2 space-separated numbers n and m (1 ≤ n, m ≤ 25) — the office room dimensions. Then there follow n lines with m characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in the room is free.
Output one number — the maximum possible perimeter of a bargaining table for Bob's office room.
null
null
[{"input": "3 3\n000\n010\n000", "output": "8"}, {"input": "5 4\n1100\n0000\n0000\n0000\n0000", "output": "16"}]
1,500
["brute force", "dp"]
23
[{"input": "3 3\r\n000\r\n010\r\n000\r\n", "output": "8\r\n"}, {"input": "5 4\r\n1100\r\n0000\r\n0000\r\n0000\r\n0000\r\n", "output": "16\r\n"}, {"input": "3 3\r\n000\r\n110\r\n000\r\n", "output": "8\r\n"}, {"input": "4 2\r\n00\r\n10\r\n11\r\n00\r\n", "output": "6\r\n"}, {"input": "3 5\r\n00001\r\n00000\r\n10100\r\n", "output": "12\r\n"}, {"input": "1 1\r\n0\r\n", "output": "4\r\n"}, {"input": "10 11\r\n11111111101\r\n01111111111\r\n11101111111\r\n01111110111\r\n11111111111\r\n11111111111\r\n11111111111\r\n11110111111\r\n11111111111\r\n11111111111\r\n", "output": "4\r\n"}, {"input": "7 7\r\n1110111\r\n1111111\r\n1111101\r\n1111101\r\n1111111\r\n1100111\r\n1011111\r\n", "output": "6\r\n"}, {"input": "10 10\r\n0110001011\r\n0101010111\r\n0010110100\r\n1010000110\r\n0111100011\r\n1010100100\r\n1010010000\r\n1011100011\r\n1110011000\r\n0010100101\r\n", "output": "16\r\n"}, {"input": "25 1\r\n1\r\n1\r\n1\r\n0\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n0\r\n1\r\n1\r\n1\r\n1\r\n1\r\n0\r\n1\r\n1\r\n1\r\n0\r\n1\r\n1\r\n1\r\n1\r\n", "output": "4\r\n"}, {"input": "25 1\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n", "output": "52\r\n"}, {"input": "1 25\r\n1111111111111111011010110\r\n", "output": "4\r\n"}, {"input": "1 25\r\n0000000000000000000000000\r\n", "output": "52\r\n"}, {"input": "3 4\r\n1111\r\n1101\r\n1011\r\n", "output": "4\r\n"}]
false
stdio
null
true
205/B
205
B
Python 3
TESTS
6
46
0
143496719
n = int(input()) s = input().split() s = [int(i) for i in s] c = 0 i = 0 while(i< n-1): if(s[i] > s[i+1]): j = i+1 while(j<len(s) and s[j] < s[i]): j += 1 c += s[i]-min(s[i:j]) i = j else: i += 1 print(c)
45
77
13,516,800
215373812
n = int(input()) a = list(map(int, input().split())) moves = 0 for i in range(n - 1, 0, -1): if a[i] < a[i - 1]: moves += a[i - 1] - a[i] print(moves)
Codeforces Round 129 (Div. 2)
CF
2,012
0.5
256
Little Elephant and Sorting
The Little Elephant loves sortings. He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r. Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
In a single line print a single integer — the answer to the problem. 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
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0. In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]). In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
[{"input": "3\n1 2 3", "output": "0"}, {"input": "3\n3 2 1", "output": "2"}, {"input": "4\n7 4 1 47", "output": "6"}]
1,400
["brute force", "greedy"]
45
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "4\r\n7 4 1 47\r\n", "output": "6\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 1000000000\r\n", "output": "0\r\n"}, {"input": "10\r\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "4999999995\r\n"}, {"input": "7\r\n47 47 47 47 47 47 48\r\n", "output": "0\r\n"}, {"input": "47\r\n7 9 9 3 7 3 6 8 3 6 6 2 6 4 2 2 4 3 6 1 3 9 8 2 3 5 3 10 7 7 5 2 8 1 5 7 2 7 6 2 1 9 7 7 4 10 3\r\n", "output": "76\r\n"}, {"input": "74\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n940259367\r\n", "output": "0\r\n"}, {"input": "2\r\n710095427 879909817\r\n", "output": "0\r\n"}, {"input": "3\r\n39740000 928596641 251625421\r\n", "output": "676971220\r\n"}]
false
stdio
null
true
21/C
21
C
PyPy 3-64
TESTS
12
62
2,662,400
193181445
import sys; R = sys.stdin.readline def S(): return map(int,R().split()) n = int(R()) a = [0]+[*S()] for i in range(1,n+1): a[i] += a[i-1] if not a[n]: k = a.count(0) print((k-2)*(k-3)//2); exit() if a[n]<0: for i in range(1,n+1): a[i] *= -1 if not a[n]%3: r = 0 q = a[n]//3 dp = [1]+[0]*2 for i in range(n): if not a[i]%q: x = a[i]//q if x<3: dp[x] += dp[x-1] r += dp[-1] print(r) else: print(0)
35
77
14,950,400
227345166
n = int(input()) a = list(map(int, input().split())) s = sum(a) counter = 0 dots = [] dots2 = [] prsum = [] a1 = dict() k6 = 0 k3 = 0 c=0 if s % 3 == 0: target = s // 3 for i in range(n): if i == 0: prsum.append(a[0]) else: prsum.append(prsum[-1] + a[i]) #print(prsum) #print(prsum.count(target//3)) ''' if counter==target: dots.append(i) counter=0 print(dots) for x in dots: counter=0 for x1 in range(x+1,n): print(a[x1],counter,x1) counter+=a[x1] if counter == target: dots2.append([x,x1]) print(dots,dots2)''' for i in prsum: c+=1 if i == target * 2 and c!=1 and c!=len(prsum): counter+=k3 if i == target: k3 += 1 '''k6 += 1''' '''a1[i] = k3 for i in prsum: if i == target * 2: counter += a1[i]''' print(counter) else: print(0)
Codeforces Alpha Round 21 (Codeforces format)
CF
2,010
1
64
Stripe 2
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?
The first input line contains integer n (1 ≤ n ≤ 105) — amount of squares in the stripe. The second line contains n space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output the amount of ways to cut the stripe into three non-empty pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
null
null
[{"input": "4\n1 2 3 3", "output": "1"}, {"input": "5\n1 2 3 4 5", "output": "0"}]
2,000
["binary search", "dp", "sortings"]
35
[{"input": "1\r\n-3\r\n", "output": "0\r\n"}, {"input": "2\r\n0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "1\r\n"}, {"input": "4\r\n-2 3 3 2\r\n", "output": "0\r\n"}, {"input": "5\r\n-6 3 -1 2 -7\r\n", "output": "0\r\n"}, {"input": "6\r\n2 3 -3 0 -3 1\r\n", "output": "0\r\n"}, {"input": "7\r\n-1 1 -3 4 3 0 2\r\n", "output": "0\r\n"}, {"input": "8\r\n2 0 0 2 -1 3 4 5\r\n", "output": "0\r\n"}, {"input": "9\r\n-5 -2 1 1 5 0 -4 4 0\r\n", "output": "3\r\n"}, {"input": "10\r\n-1 5 2 3 1 5 0 2 2 5\r\n", "output": "0\r\n"}]
false
stdio
null
true
659/D
659
D
Python 3
TESTS
6
46
0
27274368
def Izquierda(pos,D,R): c = 0 for k in range (1,pos): ax= D[k-1] ay= R[k-1] bx= D[k] by= R[k] cx= D[k+1] cy= R[k+1] if ((ax==bx and ay<by) and (by==cy and cx<bx)) or ((ay==by and ax<bx) and (bx==cx and by<cy)) or ((ax==bx and ay>by) and (by ==cy and bx<cx)) : c += 1 return c def Derecha(pos,D,R): c = 0 for k in range (pos,n): ax= D[k-1] ay= R[k-1] bx= D[k] by= R[k] cx= D[k+1] cy= R[k+1] if ((ay==by and ax>bx) and (bx==cx and by>cy)) or ((ax==bx and ay>by) and (by ==cy and bx<cx)) or ((ax==bx and ay<by) and (by ==cy and bx>cx)): c += 1 return c n = int(input()) pointsdom = [] pointsran = [] maximo = 0 p=0 for k in range (n+1): l = input() l = l.split() if int(l[0])>maximo: maximo = int(l[0]) p = k if int(l[1])>maximo: maximo=int(l[1]) p = k pointsdom.append(int(l[0])) pointsran.append(int(l[1])) Izq =Izquierda(p,pointsdom,pointsran) Der =Derecha(p,pointsdom,pointsran) print(Izq+Der)
22
31
0
150142923
n = int(input()) xi, yi = [], [] for _ in range(n + 1): x, y = map(int,input().split()) xi.append(x) yi.append(y) ans = 0 for i in range(2, n): if ((xi[i-1]-xi[i-2])*(yi[i]-yi[i-2])-(xi[i]-xi[i-2])*(yi[i-1]-yi[i-2]))>0: ans += 1 print(ans)
Codeforces Round 346 (Div. 2)
CF
2,016
1
256
Bicycle Race
Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west. Let's introduce a system of coordinates, directing the Ox axis from west to east, and the Oy axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa). Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored. Help Maria get ready for the competition — determine the number of dangerous turns on the track.
The first line of the input contains an integer n (4 ≤ n ≤ 1000) — the number of straight sections of the track. The following (n + 1)-th line contains pairs of integers (xi, yi) ( - 10 000 ≤ xi, yi ≤ 10 000). The first of these points is the starting position. The i-th straight section of the track begins at the point (xi, yi) and ends at the point (xi + 1, yi + 1). It is guaranteed that: - the first straight section is directed to the north; - the southernmost (and if there are several, then the most western of among them) point of the track is the first point; - the last point coincides with the first one (i.e., the start position); - any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point); - no pair of points (except for the first and last one) is the same; - no two adjacent straight sections are directed in the same direction or in opposite directions.
Print a single integer — the number of dangerous turns on the track.
null
The first sample corresponds to the picture: The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1.
[{"input": "6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0", "output": "1"}, {"input": "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1", "output": "6"}]
1,500
["geometry", "implementation", "math"]
22
[{"input": "6\r\n0 0\r\n0 1\r\n1 1\r\n1 2\r\n2 2\r\n2 0\r\n0 0\r\n", "output": "1\r\n"}, {"input": "16\r\n1 1\r\n1 5\r\n3 5\r\n3 7\r\n2 7\r\n2 9\r\n6 9\r\n6 7\r\n5 7\r\n5 3\r\n4 3\r\n4 4\r\n3 4\r\n3 2\r\n5 2\r\n5 1\r\n1 1\r\n", "output": "6\r\n"}, {"input": "4\r\n-10000 -10000\r\n-10000 10000\r\n10000 10000\r\n10000 -10000\r\n-10000 -10000\r\n", "output": "0\r\n"}, {"input": "4\r\n6 8\r\n6 9\r\n7 9\r\n7 8\r\n6 8\r\n", "output": "0\r\n"}, {"input": "8\r\n-10000 -10000\r\n-10000 5000\r\n0 5000\r\n0 10000\r\n10000 10000\r\n10000 0\r\n0 0\r\n0 -10000\r\n-10000 -10000\r\n", "output": "2\r\n"}, {"input": "20\r\n-4286 -10000\r\n-4286 -7778\r\n-7143 -7778\r\n-7143 -3334\r\n-10000 -3334\r\n-10000 1110\r\n-4286 1110\r\n-4286 -3334\r\n4285 -3334\r\n4285 -1112\r\n7142 -1112\r\n7142 3332\r\n4285 3332\r\n4285 9998\r\n9999 9998\r\n9999 -3334\r\n7142 -3334\r\n7142 -5556\r\n-1429 -5556\r\n-1429 -10000\r\n-4286 -10000\r\n", "output": "8\r\n"}, {"input": "24\r\n-10000 -10000\r\n-10000 9998\r\n9998 9998\r\n9998 -10000\r\n-6364 -10000\r\n-6364 6362\r\n6362 6362\r\n6362 -6364\r\n-2728 -6364\r\n-2728 2726\r\n2726 2726\r\n2726 -910\r\n908 -910\r\n908 908\r\n-910 908\r\n-910 -4546\r\n4544 -4546\r\n4544 4544\r\n-4546 4544\r\n-4546 -8182\r\n8180 -8182\r\n8180 8180\r\n-8182 8180\r\n-8182 -10000\r\n-10000 -10000\r\n", "output": "10\r\n"}, {"input": "12\r\n-10000 -10000\r\n-10000 10000\r\n10000 10000\r\n10000 6000\r\n-6000 6000\r\n-6000 2000\r\n10000 2000\r\n10000 -2000\r\n-6000 -2000\r\n-6000 -6000\r\n10000 -6000\r\n10000 -10000\r\n-10000 -10000\r\n", "output": "4\r\n"}, {"input": "12\r\n-10000 -10000\r\n-10000 10000\r\n10000 10000\r\n10000 6000\r\n-9800 6000\r\n-9800 2000\r\n10000 2000\r\n10000 -2000\r\n-9800 -2000\r\n-9800 -6000\r\n10000 -6000\r\n10000 -10000\r\n-10000 -10000\r\n", "output": "4\r\n"}, {"input": "4\r\n0 0\r\n0 10000\r\n10000 10000\r\n10000 0\r\n0 0\r\n", "output": "0\r\n"}, {"input": "4\r\n-10000 -10000\r\n-10000 10000\r\n10000 10000\r\n10000 -10000\r\n-10000 -10000\r\n", "output": "0\r\n"}]
false
stdio
null
true
205/B
205
B
Python 3
TESTS
6
46
4,505,600
134964340
import sys import math from sys import stdin, stdout # TAKE INPUT def get_ints_in_variables(): return map(int, sys.stdin.readline().strip().split()) def get_int(): return int(input()) def get_ints_in_list(): return list( map(int, sys.stdin.readline().strip().split())) def get_list_of_list(n): return [list( map(int, sys.stdin.readline().strip().split())) for _ in range(n)] def get_string(): return sys.stdin.readline().strip() def main(): # Write Your Code Here n = int(input()) arr = get_ints_in_list() count = 0 for i in range(1, n): if arr[i-1] > arr[i]: l = i r = i+1 mx = arr[l] while r < n: if arr[r] < arr[i-1]: mx = max(mx, arr[r]) r += 1 else: break # print("max", mx) diff = arr[i-1] - mx count += diff while l < r: arr[l] += diff l += 1 if arr[i] < arr[i-1]: dif = arr[i-1]-arr[i] count += (dif) arr[i] += dif print(count) # calling main Function if __name__ == "__main__": main()
45
93
8,806,400
149895214
def solve() : c=0 for i in range(n-1): if arr[i]>arr[i+1] : c+=arr[i]-arr[i+1] return c from sys import stdin input = stdin.readline n=int(input()) arr=[int(x) for x in input().split()] print(solve()) ''' t=int(input()) for i in range(t) : print(solve()) n=int(input()) x=input().strip() n,m= [int(x) for x in input().split()] n,m= [int(x) for x in input().split()] arr=[] for i in range(n): arr.append([int(x) for x in input().split()]) n=int(input()) arr=[] for i in range(n): arr.append([int(x) for x in input().split()]) n=int(input()) arr=[int(x) for x in input().split()] '''
Codeforces Round 129 (Div. 2)
CF
2,012
0.5
256
Little Elephant and Sorting
The Little Elephant loves sortings. He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r. Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
In a single line print a single integer — the answer to the problem. 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
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0. In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]). In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
[{"input": "3\n1 2 3", "output": "0"}, {"input": "3\n3 2 1", "output": "2"}, {"input": "4\n7 4 1 47", "output": "6"}]
1,400
["brute force", "greedy"]
45
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "4\r\n7 4 1 47\r\n", "output": "6\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 1000000000\r\n", "output": "0\r\n"}, {"input": "10\r\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "4999999995\r\n"}, {"input": "7\r\n47 47 47 47 47 47 48\r\n", "output": "0\r\n"}, {"input": "47\r\n7 9 9 3 7 3 6 8 3 6 6 2 6 4 2 2 4 3 6 1 3 9 8 2 3 5 3 10 7 7 5 2 8 1 5 7 2 7 6 2 1 9 7 7 4 10 3\r\n", "output": "76\r\n"}, {"input": "74\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n940259367\r\n", "output": "0\r\n"}, {"input": "2\r\n710095427 879909817\r\n", "output": "0\r\n"}, {"input": "3\r\n39740000 928596641 251625421\r\n", "output": "676971220\r\n"}]
false
stdio
null
true
205/B
205
B
PyPy 3
TESTS
6
77
0
138583267
n=int(input()) l=list(map(int,input().split())) curr=l[0] m=0 c=0 for i in range(1,n): # print(curr) if(l[i]<curr): m=max(m,curr-l[i]) # print(m) else: curr=l[i] c+=m m=0 c+=m print(c)
45
93
13,926,400
212136866
x = int(input()) l = list(map(int,input().split())) answer = 0 for i in range(x-1): answer += max(l[i] - l[i+1] , 0) print(answer)
Codeforces Round 129 (Div. 2)
CF
2,012
0.5
256
Little Elephant and Sorting
The Little Elephant loves sortings. He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r. Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
In a single line print a single integer — the answer to the problem. 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
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0. In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]). In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
[{"input": "3\n1 2 3", "output": "0"}, {"input": "3\n3 2 1", "output": "2"}, {"input": "4\n7 4 1 47", "output": "6"}]
1,400
["brute force", "greedy"]
45
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "4\r\n7 4 1 47\r\n", "output": "6\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 1000000000\r\n", "output": "0\r\n"}, {"input": "10\r\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "4999999995\r\n"}, {"input": "7\r\n47 47 47 47 47 47 48\r\n", "output": "0\r\n"}, {"input": "47\r\n7 9 9 3 7 3 6 8 3 6 6 2 6 4 2 2 4 3 6 1 3 9 8 2 3 5 3 10 7 7 5 2 8 1 5 7 2 7 6 2 1 9 7 7 4 10 3\r\n", "output": "76\r\n"}, {"input": "74\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n940259367\r\n", "output": "0\r\n"}, {"input": "2\r\n710095427 879909817\r\n", "output": "0\r\n"}, {"input": "3\r\n39740000 928596641 251625421\r\n", "output": "676971220\r\n"}]
false
stdio
null
true
205/B
205
B
Python 3
TESTS
6
31
0
212136331
x = int(input()) l = list(map(int,input().split())) l.append(int(1e10)) answer = 0 anslist = [] if l == sorted(l): print(0) else: for i in range(1,x+1): initial = max(l[0:i]) if l[i] < initial: anslist.append(l[i]) else: if len(anslist) > 0: answer += initial-min(anslist) anslist = [] else: anslist = [] print(answer)
45
108
8,704,000
183824838
def little_ele(length,array): a=0 for z in range(1,length): if array[z-1]>array[z]:a+=array[z-1]-array[z] return a a=int(input()) nums=[int(i) for i in input().split()] print(little_ele(a,nums))
Codeforces Round 129 (Div. 2)
CF
2,012
0.5
256
Little Elephant and Sorting
The Little Elephant loves sortings. He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r. Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
In a single line print a single integer — the answer to the problem. 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
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0. In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]). In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
[{"input": "3\n1 2 3", "output": "0"}, {"input": "3\n3 2 1", "output": "2"}, {"input": "4\n7 4 1 47", "output": "6"}]
1,400
["brute force", "greedy"]
45
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "4\r\n7 4 1 47\r\n", "output": "6\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 1000000000\r\n", "output": "0\r\n"}, {"input": "10\r\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "4999999995\r\n"}, {"input": "7\r\n47 47 47 47 47 47 48\r\n", "output": "0\r\n"}, {"input": "47\r\n7 9 9 3 7 3 6 8 3 6 6 2 6 4 2 2 4 3 6 1 3 9 8 2 3 5 3 10 7 7 5 2 8 1 5 7 2 7 6 2 1 9 7 7 4 10 3\r\n", "output": "76\r\n"}, {"input": "74\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n940259367\r\n", "output": "0\r\n"}, {"input": "2\r\n710095427 879909817\r\n", "output": "0\r\n"}, {"input": "3\r\n39740000 928596641 251625421\r\n", "output": "676971220\r\n"}]
false
stdio
null
true
205/B
205
B
Python 3
TESTS
6
31
0
141366358
n=int(input()) a=list(map(int,list(input().split()))) x,y,total,steps,ans=0,0,0,0,0 for i in range(n-1): if a[i]>a[i+1]: x=a[i] y=i break flag=True for i in range(y,n): if a[i]<x: steps=x-a[i] if steps>total: total=steps flag=True else: ans=ans+total total=0 x=a[i] flag=False if flag==True: ans=ans+total print(ans)
45
109
8,806,400
147382913
#بسم الله الرحمن الرحيم n = int(input()) sequence =[int(i) for i in input().split()] maxx = 0 s=0 for i in range(n-1): s=sequence[i]-sequence[i+1] if sequence[i+1]<sequence[i]: maxx+=s print(maxx)
Codeforces Round 129 (Div. 2)
CF
2,012
0.5
256
Little Elephant and Sorting
The Little Elephant loves sortings. He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r. Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
In a single line print a single integer — the answer to the problem. 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
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0. In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]). In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
[{"input": "3\n1 2 3", "output": "0"}, {"input": "3\n3 2 1", "output": "2"}, {"input": "4\n7 4 1 47", "output": "6"}]
1,400
["brute force", "greedy"]
45
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "4\r\n7 4 1 47\r\n", "output": "6\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 1000000000\r\n", "output": "0\r\n"}, {"input": "10\r\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "4999999995\r\n"}, {"input": "7\r\n47 47 47 47 47 47 48\r\n", "output": "0\r\n"}, {"input": "47\r\n7 9 9 3 7 3 6 8 3 6 6 2 6 4 2 2 4 3 6 1 3 9 8 2 3 5 3 10 7 7 5 2 8 1 5 7 2 7 6 2 1 9 7 7 4 10 3\r\n", "output": "76\r\n"}, {"input": "74\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n940259367\r\n", "output": "0\r\n"}, {"input": "2\r\n710095427 879909817\r\n", "output": "0\r\n"}, {"input": "3\r\n39740000 928596641 251625421\r\n", "output": "676971220\r\n"}]
false
stdio
null
true
205/B
205
B
Python 3
TESTS
6
62
0
104837557
def solve(arr): prev = arr[0] m = prev res = 0 for curr in arr[1:]: if curr < prev: if curr < m: m = curr else: res += prev - m prev = curr m = prev return res + prev - m n = int(input()) arr = [int(i) for i in input().split()] print(solve(arr))
45
124
8,089,600
141367431
n=int(input()) a=list(map(int,list(input().split()))) total=0 for i in range(n-1): x=max(0,a[i]-a[i+1]) total=total+x print(total)
Codeforces Round 129 (Div. 2)
CF
2,012
0.5
256
Little Elephant and Sorting
The Little Elephant loves sortings. He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r. Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.
In a single line print a single integer — the answer to the problem. 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
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0. In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]). In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].
[{"input": "3\n1 2 3", "output": "0"}, {"input": "3\n3 2 1", "output": "2"}, {"input": "4\n7 4 1 47", "output": "6"}]
1,400
["brute force", "greedy"]
45
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "4\r\n7 4 1 47\r\n", "output": "6\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 1000000000\r\n", "output": "0\r\n"}, {"input": "10\r\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "4999999995\r\n"}, {"input": "7\r\n47 47 47 47 47 47 48\r\n", "output": "0\r\n"}, {"input": "47\r\n7 9 9 3 7 3 6 8 3 6 6 2 6 4 2 2 4 3 6 1 3 9 8 2 3 5 3 10 7 7 5 2 8 1 5 7 2 7 6 2 1 9 7 7 4 10 3\r\n", "output": "76\r\n"}, {"input": "74\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n940259367\r\n", "output": "0\r\n"}, {"input": "2\r\n710095427 879909817\r\n", "output": "0\r\n"}, {"input": "3\r\n39740000 928596641 251625421\r\n", "output": "676971220\r\n"}]
false
stdio
null
true
868/D
868
D
Python 3
TESTS
5
62
0
32082628
from math import log n = int(input()) p = [bin(p)[2:] for p in range(0,256)] def q(s): for k in range(0,10): for pi in range(0,2**k): cs = p[pi] cs = (k-len(cs))*"0"+cs if not cs in s: return k - 1 s = [(v, q(v)) for v in [input() for i in range(n)]] for qa, qb in [[int(v) - 1 for v in input().split()] for i in range(int(input()))]: vs = s[qa][0] + s[qb][0] qs = q(vs) if len(vs) > 18: vs = vs[:9] + vs[-9:] v = (vs, max(qs, s[qa][1], s[qb][1], 0)) s += [v] print(v[1])
49
109
9,728,000
31023840
from sys import stdin, stdout K = 20 def findAllStrings(s): n = len(s) sDict = {} for i in range(1,K+1): sDict[i]=set() for x in range(n-i+1): sDict[i].add(s[x:x+i]) return sDict n = int(stdin.readline().rstrip()) stringDicts = [] stringEnd = [] stringBegin = [] for i in range(n): s = stdin.readline().rstrip() stringDicts.append(findAllStrings(s)) if len(s)<K: stringEnd.append(s) stringBegin.append(s) else: stringEnd.append(s[-20:]) stringBegin.append(s[:20]) m = int(stdin.readline().rstrip()) for _ in range(m): a,b = map(int,stdin.readline().rstrip().split()) a-=1 b-=1 sDict1 = findAllStrings(stringEnd[a]+stringBegin[b]) sDict2 = stringDicts[a] sDict3 = stringDicts[b] sDict={} for i in range(1,K+1): sDict[i] = sDict1[i]|sDict2[i]|sDict3[i] stringDicts.append(sDict) for i in range(1,K+1): if len(sDict[i])!=2**i: print(i-1) break if len(stringBegin[a])<K and len(stringBegin[a])+len(stringBegin[b])<K: stringBegin.append(stringBegin[a]+stringBegin[b]) elif len(stringBegin[a])<K: s = stringBegin[a]+stringBegin[b] stringBegin.append(s[:K]) else: stringBegin.append(stringBegin[a]) if len(stringEnd[b])<K and len(stringEnd[a])+len(stringEnd[b])<K: stringEnd.append(stringEnd[a]+stringEnd[b]) elif len(stringEnd[b])<K: s = stringEnd[a]+stringEnd[b] stringEnd.append(s[-K:]) else: stringEnd.append(stringEnd[b])
Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
256
Huge Strings
You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed, on each of them you concatenate two existing strings into a new one. On the i-th operation the concatenation saisbi is saved into a new string sn + i (the operations are numbered starting from 1). After each operation you need to find the maximum positive integer k such that all possible strings consisting of 0 and 1 of length k (there are 2k such strings) are substrings of the new string. If there is no such k, print 0.
The first line contains single integer n (1 ≤ n ≤ 100) — the number of strings. The next n lines contain strings s1, s2, ..., sn (1 ≤ |si| ≤ 100), one per line. The total length of strings is not greater than 100. The next line contains single integer m (1 ≤ m ≤ 100) — the number of operations. m lines follow, each of them contains two integers ai abd bi (1 ≤ ai, bi ≤ n + i - 1) — the number of strings that are concatenated to form sn + i.
Print m lines, each should contain one integer — the answer to the question after the corresponding operation.
null
On the first operation, a new string "0110" is created. For k = 1 the two possible binary strings of length k are "0" and "1", they are substrings of the new string. For k = 2 and greater there exist strings of length k that do not appear in this string (for k = 2 such string is "00"). So the answer is 1. On the second operation the string "01100" is created. Now all strings of length k = 2 are present. On the third operation the string "1111111111" is created. There is no zero, so the answer is 0.
[{"input": "5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4", "output": "1\n2\n0"}]
2,200
["bitmasks", "brute force", "dp", "implementation", "strings"]
49
[{"input": "5\r\n01\r\n10\r\n101\r\n11111\r\n0\r\n3\r\n1 2\r\n6 5\r\n4 4\r\n", "output": "1\r\n2\r\n0\r\n"}, {"input": "5\r\n01\r\n1\r\n0011\r\n0\r\n01\r\n6\r\n5 5\r\n3 2\r\n4 2\r\n6 7\r\n5 1\r\n9 7\r\n", "output": "1\r\n1\r\n1\r\n2\r\n1\r\n2\r\n"}, {"input": "5\r\n111101000111100011100110000100\r\n000111001\r\n01101000\r\n0000110100100010011001000000010100100111110110\r\n0110001\r\n10\r\n5 5\r\n2 2\r\n5 6\r\n1 1\r\n1 7\r\n10 6\r\n6 2\r\n11 1\r\n3 6\r\n8 2\r\n", "output": "2\r\n2\r\n2\r\n3\r\n3\r\n4\r\n3\r\n4\r\n2\r\n3\r\n"}, {"input": "1\r\n1\r\n1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "5\r\n110101010101010110000011011\r\n111111\r\n1000100011100111100101101010011111100000001001\r\n00\r\n1111101100001110000\r\n10\r\n4 3\r\n6 6\r\n7 5\r\n8 8\r\n8 7\r\n10 8\r\n11 9\r\n10 12\r\n13 13\r\n12 13\r\n", "output": "4\r\n4\r\n4\r\n4\r\n4\r\n4\r\n4\r\n4\r\n4\r\n4\r\n"}, {"input": "5\r\n100010010\r\n0\r\n1001100110010111\r\n0001000011000111000011011000110000010010010001110001000011011\r\n0100000100100\r\n10\r\n5 5\r\n6 6\r\n6 7\r\n7 8\r\n8 9\r\n10 8\r\n11 9\r\n10 9\r\n12 13\r\n12 13\r\n", "output": "1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n"}, {"input": "5\r\n0\r\n1\r\n11\r\n110000010001100101001\r\n1101011011111\r\n10\r\n5 3\r\n6 4\r\n7 6\r\n8 7\r\n9 8\r\n10 9\r\n11 10\r\n12 11\r\n13 12\r\n14 13\r\n", "output": "1\r\n4\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n"}, {"input": "10\r\n0\r\n1\r\n1111100000\r\n0\r\n1\r\n0000\r\n11000\r\n1010001110010010110\r\n01101001111\r\n010101110110111111\r\n20\r\n10 3\r\n11 4\r\n12 5\r\n13 6\r\n14 7\r\n15 8\r\n16 9\r\n17 16\r\n18 17\r\n19 18\r\n20 19\r\n21 20\r\n22 21\r\n23 22\r\n24 23\r\n25 24\r\n26 25\r\n27 26\r\n28 27\r\n29 28\r\n", "output": "2\r\n2\r\n3\r\n3\r\n3\r\n4\r\n5\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n"}, {"input": "10\r\n0\r\n1\r\n1111\r\n110000000\r\n100000\r\n1\r\n1\r\n000010100001110001\r\n00100010110001101000111100100110010101001011\r\n100110110011101\r\n50\r\n10 3\r\n11 4\r\n12 5\r\n13 6\r\n14 7\r\n15 8\r\n16 9\r\n17 1\r\n18 1\r\n19 2\r\n20 2\r\n21 2\r\n22 2\r\n23 2\r\n24 1\r\n25 2\r\n26 1\r\n27 2\r\n28 1\r\n29 2\r\n30 2\r\n31 1\r\n32 2\r\n33 1\r\n34 2\r\n35 2\r\n36 2\r\n37 2\r\n38 1\r\n39 2\r\n40 2\r\n41 1\r\n42 2\r\n43 2\r\n44 2\r\n45 1\r\n46 2\r\n47 2\r\n48 2\r\n49 2\r\n50 2\r\n51 2\r\n52 2\r\n53 52\r\n54 53\r\n55 54\r\n56 55\r\n57 56\r\n58 57\r\n59 58\r\n", "output": "2\r\n2\r\n3\r\n3\r\n3\r\n4\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n5\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n6\r\n"}, {"input": "2\r\n001010011100101110111\r\n001100110011001100110011001100110011001100110011001100111001\r\n14\r\n1 2\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n10 10\r\n11 11\r\n12 12\r\n13 13\r\n14 14\r\n15 15\r\n", "output": "2\r\n2\r\n2\r\n2\r\n2\r\n2\r\n2\r\n2\r\n2\r\n2\r\n2\r\n2\r\n2\r\n2\r\n"}, {"input": "2\r\n1\r\n0\r\n40\r\n1 2\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n10 10\r\n11 11\r\n12 12\r\n13 13\r\n14 14\r\n15 15\r\n16 16\r\n17 17\r\n18 18\r\n19 19\r\n20 20\r\n21 21\r\n22 22\r\n23 23\r\n24 24\r\n25 25\r\n26 26\r\n27 27\r\n28 28\r\n29 29\r\n30 30\r\n31 31\r\n32 32\r\n33 33\r\n34 34\r\n35 35\r\n36 36\r\n37 37\r\n38 38\r\n39 39\r\n40 40\r\n41 41\r\n", "output": "1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n"}, {"input": "2\r\n011\r\n100\r\n63\r\n1 1\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n10 10\r\n11 11\r\n12 12\r\n13 13\r\n14 14\r\n15 15\r\n16 16\r\n17 17\r\n18 18\r\n19 19\r\n20 20\r\n21 21\r\n22 22\r\n23 23\r\n24 24\r\n25 25\r\n26 26\r\n27 27\r\n28 28\r\n29 29\r\n30 30\r\n31 31\r\n32 32\r\n2 2\r\n34 34\r\n35 35\r\n36 36\r\n37 37\r\n38 38\r\n39 39\r\n40 40\r\n41 41\r\n42 42\r\n43 43\r\n44 44\r\n45 45\r\n46 46\r\n47 47\r\n48 48\r\n49 49\r\n50 50\r\n51 51\r\n52 52\r\n53 53\r\n54 54\r\n55 55\r\n56 56\r\n57 57\r\n58 58\r\n59 59\r\n60 60\r\n61 61\r\n62 62\r\n63 63\r\n33 64\r\n", "output": "1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n2\r\n"}, {"input": "1\r\n0000000000000000000000000000000000000000000000000000000000000000\r\n25\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n10 10\r\n11 11\r\n12 12\r\n13 13\r\n14 14\r\n15 15\r\n16 16\r\n17 17\r\n18 18\r\n19 19\r\n20 20\r\n21 21\r\n22 22\r\n23 23\r\n24 24\r\n25 25\r\n", "output": "0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n"}]
false
stdio
null
true
358/C
358
C
Python 3
TESTS
5
31
0
208024221
n = int(input()) sections = [[]] for _ in range(n): inna_command = int(input()) sections[-1].append(inna_command) if inna_command == 0: sections.append([]) if len(sections[-1]) == 0: sections.pop() for section in sections: if section[-1] != 0: for number in section: print('pushBack') elif len(section) == 1: print(0) elif len(section) == 2: print('pushStack') print('1 popStack') elif len(section) == 3: print('pushStack') print('pushQueue') print('2 popStack popQueue') else: with_indexes = enumerate(section) highest_indexes = dict(sorted(with_indexes, key=lambda x: x[1])[-3:]) highest_indexes[0] = 1 highest_indexes[1] = 2 highest_indexes[2] = 3 for i in range(len(section) - 1): if i in highest_indexes: if highest_indexes[i] == 3: print('pushStack') elif highest_indexes[i] == 2: print('pushQueue') else: print('pushFront') else: print('pushBack') print('3 popStack popQueue popFront')
26
187
4,300,800
231249531
i, n = 0, int(input()) s = ['pushQueue'] * n a, b, c = ' popQueue', ' popStack', ' popBack' p = ['0', '1' + a, '2' + a + b, '3' + a + b + c] t = [] for j in range(n): x = int(input()) if x: t.append((x, j)) continue t = sorted(k for x, k in sorted(t)[-3:]) k = len(t) if k > 0: s[i: t[0]] = ['pushStack'] * (t[0] - i) if k > 1: s[t[1]] = 'pushStack' if k > 2: s[t[2]] = 'pushBack' i, t, s[j] = j + 1, [], p[k] print('\n'.join(s))
Codeforces Round 208 (Div. 2)
CF
2,013
2
256
Dima and Containers
Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck. Inna wants her present to show Dima how great a programmer he is. For that, she is going to give Dima commands one by one. There are two types of commands: 1. Add a given number into one of containers. For the queue and the stack, you can add elements only to the end. For the deck, you can add elements to the beginning and to the end. 2. Extract a number from each of at most three distinct containers. Tell all extracted numbers to Inna and then empty all containers. In the queue container you can extract numbers only from the beginning. In the stack container you can extract numbers only from the end. In the deck number you can extract numbers from the beginning and from the end. You cannot extract numbers from empty containers. Every time Dima makes a command of the second type, Inna kisses Dima some (possibly zero) number of times. Dima knows Inna perfectly well, he is sure that this number equals the sum of numbers he extracts from containers during this operation. As we've said before, Dima knows Inna perfectly well and he knows which commands Inna will give to Dima and the order of the commands. Help Dima find the strategy that lets him give as more kisses as possible for his birthday!
The first line contains integer n (1 ≤ n ≤ 105) — the number of Inna's commands. Then n lines follow, describing Inna's commands. Each line consists an integer: 1. Integer a (1 ≤ a ≤ 105) means that Inna gives Dima a command to add number a into one of containers. 2. Integer 0 shows that Inna asks Dima to make at most three extractions from different containers.
Each command of the input must correspond to one line of the output — Dima's action. For the command of the first type (adding) print one word that corresponds to Dima's choice: - pushStack — add to the end of the stack; - pushQueue — add to the end of the queue; - pushFront — add to the beginning of the deck; - pushBack — add to the end of the deck. For a command of the second type first print an integer k (0 ≤ k ≤ 3), that shows the number of extract operations, then print k words separated by space. The words can be: - popStack — extract from the end of the stack; - popQueue — extract from the beginning of the line; - popFront — extract from the beginning from the deck; - popBack — extract from the end of the deck. The printed operations mustn't extract numbers from empty containers. Also, they must extract numbers from distinct containers. The printed sequence of actions must lead to the maximum number of kisses. If there are multiple sequences of actions leading to the maximum number of kisses, you are allowed to print any of them.
null
null
[{"input": "10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0", "output": "0\npushStack\n1 popStack\npushStack\npushQueue\n2 popStack popQueue\npushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}, {"input": "4\n1\n2\n3\n0", "output": "pushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}]
2,000
["constructive algorithms", "greedy", "implementation"]
26
[{"input": "10\r\n0\r\n1\r\n0\r\n1\r\n2\r\n0\r\n1\r\n2\r\n3\r\n0\r\n", "output": "0\r\npushStack\r\n1 popStack\r\npushStack\r\npushQueue\r\n2 popStack popQueue\r\npushStack\r\npushQueue\r\npushFront\r\n3 popStack popQueue popFront\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n0\r\n", "output": "pushStack\r\npushQueue\r\npushFront\r\n3 popStack popQueue popFront\r\n"}, {"input": "2\r\n0\r\n1\r\n", "output": "0\r\npushQueue\r\n"}, {"input": "5\r\n1\r\n1\r\n1\r\n2\r\n1\r\n", "output": "pushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\n"}, {"input": "5\r\n3\r\n2\r\n3\r\n1\r\n0\r\n", "output": "pushStack\r\npushQueue\r\npushFront\r\npushBack\r\n3 popStack popQueue popFront\r\n"}, {"input": "49\r\n8735\r\n95244\r\n50563\r\n33648\r\n10711\r\n30217\r\n49166\r\n28240\r\n0\r\n97232\r\n12428\r\n16180\r\n58610\r\n61112\r\n74423\r\n56323\r\n43327\r\n0\r\n12549\r\n48493\r\n43086\r\n69266\r\n27033\r\n37338\r\n43900\r\n5570\r\n25293\r\n44517\r\n7183\r\n41969\r\n31944\r\n32247\r\n96959\r\n44890\r\n98237\r\n52601\r\n29081\r\n93641\r\n14980\r\n29539\r\n84672\r\n57310\r\n91014\r\n31721\r\n6944\r\n67672\r\n22040\r\n86269\r\n86709\r\n", "output": "pushBack\npushStack\npushQueue\npushBack\npushBack\npushBack\npushFront\npushBack\n3 popStack popQueue popFront\npushStack\npushBack\npushBack\npushBack\npushFront\npushQueue\npushBack\npushBack\n3 popStack popQueue popFront\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushStack\npushBack\npushBack\npushFront\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushQueue\npushBack\npushBack\npushBack\npushBack\n"}, {"input": "55\r\n73792\r\n39309\r\n73808\r\n47389\r\n34803\r\n87947\r\n32460\r\n14649\r\n70151\r\n35816\r\n8272\r\n78886\r\n71345\r\n61907\r\n16977\r\n85362\r\n0\r\n43792\r\n8118\r\n83254\r\n89459\r\n32230\r\n87068\r\n82617\r\n94847\r\n83528\r\n37629\r\n31438\r\n97413\r\n62260\r\n13651\r\n47564\r\n43543\r\n61292\r\n51025\r\n64106\r\n0\r\n19282\r\n35422\r\n19657\r\n95170\r\n10266\r\n43771\r\n3190\r\n93962\r\n11747\r\n43021\r\n91531\r\n88370\r\n1760\r\n10950\r\n77059\r\n61741\r\n52965\r\n10445\r\n", "output": "pushBack\npushBack\npushBack\npushBack\npushBack\npushStack\npushBack\npushBack\npushBack\npushBack\npushBack\npushFront\npushBack\npushBack\npushBack\npushQueue\n3 popStack popQueue popFront\npushBack\npushBack\npushBack\npushFront\npushBack\npushBack\npushBack\npushQueue\npushBack\npushBack\npushBack\npushStack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\n3 popStack popQueue popFront\npushBack\npushBack\npushBack\npushBack\npushFront\npushBack\npushQueue\npushBack\npushBack\npushBack\npushBack\npushBack\npushStack\npushBack\npushBack\npushBack\npushBack\npushBack\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n5\r\n4\r\n9\r\n8\r\n6\r\n7\r\n0\r\n", "output": "pushBack\r\npushBack\r\npushBack\r\npushBack\r\npushBack\r\npushStack\r\npushQueue\r\npushBack\r\npushFront\r\n3 popStack popQueue popFront\r\n"}, {"input": "10\r\n1\r\n3\r\n4\r\n2\r\n6\r\n8\r\n5\r\n7\r\n10\r\n9\r\n", "output": "pushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}]
false
stdio
import sys from collections import deque def main(input_path, output_path, submission_path): with open(input_path) as f: input_lines = f.read().splitlines() n = int(input_lines[0]) input_commands = input_lines[1:n+1] with open(submission_path) as f: submission_lines = [line.strip() for line in f] if len(submission_lines) != len(input_commands): print(0) return stack = [] queue = [] deck = deque() sub_idx = 0 for cmd in input_commands: if cmd == '0': if sub_idx >= len(submission_lines): print(0) return line = submission_lines[sub_idx] sub_idx += 1 parts = line.split() if not parts: print(0) return try: k = int(parts[0]) except: print(0) return if k < 0 or k > 3 or len(parts) != k + 1: print(0) return ops = parts[1:] # Compute max possible sum using copies stack_copy = list(stack) queue_copy = list(queue) deck_copy = deque(deck) contributions = [] if stack_copy: contributions.append(stack_copy[-1]) if queue_copy: contributions.append(queue_copy[0]) if deck_copy: deck_val = max(deck_copy[0], deck_copy[-1]) if deck_copy else 0 contributions.append(deck_val) contributions.sort(reverse=True) max_sum = sum(contributions[:3]) # Validate submission's ops temp_stack = list(stack) temp_queue = list(queue) temp_deck = deque(deck) sum_sub = 0 used = set() valid = True for op in ops: container = None if op == 'popStack': if not temp_stack: valid = False break sum_sub += temp_stack.pop() container = 'stack' elif op == 'popQueue': if not temp_queue: valid = False break sum_sub += temp_queue.pop(0) container = 'queue' elif op == 'popFront': if not temp_deck: valid = False break sum_sub += temp_deck.popleft() container = 'deck' elif op == 'popBack': if not temp_deck: valid = False break sum_sub += temp_deck.pop() container = 'deck' else: valid = False break if container in used: valid = False break used.add(container) if not valid or sum_sub != max_sum: print(0) return # Clear containers stack.clear() queue.clear() deck.clear() else: a = int(cmd) if sub_idx >= len(submission_lines): print(0) return line = submission_lines[sub_idx] sub_idx += 1 if line == 'pushStack': stack.append(a) elif line == 'pushQueue': queue.append(a) elif line == 'pushFront': deck.appendleft(a) elif line == 'pushBack': deck.append(a) else: print(0) return print(1) if __name__ == '__main__': main(sys.argv[1], sys.argv[2], sys.argv[3])
true
71/A
71
A
PyPy 3-64
TESTS
11
61
0
225205288
# -*- coding: utf-8 -*- """waytoolongwords Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1BseqGBxW--4aunfaCeeXWMIl4SrMIEh3 """ number = int(input("")) words = [] while 100 > number > 0: wordinput = str(input("")) words.append(wordinput) number -= 1 for word in words: wordlength = len(word) if wordlength > 10: newword = word[0] + str(wordlength-2) + word[-1] print(newword) else: print(word)
20
31
0
181425366
x=int(input("")) y=[] for i in range (x): s=str(input("")) if len(s)<=10: y.append(s) else: first_letter=s[0] last_letter=s[-1] z=(first_letter+str(len(s)-2)+last_letter) y.append(z) for h in range (x): print(y[h])
Codeforces Beta Round 65 (Div. 2)
CF
2,011
1
256
Way Too Long Words
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
null
null
[{"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s"}]
800
["strings"]
20
[{"input": "4\r\nword\r\nlocalization\r\ninternationalization\r\npneumonoultramicroscopicsilicovolcanoconiosis\r\n", "output": "word\r\nl10n\r\ni18n\r\np43s\r\n"}, {"input": "5\r\nabcdefgh\r\nabcdefghi\r\nabcdefghij\r\nabcdefghijk\r\nabcdefghijklm\r\n", "output": "abcdefgh\r\nabcdefghi\r\nabcdefghij\r\na9k\r\na11m\r\n"}, {"input": "3\r\nnjfngnrurunrgunrunvurn\r\njfvnjfdnvjdbfvsbdubruvbubvkdb\r\nksdnvidnviudbvibd\r\n", "output": "n20n\r\nj27b\r\nk15d\r\n"}, {"input": "1\r\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt\r\n", "output": "t41t\r\n"}, {"input": "24\r\nyou\r\nare\r\nregistered\r\nfor\r\npractice\r\nyou\r\ncan\r\nsolve\r\nproblems\r\nunofficially\r\nresults\r\ncan\r\nbe\r\nfound\r\nin\r\nthe\r\ncontest\r\nstatus\r\nand\r\nin\r\nthe\r\nbottom\r\nof\r\nstandings\r\n", "output": "you\r\nare\r\nregistered\r\nfor\r\npractice\r\nyou\r\ncan\r\nsolve\r\nproblems\r\nu10y\r\nresults\r\ncan\r\nbe\r\nfound\r\nin\r\nthe\r\ncontest\r\nstatus\r\nand\r\nin\r\nthe\r\nbottom\r\nof\r\nstandings\r\n"}, {"input": "1\r\na\r\n", "output": "a\r\n"}, {"input": "26\r\na\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni\r\nj\r\nk\r\nl\r\nm\r\nn\r\no\r\np\r\nq\r\nr\r\ns\r\nt\r\nu\r\nv\r\nw\r\nx\r\ny\r\nz\r\n", "output": "a\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni\r\nj\r\nk\r\nl\r\nm\r\nn\r\no\r\np\r\nq\r\nr\r\ns\r\nt\r\nu\r\nv\r\nw\r\nx\r\ny\r\nz\r\n"}, {"input": "1\r\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\r\n", "output": "a98j\r\n"}, {"input": "10\r\ngyartjdxxlcl\r\nfzsck\r\nuidwu\r\nxbymclornemdmtj\r\nilppyoapitawgje\r\ncibzc\r\ndrgbeu\r\nhezplmsdekhhbo\r\nfeuzlrimbqbytdu\r\nkgdco\r\n", "output": "g10l\r\nfzsck\r\nuidwu\r\nx13j\r\ni13e\r\ncibzc\r\ndrgbeu\r\nh12o\r\nf13u\r\nkgdco\r\n"}, {"input": "20\r\nlkpmx\r\nkovxmxorlgwaomlswjxlpnbvltfv\r\nhykasjxqyjrmybejnmeumzha\r\ntuevlumpqbbhbww\r\nqgqsphvrmupxxc\r\ntrissbaf\r\nqfgrlinkzvzqdryckaizutd\r\nzzqtoaxkvwoscyx\r\noswytrlnhpjvvnwookx\r\nlpuzqgec\r\ngyzqfwxggtvpjhzmzmdw\r\nrlxjgmvdftvrmvbdwudra\r\nvsntnjpepnvdaxiporggmglhagv\r\nxlvcqkqgcrbgtgglj\r\nlyxwxbiszyhlsrgzeedzprbmcpduvq\r\nyrmqqvrkqskqukzqrwukpsifgtdc\r\nxpuohcsjhhuhvr\r\nvvlfrlxpvqejngwrbfbpmqeirxlw\r\nsvmasocxdvadmaxtrpakysmeaympy\r\nyuflqboqfdt\r\n", "output": "lkpmx\r\nk26v\r\nh22a\r\nt13w\r\nq12c\r\ntrissbaf\r\nq21d\r\nz13x\r\no17x\r\nlpuzqgec\r\ng18w\r\nr19a\r\nv25v\r\nx15j\r\nl28q\r\ny26c\r\nx12r\r\nv26w\r\ns27y\r\ny9t\r\n"}, {"input": "100\r\nm\r\nz\r\ns\r\nv\r\nd\r\nr\r\nv\r\ny\r\ny\r\ne\r\np\r\nt\r\nc\r\na\r\nn\r\nm\r\np\r\ng\r\ni\r\nj\r\nc\r\na\r\nb\r\nq\r\ne\r\nn\r\nv\r\no\r\nk\r\nx\r\nf\r\ni\r\nl\r\na\r\nq\r\nr\r\nu\r\nb\r\ns\r\nl\r\nc\r\nl\r\ne\r\nv\r\nj\r\nm\r\nx\r\nb\r\na\r\nq\r\nb\r\na\r\nf\r\nj\r\nv\r\nm\r\nq\r\nc\r\nt\r\nt\r\nn\r\nx\r\no\r\ny\r\nr\r\nu\r\nh\r\nm\r\nj\r\np\r\nj\r\nq\r\nz\r\ns\r\nj\r\no\r\ng\r\nc\r\nm\r\nn\r\no\r\nm\r\nr\r\no\r\ns\r\nt\r\nh\r\nr\r\np\r\nk\r\nb\r\nz\r\ng\r\no\r\nc\r\nc\r\nz\r\nz\r\ng\r\nr\r\n", "output": "m\r\nz\r\ns\r\nv\r\nd\r\nr\r\nv\r\ny\r\ny\r\ne\r\np\r\nt\r\nc\r\na\r\nn\r\nm\r\np\r\ng\r\ni\r\nj\r\nc\r\na\r\nb\r\nq\r\ne\r\nn\r\nv\r\no\r\nk\r\nx\r\nf\r\ni\r\nl\r\na\r\nq\r\nr\r\nu\r\nb\r\ns\r\nl\r\nc\r\nl\r\ne\r\nv\r\nj\r\nm\r\nx\r\nb\r\na\r\nq\r\nb\r\na\r\nf\r\nj\r\nv\r\nm\r\nq\r\nc\r\nt\r\nt\r\nn\r\nx\r\no\r\ny\r\nr\r\nu\r\nh\r\nm\r\nj\r\np\r\nj\r\nq\r\nz\r\ns\r\nj\r\no\r\ng\r\nc\r\nm\r\nn\r\no\r\nm\r\nr\r\no\r\ns\r\nt\r\nh\r\nr\r\np\r\nk\r\nb\r\nz\r\ng\r\no\r\nc\r\nc\r\nz\r\nz\r\ng\r\nr\r\n"}]
false
stdio
null
true
71/A
71
A
PyPy 3-64
TESTS
11
62
0
206650350
n = int(input()) wordlist = [] if (n > 0 and n < 100): while (n > 0): w = str(input()) wordlist.append(w) n = n-1 for k in wordlist: if (len(k) <= 10 ): print(k) else: print(k[0],len(k)-2,k[-1],sep="")
20
31
0
181554121
n=int(input()) for i in range(n): word=input() word.strip() if len(word)>10: mid=len(word)-2 end=word[len(word)-1] start=word[0] print(start+str(mid)+end) else: print(word)
Codeforces Beta Round 65 (Div. 2)
CF
2,011
1
256
Way Too Long Words
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
null
null
[{"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s"}]
800
["strings"]
20
[{"input": "4\r\nword\r\nlocalization\r\ninternationalization\r\npneumonoultramicroscopicsilicovolcanoconiosis\r\n", "output": "word\r\nl10n\r\ni18n\r\np43s\r\n"}, {"input": "5\r\nabcdefgh\r\nabcdefghi\r\nabcdefghij\r\nabcdefghijk\r\nabcdefghijklm\r\n", "output": "abcdefgh\r\nabcdefghi\r\nabcdefghij\r\na9k\r\na11m\r\n"}, {"input": "3\r\nnjfngnrurunrgunrunvurn\r\njfvnjfdnvjdbfvsbdubruvbubvkdb\r\nksdnvidnviudbvibd\r\n", "output": "n20n\r\nj27b\r\nk15d\r\n"}, {"input": "1\r\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt\r\n", "output": "t41t\r\n"}, {"input": "24\r\nyou\r\nare\r\nregistered\r\nfor\r\npractice\r\nyou\r\ncan\r\nsolve\r\nproblems\r\nunofficially\r\nresults\r\ncan\r\nbe\r\nfound\r\nin\r\nthe\r\ncontest\r\nstatus\r\nand\r\nin\r\nthe\r\nbottom\r\nof\r\nstandings\r\n", "output": "you\r\nare\r\nregistered\r\nfor\r\npractice\r\nyou\r\ncan\r\nsolve\r\nproblems\r\nu10y\r\nresults\r\ncan\r\nbe\r\nfound\r\nin\r\nthe\r\ncontest\r\nstatus\r\nand\r\nin\r\nthe\r\nbottom\r\nof\r\nstandings\r\n"}, {"input": "1\r\na\r\n", "output": "a\r\n"}, {"input": "26\r\na\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni\r\nj\r\nk\r\nl\r\nm\r\nn\r\no\r\np\r\nq\r\nr\r\ns\r\nt\r\nu\r\nv\r\nw\r\nx\r\ny\r\nz\r\n", "output": "a\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni\r\nj\r\nk\r\nl\r\nm\r\nn\r\no\r\np\r\nq\r\nr\r\ns\r\nt\r\nu\r\nv\r\nw\r\nx\r\ny\r\nz\r\n"}, {"input": "1\r\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\r\n", "output": "a98j\r\n"}, {"input": "10\r\ngyartjdxxlcl\r\nfzsck\r\nuidwu\r\nxbymclornemdmtj\r\nilppyoapitawgje\r\ncibzc\r\ndrgbeu\r\nhezplmsdekhhbo\r\nfeuzlrimbqbytdu\r\nkgdco\r\n", "output": "g10l\r\nfzsck\r\nuidwu\r\nx13j\r\ni13e\r\ncibzc\r\ndrgbeu\r\nh12o\r\nf13u\r\nkgdco\r\n"}, {"input": "20\r\nlkpmx\r\nkovxmxorlgwaomlswjxlpnbvltfv\r\nhykasjxqyjrmybejnmeumzha\r\ntuevlumpqbbhbww\r\nqgqsphvrmupxxc\r\ntrissbaf\r\nqfgrlinkzvzqdryckaizutd\r\nzzqtoaxkvwoscyx\r\noswytrlnhpjvvnwookx\r\nlpuzqgec\r\ngyzqfwxggtvpjhzmzmdw\r\nrlxjgmvdft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nr\r\nu\r\nb\r\ns\r\nl\r\nc\r\nl\r\ne\r\nv\r\nj\r\nm\r\nx\r\nb\r\na\r\nq\r\nb\r\na\r\nf\r\nj\r\nv\r\nm\r\nq\r\nc\r\nt\r\nt\r\nn\r\nx\r\no\r\ny\r\nr\r\nu\r\nh\r\nm\r\nj\r\np\r\nj\r\nq\r\nz\r\ns\r\nj\r\no\r\ng\r\nc\r\nm\r\nn\r\no\r\nm\r\nr\r\no\r\ns\r\nt\r\nh\r\nr\r\np\r\nk\r\nb\r\nz\r\ng\r\no\r\nc\r\nc\r\nz\r\nz\r\ng\r\nr\r\n"}]
false
stdio
null
true
620/C
620
C
PyPy 3
TESTS
34
670
28,876,800
70578834
import sys import math input=sys.stdin.readline n=int(input()) arr=list(map(int,input().split())) ans=list() left=-1 dc=dict() for i in range(n): if(arr[i] in dc.keys() and dc[arr[i]]>left): ans.append([left+1,i]) dc.pop(arr[i],None) left=i else: dc[arr[i]]=i if(len(ans)==0): print(-1) else: print(len(ans)) for i in range(len(ans)): if(i==0): print(1,ans[i][1]+1) elif(i==len(ans)-1): print(ans[i][0]+1,n) else: print(ans[i][0]+1,ans[i][1]+1)
51
264
45,772,800
176962365
import sys input = sys.stdin.readline n = int(input()) w = list(map(int, input().split())) i = 0 s = set() q = [] a = 0 while i < n: if w[i] not in s: s.add(w[i]) else: s = set() q.append((a+1, i+1)) a = i+1 i += 1 if len(q) == 0: print(-1) else: q[-1] = (q[-1][0], n) print(len(q)) for i in q: print(*i)
Educational Codeforces Round 6
ICPC
2,016
2
256
Pearls in a Row
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl.
On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1".
null
null
[{"input": "5\n1 2 3 4 1", "output": "1\n1 5"}, {"input": "5\n1 2 3 4 5", "output": "-1"}, {"input": "7\n1 2 1 3 1 2 1", "output": "2\n1 3\n4 7"}]
1,500
["greedy"]
51
[{"input": "5\r\n1 2 3 4 1\r\n", "output": "1\r\n1 5\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "7\r\n1 2 1 3 1 2 1\r\n", "output": "2\r\n1 3\r\n4 7\r\n"}, {"input": "9\r\n1 2 1 2 1 2 1 2 1\r\n", "output": "3\r\n1 3\r\n4 6\r\n7 9\r\n"}, {"input": "11\r\n1 1 2 1 2 1 2 1 2 1 1\r\n", "output": "4\r\n1 2\r\n3 5\r\n6 8\r\n9 11\r\n"}, {"input": "1\r\n576560149\r\n", "output": "-1\r\n"}, {"input": "10\r\n460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451\r\n", "output": "5\r\n1 2\r\n3 4\r\n5 6\r\n7 8\r\n9 10\r\n"}, {"input": "10\r\n933677171 80672280 80672280 933677171 933677171 933677171 933677171 80672280 80672280 933677171\r\n", "output": "4\r\n1 3\r\n4 5\r\n6 7\r\n8 10\r\n"}, {"input": "10\r\n522312461 21923894 21923894 544064902 488228616 329635457 522312461 488228616 654502493 598654597\r\n", "output": "2\r\n1 3\r\n4 10\r\n"}, {"input": "7\r\n13 9 19 13 3 13 12\r\n", "output": "1\r\n1 7\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n1 3\r\n"}, {"input": "5\r\n1 2 2 2 3\r\n", "output": "1\r\n1 5\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n", "output": "1\r\n1 5\r\n"}, {"input": "13\r\n1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "6\r\n1 2\r\n3 4\r\n5 6\r\n7 8\r\n9 10\r\n11 13\r\n"}, {"input": "4\r\n1 2 1 2\r\n", "output": "1\r\n1 4\r\n"}]
false
stdio
import sys def read_file(path): with open(path, 'r') as f: lines = [line.strip() for line in f.readlines() if line.strip()] return lines def main(): input_path = sys.argv[1] ref_path = sys.argv[2] sub_path = sys.argv[3] input_lines = read_file(input_path) ref_lines = read_file(ref_path) sub_lines = read_file(sub_path) # Parse input n = int(input_lines[0]) a = list(map(int, input_lines[1].split())) # Parse reference output if not ref_lines: print(0) return k_ref = ref_lines[0] if k_ref == '-1': # Check if submission is -1 if not sub_lines: print(0) return k_sub = sub_lines[0] if k_sub == '-1': print(1) return else: print(0) return else: # Reference's k is not -1 if not sub_lines: print(0) return k_sub = sub_lines[0] if k_sub == '-1': print(0) return try: k_ref = int(k_ref) k_sub = int(k_sub) except: print(0) return if k_ref != k_sub: print(0) return # Now check the submission's segments # Parse submission's segments try: k = int(sub_lines[0]) if k != k_ref: print(0) return if k <= 0: print(0) return segments = [] for line in sub_lines[1:]: l, r = map(int, line.split()) segments.append((l, r)) except: print(0) return # Check the segments form a valid partition # Sort by l segments.sort(key=lambda x: x[0]) current = 1 for (l, r) in segments: if l > current or r < l or r > n: print(0) return if l != current: print(0) return current = r + 1 if current != n + 1: print(0) return # Check each segment is good for (l, r) in segments: if r - l + 1 < 2: print(0) return subarray = a[l-1 : r] seen = set() has_duplicate = False for x in subarray: if x in seen: has_duplicate = True break seen.add(x) if not has_duplicate: print(0) return # All checks passed print(1) if __name__ == "__main__": main()
true
620/C
620
C
Python 3
TESTS
34
888
40,960,000
74370671
size = int(input()) myDic,capture,limit = {},[],-1 for x,y in enumerate(map(int,input().split())): if y in myDic: check = x - myDic[y][-1] if myDic[y][-1] > limit: capture.append((myDic[y][-1]+1,x+1)) limit = x; del myDic[y] else: myDic[y][-1] = x else: myDic.update({y:[x]}) if capture: res = len(capture) print(res) print(1,capture[0][1]) start = capture[0][1]+1 for c in range(1,res): print(start,capture[c][1] if c + 1 < res else size ) start = capture[c][1] + 1 else: print(-1)
51
280
44,646,400
175019623
n = int(input()) a = list(map(int, input().split())) d = dict() res = [] for i in range(len(a)): d[a[i]] = d.get(a[i], 0) + 1 if d[a[i]] % 2 == 0: res.append(i) d.clear() if len(res): res[-1] = n-1 print(len(res)) x = 0 for i in res: print(x+1, i+1) x = i+1 else: print(-1)
Educational Codeforces Round 6
ICPC
2,016
2
256
Pearls in a Row
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl.
On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1".
null
null
[{"input": "5\n1 2 3 4 1", "output": "1\n1 5"}, {"input": "5\n1 2 3 4 5", "output": "-1"}, {"input": "7\n1 2 1 3 1 2 1", "output": "2\n1 3\n4 7"}]
1,500
["greedy"]
51
[{"input": "5\r\n1 2 3 4 1\r\n", "output": "1\r\n1 5\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "7\r\n1 2 1 3 1 2 1\r\n", "output": "2\r\n1 3\r\n4 7\r\n"}, {"input": "9\r\n1 2 1 2 1 2 1 2 1\r\n", "output": "3\r\n1 3\r\n4 6\r\n7 9\r\n"}, {"input": "11\r\n1 1 2 1 2 1 2 1 2 1 1\r\n", "output": "4\r\n1 2\r\n3 5\r\n6 8\r\n9 11\r\n"}, {"input": "1\r\n576560149\r\n", "output": "-1\r\n"}, {"input": "10\r\n460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451\r\n", "output": "5\r\n1 2\r\n3 4\r\n5 6\r\n7 8\r\n9 10\r\n"}, {"input": "10\r\n933677171 80672280 80672280 933677171 933677171 933677171 933677171 80672280 80672280 933677171\r\n", "output": "4\r\n1 3\r\n4 5\r\n6 7\r\n8 10\r\n"}, {"input": "10\r\n522312461 21923894 21923894 544064902 488228616 329635457 522312461 488228616 654502493 598654597\r\n", "output": "2\r\n1 3\r\n4 10\r\n"}, {"input": "7\r\n13 9 19 13 3 13 12\r\n", "output": "1\r\n1 7\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n1 3\r\n"}, {"input": "5\r\n1 2 2 2 3\r\n", "output": "1\r\n1 5\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n", "output": "1\r\n1 5\r\n"}, {"input": "13\r\n1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "6\r\n1 2\r\n3 4\r\n5 6\r\n7 8\r\n9 10\r\n11 13\r\n"}, {"input": "4\r\n1 2 1 2\r\n", "output": "1\r\n1 4\r\n"}]
false
stdio
import sys def read_file(path): with open(path, 'r') as f: lines = [line.strip() for line in f.readlines() if line.strip()] return lines def main(): input_path = sys.argv[1] ref_path = sys.argv[2] sub_path = sys.argv[3] input_lines = read_file(input_path) ref_lines = read_file(ref_path) sub_lines = read_file(sub_path) # Parse input n = int(input_lines[0]) a = list(map(int, input_lines[1].split())) # Parse reference output if not ref_lines: print(0) return k_ref = ref_lines[0] if k_ref == '-1': # Check if submission is -1 if not sub_lines: print(0) return k_sub = sub_lines[0] if k_sub == '-1': print(1) return else: print(0) return else: # Reference's k is not -1 if not sub_lines: print(0) return k_sub = sub_lines[0] if k_sub == '-1': print(0) return try: k_ref = int(k_ref) k_sub = int(k_sub) except: print(0) return if k_ref != k_sub: print(0) return # Now check the submission's segments # Parse submission's segments try: k = int(sub_lines[0]) if k != k_ref: print(0) return if k <= 0: print(0) return segments = [] for line in sub_lines[1:]: l, r = map(int, line.split()) segments.append((l, r)) except: print(0) return # Check the segments form a valid partition # Sort by l segments.sort(key=lambda x: x[0]) current = 1 for (l, r) in segments: if l > current or r < l or r > n: print(0) return if l != current: print(0) return current = r + 1 if current != n + 1: print(0) return # Check each segment is good for (l, r) in segments: if r - l + 1 < 2: print(0) return subarray = a[l-1 : r] seen = set() has_duplicate = False for x in subarray: if x in seen: has_duplicate = True break seen.add(x) if not has_duplicate: print(0) return # All checks passed print(1) if __name__ == "__main__": main()
true
358/C
358
C
PyPy 3-64
TESTS
5
61
28,979,200
161892405
from collections import deque def main(): stack, queue, deck = [], deque(), deque() number_of_commands = int(input()) for _ in range(number_of_commands): appended_value = int(input()) if appended_value == 0: number_of_extractions = 0 extractions = "" if len(stack) > 0: stack.pop() extractions += " popStack" number_of_extractions += 1 if len(queue) > 0: queue.popleft() extractions += " popQueue" number_of_extractions += 1 if len(deck) > 0: if deck[0] > deck[-1]: deck.popleft() extractions += " popFront" number_of_extractions += 1 else: deck.pop() extractions += " popBack" number_of_extractions += 1 print(f"{number_of_extractions}{extractions}") else: operation = None if len(stack) == len(queue) == len(deck) == 0: stack.append(appended_value) operation = "pushStack" elif len(queue) == len(deck) == 0: queue.append(appended_value) operation = "pushQueue" elif len(stack) == len(deck) == 0: deck.append(appended_value) operation = "pushBack" elif len(stack) == len(queue) == 0: stack.append(appended_value) operation = "pushStack" elif len(queue) == 0: queue.append(appended_value) operation = "pushQueue" elif len(deck) == 0: deck.append(appended_value) operation = "pushBack" elif len(stack) == 0: stack.append(appended_value) operation = "pushStack" else: minimum_value = min([stack[-1], queue[-1], deck[0], deck[-1]]) if stack[-1] == minimum_value: stack.append(appended_value) operation = "pushStack" elif queue[-1] == minimum_value: queue.append(appended_value) operation = "pushQueue" elif deck[0] == minimum_value: deck.appendleft(appended_value) operation = "pushFront" else: deck.append(appended_value) operation = "pushBack" print(operation) if __name__ == "__main__": main()
26
311
28,569,600
135330920
# Author Name: Ajay Meena # Codeforce : https://codeforces.com/profile/majay1638 import sys import math import bisect import heapq from bisect import bisect_right from sys import stdin, stdout # -------------- INPUT FUNCTIONS ------------------ def get_ints_in_variables(): return map( int, sys.stdin.readline().strip().split()) def get_int(): return int(sys.stdin.readline()) def get_ints_in_list(): return list( map(int, sys.stdin.readline().strip().split())) def get_list_of_list(n): return [list( map(int, sys.stdin.readline().strip().split())) for _ in range(n)] def get_string(): return sys.stdin.readline().strip() # -------- SOME CUSTOMIZED FUNCTIONS----------- def myceil(x, y): return (x + y - 1) // y # -------------- SOLUTION FUNCTION ------------------ def Solution(): # Write Your Code Here n = get_int() arr = [get_int() for _ in range(n)] u = [0 for _ in range(n)] hp = [] # print(arr,"arr") for i, x in enumerate(arr): if x: heapq.heappush(hp, (-x, i)) else: for t in [1, 2, 3]: if len(hp) > 0: x, j = heapq.heappop(hp) u[j] = t u[i] += 1 hp = [] push = ['pushBack', 'pushStack', 'pushQueue', 'pushFront'] pop = ['popStack', 'popQueue', 'popFront'] for i, x in enumerate(arr): if x: print(push[u[i]]) else: if u[i]: print(str(u[i])+" "+" ".join(pop[:u[i]])) else: print("0") def main(): # Take input Here and Call solution function Solution() # calling main Function if __name__ == '__main__': main()
Codeforces Round 208 (Div. 2)
CF
2,013
2
256
Dima and Containers
Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck. Inna wants her present to show Dima how great a programmer he is. For that, she is going to give Dima commands one by one. There are two types of commands: 1. Add a given number into one of containers. For the queue and the stack, you can add elements only to the end. For the deck, you can add elements to the beginning and to the end. 2. Extract a number from each of at most three distinct containers. Tell all extracted numbers to Inna and then empty all containers. In the queue container you can extract numbers only from the beginning. In the stack container you can extract numbers only from the end. In the deck number you can extract numbers from the beginning and from the end. You cannot extract numbers from empty containers. Every time Dima makes a command of the second type, Inna kisses Dima some (possibly zero) number of times. Dima knows Inna perfectly well, he is sure that this number equals the sum of numbers he extracts from containers during this operation. As we've said before, Dima knows Inna perfectly well and he knows which commands Inna will give to Dima and the order of the commands. Help Dima find the strategy that lets him give as more kisses as possible for his birthday!
The first line contains integer n (1 ≤ n ≤ 105) — the number of Inna's commands. Then n lines follow, describing Inna's commands. Each line consists an integer: 1. Integer a (1 ≤ a ≤ 105) means that Inna gives Dima a command to add number a into one of containers. 2. Integer 0 shows that Inna asks Dima to make at most three extractions from different containers.
Each command of the input must correspond to one line of the output — Dima's action. For the command of the first type (adding) print one word that corresponds to Dima's choice: - pushStack — add to the end of the stack; - pushQueue — add to the end of the queue; - pushFront — add to the beginning of the deck; - pushBack — add to the end of the deck. For a command of the second type first print an integer k (0 ≤ k ≤ 3), that shows the number of extract operations, then print k words separated by space. The words can be: - popStack — extract from the end of the stack; - popQueue — extract from the beginning of the line; - popFront — extract from the beginning from the deck; - popBack — extract from the end of the deck. The printed operations mustn't extract numbers from empty containers. Also, they must extract numbers from distinct containers. The printed sequence of actions must lead to the maximum number of kisses. If there are multiple sequences of actions leading to the maximum number of kisses, you are allowed to print any of them.
null
null
[{"input": "10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0", "output": "0\npushStack\n1 popStack\npushStack\npushQueue\n2 popStack popQueue\npushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}, {"input": "4\n1\n2\n3\n0", "output": "pushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}]
2,000
["constructive algorithms", "greedy", "implementation"]
26
[{"input": "10\r\n0\r\n1\r\n0\r\n1\r\n2\r\n0\r\n1\r\n2\r\n3\r\n0\r\n", "output": "0\r\npushStack\r\n1 popStack\r\npushStack\r\npushQueue\r\n2 popStack popQueue\r\npushStack\r\npushQueue\r\npushFront\r\n3 popStack popQueue popFront\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n0\r\n", "output": "pushStack\r\npushQueue\r\npushFront\r\n3 popStack popQueue popFront\r\n"}, {"input": "2\r\n0\r\n1\r\n", "output": "0\r\npushQueue\r\n"}, {"input": "5\r\n1\r\n1\r\n1\r\n2\r\n1\r\n", "output": "pushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\n"}, {"input": "5\r\n3\r\n2\r\n3\r\n1\r\n0\r\n", "output": "pushStack\r\npushQueue\r\npushFront\r\npushBack\r\n3 popStack popQueue popFront\r\n"}, {"input": "49\r\n8735\r\n95244\r\n50563\r\n33648\r\n10711\r\n30217\r\n49166\r\n28240\r\n0\r\n97232\r\n12428\r\n16180\r\n58610\r\n61112\r\n74423\r\n56323\r\n43327\r\n0\r\n12549\r\n48493\r\n43086\r\n69266\r\n27033\r\n37338\r\n43900\r\n5570\r\n25293\r\n44517\r\n7183\r\n41969\r\n31944\r\n32247\r\n96959\r\n44890\r\n98237\r\n52601\r\n29081\r\n93641\r\n14980\r\n29539\r\n84672\r\n57310\r\n91014\r\n31721\r\n6944\r\n67672\r\n22040\r\n86269\r\n86709\r\n", "output": "pushBack\npushStack\npushQueue\npushBack\npushBack\npushBack\npushFront\npushBack\n3 popStack popQueue popFront\npushStack\npushBack\npushBack\npushBack\npushFront\npushQueue\npushBack\npushBack\n3 popStack popQueue popFront\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushStack\npushBack\npushBack\npushFront\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushQueue\npushBack\npushBack\npushBack\npushBack\n"}, {"input": "55\r\n73792\r\n39309\r\n73808\r\n47389\r\n34803\r\n87947\r\n32460\r\n14649\r\n70151\r\n35816\r\n8272\r\n78886\r\n71345\r\n61907\r\n16977\r\n85362\r\n0\r\n43792\r\n8118\r\n83254\r\n89459\r\n32230\r\n87068\r\n82617\r\n94847\r\n83528\r\n37629\r\n31438\r\n97413\r\n62260\r\n13651\r\n47564\r\n43543\r\n61292\r\n51025\r\n64106\r\n0\r\n19282\r\n35422\r\n19657\r\n95170\r\n10266\r\n43771\r\n3190\r\n93962\r\n11747\r\n43021\r\n91531\r\n88370\r\n1760\r\n10950\r\n77059\r\n61741\r\n52965\r\n10445\r\n", "output": "pushBack\npushBack\npushBack\npushBack\npushBack\npushStack\npushBack\npushBack\npushBack\npushBack\npushBack\npushFront\npushBack\npushBack\npushBack\npushQueue\n3 popStack popQueue popFront\npushBack\npushBack\npushBack\npushFront\npushBack\npushBack\npushBack\npushQueue\npushBack\npushBack\npushBack\npushStack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\n3 popStack popQueue popFront\npushBack\npushBack\npushBack\npushBack\npushFront\npushBack\npushQueue\npushBack\npushBack\npushBack\npushBack\npushBack\npushStack\npushBack\npushBack\npushBack\npushBack\npushBack\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n5\r\n4\r\n9\r\n8\r\n6\r\n7\r\n0\r\n", "output": "pushBack\r\npushBack\r\npushBack\r\npushBack\r\npushBack\r\npushStack\r\npushQueue\r\npushBack\r\npushFront\r\n3 popStack popQueue popFront\r\n"}, {"input": "10\r\n1\r\n3\r\n4\r\n2\r\n6\r\n8\r\n5\r\n7\r\n10\r\n9\r\n", "output": "pushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\npushQueue\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}]
false
stdio
import sys from collections import deque def main(input_path, output_path, submission_path): with open(input_path) as f: input_lines = f.read().splitlines() n = int(input_lines[0]) input_commands = input_lines[1:n+1] with open(submission_path) as f: submission_lines = [line.strip() for line in f] if len(submission_lines) != len(input_commands): print(0) return stack = [] queue = [] deck = deque() sub_idx = 0 for cmd in input_commands: if cmd == '0': if sub_idx >= len(submission_lines): print(0) return line = submission_lines[sub_idx] sub_idx += 1 parts = line.split() if not parts: print(0) return try: k = int(parts[0]) except: print(0) return if k < 0 or k > 3 or len(parts) != k + 1: print(0) return ops = parts[1:] # Compute max possible sum using copies stack_copy = list(stack) queue_copy = list(queue) deck_copy = deque(deck) contributions = [] if stack_copy: contributions.append(stack_copy[-1]) if queue_copy: contributions.append(queue_copy[0]) if deck_copy: deck_val = max(deck_copy[0], deck_copy[-1]) if deck_copy else 0 contributions.append(deck_val) contributions.sort(reverse=True) max_sum = sum(contributions[:3]) # Validate submission's ops temp_stack = list(stack) temp_queue = list(queue) temp_deck = deque(deck) sum_sub = 0 used = set() valid = True for op in ops: container = None if op == 'popStack': if not temp_stack: valid = False break sum_sub += temp_stack.pop() container = 'stack' elif op == 'popQueue': if not temp_queue: valid = False break sum_sub += temp_queue.pop(0) container = 'queue' elif op == 'popFront': if not temp_deck: valid = False break sum_sub += temp_deck.popleft() container = 'deck' elif op == 'popBack': if not temp_deck: valid = False break sum_sub += temp_deck.pop() container = 'deck' else: valid = False break if container in used: valid = False break used.add(container) if not valid or sum_sub != max_sum: print(0) return # Clear containers stack.clear() queue.clear() deck.clear() else: a = int(cmd) if sub_idx >= len(submission_lines): print(0) return line = submission_lines[sub_idx] sub_idx += 1 if line == 'pushStack': stack.append(a) elif line == 'pushQueue': queue.append(a) elif line == 'pushFront': deck.appendleft(a) elif line == 'pushBack': deck.append(a) else: print(0) return print(1) if __name__ == '__main__': main(sys.argv[1], sys.argv[2], sys.argv[3])
true
494/B
494
B
Python 3
TESTS
6
296
6,860,800
9120107
s = input() t = input() n = len(s) m = len(t) t = t + '$' + s p = [0] * (n + m + 1) k = 0 for i in range(1, n + m + 1): while k > 0 and t[k] != t[i]: k = p[k - 1] if t[k] == t[i]: k += 1 p[i] = k ans = [0] * n sums = [0] * (n + 1) curs = 0 was = False j = 0 MOD = 10 ** 9 + 7 for i in range(n): if p[i + m + 1] == m: if not was: was = True curs = 1 while j <= i - m: curs = (curs + sums[j] + 1) % MOD j += 1 ans[i] = curs sums[i] = sums[i - 1] + ans[i] print(sum(ans))
51
264
4,198,400
231039994
s, t = input(), input() n, m = len(t), len(s) + 1 d = 1000000007 g = [1] * m f = k = 0 for i in range(1, m) : if s[i - n:i] == t : k = i if k : f = (f + g[k - n]) % d g[i] += (g[i - 1] + f) % d print(f)
Codeforces Round 282 (Div. 1)
CF
2,014
2
256
Obsessive String
Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k ≥ 1 non-overlapping substrings from it such that each of them contains string t as a substring? More formally, you need to calculate the number of ways to choose two sequences a1, a2, ..., ak and b1, b2, ..., bk satisfying the following requirements: - k ≥ 1 - $$$$ - $$\forall i \left( 1 \leq i \leq k \right) b_i \geq a_i$$ - $$\forall i \left( 2 \leq i \leq k \right) a_i > b_{i-1}$$ - $$\forall i \left( 1 \leq i \leq k \right)$$  t is a substring of string saisai + 1... sbi (string s is considered as 1-indexed). As the number of ways can be rather large print it modulo 109 + 7.
Input consists of two lines containing strings s and t (1 ≤ |s|, |t| ≤ 105). Each string consists of lowercase Latin letters.
Print the answer in a single line.
null
null
[{"input": "ababa\naba", "output": "5"}, {"input": "welcometoroundtwohundredandeightytwo\nd", "output": "274201"}, {"input": "ddd\nd", "output": "12"}]
2,000
["dp", "strings"]
51
[{"input": "ababa\r\naba\r\n", "output": "5\r\n"}, {"input": "welcometoroundtwohundredandeightytwo\r\nd\r\n", "output": "274201\r\n"}, {"input": "ddd\r\nd\r\n", "output": "12\r\n"}, {"input": "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\r\nnssnssns\r\n", "output": "943392\r\n"}, {"input": "kpjmawawawawawawawawawawawawawawawawawawawawawawaw\r\nwawawawa\r\n", "output": "834052\r\n"}, {"input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\r\nvvvvvvvv\r\n", "output": "2728075\r\n"}, {"input": "a\r\na\r\n", "output": "1\r\n"}, {"input": "a\r\naa\r\n", "output": "0\r\n"}, {"input": "a\r\nb\r\n", "output": "0\r\n"}, {"input": "ababababab\r\nabab\r\n", "output": "35\r\n"}]
false
stdio
null
true
494/B
494
B
Python 3
TESTS
6
499
9,523,200
53181649
s, t = input(), input() p = t + '#' + s z = [0] * len(p) l = r = 0 for i in range(1, len(p)): if i <= r: z[i] = min(r - i + 1, z[i - l]) while i + z[i] < len(p) and p[z[i]] == p[i + z[i]]: z[i] += 1 if i + z[i] - 1 > r: l, r = i, i + z[i] - 1 f = [0] * (len(p) + 1) fsum = [0] * (len(p) + 1) fsum2 = [0] * (len(p) + 1) for i in range(len(p) - 1, len(t), -1): if z[i] == len(t): f[i] = fsum2[i + z[i]] + len(p) - i - z[i] + 1 else: f[i] = f[i + 1] fsum[i] = fsum[i + 1] + f[i] fsum2[i] = fsum2[i + 1] + fsum[i] print(fsum[len(t) + 1])
51
264
4,198,400
231039994
s, t = input(), input() n, m = len(t), len(s) + 1 d = 1000000007 g = [1] * m f = k = 0 for i in range(1, m) : if s[i - n:i] == t : k = i if k : f = (f + g[k - n]) % d g[i] += (g[i - 1] + f) % d print(f)
Codeforces Round 282 (Div. 1)
CF
2,014
2
256
Obsessive String
Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k ≥ 1 non-overlapping substrings from it such that each of them contains string t as a substring? More formally, you need to calculate the number of ways to choose two sequences a1, a2, ..., ak and b1, b2, ..., bk satisfying the following requirements: - k ≥ 1 - $$$$ - $$\forall i \left( 1 \leq i \leq k \right) b_i \geq a_i$$ - $$\forall i \left( 2 \leq i \leq k \right) a_i > b_{i-1}$$ - $$\forall i \left( 1 \leq i \leq k \right)$$  t is a substring of string saisai + 1... sbi (string s is considered as 1-indexed). As the number of ways can be rather large print it modulo 109 + 7.
Input consists of two lines containing strings s and t (1 ≤ |s|, |t| ≤ 105). Each string consists of lowercase Latin letters.
Print the answer in a single line.
null
null
[{"input": "ababa\naba", "output": "5"}, {"input": "welcometoroundtwohundredandeightytwo\nd", "output": "274201"}, {"input": "ddd\nd", "output": "12"}]
2,000
["dp", "strings"]
51
[{"input": "ababa\r\naba\r\n", "output": "5\r\n"}, {"input": "welcometoroundtwohundredandeightytwo\r\nd\r\n", "output": "274201\r\n"}, {"input": "ddd\r\nd\r\n", "output": "12\r\n"}, {"input": "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\r\nnssnssns\r\n", "output": "943392\r\n"}, {"input": "kpjmawawawawawawawawawawawawawawawawawawawawawawaw\r\nwawawawa\r\n", "output": "834052\r\n"}, {"input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\r\nvvvvvvvv\r\n", "output": "2728075\r\n"}, {"input": "a\r\na\r\n", "output": "1\r\n"}, {"input": "a\r\naa\r\n", "output": "0\r\n"}, {"input": "a\r\nb\r\n", "output": "0\r\n"}, {"input": "ababababab\r\nabab\r\n", "output": "35\r\n"}]
false
stdio
null
true
71/A
71
A
PyPy 3-64
TESTS
11
61
0
227592389
no_line = int (input ()) if no_line > 0 and no_line < 100: for i in range (no_line): word = input () length = len (word) if length > 10 and length < 101: abrivation = word [0]+ str (length - 2) + word [-1] print (abrivation) else: print (word)
20
31
0
182110578
for _ in range(int(input())): word = input() l = len(word) if l > 10: print(word[0], l-2, word[-1], sep='') else: print(word)
Codeforces Beta Round 65 (Div. 2)
CF
2,011
1
256
Way Too Long Words
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
null
null
[{"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s"}]
800
["strings"]
20
[{"input": "4\r\nword\r\nlocalization\r\ninternationalization\r\npneumonoultramicroscopicsilicovolcanoconiosis\r\n", "output": "word\r\nl10n\r\ni18n\r\np43s\r\n"}, {"input": "5\r\nabcdefgh\r\nabcdefghi\r\nabcdefghij\r\nabcdefghijk\r\nabcdefghijklm\r\n", "output": "abcdefgh\r\nabcdefghi\r\nabcdefghij\r\na9k\r\na11m\r\n"}, {"input": "3\r\nnjfngnrurunrgunrunvurn\r\njfvnjfdnvjdbfvsbdubruvbubvkdb\r\nksdnvidnviudbvibd\r\n", "output": "n20n\r\nj27b\r\nk15d\r\n"}, {"input": "1\r\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt\r\n", "output": "t41t\r\n"}, {"input": "24\r\nyou\r\nare\r\nregistered\r\nfor\r\npractice\r\nyou\r\ncan\r\nsolve\r\nproblems\r\nunofficially\r\nresults\r\ncan\r\nbe\r\nfound\r\nin\r\nthe\r\ncontest\r\nstatus\r\nand\r\nin\r\nthe\r\nbottom\r\nof\r\nstandings\r\n", "output": "you\r\nare\r\nregistered\r\nfor\r\npractice\r\nyou\r\ncan\r\nsolve\r\nproblems\r\nu10y\r\nresults\r\ncan\r\nbe\r\nfound\r\nin\r\nthe\r\ncontest\r\nstatus\r\nand\r\nin\r\nthe\r\nbottom\r\nof\r\nstandings\r\n"}, {"input": "1\r\na\r\n", "output": "a\r\n"}, {"input": "26\r\na\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni\r\nj\r\nk\r\nl\r\nm\r\nn\r\no\r\np\r\nq\r\nr\r\ns\r\nt\r\nu\r\nv\r\nw\r\nx\r\ny\r\nz\r\n", "output": "a\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni\r\nj\r\nk\r\nl\r\nm\r\nn\r\no\r\np\r\nq\r\nr\r\ns\r\nt\r\nu\r\nv\r\nw\r\nx\r\ny\r\nz\r\n"}, {"input": "1\r\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\r\n", "output": "a98j\r\n"}, {"input": "10\r\ngyartjdxxlcl\r\nfzsck\r\nuidwu\r\nxbymclornemdmtj\r\nilppyoapitawgje\r\ncibzc\r\ndrgbeu\r\nhezplmsdekhhbo\r\nfeuzlrimbqbytdu\r\nkgdco\r\n", "output": "g10l\r\nfzsck\r\nuidwu\r\nx13j\r\ni13e\r\ncibzc\r\ndrgbeu\r\nh12o\r\nf13u\r\nkgdco\r\n"}, {"input": "20\r\nlkpmx\r\nkovxmxorlgwaomlswjxlpnbvltfv\r\nhykasjxqyjrmybejnmeumzha\r\ntuevlumpqbbhbww\r\nqgqsphvrmupxxc\r\ntrissbaf\r\nqfgrlinkzvzqdryckaizutd\r\nzzqtoaxkvwoscyx\r\noswytrlnhpjvvnwookx\r\nlpuzqgec\r\ngyzqfwxggtvpjhzmzmdw\r\nrlxjgmvdftvrmvbdwudra\r\nvsntnjpepnvdaxiporggmglhagv\r\nxlvcqkqgcrbgtgglj\r\nlyxwxbiszyhlsrgzeedzprbmcpduvq\r\nyrmqqvrkqskqukzqrwukpsifgtdc\r\nxpuohcsjhhuhvr\r\nvvlfrlxpvqejngwrbfbpmqeirxlw\r\nsvmasocxdvadmaxtrpakysmeaympy\r\nyuflqboqfdt\r\n", "output": "l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c\r\nm\r\nn\r\no\r\nm\r\nr\r\no\r\ns\r\nt\r\nh\r\nr\r\np\r\nk\r\nb\r\nz\r\ng\r\no\r\nc\r\nc\r\nz\r\nz\r\ng\r\nr\r\n"}]
false
stdio
null
true
71/A
71
A
PyPy 3-64
TESTS
11
61
0
225207058
# -*- coding: utf-8 -*- """WayTooLongWords.ipynb Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1jR-K7NZyALsIcfCmgQTjg97eGOjfLWg- """ reps = int(input()) if reps<100: outputList = [] while reps>0: reps-= 1 word = str(input()) firstL = word[0] lastL = word[-1] lenbet = len(word)-2 if len(word)>10: output = str(firstL) + str(lenbet) + str(lastL) print(output) else: print(word) else: print("stop")
20
31
0
182335247
n = int(input()) def long(x): if len(x) <= 10: return x else: length = str(len(x) - 2) p = x[0] + length + x[len(x) - 1] return p for i in range(n): word = input() print(long(word))
Codeforces Beta Round 65 (Div. 2)
CF
2,011
1
256
Way Too Long Words
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
null
null
[{"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s"}]
800
["strings"]
20
[{"input": "4\r\nword\r\nlocalization\r\ninternationalization\r\npneumonoultramicroscopicsilicovolcanoconiosis\r\n", "output": "word\r\nl10n\r\ni18n\r\np43s\r\n"}, {"input": "5\r\nabcdefgh\r\nabcdefghi\r\nabcdefghij\r\nabcdefghijk\r\nabcdefghijklm\r\n", "output": "abcdefgh\r\nabcdefghi\r\nabcdefghij\r\na9k\r\na11m\r\n"}, {"input": "3\r\nnjfngnrurunrgunrunvurn\r\njfvnjfdnvjdbfvsbdubruvbubvkdb\r\nksdnvidnviudbvibd\r\n", "output": "n20n\r\nj27b\r\nk15d\r\n"}, {"input": "1\r\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt\r\n", "output": "t41t\r\n"}, {"input": "24\r\nyou\r\nare\r\nregistered\r\nfor\r\npractice\r\nyou\r\ncan\r\nsolve\r\nproblems\r\nunofficially\r\nresults\r\ncan\r\nbe\r\nfound\r\nin\r\nthe\r\ncontest\r\nstatus\r\nand\r\nin\r\nthe\r\nbottom\r\nof\r\nstandings\r\n", "output": "you\r\nare\r\nregistered\r\nfor\r\npractice\r\nyou\r\ncan\r\nsolve\r\nproblems\r\nu10y\r\nresults\r\ncan\r\nbe\r\nfound\r\nin\r\nthe\r\ncontest\r\nstatus\r\nand\r\nin\r\nthe\r\nbottom\r\nof\r\nstandings\r\n"}, {"input": "1\r\na\r\n", "output": "a\r\n"}, {"input": "26\r\na\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni\r\nj\r\nk\r\nl\r\nm\r\nn\r\no\r\np\r\nq\r\nr\r\ns\r\nt\r\nu\r\nv\r\nw\r\nx\r\ny\r\nz\r\n", "output": "a\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni\r\nj\r\nk\r\nl\r\nm\r\nn\r\no\r\np\r\nq\r\nr\r\ns\r\nt\r\nu\r\nv\r\nw\r\nx\r\ny\r\nz\r\n"}, {"input": "1\r\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\r\n", "output": "a98j\r\n"}, {"input": "10\r\ngyartjdxxlcl\r\nfzsck\r\nuidwu\r\nxbymclornemdmtj\r\nilppyoapitawgje\r\ncibzc\r\ndrgbeu\r\nhezplmsdekhhbo\r\nfeuzlrimbqbytdu\r\nkgdco\r\n", "output": "g10l\r\nfzsck\r\nuidwu\r\nx13j\r\ni13e\r\ncibzc\r\ndrgbeu\r\nh12o\r\nf13u\r\nkgdco\r\n"}, {"input": "20\r\nlkpmx\r\nkovxmxorlgwaomlswjxlpnbvltfv\r\nhykasjxqyjrmybejnmeumzha\r\ntuevlumpqbbhbww\r\nqgqsphvrmupxxc\r\ntrissbaf\r\nqfgrlinkzvzqdryckaizutd\r\nzzqtoaxkvwoscyx\r\noswytrlnhpjvvnwookx\r\nlpuzqgec\r\ngyzqfwxggtvpjhzmzmdw\r\nrlxjgmvdftvrmvbdwudra\r\nvsntnjpepnvdaxiporggmglhagv\r\nxlvcqkqgcrbgtgglj\r\nlyxwxbiszyhlsrgzeedzprbmcpduvq\r\nyrmqqvrkqskqukzqrwukpsifgtdc\r\nxpuohcsjhhuhvr\r\nvvlfrlxpvqejngwrbfbpmqeirxlw\r\nsvmasocxdvadmaxtrpakysmeaympy\r\nyuflqboqfdt\r\n", "output": "lkpmx\r\nk26v\r\nh22a\r\nt13w\r\nq12c\r\ntrissbaf\r\nq21d\r\nz13x\r\no17x\r\nlpuzqgec\r\ng18w\r\nr19a\r\nv25v\r\nx15j\r\nl28q\r\ny26c\r\nx12r\r\nv26w\r\ns27y\r\ny9t\r\n"}, {"input": "100\r\nm\r\nz\r\ns\r\nv\r\nd\r\nr\r\nv\r\ny\r\ny\r\ne\r\np\r\nt\r\nc\r\na\r\nn\r\nm\r\np\r\ng\r\ni\r\nj\r\nc\r\na\r\nb\r\nq\r\ne\r\nn\r\nv\r\no\r\nk\r\nx\r\nf\r\ni\r\nl\r\na\r\nq\r\nr\r\nu\r\nb\r\ns\r\nl\r\nc\r\nl\r\ne\r\nv\r\nj\r\nm\r\nx\r\nb\r\na\r\nq\r\nb\r\na\r\nf\r\nj\r\nv\r\nm\r\nq\r\nc\r\nt\r\nt\r\nn\r\nx\r\no\r\ny\r\nr\r\nu\r\nh\r\nm\r\nj\r\np\r\nj\r\nq\r\nz\r\ns\r\nj\r\no\r\ng\r\nc\r\nm\r\nn\r\no\r\nm\r\nr\r\no\r\ns\r\nt\r\nh\r\nr\r\np\r\nk\r\nb\r\nz\r\ng\r\no\r\nc\r\nc\r\nz\r\nz\r\ng\r\nr\r\n", "output": "m\r\nz\r\ns\r\nv\r\nd\r\nr\r\nv\r\ny\r\ny\r\ne\r\np\r\nt\r\nc\r\na\r\nn\r\nm\r\np\r\ng\r\ni\r\nj\r\nc\r\na\r\nb\r\nq\r\ne\r\nn\r\nv\r\no\r\nk\r\nx\r\nf\r\ni\r\nl\r\na\r\nq\r\nr\r\nu\r\nb\r\ns\r\nl\r\nc\r\nl\r\ne\r\nv\r\nj\r\nm\r\nx\r\nb\r\na\r\nq\r\nb\r\na\r\nf\r\nj\r\nv\r\nm\r\nq\r\nc\r\nt\r\nt\r\nn\r\nx\r\no\r\ny\r\nr\r\nu\r\nh\r\nm\r\nj\r\np\r\nj\r\nq\r\nz\r\ns\r\nj\r\no\r\ng\r\nc\r\nm\r\nn\r\no\r\nm\r\nr\r\no\r\ns\r\nt\r\nh\r\nr\r\np\r\nk\r\nb\r\nz\r\ng\r\no\r\nc\r\nc\r\nz\r\nz\r\ng\r\nr\r\n"}]
false
stdio
null
true
2/B
2
B
PyPy 3
TESTS
30
1,497
23,347,200
71433062
import sys,math input=sys.stdin.readline print=sys.stdout.write n=int(input()) def primefact(n,b): lo=0 hi=int(math.log(n,b)) if(hi==0): return 0 while(lo<hi): mid=(lo+hi)//2 if(n%pow(b,mid)==0): lo=mid+1 else: hi=mid-1 if(n%pow(b,lo)==0): return lo else: #print("s") return lo-1 #print(str(primefact(3072,2))) #print(str(primefact(250,5))) tl=[[0]*(n+1)] fl=[[0]*(n+1)] for i in range(n): x=[0] y=[0] w=list(map(int,input().split())) for j in range(n): a=w[j] if(a==0): x.append(0) y.append(0) else: x.append(primefact(a,2)) y.append(primefact(a,5)) tl.append(x) fl.append(y) dp=[] for i in range(n+1): x=[0]*(n+1) dp.append(x) for i in range(1,n+1): for j in range(1,n+1): a=10**9 b=10**9 if(j==1 and i==1): dp[i][j]=tl[i][j] else: if(i-1): a=dp[i-1][j]+tl[i][j] if(j-1): b=dp[i][j-1]+tl[i][j] dp[i][j]=min(a,b) fp=[] for i in range(n+1): x=[0]*(n+1) fp.append(x) for i in range(1,n+1): for j in range(1,n+1): a=10**9 b=10**9 if(i==1 and j==1): fp[i][j]=fl[i][j] else: if(i-1): a=fp[i-1][j]+fl[i][j] if(j-1): b=fp[i][j-1]+fl[i][j] fp[i][j]=min(a,b) if(dp[n][n]>=fp[n][n]): print(str(fp[n][n])) print("\n") i=n j=n w="" while(i>1 and j>1): if(fp[i-1][j]>fp[i][j-1]): w="R"+w j-=1 else: w="D"+w i-=1 if(i+j!=2): if(i!=1): while(i!=1): w="D"+w i-=1 else: while(j!=1): w="R"+w j-=1 print(w) else: print(str(dp[n][n])) print("\n") i=n j=n s="" while(i>1 and j>1): if(dp[i-1][j]>dp[i][j-1]): s="R"+s j-=1 else: s="D"+s i-=1 if(i+j!=2): if(i!=1): while(i!=1): s="D"+s i-=1 else: while(j!=1): s="R"+s j-=1 print(s)
37
405
52,121,600
187664948
n=int(input()); ma=[[] for x in range(n)]; zflag=0; zindex=[0,0]; #reading the input for i in range(n): j=0; inp=input().split(); for x in inp: if x=='0': ma[i].append(10); zflag=1; zindex=[i,j]; else: ma[i].append(int(x)); j+=1; #counting the number of 2s and 5s of each element ct2=[[0 for x in range(n)] for y in range(n)]; ct5=[[0 for x in range(n)] for y in range(n)]; for i in range(n): for j in range(n): tmp=ma[i][j]; while tmp%2==0: ct2[i][j]+=1; tmp//=2; while tmp%5==0: ct5[i][j]+=1; tmp//=5; #dynamic programming for 2s and 5s dp2=[[0 for x in range(n)] for y in range(n)]; dp5=[[0 for x in range(n)] for y in range(n)]; dp2[0][0]=ct2[0][0]; dp5[0][0]=ct5[0][0]; for i in range(1,n): dp2[0][i]=dp2[0][i-1]+ct2[0][i]; dp5[0][i]=dp5[0][i-1]+ct5[0][i]; dp2[i][0]=dp2[i-1][0]+ct2[i][0]; dp5[i][0]=dp5[i-1][0]+ct5[i][0]; for i in range(1,n): for j in range(1,n): dp2[i][j]=min(dp2[i-1][j]+ct2[i][j],dp2[i][j-1]+ct2[i][j]); dp5[i][j]=min(dp5[i-1][j]+ct5[i][j],dp5[i][j-1]+ct5[i][j]); res=min(dp2[n-1][n-1],dp5[n-1][n-1]); #path calculation if dp2[n-1][n-1]<dp5[n-1][n-1]: path=''; i=n-1; j=n-1; while i>0 and j>0: if dp2[i-1][j]<dp2[i][j-1]: path='D'+path; i-=1; else: path='R'+path; j-=1; while i>0: path='D'+path; i-=1; while j>0: path='R'+path; j-=1; else: path=''; i=n-1; j=n-1; while i>0 and j>0: if dp5[i-1][j]<dp5[i][j-1]: path='D'+path; i-=1; else: path='R'+path; j-=1; while i>0: path='D'+path; i-=1; while j>0: path='R'+path; j-=1; #zero-containing case if zflag: if res>0: res=1; path=''; for i in range(zindex[0]): path+='D'; for i in range(zindex[1]): path+='R'; for i in range(n-zindex[0]-1): path+='D'; for i in range(n-zindex[1]-1): path+='R'; print(res); print(path);
Codeforces Beta Round 2
ICPC
2,010
2
64
The least round way
There is a square matrix n × n, consisting of non-negative integer numbers. You should find such a way on it that - starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell. Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros.
The first line contains an integer number n (2 ≤ n ≤ 1000), n is the size of the matrix. Then follow n lines containing the matrix elements (non-negative integer numbers not exceeding 109).
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.
null
null
[{"input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "0\nDDRR"}]
2,000
["dp", "math"]
37
[{"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "0\r\nDDRR\r\n"}, {"input": "2\r\n7 6\r\n3 8\r\n", "output": "0\r\nDR\r\n"}, {"input": "3\r\n4 10 5\r\n10 9 4\r\n6 5 3\r\n", "output": "1\r\nDRRD\r\n"}, {"input": "4\r\n1 1 9 9\r\n3 4 7 3\r\n7 9 1 7\r\n1 7 1 5\r\n", "output": "0\r\nDDDRRR\r\n"}, {"input": "5\r\n8 3 2 1 4\r\n3 7 2 4 8\r\n9 2 8 9 10\r\n2 3 6 10 1\r\n8 2 2 8 4\r\n", "output": "0\r\nDDDDRRRR\r\n"}, {"input": "6\r\n5 5 4 10 5 5\r\n7 10 8 7 6 6\r\n7 1 7 9 7 8\r\n5 5 3 3 10 9\r\n5 8 10 6 3 8\r\n3 10 5 4 3 4\r\n", "output": "1\r\nDDRRDRDDRR\r\n"}, {"input": "7\r\n2 9 8 2 7 4 8\r\n9 5 4 4 8 5 3\r\n5 7 2 10 8 1 8\r\n2 7 10 7 5 7 7\r\n9 2 7 6 4 8 4\r\n7 2 4 7 4 1 8\r\n9 5 3 10 1 6 2\r\n", "output": "0\r\nRRDRRDRDDDDR\r\n"}, {"input": "8\r\n1 1 10 1 8 4 8 7\r\n9 3 3 2 2 6 2 4\r\n7 4 3 5 10 3 5 1\r\n8 4 4 10 4 5 9 4\r\n5 5 5 2 6 7 1 8\r\n4 10 1 3 2 4 8 3\r\n8 1 10 2 8 2 2 4\r\n2 10 6 8 10 2 8 4\r\n", "output": "0\r\nDRRRRRRRDDDDDD\r\n"}, {"input": "9\r\n8 3 3 3 10 3 10 5 6\r\n2 1 6 1 8 1 9 1 6\r\n6 1 5 4 2 2 10 4 9\r\n1 9 1 3 10 6 10 5 5\r\n1 10 5 4 7 2 5 9 10\r\n6 6 1 3 1 9 4 9 9\r\n5 3 7 6 4 6 2 10 2\r\n9 3 3 10 5 6 7 6 4\r\n4 9 6 7 4 3 7 6 5\r\n", "output": "1\r\nDDDDDRDDDRRRRRRR\r\n"}, {"input": "10\r\n10 8 6 5 9 8 2 5 3 2\r\n3 1 8 6 8 10 5 5 7 8\r\n5 9 7 7 4 9 7 2 5 2\r\n5 9 9 5 4 2 6 6 8 1\r\n10 6 9 9 10 5 6 3 5 9\r\n6 7 10 3 1 4 3 6 7 6\r\n10 10 4 7 4 4 8 6 7 4\r\n10 5 8 2 2 7 4 4 1 4\r\n8 4 6 10 10 6 1 3 3 1\r\n9 9 7 2 9 5 1 8 6 3\r\n", "output": "1\r\nDRDDDRRDDDRRDRDRRR\r\n"}]
false
stdio
import sys def count_factors(x, factor): count = 0 while x > 0 and x % factor == 0: count += 1 x //= factor return count def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input matrix with open(input_path) as f: n = int(f.readline()) matrix = [] for _ in range(n): row = list(map(int, f.readline().split())) matrix.append(row) # Read reference correct_min with open(output_path) as f: correct_min = int(f.readline().strip()) # Read submission's output with open(submission_path) as f: lines = f.read().splitlines() if len(lines) < 2: print(0) return submitted_min_line = lines[0].strip() try: submitted_min = int(submitted_min_line) except: print(0) return if len(lines) >= 2: path = lines[1].strip() else: path = '' # Check submitted_min matches correct_min if submitted_min != correct_min: print(0) return # Check path validity current_i, current_j = 0, 0 expected_length = 2 * (n - 1) if len(path) != expected_length: print(0) return has_zero = False numbers_in_path = [matrix[0][0]] if matrix[0][0] == 0: has_zero = True for move in path: if move == 'D': current_i += 1 elif move == 'R': current_j += 1 else: # invalid move print(0) return # Check if current_i and current_j are within bounds if current_i >= n or current_j >= n: print(0) return num = matrix[current_i][current_j] numbers_in_path.append(num) if num == 0: has_zero = True # Check if path ends at (n-1, n-1) if current_i != n-1 or current_j != n-1: print(0) return # Now check numbers_in_path if has_zero: if correct_min != 1: print(0) return else: print(1) return else: sum_2 = 0 sum_5 = 0 for num in numbers_in_path: sum_2 += count_factors(num, 2) sum_5 += count_factors(num, 5) total_min = min(sum_2, sum_5) if total_min == correct_min: print(1) else: print(0) if __name__ == "__main__": main()
true
53/A
53
A
Python 3
TESTS
11
92
0
169668652
s = input() x = len(s) z = int(input()) l = [] for i in range(0,z): t = input() if t.startswith(s): if x== len(t): break else: l.append(t) l.sort() if len(l) ==0: print(s) else: print(l[0])
25
92
0
141852553
pattern, n = input(), int(input()) _len, arr = len(pattern), [] for i in range(n): helper = input() if pattern == helper[:_len]: arr.append(helper) arr.sort() print(arr[0] if len(arr) > 0 else pattern)
Codeforces Beta Round 49 (Div. 2)
CF
2,011
2
256
Autocomplete
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of n last visited by the user pages and the inputted part s are known. Your task is to complete s to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix s.
The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.
If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages.
null
null
[{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}]
1,100
["implementation"]
25
[{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r\nszjebdoad\r\nchz\r\na\r\n", "output": "kudljmxcse\r\n"}, {"input": "ntqwpa\r\n5\r\nvvepyowvn\r\nntqwpakay\r\nhh\r\nygiafasda\r\nntqwpadm\r\n", "output": "ntqwpadm\r\n"}, {"input": "aflb\r\n6\r\nsaej\r\nujxsiijg\r\npp\r\nhgoprw\r\ncp\r\nnt\r\n", "output": "aflb\r\n"}, {"input": "dzwzyj\r\n7\r\nwvixktp\r\ndzwzyjuhn\r\ndzwzyjqrbd\r\ndzwzyji\r\ndzwzyjyfys\r\ndzwzyjrcb\r\nxptb\r\n", "output": "dzwzyji\r\n"}, {"input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n1\r\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn\r\n", "output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n"}, {"input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\r\n1\r\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n", "output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n"}, {"input": "msjnqudojxtzvpc\r\n2\r\nvlxclsvqbucmbrkwwtoxek\r\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n", "output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n"}]
false
stdio
null
true
53/A
53
A
Python 3
TESTS
10
62
0
178808266
a=input() l=[] for i in range(int(input())): str=input() if str[0:len(a)]==a: l.append(str) if len(l)==0: print(a) else: k=l[0] for i in l: if len(i)<len(k): k=i print(k)
25
92
0
142539513
a=input() b=int(input()) c=[] for i in range(b): d=input() if d[:len(a)]==a: c.append(d) if len(c)>0: print(min(c)) else: print(a)
Codeforces Beta Round 49 (Div. 2)
CF
2,011
2
256
Autocomplete
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of n last visited by the user pages and the inputted part s are known. Your task is to complete s to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix s.
The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.
If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages.
null
null
[{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}]
1,100
["implementation"]
25
[{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r\nszjebdoad\r\nchz\r\na\r\n", "output": "kudljmxcse\r\n"}, {"input": "ntqwpa\r\n5\r\nvvepyowvn\r\nntqwpakay\r\nhh\r\nygiafasda\r\nntqwpadm\r\n", "output": "ntqwpadm\r\n"}, {"input": "aflb\r\n6\r\nsaej\r\nujxsiijg\r\npp\r\nhgoprw\r\ncp\r\nnt\r\n", "output": "aflb\r\n"}, {"input": "dzwzyj\r\n7\r\nwvixktp\r\ndzwzyjuhn\r\ndzwzyjqrbd\r\ndzwzyji\r\ndzwzyjyfys\r\ndzwzyjrcb\r\nxptb\r\n", "output": "dzwzyji\r\n"}, {"input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n1\r\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn\r\n", "output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n"}, {"input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\r\n1\r\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n", "output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n"}, {"input": "msjnqudojxtzvpc\r\n2\r\nvlxclsvqbucmbrkwwtoxek\r\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n", "output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n"}]
false
stdio
null
true
53/A
53
A
PyPy 3
TESTS
15
280
0
97199769
s = input() res = float('inf') flag = 0 for j in range(int(input())): k = input() if((k.find(s)!=-1) and (k.find(s)==0)): l = len(k) if(l<=res): res = l s1 = k flag = 1 if((k==s) or (k.find(s)==-1 and flag == 0) ): s1=s print(s1)
25
92
0
146307674
s = input() n = int(input()) length_orig = len(s) ans = "z"*100 for _ in range(n): astring = input() if astring[:length_orig] == s and astring < ans: ans = astring print(s if ans == "z"*100 else ans)
Codeforces Beta Round 49 (Div. 2)
CF
2,011
2
256
Autocomplete
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of n last visited by the user pages and the inputted part s are known. Your task is to complete s to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix s.
The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.
If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages.
null
null
[{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}]
1,100
["implementation"]
25
[{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r\nszjebdoad\r\nchz\r\na\r\n", "output": "kudljmxcse\r\n"}, {"input": "ntqwpa\r\n5\r\nvvepyowvn\r\nntqwpakay\r\nhh\r\nygiafasda\r\nntqwpadm\r\n", "output": "ntqwpadm\r\n"}, {"input": "aflb\r\n6\r\nsaej\r\nujxsiijg\r\npp\r\nhgoprw\r\ncp\r\nnt\r\n", "output": "aflb\r\n"}, {"input": "dzwzyj\r\n7\r\nwvixktp\r\ndzwzyjuhn\r\ndzwzyjqrbd\r\ndzwzyji\r\ndzwzyjyfys\r\ndzwzyjrcb\r\nxptb\r\n", "output": "dzwzyji\r\n"}, {"input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n1\r\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn\r\n", "output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n"}, {"input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\r\n1\r\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n", "output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n"}, {"input": "msjnqudojxtzvpc\r\n2\r\nvlxclsvqbucmbrkwwtoxek\r\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n", "output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n"}]
false
stdio
null
true
53/A
53
A
Python 3
TESTS
10
62
0
209653034
s=list(input()) n=int(input()) out_put="" size_out_put=1000 for i in range(n): tem=list(input()) if (s==tem[:len(s)] and len(tem)<size_out_put): size_out_put=len(tem) out_put=tem if(tem==s): break if(out_put==""): print("".join(s)) else: print("".join(out_put))
25
92
0
147235582
s=input() k=[] l=0 for i in range(int(input())): a=input() if a.startswith(s): k.append(a) l=1 if l==0: print(s) exit() min=k[0] for i in range(1,len(k)): if k[i]<min: min=k[i] print(min)
Codeforces Beta Round 49 (Div. 2)
CF
2,011
2
256
Autocomplete
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of n last visited by the user pages and the inputted part s are known. Your task is to complete s to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix s.
The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.
If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages.
null
null
[{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}]
1,100
["implementation"]
25
[{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r\nszjebdoad\r\nchz\r\na\r\n", "output": "kudljmxcse\r\n"}, {"input": "ntqwpa\r\n5\r\nvvepyowvn\r\nntqwpakay\r\nhh\r\nygiafasda\r\nntqwpadm\r\n", "output": "ntqwpadm\r\n"}, {"input": "aflb\r\n6\r\nsaej\r\nujxsiijg\r\npp\r\nhgoprw\r\ncp\r\nnt\r\n", "output": "aflb\r\n"}, {"input": "dzwzyj\r\n7\r\nwvixktp\r\ndzwzyjuhn\r\ndzwzyjqrbd\r\ndzwzyji\r\ndzwzyjyfys\r\ndzwzyjrcb\r\nxptb\r\n", "output": "dzwzyji\r\n"}, {"input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n1\r\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn\r\n", "output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n"}, {"input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\r\n1\r\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n", "output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n"}, {"input": "msjnqudojxtzvpc\r\n2\r\nvlxclsvqbucmbrkwwtoxek\r\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n", "output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n"}]
false
stdio
null
true
87/D
87
D
PyPy 3
TESTS
3
77
307,200
149847642
from collections import defaultdict import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def get_root(s): v = [] while not s == root[s]: v.append(s) s = root[s] for i in v: root[i] = s return s def unite(s, t): rs, rt = get_root(s), get_root(t) if not rs ^ rt: return if rank[s] == rank[t]: rank[rs] += 1 if rank[s] >= rank[t]: root[rt] = rs size[rs] += size[rt] else: root[rs] = rt size[rt] += size[rs] return def same(s, t): return True if get_root(s) == get_root(t) else False def get_size(s): return size[get_root(s)] d = defaultdict(lambda : []) n = int(input()) for i in range(n - 1): a, b, c = map(int, input().split()) d[c].append((i, a, b)) x = [0] * (n - 1) root = [i for i in range(n + 1)] rank = [1 for _ in range(n + 1)] size = [1 for _ in range(n + 1)] for i in sorted(d.keys()): for j, a, b in d[i]: x[j] = 2 * get_size(a) * get_size(b) unite(a, b) m = max(x) c = x.count(m) print(m, c) l = [] for i in range(n - 1): if not x[i] ^ m: l.append(i + 1) sys.stdout.write(" ".join(map(str, l)))
80
982
48,025,600
191793487
from collections import defaultdict import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def get_root(s): v = [] while not s == root[s]: v.append(s) s = root[s] for i in v: root[i] = s return s def unite(s, t): rs, rt = get_root(s), get_root(t) if not rs ^ rt: return if rank[s] == rank[t]: rank[rs] += 1 if rank[s] >= rank[t]: root[rt] = rs size[rs] += size[rt] else: root[rs] = rt size[rt] += size[rs] return def same(s, t): return True if get_root(s) == get_root(t) else False def get_size(s): return size[get_root(s)] def bfs(u): q, k = [u], 0 visit[u] = 1 while len(q) ^ k: i = q[k] for j in G[i]: if not visit[j]: q.append(j) visit[j] = 1 parent[j] = i k += 1 return q n = int(input()) d = defaultdict(lambda : []) for i in range(1, n): a, b, c = map(int, input().split()) d[c].append((a, b, i)) root = [i for i in range(n + 1)] rank = [1 for _ in range(n + 1)] size = [1 for _ in range(n + 1)] x = [0] * (n + 1) y = [0] * (n + 1) color = [0] * (n + 1) z = [0] * n for c in sorted(d.keys()): l = 0 s = [0] for a, b, _ in d[c]: u, v = get_root(a), get_root(b) if color[u] ^ c: color[u], x[u], y[l + 1] = c, l + 1, a s.append(get_size(u)) l += 1 if color[v] ^ c: color[v], x[v], y[l + 1] = c, l + 1, b s.append(get_size(v)) l += 1 G = [[] for _ in range(l + 1)] e = dict() for a, b, i in d[c]: u, v = x[get_root(a)], x[get_root(b)] e[(u, v)], e[(v, u)] = i, i G[u].append(v) G[v].append(u) visit, parent = [0] * (l + 1), [-1] * (l + 1) for i in range(1, l + 1): if visit[i]: continue p = bfs(i) cnt = 0 for j in p: cnt += s[j] for j in p[::-1][:-1]: k = parent[j] s[k] += s[j] z[e[(j, k)]] = s[j] * (cnt - s[j]) for a, b, _ in d[c]: unite(a, b) m = max(z) ans = [] for i in range(1, n): if z[i] == m: ans.append(i) m *= 2 c = len(ans) print(m, c) sys.stdout.write(" ".join(map(str, ans)))
Codeforces Beta Round 73 (Div. 1 Only)
CF
2,011
1
256
Beautiful Road
A long time ago in some country in Asia were civil wars. Each of n cities wanted to seize power. That's why sometimes one city gathered an army and sent it to campaign against another city. Road making was difficult, so the country had few roads, exactly n - 1. Also you could reach any city from any other city going on those roads. Even during the war the Oriental people remain spiritually rich and appreciate the beauty of nature. And to keep the memory of this great crusade for the centuries to come, they planted one beautiful tree by the road on which the army spent most time. The Oriental people love nature, that's why if there were several such roads, then one tree was planted by each of them. Recently, when the records of the war were found, it became clear that each city attacked each other one exactly once. There were exactly n(n - 1) attacks in total. Everyone has been wondering what road after those wars became the most beautiful, that is, by which road they planted the largest number of beautiful trees.
The first line contains an integer n (2 ≤ n ≤ 105), which represents the number of cities. Next n - 1 lines contain three integers each: the numbers of cities ai, bi (1 ≤ ai, bi ≤ n), connected by the i-th road and the number of days di the army spends to go on it (1 ≤ di ≤ 109). The lengths of several roads may coincide.
Print on the first line two integers — the number of beautiful trees on the most beautiful road and the number of the most beautiful roads. Print on the second line the list of the most beautiful roads in the sorted order by the numbers' increasing. The roads are numbered from 1 to n - 1 in the order in which they are given in the input data. Please, do not use %lld specificator to write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).
null
null
[{"input": "2\n2 1 5", "output": "2 1\n1"}, {"input": "6\n1 2 1\n1 3 5\n3 4 2\n3 5 3\n3 6 4", "output": "16 1\n2"}]
2,300
["dfs and similar", "dp", "dsu", "graphs", "implementation", "sortings", "trees"]
80
[{"input": "2\r\n2 1 5\r\n", "output": "2 1\r\n1 \r\n"}, {"input": "6\r\n1 2 1\r\n1 3 5\r\n3 4 2\r\n3 5 3\r\n3 6 4\r\n", "output": "16 1\r\n2 \r\n"}, {"input": "10\r\n3 9 131\r\n1 6 77017\r\n4 10 93113\r\n4 8 30971\r\n2 7 93113\r\n10 6 30971\r\n3 7 35091\r\n5 9 14051\r\n5 1 35091\r\n", "output": "32 1\r\n3 \r\n"}, {"input": "9\r\n1 2 13378\r\n2 7 36739\r\n2 4 13378\r\n2 8 36739\r\n3 2 13378\r\n9 2 36739\r\n5 2 36739\r\n2 6 13378\r\n", "output": "16 4\r\n2 4 6 7 \r\n"}, {"input": "10\r\n7 6 91372\r\n8 1 91372\r\n9 10 14279\r\n6 2 99261\r\n1 6 91372\r\n3 10 84628\r\n10 2 99261\r\n7 5 14279\r\n1 4 8070\r\n", "output": "48 1\r\n4 \r\n"}, {"input": "7\r\n6 4 11023\r\n1 6 71134\r\n1 5 86725\r\n3 4 11023\r\n4 2 86725\r\n7 4 71134\r\n", "output": "12 2\r\n3 5 \r\n"}, {"input": "4\r\n3 2 18720\r\n1 3 18720\r\n4 1 36781\r\n", "output": "6 1\r\n3 \r\n"}, {"input": "5\r\n2 4 82826\r\n3 1 15614\r\n1 5 22316\r\n1 2 15614\r\n", "output": "8 1\r\n1 \r\n"}, {"input": "9\r\n5 8 24153\r\n1 2 29795\r\n4 3 24153\r\n9 7 9865\r\n3 9 24153\r\n3 6 24153\r\n8 1 52473\r\n5 3 9865\r\n", "output": "28 1\r\n7 \r\n"}, {"input": "5\r\n4 5 89024\r\n1 2 85727\r\n3 2 89024\r\n5 3 89024\r\n", "output": "12 2\r\n3 4 \r\n"}, {"input": "10\r\n6 3 59\r\n1 3 85\r\n5 1 3\r\n7 1 59\r\n2 1 59\r\n5 4 59\r\n9 7 59\r\n1 10 59\r\n8 3 3\r\n", "output": "42 1\r\n2 \r\n"}, {"input": "10\r\n8 5 11\r\n9 1 48\r\n9 5 19\r\n3 1 100\r\n10 5 38\r\n5 6 11\r\n10 4 88\r\n7 1 100\r\n1 2 11\r\n", "output": "20 1\r\n2 \r\n"}, {"input": "10\r\n8 7 58\r\n4 1 53\r\n7 2 80\r\n8 5 13\r\n4 6 53\r\n8 10 53\r\n1 3 58\r\n5 9 58\r\n10 4 80\r\n", "output": "48 1\r\n9 \r\n"}, {"input": "10\r\n7 2 23\r\n5 8 45\r\n1 4 47\r\n8 7 29\r\n2 9 4\r\n1 7 47\r\n10 2 47\r\n3 7 47\r\n6 10 4\r\n", "output": "32 2\r\n6 7 \r\n"}, {"input": "17\r\n8 15 4642\r\n6 13 21576\r\n1 9 21576\r\n3 10 79919\r\n12 16 21576\r\n13 2 40245\r\n5 16 86964\r\n14 1 21576\r\n6 12 18234\r\n4 2 4642\r\n17 11 76268\r\n14 4 4642\r\n5 11 26828\r\n7 8 79919\r\n3 9 40245\r\n15 17 4642\r\n", "output": "132 1\r\n7 \r\n"}, {"input": "9\r\n1 5 276075940\r\n4 2 661019424\r\n7 4 659149917\r\n2 9 262370785\r\n5 6 699554153\r\n3 7 688485178\r\n4 5 262370785\r\n2 8 276075940\r\n", "output": "24 1\r\n2 \r\n"}]
false
stdio
null
true
875/D
875
D
Python 3
TESTS
6
62
5,529,600
31432874
n = int(input()) a = list(map(int, input().split())) c = 0 m = 0 for k in range(n): m = max(m, a[k]) for i in range(n): for j in range(n): if (a[i] <= a[j]): if (a[i] | a[j] < m): c += 1 print(c)
78
514
127,283,200
226308676
from collections import defaultdict def read_ints(): return map(int, input().split()) def read_int(): return int(input()) def yes_no(yes): print('Yes' if yes else 'No') return yes def solve_test(): n = read_int() a = list(read_ints()) def get_ans(): bit_size = 32 lefts = [[-1] * n for _ in range(bit_size)] rights = [[n] * n for _ in range(bit_size)] for i in range(n): value = a[i] for bit in range(bit_size): if i > 0: lefts[bit][i] = lefts[bit][i - 1] has = value % 2 == 1 if has: lefts[bit][i] = i value //= 2 for i in range(n - 1, -1, -1): value = a[i] for bit in range(bit_size): if i < n - 1: rights[bit][i] = rights[bit][i + 1] has = value % 2 == 1 if has: rights[bit][i] = i value //= 2 left_larger = [-1] * n right_larger = [n] * n stack = [-1] for i in range(n): value = a[i] while len(stack) > 1: top_value = a[stack[-1]] if top_value < value: stack.pop() else: break left_larger[i] = stack[-1] stack.append(i) stack = [n] for i in range(n - 1, -1, -1): value = a[i] while len(stack) > 1: top_value = a[stack[-1]] if top_value <= value: stack.pop() else: break right_larger[i] = stack[-1] stack.append(i) ans = 0 for i in range(n): value = a[i] start = left_larger[i] + 1 end = right_larger[i] - 1 max_left = start - 1 min_right = end + 1 for bit in range(bit_size): has = value % 2 == 1 if not has: max_left = max(max_left, lefts[bit][i]) min_right = min(min_right, rights[bit][i]) value //= 2 total = (end - i + 1) * (i - start + 1) bad = (min_right - i) * (i - max_left) # print(total, bad) ans += total - bad return ans print(get_ans()) """ 5 3 2 1 6 5 4 3 3 3 3 """ """ 8 0 """ def solve(): t = 1 # t = read_int() for _ in range(t): solve_test() if __name__ == '__main__': solve()
Codeforces Round 441 (Div. 1, by Moscow Team Olympiad)
CF
2,017
1
512
High Cry
Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :) Rick and Morty like to go to the ridge High Cry for crying loudly — there is an extraordinary echo. Recently they discovered an interesting acoustic characteristic of this ridge: if Rick and Morty begin crying simultaneously from different mountains, their cry would be heard between these mountains up to the height equal the bitwise OR of mountains they've climbed and all the mountains between them. Bitwise OR is a binary operation which is determined the following way. Consider representation of numbers x and y in binary numeric system (probably with leading zeroes) x = xk... x1x0 and y = yk... y1y0. Then z = x | y is defined following way: z = zk... z1z0, where zi = 1, if xi = 1 or yi = 1, and zi = 0 otherwise. In the other words, digit of bitwise OR of two numbers equals zero if and only if digits at corresponding positions is both numbers equals zero. For example bitwise OR of numbers 10 = 10102 and 9 = 10012 equals 11 = 10112. In programming languages C/C++/Java/Python this operation is defined as «|», and in Pascal as «or». Help Rick and Morty calculate the number of ways they can select two mountains in such a way that if they start crying from these mountains their cry will be heard above these mountains and all mountains between them. More formally you should find number of pairs l and r (1 ≤ l < r ≤ n) such that bitwise OR of heights of all mountains between l and r (inclusive) is larger than the height of any mountain at this interval.
The first line contains integer n (1 ≤ n ≤ 200 000), the number of mountains in the ridge. Second line contains n integers ai (0 ≤ ai ≤ 109), the heights of mountains in order they are located in the ridge.
Print the only integer, the number of ways to choose two different mountains.
null
In the first test case all the ways are pairs of mountains with the numbers (numbering from one): (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5) In the second test case there are no such pairs because for any pair of mountains the height of cry from them is 3, and this height is equal to the height of any mountain.
[{"input": "5\n3 2 1 6 5", "output": "8"}, {"input": "4\n3 3 3 3", "output": "0"}]
2,200
["binary search", "bitmasks", "combinatorics", "data structures", "divide and conquer"]
78
[{"input": "5\r\n3 2 1 6 5\r\n", "output": "8\r\n"}, {"input": "4\r\n3 3 3 3\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "1\r\n6\r\n", "output": "0\r\n"}, {"input": "228\r\n1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 127 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 255 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 127 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7\r\n", "output": "0\r\n"}, {"input": "50\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "81\r\n52673 19697 35512 34827 62387 60516 43450 22979 133 42838 16525 37792 12752 47765 45874 64082 14727 51748 56809 604 51751 59450 43797 31724 1024 9648 59503 53771 60868 38612 62867 57026 62297 15806 10549 7660 47983 30060 20829 46168 64832 18145 32300 53558 56554 33754 21953 58346 13894 6318 33563 63571 41705 49407 26794 51159 29011 43310 6847 11688 45129 2180 50406 12475 58021 58899 32867 15910 25819 33961 18759 64166 34472 57376 10903 16958 22656 14459 26900 33012 11615\r\n", "output": "3239\r\n"}, {"input": "69\r\n3 4 2 4 5 2 0 5 2 8 8 0 0 8 6 4 3 0 0 1 2 5 8 1 7 4 6 0 6 1 8 4 2 0 4 3 5 6 2 8 3 7 7 6 0 3 8 6 2 6 0 2 4 5 0 3 6 8 8 8 3 2 2 6 7 8 5 3 5\r\n", "output": "2262\r\n"}, {"input": "92\r\n7 1 1 2 5 8 3 4 1 3 0 7 5 2 0 7 2 7 3 2 7 3 7 7 7 0 8 2 0 7 4 7 6 7 3 6 2 0 2 4 1 6 6 4 5 7 3 2 8 6 7 8 8 2 4 2 7 2 2 4 7 5 4 3 4 4 1 2 2 1 4 4 1 8 0 7 8 0 8 6 7 3 2 6 7 2 7 3 1 0 3 6\r\n", "output": "3630\r\n"}, {"input": "79\r\n48952 12057 54091 43986 4825 65319 8888 63361 37922 29880 42348 16202 7107 33942 28418 5373 37969 36323 36644 8650 2951 22084 38174 65285 4123 19887 46516 40807 40062 20157 58343 52857 42065 28397 15571 29810 17508 34053 2732 26989 37441 53824 23112 13218 6696 46519 10848 37031 16381 32753 39768 8870 61745 57147 47588 1759 25424 29718 34450 31641 64681 59257 47088 36889 31207 23425 25712 41458 27960 49566 50455 10157 53577 34807 39258 31040 39873 10859 24672\r\n", "output": "3081\r\n"}, {"input": "80\r\n2 3 2 2 3 5 4 0 2 3 3 8 4 8 3 8 4 0 0 8 1 7 3 0 7 2 8 5 5 3 0 0 2 7 4 1 6 0 6 2 5 3 0 4 8 6 7 0 3 2 3 3 8 5 6 5 5 6 3 4 0 5 8 3 6 3 6 8 1 7 8 8 3 0 3 8 0 4 2 3\r\n", "output": "2997\r\n"}, {"input": "74\r\n63528 64641 32712 5228 59859 45909 4464 57592 27841 17687 62064 19286 40682 40598 63681 18441 53374 38527 16119 35588 42691 4015 20251 13679 50493 37149 34328 37977 24309 8750 54309 44091 12187 21917 24216 31326 40587 52208 19362 1642 13268 6596 10380 4937 37224 25970 59246 63483 20707 47702 57607 26046 30796 32636 7168 8816 11892 12934 53913 704 61887 65147 52243 14676 20993 33174 40778 23764 37017 5206 22521 55323 36803 9943\r\n", "output": "2691\r\n"}, {"input": "47\r\n4 4 3 1 0 1 2 8 6 3 1 5 6 5 4 5 3 8 4 8 7 6 8 1 4 8 1 5 7 4 8 7 8 7 5 6 7 5 5 5 6 5 3 0 2 5 6\r\n", "output": "1010\r\n"}, {"input": "53\r\n1 2 0 1 0 1 1 1 1 2 0 2 1 0 2 2 1 1 2 0 0 2 1 2 2 1 1 0 0 1 0 1 2 2 1 1 1 1 1 1 2 1 0 1 2 1 0 0 0 1 2 0 2\r\n", "output": "1288\r\n"}, {"input": "85\r\n4 4 4 4 2 1 2 0 0 3 1 0 4 3 2 2 3 4 1 0 0 0 0 2 1 1 1 1 0 1 4 2 2 1 0 4 4 1 4 0 3 2 3 4 0 4 3 0 3 1 0 1 3 1 2 0 2 3 1 1 2 4 0 4 1 1 1 3 3 4 3 1 0 3 0 0 0 4 2 3 1 1 4 0 0\r\n", "output": "3346\r\n"}, {"input": "100\r\n1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 127 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7\r\n", "output": "0\r\n"}, {"input": "100\r\n1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 32 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 64 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 32 1 2 1 4\r\n", "output": "4950\r\n"}, {"input": "100\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "100\r\n1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512\r\n", "output": "4950\r\n"}, {"input": "100\r\n1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 4 8 8 8 8 8 8 8 8 8 8 16 16 16 16 16 16 16 16 16 16 32 32 32 32 32 32 32 32 32 32 64 64 64 64 64 64 64 64 64 64 128 128 128 128 128 128 128 128 128 128 256 256 256 256 256 256 256 256 256 256 512 512 512 512 512 512 512 512 512 512\r\n", "output": "4500\r\n"}]
false
stdio
null
true
53/A
53
A
Python 3
TESTS
15
218
307,200
69823598
a='z'*101 z=input() for i in range(int(input())): x=input() if z==x[0:len(z)]: if len(x)<=len(a) and sum(map(ord,x))<sum(map(ord,a)): a=x print([z,a][z==a[0:len(z)]])
25
92
0
148263339
s=input() n=int(input()) lst=[] for i in range(n): s1=input() if len(s1)<len(s): continue if s1[:len(s)]==s: lst.append(s1) lst.sort() if len(lst)==0: print(s) else: print(lst[0])
Codeforces Beta Round 49 (Div. 2)
CF
2,011
2
256
Autocomplete
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of n last visited by the user pages and the inputted part s are known. Your task is to complete s to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix s.
The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.
If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages.
null
null
[{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}]
1,100
["implementation"]
25
[{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r\nszjebdoad\r\nchz\r\na\r\n", "output": "kudljmxcse\r\n"}, {"input": "ntqwpa\r\n5\r\nvvepyowvn\r\nntqwpakay\r\nhh\r\nygiafasda\r\nntqwpadm\r\n", "output": "ntqwpadm\r\n"}, {"input": "aflb\r\n6\r\nsaej\r\nujxsiijg\r\npp\r\nhgoprw\r\ncp\r\nnt\r\n", "output": "aflb\r\n"}, {"input": "dzwzyj\r\n7\r\nwvixktp\r\ndzwzyjuhn\r\ndzwzyjqrbd\r\ndzwzyji\r\ndzwzyjyfys\r\ndzwzyjrcb\r\nxptb\r\n", "output": "dzwzyji\r\n"}, {"input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n1\r\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn\r\n", "output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n"}, {"input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\r\n1\r\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n", "output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n"}, {"input": "msjnqudojxtzvpc\r\n2\r\nvlxclsvqbucmbrkwwtoxek\r\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n", "output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n"}]
false
stdio
null
true
53/A
53
A
Python 3
TESTS
10
92
0
216985063
a=input() c="a"*100 n="" for i in range(int(input())): b=input() if a == b[:len(a)] : if len(b) <len(c): n=b c=b if len(n) > 0: print(n) else: print(a)
25
92
0
153434389
def startWith(s1, s): if len(s1) < len(s): return False if s1[:len(s)] == s: return True return False s = input() n = int(input()) myList = [] for i in range(n): s1 = input() if startWith(s1, s): myList.append(s1) myList.sort() if len(myList) == 0: print(s) else: print(myList[0])
Codeforces Beta Round 49 (Div. 2)
CF
2,011
2
256
Autocomplete
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of n last visited by the user pages and the inputted part s are known. Your task is to complete s to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix s.
The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.
If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages.
null
null
[{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}]
1,100
["implementation"]
25
[{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r\nszjebdoad\r\nchz\r\na\r\n", "output": "kudljmxcse\r\n"}, {"input": "ntqwpa\r\n5\r\nvvepyowvn\r\nntqwpakay\r\nhh\r\nygiafasda\r\nntqwpadm\r\n", "output": "ntqwpadm\r\n"}, {"input": "aflb\r\n6\r\nsaej\r\nujxsiijg\r\npp\r\nhgoprw\r\ncp\r\nnt\r\n", "output": "aflb\r\n"}, {"input": "dzwzyj\r\n7\r\nwvixktp\r\ndzwzyjuhn\r\ndzwzyjqrbd\r\ndzwzyji\r\ndzwzyjyfys\r\ndzwzyjrcb\r\nxptb\r\n", "output": "dzwzyji\r\n"}, {"input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n1\r\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn\r\n", "output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n"}, {"input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\r\n1\r\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n", "output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n"}, {"input": "msjnqudojxtzvpc\r\n2\r\nvlxclsvqbucmbrkwwtoxek\r\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n", "output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n"}]
false
stdio
null
true
39/F
39
F
PyPy 3
TESTS
10
280
0
68866503
rdl = lambda: map(int, input().split()) def conv(x): x = str(x); x = x.replace('{','');x = x.replace('}',''); x = x.replace(',',''); return [int(s) for s in x.split()] a,b,c = rdl();ll = list(rdl());hh = conv(set(ll));x = sorted(list(rdl()));lx =[];xr=[];sna = [];flag = False;Opss = False;xsa=[] for i in range(len(x)): f = x[i];cou = 0 for j in range(len(hh)): if f % ll[j] == 0:lx.append(ll[j]) else: xsa.append(ll[j]) for i in range(len(xsa)): if xsa[i] not in lx:xr.append(xsa[i]);Opss = True if Opss: xr = conv(set(xr)) for i in range(len(xr)): if xr[i] not in lx: sna.append(ll.index(xr[i])+1) flag = True if flag: print(len(sna)) print(*sna) exit() lsx = conv(set(lx));rf = [] for i in range(len(lsx)): rf.append(lx.count(lsx[i])) xsr = min(rf);ans = [] for i in range(len(rf)): if rf[i] == xsr:ans.append(i) for i in range(len(ans)): f = lsx[ans[i]] for j in range(len(ll)): if f == ll[j]:sna.append(j+1) print(len(sna)) print(*sorted(sna)) ''' 10 5 5 1 5 3 5 1 1 6 5 7 2 '''
35
92
0
193071126
n, m, k = map(int, input().split()) jumps = list(map(int, input().split())) mos = list(map(int, input().split())) hash = {} for x, frog in enumerate(jumps, start=1): count = 0 for kill in mos: count += int(kill % frog == 0) hash[count] = hash.get(count, []) hash[count].append(x) ans = min(hash) print(len(hash[ans])) print(*hash[ans])
School Team Contest 1 (Winter Computer School 2010/11)
ICPC
2,010
2
64
Pacifist frogs
Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much. One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to n and the number of a hill is equal to the distance in meters between it and the island. The distance between the n-th hill and the shore is also 1 meter. Thumbelina is too small to make such jumps. Fortunately, a family of frogs living in the swamp suggests to help her. Each frog agrees to give Thumbelina a ride but Thumbelina should choose only one frog. Each frog has a certain jump length. If Thumbelina agrees to accept help from a frog whose jump length is d, the frog will jump from the island on the hill d, then — on the hill 2d, then 3d and so on until they get to the shore (i.e. find itself beyond the hill n). However, there is one more problem: mosquitoes also live in the swamp. At the moment they have a siesta, and they are having a nap on some hills. If the frog jumps on a hill with a mosquito the frog will smash it. The frogs Thumbelina has met are pacifists, so they will find the death of each mosquito very much sad. Help Thumbelina choose a frog that will bring her to the shore and smash as small number of mosquitoes as possible.
The first line contains three integers n, m and k (1 ≤ n ≤ 109, 1 ≤ m, k ≤ 100) — the number of hills, frogs and mosquitoes respectively. The second line contains m integers di (1 ≤ di ≤ 109) — the lengths of the frogs’ jumps. The third line contains k integers — the numbers of the hills on which each mosquito is sleeping. No more than one mosquito can sleep on each hill. The numbers in the lines are separated by single spaces.
In the first line output the number of frogs that smash the minimal number of mosquitoes, in the second line — their numbers in increasing order separated by spaces. The frogs are numbered from 1 to m in the order of the jump length given in the input data.
null
null
[{"input": "5 3 5\n2 3 4\n1 2 3 4 5", "output": "2\n2 3"}, {"input": "1000000000 2 3\n2 5\n999999995 999999998 999999996", "output": "1\n2"}]
1,300
["implementation"]
35
[{"input": "5 3 5\r\n2 3 4\r\n1 2 3 4 5\r\n", "output": "2\r\n2 3\r\n"}, {"input": "1000000000 2 3\r\n2 5\r\n999999995 999999998 999999996\r\n", "output": "1\r\n2\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "2 2 1\r\n2 1\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "3 2 2\r\n2 4\r\n3 2\r\n", "output": "1\r\n2\r\n"}, {"input": "10 3 6\r\n5 2 8\r\n5 6 7 8 9 10\r\n", "output": "1\r\n3\r\n"}, {"input": "10 10 9\r\n10 9 8 7 6 5 4 3 2 1\r\n10 9 8 7 5 4 3 2 1\r\n", "output": "1\r\n5\r\n"}, {"input": "20 3 5\r\n2 3 5\r\n2 5 6 10 15\r\n", "output": "1\r\n2\r\n"}, {"input": "20 4 8\r\n1 2 3 4\r\n2 4 6 8 10 12 14 16 18 20\r\n", "output": "1\r\n3\r\n"}, {"input": "10 5 5\r\n1 5 3 5 1\r\n1 6 5 7 2\r\n", "output": "3\r\n2 3 4\r\n"}, {"input": "20 10 5\r\n1 12 6 11 9 21 15 16 8 9\r\n11 13 15 2 1\r\n", "output": "7\r\n2 3 5 6 8 9 10\r\n"}, {"input": "20 10 10\r\n9 8 21 8 7 2 13 17 20 18\r\n7 16 20 3 6 1 11 18 15 17\r\n", "output": "2\r\n3 7\r\n"}, {"input": "20 10 10\r\n6 17 14 12 13 15 6 14 16 17\r\n1 6 16 14 7 8 9 12 10 2\r\n", "output": "4\r\n2 5 6 10\r\n"}, {"input": "100 30 30\r\n25 34 81 32 96 79 36 21 53 15 51 69 78 99 60 2 80 37 61 70 32 31 31 6 7 38 95 70 81 39\r\n1 50 75 8 90 69 13 57 6 4 60 19 94 52 45 42 95 88 21 22 96 2 56 61 31 78 7 62 68 72\r\n", "output": "11\r\n3 6 9 11 14 17 18 20 26 28 29\r\n"}, {"input": "1000 19 27\r\n656 162 264 790 579 786 877 998 516 247 650 150 858 281 279 549 354 353 533\r\n349 411 1 248 22 649 726 382 423 832 172 864 17 658 840 572 564 287 800 919 500 575 461 40 1000 383 624\r\n", "output": "19\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\r\n"}]
false
stdio
null
true
313/C
313
C
PyPy 3-64
TESTS
2
46
0
219947693
import sys input=sys.stdin.readline n=int(input()) l=[int(i) for i in input().split(" ")] l.sort() def f(n,l): if n==1: return l[0] else: l1=l[-1:-4-1*n:-4] l2=l[-2:-4-1*n:-4] l3=l[-3:-4-1*n:-4] l4=l[-4:-4-1*n:-4] k=n//4 return l[-1]+f(k,l1)+f(k,l2)+f(k,l3)+f(k,l4) print(f(n,l))
61
576
141,107,200
215367603
n = int(input()) A = list(map(int, input().split())) A.sort(reverse=True) if n == 1: print(A[0]) else: res = 0 i = 1 while(i <= n): res += sum(A[0: i]) i *= 4 print(res)
Codeforces Round 186 (Div. 2)
CF
2,013
1
256
Ilya and Matrix
Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve. He's got a square 2n × 2n-sized matrix and 4n integers. You need to arrange all these numbers in the matrix (put each number in a single individual cell) so that the beauty of the resulting matrix with numbers is maximum. The beauty of a 2n × 2n-sized matrix is an integer, obtained by the following algorithm: 1. Find the maximum element in the matrix. Let's denote it as m. 2. If n = 0, then the beauty of the matrix equals m. Otherwise, a matrix can be split into 4 non-intersecting 2n - 1 × 2n - 1-sized submatrices, then the beauty of the matrix equals the sum of number m and other four beauties of the described submatrices. As you can see, the algorithm is recursive. Help Ilya, solve the problem and print the resulting maximum beauty of the matrix.
The first line contains integer 4n (1 ≤ 4n ≤ 2·106). The next line contains 4n integers ai (1 ≤ ai ≤ 109) — the numbers you need to arrange in the 2n × 2n-sized matrix.
On a single line print the maximum value of the beauty of the described matrix. 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
Consider the second sample. You need to arrange the numbers in the matrix as follows: Then the beauty of the matrix will equal: 4 + 1 + 2 + 3 + 4 = 14.
[{"input": "1\n13", "output": "13"}, {"input": "4\n1 2 3 4", "output": "14"}]
1,400
["constructive algorithms", "greedy", "implementation", "sortings"]
61
[{"input": "1\r\n13\r\n", "output": "13\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "14\r\n"}, {"input": "16\r\n978618343 473608041 799158564 800910753 461479363 520477481 780529176 678879534 118274424 720632652 639921017 582019792 143353286 537373229 944668919 758615621\r\n", "output": "14440495117\r\n"}, {"input": "16\r\n521848329 105907607 414661942 473600423 264555612 186332345 774233687 736918178 456150336 216550357 568433949 135218174 18789799 324141005 617635501 149674864\r\n", "output": "9436107110\r\n"}, {"input": "16\r\n612095723 222321386 616933999 386488979 943748076 902598472 681820298 449949990 359507903 613063462 437031953 902348579 697631196 99280352 60225467 969809069\r\n", "output": "13643168169\r\n"}, {"input": "16\r\n666766712 653140033 670637874 170909587 210382562 358152171 128926299 750686139 315428350 607830667 363710774 325047228 570196776 38425426 438601514 634274054\r\n", "output": "10395033063\r\n"}, {"input": "1\r\n6\r\n", "output": "6\r\n"}, {"input": "1\r\n8\r\n", "output": "8\r\n"}, {"input": "1\r\n9\r\n", "output": "9\r\n"}, {"input": "4\r\n7 9 6 9\r\n", "output": "40\r\n"}, {"input": "4\r\n423654797 623563697 645894116 384381709\r\n", "output": "2723388435\r\n"}, {"input": "4\r\n437587210 297534606 891773002 56712976\r\n", "output": "2575380796\r\n"}, {"input": "4\r\n963662765 272656295 383441522 477665112\r\n", "output": "3061088459\r\n"}, {"input": "4\r\n791725034 812168727 528894922 479977172\r\n", "output": "3424934582\r\n"}]
false
stdio
null
true
313/C
313
C
Python 3
TESTS
2
61
1,228,800
213012249
from math import log2, sqrt from typing import List def calculate_beauty(nums: List[int], n: int) -> int: if n == 0: return nums[0] # Divide the list into four roughly equal parts quarter = len(nums) // 4 parts = [nums[i * quarter:(i + 1) * quarter] for i in range(4)] # For each part, recursively calculate its beauty beauties = [calculate_beauty(part, n - 1) for part in parts] # The beauty of the current group is the sum of the maximum element and the beauties of the subgroups return max(nums) + sum(beauties) def main(): # Get input from the user n = int(input()) nums = list(map(int, input().split())) nums.sort(reverse=True) # Calculate n from 4^n n = int(log2(sqrt(n))) # Calculate and print the maximum beauty result = calculate_beauty(nums, n) print(result) main()
61
576
141,107,200
215367603
n = int(input()) A = list(map(int, input().split())) A.sort(reverse=True) if n == 1: print(A[0]) else: res = 0 i = 1 while(i <= n): res += sum(A[0: i]) i *= 4 print(res)
Codeforces Round 186 (Div. 2)
CF
2,013
1
256
Ilya and Matrix
Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve. He's got a square 2n × 2n-sized matrix and 4n integers. You need to arrange all these numbers in the matrix (put each number in a single individual cell) so that the beauty of the resulting matrix with numbers is maximum. The beauty of a 2n × 2n-sized matrix is an integer, obtained by the following algorithm: 1. Find the maximum element in the matrix. Let's denote it as m. 2. If n = 0, then the beauty of the matrix equals m. Otherwise, a matrix can be split into 4 non-intersecting 2n - 1 × 2n - 1-sized submatrices, then the beauty of the matrix equals the sum of number m and other four beauties of the described submatrices. As you can see, the algorithm is recursive. Help Ilya, solve the problem and print the resulting maximum beauty of the matrix.
The first line contains integer 4n (1 ≤ 4n ≤ 2·106). The next line contains 4n integers ai (1 ≤ ai ≤ 109) — the numbers you need to arrange in the 2n × 2n-sized matrix.
On a single line print the maximum value of the beauty of the described matrix. 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
Consider the second sample. You need to arrange the numbers in the matrix as follows: Then the beauty of the matrix will equal: 4 + 1 + 2 + 3 + 4 = 14.
[{"input": "1\n13", "output": "13"}, {"input": "4\n1 2 3 4", "output": "14"}]
1,400
["constructive algorithms", "greedy", "implementation", "sortings"]
61
[{"input": "1\r\n13\r\n", "output": "13\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "14\r\n"}, {"input": "16\r\n978618343 473608041 799158564 800910753 461479363 520477481 780529176 678879534 118274424 720632652 639921017 582019792 143353286 537373229 944668919 758615621\r\n", "output": "14440495117\r\n"}, {"input": "16\r\n521848329 105907607 414661942 473600423 264555612 186332345 774233687 736918178 456150336 216550357 568433949 135218174 18789799 324141005 617635501 149674864\r\n", "output": "9436107110\r\n"}, {"input": "16\r\n612095723 222321386 616933999 386488979 943748076 902598472 681820298 449949990 359507903 613063462 437031953 902348579 697631196 99280352 60225467 969809069\r\n", "output": "13643168169\r\n"}, {"input": "16\r\n666766712 653140033 670637874 170909587 210382562 358152171 128926299 750686139 315428350 607830667 363710774 325047228 570196776 38425426 438601514 634274054\r\n", "output": "10395033063\r\n"}, {"input": "1\r\n6\r\n", "output": "6\r\n"}, {"input": "1\r\n8\r\n", "output": "8\r\n"}, {"input": "1\r\n9\r\n", "output": "9\r\n"}, {"input": "4\r\n7 9 6 9\r\n", "output": "40\r\n"}, {"input": "4\r\n423654797 623563697 645894116 384381709\r\n", "output": "2723388435\r\n"}, {"input": "4\r\n437587210 297534606 891773002 56712976\r\n", "output": "2575380796\r\n"}, {"input": "4\r\n963662765 272656295 383441522 477665112\r\n", "output": "3061088459\r\n"}, {"input": "4\r\n791725034 812168727 528894922 479977172\r\n", "output": "3424934582\r\n"}]
false
stdio
null
true
53/A
53
A
Python 3
TESTS
15
216
0
52326209
s = input() n = int(input()) t = s lt = 10**10 for a in range(n): x = input() if x.startswith(s): lx = len(x) if lx < lt: lt = lx t = x elif lx == lt: tx = x[len(s):] tt = t[len(s):] for i in range(len(tx)): if ord(tx[i]) < ord(tt[i]): lt = lx t = x break print(t)
25
92
0
153995316
arr,keyWord,n = [],input(),int(input()) for i in range (n): line = input() if line.startswith(keyWord): arr.append(line) arr.sort() print(arr[0] if len(arr) > 0 else keyWord)
Codeforces Beta Round 49 (Div. 2)
CF
2,011
2
256
Autocomplete
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of n last visited by the user pages and the inputted part s are known. Your task is to complete s to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix s.
The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.
If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages.
null
null
[{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}]
1,100
["implementation"]
25
[{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r\nszjebdoad\r\nchz\r\na\r\n", "output": "kudljmxcse\r\n"}, {"input": "ntqwpa\r\n5\r\nvvepyowvn\r\nntqwpakay\r\nhh\r\nygiafasda\r\nntqwpadm\r\n", "output": "ntqwpadm\r\n"}, {"input": "aflb\r\n6\r\nsaej\r\nujxsiijg\r\npp\r\nhgoprw\r\ncp\r\nnt\r\n", "output": "aflb\r\n"}, {"input": "dzwzyj\r\n7\r\nwvixktp\r\ndzwzyjuhn\r\ndzwzyjqrbd\r\ndzwzyji\r\ndzwzyjyfys\r\ndzwzyjrcb\r\nxptb\r\n", "output": "dzwzyji\r\n"}, {"input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n1\r\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn\r\n", "output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n"}, {"input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\r\n1\r\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n", "output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n"}, {"input": "msjnqudojxtzvpc\r\n2\r\nvlxclsvqbucmbrkwwtoxek\r\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n", "output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n"}]
false
stdio
null
true
53/A
53
A
Python 3
TESTS
10
92
0
172996736
s=input() t=int(input()) z=10100000021490214901902490214091491041290109411204929041209421490129040921490124901490214901490 s2=s for i in range(t): k=input() if k.startswith(s): if len(k)<z: z=len(k) s2=k print(s2) ''' next 2 nextpermutation nextelement '''
25
92
0
158134329
import sys input = sys.stdin.readline s = input()[:-1] a = len(s) c = s + '~' for _ in range(int(input())): x = input()[:-1] if x[:a] == s and x < c: c = x print(c if c != s+'~' else s)
Codeforces Beta Round 49 (Div. 2)
CF
2,011
2
256
Autocomplete
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of n last visited by the user pages and the inputted part s are known. Your task is to complete s to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix s.
The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.
If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages.
null
null
[{"input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement"}, {"input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find"}, {"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find"}]
1,100
["implementation"]
25
[{"input": "next\r\n2\r\nnextpermutation\r\nnextelement\r\n", "output": "nextelement\r\n"}, {"input": "find\r\n4\r\nfind\r\nfindfirstof\r\nfindit\r\nfand\r\n", "output": "find\r\n"}, {"input": "find\r\n4\r\nfondfind\r\nfondfirstof\r\nfondit\r\nfand\r\n", "output": "find\r\n"}, {"input": "kudljmxcse\r\n4\r\nkudljmxcse\r\nszjebdoad\r\nchz\r\na\r\n", "output": "kudljmxcse\r\n"}, {"input": "ntqwpa\r\n5\r\nvvepyowvn\r\nntqwpakay\r\nhh\r\nygiafasda\r\nntqwpadm\r\n", "output": "ntqwpadm\r\n"}, {"input": "aflb\r\n6\r\nsaej\r\nujxsiijg\r\npp\r\nhgoprw\r\ncp\r\nnt\r\n", "output": "aflb\r\n"}, {"input": "dzwzyj\r\n7\r\nwvixktp\r\ndzwzyjuhn\r\ndzwzyjqrbd\r\ndzwzyji\r\ndzwzyjyfys\r\ndzwzyjrcb\r\nxptb\r\n", "output": "dzwzyji\r\n"}, {"input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n1\r\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn\r\n", "output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\r\n"}, {"input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\r\n1\r\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n", "output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb\r\n"}, {"input": "msjnqudojxtzvpc\r\n2\r\nvlxclsvqbucmbrkwwtoxek\r\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n", "output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\r\n"}]
false
stdio
null
true
659/D
659
D
PyPy 3
TESTS
5
108
20,172,800
123129141
n = int(input()) vertical = [] horizontal = [] l = [] ans = 0 for i in range(n+1): l.append([int(j) for j in input().split()]) unique = {} unique_id = 1 for i in range(1,n+1): if l[i][0] == l[i-1][0]: vertical.append([min(l[i][1],l[i-1][1]),max(l[i][1],l[i-1][1]),l[i][0]]) unique[unique_id] = [min(l[i][1],l[i-1][1]),max(l[i][1],l[i-1][1]),l[i][0],'v'] else: horizontal.append([min(l[i][0],l[i-1][0]),max(l[i][0],l[i-1][0]),l[i][1]]) unique[unique_id] = [min(l[i][0],l[i-1][0]),max(l[i][0],l[i-1][0]),l[i][1],'h'] unique_id += 1 for i in range(1,n+1): if l[i][0] == l[i-1][0]: if l[i][1] > l[i-1][1]: direction = 'up' else: direction = 'down' count = 0 if direction == 'up': for j in horizontal: if l[i][0] > j[0] and l[i][0] < j[1] and l[i][1] < j[2]: count += 1 for k in unique: if unique[k][2] == l[i][0] and unique[k][3] == 'v' and unique[k][0] > l[i][1] : if unique.get(k-1,[-1,-1,-1])[1] == l[i][0] and unique.get(k+1,[-1,-1,-1])[0] == l[i][0]: count += 1 elif unique.get(k-1,[-1,-1,-1])[0] == l[i][0] and unique.get(k+1,[-1,-1,-1])[1] == l[i][0]: count += 1 if count%2 == 1: ans += 1 else: for j in horizontal: if l[i][0] > j[0] and l[i][0] < j[1] and l[i][1] > j[2]: count += 1 for k in unique: if unique[k][2] == l[i][0] and unique[k][3] == 'v' and unique[k][1] < l[i][1] : if unique.get(k-1,[-1,-1,-1])[1] == l[i][0] and unique.get(k+1,[-1,-1,-1])[0] == l[i][0]: count += 1 elif unique.get(k-1,[-1,-1,-1])[0] == l[i][0] and unique.get(k+1,[-1,-1,-1])[1] == l[i][0]: count += 1 if count%2 == 1: ans += 1 else: if l[i][0] > l[i-1][0]: direction = 'right' else: direction = 'left' count = 0 if direction == 'right': for j in vertical: if l[i][1] > j[0] and l[i][1] < j[1] and l[i][0] < j[2]: count += 1 for k in unique: if unique[k][2] == l[i][1] and unique[k][3] == 'h' and unique[k][0] > l[i][0] : if unique.get(k-1,[-1,-1,-1])[1] == l[i][1] and unique.get(k+1,[-1,-1,-1])[0] == l[i][1]: count += 1 elif unique.get(k-1,[-1,-1,-1])[0] == l[i][1] and unique.get(k+1,[-1,-1,-1])[1] == l[i][1]: count += 1 if count%2 == 1: ans += 1 else: for j in vertical: if l[i][1] > j[0] and l[i][1] < j[1] and l[i][0] > j[2]: count += 1 for k in unique: if unique[k][2] == l[i][1] and unique[k][3] == 'h' and unique[k][1] < l[i][0] : if unique.get(k-1,[-1,-1,-1])[1] == l[i][1] and unique.get(k+1,[-1,-1,-1])[0] == l[i][1]: count += 1 elif unique.get(k-1,[-1,-1,-1])[0] == l[i][1] and unique.get(k+1,[-1,-1,-1])[1] == l[i][1]: count += 1 if count%2 == 1: ans += 1 print(ans)
22
46
0
145393059
n = int(input()) trajeto = [] curvas = 0 for i in range(n): x, y = input().split() trajeto.append((int(x), int(y))) for i in range(len(trajeto)-2): if trajeto[i][1]<trajeto[i+1][1] and trajeto[i+1][0]>trajeto[i+2][0]: curvas += 1 elif trajeto[i][0]<trajeto[i+1][0] and trajeto[i+1][1]<trajeto[i+2][1]: curvas += 1 elif trajeto[i][1]>trajeto[i+1][1] and trajeto[i+1][0]<trajeto[i+2][0]: curvas += 1 elif trajeto[i][0]>trajeto[i+1][0] and trajeto[i+1][1]>trajeto[i+2][1]: curvas += 1 print(curvas)
Codeforces Round 346 (Div. 2)
CF
2,016
1
256
Bicycle Race
Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west. Let's introduce a system of coordinates, directing the Ox axis from west to east, and the Oy axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa). Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored. Help Maria get ready for the competition — determine the number of dangerous turns on the track.
The first line of the input contains an integer n (4 ≤ n ≤ 1000) — the number of straight sections of the track. The following (n + 1)-th line contains pairs of integers (xi, yi) ( - 10 000 ≤ xi, yi ≤ 10 000). The first of these points is the starting position. The i-th straight section of the track begins at the point (xi, yi) and ends at the point (xi + 1, yi + 1). It is guaranteed that: - the first straight section is directed to the north; - the southernmost (and if there are several, then the most western of among them) point of the track is the first point; - the last point coincides with the first one (i.e., the start position); - any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point); - no pair of points (except for the first and last one) is the same; - no two adjacent straight sections are directed in the same direction or in opposite directions.
Print a single integer — the number of dangerous turns on the track.
null
The first sample corresponds to the picture: The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1.
[{"input": "6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0", "output": "1"}, {"input": "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1", "output": "6"}]
1,500
["geometry", "implementation", "math"]
22
[{"input": "6\r\n0 0\r\n0 1\r\n1 1\r\n1 2\r\n2 2\r\n2 0\r\n0 0\r\n", "output": "1\r\n"}, {"input": "16\r\n1 1\r\n1 5\r\n3 5\r\n3 7\r\n2 7\r\n2 9\r\n6 9\r\n6 7\r\n5 7\r\n5 3\r\n4 3\r\n4 4\r\n3 4\r\n3 2\r\n5 2\r\n5 1\r\n1 1\r\n", "output": "6\r\n"}, {"input": "4\r\n-10000 -10000\r\n-10000 10000\r\n10000 10000\r\n10000 -10000\r\n-10000 -10000\r\n", "output": "0\r\n"}, {"input": "4\r\n6 8\r\n6 9\r\n7 9\r\n7 8\r\n6 8\r\n", "output": "0\r\n"}, {"input": "8\r\n-10000 -10000\r\n-10000 5000\r\n0 5000\r\n0 10000\r\n10000 10000\r\n10000 0\r\n0 0\r\n0 -10000\r\n-10000 -10000\r\n", "output": "2\r\n"}, {"input": "20\r\n-4286 -10000\r\n-4286 -7778\r\n-7143 -7778\r\n-7143 -3334\r\n-10000 -3334\r\n-10000 1110\r\n-4286 1110\r\n-4286 -3334\r\n4285 -3334\r\n4285 -1112\r\n7142 -1112\r\n7142 3332\r\n4285 3332\r\n4285 9998\r\n9999 9998\r\n9999 -3334\r\n7142 -3334\r\n7142 -5556\r\n-1429 -5556\r\n-1429 -10000\r\n-4286 -10000\r\n", "output": "8\r\n"}, {"input": "24\r\n-10000 -10000\r\n-10000 9998\r\n9998 9998\r\n9998 -10000\r\n-6364 -10000\r\n-6364 6362\r\n6362 6362\r\n6362 -6364\r\n-2728 -6364\r\n-2728 2726\r\n2726 2726\r\n2726 -910\r\n908 -910\r\n908 908\r\n-910 908\r\n-910 -4546\r\n4544 -4546\r\n4544 4544\r\n-4546 4544\r\n-4546 -8182\r\n8180 -8182\r\n8180 8180\r\n-8182 8180\r\n-8182 -10000\r\n-10000 -10000\r\n", "output": "10\r\n"}, {"input": "12\r\n-10000 -10000\r\n-10000 10000\r\n10000 10000\r\n10000 6000\r\n-6000 6000\r\n-6000 2000\r\n10000 2000\r\n10000 -2000\r\n-6000 -2000\r\n-6000 -6000\r\n10000 -6000\r\n10000 -10000\r\n-10000 -10000\r\n", "output": "4\r\n"}, {"input": "12\r\n-10000 -10000\r\n-10000 10000\r\n10000 10000\r\n10000 6000\r\n-9800 6000\r\n-9800 2000\r\n10000 2000\r\n10000 -2000\r\n-9800 -2000\r\n-9800 -6000\r\n10000 -6000\r\n10000 -10000\r\n-10000 -10000\r\n", "output": "4\r\n"}, {"input": "4\r\n0 0\r\n0 10000\r\n10000 10000\r\n10000 0\r\n0 0\r\n", "output": "0\r\n"}, {"input": "4\r\n-10000 -10000\r\n-10000 10000\r\n10000 10000\r\n10000 -10000\r\n-10000 -10000\r\n", "output": "0\r\n"}]
false
stdio
null
true
239/B
239
B
Python 3
TESTS
3
186
307,200
54567099
n,Q = map(int,input().strip().split()) s = input() d = 1 for q in range(Q): arr = [0]*(10) l,r = map(int,input().strip().split()) su = "" for i in range(l-1,r): su+=s[i] su = list(su) i = 0 d = 1 #print(su) while i<len(su) and i>=0: if su[i].isdigit(): arr[int(su[i])]+=1 if su[i]=='0': su = su[:i]+su[i+1:] else: su[i] = str(int(su[i])-1) if d==1: i+=1; else: i-=1; else: if su[i]=='>' or su[i]=='<': if d==1 and i!=0: if su[i-1]=='>' or su[i-1]=='<' or su[i-1]=='-1': su = su[:i-1]+su[i:] i-=1 if d==0 and i!=n-1: if su[i+1]=='>' or su[i+1]=='<' or su[i+1]=='-1': su = su[:i+1]+su[i+2:] if su[i]=='>': d = 1 else: d = 0 if d==0: i-=1; else: i+=1 #print(su,i) #print(arr) #print(su) print(*arr)
33
92
0
154842265
n, q = map(int, input().split()) S = list('x'+input()+'x') for _ in range(q): l, r = map(int, input().split()) s = S[l-1:r+2] s[0] = s[-1] = 'x' c = [0]*10 dp, p = 1, 1 while s[p]!='x': if s[p]=='>': dp = 1 if s[p+1] in "><": s.pop(p) else: p += 1 elif s[p]=='<': dp = -1 p -= 1 if s[p] in "><": s.pop(p+1) else: d = ord(s[p])-ord('0') c[d] += 1 if d==0: s.pop(p) else: s[p] = chr(d-1+ord('0')) p += dp if d==0 and dp==1: p -= 1 print(' '.join(map(str, c)))
Codeforces Round 148 (Div. 2)
CF
2,012
2
256
Easy Tape Programming
There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts. - Current character pointer (CP); - Direction pointer (DP) which can point left or right; Initially CP points to the leftmost character of the sequence and DP points to the right. We repeat the following steps until the first moment that CP points to somewhere outside the sequence. - If CP is pointing to a digit the interpreter prints that digit then CP moves one step according to the direction of DP. After that the value of the printed digit in the sequence decreases by one. If the printed digit was 0 then it cannot be decreased therefore it's erased from the sequence and the length of the sequence decreases by one. - If CP is pointing to "<" or ">" then the direction of DP changes to "left" or "right" correspondingly. Then CP moves one step according to DP. If the new character that CP is pointing to is "<" or ">" then the previous character will be erased from the sequence. If at any moment the CP goes outside of the sequence the execution is terminated. It's obvious the every program in this language terminates after some steps. We have a sequence s1, s2, ..., sn of "<", ">" and digits. You should answer q queries. Each query gives you l and r and asks how many of each digit will be printed if we run the sequence sl, sl + 1, ..., sr as an independent program in this language.
The first line of input contains two integers n and q (1 ≤ n, q ≤ 100) — represents the length of the sequence s and the number of queries. The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces. The next q lines each contains two integers li and ri (1 ≤ li ≤ ri ≤ n) — the i-th query.
For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input.
null
null
[{"input": "7 4\n1>3>22<\n1 3\n4 7\n7 7\n1 7", "output": "0 1 0 1 0 0 0 0 0 0\n2 2 2 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n2 3 2 1 0 0 0 0 0 0"}]
1,500
["brute force", "implementation"]
33
[{"input": "7 4\r\n1>3>22<\r\n1 3\r\n4 7\r\n7 7\r\n1 7\r\n", "output": "0 1 0 1 0 0 0 0 0 0 \r\n2 2 2 0 0 0 0 0 0 0 \r\n0 0 0 0 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 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n"}, {"input": "1 1\r\n0\r\n1 1\r\n", "output": "1 0 0 0 0 0 0 0 0 0 \r\n"}, {"input": "3 10\r\n<<<\r\n2 3\r\n3 3\r\n2 3\r\n3 3\r\n1 3\r\n1 1\r\n1 2\r\n3 3\r\n1 1\r\n2 2\r\n", "output": "0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n"}, {"input": "5 1\r\n1>3><\r\n4 5\r\n", "output": "0 0 0 0 0 0 0 0 0 0 \r\n"}, {"input": "4 1\r\n217<\r\n1 4\r\n", "output": "1 2 1 0 0 0 1 1 0 0 \r\n"}, {"input": "4 1\r\n34><\r\n1 4\r\n", "output": "0 0 1 2 1 0 0 0 0 0 \r\n"}]
false
stdio
null
true
878/E
878
E
Python 3
TESTS
8
61
0
32121679
def find_max_ind(arr): max_el, max_ind = arr[0], 0 for i in range(1, len(arr)): el = arr[i] if el >= max_el: max_el = el max_ind = i return max_ind def calc_max_prod(arr, l): if l == 1: return arr[0] if l == 2: a = arr[0] + arr[1] * 2 return a max_ind = find_max_ind(arr) if max_ind == 0: a = calc_max_prod([calc_max_prod(arr[:2], 2)] + arr[2:], l - 1) return a before = arr[:max_ind - 1] calc = arr[max_ind - 1:max_ind + 1] after = arr[max_ind + 1:] a = calc_max_prod(before + [calc_max_prod(calc, 2)] + after, l - 1) return a ''' def calc_max_prod(arr, l): if l == 1: return arr[0] if l == 2: return arr[0] + arr[1] * 2 max_prod = -float("inf") for i in range(l - 1): prod = calc_max_prod(arr[:i] + [calc_max_prod(arr[i:i + 2], 2)] + arr[i + 2:], l - 1) max_prod = max(prod, max_prod) return max_prod''' n, q = list(map(int, input().split())) nums = list(map(int, input().split())) rem = [list(map(int, input().split())) for i in range(q)] for i in range(q): li, ri = rem[i] print(calc_max_prod(nums[li - 1:ri], ri - li + 1) % (10 ** 9 + 7))
55
999
80,281,600
303302080
import sys MOD = 10**9 + 7 INF = 2 * 10**9 + 5 def upd(a): a += (a >> 31) & MOD return a def init(n): _2 = [1] * (n + 1) for i in range(1, n + 1): _2[i] = (_2[i-1] << 1) % MOD return _2 def find(x, fa): if fa[x] != x: fa[x] = find(fa[x], fa) return fa[x] def merge(x, y, fa, L, s, f, _2): fa[y] = x if (L[x] > 30 and s[x] > 0) or (s[x] + (s[y] << L[x]) >= INF): s[x] = INF else: s[x] += s[y] << L[x] f[x] = (f[x] + f[y] * _2[L[x]]) % MOD L[x] += L[y] def calc(l, r, pr, _2): return (pr[l] - pr[r+1] * _2[r-l+1] % MOD + MOD) % MOD def main(): input = sys.stdin.read data = input().split() idx = 0 n = int(data[idx]) m = int(data[idx+1]) idx += 2 a = [0] * (n + 1) for i in range(1, n+1): a[i] = int(data[idx]) idx += 1 _2 = init(n) pr = [0] * (n + 2) for i in range(n, 0, -1): pr[i] = ((pr[i+1] << 1) + a[i] + MOD) % MOD fa = [i for i in range(n+1)] L = [1] * (n+1) f = [0] * (n+1) s = [0] * (n+1) for i in range(1, n+1): f[i] = s[i] = a[i] vec = [[] for _ in range(n+1)] for i in range(1, m+1): l = int(data[idx]) r = int(data[idx+1]) idx += 2 vec[r].append((l, i)) ans = [0] * (m+1) ps = [0] * (n+1) for i in range(1, n+1): while find(i, fa) > 1 and s[find(i, fa)] >= 0: merge(find(find(i, fa)-1, fa), find(i, fa), fa, L, s, f, _2) ps[find(i, fa)] = (ps[find(find(i, fa)-1, fa)] + f[find(i, fa)]) % MOD for q in vec[i]: l, id = q ans[id] = ((ps[find(i, fa)] - ps[find(l, fa)] + MOD) * 2 + calc(l, find(l, fa) + L[find(l, fa)] - 1, pr, _2) + MOD) % MOD for i in range(1, m+1): print(ans[i]) if __name__ == "__main__": main()
Codeforces Round 443 (Div. 1)
CF
2,017
2
512
Numbers on the blackboard
A sequence of n integers is written on a blackboard. Soon Sasha will come to the blackboard and start the following actions: let x and y be two adjacent numbers (x before y), then he can remove them and write x + 2y instead of them. He will perform these operations until one number is left. Sasha likes big numbers and will get the biggest possible number. Nikita wants to get to the blackboard before Sasha and erase some of the numbers. He has q options, in the option i he erases all numbers to the left of the li-th number and all numbers to the right of ri-th number, i. e. all numbers between the li-th and the ri-th, inclusive, remain on the blackboard. For each of the options he wants to know how big Sasha's final number is going to be. This number can be very big, so output it modulo 109 + 7.
The first line contains two integers n and q (1 ≤ n, q ≤ 105) — the number of integers on the blackboard and the number of Nikita's options. The next line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the sequence on the blackboard. Each of the next q lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n), describing Nikita's options.
For each option output Sasha's result modulo 109 + 7.
null
In the second sample Nikita doesn't erase anything. Sasha first erases the numbers 1 and 2 and writes 5. Then he erases 5 and -3 and gets -1. -1 modulo 109 + 7 is 109 + 6.
[{"input": "3 3\n1 2 3\n1 3\n1 2\n2 3", "output": "17\n5\n8"}, {"input": "3 1\n1 2 -3\n1 3", "output": "1000000006"}, {"input": "4 2\n1 1 1 -1\n1 4\n3 4", "output": "5\n1000000006"}]
3,300
["combinatorics", "dp"]
55
[{"input": "3 3\r\n1 2 3\r\n1 3\r\n1 2\r\n2 3\r\n", "output": "17\r\n5\r\n8\r\n"}, {"input": "3 1\r\n1 2 -3\r\n1 3\r\n", "output": "1000000006\r\n"}, {"input": "4 2\r\n1 1 1 -1\r\n1 4\r\n3 4\r\n", "output": "5\r\n1000000006\r\n"}, {"input": "4 1\r\n1 1 -3 1\r\n1 4\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1000000000\r\n1 1\r\n", "output": "1000000000\r\n"}, {"input": "1 1\r\n-1000000000\r\n1 1\r\n", "output": "7\r\n"}, {"input": "2 3\r\n0 0\r\n1 2\r\n1 1\r\n2 2\r\n", "output": "0\r\n0\r\n0\r\n"}, {"input": "2 3\r\n1000000000 1000000000\r\n1 2\r\n1 1\r\n2 2\r\n", "output": "999999986\r\n1000000000\r\n1000000000\r\n"}, {"input": "10 10\r\n-7 4 4 -5 2 3 -9 7 -4 -2\r\n8 10\r\n8 9\r\n2 3\r\n2 9\r\n2 3\r\n7 8\r\n1 3\r\n2 6\r\n6 8\r\n3 3\r\n", "output": "1000000002\r\n1000000006\r\n12\r\n208\r\n12\r\n5\r\n17\r\n56\r\n13\r\n4\r\n"}, {"input": "10 10\r\n593536087 56559483 -439122178 -126803734 606390399 -809361217 444436245 71742850 -477364598 -818526589\r\n5 9\r\n5 7\r\n5 5\r\n1 9\r\n5 10\r\n2 2\r\n3 10\r\n4 5\r\n2 4\r\n4 4\r\n", "output": "384626549\r\n765412945\r\n606390399\r\n410699067\r\n747573385\r\n56559483\r\n72910946\r\n85977057\r\n924707673\r\n873196273\r\n"}, {"input": "10 10\r\n-616555628 133372392 -749502876 499498544 927177575 -838173566 -139786799 -676011158 155638259 102225904\r\n1 3\r\n3 3\r\n1 2\r\n2 10\r\n5 7\r\n4 5\r\n6 6\r\n8 9\r\n3 5\r\n7 7\r\n", "output": "151183418\r\n250497131\r\n650189163\r\n270536548\r\n971256859\r\n353853680\r\n161826441\r\n635265367\r\n958204491\r\n860213208\r\n"}, {"input": "10 1\r\n-11 81 -4 79 44 -11 -50 26 -38 13\r\n4 10\r\n", "output": "129\r\n"}, {"input": "10 1\r\n-858350203 62991893 757167826 -643742467 -122005341 210910071 973749788 -554405426 91646398 811009699\r\n1 6\r\n", "output": "208079143\r\n"}, {"input": "101 1\r\n-2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 -2 -1 -1 -1 1 1000000000\r\n1 101\r\n", "output": "165401054\r\n"}, {"input": "108 1\r\n-1 -1 -1 -2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1000000000\r\n1 108\r\n", "output": "171334758\r\n"}]
false
stdio
null
true
384/B
384
B
Python 3
TESTS
0
15
0
196246988
n,m,k = list(map(int,input().split())) ans = [] vis = set() for _ in range(n): lst = list(map(int,input().split())) for i in range(m): for j in range(i+1,m): if k==0 and lst[i] > lst[j] and (i,j) not in vis: ans.append((i,j)) vis.add((i,j)) lst[i],lst[j] = lst[j],lst[i] # if _ ==1: # print(lst[i],lst[j]) elif k == 1 and lst[j] > lst[i] and (j,i) not in vis: ans.append((j,i)) lst[i],lst[j] = lst[j],lst[i] vis.add((j,i)) print(len(ans)) for x,y in ans: print(x+1,y+1)
31
46
0
181167279
n,m,k = map(int, input().split()) print(m*(m-1)//2) for i in range(m): for j in range(i+1, m): if k: print (j+1, i+1) else: print (i+1, j+1)
Codeforces Round 225 (Div. 2)
CF
2,014
1
256
Multitasking
Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers. Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position i is strictly greater than the value at position j. Iahub wants to find an array of pairs of distinct indices that, chosen in order, sort all of the n arrays in ascending or descending order (the particular order is given in input). The size of the array can be at most $$\frac{m(m-1)}{2}$$ (at most $$\frac{m(m-1)}{2}$$ pairs). Help Iahub, find any suitable array.
The first line contains three integers n (1 ≤ n ≤ 1000), m (1 ≤ m ≤ 100) and k. Integer k is 0 if the arrays must be sorted in ascending order, and 1 if the arrays must be sorted in descending order. Each line i of the next n lines contains m integers separated by a space, representing the i-th array. For each element x of the array i, 1 ≤ x ≤ 106 holds.
On the first line of the output print an integer p, the size of the array (p can be at most $$\frac{m(m-1)}{2}$$). Each of the next p lines must contain two distinct integers i and j (1 ≤ i, j ≤ m, i ≠ j), representing the chosen indices. If there are multiple correct answers, you can print any.
null
Consider the first sample. After the first operation, the arrays become [1, 3, 2, 5, 4] and [1, 2, 3, 4, 5]. After the second operation, the arrays become [1, 2, 3, 5, 4] and [1, 2, 3, 4, 5]. After the third operation they become [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5].
[{"input": "2 5 0\n1 3 2 5 4\n1 4 3 2 5", "output": "3\n2 4\n2 3\n4 5"}, {"input": "3 2 1\n1 2\n2 3\n3 4", "output": "1\n2 1"}]
1,500
["greedy", "implementation", "sortings", "two pointers"]
31
[{"input": "2 5 0\r\n1 3 2 5 4\r\n1 4 3 2 5\r\n", "output": "3\r\n2 4\r\n2 3\r\n4 5\r\n"}, {"input": "3 2 1\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "1\r\n2 1\r\n"}, {"input": "2 5 0\r\n836096 600367 472071 200387 79763\r\n714679 505282 233544 157810 152591\r\n", "output": "10\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n2 3\r\n2 4\r\n2 5\r\n3 4\r\n3 5\r\n4 5\r\n"}, {"input": "2 5 1\r\n331081 525217 574775 753333 840639\r\n225591 347017 538639 620341 994088\r\n", "output": "10\r\n2 1\r\n3 1\r\n4 1\r\n5 1\r\n3 2\r\n4 2\r\n5 2\r\n4 3\r\n5 3\r\n5 4\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 0\r\n1\r\n2\r\n", "output": "0\r\n"}, {"input": "1 2 1\r\n2 1\r\n", "output": "1\r\n2 1\r\n"}, {"input": "2 2 0\r\n2 1\r\n3 1\r\n", "output": "1\r\n1 2\r\n"}, {"input": "2 2 0\r\n2 1\r\n1 3\r\n", "output": "1\r\n1 2\r\n"}, {"input": "2 2 1\r\n2 1\r\n3 1\r\n", "output": "1\r\n2 1\r\n"}]
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: lines = f.read().splitlines() n, m, k = map(int, lines[0].split()) arrays = [list(map(int, line.split())) for line in lines[1:n+1]] try: with open(submission_path) as f: sub_lines = f.read().splitlines() except: print(0) return if not sub_lines: print(0) return try: p = int(sub_lines[0].strip()) if p < 0 or p > m * (m-1) // 2: print(0) return except: print(0) return swaps = [] for line in sub_lines[1:p+1]: parts = line.strip().split() if len(parts) != 2: print(0) return try: i = int(parts[0]) j = int(parts[1]) except: print(0) return if i < 1 or i > m or j < 1 or j > m or i == j: print(0) return swaps.append( (i-1, j-1) ) for arr in arrays: current = arr.copy() for i, j in swaps: if current[i] > current[j]: current[i], current[j] = current[j], current[i] valid = True if k == 0: for x in range(m-1): if current[x] > current[x+1]: valid = False break else: for x in range(m-1): if current[x] < current[x+1]: valid = False break if not valid: print(0) return print(1) if __name__ == "__main__": main()
true
383/D
383
D
Python 3
TESTS
2
46
307,200
5764170
__author__ = 'Pavel Mavrin' n = int(input()) a = [int(x) for x in input().split()] d = [1] res = 0 for i in range(n): dd = [0] * (len(d) + a[i]) dd[0] += 1 for j in range(len(d)): kk = j + a[i] dd[kk] += d[j] kk = abs(j - a[i]) dd[kk] += d[j] d = dd res += d[0] print(res - n)
48
249
4,915,200
178764601
n = int(input()) a = list(map(int, input().split())) maxn, mod, ans = 12000, 10 ** 9 + 7, 0 dp = [[0] * 2 for _ in range(2 * maxn + 10)] curr, pre = 1, 0 for x in a: for i in range(2000, 2 * maxn - 2000 + 1): dp[i][curr] = (dp[i - x][pre] + dp[i + x][pre]) % mod dp[maxn - x][curr] = (dp[maxn - x][curr] + 1) % mod dp[maxn + x][curr] = (dp[maxn + x][curr] + 1) % mod ans = (ans + dp[maxn][curr]) % mod curr ^= 1 pre ^= 1 print(ans)
Codeforces Round 225 (Div. 1)
CF
2,014
1
256
Antimatter
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter. Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode for each of them (produce matter or antimatter) and finally take a photo of it. However he will be successful only if the amounts of matter and antimatter produced in the selected subarray will be the same (otherwise there would be overflowing matter or antimatter in the photo). You are requested to compute the number of different ways Iahub can successful take a photo. A photo is different than another if it represents another subarray, or if at least one device of the subarray is set to produce matter in one of the photos and antimatter in the other one.
The first line contains an integer n (1 ≤ n ≤ 1000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The sum a1 + a2 + ... + an will be less than or equal to 10000.
Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109 + 7).
null
The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "i+" means that the i-th element produces matter, and "i-" means that the i-th element produces antimatter.
[{"input": "4\n1 1 1 1", "output": "12"}]
2,300
["dp"]
48
[{"input": "4\r\n1 1 1 1\r\n", "output": "12\r\n"}, {"input": "10\r\n16 9 9 11 10 12 9 6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"}, {"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "2\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "3\r\n999 999 999\r\n", "output": "4\r\n"}]
false
stdio
null
true
383/D
383
D
Python 3
TESTS
2
46
102,400
153285959
from collections import defaultdict import sys readline=sys.stdin.readline mod=10**9+7 N=int(readline()) A=list(map(int,readline().split())) def main(l,r): if l+1==r: return 0 mid=(l+r)//2 ans=main(l,mid)+main(mid,r) S=max(sum(A[l:mid]),sum(A[mid:r])) AA=A[l:mid][::-1] dp=[0]*(2*S+1) dp[S]=1 DP=[0]*(2*S+1) for a in AA: prev=dp dp=[0]*(2*S+1) for i in range(2*S+1): for aa in (a,-a): if 0<=i+aa<2*S+1: dp[i+aa]+=prev[i] dp[i+aa]%=mod for i in range(2*S+1): DP[i]+=dp[i] DP[i]%=mod DPL=DP AA=A[mid:r] dp=[0]*(2*S+1) dp[S]=1 DP=[0]*(2*S+1) for a in AA: prev=dp dp=[0]*(2*S+1) for i in range(2*S+1): for aa in (a,-a): if 0<=i+aa<2*S+1: dp[i+aa]+=prev[i] dp[i+aa]%=mod for i in range(2*S+1): DP[i]+=dp[i] DP[i]%=mod DPR=DP[::-1] for cL,cR in zip(DPL,DPR): ans+=cL*cR return ans ans=main(0,N) print(ans)
48
249
10,444,800
217982702
n = int(input()) nums = list(map(int, input().split())) mod = 10 ** 9 + 7 dp = [0] * 20001 ans = 0 for num in nums: new_dp = [0] * 20001 for i in range(20001): if dp[i]: new_dp[i+num] += dp[i] new_dp[i+num] %= mod new_dp[i-num] += dp[i] new_dp[i-num] %= mod dp = new_dp dp[num+10000] += 1 dp[-num+10000] += 1 ans += dp[10000] print(ans % mod)
Codeforces Round 225 (Div. 1)
CF
2,014
1
256
Antimatter
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter. Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode for each of them (produce matter or antimatter) and finally take a photo of it. However he will be successful only if the amounts of matter and antimatter produced in the selected subarray will be the same (otherwise there would be overflowing matter or antimatter in the photo). You are requested to compute the number of different ways Iahub can successful take a photo. A photo is different than another if it represents another subarray, or if at least one device of the subarray is set to produce matter in one of the photos and antimatter in the other one.
The first line contains an integer n (1 ≤ n ≤ 1000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The sum a1 + a2 + ... + an will be less than or equal to 10000.
Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109 + 7).
null
The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "i+" means that the i-th element produces matter, and "i-" means that the i-th element produces antimatter.
[{"input": "4\n1 1 1 1", "output": "12"}]
2,300
["dp"]
48
[{"input": "4\r\n1 1 1 1\r\n", "output": "12\r\n"}, {"input": "10\r\n16 9 9 11 10 12 9 6 10 8\r\n", "output": "86\r\n"}, {"input": "50\r\n2 1 5 2 1 3 1 2 3 2 1 1 5 2 2 2 3 2 1 2 2 2 3 3 1 3 1 1 2 2 2 2 1 2 3 1 2 4 1 1 1 3 2 1 1 1 3 2 1 3\r\n", "output": "115119382\r\n"}, {"input": "100\r\n8 3 3 7 3 6 4 6 9 4 6 5 5 5 4 3 4 2 3 5 3 6 5 3 6 5 6 6 2 6 4 5 5 4 6 4 3 2 8 5 6 6 7 4 4 9 5 6 6 3 7 1 6 2 6 5 9 3 8 6 2 6 3 2 4 4 3 5 4 7 6 5 4 6 3 5 6 8 8 6 3 7 7 1 4 6 8 6 5 3 7 8 4 7 5 3 8 5 4 4\r\n", "output": "450259307\r\n"}, {"input": "250\r\n1 1 1 1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", "output": "377970747\r\n"}, {"input": "250\r\n2 2 2 2 3 2 4 2 3 2 5 1 2 3 4 4 5 3 5 1 2 5 2 3 5 3 2 3 3 3 5 1 5 5 5 4 1 3 2 5 1 2 3 5 3 3 5 2 1 1 3 3 5 1 4 2 3 3 2 2 3 5 5 4 1 4 1 5 1 3 3 4 1 5 2 5 5 3 2 4 4 4 4 3 5 1 3 4 3 4 2 1 4 3 5 1 2 3 4 2 5 5 3 2 5 3 5 4 2 3 2 3 1 1 2 4 2 5 2 3 3 2 4 5 4 2 2 5 5 5 5 4 3 4 5 2 2 3 3 4 5 1 5 5 2 5 1 5 5 4 4 1 4 2 1 2 1 2 2 3 1 4 5 4 2 4 5 1 1 3 2 1 4 1 5 2 3 1 2 3 2 3 3 2 4 2 5 5 2 3 4 2 2 4 2 4 1 5 5 3 1 3 4 5 2 5 5 1 3 1 3 3 2 5 3 5 2 4 3 5 5 3 3 2 3 2 5 3 4 3 5 3 3 4 5 3 1 2 2 5 4 4 5 1 4 1 2 5 2 3\r\n", "output": "257270797\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "2\r\n"}, {"input": "2\r\n1000 1000\r\n", "output": "2\r\n"}, {"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "2\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "3\r\n999 999 999\r\n", "output": "4\r\n"}]
false
stdio
null
true
384/B
384
B
Python 3
TESTS
3
62
0
6912443
n, m, k = map(int, input().split()) arrays = [] for i in range(n): arrays.append(list(map(int, input().split()))) print(m * (m - 1) // 2) if k == 0: for i in range(1, m): for j in range(1, m - i + 1): print(j, j + 1) else: for i in range(1, m): for j in range(m - i + 1, 1, -1): print(j, j - 1)
31
46
0
187148211
n, m, k = map(int, input().split()) if m == 1: print(0) else: q = (m - 1) * m // 2 print(q) if k == 0: for i in range(1, m+1): for j in range(i+1, m+1): print(i, j) else: for i in range(1, m+1): for j in range(i+1, m+1): print(j, i)
Codeforces Round 225 (Div. 2)
CF
2,014
1
256
Multitasking
Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers. Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position i is strictly greater than the value at position j. Iahub wants to find an array of pairs of distinct indices that, chosen in order, sort all of the n arrays in ascending or descending order (the particular order is given in input). The size of the array can be at most $$\frac{m(m-1)}{2}$$ (at most $$\frac{m(m-1)}{2}$$ pairs). Help Iahub, find any suitable array.
The first line contains three integers n (1 ≤ n ≤ 1000), m (1 ≤ m ≤ 100) and k. Integer k is 0 if the arrays must be sorted in ascending order, and 1 if the arrays must be sorted in descending order. Each line i of the next n lines contains m integers separated by a space, representing the i-th array. For each element x of the array i, 1 ≤ x ≤ 106 holds.
On the first line of the output print an integer p, the size of the array (p can be at most $$\frac{m(m-1)}{2}$$). Each of the next p lines must contain two distinct integers i and j (1 ≤ i, j ≤ m, i ≠ j), representing the chosen indices. If there are multiple correct answers, you can print any.
null
Consider the first sample. After the first operation, the arrays become [1, 3, 2, 5, 4] and [1, 2, 3, 4, 5]. After the second operation, the arrays become [1, 2, 3, 5, 4] and [1, 2, 3, 4, 5]. After the third operation they become [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5].
[{"input": "2 5 0\n1 3 2 5 4\n1 4 3 2 5", "output": "3\n2 4\n2 3\n4 5"}, {"input": "3 2 1\n1 2\n2 3\n3 4", "output": "1\n2 1"}]
1,500
["greedy", "implementation", "sortings", "two pointers"]
31
[{"input": "2 5 0\r\n1 3 2 5 4\r\n1 4 3 2 5\r\n", "output": "3\r\n2 4\r\n2 3\r\n4 5\r\n"}, {"input": "3 2 1\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "1\r\n2 1\r\n"}, {"input": "2 5 0\r\n836096 600367 472071 200387 79763\r\n714679 505282 233544 157810 152591\r\n", "output": "10\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n2 3\r\n2 4\r\n2 5\r\n3 4\r\n3 5\r\n4 5\r\n"}, {"input": "2 5 1\r\n331081 525217 574775 753333 840639\r\n225591 347017 538639 620341 994088\r\n", "output": "10\r\n2 1\r\n3 1\r\n4 1\r\n5 1\r\n3 2\r\n4 2\r\n5 2\r\n4 3\r\n5 3\r\n5 4\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 0\r\n1\r\n2\r\n", "output": "0\r\n"}, {"input": "1 2 1\r\n2 1\r\n", "output": "1\r\n2 1\r\n"}, {"input": "2 2 0\r\n2 1\r\n3 1\r\n", "output": "1\r\n1 2\r\n"}, {"input": "2 2 0\r\n2 1\r\n1 3\r\n", "output": "1\r\n1 2\r\n"}, {"input": "2 2 1\r\n2 1\r\n3 1\r\n", "output": "1\r\n2 1\r\n"}]
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: lines = f.read().splitlines() n, m, k = map(int, lines[0].split()) arrays = [list(map(int, line.split())) for line in lines[1:n+1]] try: with open(submission_path) as f: sub_lines = f.read().splitlines() except: print(0) return if not sub_lines: print(0) return try: p = int(sub_lines[0].strip()) if p < 0 or p > m * (m-1) // 2: print(0) return except: print(0) return swaps = [] for line in sub_lines[1:p+1]: parts = line.strip().split() if len(parts) != 2: print(0) return try: i = int(parts[0]) j = int(parts[1]) except: print(0) return if i < 1 or i > m or j < 1 or j > m or i == j: print(0) return swaps.append( (i-1, j-1) ) for arr in arrays: current = arr.copy() for i, j in swaps: if current[i] > current[j]: current[i], current[j] = current[j], current[i] valid = True if k == 0: for x in range(m-1): if current[x] > current[x+1]: valid = False break else: for x in range(m-1): if current[x] < current[x+1]: valid = False break if not valid: print(0) return print(1) if __name__ == "__main__": main()
true
490/B
490
B
Python 3
TESTS
2
46
102,400
165853769
from collections import * n=int(input()) w=[0]*n q=Counter([]) x=Counter([]) for i in range(n): a,b=map(int,input().split()) q[a]=b x[b]=a k=q[0] for i in range(1,n,2): w[i]=k k=q[k] k=x[0] for i in range(n-2,-1,-2): w[i]=k k=x[k] print(*w)
61
343
42,188,800
229878738
from os import path from sys import stdin, stdout filename = "../templates/input.txt" if path.exists(filename): stdin = open(filename, 'r') def input(): return stdin.readline().rstrip() def print(*args, sep=' ', end='\n'): stdout.write(sep.join(map(str, args))) stdout.write(end) def solution(): n = int(input()) ans = [0 for i in range(n)] pair1 = dict() pair2 = dict() for i in range(n): a, b = [int(num) for num in input().split()] pair1[a] = b pair2[b] = a if n % 2 == 0: cur = 0 for i in range(n // 2): cur = pair1[cur] ans[i * 2 + 1] = cur cur = 0 for i in range(n // 2): cur = pair2[cur] ans[n - 1 - i * 2 - 1] = cur else: cur = 0 for i in range(n // 2): cur = pair1[cur] ans[i * 2 + 1] = cur for k in pair1: if k not in pair2: cur = k ans[0] = cur for i in range(1, n // 2 + 1): cur = pair1[cur] ans[i * 2] = cur print(*ans) def main(): t = 1 while t: solution() t -= 1 if __name__ == '__main__': main()
Codeforces Round 279 (Div. 2)
CF
2,014
2
256
Queue
During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working. Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of the student that stands in line directly in front of him, and the student that stands in line directly behind him. If no one stands before or after a student (that is, he is the first one or the last one), then he writes down number 0 instead (in Berland State University student IDs are numerated from 1). After that, all the students went about their business. When they returned, they found out that restoring the queue is not such an easy task. Help the students to restore the state of the queue by the numbers of the student ID's of their neighbors in the queue.
The first line contains integer n (2 ≤ n ≤ 2·105) — the number of students in the queue. Then n lines follow, i-th line contains the pair of integers ai, bi (0 ≤ ai, bi ≤ 106), where ai is the ID number of a person in front of a student and bi is the ID number of a person behind a student. The lines are given in the arbitrary order. Value 0 is given instead of a neighbor's ID number if the neighbor doesn't exist. The ID numbers of all students are distinct. It is guaranteed that the records correspond too the queue where all the students stand in some order.
Print a sequence of n integers x1, x2, ..., xn — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one.
null
The picture illustrates the queue for the first sample.
[{"input": "4\n92 31\n0 7\n31 0\n7 141", "output": "92 7 31 141"}]
1,500
["dsu", "implementation"]
61
[{"input": "4\r\n92 31\r\n0 7\r\n31 0\r\n7 141\r\n", "output": "92 7 31 141 \r\n"}, {"input": "2\r\n0 1\r\n2 0\r\n", "output": "2 1 \r\n"}, {"input": "3\r\n0 2\r\n1 3\r\n2 0\r\n", "output": "1 2 3 \r\n"}, {"input": "4\r\n101 0\r\n0 102\r\n102 100\r\n103 101\r\n", "output": "103 102 101 100 \r\n"}, {"input": "5\r\n0 1\r\n1 4\r\n4 0\r\n3 2\r\n5 3\r\n", "output": "5 1 3 4 2 \r\n"}, {"input": "6\r\n10001 0\r\n0 10005\r\n10003 10001\r\n10002 10000\r\n10005 10002\r\n10004 10003\r\n", "output": "10004 10005 10003 10002 10001 10000 \r\n"}, {"input": "3\r\n0 743259\r\n72866 70294\r\n743259 0\r\n", "output": "72866 743259 70294 \r\n"}, {"input": "4\r\n263750 0\r\n513707 263750\r\n0 718595\r\n718595 148112\r\n", "output": "513707 718595 263750 148112 \r\n"}, {"input": "5\r\n645873 145459\r\n638930 82975\r\n0 645873\r\n82975 389665\r\n145459 0\r\n", "output": "638930 645873 82975 145459 389665 \r\n"}, {"input": "6\r\n341637 51795\r\n0 809471\r\n51795 0\r\n244669 341637\r\n852537 508622\r\n809471 852537\r\n", "output": "244669 809471 341637 852537 51795 508622 \r\n"}, {"input": "7\r\n111283 0\r\n496010 510417\r\n423431 921854\r\n510417 111283\r\n0 496010\r\n758535 423431\r\n921854 59208\r\n", "output": "758535 496010 423431 510417 921854 111283 59208 \r\n"}, {"input": "8\r\n611412 115521\r\n114290 712424\r\n115521 242491\r\n242491 0\r\n0 114290\r\n712424 282922\r\n282922 589147\r\n359823 611412\r\n", "output": "359823 114290 611412 712424 115521 282922 242491 589147 \r\n"}, {"input": "9\r\n308992 348750\r\n0 6496\r\n487447 676506\r\n874677 985199\r\n260782 487447\r\n985199 260782\r\n348750 0\r\n570981 308992\r\n6496 570981\r\n", "output": "874677 6496 985199 570981 260782 308992 487447 348750 676506 \r\n"}, {"input": "10\r\n419946 201769\r\n245945 0\r\n842799 113073\r\n836998 245945\r\n0 794376\r\n692107 836998\r\n113073 904403\r\n904403 987165\r\n201769 692107\r\n794376 842799\r\n", "output": "419946 794376 201769 842799 692107 113073 836998 904403 245945 987165 \r\n"}, {"input": "10\r\n189071 852255\r\n227133 652124\r\n329720 4848\r\n652124 329720\r\n0 72517\r\n943168 0\r\n72517 544697\r\n4848 943168\r\n538963 189071\r\n544697 538963\r\n", "output": "227133 72517 652124 544697 329720 538963 4848 189071 943168 852255 \r\n"}, {"input": "2\r\n0 300000\r\n1000000 0\r\n", "output": "1000000 300000 \r\n"}]
false
stdio
null
true
19/B
19
B
PyPy 3-64
TESTS
13
62
2,048,000
229769422
# First,for every i increase ti by 1..then you will see that statement require sum of t of the items # bigger or equal to n..and their sum of c should be minimal..so it's just a 0-1 knapsack problem. n = int(input()) nums = [] for _ in range(n): time, cost = map(int, input().split()) nums.append([time+1, cost]) # print(nums) dp = [10**10] * (n+2) dp[0] = 0 for i in range(len(nums)): for j in range(n+1,-1,-1): dp[j] = min(dp[j], dp[max(0,j-nums[i][0])]+nums[i][1]) print(dp[-2])
34
140
5,734,400
164988162
n=int(input()) ar=[float('inf')]*(n+1) ar[0]=0 for i in range(n): t,c=map(int,input().split()) for j in range(n-1,-1,-1): w=min(j+t+1,n) ar[w]=min(ar[w],ar[j]+c) print(ar[n])
Codeforces Beta Round 19
ICPC
2,010
1
256
Checkout Assistant
Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. To steal one item Bob needs exactly 1 second. What is the minimum amount of money that Bob will have to pay to the checkout assistant? Remember, please, that it is Bob, who determines the order of items for the checkout assistant.
The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers ti, ci (0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i.
Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.
null
null
[{"input": "4\n2 10\n0 20\n1 5\n1 3", "output": "8"}, {"input": "3\n0 1\n0 10\n0 100", "output": "111"}]
1,900
["dp"]
34
[{"input": "4\r\n2 10\r\n0 20\r\n1 5\r\n1 3\r\n", "output": "8\r\n"}, {"input": "3\r\n0 1\r\n0 10\r\n0 100\r\n", "output": "111\r\n"}, {"input": "2\r\n0 635254032\r\n0 75159864\r\n", "output": "710413896\r\n"}, {"input": "2\r\n0 861438648\r\n1 469893784\r\n", "output": "469893784\r\n"}, {"input": "2\r\n2 87623264\r\n0 864627704\r\n", "output": "87623264\r\n"}, {"input": "5\r\n0 51690939\r\n0 62436494\r\n0 39009053\r\n0 70426298\r\n0 631569476\r\n", "output": "855132260\r\n"}, {"input": "5\r\n0 968804136\r\n0 736567537\r\n2 343136264\r\n0 259899572\r\n1 425744418\r\n", "output": "768880682\r\n"}, {"input": "5\r\n4 33400980\r\n2 410698581\r\n4 794747123\r\n0 301889198\r\n3 219919361\r\n", "output": "33400980\r\n"}, {"input": "5\r\n5 491957578\r\n4 747764103\r\n3 446810728\r\n4 896625835\r\n4 190748656\r\n", "output": "190748656\r\n"}, {"input": "10\r\n3 512981548\r\n0 214269975\r\n2 603901234\r\n3 772872647\r\n0 224281389\r\n4 561877930\r\n1 809519308\r\n4 883486551\r\n1 114469023\r\n2 184038037\r\n", "output": "860384990\r\n"}]
false
stdio
null
true
19/C
19
C
Python 3
TESTS
1
186
0
68205670
n = int(input()) number = [int(x) for x in input().split()] x = list(set(number)) print(len(x)) for i in x: print(i,end=" ")
70
1,216
14,131,200
174568804
import sys n=int(input()) a=list(map(int,input().split())) M=10**9+1 g={} for i in range(n): g[a[i]]=g.get(a[i],[])+[i] p=[1] for i in range(n): p+=[hash(M*p[-1])] h=[0]*(n+1) for i in range(n): h[i+1]=hash(h[i]*M+a[i]) gh=lambda k,l:hash(h[k+l]-h[k]*p[l])%sys.hash_info.modulus i,t=0,0 while i < n: for j in g[a[i]]: if j <= i: continue w=j-i if j+w<=n and gh(i,w)==gh(j,w): i=j-1 t=max(t,j) break i+=1 r=a[t:] print(len(r)) print(*r)
Codeforces Beta Round 19
ICPC
2,010
2
256
Deletion of Repeats
Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a repeat of length x is such a substring of length 2x, that its first half coincides character by character with its second half. Bob started deleting all the repeats from the string. He does it as follows: while it's possible, Bob takes the shortest repeat, if it is not unique, he takes the leftmost one, and deletes its left half and everything that is to the left of this repeat. You're given the string seen by Bob. Find out, what it will look like after Bob deletes all the repeats in the way described above.
The first input line contains integer n (1 ≤ n ≤ 105) — length of the string. The following line contains n space-separated integer numbers from 0 to 109 inclusive — numbers that stand for the letters of the string. It's guaranteed that each letter can be met in the string at most 10 times.
In the first line output the length of the string's part, left after Bob's deletions. In the second line output all the letters (separated by a space) of the string, left after Bob deleted all the repeats in the described way.
null
null
[{"input": "6\n1 2 3 1 2 3", "output": "3\n1 2 3"}, {"input": "7\n4 5 6 5 6 7 7", "output": "1\n7"}]
2,200
["greedy", "hashing", "string suffix structures"]
70
[{"input": "6\r\n1 2 3 1 2 3\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "7\r\n4 5 6 5 6 7 7\r\n", "output": "1\r\n7 \r\n"}, {"input": "10\r\n5 7 2 1 8 8 5 10 2 5\r\n", "output": "5\r\n8 5 10 2 5 \r\n"}, {"input": "10\r\n0 1 1 1 0 3 0 1 4 0\r\n", "output": "7\r\n1 0 3 0 1 4 0 \r\n"}, {"input": "10\r\n0 1 0 2 0 0 1 1 1 0\r\n", "output": "2\r\n1 0 \r\n"}, {"input": "30\r\n17 17 2 4 13 21 17 11 15 0 9 2 23 10 24 21 23 17 5 11 25 1 16 6 11 22 19 2 12 16\r\n", "output": "29\r\n17 2 4 13 21 17 11 15 0 9 2 23 10 24 21 23 17 5 11 25 1 16 6 11 22 19 2 12 16 \r\n"}, {"input": "100\r\n5 4 8 2 4 7 6 6 9 0 5 9 9 8 2 1 10 7 1 0 0 6 3 5 3 7 8 0 0 10 6 7 10 5 4 10 7 6 7 5 1 5 0 10 3 10 5 7 4 10 0 9 1 2 6 3 3 6 10 6 9 1 6 3 4 6 2 8 8 9 5 2 3 3 10 7 4 1 10 1 8 5 4 3 2 2 0 4 4 1 4 5 7 2 8 7 1 1 2 8\r\n", "output": "3\r\n1 2 8 \r\n"}, {"input": "10\r\n1 2 1 2 1 2 1 2 1 2\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "10\r\n1 2 3 4 5 1 2 3 4 5\r\n", "output": "5\r\n1 2 3 4 5 \r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n1 \r\n"}, {"input": "21\r\n16417014 805849548 385039296 16417014 805849548 385039296 16417014 805849548 385039296 16417014 805849548 385039296 16417014 805849548 385039296 16417014 805849548 385039296 16417014 805849548 385039296\r\n", "output": "3\r\n16417014 805849548 385039296 \r\n"}, {"input": "22\r\n823078040 389511796 683819000 823078040 389511796 683819000 823078040 389511796 683819000 823078040 389511796 683819000 823078040 389511796 683819000 823078040 389511796 683819000 823078040 389511796 683819000 823078040\r\n", "output": "4\r\n823078040 389511796 683819000 823078040 \r\n"}, {"input": "23\r\n482255418 973174044 835115058 482255418 973174044 835115058 482255418 973174044 835115058 482255418 973174044 835115058 482255418 973174044 835115058 482255418 973174044 835115058 482255418 973174044 835115058 482255418 973174044\r\n", "output": "5\r\n482255418 973174044 835115058 482255418 973174044 \r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n0 \r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "1\r\n1000000000 \r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "1\r\n1000000000 \r\n"}, {"input": "4\r\n1000000000 1000000000 1000000000 1000000000\r\n", "output": "1\r\n1000000000 \r\n"}, {"input": "7\r\n1 2 3 1 2 3 1\r\n", "output": "4\r\n1 2 3 1 \r\n"}, {"input": "30\r\n0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2\r\n", "output": "1\r\n2 \r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "1\r\n0 \r\n"}, {"input": "20\r\n0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n1 \r\n"}]
false
stdio
null
true
19/B
19
B
Python 3
TESTS
13
77
0
155582766
n = int(input()) gifts, prices = [], [] for i in range(n): line = list(map(int, input().split())) gifts.append(line[0] + 1) prices.append(line[1]) dp = [10 ** 10] * (n + 1) dp[0] = 0 for i in range(n): for j in range(n, -1, -1): dp[j] = min(dp[j], dp[max(0, j - gifts[i])] + prices[i]) print(dp[n])
34
202
6,656,000
227722808
n = int(input()) dp = [float('inf')] * (n+1) dp[0] = 0 for i in range(n): t, c = tuple(int(x) for x in input().split()) for j in range(n)[::-1]: dp[min(n,j+t+1)] = min(dp[min(n,j+t+1)],dp[j]+c) print(dp[n])
Codeforces Beta Round 19
ICPC
2,010
1
256
Checkout Assistant
Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. To steal one item Bob needs exactly 1 second. What is the minimum amount of money that Bob will have to pay to the checkout assistant? Remember, please, that it is Bob, who determines the order of items for the checkout assistant.
The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers ti, ci (0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i.
Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.
null
null
[{"input": "4\n2 10\n0 20\n1 5\n1 3", "output": "8"}, {"input": "3\n0 1\n0 10\n0 100", "output": "111"}]
1,900
["dp"]
34
[{"input": "4\r\n2 10\r\n0 20\r\n1 5\r\n1 3\r\n", "output": "8\r\n"}, {"input": "3\r\n0 1\r\n0 10\r\n0 100\r\n", "output": "111\r\n"}, {"input": "2\r\n0 635254032\r\n0 75159864\r\n", "output": "710413896\r\n"}, {"input": "2\r\n0 861438648\r\n1 469893784\r\n", "output": "469893784\r\n"}, {"input": "2\r\n2 87623264\r\n0 864627704\r\n", "output": "87623264\r\n"}, {"input": "5\r\n0 51690939\r\n0 62436494\r\n0 39009053\r\n0 70426298\r\n0 631569476\r\n", "output": "855132260\r\n"}, {"input": "5\r\n0 968804136\r\n0 736567537\r\n2 343136264\r\n0 259899572\r\n1 425744418\r\n", "output": "768880682\r\n"}, {"input": "5\r\n4 33400980\r\n2 410698581\r\n4 794747123\r\n0 301889198\r\n3 219919361\r\n", "output": "33400980\r\n"}, {"input": "5\r\n5 491957578\r\n4 747764103\r\n3 446810728\r\n4 896625835\r\n4 190748656\r\n", "output": "190748656\r\n"}, {"input": "10\r\n3 512981548\r\n0 214269975\r\n2 603901234\r\n3 772872647\r\n0 224281389\r\n4 561877930\r\n1 809519308\r\n4 883486551\r\n1 114469023\r\n2 184038037\r\n", "output": "860384990\r\n"}]
false
stdio
null
true
19/B
19
B
Python 3
TESTS
13
108
0
196441661
n=int(input()); dp=[10**10]*(n+1); dp[0]=0; for _ in range(n): ti,ci=map(int,input().split()); for j in range(n-1,-1,-1): k=min(j+ti+1,n); dp[k]=min(dp[k],dp[j]+ci); print(dp[n]);
34
296
9,318,400
154633479
from math import inf n = int(input()) F = [inf]*(n+1) F[0] = 0 for i in range(n): t, c = map(int, input().split()) for j in range(n-1, -1, -1): w = min(j+t+1, n) F[w] = min(F[w], F[j]+c) print(F[n]) # F[i][j] = min(F[i][j], F[i][j-t-1])
Codeforces Beta Round 19
ICPC
2,010
1
256
Checkout Assistant
Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. To steal one item Bob needs exactly 1 second. What is the minimum amount of money that Bob will have to pay to the checkout assistant? Remember, please, that it is Bob, who determines the order of items for the checkout assistant.
The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers ti, ci (0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i.
Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.
null
null
[{"input": "4\n2 10\n0 20\n1 5\n1 3", "output": "8"}, {"input": "3\n0 1\n0 10\n0 100", "output": "111"}]
1,900
["dp"]
34
[{"input": "4\r\n2 10\r\n0 20\r\n1 5\r\n1 3\r\n", "output": "8\r\n"}, {"input": "3\r\n0 1\r\n0 10\r\n0 100\r\n", "output": "111\r\n"}, {"input": "2\r\n0 635254032\r\n0 75159864\r\n", "output": "710413896\r\n"}, {"input": "2\r\n0 861438648\r\n1 469893784\r\n", "output": "469893784\r\n"}, {"input": "2\r\n2 87623264\r\n0 864627704\r\n", "output": "87623264\r\n"}, {"input": "5\r\n0 51690939\r\n0 62436494\r\n0 39009053\r\n0 70426298\r\n0 631569476\r\n", "output": "855132260\r\n"}, {"input": "5\r\n0 968804136\r\n0 736567537\r\n2 343136264\r\n0 259899572\r\n1 425744418\r\n", "output": "768880682\r\n"}, {"input": "5\r\n4 33400980\r\n2 410698581\r\n4 794747123\r\n0 301889198\r\n3 219919361\r\n", "output": "33400980\r\n"}, {"input": "5\r\n5 491957578\r\n4 747764103\r\n3 446810728\r\n4 896625835\r\n4 190748656\r\n", "output": "190748656\r\n"}, {"input": "10\r\n3 512981548\r\n0 214269975\r\n2 603901234\r\n3 772872647\r\n0 224281389\r\n4 561877930\r\n1 809519308\r\n4 883486551\r\n1 114469023\r\n2 184038037\r\n", "output": "860384990\r\n"}]
false
stdio
null
true
992/D
992
D
PyPy 3
TESTS
0
77
0
135798591
def process(A, k): n = len(A) S = [0] P = [1] answer = 0 p_index = 0 for i in range(n): S.append(S[-1]+A[i]) P.append(P[-1]*A[i]) while P[-1] > P[p_index]*k*S[-1]: p_index+=1 if p_index > 0: for j in range(p_index, i+1): P[j] = P[j]//P[p_index-1] if P[-1] % k==0: for j in range(p_index, i): if P[-1]==k*P[j]*(S[-1]-S[j]): answer+=1 if P[-1] < k*P[j]*A[i]: break return answer n, k = [int(x) for x in input().split()] A = [int(x) for x in input().split()] print(process(A, k))
134
1,325
26,624,000
80847835
n,k = map(int,input().split()) A = list(map(int,input().split())) A = [0]+A; x = 0 prev = [0 for i in range(n+1)] sm = [0 for i in range(n+1)] for i in range(1,n+1): prev[i] = x if A[i]>1: x = i sm[i] = A[i]+sm[i-1] lim = int(2*(10**18)) ans = 0 for i in range(1,n+1): p = 1 j = i while j: if lim//A[j]>p: s = sm[i]-sm[j-1] p *= A[j] if p%k == 0 and p//k>=s and j-1-prev[j]>=p/k-s: ans += 1 else: break j = prev[j] print(ans)
Codeforces Round 489 (Div. 2)
CF
2,018
2
256
Nastya and a Game
Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $$\frac{p}{s} = k$$, where p is the product of all integers on the given array, s is their sum, and k is a given constant for all subsegments. Nastya wonders how many subsegments of the array fit the described conditions. A subsegment of an array is several consecutive integers of the array.
The first line contains two integers n and k (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 105), where n is the length of the array and k is the constant described above. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 108) — the elements of the array.
In the only line print the number of subsegments such that the ratio between the product and the sum on them is equal to k.
null
In the first example the only subsegment is [1]. The sum equals 1, the product equals 1, so it suits us because $${ \frac { 1 } { 1 } } = 1$$. There are two suitable subsegments in the second example — [6, 3] and [3, 8, 1]. Subsegment [6, 3] has sum 9 and product 18, so it suits us because $$\frac{18}{9}=2$$. Subsegment [3, 8, 1] has sum 12 and product 24, so it suits us because $$\frac{24}{12}=2$$.
[{"input": "1 1\n1", "output": "1"}, {"input": "4 2\n6 3 8 1", "output": "2"}]
2,100
["brute force", "implementation", "math"]
134
[{"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "4 2\r\n6 3 8 1\r\n", "output": "2\r\n"}, {"input": "94 58\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 29 58 1 1 1 29 58 58 1 1 29 1 1 1 1 2 1 58 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 29 1 1 1 1 1 58 1 29 1 1 1 1 1 1 1 1 1 1 1 1 58 1 1 1 1 1 2 1 1 1\r\n", "output": "5\r\n"}, {"input": "6 76\r\n1 38 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "16 53\r\n53 1 1 1 1 1 53 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "13 16\r\n2 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "90 45\r\n15 1 1 1 1 3 1 1 5 3 5 1 1 15 15 3 1 15 1 1 1 15 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 15 1 1 1 1 1 1 1 1 1 15 1 1 1 1 5 1 1 1 1 15 1 1 1 15 1 1 1 1 1 1 1 1 3 1 1 15 3 1 1 1 15 15 1 1 1 1 15\r\n", "output": "5\r\n"}, {"input": "9 209\r\n2 7 31 673 853 1669 5821 7621 16677\r\n", "output": "0\r\n"}, {"input": "8 27\r\n8 3 9 8 3 10 7 1\r\n", "output": "0\r\n"}, {"input": "50 5\r\n1 5 11 10 3 6 9 3 9 6 1 1 4 7 8 6 11 2 6 10 4 1 8 11 5 6 5 6 7 2 2 3 1 10 8 8 2 10 7 3 8 10 11 7 3 2 10 11 7 4\r\n", "output": "0\r\n"}, {"input": "16 1\r\n2 6 1 11 5 9 5 9 7 5 8 5 3 2 7 2\r\n", "output": "16\r\n"}, {"input": "13 38\r\n1 10 4 1 5 5 4 4 8 4 11 1 9\r\n", "output": "0\r\n"}, {"input": "5 15\r\n10 9 5 2 2\r\n", "output": "0\r\n"}, {"input": "10 2\r\n1 1 1 1 10 3 1 1 1 1\r\n", "output": "3\r\n"}]
false
stdio
null
true
766/D
766
D
PyPy 3
TESTS
1
77
0
179671116
# LUOGU_RID: 93124141 n, m, q = map(int, input().split()) words = input().split() idx = {word: i for i, word in enumerate(words)} fa = list(range(n * 2)) def find(x): if fa[x] != x: fa[x] = find(fa[x]) return fa[x] def union(x, y): rx, ry = find(x), find(y) if rx <= ry: fa[ry] = rx return rx else: fa[rx] = ry return ry ans1 = [''] * m for i in range(m): t, w1, w2 = input().split() i1, i2 = idx[w1], idx[w2] if t == '1': if find(i1) == find(i2 + n) or find(i2) == find(i1 + n): ans1[i] = 'NO' else: union(i1, i2) union(i1 + n, i2 + n) ans1[i] = 'YES' else: if find(i1) == find(i2): ans1[i] = 'NO' else: union(i1, i2 + n) union(i2, i1 + n) ans1[i] = 'YES' for i in range(n): find(i) ans2 = [3] * q for i in range(q): w1, w2 = input().split() i1, i2 = idx[w1], idx[w2] if fa[i1] == fa[i2]: ans2[i] = 1 elif fa[i1] == fa[i2 + n] or fa[i2] == fa[i1 + n]: ans2[i] = 2 for ans in ans1: print(ans) for ans in ans2: print(ans)
32
1,154
45,568,000
189635045
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def get_root(s): v = [] while not s == root[s]: v.append(s) s = root[s] for i in v: root[i] = s return s def unite(s, t): rs, rt = get_root(s), get_root(t) if not rs ^ rt: return if rank[s] == rank[t]: rank[rs] += 1 if rank[s] >= rank[t]: root[rt] = rs size[rs] += size[rt] else: root[rs] = rt size[rt] += size[rs] return def same(s, t): return True if get_root(s) == get_root(t) else False def get_size(s): return size[get_root(s)] n, m, q = map(int, input().split()) a = list(input().rstrip().decode().split()) d = dict() for i in range(n): d[a[i]] = i root = [i for i in range(2 * n)] rank = [1 for _ in range(2 * n)] size = [1 for _ in range(2 * n)] ans = [] for _ in range(m): t = list(input().rstrip().decode().split()) u, v = d[t[1]], d[t[2]] if t[0] == "1": ans0 = "YES" if not same(u, v + n) else "NO" if ans0 == "YES": unite(u, v) unite(u + n, v + n) else: ans0 = "YES" if not same(u, v) else "NO" if ans0 == "YES": unite(u, v + n) unite(u + n, v) ans.append(ans0) for _ in range(q): t = list(input().rstrip().decode().split()) u, v = d[t[0]], d[t[1]] if same(u, v): ans0 = 1 elif same(u, v + n): ans0 = 2 else: ans0 = 3 ans.append(str(ans0)) sys.stdout.write("\n".join(ans))
Codeforces Round 396 (Div. 2)
CF
2,017
4
256
Mahmoud and a Dictionary
Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discovers a new relation between two words. He know that if two words have a relation between them, then each of them has relations with the words that has relations with the other. For example, if like means love and love is the opposite of hate, then like is also the opposite of hate. One more example: if love is the opposite of hate and hate is the opposite of like, then love means like, and so on. Sometimes Mahmoud discovers a wrong relation. A wrong relation is a relation that makes two words equal and opposite at the same time. For example if he knows that love means like and like is the opposite of hate, and then he figures out that hate means like, the last relation is absolutely wrong because it makes hate and like opposite and have the same meaning at the same time. After Mahmoud figured out many relations, he was worried that some of them were wrong so that they will make other relations also wrong, so he decided to tell every relation he figured out to his coder friend Ehab and for every relation he wanted to know is it correct or wrong, basing on the previously discovered relations. If it is wrong he ignores it, and doesn't check with following relations. After adding all relations, Mahmoud asked Ehab about relations between some words based on the information he had given to him. Ehab is busy making a Codeforces round so he asked you for help.
The first line of input contains three integers n, m and q (2 ≤ n ≤ 105, 1 ≤ m, q ≤ 105) where n is the number of words in the dictionary, m is the number of relations Mahmoud figured out and q is the number of questions Mahmoud asked after telling all relations. The second line contains n distinct words a1, a2, ..., an consisting of small English letters with length not exceeding 20, which are the words in the dictionary. Then m lines follow, each of them contains an integer t (1 ≤ t ≤ 2) followed by two different words xi and yi which has appeared in the dictionary words. If t = 1, that means xi has a synonymy relation with yi, otherwise xi has an antonymy relation with yi. Then q lines follow, each of them contains two different words which has appeared in the dictionary. That are the pairs of words Mahmoud wants to know the relation between basing on the relations he had discovered. All words in input contain only lowercase English letters and their lengths don't exceed 20 characters. In all relations and in all questions the two words are different.
First, print m lines, one per each relation. If some relation is wrong (makes two words opposite and have the same meaning at the same time) you should print "NO" (without quotes) and ignore it, otherwise print "YES" (without quotes). After that print q lines, one per each question. If the two words have the same meaning, output 1. If they are opposites, output 2. If there is no relation between them, output 3. See the samples for better understanding.
null
null
[{"input": "3 3 4\nhate love like\n1 love like\n2 love hate\n1 hate like\nlove like\nlove hate\nlike hate\nhate like", "output": "YES\nYES\nNO\n1\n2\n2\n2"}, {"input": "8 6 5\nhi welcome hello ihateyou goaway dog cat rat\n1 hi welcome\n1 ihateyou goaway\n2 hello ihateyou\n2 hi goaway\n2 hi hello\n1 hi hello\ndog cat\ndog hi\nhi hello\nihateyou goaway\nwelcome ihateyou", "output": "YES\nYES\nYES\nYES\nNO\nYES\n3\n3\n1\n1\n2"}]
2,000
["data structures", "dfs and similar", "dp", "dsu", "graphs"]
32
[{"input": "3 3 4\r\nhate love like\r\n1 love like\r\n2 love hate\r\n1 hate like\r\nlove like\r\nlove hate\r\nlike hate\r\nhate like\r\n", "output": "YES\r\nYES\r\nNO\r\n1\r\n2\r\n2\r\n2\r\n"}, {"input": "8 6 5\r\nhi welcome hello ihateyou goaway dog cat rat\r\n1 hi welcome\r\n1 ihateyou goaway\r\n2 hello ihateyou\r\n2 hi goaway\r\n2 hi hello\r\n1 hi hello\r\ndog cat\r\ndog hi\r\nhi hello\r\nihateyou goaway\r\nwelcome ihateyou\r\n", "output": "YES\r\nYES\r\nYES\r\nYES\r\nNO\r\nYES\r\n3\r\n3\r\n1\r\n1\r\n2\r\n"}, {"input": "5 4 5\r\nhello hi welcome ihateyou goaway\r\n1 hello hi\r\n1 hi welcome\r\n2 ihateyou hi\r\n2 goaway hi\r\nwelcome hello\r\nihateyou welcome\r\nwelcome goaway\r\ngoaway ihateyou\r\nwelcome hi\r\n", "output": "YES\r\nYES\r\nYES\r\nYES\r\n1\r\n2\r\n2\r\n1\r\n1\r\n"}, {"input": "2 1 1\r\na b\r\n1 a b\r\na b\r\n", "output": "YES\r\n1\r\n"}, {"input": "5 5 5\r\nhello hi welcome hallo ahlan\r\n1 hello hi\r\n1 hi welcome\r\n1 welcome hallo\r\n1 hallo ahlan\r\n2 ahlan hello\r\nhello hi\r\nahlan welcome\r\nhi welcome\r\nhi ahlan\r\nhallo hello\r\n", "output": "YES\r\nYES\r\nYES\r\nYES\r\nNO\r\n1\r\n1\r\n1\r\n1\r\n1\r\n"}, {"input": "6 2 6\r\nhello hi welcome dog cat lion\r\n1 hello hi\r\n1 hi welcome\r\nhi dog\r\ndog cat\r\nhello hi\r\nhi hello\r\nwelcome cat\r\nlion cat\r\n", "output": "YES\r\nYES\r\n3\r\n3\r\n1\r\n1\r\n3\r\n3\r\n"}, {"input": "2 1 1\r\nhi hello\r\n1 hi hello\r\nhi hello\r\n", "output": "YES\r\n1\r\n"}, {"input": "8 4 12\r\nhello hi welcome goaway hateyou mmmm momo mana\r\n1 hello hi\r\n1 hi welcome\r\n2 goaway welcome\r\n2 hateyou hi\r\nhateyou goaway\r\nhateyou hi\r\nhateyou hi\r\nhateyou welcome\r\nmmmm momo\r\nwelcome hi\r\nwelcome hateyou\r\nhateyou goaway\r\nhello goaway\r\nhello goaway\r\nhello hateyou\r\ngoaway mmmm\r\n", "output": "YES\r\nYES\r\nYES\r\nYES\r\n1\r\n2\r\n2\r\n2\r\n3\r\n1\r\n2\r\n1\r\n2\r\n2\r\n2\r\n3\r\n"}, {"input": "12 9 16\r\na b c d e f g h i j k l\r\n1 a b\r\n2 a c\r\n2 a d\r\n2 b e\r\n2 b f\r\n2 e g\r\n2 f h\r\n2 g i\r\n2 h j\r\ni j\r\ne i\r\nc d\r\ne f\r\nc f\r\nd e\r\nb c\r\nb c\r\nb f\r\nb f\r\nk a\r\nk b\r\nk l\r\nk l\r\nj e\r\nh g\r\n", "output": "YES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n3\r\n3\r\n3\r\n3\r\n1\r\n1\r\n"}, {"input": "10 5 10\r\na b c d e f g h i j\r\n1 f j\r\n2 a e\r\n2 b g\r\n2 f e\r\n2 j g\r\na b\r\nb c\r\na b\r\nb c\r\nh j\r\nh j\r\na f\r\ne g\r\nb e\r\na g\r\n", "output": "YES\r\nYES\r\nYES\r\nYES\r\nYES\r\n1\r\n3\r\n1\r\n3\r\n3\r\n3\r\n1\r\n1\r\n2\r\n2\r\n"}, {"input": "10 7 10\r\na b c d e f g h i j\r\n1 h j\r\n2 a e\r\n2 b g\r\n2 g c\r\n2 e d\r\n2 d f\r\n2 c f\r\na b\r\nb c\r\na b\r\nb c\r\nh j\r\nh j\r\na f\r\ne g\r\nb e\r\na g\r\n", "output": "YES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n2\r\n1\r\n2\r\n2\r\n"}]
false
stdio
null
true
615/B
615
B
Python 3
TESTS
5
483
19,660,800
87278461
from collections import defaultdict graph = defaultdict(list) n, m = list(map(int, input().split())) for i in range(m): v, u = list(map(int, input().split())) graph[v].append(u) graph[u].append(v) dp = [0] * (n + 1) dp[1] = 1 ans = len(graph[1]) for i in range(2, n + 1): for v in graph[i]: if v < i: dp[i] = max(dp[i], dp[v] + 1) ans = max(ans, dp[i] * len(graph[i])) print(ans)
60
280
20,480,000
194207905
import sys input = sys.stdin.readline n, m = map(int, input().split()) d = [[] for i in range(n+1)] for i in range(m): a, b = map(int, input().split()) d[a].append(b) d[b].append(a) x = [1]*(n+1) t = 0 for i in range(1, n+1): t = max(t, x[i]*len(d[i])) for j in d[i]: if j > i: x[j] = max(x[j], 1+x[i]) print(t)
Codeforces Round 338 (Div. 2)
CF
2,016
3
256
Longtail Hedgehog
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions: 1. Only segments already presented on the picture can be painted; 2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment; 3. The numbers of points from the beginning of the tail to the end should strictly increase. Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get. Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
First line of the input contains two integers n and m(2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number segments on the picture respectively. Then follow m lines, each containing two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Print the maximum possible value of the hedgehog's beauty.
null
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3·3 = 9.
[{"input": "8 6\n4 5\n3 5\n2 5\n1 2\n2 8\n6 7", "output": "9"}, {"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "12"}]
1,600
["dp", "graphs"]
60
[{"input": "8 6\r\n4 5\r\n3 5\r\n2 5\r\n1 2\r\n2 8\r\n6 7\r\n", "output": "9\r\n"}, {"input": "4 6\r\n1 2\r\n1 3\r\n1 4\r\n2 3\r\n2 4\r\n3 4\r\n", "output": "12\r\n"}, {"input": "5 7\r\n1 3\r\n2 4\r\n4 5\r\n5 3\r\n2 1\r\n1 4\r\n3 2\r\n", "output": "9\r\n"}, {"input": "5 9\r\n1 3\r\n2 4\r\n4 5\r\n5 3\r\n2 1\r\n1 4\r\n3 2\r\n1 5\r\n2 5\r\n", "output": "16\r\n"}, {"input": "10 10\r\n6 3\r\n2 9\r\n9 4\r\n4 5\r\n10 3\r\n8 3\r\n10 5\r\n7 6\r\n1 4\r\n6 8\r\n", "output": "8\r\n"}, {"input": "100 50\r\n66 3\r\n92 79\r\n9 44\r\n84 45\r\n30 63\r\n30 20\r\n33 86\r\n8 83\r\n40 75\r\n7 36\r\n91 4\r\n76 88\r\n77 76\r\n28 27\r\n6 52\r\n41 57\r\n8 23\r\n34 75\r\n50 15\r\n86 68\r\n36 98\r\n30 84\r\n37 62\r\n22 4\r\n6 45\r\n72 80\r\n98 74\r\n78 84\r\n1 54\r\n99 27\r\n84 91\r\n78 7\r\n80 61\r\n67 48\r\n51 52\r\n36 72\r\n97 87\r\n25 17\r\n20 80\r\n20 39\r\n72 5\r\n21 77\r\n48 1\r\n63 21\r\n92 45\r\n34 93\r\n28 84\r\n3 91\r\n56 99\r\n7 53\r\n", "output": "15\r\n"}, {"input": "5 8\r\n1 3\r\n2 4\r\n4 5\r\n5 3\r\n2 1\r\n1 4\r\n3 2\r\n1 5\r\n", "output": "12\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "2\r\n"}, {"input": "10 9\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n1 6\r\n1 7\r\n1 8\r\n1 9\r\n1 10\r\n", "output": "9\r\n"}, {"input": "5 4\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n", "output": "4\r\n"}, {"input": "6 5\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n1 6\r\n", "output": "5\r\n"}]
false
stdio
null
true
66/C
66
C
Python 3
TESTS
10
216
307,200
66518468
import sys, operator filePaths = sys.stdin.readlines() foldercount = 0 fileoccurences = {'C:':[0,0,{}],'D:':[0,0,{}],'E:':[0,0,{}],'F:':[0,0,{}],'G:':[0,0,{}]} for line in filePaths: path = list(map(str,line.split('\\'))) fileoccurences[path[0]][0] += 1 newFolder = False for i in range(1,len(path)-1): if path[i] not in fileoccurences[path[0]][2].keys(): fileoccurences[path[0]][2].update({path[i]:[i]}) if i != 1: fileoccurences[path[0]][1] += 1 newFolder = True else: if not newFolder: if i not in fileoccurences[path[0]][2][path[i]]: newFolder = True; fileoccurences[path[0]][1] += 1 fileoccurences[path[0]][2][path[i]].append(i) else: fileoccurences[path[0]][1] += 1 fileoccurences[path[0]][2][path[i]].append(i) print(max(fileoccurences.items(),key = lambda k: k[1][1])[1][1], max(fileoccurences.items(),key = lambda h: h[1][0])[1][0])
100
92
716,800
205045482
import sys def main(): path_set = set() is_created = {} storage = {} freq_folders = {} folder_recorded = {} for path in sys.stdin: path = path.strip() if path in path_set: continue path_set.add(path) if path not in is_created: is_created[path] = True disk, dir = path.split(":", 1)[0], path.split(":", 1)[1] dir = dir.lstrip("\\") root = "" inserted_file = 0 length = len(dir) if disk not in storage: storage[disk] = {} freq_folders[disk] = {} folder_recorded[disk] = {} for i in range(length): root += dir[i] if dir[i] == "\\": current_folder = root + "\\" current_root = freq_folders[disk] current_root_record = folder_recorded[disk] if root not in storage[disk]: current_root[root] = 0 storage[disk][root] = 0 storage[disk][root] += 1 for j in range(i + 1, length): current_folder += dir[j] if dir[j] == "\\" and current_folder not in current_root_record: current_root[root] += 1 current_root_record[current_folder] = True break max_files = 0 max_folders = 0 for p in storage.values(): for freq in p.values(): max_files = max(max_files, freq) for freq_disk in freq_folders.values(): for freq in freq_disk.values(): max_folders = max(max_folders, freq) print(max_folders, max_files) if __name__ == "__main__": main()
Codeforces Beta Round 61 (Div. 2)
CF
2,011
3
256
Petya and File System
Recently, on a programming lesson little Petya showed how quickly he can create files and folders on the computer. But he got soon fed up with this activity, and he decided to do a much more useful thing. He decided to calculate what folder contains most subfolders (including nested folders, nested folders of nested folders, and so on) and what folder contains most files (including the files in the subfolders). More formally, the subfolders of the folder are all its directly nested folders and the subfolders of these nested folders. The given folder is not considered the subfolder of itself. A file is regarded as lying in a folder, if and only if it either lies directly in this folder, or lies in some subfolder of the folder. For a better understanding of how to count subfolders and files for calculating the answer, see notes and answers to the samples. You are given a few files that Petya has managed to create. The path to each file looks as follows: diskName:\folder1\folder2\...\ foldern\fileName - diskName is single capital letter from the set {C,D,E,F,G}. - folder1, ..., foldern are folder names. Each folder name is nonempty sequence of lowercase Latin letters and digits from 0 to 9. (n ≥ 1) - fileName is a file name in the form of name.extension, where the name and the extension are nonempty sequences of lowercase Latin letters and digits from 0 to 9. It is also known that there is no file whose path looks like diskName:\fileName. That is, each file is stored in some folder, but there are no files directly in the root. Also let us assume that the disk root is not a folder. Help Petya to find the largest number of subfolders, which can be in some folder, and the largest number of files that can be in some folder, counting all its subfolders.
Each line of input data contains the description of one file path. The length of each line does not exceed 100, and overall there are no more than 100 lines. It is guaranteed, that all the paths are correct and meet the above rules. It is also guaranteed, that there are no two completely equal lines. That is, each file is described exactly once. There is at least one line in the input data.
Print two space-separated numbers. The first one is the maximal number of possible subfolders in a folder (including nested folders, nested folders of nested folders, and so on). The second one is the maximal number of files in a folder (including nested files in subfolders). Note that the disks are not regarded as folders.
null
In the first sample we have one folder on the "C" disk. It has no subfolders, which is why the first number in the answer is 0. But this folder contains one file, so the second number of the answer is 1. In the second sample we have several different folders. Consider the "folder1" folder on the "C" disk. This folder directly contains one folder, "folder2". The "folder2" folder contains two more folders — "folder3" and "folder4". Thus, the "folder1" folder on the "C" drive has exactly 3 subfolders. Also this folder contains two files, even though they do not lie directly in the folder, but they are located in subfolders of "folder1". In the third example we see that the names of some folders and some subfolders are identical. Consider the "file" folder, which lies directly on the "C" disk. That folder contains another "file" folder, which in turn contains another "file" folder, which contains two more folders, "file" and "file2". Thus, the "file" folder, which lies directly on the "C" disk, contains 4 subfolders.
[{"input": "C:\n\\\nfolder1\n\\\nfile1.txt", "output": "0 1"}, {"input": "C:\n\\\nfolder1\n\\\nfolder2\n\\\nfolder3\n\\\nfile1.txt\nC:\n\\\nfolder1\n\\\nfolder2\n\\\nfolder4\n\\\nfile1.txt\nD:\n\\\nfolder1\n\\\nfile1.txt", "output": "3 2"}, {"input": "C:\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile.txt\nC:\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile2\n\\\nfile.txt", "output": "4 2"}]
1,800
["data structures", "implementation"]
100
[{"input": "C:\\folder1\\file1.txt\r\n", "output": "0 1\r\n"}, {"input": "C:\\folder1\\folder2\\folder3\\file1.txt\r\nC:\\folder1\\folder2\\folder4\\file1.txt\r\nD:\\folder1\\file1.txt\r\n", "output": "3 2\r\n"}, {"input": "C:\\file\\file\\file\\file\\file.txt\r\nC:\\file\\file\\file\\file2\\file.txt\r\n", "output": "4 2\r\n"}, {"input": "C:\\file\\file.txt\r\nD:\\file\\file.txt\r\nE:\\file\\file.txt\r\nF:\\file\\file.txt\r\nG:\\file\\file.txt\r\n", "output": "0 1\r\n"}, {"input": "C:\\a\\b\\c\\d\\d.txt\r\nC:\\a\\b\\c\\e\\f.txt\r\n", "output": "4 2\r\n"}, {"input": "C:\\z\\z.txt\r\nD:\\1\\1.txt\r\nD:\\1\\2.txt\r\n", "output": "0 2\r\n"}, {"input": "D:\\0000\\1.txt\r\nE:\\00000\\1.txt\r\n", "output": "0 1\r\n"}, {"input": "C:\\a\\b\\c\\d.txt\r\nC:\\a\\e\\c\\d.txt\r\n", "output": "4 2\r\n"}, {"input": "C:\\test1\\test2\\test3\\test.txt\r\nC:\\test1\\test3\\test3\\test4\\test.txt\r\nC:\\test1\\test2\\test3\\test2.txt\r\nD:\\test1\\test2\\test.txt\r\nD:\\test1\\test3\\test4.txt\r\n", "output": "5 3\r\n"}, {"input": "C:\\test1\\test2\\test.txt\r\nC:\\test1\\test2\\test2.txt\r\n", "output": "1 2\r\n"}]
false
stdio
null
true
884/A
884
A
Python 3
TESTS
14
62
0
31875754
line = input().split() n = int(line[0]) t = int(line[1]) line = input().split() for i in range(t): t = t - (86400 - int(line[i])) if t < 1: break print(i + 1)
16
31
0
184609915
g = list(map(int ,input().strip().split())) n=int(g[0]) m=int(g[-1]) l = list(map(int ,input().strip().split())) c = 0 day = 0 for i in range(n): c += 86400 - l[i] day += 1 if c >= m: print(day) break
Educational Codeforces Round 31
ICPC
2,017
2
256
Book Reading
Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of n next days. The number of seconds that Luba has to spend working during i-th day is ai. If some free time remains, she can spend it on reading. Help Luba to determine the minimum number of day when she finishes reading. It is guaranteed that the answer doesn't exceed n. Remember that there are 86400 seconds in a day.
The first line contains two integers n and t (1 ≤ n ≤ 100, 1 ≤ t ≤ 106) — the number of days and the time required to read the book. The second line contains n integers ai (0 ≤ ai ≤ 86400) — the time Luba has to spend on her work during i-th day.
Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed n.
null
null
[{"input": "2 2\n86400 86398", "output": "2"}, {"input": "2 86400\n0 86400", "output": "1"}]
800
["implementation"]
16
[{"input": "2 2\r\n86400 86398\r\n", "output": "2\r\n"}, {"input": "2 86400\r\n0 86400\r\n", "output": "1\r\n"}, {"input": "2 86400\r\n1 86399\r\n", "output": "2\r\n"}, {"input": "100 1000000\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n", "output": "12\r\n"}, {"input": "1 1\r\n86399\r\n", "output": "1\r\n"}, {"input": "6 1200\r\n86400 86400 86000 86000 86000 86400\r\n", "output": "5\r\n"}, {"input": "6 1200\r\n86400 86400 86000 86000 86001 86399\r\n", "output": "6\r\n"}, {"input": "4 172799\r\n1 1 86400 0\r\n", "output": "4\r\n"}, {"input": "4 172799\r\n0 86400 86399 0\r\n", "output": "4\r\n"}, {"input": "6 1\r\n1 1 86400 1 86399 1\r\n", "output": "1\r\n"}, {"input": "4 1\r\n86400 86399 86400 86400\r\n", "output": "2\r\n"}, {"input": "4 1\r\n86400 86400 0 86400\r\n", "output": "3\r\n"}]
false
stdio
null
true
884/A
884
A
Python 3
TESTS
4
30
0
135766151
n,t=map(int,input().split()) a=[int(a) for a in input().split()] count=0 for i in range(n): if 86400>=t+a[i]: count+=1 break count+=1 print(count)
16
31
0
187660697
[a,b] = map(int,input().split()) l = list(map(int,input().split())) s = 0 d = 0 for i in range(a): d += 1 s += 86400-l[i] if s >= b: break print(d)
Educational Codeforces Round 31
ICPC
2,017
2
256
Book Reading
Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of n next days. The number of seconds that Luba has to spend working during i-th day is ai. If some free time remains, she can spend it on reading. Help Luba to determine the minimum number of day when she finishes reading. It is guaranteed that the answer doesn't exceed n. Remember that there are 86400 seconds in a day.
The first line contains two integers n and t (1 ≤ n ≤ 100, 1 ≤ t ≤ 106) — the number of days and the time required to read the book. The second line contains n integers ai (0 ≤ ai ≤ 86400) — the time Luba has to spend on her work during i-th day.
Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed n.
null
null
[{"input": "2 2\n86400 86398", "output": "2"}, {"input": "2 86400\n0 86400", "output": "1"}]
800
["implementation"]
16
[{"input": "2 2\r\n86400 86398\r\n", "output": "2\r\n"}, {"input": "2 86400\r\n0 86400\r\n", "output": "1\r\n"}, {"input": "2 86400\r\n1 86399\r\n", "output": "2\r\n"}, {"input": "100 1000000\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n", "output": "12\r\n"}, {"input": "1 1\r\n86399\r\n", "output": "1\r\n"}, {"input": "6 1200\r\n86400 86400 86000 86000 86000 86400\r\n", "output": "5\r\n"}, {"input": "6 1200\r\n86400 86400 86000 86000 86001 86399\r\n", "output": "6\r\n"}, {"input": "4 172799\r\n1 1 86400 0\r\n", "output": "4\r\n"}, {"input": "4 172799\r\n0 86400 86399 0\r\n", "output": "4\r\n"}, {"input": "6 1\r\n1 1 86400 1 86399 1\r\n", "output": "1\r\n"}, {"input": "4 1\r\n86400 86399 86400 86400\r\n", "output": "2\r\n"}, {"input": "4 1\r\n86400 86400 0 86400\r\n", "output": "3\r\n"}]
false
stdio
null
true
289/A
289
A
Python 3
TESTS
13
92
0
215088212
n,k =map(int,input().split()) num1,num2=0,0 sum=0 for i in range(n): num1,num2 =map(int,input().split()) sum+=abs(abs(num1)-abs(num2))+1 i=0 while True : if ((sum+i) % k) ==0: print(i) break i+=1
28
342
0
211253332
n, k = map(int, input().split()) value = 0 positions = {} for i in range(n): l, r = map(int, input().split()) value += r-l+1 print((((value+k)-(value+k)%k)-value)%k)
Codeforces Round 177 (Div. 2)
CF
2,013
2
256
Polo the Penguin and Segments
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1]. The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj. Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj).
In a single line print a single integer — the answer to the problem.
null
null
[{"input": "2 3\n1 2\n3 4", "output": "2"}, {"input": "3 7\n1 2\n3 3\n4 7", "output": "0"}]
1,100
["brute force", "implementation"]
28
[{"input": "2 3\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "3 7\r\n1 2\r\n3 3\r\n4 7\r\n", "output": "0\r\n"}, {"input": "3 7\r\n1 10\r\n11 47\r\n74 128\r\n", "output": "3\r\n"}, {"input": "5 4\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n", "output": "3\r\n"}, {"input": "7 4\r\n2 2\r\n-1 -1\r\n0 1\r\n7 8\r\n-3 -2\r\n9 9\r\n4 6\r\n", "output": "0\r\n"}, {"input": "10 2\r\n92 92\r\n55 59\r\n70 73\r\n78 81\r\n62 65\r\n95 99\r\n74 75\r\n85 87\r\n51 51\r\n60 60\r\n", "output": "0\r\n"}, {"input": "10 474\r\n56 60\r\n82 82\r\n73 73\r\n105 109\r\n77 80\r\n51 51\r\n85 88\r\n97 100\r\n91 92\r\n64 68\r\n", "output": "442\r\n"}, {"input": "3 4587\r\n-49 368\r\n-734 -390\r\n-380 -117\r\n", "output": "3560\r\n"}, {"input": "1 100000\r\n-100000 100000\r\n", "output": "99999\r\n"}, {"input": "2 100000\r\n-100000 99999\r\n100000 100000\r\n", "output": "99999\r\n"}, {"input": "1 7\r\n0 0\r\n", "output": "6\r\n"}, {"input": "2 5848\r\n-100000 0\r\n1 100000\r\n", "output": "4679\r\n"}, {"input": "3 99999\r\n-100000 -100000\r\n-99999 99998\r\n99999 100000\r\n", "output": "99996\r\n"}]
false
stdio
null
true