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
750/B
750
B
PyPy 3-64
TESTS
0
30
0
222621675
def is_valid_journey(n, instructions): current_position = 0 # Start at the North Pole for i in range(n): t, dir_i = instructions[i] # Update the current position based on the direction if dir_i == "North": current_position += t elif dir_i == "South": current_position -= t # Check if we are on the North Pole if current_position < 0: return "NO" # Check if the journey ends on the North Pole if current_position == 0: return "YES" else: return "NO" # Read input n = int(input()) instructions = [] for _ in range(n): t, dir_i = input().split() t = int(t) instructions.append((t, dir_i)) # Check and print the result result = is_valid_journey(n, instructions) print(result)
140
62
4,710,400
23432135
q=int(input()) s=20000 z=['North', 'South'] x=['West', 'East'] b=True for j in range(0,q): a=list(input().split()) if b: a[0]=int(a[0]) if ((s==0)|(s==20000))&(a[1] in x): b=False elif (s==20000)&(a[1]=='North'): b=False elif (s==0)&(a[1]=='South'): b=False elif a[1] in z: if a[1]==z[0]: s+=a[0] if s>20000: b=False else: s-=a[0] if s<0: b=False if (b)&(s!=20000): b=False print('YES' if b else 'NO')
Good Bye 2016
CF
2,016
2
256
New Year and North Pole
In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers. Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move ti kilometers in the direction represented by a string diri that is one of: "North", "South", "West", "East". Limak isn’t sure whether the description is valid. You must help him to check the following conditions: - If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South. - If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North. - The journey must end on the North Pole. Check if the above conditions are satisfied and print "YES" or "NO" on a single line.
The first line of the input contains a single integer n (1 ≤ n ≤ 50). The i-th of next n lines contains an integer ti and a string diri (1 ≤ ti ≤ 106, $${ dir } _ { i } \in \{ \mathrm { N o r t h, ~ S o u t h, ~ W e s t, ~ E a s t } \}$$) — the length and the direction of the i-th part of the journey, according to the description Limak got.
Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes.
null
Drawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole.
[{"input": "5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North", "output": "YES"}, {"input": "2\n15000 South\n4000 East", "output": "NO"}, {"input": "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North", "output": "YES"}, {"input": "3\n20000 South\n10 East\n20000 North", "output": "NO"}, {"input": "2\n1000 North\n1000 South", "output": "NO"}, {"input": "4\n50 South\n50 North\n15000 South\n15000 North", "output": "YES"}]
1,300
["geometry", "implementation"]
140
[{"input": "5\r\n7500 South\r\n10000 East\r\n3500 North\r\n4444 West\r\n4000 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n15000 South\r\n4000 East\r\n", "output": "NO\r\n"}, {"input": "5\r\n20000 South\r\n1000 North\r\n1000000 West\r\n9000 North\r\n10000 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n20000 South\r\n10 East\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n1000 North\r\n1000 South\r\n", "output": "NO\r\n"}, {"input": "4\r\n50 South\r\n50 North\r\n15000 South\r\n15000 North\r\n", "output": "YES\r\n"}, {"input": "1\r\n1 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n1 East\r\n", "output": "NO\r\n"}, {"input": "2\r\n1000000 South\r\n1000000 North\r\n", "output": "NO\r\n"}, {"input": "1\r\n149 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n16277 East\r\n", "output": "NO\r\n"}, {"input": "1\r\n19701 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n3125 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n6549 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n2677 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n6101 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n9525 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n5653 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n15072 South\r\n15072 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n11200 South\r\n11200 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n14624 South\r\n14624 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n18048 South\r\n15452 West\r\n", "output": "NO\r\n"}, {"input": "2\r\n1472 West\r\n4930 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n17600 South\r\n17600 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n8320 East\r\n16589 East\r\n", "output": "NO\r\n"}, {"input": "2\r\n4448 South\r\n4448 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n576 South\r\n576 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n14186 South\r\n2291 West\r\n14186 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n10314 South\r\n15961 North\r\n5647 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n1035 East\r\n18143 South\r\n18143 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n17163 South\r\n7620 East\r\n17163 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n587 South\r\n17098 North\r\n16511 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n16715 North\r\n6576 West\r\n12132 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n7435 South\r\n245 North\r\n7190 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n3563 South\r\n2427 South\r\n5990 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n6987 South\r\n11904 East\r\n19951 East\r\n", "output": "NO\r\n"}, {"input": "4\r\n13301 South\r\n5948 East\r\n9265 East\r\n6891 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n16725 South\r\n8129 South\r\n19530 West\r\n24854 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n149 South\r\n17607 West\r\n18306 South\r\n18455 North\r\n", "output": "YES\r\n"}, {"input": "4\r\n16277 South\r\n19789 North\r\n4379 South\r\n867 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n19701 South\r\n13458 South\r\n3156 North\r\n30003 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n3125 South\r\n15640 East\r\n6125 East\r\n19535 South\r\n", "output": "NO\r\n"}, {"input": "4\r\n6549 East\r\n5118 North\r\n12198 East\r\n5118 South\r\n", "output": "NO\r\n"}, {"input": "4\r\n2677 East\r\n1891 West\r\n10974 West\r\n7511 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n6102 South\r\n8265 East\r\n13943 South\r\n20045 North\r\n", "output": "NO\r\n"}, {"input": "5\r\n12416 South\r\n18116 North\r\n10553 West\r\n18435 West\r\n5700 South\r\n", "output": "NO\r\n"}, {"input": "5\r\n15840 South\r\n7594 South\r\n13522 South\r\n2423 South\r\n3334 West\r\n", "output": "NO\r\n"}, {"input": "5\r\n19264 East\r\n13968 East\r\n19595 North\r\n19115 North\r\n38710 South\r\n", "output": "NO\r\n"}, {"input": "5\r\n15392 South\r\n3445 North\r\n18372 East\r\n10399 North\r\n4403 South\r\n", "output": "NO\r\n"}, {"input": "5\r\n18816 South\r\n5627 West\r\n14045 East\r\n7091 East\r\n18816 North\r\n", "output": "YES\r\n"}, {"input": "5\r\n2240 South\r\n15104 North\r\n118 West\r\n11079 East\r\n12864 South\r\n", "output": "NO\r\n"}, {"input": "5\r\n5664 South\r\n1478 South\r\n18894 South\r\n2363 West\r\n26036 North\r\n", "output": "NO\r\n"}, {"input": "5\r\n1792 South\r\n10956 East\r\n9159 South\r\n19055 West\r\n10951 North\r\n", "output": "YES\r\n"}, {"input": "5\r\n12512 South\r\n13137 North\r\n7936 North\r\n7235 South\r\n1326 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n14635 North\r\n14477 South\r\n17250 North\r\n14170 East\r\n15166 South\r\n2242 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n10763 North\r\n3954 West\r\n7515 North\r\n18158 West\r\n6644 South\r\n11634 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n14187 South\r\n13432 North\r\n6292 East\r\n14850 West\r\n10827 South\r\n9639 East\r\n", "output": "NO\r\n"}, {"input": "6\r\n10315 South\r\n15614 South\r\n5069 West\r\n6134 South\r\n7713 North\r\n24350 North\r\n", "output": "NO\r\n"}, {"input": "6\r\n1035 South\r\n9283 East\r\n15333 South\r\n2826 South\r\n19191 North\r\n3 North\r\n", "output": "YES\r\n"}, {"input": "6\r\n17163 West\r\n11465 North\r\n14110 South\r\n6814 North\r\n3373 East\r\n4169 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n587 South\r\n942 West\r\n183 North\r\n18098 North\r\n260 East\r\n17694 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n16715 West\r\n3124 East\r\n3152 East\r\n14790 East\r\n11738 West\r\n11461 East\r\n", "output": "NO\r\n"}, {"input": "6\r\n7435 South\r\n12602 South\r\n1929 East\r\n6074 East\r\n15920 West\r\n20037 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n13750 South\r\n6645 South\r\n18539 East\r\n5713 North\r\n1580 North\r\n10012 West\r\n13102 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n9878 West\r\n8827 East\r\n1508 West\r\n9702 North\r\n5763 North\r\n9755 North\r\n10034 South\r\n", "output": "NO\r\n"}, {"input": "7\r\n13302 West\r\n2496 North\r\n284 West\r\n6394 East\r\n9945 North\r\n12603 West\r\n12275 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n16726 East\r\n19270 West\r\n6357 South\r\n17678 East\r\n14127 East\r\n12347 South\r\n6005 East\r\n", "output": "NO\r\n"}, {"input": "7\r\n150 South\r\n1452 North\r\n9326 North\r\n1666 West\r\n18309 East\r\n19386 East\r\n8246 West\r\n", "output": "NO\r\n"}, {"input": "7\r\n16278 South\r\n10929 South\r\n8103 East\r\n18358 West\r\n2492 West\r\n11834 South\r\n39041 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n19702 South\r\n13111 East\r\n6880 East\r\n9642 South\r\n6674 West\r\n18874 East\r\n1112 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n3126 South\r\n6780 North\r\n9848 West\r\n6334 North\r\n10856 West\r\n14425 West\r\n10649 East\r\n", "output": "NO\r\n"}, {"input": "7\r\n6550 South\r\n8962 West\r\n15921 South\r\n17618 North\r\n15038 South\r\n1465 North\r\n18426 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n12864 South\r\n3005 West\r\n16723 West\r\n17257 West\r\n12187 East\r\n12976 South\r\n1598 North\r\n24242 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n8992 South\r\n12483 North\r\n15500 South\r\n1245 South\r\n9073 East\r\n12719 East\r\n3839 East\r\n7130 South\r\n", "output": "NO\r\n"}, {"input": "8\r\n12416 North\r\n14665 South\r\n14277 North\r\n2129 South\r\n13255 East\r\n19759 South\r\n10272 West\r\n9860 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n15840 South\r\n4142 East\r\n17246 North\r\n13413 North\r\n4733 West\r\n15311 North\r\n12514 South\r\n17616 South\r\n", "output": "NO\r\n"}, {"input": "8\r\n19264 South\r\n10516 North\r\n3319 East\r\n17401 East\r\n1620 West\r\n2350 West\r\n6243 North\r\n2505 North\r\n", "output": "YES\r\n"}, {"input": "8\r\n15392 South\r\n7290 West\r\n2096 West\r\n14093 East\r\n5802 South\r\n2094 North\r\n8484 East\r\n19100 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n6113 South\r\n16767 East\r\n5064 South\r\n5377 West\r\n17280 South\r\n1838 West\r\n2213 West\r\n28457 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n2241 West\r\n18949 South\r\n11137 South\r\n2069 West\r\n14166 South\r\n1581 South\r\n4455 South\r\n50288 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n5665 South\r\n8426 East\r\n9914 North\r\n13353 South\r\n18349 North\r\n4429 East\r\n18184 North\r\n27429 South\r\n", "output": "NO\r\n"}, {"input": "9\r\n11979 South\r\n2470 East\r\n10716 North\r\n12992 East\r\n15497 West\r\n15940 North\r\n8107 West\r\n18934 East\r\n6993 South\r\n", "output": "NO\r\n"}, {"input": "9\r\n8107 South\r\n4652 North\r\n9493 North\r\n16980 West\r\n12383 West\r\n2980 West\r\n17644 South\r\n11043 West\r\n11447 North\r\n", "output": "NO\r\n"}, {"input": "9\r\n18827 South\r\n18321 West\r\n8270 East\r\n968 West\r\n16565 West\r\n15427 North\r\n4077 North\r\n18960 North\r\n19006 West\r\n", "output": "NO\r\n"}, {"input": "9\r\n14955 West\r\n503 North\r\n18535 West\r\n4956 South\r\n8044 South\r\n2467 East\r\n13615 East\r\n6877 East\r\n3460 North\r\n", "output": "NO\r\n"}, {"input": "9\r\n18379 South\r\n9980 South\r\n17311 West\r\n8944 South\r\n4930 South\r\n18019 South\r\n48 West\r\n14794 South\r\n75046 North\r\n", "output": "NO\r\n"}, {"input": "9\r\n14507 East\r\n12162 East\r\n16088 South\r\n5636 North\r\n9112 North\r\n5058 East\r\n9585 South\r\n2712 East\r\n10925 North\r\n", "output": "NO\r\n"}, {"input": "9\r\n5227 East\r\n8936 North\r\n6353 North\r\n16920 North\r\n591 North\r\n4802 South\r\n8722 North\r\n3333 West\r\n36720 South\r\n", "output": "NO\r\n"}, {"input": "9\r\n1355 North\r\n15309 West\r\n17834 North\r\n13612 East\r\n17477 North\r\n4546 North\r\n18260 East\r\n15442 North\r\n56654 South\r\n", "output": "NO\r\n"}, {"input": "9\r\n4779 South\r\n4787 East\r\n3907 East\r\n4896 East\r\n1659 East\r\n4289 West\r\n4693 West\r\n3359 East\r\n4779 North\r\n", "output": "YES\r\n"}, {"input": "1\r\n80000 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n40000 South\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "1\r\n40000 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n20001 South\r\n20001 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n10000 South\r\n20000 South\r\n10000 North\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n10 South\r\n20 North\r\n10 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1000 South\r\n1001 North\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20000 South\r\n20000 West\r\n", "output": "NO\r\n"}, {"input": "3\r\n10000 South\r\n20000 South\r\n10000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 East\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20000 West\r\n20000 West\r\n", "output": "NO\r\n"}, {"input": "2\r\n80000 South\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n19999 South\r\n20001 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n500 South\r\n1000 North\r\n500 North\r\n", "output": "NO\r\n"}, {"input": "1\r\n400000 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n40000 South\r\n80000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n100 West\r\n100 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n40000 South\r\n40000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n30000 South\r\n10000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20000 South\r\n40000 North\r\n", "output": "NO\r\n"}, {"input": "10\r\n20000 South\r\n20000 North\r\n20000 South\r\n20000 North\r\n20000 South\r\n20000 North\r\n20000 South\r\n20000 North\r\n20000 South\r\n20000 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n40001 South\r\n40001 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n40001 South\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n50000 South\r\n50000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n30000 South\r\n30000 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n10000 South\r\n50000 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n15000 South\r\n15000 South\r\n15000 North\r\n15000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n50 South\r\n100 North\r\n50 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20001 South\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n5 South\r\n6 North\r\n1 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n20000 South\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 South\r\n20000 South\r\n1 North\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n30000 South\r\n30000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n2 North\r\n1 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n60000 South\r\n60000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n50000 South\r\n10000 North\r\n", "output": "NO\r\n"}, {"input": "1\r\n5 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20010 South\r\n19990 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n20000 South\r\n1 South\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n2 North\r\n39999 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n10 South\r\n20 North\r\n10 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n2 North\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n2000 South\r\n19000 South\r\n19000 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n15000 South\r\n15000 South\r\n15000 South\r\n15000 North\r\n15000 North\r\n15000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n1 North\r\n1 East\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 West\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n123456 West\r\n1 North\r\n", "output": "YES\r\n"}]
false
stdio
null
true
818/E
818
E
PyPy 3
TESTS
2
171
409,600
56769782
import math from math import gcd # A function to print all prime factors of # a given number n def primeFactors(n,seti): # Print the number of two's that divide n while n % 2 == 0: seti.append(2) n = n / 2 # n must be odd at this point # so a skip of 2 ( i = i + 2) can be used for i in range(3,int(math.sqrt(n))+1,2): # while i divides n , print i ad divide n while n % i== 0: seti.append(int(i)), n = n / i # Condition if n is a prime # number greater than 2 if n > 2: seti.append(int(n)), from collections import defaultdict n,k = map(int,input().split()) l = list(map(int,input().split())) min_hash = defaultdict(int) hash = defaultdict(int) seti = [] primeFactors(k,seti) for i in seti: min_hash[i]+=1 i = 0 j = 0 prod = 1 se = set() def solve(i,j): ans = 0 while i<n and j<n: flag = 0 bo = [] primeFactors(l[j],bo) if j not in se: for x in bo: hash[x]+=1 for x in min_hash.keys(): if hash[x]<min_hash[x]: flag = 1 break se.add(j) if flag == 0: ho = [] ans+=(n-j) primeFactors(l[i],ho) for x in ho: if x in hash: hash[x]-=1 i+=1 else: j+=1 return ans print(solve(i,j))
135
373
31,744,000
127711452
import bisect import sys input = sys.stdin.readline def prime_factorize(n): ans = [] for i in range(2, int(n ** (1 / 2)) + 1): while True: if n % i: break ans.append(i) n //= i if n == 1: break if not n == 1: ans.append(n) return ans n, k = map(int, input().split()) a = list(map(int, input().split())) s = list(set(prime_factorize(k))) l = len(s) cnt = [] for i in s: cnt0 = [0] * (n + 1) c = 0 for j in range(n): aj = a[j] while not aj % i: aj //= i c += 1 cnt0[j + 1] = c cnt.append(cnt0) t = [] for i in s: c = 0 while not k % i: k //= i c += 1 t.append(c) ans = 0 for i in range(1, n + 1): m = i for j in range(l): m = min(m, bisect.bisect_left(cnt[j], cnt[j][i] - t[j] + 0.5)) ans += m print(ans)
Educational Codeforces Round 24
ICPC
2,017
2
256
Card Game Again
Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number ai is written on the i-th card in the deck. After receiving the deck and the magic number, Vova removes x (possibly x = 0) cards from the top of the deck, y (possibly y = 0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards x + 1, x + 2, ... n - y - 1, n - y from the original deck. Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by k. So Vova received a deck (possibly not a valid one) and a number k, and now he wonders, how many ways are there to choose x and y so the deck he will get after removing x cards from the top and y cards from the bottom is valid?
The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers written on the cards.
Print the number of ways to choose x and y so the resulting deck is valid.
null
In the first example the possible values of x and y are: 1. x = 0, y = 0; 2. x = 1, y = 0; 3. x = 2, y = 0; 4. x = 0, y = 1.
[{"input": "3 4\n6 2 8", "output": "4"}, {"input": "3 6\n9 1 14", "output": "1"}]
1,900
["binary search", "data structures", "number theory", "two pointers"]
135
[{"input": "3 4\r\n6 2 8\r\n", "output": "4\r\n"}, {"input": "3 6\r\n9 1 14\r\n", "output": "1\r\n"}, {"input": "5 1\r\n1 3 1 3 1\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 5 5 5 5\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 4 4 4 4\r\n", "output": "15\r\n"}, {"input": "100 1\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": "5050\r\n"}, {"input": "100 1\r\n3 3 2 1 1 2 1 2 3 4 1 5 2 4 5 1 1 3 2 3 4 2 1 3 4 4 5 5 1 5 2 5 3 3 1 1 1 3 2 2 3 4 4 4 4 3 1 3 5 3 3 3 3 2 3 2 2 3 3 1 2 4 3 2 2 5 3 1 5 2 2 5 1 2 1 1 5 1 5 2 4 5 3 4 2 5 4 2 2 5 5 5 3 3 5 3 4 3 3 1\r\n", "output": "5050\r\n"}, {"input": "100 5\r\n4 4 3 2 4 4 1 2 2 1 5 3 2 5 5 3 2 3 4 5 2 2 3 4 2 4 3 1 2 3 5 5 1 3 3 5 2 3 3 4 1 3 1 5 4 4 2 1 5 1 4 4 1 5 1 1 5 5 5 4 1 3 1 2 3 2 4 5 5 1 3 4 3 3 1 2 2 4 1 5 1 1 2 4 4 4 5 5 5 3 4 3 3 3 3 2 1 1 5 5\r\n", "output": "4713\r\n"}, {"input": "100 6\r\n4 4 1 1 1 1 3 3 5 5 4 2 2 4 3 4 4 5 5 4 5 1 3 1 5 4 5 1 2 5 5 2 2 4 2 4 4 2 5 5 3 3 1 3 3 5 2 3 1 4 1 4 4 1 5 5 1 2 3 2 3 3 5 3 4 2 3 4 3 1 5 3 5 5 3 5 4 4 3 1 1 2 1 2 1 3 2 4 3 2 1 4 3 1 1 5 1 5 4 3\r\n", "output": "4580\r\n"}, {"input": "100 72\r\n8 8 7 9 6 1 4 5 3 7 5 10 5 4 1 3 4 1 3 1 6 6 4 5 4 5 6 1 10 7 9 1 6 10 6 6 9 3 3 4 5 9 4 9 8 1 5 9 3 7 1 8 5 2 1 1 7 7 7 6 6 4 2 9 10 2 8 3 1 1 4 8 5 9 7 10 9 4 2 3 7 7 6 7 8 5 1 3 8 5 1 8 9 10 3 7 1 8 10 5\r\n", "output": "4549\r\n"}, {"input": "100 72\r\n3 2 1 3 3 3 4 3 5 5 2 5 1 2 2 2 1 4 1 5 1 4 5 4 3 1 4 3 4 4 1 4 4 3 4 1 4 4 5 2 2 3 3 5 4 5 4 2 4 3 1 1 1 4 5 5 3 1 5 3 4 4 5 3 5 1 4 3 2 2 1 4 2 1 3 2 4 2 1 4 4 1 3 4 4 4 1 5 5 2 5 2 3 1 5 1 1 1 2 3\r\n", "output": "4123\r\n"}, {"input": "2 999634589\r\n31607 31627\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1\r\n", "output": "0\r\n"}, {"input": "1 3\r\n1\r\n", "output": "0\r\n"}, {"input": "1 4\r\n1\r\n", "output": "0\r\n"}, {"input": "1 5\r\n3\r\n", "output": "0\r\n"}, {"input": "1 6\r\n4\r\n", "output": "0\r\n"}, {"input": "1 7\r\n2\r\n", "output": "0\r\n"}, {"input": "1 8\r\n3\r\n", "output": "0\r\n"}, {"input": "1 9\r\n5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n3\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n", "output": "3\r\n"}, {"input": "2 2\r\n2 2\r\n", "output": "3\r\n"}, {"input": "2 3\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2 4\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2 5\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 6\r\n2 1\r\n", "output": "0\r\n"}, {"input": "2 7\r\n1 4\r\n", "output": "0\r\n"}, {"input": "2 8\r\n5 3\r\n", "output": "0\r\n"}, {"input": "2 9\r\n2 2\r\n", "output": "0\r\n"}, {"input": "2 10\r\n6 1\r\n", "output": "0\r\n"}, {"input": "3 1\r\n1 1 1\r\n", "output": "6\r\n"}, {"input": "3 2\r\n2 2 1\r\n", "output": "5\r\n"}, {"input": "3 3\r\n2 1 2\r\n", "output": "0\r\n"}, {"input": "3 4\r\n2 2 2\r\n", "output": "3\r\n"}, {"input": "3 5\r\n1 1 2\r\n", "output": "0\r\n"}, {"input": "3 6\r\n4 3 2\r\n", "output": "3\r\n"}, {"input": "3 7\r\n3 4 1\r\n", "output": "0\r\n"}, {"input": "3 8\r\n5 1 4\r\n", "output": "0\r\n"}, {"input": "3 9\r\n3 2 1\r\n", "output": "0\r\n"}, {"input": "3 10\r\n6 5 5\r\n", "output": "2\r\n"}, {"input": "4 1\r\n1 1 1 1\r\n", "output": "10\r\n"}, {"input": "4 2\r\n2 2 1 2\r\n", "output": "9\r\n"}, {"input": "4 3\r\n2 1 1 1\r\n", "output": "0\r\n"}, {"input": "4 4\r\n2 2 1 1\r\n", "output": "3\r\n"}, {"input": "4 5\r\n2 3 2 1\r\n", "output": "0\r\n"}, {"input": "4 6\r\n1 1 3 3\r\n", "output": "0\r\n"}, {"input": "4 7\r\n1 1 2 2\r\n", "output": "0\r\n"}, {"input": "4 8\r\n5 4 5 5\r\n", "output": "0\r\n"}, {"input": "4 9\r\n1 1 4 2\r\n", "output": "0\r\n"}, {"input": "4 10\r\n2 6 2 1\r\n", "output": "0\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n", "output": "15\r\n"}, {"input": "5 2\r\n2 2 1 2 1\r\n", "output": "13\r\n"}, {"input": "5 3\r\n2 1 1 2 1\r\n", "output": "0\r\n"}, {"input": "5 4\r\n2 2 1 3 1\r\n", "output": "4\r\n"}, {"input": "5 5\r\n2 3 1 1 3\r\n", "output": "0\r\n"}, {"input": "5 6\r\n3 4 3 4 3\r\n", "output": "10\r\n"}, {"input": "5 7\r\n3 1 3 2 4\r\n", "output": "0\r\n"}, {"input": "5 8\r\n2 2 3 3 1\r\n", "output": "0\r\n"}, {"input": "5 9\r\n3 1 3 3 4\r\n", "output": "7\r\n"}, {"input": "5 10\r\n3 6 6 1 5\r\n", "output": "3\r\n"}, {"input": "6 1\r\n1 1 1 1 1 1\r\n", "output": "21\r\n"}, {"input": "6 2\r\n1 2 2 1 1 1\r\n", "output": "14\r\n"}, {"input": "6 3\r\n2 2 2 2 1 2\r\n", "output": "0\r\n"}, {"input": "6 4\r\n1 3 3 3 3 2\r\n", "output": "0\r\n"}, {"input": "6 5\r\n2 3 3 2 1 2\r\n", "output": "0\r\n"}, {"input": "6 6\r\n1 2 4 1 4 4\r\n", "output": "0\r\n"}, {"input": "6 7\r\n2 2 4 3 2 1\r\n", "output": "0\r\n"}, {"input": "6 8\r\n3 2 3 5 5 3\r\n", "output": "0\r\n"}, {"input": "6 9\r\n1 4 1 2 1 1\r\n", "output": "0\r\n"}, {"input": "6 10\r\n1 2 5 6 6 6\r\n", "output": "11\r\n"}, {"input": "7 1\r\n1 1 1 1 1 1 1\r\n", "output": "28\r\n"}, {"input": "7 2\r\n1 1 2 2 2 2 1\r\n", "output": "24\r\n"}, {"input": "7 3\r\n2 2 1 1 2 2 2\r\n", "output": "0\r\n"}, {"input": "7 4\r\n3 2 1 2 1 1 1\r\n", "output": "8\r\n"}, {"input": "7 5\r\n2 3 3 3 2 3 2\r\n", "output": "0\r\n"}, {"input": "7 6\r\n3 4 4 1 4 3 2\r\n", "output": "15\r\n"}, {"input": "7 7\r\n4 2 4 4 1 4 4\r\n", "output": "0\r\n"}, {"input": "7 8\r\n4 4 2 4 2 5 3\r\n", "output": "18\r\n"}, {"input": "7 9\r\n2 1 3 4 4 5 4\r\n", "output": "0\r\n"}, {"input": "7 10\r\n6 3 3 5 3 6 1\r\n", "output": "10\r\n"}, {"input": "8 1\r\n1 1 1 1 1 1 1 1\r\n", "output": "36\r\n"}, {"input": "8 2\r\n1 1 1 1 1 1 1 2\r\n", "output": "8\r\n"}, {"input": "8 3\r\n1 1 2 2 1 1 2 2\r\n", "output": "0\r\n"}, {"input": "8 4\r\n2 3 2 3 3 3 2 3\r\n", "output": "10\r\n"}, {"input": "8 5\r\n1 3 1 2 2 2 1 3\r\n", "output": "0\r\n"}, {"input": "8 6\r\n4 2 4 2 1 2 1 4\r\n", "output": "0\r\n"}, {"input": "8 7\r\n2 2 1 4 4 4 2 2\r\n", "output": "0\r\n"}, {"input": "8 8\r\n5 2 1 2 4 2 2 4\r\n", "output": "21\r\n"}, {"input": "8 9\r\n4 4 2 2 5 5 4 1\r\n", "output": "0\r\n"}, {"input": "8 10\r\n2 1 4 4 3 4 4 6\r\n", "output": "0\r\n"}, {"input": "9 1\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "45\r\n"}, {"input": "9 2\r\n1 1 1 2 1 1 2 2 2\r\n", "output": "36\r\n"}, {"input": "9 3\r\n1 1 1 2 2 1 1 2 1\r\n", "output": "0\r\n"}, {"input": "9 4\r\n1 1 2 1 2 1 1 1 1\r\n", "output": "15\r\n"}, {"input": "9 5\r\n3 2 3 2 3 1 1 3 2\r\n", "output": "0\r\n"}, {"input": "9 6\r\n2 1 1 3 2 4 1 2 2\r\n", "output": "21\r\n"}, {"input": "9 7\r\n4 3 2 1 2 3 3 4 4\r\n", "output": "0\r\n"}, {"input": "9 8\r\n5 5 2 1 3 1 3 1 3\r\n", "output": "0\r\n"}, {"input": "9 9\r\n2 4 1 4 4 3 3 4 1\r\n", "output": "18\r\n"}, {"input": "9 10\r\n4 3 2 5 2 2 2 2 6\r\n", "output": "23\r\n"}, {"input": "10 1\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "55\r\n"}, {"input": "10 2\r\n2 2 2 2 2 2 2 1 2 1\r\n", "output": "53\r\n"}, {"input": "10 3\r\n2 2 1 1 2 2 2 2 1 2\r\n", "output": "0\r\n"}, {"input": "10 4\r\n1 1 2 3 3 1 2 2 2 3\r\n", "output": "26\r\n"}, {"input": "10 5\r\n3 3 2 2 3 1 1 1 3 1\r\n", "output": "0\r\n"}, {"input": "10 6\r\n4 4 4 3 2 1 1 1 2 4\r\n", "output": "27\r\n"}, {"input": "10 7\r\n4 2 2 2 3 3 2 4 4 3\r\n", "output": "0\r\n"}, {"input": "10 8\r\n5 4 1 4 3 2 1 2 3 3\r\n", "output": "24\r\n"}, {"input": "10 9\r\n1 2 3 4 5 2 3 5 5 4\r\n", "output": "12\r\n"}, {"input": "10 10\r\n5 3 2 5 1 2 5 1 5 1\r\n", "output": "35\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "1 100000000\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1000000000\r\n", "output": "1\r\n"}]
false
stdio
null
true
797/B
797
B
Python 3
TESTS
16
61
0
117353977
# cook your dish here n=int(input()) ar=list(map(int,input().split())) se=0 so=0 minop=10000 maxon=-10000 cnt=0 for i in range(n): if(ar[i]%2==0 and ar[i]>0): se+=ar[i] elif(ar[i]%2 and ar[i]>0): so+=ar[i] minop=min(minop,ar[i]) cnt+=1 elif(ar[i]%2 and ar[i]<0): maxon=max(maxon,ar[i]) if(cnt==0): print(se+maxon) elif(cnt%2==0): print(se+so-minop) else: print(se+so)
126
93
7,270,400
132392463
n = int(input()) sum_all_pos = 0 numbers = list(map(int, input().split())) for num in numbers: if num > 0: # Directly return all positive numbers sum if odd sum_all_pos += num def isOdd(val): return val % 2 if isOdd(sum_all_pos): print(sum_all_pos) else: # even - odd = odd # Removes the minimum positive odd number or add the maximum negative odd = [] for num in numbers: if isOdd(num): odd.append(abs(num)) print(sum_all_pos - min(odd))
Educational Codeforces Round 19
ICPC
2,017
1
256
Odd sum
You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence.
The first line contains integer number n (1 ≤ n ≤ 105). The second line contains n integer numbers a1, a2, ..., an ( - 104 ≤ ai ≤ 104). The sequence contains at least one subsequence with odd sum.
Print sum of resulting subseqeuence.
null
In the first example sum of the second and the fourth elements is 3.
[{"input": "4\n-2 2 -3 1", "output": "3"}, {"input": "3\n2 -5 -3", "output": "-1"}]
1,400
["dp", "greedy", "implementation"]
126
[{"input": "4\r\n-2 2 -3 1\r\n", "output": "3\r\n"}, {"input": "3\r\n2 -5 -3\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "15\r\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046\r\n", "output": "53507\r\n"}, {"input": "2\r\n-5439 -6705\r\n", "output": "-5439\r\n"}, {"input": "2\r\n2850 6843\r\n", "output": "9693\r\n"}, {"input": "2\r\n144 9001\r\n", "output": "9145\r\n"}, {"input": "10\r\n7535 -819 2389 4933 5495 4887 -5181 -9355 7955 5757\r\n", "output": "38951\r\n"}, {"input": "10\r\n-9169 -1574 3580 -8579 -7177 -3216 7490 3470 3465 -1197\r\n", "output": "18005\r\n"}, {"input": "10\r\n941 7724 2220 -4704 -8374 -8249 7606 9502 612 -9097\r\n", "output": "28605\r\n"}, {"input": "10\r\n4836 -2331 -3456 2312 -1574 3134 -670 -204 512 -5504\r\n", "output": "8463\r\n"}, {"input": "10\r\n1184 5136 1654 3254 6576 6900 6468 327 179 7114\r\n", "output": "38613\r\n"}, {"input": "10\r\n-2152 -1776 -1810 -9046 -6090 -2324 -8716 -6103 -787 -812\r\n", "output": "-787\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "3\r\n"}, {"input": "5\r\n5 5 5 3 -1\r\n", "output": "17\r\n"}, {"input": "5\r\n-1 -2 5 3 0\r\n", "output": "7\r\n"}, {"input": "5\r\n-3 -2 5 -1 3\r\n", "output": "7\r\n"}, {"input": "3\r\n-2 2 -1\r\n", "output": "1\r\n"}, {"input": "5\r\n5 0 7 -2 3\r\n", "output": "15\r\n"}, {"input": "2\r\n-2 -5\r\n", "output": "-5\r\n"}, {"input": "3\r\n-1 -3 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 -1 0 -3 -2\r\n", "output": "1\r\n"}, {"input": "4\r\n2 3 0 5\r\n", "output": "7\r\n"}, {"input": "5\r\n-5 3 -2 2 5\r\n", "output": "7\r\n"}, {"input": "59\r\n8593 5929 3016 -859 4366 -6842 8435 -3910 -2458 -8503 -3612 -9793 -5360 -9791 -362 -7180 727 -6245 -8869 -7316 8214 -7944 7098 3788 -5436 -6626 -1131 -2410 -5647 -7981 263 -5879 8786 709 6489 5316 -4039 4909 -4340 7979 -89 9844 -906 172 -7674 -3371 -6828 9505 3284 5895 3646 6680 -1255 3635 -9547 -5104 -1435 -7222 2244\r\n", "output": "129433\r\n"}, {"input": "17\r\n-6170 2363 6202 -9142 7889 779 2843 -5089 2313 -3952 1843 5171 462 -3673 5098 -2519 9565\r\n", "output": "43749\r\n"}, {"input": "26\r\n-8668 9705 1798 -1766 9644 3688 8654 -3077 -5462 2274 6739 2732 3635 -4745 -9144 -9175 -7488 -2010 1637 1118 8987 1597 -2873 -5153 -8062 146\r\n", "output": "60757\r\n"}, {"input": "51\r\n8237 -7239 -3545 -6059 -5110 4066 -4148 -7641 -5797 -994 963 1144 -2785 -8765 -1216 5410 1508 -6312 -6313 -680 -7657 4579 -6898 7379 2015 -5087 -5417 -6092 3819 -9101 989 -8380 9161 -7519 -9314 -3838 7160 5180 567 -1606 -3842 -9665 -2266 1296 -8417 -3976 7436 -2075 -441 -4565 3313\r\n", "output": "73781\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "2\r\n-2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n", "output": "5\r\n"}, {"input": "2\r\n1 2\r\n", "output": "3\r\n"}, {"input": "2\r\n-1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n0 -1\r\n", "output": "-1\r\n"}, {"input": "2\r\n2 1\r\n", "output": "3\r\n"}, {"input": "2\r\n3 0\r\n", "output": "3\r\n"}, {"input": "2\r\n0 -1\r\n", "output": "-1\r\n"}, {"input": "3\r\n-3 1 -1\r\n", "output": "1\r\n"}, {"input": "3\r\n3 -1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "5\r\n"}, {"input": "3\r\n-1 0 1\r\n", "output": "1\r\n"}, {"input": "3\r\n-3 -3 -2\r\n", "output": "-3\r\n"}, {"input": "3\r\n3 -1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 -1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n-2 -2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n0 -1 -3 -4\r\n", "output": "-1\r\n"}, {"input": "4\r\n5 3 2 1\r\n", "output": "11\r\n"}, {"input": "4\r\n-1 -2 4 -2\r\n", "output": "3\r\n"}, {"input": "4\r\n-1 -3 0 -3\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 -4 -3 -4\r\n", "output": "1\r\n"}, {"input": "4\r\n5 3 3 4\r\n", "output": "15\r\n"}, {"input": "4\r\n-1 -3 -1 2\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 -1 -4\r\n", "output": "5\r\n"}, {"input": "5\r\n-5 -4 -3 -5 2\r\n", "output": "-1\r\n"}, {"input": "5\r\n5 5 1 2 -2\r\n", "output": "13\r\n"}, {"input": "5\r\n-2 -1 -5 -1 4\r\n", "output": "3\r\n"}, {"input": "5\r\n-5 -5 -4 4 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 -3 -1 -4 -5\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 3\r\n", "output": "13\r\n"}, {"input": "5\r\n0 -2 -5 3 3\r\n", "output": "3\r\n"}, {"input": "5\r\n4 -2 -2 -3 0\r\n", "output": "1\r\n"}, {"input": "6\r\n6 7 -1 1 5 -1\r\n", "output": "19\r\n"}, {"input": "6\r\n-1 7 2 -3 -4 -5\r\n", "output": "9\r\n"}, {"input": "6\r\n0 -1 -3 -5 2 -6\r\n", "output": "1\r\n"}, {"input": "6\r\n4 -1 0 3 6 1\r\n", "output": "13\r\n"}, {"input": "6\r\n5 3 3 4 4 -3\r\n", "output": "19\r\n"}, {"input": "6\r\n0 -3 5 -4 5 -4\r\n", "output": "7\r\n"}, {"input": "6\r\n-5 -3 1 -1 -5 -3\r\n", "output": "1\r\n"}, {"input": "6\r\n-2 1 3 -2 7 4\r\n", "output": "15\r\n"}, {"input": "7\r\n0 7 6 2 7 0 6\r\n", "output": "21\r\n"}, {"input": "7\r\n6 -6 -1 -5 7 1 7\r\n", "output": "21\r\n"}, {"input": "7\r\n2 3 -5 0 -4 0 -4\r\n", "output": "5\r\n"}, {"input": "7\r\n-6 3 -3 -1 -6 -6 -5\r\n", "output": "3\r\n"}, {"input": "7\r\n7 6 3 2 4 2 0\r\n", "output": "21\r\n"}, {"input": "7\r\n-2 3 -3 4 4 0 -1\r\n", "output": "11\r\n"}, {"input": "7\r\n-5 -7 4 0 5 -3 -5\r\n", "output": "9\r\n"}, {"input": "7\r\n-3 -5 -4 1 3 -4 -7\r\n", "output": "3\r\n"}, {"input": "8\r\n5 2 4 5 7 -2 7 3\r\n", "output": "33\r\n"}, {"input": "8\r\n-8 -3 -1 3 -8 -4 -4 4\r\n", "output": "7\r\n"}, {"input": "8\r\n-6 -7 -7 -5 -4 -9 -2 -7\r\n", "output": "-5\r\n"}, {"input": "8\r\n8 7 6 8 3 4 8 -2\r\n", "output": "41\r\n"}, {"input": "8\r\n6 7 0 -6 6 5 4 7\r\n", "output": "35\r\n"}, {"input": "8\r\n0 -7 -5 -5 5 -1 -8 -7\r\n", "output": "5\r\n"}, {"input": "8\r\n1 -6 -5 7 -3 -4 2 -2\r\n", "output": "9\r\n"}, {"input": "8\r\n1 -8 -6 -6 -6 -7 -5 -1\r\n", "output": "1\r\n"}, {"input": "9\r\n-3 -1 4 4 8 -8 -5 9 -2\r\n", "output": "25\r\n"}, {"input": "9\r\n-9 -1 3 -2 -7 2 -9 -1 -4\r\n", "output": "5\r\n"}, {"input": "9\r\n-6 -9 -3 -8 -5 2 -6 0 -5\r\n", "output": "-1\r\n"}, {"input": "9\r\n5 4 3 3 6 7 8 5 9\r\n", "output": "47\r\n"}, {"input": "9\r\n5 3 9 1 5 2 -3 7 0\r\n", "output": "31\r\n"}, {"input": "9\r\n-3 -9 -1 -7 5 6 -4 -6 -6\r\n", "output": "11\r\n"}, {"input": "9\r\n-6 -5 6 -5 -2 0 1 2 -9\r\n", "output": "9\r\n"}, {"input": "9\r\n8 3 6 1 -3 5 2 9 1\r\n", "output": "35\r\n"}, {"input": "10\r\n-6 -4 -7 -1 -9 -10 -10 1 0 -3\r\n", "output": "1\r\n"}, {"input": "10\r\n-2 -10 -5 -6 -10 -3 -6 -3 -8 -8\r\n", "output": "-3\r\n"}, {"input": "10\r\n8 5 9 2 3 3 -6 1 -1 8\r\n", "output": "39\r\n"}, {"input": "10\r\n2 10 -7 6 -1 -1 7 -9 -4 -6\r\n", "output": "25\r\n"}, {"input": "10\r\n-10 -2 -2 -1 -10 -7 1 0 -4 -5\r\n", "output": "1\r\n"}, {"input": "10\r\n4 3 10 -2 -1 0 10 6 7 0\r\n", "output": "39\r\n"}, {"input": "10\r\n-2 6 6 5 0 10 6 7 -1 1\r\n", "output": "41\r\n"}, {"input": "10\r\n-10 2 8 -6 -1 -5 1 -10 -10 -1\r\n", "output": "11\r\n"}]
false
stdio
null
true
797/B
797
B
PyPy 3
TESTS
16
92
0
153709682
n = int(input()) a = [int(x) for x in input().split()] odd = [] even = 0 m = -10**8 for x in a: if x % 2 == 0 and x > 0: even += x if x % 2 == 1 and x > 0: odd.append(x) if x % 2 == 1 and x > m: m = x if len(odd) > 0: if len(odd) % 2 == 1: print(sum(odd) + even) else: odd.sort() print(sum(odd[1:]) + even) else: print(m + even)
126
93
13,107,200
204420316
n = int(input()) a = list(map(int, input().split())) count_nech = 0 prev_nech = None ans = 0 a.sort(reverse=True) for i in a: if i > 0: if i % 2 == 0: ans += i else: if count_nech == 0: ans += i elif count_nech % 2 == 0: ans += prev_nech ans += i prev_nech = None else: prev_nech = i count_nech += 1 if i < 0: if i % 2 != 0: if count_nech == 0: ans += i break if prev_nech is not None and i + prev_nech > 0: ans += i + prev_nech break print(ans)
Educational Codeforces Round 19
ICPC
2,017
1
256
Odd sum
You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence.
The first line contains integer number n (1 ≤ n ≤ 105). The second line contains n integer numbers a1, a2, ..., an ( - 104 ≤ ai ≤ 104). The sequence contains at least one subsequence with odd sum.
Print sum of resulting subseqeuence.
null
In the first example sum of the second and the fourth elements is 3.
[{"input": "4\n-2 2 -3 1", "output": "3"}, {"input": "3\n2 -5 -3", "output": "-1"}]
1,400
["dp", "greedy", "implementation"]
126
[{"input": "4\r\n-2 2 -3 1\r\n", "output": "3\r\n"}, {"input": "3\r\n2 -5 -3\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "15\r\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046\r\n", "output": "53507\r\n"}, {"input": "2\r\n-5439 -6705\r\n", "output": "-5439\r\n"}, {"input": "2\r\n2850 6843\r\n", "output": "9693\r\n"}, {"input": "2\r\n144 9001\r\n", "output": "9145\r\n"}, {"input": "10\r\n7535 -819 2389 4933 5495 4887 -5181 -9355 7955 5757\r\n", "output": "38951\r\n"}, {"input": "10\r\n-9169 -1574 3580 -8579 -7177 -3216 7490 3470 3465 -1197\r\n", "output": "18005\r\n"}, {"input": "10\r\n941 7724 2220 -4704 -8374 -8249 7606 9502 612 -9097\r\n", "output": "28605\r\n"}, {"input": "10\r\n4836 -2331 -3456 2312 -1574 3134 -670 -204 512 -5504\r\n", "output": "8463\r\n"}, {"input": "10\r\n1184 5136 1654 3254 6576 6900 6468 327 179 7114\r\n", "output": "38613\r\n"}, {"input": "10\r\n-2152 -1776 -1810 -9046 -6090 -2324 -8716 -6103 -787 -812\r\n", "output": "-787\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "3\r\n"}, {"input": "5\r\n5 5 5 3 -1\r\n", "output": "17\r\n"}, {"input": "5\r\n-1 -2 5 3 0\r\n", "output": "7\r\n"}, {"input": "5\r\n-3 -2 5 -1 3\r\n", "output": "7\r\n"}, {"input": "3\r\n-2 2 -1\r\n", "output": "1\r\n"}, {"input": "5\r\n5 0 7 -2 3\r\n", "output": "15\r\n"}, {"input": "2\r\n-2 -5\r\n", "output": "-5\r\n"}, {"input": "3\r\n-1 -3 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 -1 0 -3 -2\r\n", "output": "1\r\n"}, {"input": "4\r\n2 3 0 5\r\n", "output": "7\r\n"}, {"input": "5\r\n-5 3 -2 2 5\r\n", "output": "7\r\n"}, {"input": "59\r\n8593 5929 3016 -859 4366 -6842 8435 -3910 -2458 -8503 -3612 -9793 -5360 -9791 -362 -7180 727 -6245 -8869 -7316 8214 -7944 7098 3788 -5436 -6626 -1131 -2410 -5647 -7981 263 -5879 8786 709 6489 5316 -4039 4909 -4340 7979 -89 9844 -906 172 -7674 -3371 -6828 9505 3284 5895 3646 6680 -1255 3635 -9547 -5104 -1435 -7222 2244\r\n", "output": "129433\r\n"}, {"input": "17\r\n-6170 2363 6202 -9142 7889 779 2843 -5089 2313 -3952 1843 5171 462 -3673 5098 -2519 9565\r\n", "output": "43749\r\n"}, {"input": "26\r\n-8668 9705 1798 -1766 9644 3688 8654 -3077 -5462 2274 6739 2732 3635 -4745 -9144 -9175 -7488 -2010 1637 1118 8987 1597 -2873 -5153 -8062 146\r\n", "output": "60757\r\n"}, {"input": "51\r\n8237 -7239 -3545 -6059 -5110 4066 -4148 -7641 -5797 -994 963 1144 -2785 -8765 -1216 5410 1508 -6312 -6313 -680 -7657 4579 -6898 7379 2015 -5087 -5417 -6092 3819 -9101 989 -8380 9161 -7519 -9314 -3838 7160 5180 567 -1606 -3842 -9665 -2266 1296 -8417 -3976 7436 -2075 -441 -4565 3313\r\n", "output": "73781\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "2\r\n-2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n", "output": "5\r\n"}, {"input": "2\r\n1 2\r\n", "output": "3\r\n"}, {"input": "2\r\n-1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n0 -1\r\n", "output": "-1\r\n"}, {"input": "2\r\n2 1\r\n", "output": "3\r\n"}, {"input": "2\r\n3 0\r\n", "output": "3\r\n"}, {"input": "2\r\n0 -1\r\n", "output": "-1\r\n"}, {"input": "3\r\n-3 1 -1\r\n", "output": "1\r\n"}, {"input": "3\r\n3 -1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "5\r\n"}, {"input": "3\r\n-1 0 1\r\n", "output": "1\r\n"}, {"input": "3\r\n-3 -3 -2\r\n", "output": "-3\r\n"}, {"input": "3\r\n3 -1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 -1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n-2 -2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n0 -1 -3 -4\r\n", "output": "-1\r\n"}, {"input": "4\r\n5 3 2 1\r\n", "output": "11\r\n"}, {"input": "4\r\n-1 -2 4 -2\r\n", "output": "3\r\n"}, {"input": "4\r\n-1 -3 0 -3\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 -4 -3 -4\r\n", "output": "1\r\n"}, {"input": "4\r\n5 3 3 4\r\n", "output": "15\r\n"}, {"input": "4\r\n-1 -3 -1 2\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 -1 -4\r\n", "output": "5\r\n"}, {"input": "5\r\n-5 -4 -3 -5 2\r\n", "output": "-1\r\n"}, {"input": "5\r\n5 5 1 2 -2\r\n", "output": "13\r\n"}, {"input": "5\r\n-2 -1 -5 -1 4\r\n", "output": "3\r\n"}, {"input": "5\r\n-5 -5 -4 4 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 -3 -1 -4 -5\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 3\r\n", "output": "13\r\n"}, {"input": "5\r\n0 -2 -5 3 3\r\n", "output": "3\r\n"}, {"input": "5\r\n4 -2 -2 -3 0\r\n", "output": "1\r\n"}, {"input": "6\r\n6 7 -1 1 5 -1\r\n", "output": "19\r\n"}, {"input": "6\r\n-1 7 2 -3 -4 -5\r\n", "output": "9\r\n"}, {"input": "6\r\n0 -1 -3 -5 2 -6\r\n", "output": "1\r\n"}, {"input": "6\r\n4 -1 0 3 6 1\r\n", "output": "13\r\n"}, {"input": "6\r\n5 3 3 4 4 -3\r\n", "output": "19\r\n"}, {"input": "6\r\n0 -3 5 -4 5 -4\r\n", "output": "7\r\n"}, {"input": "6\r\n-5 -3 1 -1 -5 -3\r\n", "output": "1\r\n"}, {"input": "6\r\n-2 1 3 -2 7 4\r\n", "output": "15\r\n"}, {"input": "7\r\n0 7 6 2 7 0 6\r\n", "output": "21\r\n"}, {"input": "7\r\n6 -6 -1 -5 7 1 7\r\n", "output": "21\r\n"}, {"input": "7\r\n2 3 -5 0 -4 0 -4\r\n", "output": "5\r\n"}, {"input": "7\r\n-6 3 -3 -1 -6 -6 -5\r\n", "output": "3\r\n"}, {"input": "7\r\n7 6 3 2 4 2 0\r\n", "output": "21\r\n"}, {"input": "7\r\n-2 3 -3 4 4 0 -1\r\n", "output": "11\r\n"}, {"input": "7\r\n-5 -7 4 0 5 -3 -5\r\n", "output": "9\r\n"}, {"input": "7\r\n-3 -5 -4 1 3 -4 -7\r\n", "output": "3\r\n"}, {"input": "8\r\n5 2 4 5 7 -2 7 3\r\n", "output": "33\r\n"}, {"input": "8\r\n-8 -3 -1 3 -8 -4 -4 4\r\n", "output": "7\r\n"}, {"input": "8\r\n-6 -7 -7 -5 -4 -9 -2 -7\r\n", "output": "-5\r\n"}, {"input": "8\r\n8 7 6 8 3 4 8 -2\r\n", "output": "41\r\n"}, {"input": "8\r\n6 7 0 -6 6 5 4 7\r\n", "output": "35\r\n"}, {"input": "8\r\n0 -7 -5 -5 5 -1 -8 -7\r\n", "output": "5\r\n"}, {"input": "8\r\n1 -6 -5 7 -3 -4 2 -2\r\n", "output": "9\r\n"}, {"input": "8\r\n1 -8 -6 -6 -6 -7 -5 -1\r\n", "output": "1\r\n"}, {"input": "9\r\n-3 -1 4 4 8 -8 -5 9 -2\r\n", "output": "25\r\n"}, {"input": "9\r\n-9 -1 3 -2 -7 2 -9 -1 -4\r\n", "output": "5\r\n"}, {"input": "9\r\n-6 -9 -3 -8 -5 2 -6 0 -5\r\n", "output": "-1\r\n"}, {"input": "9\r\n5 4 3 3 6 7 8 5 9\r\n", "output": "47\r\n"}, {"input": "9\r\n5 3 9 1 5 2 -3 7 0\r\n", "output": "31\r\n"}, {"input": "9\r\n-3 -9 -1 -7 5 6 -4 -6 -6\r\n", "output": "11\r\n"}, {"input": "9\r\n-6 -5 6 -5 -2 0 1 2 -9\r\n", "output": "9\r\n"}, {"input": "9\r\n8 3 6 1 -3 5 2 9 1\r\n", "output": "35\r\n"}, {"input": "10\r\n-6 -4 -7 -1 -9 -10 -10 1 0 -3\r\n", "output": "1\r\n"}, {"input": "10\r\n-2 -10 -5 -6 -10 -3 -6 -3 -8 -8\r\n", "output": "-3\r\n"}, {"input": "10\r\n8 5 9 2 3 3 -6 1 -1 8\r\n", "output": "39\r\n"}, {"input": "10\r\n2 10 -7 6 -1 -1 7 -9 -4 -6\r\n", "output": "25\r\n"}, {"input": "10\r\n-10 -2 -2 -1 -10 -7 1 0 -4 -5\r\n", "output": "1\r\n"}, {"input": "10\r\n4 3 10 -2 -1 0 10 6 7 0\r\n", "output": "39\r\n"}, {"input": "10\r\n-2 6 6 5 0 10 6 7 -1 1\r\n", "output": "41\r\n"}, {"input": "10\r\n-10 2 8 -6 -1 -5 1 -10 -10 -1\r\n", "output": "11\r\n"}]
false
stdio
null
true
797/B
797
B
PyPy 3
TESTS
16
93
0
117496190
from sys import stdin input = stdin.readline n = int(input()) a = [int(x) for x in input().split()] ans = 0 number_odd = 0 biggest_odd = float("-inf") smallest_odd = float("inf") for i in a: if i % 2 == 0: if i > 0: ans += i else: if i > 0: number_odd += 1 smallest_odd = min(smallest_odd, i) ans += i biggest_odd = max(biggest_odd, i) if number_odd == 0: ans += biggest_odd elif number_odd % 2 == 0: ans -= smallest_odd print(ans)
126
93
13,312,000
219027901
n = int(input()) a = [int(_) for _ in input().split()] c = [] b = [] ans = 0 for elem in a: if elem>=0: ans+=elem if elem%2!=0: if elem>0: c.append(elem) else: b.append(elem) if len(c)%2!=0: print(ans) else: if len(b)==0: print(ans-min(c)) elif len(c)==0: print(ans+max(b)) else: print(ans-min(-max(b),min(c)))
Educational Codeforces Round 19
ICPC
2,017
1
256
Odd sum
You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence.
The first line contains integer number n (1 ≤ n ≤ 105). The second line contains n integer numbers a1, a2, ..., an ( - 104 ≤ ai ≤ 104). The sequence contains at least one subsequence with odd sum.
Print sum of resulting subseqeuence.
null
In the first example sum of the second and the fourth elements is 3.
[{"input": "4\n-2 2 -3 1", "output": "3"}, {"input": "3\n2 -5 -3", "output": "-1"}]
1,400
["dp", "greedy", "implementation"]
126
[{"input": "4\r\n-2 2 -3 1\r\n", "output": "3\r\n"}, {"input": "3\r\n2 -5 -3\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "15\r\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046\r\n", "output": "53507\r\n"}, {"input": "2\r\n-5439 -6705\r\n", "output": "-5439\r\n"}, {"input": "2\r\n2850 6843\r\n", "output": "9693\r\n"}, {"input": "2\r\n144 9001\r\n", "output": "9145\r\n"}, {"input": "10\r\n7535 -819 2389 4933 5495 4887 -5181 -9355 7955 5757\r\n", "output": "38951\r\n"}, {"input": "10\r\n-9169 -1574 3580 -8579 -7177 -3216 7490 3470 3465 -1197\r\n", "output": "18005\r\n"}, {"input": "10\r\n941 7724 2220 -4704 -8374 -8249 7606 9502 612 -9097\r\n", "output": "28605\r\n"}, {"input": "10\r\n4836 -2331 -3456 2312 -1574 3134 -670 -204 512 -5504\r\n", "output": "8463\r\n"}, {"input": "10\r\n1184 5136 1654 3254 6576 6900 6468 327 179 7114\r\n", "output": "38613\r\n"}, {"input": "10\r\n-2152 -1776 -1810 -9046 -6090 -2324 -8716 -6103 -787 -812\r\n", "output": "-787\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "3\r\n"}, {"input": "5\r\n5 5 5 3 -1\r\n", "output": "17\r\n"}, {"input": "5\r\n-1 -2 5 3 0\r\n", "output": "7\r\n"}, {"input": "5\r\n-3 -2 5 -1 3\r\n", "output": "7\r\n"}, {"input": "3\r\n-2 2 -1\r\n", "output": "1\r\n"}, {"input": "5\r\n5 0 7 -2 3\r\n", "output": "15\r\n"}, {"input": "2\r\n-2 -5\r\n", "output": "-5\r\n"}, {"input": "3\r\n-1 -3 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 -1 0 -3 -2\r\n", "output": "1\r\n"}, {"input": "4\r\n2 3 0 5\r\n", "output": "7\r\n"}, {"input": "5\r\n-5 3 -2 2 5\r\n", "output": "7\r\n"}, {"input": "59\r\n8593 5929 3016 -859 4366 -6842 8435 -3910 -2458 -8503 -3612 -9793 -5360 -9791 -362 -7180 727 -6245 -8869 -7316 8214 -7944 7098 3788 -5436 -6626 -1131 -2410 -5647 -7981 263 -5879 8786 709 6489 5316 -4039 4909 -4340 7979 -89 9844 -906 172 -7674 -3371 -6828 9505 3284 5895 3646 6680 -1255 3635 -9547 -5104 -1435 -7222 2244\r\n", "output": "129433\r\n"}, {"input": "17\r\n-6170 2363 6202 -9142 7889 779 2843 -5089 2313 -3952 1843 5171 462 -3673 5098 -2519 9565\r\n", "output": "43749\r\n"}, {"input": "26\r\n-8668 9705 1798 -1766 9644 3688 8654 -3077 -5462 2274 6739 2732 3635 -4745 -9144 -9175 -7488 -2010 1637 1118 8987 1597 -2873 -5153 -8062 146\r\n", "output": "60757\r\n"}, {"input": "51\r\n8237 -7239 -3545 -6059 -5110 4066 -4148 -7641 -5797 -994 963 1144 -2785 -8765 -1216 5410 1508 -6312 -6313 -680 -7657 4579 -6898 7379 2015 -5087 -5417 -6092 3819 -9101 989 -8380 9161 -7519 -9314 -3838 7160 5180 567 -1606 -3842 -9665 -2266 1296 -8417 -3976 7436 -2075 -441 -4565 3313\r\n", "output": "73781\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "2\r\n-2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n", "output": "5\r\n"}, {"input": "2\r\n1 2\r\n", "output": "3\r\n"}, {"input": "2\r\n-1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n0 -1\r\n", "output": "-1\r\n"}, {"input": "2\r\n2 1\r\n", "output": "3\r\n"}, {"input": "2\r\n3 0\r\n", "output": "3\r\n"}, {"input": "2\r\n0 -1\r\n", "output": "-1\r\n"}, {"input": "3\r\n-3 1 -1\r\n", "output": "1\r\n"}, {"input": "3\r\n3 -1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "5\r\n"}, {"input": "3\r\n-1 0 1\r\n", "output": "1\r\n"}, {"input": "3\r\n-3 -3 -2\r\n", "output": "-3\r\n"}, {"input": "3\r\n3 -1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 -1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n-2 -2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n0 -1 -3 -4\r\n", "output": "-1\r\n"}, {"input": "4\r\n5 3 2 1\r\n", "output": "11\r\n"}, {"input": "4\r\n-1 -2 4 -2\r\n", "output": "3\r\n"}, {"input": "4\r\n-1 -3 0 -3\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 -4 -3 -4\r\n", "output": "1\r\n"}, {"input": "4\r\n5 3 3 4\r\n", "output": "15\r\n"}, {"input": "4\r\n-1 -3 -1 2\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 -1 -4\r\n", "output": "5\r\n"}, {"input": "5\r\n-5 -4 -3 -5 2\r\n", "output": "-1\r\n"}, {"input": "5\r\n5 5 1 2 -2\r\n", "output": "13\r\n"}, {"input": "5\r\n-2 -1 -5 -1 4\r\n", "output": "3\r\n"}, {"input": "5\r\n-5 -5 -4 4 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 -3 -1 -4 -5\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 3\r\n", "output": "13\r\n"}, {"input": "5\r\n0 -2 -5 3 3\r\n", "output": "3\r\n"}, {"input": "5\r\n4 -2 -2 -3 0\r\n", "output": "1\r\n"}, {"input": "6\r\n6 7 -1 1 5 -1\r\n", "output": "19\r\n"}, {"input": "6\r\n-1 7 2 -3 -4 -5\r\n", "output": "9\r\n"}, {"input": "6\r\n0 -1 -3 -5 2 -6\r\n", "output": "1\r\n"}, {"input": "6\r\n4 -1 0 3 6 1\r\n", "output": "13\r\n"}, {"input": "6\r\n5 3 3 4 4 -3\r\n", "output": "19\r\n"}, {"input": "6\r\n0 -3 5 -4 5 -4\r\n", "output": "7\r\n"}, {"input": "6\r\n-5 -3 1 -1 -5 -3\r\n", "output": "1\r\n"}, {"input": "6\r\n-2 1 3 -2 7 4\r\n", "output": "15\r\n"}, {"input": "7\r\n0 7 6 2 7 0 6\r\n", "output": "21\r\n"}, {"input": "7\r\n6 -6 -1 -5 7 1 7\r\n", "output": "21\r\n"}, {"input": "7\r\n2 3 -5 0 -4 0 -4\r\n", "output": "5\r\n"}, {"input": "7\r\n-6 3 -3 -1 -6 -6 -5\r\n", "output": "3\r\n"}, {"input": "7\r\n7 6 3 2 4 2 0\r\n", "output": "21\r\n"}, {"input": "7\r\n-2 3 -3 4 4 0 -1\r\n", "output": "11\r\n"}, {"input": "7\r\n-5 -7 4 0 5 -3 -5\r\n", "output": "9\r\n"}, {"input": "7\r\n-3 -5 -4 1 3 -4 -7\r\n", "output": "3\r\n"}, {"input": "8\r\n5 2 4 5 7 -2 7 3\r\n", "output": "33\r\n"}, {"input": "8\r\n-8 -3 -1 3 -8 -4 -4 4\r\n", "output": "7\r\n"}, {"input": "8\r\n-6 -7 -7 -5 -4 -9 -2 -7\r\n", "output": "-5\r\n"}, {"input": "8\r\n8 7 6 8 3 4 8 -2\r\n", "output": "41\r\n"}, {"input": "8\r\n6 7 0 -6 6 5 4 7\r\n", "output": "35\r\n"}, {"input": "8\r\n0 -7 -5 -5 5 -1 -8 -7\r\n", "output": "5\r\n"}, {"input": "8\r\n1 -6 -5 7 -3 -4 2 -2\r\n", "output": "9\r\n"}, {"input": "8\r\n1 -8 -6 -6 -6 -7 -5 -1\r\n", "output": "1\r\n"}, {"input": "9\r\n-3 -1 4 4 8 -8 -5 9 -2\r\n", "output": "25\r\n"}, {"input": "9\r\n-9 -1 3 -2 -7 2 -9 -1 -4\r\n", "output": "5\r\n"}, {"input": "9\r\n-6 -9 -3 -8 -5 2 -6 0 -5\r\n", "output": "-1\r\n"}, {"input": "9\r\n5 4 3 3 6 7 8 5 9\r\n", "output": "47\r\n"}, {"input": "9\r\n5 3 9 1 5 2 -3 7 0\r\n", "output": "31\r\n"}, {"input": "9\r\n-3 -9 -1 -7 5 6 -4 -6 -6\r\n", "output": "11\r\n"}, {"input": "9\r\n-6 -5 6 -5 -2 0 1 2 -9\r\n", "output": "9\r\n"}, {"input": "9\r\n8 3 6 1 -3 5 2 9 1\r\n", "output": "35\r\n"}, {"input": "10\r\n-6 -4 -7 -1 -9 -10 -10 1 0 -3\r\n", "output": "1\r\n"}, {"input": "10\r\n-2 -10 -5 -6 -10 -3 -6 -3 -8 -8\r\n", "output": "-3\r\n"}, {"input": "10\r\n8 5 9 2 3 3 -6 1 -1 8\r\n", "output": "39\r\n"}, {"input": "10\r\n2 10 -7 6 -1 -1 7 -9 -4 -6\r\n", "output": "25\r\n"}, {"input": "10\r\n-10 -2 -2 -1 -10 -7 1 0 -4 -5\r\n", "output": "1\r\n"}, {"input": "10\r\n4 3 10 -2 -1 0 10 6 7 0\r\n", "output": "39\r\n"}, {"input": "10\r\n-2 6 6 5 0 10 6 7 -1 1\r\n", "output": "41\r\n"}, {"input": "10\r\n-10 2 8 -6 -1 -5 1 -10 -10 -1\r\n", "output": "11\r\n"}]
false
stdio
null
true
797/B
797
B
Python 3
TESTS
16
46
0
197491325
n=int(input()) l=list(map(int,input().split())) ev=[] od=[] s=0 so=0 mmo=-10000000000 mino=123456789 for i in l: if i%2==1: if i>0: so+=i; mino=min(mino,i); else: mmo=max(mmo,i); else: if i>0: s+=i if so>0: print(max(so-(mino*(so%2==0)),mmo)+s) else: print(mmo+s)
126
93
13,516,800
167714511
n=int(input()) a=list(map(int,input().split())) sp=0 mx=1<<33 for i in a: if i>0:sp+=i if i&1: mx=min(mx,abs(i)) if not sp&1: sp-=mx print(sp)
Educational Codeforces Round 19
ICPC
2,017
1
256
Odd sum
You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence.
The first line contains integer number n (1 ≤ n ≤ 105). The second line contains n integer numbers a1, a2, ..., an ( - 104 ≤ ai ≤ 104). The sequence contains at least one subsequence with odd sum.
Print sum of resulting subseqeuence.
null
In the first example sum of the second and the fourth elements is 3.
[{"input": "4\n-2 2 -3 1", "output": "3"}, {"input": "3\n2 -5 -3", "output": "-1"}]
1,400
["dp", "greedy", "implementation"]
126
[{"input": "4\r\n-2 2 -3 1\r\n", "output": "3\r\n"}, {"input": "3\r\n2 -5 -3\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "15\r\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046\r\n", "output": "53507\r\n"}, {"input": "2\r\n-5439 -6705\r\n", "output": "-5439\r\n"}, {"input": "2\r\n2850 6843\r\n", "output": "9693\r\n"}, {"input": "2\r\n144 9001\r\n", "output": "9145\r\n"}, {"input": "10\r\n7535 -819 2389 4933 5495 4887 -5181 -9355 7955 5757\r\n", "output": "38951\r\n"}, {"input": "10\r\n-9169 -1574 3580 -8579 -7177 -3216 7490 3470 3465 -1197\r\n", "output": "18005\r\n"}, {"input": "10\r\n941 7724 2220 -4704 -8374 -8249 7606 9502 612 -9097\r\n", "output": "28605\r\n"}, {"input": "10\r\n4836 -2331 -3456 2312 -1574 3134 -670 -204 512 -5504\r\n", "output": "8463\r\n"}, {"input": "10\r\n1184 5136 1654 3254 6576 6900 6468 327 179 7114\r\n", "output": "38613\r\n"}, {"input": "10\r\n-2152 -1776 -1810 -9046 -6090 -2324 -8716 -6103 -787 -812\r\n", "output": "-787\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "3\r\n"}, {"input": "5\r\n5 5 5 3 -1\r\n", "output": "17\r\n"}, {"input": "5\r\n-1 -2 5 3 0\r\n", "output": "7\r\n"}, {"input": "5\r\n-3 -2 5 -1 3\r\n", "output": "7\r\n"}, {"input": "3\r\n-2 2 -1\r\n", "output": "1\r\n"}, {"input": "5\r\n5 0 7 -2 3\r\n", "output": "15\r\n"}, {"input": "2\r\n-2 -5\r\n", "output": "-5\r\n"}, {"input": "3\r\n-1 -3 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 -1 0 -3 -2\r\n", "output": "1\r\n"}, {"input": "4\r\n2 3 0 5\r\n", "output": "7\r\n"}, {"input": "5\r\n-5 3 -2 2 5\r\n", "output": "7\r\n"}, {"input": "59\r\n8593 5929 3016 -859 4366 -6842 8435 -3910 -2458 -8503 -3612 -9793 -5360 -9791 -362 -7180 727 -6245 -8869 -7316 8214 -7944 7098 3788 -5436 -6626 -1131 -2410 -5647 -7981 263 -5879 8786 709 6489 5316 -4039 4909 -4340 7979 -89 9844 -906 172 -7674 -3371 -6828 9505 3284 5895 3646 6680 -1255 3635 -9547 -5104 -1435 -7222 2244\r\n", "output": "129433\r\n"}, {"input": "17\r\n-6170 2363 6202 -9142 7889 779 2843 -5089 2313 -3952 1843 5171 462 -3673 5098 -2519 9565\r\n", "output": "43749\r\n"}, {"input": "26\r\n-8668 9705 1798 -1766 9644 3688 8654 -3077 -5462 2274 6739 2732 3635 -4745 -9144 -9175 -7488 -2010 1637 1118 8987 1597 -2873 -5153 -8062 146\r\n", "output": "60757\r\n"}, {"input": "51\r\n8237 -7239 -3545 -6059 -5110 4066 -4148 -7641 -5797 -994 963 1144 -2785 -8765 -1216 5410 1508 -6312 -6313 -680 -7657 4579 -6898 7379 2015 -5087 -5417 -6092 3819 -9101 989 -8380 9161 -7519 -9314 -3838 7160 5180 567 -1606 -3842 -9665 -2266 1296 -8417 -3976 7436 -2075 -441 -4565 3313\r\n", "output": "73781\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "2\r\n-2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n", "output": "5\r\n"}, {"input": "2\r\n1 2\r\n", "output": "3\r\n"}, {"input": "2\r\n-1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n0 -1\r\n", "output": "-1\r\n"}, {"input": "2\r\n2 1\r\n", "output": "3\r\n"}, {"input": "2\r\n3 0\r\n", "output": "3\r\n"}, {"input": "2\r\n0 -1\r\n", "output": "-1\r\n"}, {"input": "3\r\n-3 1 -1\r\n", "output": "1\r\n"}, {"input": "3\r\n3 -1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "5\r\n"}, {"input": "3\r\n-1 0 1\r\n", "output": "1\r\n"}, {"input": "3\r\n-3 -3 -2\r\n", "output": "-3\r\n"}, {"input": "3\r\n3 -1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 -1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n-2 -2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n0 -1 -3 -4\r\n", "output": "-1\r\n"}, {"input": "4\r\n5 3 2 1\r\n", "output": "11\r\n"}, {"input": "4\r\n-1 -2 4 -2\r\n", "output": "3\r\n"}, {"input": "4\r\n-1 -3 0 -3\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 -4 -3 -4\r\n", "output": "1\r\n"}, {"input": "4\r\n5 3 3 4\r\n", "output": "15\r\n"}, {"input": "4\r\n-1 -3 -1 2\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 -1 -4\r\n", "output": "5\r\n"}, {"input": "5\r\n-5 -4 -3 -5 2\r\n", "output": "-1\r\n"}, {"input": "5\r\n5 5 1 2 -2\r\n", "output": "13\r\n"}, {"input": "5\r\n-2 -1 -5 -1 4\r\n", "output": "3\r\n"}, {"input": "5\r\n-5 -5 -4 4 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 -3 -1 -4 -5\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 3\r\n", "output": "13\r\n"}, {"input": "5\r\n0 -2 -5 3 3\r\n", "output": "3\r\n"}, {"input": "5\r\n4 -2 -2 -3 0\r\n", "output": "1\r\n"}, {"input": "6\r\n6 7 -1 1 5 -1\r\n", "output": "19\r\n"}, {"input": "6\r\n-1 7 2 -3 -4 -5\r\n", "output": "9\r\n"}, {"input": "6\r\n0 -1 -3 -5 2 -6\r\n", "output": "1\r\n"}, {"input": "6\r\n4 -1 0 3 6 1\r\n", "output": "13\r\n"}, {"input": "6\r\n5 3 3 4 4 -3\r\n", "output": "19\r\n"}, {"input": "6\r\n0 -3 5 -4 5 -4\r\n", "output": "7\r\n"}, {"input": "6\r\n-5 -3 1 -1 -5 -3\r\n", "output": "1\r\n"}, {"input": "6\r\n-2 1 3 -2 7 4\r\n", "output": "15\r\n"}, {"input": "7\r\n0 7 6 2 7 0 6\r\n", "output": "21\r\n"}, {"input": "7\r\n6 -6 -1 -5 7 1 7\r\n", "output": "21\r\n"}, {"input": "7\r\n2 3 -5 0 -4 0 -4\r\n", "output": "5\r\n"}, {"input": "7\r\n-6 3 -3 -1 -6 -6 -5\r\n", "output": "3\r\n"}, {"input": "7\r\n7 6 3 2 4 2 0\r\n", "output": "21\r\n"}, {"input": "7\r\n-2 3 -3 4 4 0 -1\r\n", "output": "11\r\n"}, {"input": "7\r\n-5 -7 4 0 5 -3 -5\r\n", "output": "9\r\n"}, {"input": "7\r\n-3 -5 -4 1 3 -4 -7\r\n", "output": "3\r\n"}, {"input": "8\r\n5 2 4 5 7 -2 7 3\r\n", "output": "33\r\n"}, {"input": "8\r\n-8 -3 -1 3 -8 -4 -4 4\r\n", "output": "7\r\n"}, {"input": "8\r\n-6 -7 -7 -5 -4 -9 -2 -7\r\n", "output": "-5\r\n"}, {"input": "8\r\n8 7 6 8 3 4 8 -2\r\n", "output": "41\r\n"}, {"input": "8\r\n6 7 0 -6 6 5 4 7\r\n", "output": "35\r\n"}, {"input": "8\r\n0 -7 -5 -5 5 -1 -8 -7\r\n", "output": "5\r\n"}, {"input": "8\r\n1 -6 -5 7 -3 -4 2 -2\r\n", "output": "9\r\n"}, {"input": "8\r\n1 -8 -6 -6 -6 -7 -5 -1\r\n", "output": "1\r\n"}, {"input": "9\r\n-3 -1 4 4 8 -8 -5 9 -2\r\n", "output": "25\r\n"}, {"input": "9\r\n-9 -1 3 -2 -7 2 -9 -1 -4\r\n", "output": "5\r\n"}, {"input": "9\r\n-6 -9 -3 -8 -5 2 -6 0 -5\r\n", "output": "-1\r\n"}, {"input": "9\r\n5 4 3 3 6 7 8 5 9\r\n", "output": "47\r\n"}, {"input": "9\r\n5 3 9 1 5 2 -3 7 0\r\n", "output": "31\r\n"}, {"input": "9\r\n-3 -9 -1 -7 5 6 -4 -6 -6\r\n", "output": "11\r\n"}, {"input": "9\r\n-6 -5 6 -5 -2 0 1 2 -9\r\n", "output": "9\r\n"}, {"input": "9\r\n8 3 6 1 -3 5 2 9 1\r\n", "output": "35\r\n"}, {"input": "10\r\n-6 -4 -7 -1 -9 -10 -10 1 0 -3\r\n", "output": "1\r\n"}, {"input": "10\r\n-2 -10 -5 -6 -10 -3 -6 -3 -8 -8\r\n", "output": "-3\r\n"}, {"input": "10\r\n8 5 9 2 3 3 -6 1 -1 8\r\n", "output": "39\r\n"}, {"input": "10\r\n2 10 -7 6 -1 -1 7 -9 -4 -6\r\n", "output": "25\r\n"}, {"input": "10\r\n-10 -2 -2 -1 -10 -7 1 0 -4 -5\r\n", "output": "1\r\n"}, {"input": "10\r\n4 3 10 -2 -1 0 10 6 7 0\r\n", "output": "39\r\n"}, {"input": "10\r\n-2 6 6 5 0 10 6 7 -1 1\r\n", "output": "41\r\n"}, {"input": "10\r\n-10 2 8 -6 -1 -5 1 -10 -10 -1\r\n", "output": "11\r\n"}]
false
stdio
null
true
818/E
818
E
Python 3
TESTS
1
46
4,608,000
28145165
read = lambda: map(int, input().split()) n, k = read() a = list(read()) p = 1 ans = 0 r = 0 for i in range(n): r = max(r, i) if r == i: p = a[i] while r + 1 < n and p % k: p *= a[r + 1] r += 1 if p % k == 0: ans += n - r print(ans)
135
1,809
14,950,400
90465157
def gcd(a,b): if a == 0: return b return gcd(b%a,a) n,k = [int(x) for x in input().split()] a = [gcd(int(x),k) for x in input().split()] if k == 1: print(((n+1)*(n+2))//2-n-1) else: s = 0 e = 0 total = ((n+1)*(n+2))//2-1-n #print(total) #extra = {} c = 1 while e < n: flag = False while c%k != 0 and e < n: total -= e-s c *= a[e] e += 1 while c%k == 0 and s < e: c //= a[s] s += 1 total -= e-s print(total)
Educational Codeforces Round 24
ICPC
2,017
2
256
Card Game Again
Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number ai is written on the i-th card in the deck. After receiving the deck and the magic number, Vova removes x (possibly x = 0) cards from the top of the deck, y (possibly y = 0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards x + 1, x + 2, ... n - y - 1, n - y from the original deck. Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by k. So Vova received a deck (possibly not a valid one) and a number k, and now he wonders, how many ways are there to choose x and y so the deck he will get after removing x cards from the top and y cards from the bottom is valid?
The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers written on the cards.
Print the number of ways to choose x and y so the resulting deck is valid.
null
In the first example the possible values of x and y are: 1. x = 0, y = 0; 2. x = 1, y = 0; 3. x = 2, y = 0; 4. x = 0, y = 1.
[{"input": "3 4\n6 2 8", "output": "4"}, {"input": "3 6\n9 1 14", "output": "1"}]
1,900
["binary search", "data structures", "number theory", "two pointers"]
135
[{"input": "3 4\r\n6 2 8\r\n", "output": "4\r\n"}, {"input": "3 6\r\n9 1 14\r\n", "output": "1\r\n"}, {"input": "5 1\r\n1 3 1 3 1\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 5 5 5 5\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 4 4 4 4\r\n", "output": "15\r\n"}, {"input": "100 1\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": "5050\r\n"}, {"input": "100 1\r\n3 3 2 1 1 2 1 2 3 4 1 5 2 4 5 1 1 3 2 3 4 2 1 3 4 4 5 5 1 5 2 5 3 3 1 1 1 3 2 2 3 4 4 4 4 3 1 3 5 3 3 3 3 2 3 2 2 3 3 1 2 4 3 2 2 5 3 1 5 2 2 5 1 2 1 1 5 1 5 2 4 5 3 4 2 5 4 2 2 5 5 5 3 3 5 3 4 3 3 1\r\n", "output": "5050\r\n"}, {"input": "100 5\r\n4 4 3 2 4 4 1 2 2 1 5 3 2 5 5 3 2 3 4 5 2 2 3 4 2 4 3 1 2 3 5 5 1 3 3 5 2 3 3 4 1 3 1 5 4 4 2 1 5 1 4 4 1 5 1 1 5 5 5 4 1 3 1 2 3 2 4 5 5 1 3 4 3 3 1 2 2 4 1 5 1 1 2 4 4 4 5 5 5 3 4 3 3 3 3 2 1 1 5 5\r\n", "output": "4713\r\n"}, {"input": "100 6\r\n4 4 1 1 1 1 3 3 5 5 4 2 2 4 3 4 4 5 5 4 5 1 3 1 5 4 5 1 2 5 5 2 2 4 2 4 4 2 5 5 3 3 1 3 3 5 2 3 1 4 1 4 4 1 5 5 1 2 3 2 3 3 5 3 4 2 3 4 3 1 5 3 5 5 3 5 4 4 3 1 1 2 1 2 1 3 2 4 3 2 1 4 3 1 1 5 1 5 4 3\r\n", "output": "4580\r\n"}, {"input": "100 72\r\n8 8 7 9 6 1 4 5 3 7 5 10 5 4 1 3 4 1 3 1 6 6 4 5 4 5 6 1 10 7 9 1 6 10 6 6 9 3 3 4 5 9 4 9 8 1 5 9 3 7 1 8 5 2 1 1 7 7 7 6 6 4 2 9 10 2 8 3 1 1 4 8 5 9 7 10 9 4 2 3 7 7 6 7 8 5 1 3 8 5 1 8 9 10 3 7 1 8 10 5\r\n", "output": "4549\r\n"}, {"input": "100 72\r\n3 2 1 3 3 3 4 3 5 5 2 5 1 2 2 2 1 4 1 5 1 4 5 4 3 1 4 3 4 4 1 4 4 3 4 1 4 4 5 2 2 3 3 5 4 5 4 2 4 3 1 1 1 4 5 5 3 1 5 3 4 4 5 3 5 1 4 3 2 2 1 4 2 1 3 2 4 2 1 4 4 1 3 4 4 4 1 5 5 2 5 2 3 1 5 1 1 1 2 3\r\n", "output": "4123\r\n"}, {"input": "2 999634589\r\n31607 31627\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1\r\n", "output": "0\r\n"}, {"input": "1 3\r\n1\r\n", "output": "0\r\n"}, {"input": "1 4\r\n1\r\n", "output": "0\r\n"}, {"input": "1 5\r\n3\r\n", "output": "0\r\n"}, {"input": "1 6\r\n4\r\n", "output": "0\r\n"}, {"input": "1 7\r\n2\r\n", "output": "0\r\n"}, {"input": "1 8\r\n3\r\n", "output": "0\r\n"}, {"input": "1 9\r\n5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n3\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n", "output": "3\r\n"}, {"input": "2 2\r\n2 2\r\n", "output": "3\r\n"}, {"input": "2 3\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2 4\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2 5\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 6\r\n2 1\r\n", "output": "0\r\n"}, {"input": "2 7\r\n1 4\r\n", "output": "0\r\n"}, {"input": "2 8\r\n5 3\r\n", "output": "0\r\n"}, {"input": "2 9\r\n2 2\r\n", "output": "0\r\n"}, {"input": "2 10\r\n6 1\r\n", "output": "0\r\n"}, {"input": "3 1\r\n1 1 1\r\n", "output": "6\r\n"}, {"input": "3 2\r\n2 2 1\r\n", "output": "5\r\n"}, {"input": "3 3\r\n2 1 2\r\n", "output": "0\r\n"}, {"input": "3 4\r\n2 2 2\r\n", "output": "3\r\n"}, {"input": "3 5\r\n1 1 2\r\n", "output": "0\r\n"}, {"input": "3 6\r\n4 3 2\r\n", "output": "3\r\n"}, {"input": "3 7\r\n3 4 1\r\n", "output": "0\r\n"}, {"input": "3 8\r\n5 1 4\r\n", "output": "0\r\n"}, {"input": "3 9\r\n3 2 1\r\n", "output": "0\r\n"}, {"input": "3 10\r\n6 5 5\r\n", "output": "2\r\n"}, {"input": "4 1\r\n1 1 1 1\r\n", "output": "10\r\n"}, {"input": "4 2\r\n2 2 1 2\r\n", "output": "9\r\n"}, {"input": "4 3\r\n2 1 1 1\r\n", "output": "0\r\n"}, {"input": "4 4\r\n2 2 1 1\r\n", "output": "3\r\n"}, {"input": "4 5\r\n2 3 2 1\r\n", "output": "0\r\n"}, {"input": "4 6\r\n1 1 3 3\r\n", "output": "0\r\n"}, {"input": "4 7\r\n1 1 2 2\r\n", "output": "0\r\n"}, {"input": "4 8\r\n5 4 5 5\r\n", "output": "0\r\n"}, {"input": "4 9\r\n1 1 4 2\r\n", "output": "0\r\n"}, {"input": "4 10\r\n2 6 2 1\r\n", "output": "0\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n", "output": "15\r\n"}, {"input": "5 2\r\n2 2 1 2 1\r\n", "output": "13\r\n"}, {"input": "5 3\r\n2 1 1 2 1\r\n", "output": "0\r\n"}, {"input": "5 4\r\n2 2 1 3 1\r\n", "output": "4\r\n"}, {"input": "5 5\r\n2 3 1 1 3\r\n", "output": "0\r\n"}, {"input": "5 6\r\n3 4 3 4 3\r\n", "output": "10\r\n"}, {"input": "5 7\r\n3 1 3 2 4\r\n", "output": "0\r\n"}, {"input": "5 8\r\n2 2 3 3 1\r\n", "output": "0\r\n"}, {"input": "5 9\r\n3 1 3 3 4\r\n", "output": "7\r\n"}, {"input": "5 10\r\n3 6 6 1 5\r\n", "output": "3\r\n"}, {"input": "6 1\r\n1 1 1 1 1 1\r\n", "output": "21\r\n"}, {"input": "6 2\r\n1 2 2 1 1 1\r\n", "output": "14\r\n"}, {"input": "6 3\r\n2 2 2 2 1 2\r\n", "output": "0\r\n"}, {"input": "6 4\r\n1 3 3 3 3 2\r\n", "output": "0\r\n"}, {"input": "6 5\r\n2 3 3 2 1 2\r\n", "output": "0\r\n"}, {"input": "6 6\r\n1 2 4 1 4 4\r\n", "output": "0\r\n"}, {"input": "6 7\r\n2 2 4 3 2 1\r\n", "output": "0\r\n"}, {"input": "6 8\r\n3 2 3 5 5 3\r\n", "output": "0\r\n"}, {"input": "6 9\r\n1 4 1 2 1 1\r\n", "output": "0\r\n"}, {"input": "6 10\r\n1 2 5 6 6 6\r\n", "output": "11\r\n"}, {"input": "7 1\r\n1 1 1 1 1 1 1\r\n", "output": "28\r\n"}, {"input": "7 2\r\n1 1 2 2 2 2 1\r\n", "output": "24\r\n"}, {"input": "7 3\r\n2 2 1 1 2 2 2\r\n", "output": "0\r\n"}, {"input": "7 4\r\n3 2 1 2 1 1 1\r\n", "output": "8\r\n"}, {"input": "7 5\r\n2 3 3 3 2 3 2\r\n", "output": "0\r\n"}, {"input": "7 6\r\n3 4 4 1 4 3 2\r\n", "output": "15\r\n"}, {"input": "7 7\r\n4 2 4 4 1 4 4\r\n", "output": "0\r\n"}, {"input": "7 8\r\n4 4 2 4 2 5 3\r\n", "output": "18\r\n"}, {"input": "7 9\r\n2 1 3 4 4 5 4\r\n", "output": "0\r\n"}, {"input": "7 10\r\n6 3 3 5 3 6 1\r\n", "output": "10\r\n"}, {"input": "8 1\r\n1 1 1 1 1 1 1 1\r\n", "output": "36\r\n"}, {"input": "8 2\r\n1 1 1 1 1 1 1 2\r\n", "output": "8\r\n"}, {"input": "8 3\r\n1 1 2 2 1 1 2 2\r\n", "output": "0\r\n"}, {"input": "8 4\r\n2 3 2 3 3 3 2 3\r\n", "output": "10\r\n"}, {"input": "8 5\r\n1 3 1 2 2 2 1 3\r\n", "output": "0\r\n"}, {"input": "8 6\r\n4 2 4 2 1 2 1 4\r\n", "output": "0\r\n"}, {"input": "8 7\r\n2 2 1 4 4 4 2 2\r\n", "output": "0\r\n"}, {"input": "8 8\r\n5 2 1 2 4 2 2 4\r\n", "output": "21\r\n"}, {"input": "8 9\r\n4 4 2 2 5 5 4 1\r\n", "output": "0\r\n"}, {"input": "8 10\r\n2 1 4 4 3 4 4 6\r\n", "output": "0\r\n"}, {"input": "9 1\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "45\r\n"}, {"input": "9 2\r\n1 1 1 2 1 1 2 2 2\r\n", "output": "36\r\n"}, {"input": "9 3\r\n1 1 1 2 2 1 1 2 1\r\n", "output": "0\r\n"}, {"input": "9 4\r\n1 1 2 1 2 1 1 1 1\r\n", "output": "15\r\n"}, {"input": "9 5\r\n3 2 3 2 3 1 1 3 2\r\n", "output": "0\r\n"}, {"input": "9 6\r\n2 1 1 3 2 4 1 2 2\r\n", "output": "21\r\n"}, {"input": "9 7\r\n4 3 2 1 2 3 3 4 4\r\n", "output": "0\r\n"}, {"input": "9 8\r\n5 5 2 1 3 1 3 1 3\r\n", "output": "0\r\n"}, {"input": "9 9\r\n2 4 1 4 4 3 3 4 1\r\n", "output": "18\r\n"}, {"input": "9 10\r\n4 3 2 5 2 2 2 2 6\r\n", "output": "23\r\n"}, {"input": "10 1\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "55\r\n"}, {"input": "10 2\r\n2 2 2 2 2 2 2 1 2 1\r\n", "output": "53\r\n"}, {"input": "10 3\r\n2 2 1 1 2 2 2 2 1 2\r\n", "output": "0\r\n"}, {"input": "10 4\r\n1 1 2 3 3 1 2 2 2 3\r\n", "output": "26\r\n"}, {"input": "10 5\r\n3 3 2 2 3 1 1 1 3 1\r\n", "output": "0\r\n"}, {"input": "10 6\r\n4 4 4 3 2 1 1 1 2 4\r\n", "output": "27\r\n"}, {"input": "10 7\r\n4 2 2 2 3 3 2 4 4 3\r\n", "output": "0\r\n"}, {"input": "10 8\r\n5 4 1 4 3 2 1 2 3 3\r\n", "output": "24\r\n"}, {"input": "10 9\r\n1 2 3 4 5 2 3 5 5 4\r\n", "output": "12\r\n"}, {"input": "10 10\r\n5 3 2 5 1 2 5 1 5 1\r\n", "output": "35\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "1 100000000\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1000000000\r\n", "output": "1\r\n"}]
false
stdio
null
true
750/B
750
B
Python 3
TESTS
8
31
0
223789315
flag=True north=0 south=0 for _ in range(int(input())): t,s=map(str,input().split()) if south-north==20000: if s!="North": flag=False if north-south==0 or (north==0 and south==0): if s!="South": flag=False if s=="North": north+=int(t) if s=="South": south+=int(t) print("YES" if south-north==0 and flag else "NO")
140
62
4,710,400
23433068
tmp=0 flag=True for i in range(int(input())): a,b=input().split() if b=="South": tmp+=int(a) if tmp>20000: flag=False elif b=="North": tmp-=int(a) if tmp<0: flag=False elif tmp==0 or tmp == 20000: flag=False if flag and tmp==0: print("YES") else: print("NO")
Good Bye 2016
CF
2,016
2
256
New Year and North Pole
In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers. Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move ti kilometers in the direction represented by a string diri that is one of: "North", "South", "West", "East". Limak isn’t sure whether the description is valid. You must help him to check the following conditions: - If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South. - If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North. - The journey must end on the North Pole. Check if the above conditions are satisfied and print "YES" or "NO" on a single line.
The first line of the input contains a single integer n (1 ≤ n ≤ 50). The i-th of next n lines contains an integer ti and a string diri (1 ≤ ti ≤ 106, $${ dir } _ { i } \in \{ \mathrm { N o r t h, ~ S o u t h, ~ W e s t, ~ E a s t } \}$$) — the length and the direction of the i-th part of the journey, according to the description Limak got.
Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes.
null
Drawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole.
[{"input": "5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North", "output": "YES"}, {"input": "2\n15000 South\n4000 East", "output": "NO"}, {"input": "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North", "output": "YES"}, {"input": "3\n20000 South\n10 East\n20000 North", "output": "NO"}, {"input": "2\n1000 North\n1000 South", "output": "NO"}, {"input": "4\n50 South\n50 North\n15000 South\n15000 North", "output": "YES"}]
1,300
["geometry", "implementation"]
140
[{"input": "5\r\n7500 South\r\n10000 East\r\n3500 North\r\n4444 West\r\n4000 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n15000 South\r\n4000 East\r\n", "output": "NO\r\n"}, {"input": "5\r\n20000 South\r\n1000 North\r\n1000000 West\r\n9000 North\r\n10000 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n20000 South\r\n10 East\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n1000 North\r\n1000 South\r\n", "output": "NO\r\n"}, {"input": "4\r\n50 South\r\n50 North\r\n15000 South\r\n15000 North\r\n", "output": "YES\r\n"}, {"input": "1\r\n1 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n1 East\r\n", "output": "NO\r\n"}, {"input": "2\r\n1000000 South\r\n1000000 North\r\n", "output": "NO\r\n"}, {"input": "1\r\n149 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n16277 East\r\n", "output": "NO\r\n"}, {"input": "1\r\n19701 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n3125 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n6549 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n2677 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n6101 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n9525 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n5653 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n15072 South\r\n15072 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n11200 South\r\n11200 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n14624 South\r\n14624 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n18048 South\r\n15452 West\r\n", "output": "NO\r\n"}, {"input": "2\r\n1472 West\r\n4930 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n17600 South\r\n17600 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n8320 East\r\n16589 East\r\n", "output": "NO\r\n"}, {"input": "2\r\n4448 South\r\n4448 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n576 South\r\n576 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n14186 South\r\n2291 West\r\n14186 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n10314 South\r\n15961 North\r\n5647 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n1035 East\r\n18143 South\r\n18143 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n17163 South\r\n7620 East\r\n17163 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n587 South\r\n17098 North\r\n16511 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n16715 North\r\n6576 West\r\n12132 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n7435 South\r\n245 North\r\n7190 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n3563 South\r\n2427 South\r\n5990 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n6987 South\r\n11904 East\r\n19951 East\r\n", "output": "NO\r\n"}, {"input": "4\r\n13301 South\r\n5948 East\r\n9265 East\r\n6891 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n16725 South\r\n8129 South\r\n19530 West\r\n24854 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n149 South\r\n17607 West\r\n18306 South\r\n18455 North\r\n", "output": "YES\r\n"}, {"input": "4\r\n16277 South\r\n19789 North\r\n4379 South\r\n867 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n19701 South\r\n13458 South\r\n3156 North\r\n30003 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n3125 South\r\n15640 East\r\n6125 East\r\n19535 South\r\n", "output": "NO\r\n"}, {"input": "4\r\n6549 East\r\n5118 North\r\n12198 East\r\n5118 South\r\n", "output": "NO\r\n"}, {"input": "4\r\n2677 East\r\n1891 West\r\n10974 West\r\n7511 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n6102 South\r\n8265 East\r\n13943 South\r\n20045 North\r\n", "output": "NO\r\n"}, {"input": "5\r\n12416 South\r\n18116 North\r\n10553 West\r\n18435 West\r\n5700 South\r\n", "output": "NO\r\n"}, {"input": "5\r\n15840 South\r\n7594 South\r\n13522 South\r\n2423 South\r\n3334 West\r\n", "output": "NO\r\n"}, {"input": "5\r\n19264 East\r\n13968 East\r\n19595 North\r\n19115 North\r\n38710 South\r\n", "output": "NO\r\n"}, {"input": "5\r\n15392 South\r\n3445 North\r\n18372 East\r\n10399 North\r\n4403 South\r\n", "output": "NO\r\n"}, {"input": "5\r\n18816 South\r\n5627 West\r\n14045 East\r\n7091 East\r\n18816 North\r\n", "output": "YES\r\n"}, {"input": "5\r\n2240 South\r\n15104 North\r\n118 West\r\n11079 East\r\n12864 South\r\n", "output": "NO\r\n"}, {"input": "5\r\n5664 South\r\n1478 South\r\n18894 South\r\n2363 West\r\n26036 North\r\n", "output": "NO\r\n"}, {"input": "5\r\n1792 South\r\n10956 East\r\n9159 South\r\n19055 West\r\n10951 North\r\n", "output": "YES\r\n"}, {"input": "5\r\n12512 South\r\n13137 North\r\n7936 North\r\n7235 South\r\n1326 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n14635 North\r\n14477 South\r\n17250 North\r\n14170 East\r\n15166 South\r\n2242 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n10763 North\r\n3954 West\r\n7515 North\r\n18158 West\r\n6644 South\r\n11634 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n14187 South\r\n13432 North\r\n6292 East\r\n14850 West\r\n10827 South\r\n9639 East\r\n", "output": "NO\r\n"}, {"input": "6\r\n10315 South\r\n15614 South\r\n5069 West\r\n6134 South\r\n7713 North\r\n24350 North\r\n", "output": "NO\r\n"}, {"input": "6\r\n1035 South\r\n9283 East\r\n15333 South\r\n2826 South\r\n19191 North\r\n3 North\r\n", "output": "YES\r\n"}, {"input": "6\r\n17163 West\r\n11465 North\r\n14110 South\r\n6814 North\r\n3373 East\r\n4169 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n587 South\r\n942 West\r\n183 North\r\n18098 North\r\n260 East\r\n17694 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n16715 West\r\n3124 East\r\n3152 East\r\n14790 East\r\n11738 West\r\n11461 East\r\n", "output": "NO\r\n"}, {"input": "6\r\n7435 South\r\n12602 South\r\n1929 East\r\n6074 East\r\n15920 West\r\n20037 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n13750 South\r\n6645 South\r\n18539 East\r\n5713 North\r\n1580 North\r\n10012 West\r\n13102 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n9878 West\r\n8827 East\r\n1508 West\r\n9702 North\r\n5763 North\r\n9755 North\r\n10034 South\r\n", "output": "NO\r\n"}, {"input": "7\r\n13302 West\r\n2496 North\r\n284 West\r\n6394 East\r\n9945 North\r\n12603 West\r\n12275 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n16726 East\r\n19270 West\r\n6357 South\r\n17678 East\r\n14127 East\r\n12347 South\r\n6005 East\r\n", "output": "NO\r\n"}, {"input": "7\r\n150 South\r\n1452 North\r\n9326 North\r\n1666 West\r\n18309 East\r\n19386 East\r\n8246 West\r\n", "output": "NO\r\n"}, {"input": "7\r\n16278 South\r\n10929 South\r\n8103 East\r\n18358 West\r\n2492 West\r\n11834 South\r\n39041 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n19702 South\r\n13111 East\r\n6880 East\r\n9642 South\r\n6674 West\r\n18874 East\r\n1112 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n3126 South\r\n6780 North\r\n9848 West\r\n6334 North\r\n10856 West\r\n14425 West\r\n10649 East\r\n", "output": "NO\r\n"}, {"input": "7\r\n6550 South\r\n8962 West\r\n15921 South\r\n17618 North\r\n15038 South\r\n1465 North\r\n18426 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n12864 South\r\n3005 West\r\n16723 West\r\n17257 West\r\n12187 East\r\n12976 South\r\n1598 North\r\n24242 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n8992 South\r\n12483 North\r\n15500 South\r\n1245 South\r\n9073 East\r\n12719 East\r\n3839 East\r\n7130 South\r\n", "output": "NO\r\n"}, {"input": "8\r\n12416 North\r\n14665 South\r\n14277 North\r\n2129 South\r\n13255 East\r\n19759 South\r\n10272 West\r\n9860 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n15840 South\r\n4142 East\r\n17246 North\r\n13413 North\r\n4733 West\r\n15311 North\r\n12514 South\r\n17616 South\r\n", "output": "NO\r\n"}, {"input": "8\r\n19264 South\r\n10516 North\r\n3319 East\r\n17401 East\r\n1620 West\r\n2350 West\r\n6243 North\r\n2505 North\r\n", "output": "YES\r\n"}, {"input": "8\r\n15392 South\r\n7290 West\r\n2096 West\r\n14093 East\r\n5802 South\r\n2094 North\r\n8484 East\r\n19100 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n6113 South\r\n16767 East\r\n5064 South\r\n5377 West\r\n17280 South\r\n1838 West\r\n2213 West\r\n28457 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n2241 West\r\n18949 South\r\n11137 South\r\n2069 West\r\n14166 South\r\n1581 South\r\n4455 South\r\n50288 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n5665 South\r\n8426 East\r\n9914 North\r\n13353 South\r\n18349 North\r\n4429 East\r\n18184 North\r\n27429 South\r\n", "output": "NO\r\n"}, {"input": "9\r\n11979 South\r\n2470 East\r\n10716 North\r\n12992 East\r\n15497 West\r\n15940 North\r\n8107 West\r\n18934 East\r\n6993 South\r\n", "output": "NO\r\n"}, {"input": "9\r\n8107 South\r\n4652 North\r\n9493 North\r\n16980 West\r\n12383 West\r\n2980 West\r\n17644 South\r\n11043 West\r\n11447 North\r\n", "output": "NO\r\n"}, {"input": "9\r\n18827 South\r\n18321 West\r\n8270 East\r\n968 West\r\n16565 West\r\n15427 North\r\n4077 North\r\n18960 North\r\n19006 West\r\n", "output": "NO\r\n"}, {"input": "9\r\n14955 West\r\n503 North\r\n18535 West\r\n4956 South\r\n8044 South\r\n2467 East\r\n13615 East\r\n6877 East\r\n3460 North\r\n", "output": "NO\r\n"}, {"input": "9\r\n18379 South\r\n9980 South\r\n17311 West\r\n8944 South\r\n4930 South\r\n18019 South\r\n48 West\r\n14794 South\r\n75046 North\r\n", "output": "NO\r\n"}, {"input": "9\r\n14507 East\r\n12162 East\r\n16088 South\r\n5636 North\r\n9112 North\r\n5058 East\r\n9585 South\r\n2712 East\r\n10925 North\r\n", "output": "NO\r\n"}, {"input": "9\r\n5227 East\r\n8936 North\r\n6353 North\r\n16920 North\r\n591 North\r\n4802 South\r\n8722 North\r\n3333 West\r\n36720 South\r\n", "output": "NO\r\n"}, {"input": "9\r\n1355 North\r\n15309 West\r\n17834 North\r\n13612 East\r\n17477 North\r\n4546 North\r\n18260 East\r\n15442 North\r\n56654 South\r\n", "output": "NO\r\n"}, {"input": "9\r\n4779 South\r\n4787 East\r\n3907 East\r\n4896 East\r\n1659 East\r\n4289 West\r\n4693 West\r\n3359 East\r\n4779 North\r\n", "output": "YES\r\n"}, {"input": "1\r\n80000 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n40000 South\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "1\r\n40000 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n20001 South\r\n20001 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n10000 South\r\n20000 South\r\n10000 North\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n10 South\r\n20 North\r\n10 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1000 South\r\n1001 North\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20000 South\r\n20000 West\r\n", "output": "NO\r\n"}, {"input": "3\r\n10000 South\r\n20000 South\r\n10000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 East\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20000 West\r\n20000 West\r\n", "output": "NO\r\n"}, {"input": "2\r\n80000 South\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n19999 South\r\n20001 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n500 South\r\n1000 North\r\n500 North\r\n", "output": "NO\r\n"}, {"input": "1\r\n400000 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n40000 South\r\n80000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n100 West\r\n100 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n40000 South\r\n40000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n30000 South\r\n10000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20000 South\r\n40000 North\r\n", "output": "NO\r\n"}, {"input": "10\r\n20000 South\r\n20000 North\r\n20000 South\r\n20000 North\r\n20000 South\r\n20000 North\r\n20000 South\r\n20000 North\r\n20000 South\r\n20000 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n40001 South\r\n40001 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n40001 South\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n50000 South\r\n50000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n30000 South\r\n30000 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n10000 South\r\n50000 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n15000 South\r\n15000 South\r\n15000 North\r\n15000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n50 South\r\n100 North\r\n50 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20001 South\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n5 South\r\n6 North\r\n1 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n20000 South\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 South\r\n20000 South\r\n1 North\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n30000 South\r\n30000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n2 North\r\n1 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n60000 South\r\n60000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n50000 South\r\n10000 North\r\n", "output": "NO\r\n"}, {"input": "1\r\n5 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20010 South\r\n19990 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n20000 South\r\n1 South\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n2 North\r\n39999 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n10 South\r\n20 North\r\n10 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n2 North\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n2000 South\r\n19000 South\r\n19000 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n15000 South\r\n15000 South\r\n15000 South\r\n15000 North\r\n15000 North\r\n15000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n1 North\r\n1 East\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 West\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n123456 West\r\n1 North\r\n", "output": "YES\r\n"}]
false
stdio
null
true
858/E
858
E
Python 3
TESTS
2
77
819,200
31102053
import random def genTemp(): sl = "" firstTime = True while firstTime or sl in pre or sl in post: sl = "" firstTime = False for i in range(6): sl += chr(random.randint(ord("a"), ord("z"))) return sl n = int(input()) e = 0 pre = set() post = set() for i in range(n): name, tp = input().split() if tp == "1": e += 1 pre.add(name) else: post.add(name) temp = genTemp() preAns = {str(x) for x in range(1, e + 1)} postAns = {str(x) for x in range(e + 1, n + 1)} preMissing = preAns - pre postMissing = postAns - post preNeed = pre - preAns postNeed = post - postAns preWrong = postAns & preNeed postWrong = preAns & postNeed d = min(len(preWrong), len(postWrong)) print(d + len(preNeed) + len(postNeed)) while preWrong and postWrong: # bad, using temp x = preWrong.pop() y = postWrong.pop() print("move", x, temp) print("move", y, x) print("move", temp, y) preNeed.discard(x) postNeed.discard(y) preMissing.discard(y) postMissing.discard(x) while preNeed: x = preNeed.pop() y = preMissing.pop() print("move", x, y) while postNeed: x = postNeed.pop() y = postMissing.pop() print("move", x, y)
165
295
27,136,000
230751905
n = int(input()) t = [1] + [0] * n b, a = d = [], [] h, s = [], [] for i in range(n): f, k = input().split() d[int(k)].append(f) m = len(a) for i in a: if i.isdigit() and i[0] != '0': j = int(i) if 0 < j <= m: t[j] = 1 elif m < j <= n: t[j] = -1 else: s.append(i) else: s.append(i) for i in b: if i.isdigit() and i[0] != '0': j = int(i) if m < j <= n: t[j] = 1 elif 0 < j <= m: t[j] = -1 else: s.append(i) else: s.append(i) x = [j for j in range(1, m + 1) if t[j] < 0] y = [j for j in range(m + 1, n + 1) if t[j] < 0] u = [j for j in range(1, m + 1) if not t[j]] v = [j for j in range(m + 1, n + 1) if not t[j]] if not s and (x or y): s = ['0'] if y: i = y.pop() v.append(i) else: i = x.pop() u.append(i) h.append(str(i) + ' 0') t[i] = 0 while x or y: if v and x: i = x.pop() j = v.pop() t[j] = 1 h.append(str(i) + ' ' + str(j)) u.append(i) else: u, v, x, y = v, u, y, x k = 1 for j in s: while t[k] == 1: k += 1 h.append(j + ' ' + str(k)) k += 1 d = '\nmove ' print(str(len(h)) + d + d.join(h) if h else 0)
Технокубок 2018 - Отборочный Раунд 1
CF
2,017
2
256
Tests Renumeration
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website. Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic. Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests. Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only. The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command. Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run: - all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples; - all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests.
The first line contains single integer n (1 ≤ n ≤ 105) — the number of files with tests. n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct.
In the first line print the minimum number of lines in Vladimir's script file. After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6.
null
null
[{"input": "5\n01 0\n2 1\n2extra 0\n3 1\n99 0", "output": "4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3"}, {"input": "2\n1 0\n2 1", "output": "3\nmove 1 3\nmove 2 1\nmove 3 2"}, {"input": "5\n1 0\n11 1\n111 0\n1111 1\n11111 0", "output": "5\nmove 1 5\nmove 11 1\nmove 1111 2\nmove 111 4\nmove 11111 3"}]
2,200
["greedy", "implementation"]
165
[{"input": "5\r\n01 0\r\n2 1\r\n2extra 0\r\n3 1\r\n99 0\r\n", "output": "4\r\nmove 3 1\r\nmove 01 5\r\nmove 2extra 4\r\nmove 99 3\r\n"}, {"input": "2\r\n1 0\r\n2 1\r\n", "output": "3\r\nmove 1 dytuig\r\nmove 2 1\r\nmove dytuig 2\r\n"}, {"input": "5\r\n1 0\r\n11 1\r\n111 0\r\n1111 1\r\n11111 0\r\n", "output": "5\r\nmove 1 5\r\nmove 11 1\r\nmove 1111 2\r\nmove 111 4\r\nmove 11111 3\r\n"}, {"input": "4\r\nir7oz8 1\r\nvj4v5t 1\r\nkwkahb 1\r\nj5s8o1 0\r\n", "output": "4\r\nmove ir7oz8 1\r\nmove vj4v5t 2\r\nmove kwkahb 3\r\nmove j5s8o1 4\r\n"}, {"input": "4\r\n3 1\r\n1o0bp2 0\r\n9tn379 0\r\nv04v6j 1\r\n", "output": "4\r\nmove 3 1\r\nmove v04v6j 2\r\nmove 1o0bp2 4\r\nmove 9tn379 3\r\n"}, {"input": "4\r\n1 0\r\nsc7czx 0\r\nfr4033 1\r\n3 0\r\n", "output": "3\r\nmove 1 4\r\nmove fr4033 1\r\nmove sc7czx 2\r\n"}, {"input": "4\r\n4 0\r\n1 0\r\n2 0\r\nizfotg 1\r\n", "output": "2\r\nmove 1 3\r\nmove izfotg 1\r\n"}, {"input": "4\r\n2 0\r\n3 0\r\n1 1\r\n4 1\r\n", "output": "3\r\nmove 2 0b9r8j\r\nmove 4 2\r\nmove 0b9r8j 4\r\n"}, {"input": "5\r\npuusew 1\r\npvoy4h 0\r\nwdzx4r 0\r\n1z84cx 0\r\nozsuvd 0\r\n", "output": "5\r\nmove puusew 1\r\nmove pvoy4h 5\r\nmove wdzx4r 4\r\nmove 1z84cx 3\r\nmove ozsuvd 2\r\n"}, {"input": "5\r\n949pnr 1\r\n9sxhcr 0\r\n5 1\r\nx8srx3 1\r\ncl7ppd 1\r\n", "output": "5\r\nmove 5 1\r\nmove 949pnr 2\r\nmove x8srx3 3\r\nmove cl7ppd 4\r\nmove 9sxhcr 5\r\n"}, {"input": "5\r\n2 0\r\n1 0\r\np2gcxf 1\r\nwfyoiq 1\r\nzjw3vg 1\r\n", "output": "5\r\nmove 2 5\r\nmove 1 4\r\nmove p2gcxf 1\r\nmove wfyoiq 2\r\nmove zjw3vg 3\r\n"}, {"input": "5\r\nogvgi7 0\r\n3 1\r\n4 1\r\n1 1\r\nm5nhux 0\r\n", "output": "3\r\nmove 4 2\r\nmove ogvgi7 5\r\nmove m5nhux 4\r\n"}, {"input": "5\r\nt6kdte 1\r\n2 1\r\n4 1\r\n5 1\r\n3 1\r\n", "output": "1\r\nmove t6kdte 1\r\n"}, {"input": "5\r\n2 0\r\n3 1\r\n4 0\r\n1 1\r\n5 1\r\n", "output": "3\r\nmove 2 p6w7mu\r\nmove 5 2\r\nmove p6w7mu 5\r\n"}, {"input": "1\r\nsd84r7 1\r\n", "output": "1\r\nmove sd84r7 1\r\n"}, {"input": "1\r\n1 0\r\n", "output": "0\r\n"}, {"input": "2\r\n5xzjm4 0\r\njoa6mr 1\r\n", "output": "2\r\nmove joa6mr 1\r\nmove 5xzjm4 2\r\n"}, {"input": "2\r\n1 0\r\nxdkh5a 1\r\n", "output": "2\r\nmove 1 2\r\nmove xdkh5a 1\r\n"}, {"input": "2\r\n1 0\r\n2 0\r\n", "output": "0\r\n"}, {"input": "3\r\nz1nwrd 1\r\nt0xrja 0\r\n106qy1 0\r\n", "output": "3\r\nmove z1nwrd 1\r\nmove t0xrja 3\r\nmove 106qy1 2\r\n"}, {"input": "3\r\nt4hdos 0\r\ndhje0g 0\r\n3 0\r\n", "output": "2\r\nmove t4hdos 2\r\nmove dhje0g 1\r\n"}, {"input": "3\r\n3 0\r\n26mp5s 0\r\n1 1\r\n", "output": "1\r\nmove 26mp5s 2\r\n"}, {"input": "3\r\n2 1\r\n1 0\r\n3 0\r\n", "output": "3\r\nmove 2 1ntx05\r\nmove 1 2\r\nmove 1ntx05 1\r\n"}, {"input": "1\r\nprzvln 0\r\n", "output": "1\r\nmove przvln 1\r\n"}, {"input": "2\r\nkfsipl 0\r\n1jj1ol 0\r\n", "output": "2\r\nmove kfsipl 2\r\nmove 1jj1ol 1\r\n"}, {"input": "3\r\n2x7a4g 0\r\n27lqe6 0\r\nzfo3sp 0\r\n", "output": "3\r\nmove 2x7a4g 3\r\nmove 27lqe6 2\r\nmove zfo3sp 1\r\n"}, {"input": "1\r\nxzp9ni 1\r\n", "output": "1\r\nmove xzp9ni 1\r\n"}, {"input": "1\r\nabbdf7 1\r\n", "output": "1\r\nmove abbdf7 1\r\n"}, {"input": "2\r\ndbif39 1\r\ne8dkf8 0\r\n", "output": "2\r\nmove dbif39 1\r\nmove e8dkf8 2\r\n"}, {"input": "2\r\n2 0\r\njkwekx 1\r\n", "output": "1\r\nmove jkwekx 1\r\n"}, {"input": "3\r\nn3pmj8 0\r\n2alui6 0\r\ne7lf4u 1\r\n", "output": "3\r\nmove e7lf4u 1\r\nmove n3pmj8 3\r\nmove 2alui6 2\r\n"}, {"input": "3\r\ndr1lp8 0\r\n1 0\r\n6a2egk 1\r\n", "output": "3\r\nmove 1 3\r\nmove 6a2egk 1\r\nmove dr1lp8 2\r\n"}, {"input": "4\r\nyi9ta0 1\r\nmeljgm 0\r\nf7bqon 0\r\n5bbvun 0\r\n", "output": "4\r\nmove yi9ta0 1\r\nmove meljgm 4\r\nmove f7bqon 3\r\nmove 5bbvun 2\r\n"}, {"input": "4\r\n0la3gu 0\r\nzhrmyb 1\r\n3iprc0 0\r\n3 0\r\n", "output": "3\r\nmove zhrmyb 1\r\nmove 0la3gu 4\r\nmove 3iprc0 2\r\n"}, {"input": "1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n17dgbb 0\r\n2 1\r\n", "output": "2\r\nmove 2 1\r\nmove 17dgbb 2\r\n"}, {"input": "2\r\n1 0\r\n2 1\r\n", "output": "3\r\nmove 1 xrjgjv\r\nmove 2 1\r\nmove xrjgjv 2\r\n"}, {"input": "3\r\nscrn8k 0\r\n3 1\r\nycvm9s 0\r\n", "output": "3\r\nmove 3 1\r\nmove scrn8k 3\r\nmove ycvm9s 2\r\n"}, {"input": "3\r\nt0dfz3 0\r\n3 0\r\n1 1\r\n", "output": "1\r\nmove t0dfz3 2\r\n"}, {"input": "4\r\nkgw83p 0\r\np3p3ch 0\r\n4 1\r\n0te9lv 0\r\n", "output": "4\r\nmove 4 1\r\nmove kgw83p 4\r\nmove p3p3ch 3\r\nmove 0te9lv 2\r\n"}, {"input": "4\r\n3 1\r\nnj94jx 0\r\n3a5ad1 0\r\n1 0\r\n", "output": "4\r\nmove 1 4\r\nmove 3 1\r\nmove nj94jx 3\r\nmove 3a5ad1 2\r\n"}, {"input": "2\r\no9z069 1\r\n5hools 1\r\n", "output": "2\r\nmove o9z069 1\r\nmove 5hools 2\r\n"}, {"input": "2\r\nyzzyab 1\r\n728oq0 1\r\n", "output": "2\r\nmove yzzyab 1\r\nmove 728oq0 2\r\n"}, {"input": "2\r\nqy2kmc 1\r\nqb4crj 1\r\n", "output": "2\r\nmove qy2kmc 1\r\nmove qb4crj 2\r\n"}, {"input": "3\r\nunw560 1\r\n0iswxk 0\r\ndonjp9 1\r\n", "output": "3\r\nmove unw560 1\r\nmove donjp9 2\r\nmove 0iswxk 3\r\n"}, {"input": "3\r\n2 0\r\nuv8c54 1\r\n508bb0 1\r\n", "output": "3\r\nmove 2 3\r\nmove uv8c54 1\r\nmove 508bb0 2\r\n"}, {"input": "3\r\n9afh0z 1\r\n0qcaht 1\r\n3 0\r\n", "output": "2\r\nmove 9afh0z 1\r\nmove 0qcaht 2\r\n"}, {"input": "4\r\n2kk04q 0\r\nkdktvk 1\r\nc4i5k8 1\r\nawaock 0\r\n", "output": "4\r\nmove kdktvk 1\r\nmove c4i5k8 2\r\nmove 2kk04q 4\r\nmove awaock 3\r\n"}, {"input": "4\r\n2 0\r\nmqbjos 0\r\n6mhijg 1\r\n6wum8y 1\r\n", "output": "4\r\nmove 2 4\r\nmove 6mhijg 1\r\nmove 6wum8y 2\r\nmove mqbjos 3\r\n"}, {"input": "4\r\n4 0\r\npa613p 1\r\nuuizq7 1\r\n2 0\r\n", "output": "3\r\nmove 2 3\r\nmove pa613p 1\r\nmove uuizq7 2\r\n"}, {"input": "5\r\nw0g96a 1\r\nv99tdi 0\r\nmywrle 0\r\nweh22w 1\r\n9hywt4 0\r\n", "output": "5\r\nmove w0g96a 1\r\nmove weh22w 2\r\nmove v99tdi 5\r\nmove mywrle 4\r\nmove 9hywt4 3\r\n"}, {"input": "5\r\n5 0\r\n12qcjd 1\r\nuthzbz 0\r\nb3670z 0\r\nl2u93o 1\r\n", "output": "4\r\nmove 12qcjd 1\r\nmove l2u93o 2\r\nmove uthzbz 4\r\nmove b3670z 3\r\n"}, {"input": "5\r\n0jc7xb 1\r\n2 0\r\n1m7l9s 0\r\n9xzkau 1\r\n1 0\r\n", "output": "5\r\nmove 2 5\r\nmove 1 4\r\nmove 0jc7xb 1\r\nmove 9xzkau 2\r\nmove 1m7l9s 3\r\n"}, {"input": "2\r\n1 1\r\nvinxur 1\r\n", "output": "1\r\nmove vinxur 2\r\n"}, {"input": "2\r\n1qe46n 1\r\n1 1\r\n", "output": "1\r\nmove 1qe46n 2\r\n"}, {"input": "2\r\n1 1\r\ng5jlzp 1\r\n", "output": "1\r\nmove g5jlzp 2\r\n"}, {"input": "3\r\nc8p28p 1\r\n2 1\r\nvk4gdf 0\r\n", "output": "2\r\nmove c8p28p 1\r\nmove vk4gdf 3\r\n"}, {"input": "3\r\n2 1\r\n3 0\r\nhs9j9t 1\r\n", "output": "1\r\nmove hs9j9t 1\r\n"}, {"input": "3\r\n2 1\r\n1 0\r\nomitxh 1\r\n", "output": "2\r\nmove 1 3\r\nmove omitxh 1\r\n"}, {"input": "4\r\n4 1\r\nu9do88 1\r\n787at9 0\r\nfcud6k 0\r\n", "output": "4\r\nmove 4 1\r\nmove u9do88 2\r\nmove 787at9 4\r\nmove fcud6k 3\r\n"}, {"input": "4\r\n3 0\r\nqvw4ow 1\r\nne0ng9 0\r\n1 1\r\n", "output": "2\r\nmove qvw4ow 2\r\nmove ne0ng9 4\r\n"}, {"input": "4\r\ng6ugrm 1\r\n1 1\r\n3 0\r\n2 0\r\n", "output": "2\r\nmove 2 4\r\nmove g6ugrm 2\r\n"}, {"input": "5\r\n5 1\r\nz9zr7d 0\r\ne8rwo4 1\r\nrfpjp6 0\r\ngz6dhj 0\r\n", "output": "5\r\nmove 5 1\r\nmove e8rwo4 2\r\nmove z9zr7d 5\r\nmove rfpjp6 4\r\nmove gz6dhj 3\r\n"}, {"input": "5\r\n5sn77g 0\r\nsetddt 1\r\nbz16cb 0\r\n4 1\r\n2 0\r\n", "output": "5\r\nmove 4 1\r\nmove 2 5\r\nmove setddt 2\r\nmove 5sn77g 4\r\nmove bz16cb 3\r\n"}, {"input": "5\r\n1 1\r\nx2miqh 1\r\n3 0\r\n2 0\r\n1rq643 0\r\n", "output": "3\r\nmove 2 5\r\nmove x2miqh 2\r\nmove 1rq643 4\r\n"}, {"input": "2\r\n1 1\r\n2 1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n2 1\r\n", "output": "0\r\n"}, {"input": "2\r\n2 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1\r\nav5vex 0\r\n1 1\r\n", "output": "2\r\nmove 3 2\r\nmove av5vex 3\r\n"}, {"input": "3\r\n3 1\r\n1 0\r\n2 1\r\n", "output": "3\r\nmove 3 fopgrb\r\nmove 1 3\r\nmove fopgrb 1\r\n"}, {"input": "3\r\n3 1\r\n1 0\r\n2 1\r\n", "output": "3\r\nmove 3 wzgsm0\r\nmove 1 3\r\nmove wzgsm0 1\r\n"}, {"input": "4\r\ny9144q 0\r\n3 1\r\n2 1\r\ns0bdnf 0\r\n", "output": "3\r\nmove 3 1\r\nmove y9144q 4\r\nmove s0bdnf 3\r\n"}, {"input": "4\r\n4 1\r\n1 0\r\n3 1\r\nmod9zl 0\r\n", "output": "4\r\nmove 4 2\r\nmove 1 4\r\nmove 3 1\r\nmove mod9zl 3\r\n"}, {"input": "4\r\n4 1\r\n3 1\r\n1 0\r\n2 0\r\n", "output": "5\r\nmove 4 ow3q4a\r\nmove 1 4\r\nmove 3 1\r\nmove 2 3\r\nmove ow3q4a 2\r\n"}, {"input": "5\r\n1 1\r\nnoidnv 0\r\n3 1\r\nx3xiiz 0\r\n1lfa9v 0\r\n", "output": "4\r\nmove 3 2\r\nmove noidnv 5\r\nmove x3xiiz 4\r\nmove 1lfa9v 3\r\n"}, {"input": "5\r\n1 1\r\nvsyajx 0\r\n783b38 0\r\n4 0\r\n2 1\r\n", "output": "2\r\nmove vsyajx 5\r\nmove 783b38 3\r\n"}, {"input": "5\r\n3 1\r\n5 0\r\ncvfl8i 0\r\n4 1\r\n2 0\r\n", "output": "4\r\nmove 3 1\r\nmove 2 3\r\nmove 4 2\r\nmove cvfl8i 4\r\n"}, {"input": "3\r\nbxo0pe 1\r\nbt50pa 1\r\n2tx68t 1\r\n", "output": "3\r\nmove bxo0pe 1\r\nmove bt50pa 2\r\nmove 2tx68t 3\r\n"}, {"input": "3\r\nj9rnac 1\r\noetwfz 1\r\nd6n3ww 1\r\n", "output": "3\r\nmove j9rnac 1\r\nmove oetwfz 2\r\nmove d6n3ww 3\r\n"}, {"input": "3\r\naf2f6j 1\r\nmjni5l 1\r\njvyxgc 1\r\n", "output": "3\r\nmove af2f6j 1\r\nmove mjni5l 2\r\nmove jvyxgc 3\r\n"}, {"input": "3\r\nr2qlj2 1\r\nt8wf1y 1\r\nigids8 1\r\n", "output": "3\r\nmove r2qlj2 1\r\nmove t8wf1y 2\r\nmove igids8 3\r\n"}, {"input": "4\r\nuilh9a 0\r\n4lxxh9 1\r\nkqdpzy 1\r\nn1d7hd 1\r\n", "output": "4\r\nmove 4lxxh9 1\r\nmove kqdpzy 2\r\nmove n1d7hd 3\r\nmove uilh9a 4\r\n"}, {"input": "4\r\n3 0\r\niipymv 1\r\nvakd5b 1\r\n2ktczv 1\r\n", "output": "4\r\nmove 3 4\r\nmove iipymv 1\r\nmove vakd5b 2\r\nmove 2ktczv 3\r\n"}, {"input": "4\r\nq4b449 1\r\n3 0\r\ncjg1x2 1\r\ne878er 1\r\n", "output": "4\r\nmove 3 4\r\nmove q4b449 1\r\nmove cjg1x2 2\r\nmove e878er 3\r\n"}, {"input": "4\r\n9f4aoa 1\r\n4 0\r\nf4m1ec 1\r\nqyr2h6 1\r\n", "output": "3\r\nmove 9f4aoa 1\r\nmove f4m1ec 2\r\nmove qyr2h6 3\r\n"}, {"input": "5\r\n73s1nt 1\r\nsbngv2 0\r\n4n3qri 1\r\nbyhzp8 1\r\nadpjs4 0\r\n", "output": "5\r\nmove 73s1nt 1\r\nmove 4n3qri 2\r\nmove byhzp8 3\r\nmove sbngv2 5\r\nmove adpjs4 4\r\n"}, {"input": "5\r\n7ajg8o 1\r\np7cqxy 1\r\n3qrp34 0\r\nh93m07 1\r\n2 0\r\n", "output": "5\r\nmove 2 5\r\nmove 7ajg8o 1\r\nmove p7cqxy 2\r\nmove h93m07 3\r\nmove 3qrp34 4\r\n"}, {"input": "5\r\ny0wnwz 1\r\n5 0\r\n0totai 1\r\n1 0\r\nym8xwz 1\r\n", "output": "4\r\nmove 1 4\r\nmove y0wnwz 1\r\nmove 0totai 2\r\nmove ym8xwz 3\r\n"}, {"input": "5\r\n5 0\r\n4 0\r\n5nvzu4 1\r\nvkpzzk 1\r\nzamzcz 1\r\n", "output": "3\r\nmove 5nvzu4 1\r\nmove vkpzzk 2\r\nmove zamzcz 3\r\n"}, {"input": "6\r\np1wjw9 1\r\nueksby 0\r\nu1ixfc 1\r\nj3lk2e 1\r\n36iskv 0\r\n9imqi1 0\r\n", "output": "6\r\nmove p1wjw9 1\r\nmove u1ixfc 2\r\nmove j3lk2e 3\r\nmove ueksby 6\r\nmove 36iskv 5\r\nmove 9imqi1 4\r\n"}, {"input": "6\r\n6slonw 1\r\nptk9mc 1\r\n57a4nq 0\r\nhiq2f7 1\r\n2 0\r\nc0gtv3 0\r\n", "output": "6\r\nmove 2 6\r\nmove 6slonw 1\r\nmove ptk9mc 2\r\nmove hiq2f7 3\r\nmove 57a4nq 5\r\nmove c0gtv3 4\r\n"}, {"input": "6\r\n5 0\r\n2 0\r\ncbhvyf 1\r\nl1z5mg 0\r\nwkwhby 1\r\nx7fdh9 1\r\n", "output": "5\r\nmove 2 6\r\nmove cbhvyf 1\r\nmove wkwhby 2\r\nmove x7fdh9 3\r\nmove l1z5mg 4\r\n"}, {"input": "6\r\n1t68ks 1\r\npkbj1g 1\r\n5 0\r\n5pw8wm 1\r\n1 0\r\n4 0\r\n", "output": "4\r\nmove 1 6\r\nmove 1t68ks 1\r\nmove pkbj1g 2\r\nmove 5pw8wm 3\r\n"}, {"input": "3\r\n1 1\r\n7ph5fw 1\r\ntfxz1j 1\r\n", "output": "2\r\nmove 7ph5fw 2\r\nmove tfxz1j 3\r\n"}, {"input": "3\r\norwsz0 1\r\nmbt097 1\r\n3 1\r\n", "output": "2\r\nmove orwsz0 1\r\nmove mbt097 2\r\n"}, {"input": "3\r\n1 1\r\nzwfnx2 1\r\n7g8t6z 1\r\n", "output": "2\r\nmove zwfnx2 2\r\nmove 7g8t6z 3\r\n"}, {"input": "3\r\nqmf7iz 1\r\ndjwdce 1\r\n1 1\r\n", "output": "2\r\nmove qmf7iz 2\r\nmove djwdce 3\r\n"}, {"input": "4\r\n4i2i2a 0\r\n4 1\r\npf618n 1\r\nlx6nmh 1\r\n", "output": "4\r\nmove 4 1\r\nmove pf618n 2\r\nmove lx6nmh 3\r\nmove 4i2i2a 4\r\n"}, {"input": "4\r\nxpteku 1\r\n1 0\r\n4 1\r\n73xpqz 1\r\n", "output": "4\r\nmove 4 2\r\nmove 1 4\r\nmove xpteku 1\r\nmove 73xpqz 3\r\n"}, {"input": "4\r\n1wp56i 1\r\n2 1\r\n1 0\r\n6m76jb 1\r\n", "output": "3\r\nmove 1 4\r\nmove 1wp56i 1\r\nmove 6m76jb 3\r\n"}, {"input": "4\r\n3 1\r\nyumiqt 1\r\n1 0\r\nt19jus 1\r\n", "output": "3\r\nmove 1 4\r\nmove yumiqt 1\r\nmove t19jus 2\r\n"}, {"input": "5\r\nynagvf 1\r\n3 1\r\nojz4mm 1\r\ndovec3 0\r\nnc1jye 0\r\n", "output": "4\r\nmove ynagvf 1\r\nmove ojz4mm 2\r\nmove dovec3 5\r\nmove nc1jye 4\r\n"}, {"input": "5\r\n5 1\r\nwje9ts 1\r\nkytn5q 1\r\n7frk8z 0\r\n3 0\r\n", "output": "5\r\nmove 5 1\r\nmove 3 5\r\nmove wje9ts 2\r\nmove kytn5q 3\r\nmove 7frk8z 4\r\n"}, {"input": "5\r\n1 0\r\n4 1\r\n3 0\r\nlog9cm 1\r\nu5m0ls 1\r\n", "output": "5\r\nmove 4 2\r\nmove 1 5\r\nmove 3 4\r\nmove log9cm 1\r\nmove u5m0ls 3\r\n"}, {"input": "5\r\nh015vv 1\r\n3 1\r\n1 0\r\n9w2keb 1\r\n2 0\r\n", "output": "4\r\nmove 1 5\r\nmove 2 4\r\nmove h015vv 1\r\nmove 9w2keb 2\r\n"}, {"input": "6\r\n0zluka 0\r\nqp7q8l 1\r\nwglqu8 1\r\n9i7kta 0\r\nnwf8m3 0\r\n3 1\r\n", "output": "5\r\nmove qp7q8l 1\r\nmove wglqu8 2\r\nmove 0zluka 6\r\nmove 9i7kta 5\r\nmove nwf8m3 4\r\n"}, {"input": "6\r\n3 1\r\n1h3t85 1\r\n5 0\r\nrf2ikt 0\r\n3vhl6e 1\r\n5l3oka 0\r\n", "output": "4\r\nmove 1h3t85 1\r\nmove 3vhl6e 2\r\nmove rf2ikt 6\r\nmove 5l3oka 4\r\n"}, {"input": "6\r\n2 0\r\n3 0\r\nw9h0pv 1\r\n5 1\r\nq92z4i 0\r\n6qb4ia 1\r\n", "output": "6\r\nmove 5 1\r\nmove 2 6\r\nmove 3 5\r\nmove w9h0pv 2\r\nmove 6qb4ia 3\r\nmove q92z4i 4\r\n"}, {"input": "6\r\n4 1\r\n410jiy 1\r\n1 0\r\n6 0\r\nxc98l2 1\r\n5 0\r\n", "output": "4\r\nmove 4 2\r\nmove 1 4\r\nmove 410jiy 1\r\nmove xc98l2 3\r\n"}, {"input": "3\r\n1 1\r\nc9qyld 1\r\n3 1\r\n", "output": "1\r\nmove c9qyld 2\r\n"}, {"input": "3\r\ngdm5ri 1\r\n1 1\r\n2 1\r\n", "output": "1\r\nmove gdm5ri 3\r\n"}, {"input": "3\r\n3 1\r\n2 1\r\ni19lnk 1\r\n", "output": "1\r\nmove i19lnk 1\r\n"}, {"input": "3\r\ncxbbpd 1\r\n3 1\r\n1 1\r\n", "output": "1\r\nmove cxbbpd 2\r\n"}, {"input": "4\r\nwy6i6o 0\r\n1 1\r\n3 1\r\niy1dq6 1\r\n", "output": "2\r\nmove iy1dq6 2\r\nmove wy6i6o 4\r\n"}, {"input": "4\r\n4 1\r\nwgh8s0 1\r\n1 0\r\n2 1\r\n", "output": "3\r\nmove 4 3\r\nmove 1 4\r\nmove wgh8s0 1\r\n"}, {"input": "4\r\nhex0ur 1\r\n4 1\r\n3 0\r\n2 1\r\n", "output": "3\r\nmove 4 1\r\nmove 3 4\r\nmove hex0ur 3\r\n"}, {"input": "4\r\n4 1\r\n1 1\r\n3 0\r\n4soxj3 1\r\n", "output": "3\r\nmove 4 2\r\nmove 3 4\r\nmove 4soxj3 3\r\n"}, {"input": "5\r\n5sbtul 1\r\n2 1\r\n8i2duz 0\r\n5 1\r\n4b85z6 0\r\n", "output": "4\r\nmove 5 1\r\nmove 5sbtul 3\r\nmove 8i2duz 5\r\nmove 4b85z6 4\r\n"}, {"input": "5\r\n3 1\r\n4 0\r\nejo0a4 1\r\ngqzdbk 0\r\n1 1\r\n", "output": "2\r\nmove ejo0a4 2\r\nmove gqzdbk 5\r\n"}, {"input": "5\r\n2y4agr 1\r\n5 0\r\n3 0\r\n1 1\r\n4 1\r\n", "output": "3\r\nmove 4 2\r\nmove 3 4\r\nmove 2y4agr 3\r\n"}, {"input": "5\r\n2 0\r\n1 1\r\nq4hyeg 1\r\n5 0\r\n4 1\r\n", "output": "3\r\nmove 4 3\r\nmove 2 4\r\nmove q4hyeg 2\r\n"}, {"input": "6\r\n5 1\r\nrdm6fu 0\r\n4 1\r\noclx1h 0\r\n7l3kg1 1\r\nq25te0 0\r\n", "output": "6\r\nmove 5 1\r\nmove 4 2\r\nmove 7l3kg1 3\r\nmove rdm6fu 6\r\nmove oclx1h 5\r\nmove q25te0 4\r\n"}, {"input": "6\r\n1 0\r\np4tuyt 0\r\n5 1\r\n2 1\r\nwrrcmu 1\r\n3r4wqz 0\r\n", "output": "5\r\nmove 5 3\r\nmove 1 6\r\nmove wrrcmu 1\r\nmove p4tuyt 5\r\nmove 3r4wqz 4\r\n"}, {"input": "6\r\n5 1\r\n6 0\r\nxhfzge 0\r\n3 1\r\n1 0\r\n1n9mqv 1\r\n", "output": "4\r\nmove 5 2\r\nmove 1 5\r\nmove 1n9mqv 1\r\nmove xhfzge 4\r\n"}, {"input": "6\r\nhmpfsz 1\r\n6 0\r\n5 1\r\n4 0\r\n1 0\r\n3 1\r\n", "output": "3\r\nmove 5 2\r\nmove 1 5\r\nmove hmpfsz 1\r\n"}, {"input": "3\r\n1 1\r\n3 1\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n2 1\r\n3 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n2 1\r\n1 1\r\n3 1\r\n", "output": "0\r\n"}, {"input": "3\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "0\r\n"}, {"input": "4\r\n3 1\r\n1 1\r\n4 1\r\nd1cks2 0\r\n", "output": "2\r\nmove 4 2\r\nmove d1cks2 4\r\n"}, {"input": "4\r\n4 0\r\n3 1\r\n1 1\r\n2 1\r\n", "output": "0\r\n"}, {"input": "4\r\n2 1\r\n4 1\r\n1 0\r\n3 1\r\n", "output": "3\r\nmove 4 e15gvb\r\nmove 1 4\r\nmove e15gvb 1\r\n"}, {"input": "4\r\n4 1\r\n1 1\r\n3 1\r\n2 0\r\n", "output": "3\r\nmove 4 7l41cc\r\nmove 2 4\r\nmove 7l41cc 2\r\n"}, {"input": "5\r\n4 1\r\nhvshea 0\r\naio11n 0\r\n2 1\r\n3 1\r\n", "output": "3\r\nmove 4 1\r\nmove hvshea 5\r\nmove aio11n 4\r\n"}, {"input": "5\r\n5 0\r\nts7a1c 0\r\n4 1\r\n1 1\r\n2 1\r\n", "output": "2\r\nmove 4 3\r\nmove ts7a1c 4\r\n"}, {"input": "5\r\n4 0\r\n3 1\r\n5 0\r\n2 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "5\r\n3 1\r\n5 0\r\n4 1\r\n1 1\r\n2 0\r\n", "output": "3\r\nmove 4 kmnhgt\r\nmove 2 4\r\nmove kmnhgt 2\r\n"}, {"input": "6\r\neik3kw 0\r\n5 1\r\nzoonoj 0\r\n2 1\r\n1 1\r\nivzfie 0\r\n", "output": "4\r\nmove 5 3\r\nmove eik3kw 6\r\nmove zoonoj 5\r\nmove ivzfie 4\r\n"}, {"input": "6\r\n7igwk9 0\r\n6 1\r\n5 1\r\ndx2yu0 0\r\n2 0\r\n1 1\r\n", "output": "5\r\nmove 6 3\r\nmove 2 6\r\nmove 5 2\r\nmove 7igwk9 5\r\nmove dx2yu0 4\r\n"}, {"input": "6\r\nc3py3h 0\r\n2 1\r\n4 0\r\n3 0\r\n1 1\r\n5 1\r\n", "output": "3\r\nmove 3 6\r\nmove 5 3\r\nmove c3py3h 5\r\n"}, {"input": "6\r\n1 1\r\n3 0\r\n2 1\r\n6 1\r\n4 0\r\n5 0\r\n", "output": "3\r\nmove 3 4r6zp7\r\nmove 6 3\r\nmove 4r6zp7 6\r\n"}, {"input": "20\r\nphp8vy 1\r\nkeeona 0\r\n8 0\r\nwzf4eb 0\r\n16 1\r\n9 0\r\nf2548d 0\r\n11 0\r\nyszsig 0\r\nyyf4q2 0\r\n1pon1p 1\r\njvpwuo 0\r\nd9stsx 0\r\ne14bkx 1\r\n5 0\r\n17 0\r\nsbklx4 0\r\nsfms2u 1\r\n6 0\r\n18 1\r\n", "output": "16\r\nmove 16 1\r\nmove 18 2\r\nmove 5 20\r\nmove 6 19\r\nmove php8vy 3\r\nmove 1pon1p 4\r\nmove e14bkx 5\r\nmove sfms2u 6\r\nmove keeona 18\r\nmove wzf4eb 16\r\nmove f2548d 15\r\nmove yszsig 14\r\nmove yyf4q2 13\r\nmove jvpwuo 12\r\nmove d9stsx 10\r\nmove sbklx4 7\r\n"}, {"input": "4\r\n3 1\r\n4 1\r\n1 0\r\n2 0\r\n", "output": "5\r\nmove 3 41nqph\r\nmove 1 3\r\nmove 4 1\r\nmove 2 4\r\nmove 41nqph 2\r\n"}, {"input": "1\r\n01 1\r\n", "output": "1\r\nmove 01 1\r\n"}, {"input": "2\r\n01 0\r\n02 1\r\n", "output": "2\r\nmove 02 1\r\nmove 01 2\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: n = int(f.readline()) files = [] type1_count = 0 for _ in range(n): line = f.readline().strip() name, typ = line.split() files.append((name, typ)) if typ == '1': type1_count += 1 e = type1_count cnt = 0 valid_numbers = set() for name, typ in files: if name.isdigit() and (len(name) == 1 or name[0] != '0'): num = int(name) if 1 <= num <= n: valid_numbers.add(num) if typ == '1': if not name.isdigit() or (len(name) > 1 and name[0] == '0'): cnt += 1 continue num = int(name) if not (1 <= num <= e): cnt += 1 else: if not name.isdigit() or (len(name) > 1 and name[0] == '0'): cnt += 1 continue num = int(name) if not (e + 1 <= num <= n): cnt += 1 initial_free = n - len(valid_numbers) minimal_steps = cnt + 1 if (initial_free == 0 and cnt > 0) else cnt with open(submission_path) as f: lines = f.read().splitlines() if not lines: print(0) return try: k = int(lines[0]) except: print(0) return if k != minimal_steps: print(0) return moves = lines[1:] if len(moves) != k: print(0) return current_files = {name: typ for name, typ in files} for move in moves: parts = move.split() if len(parts) != 3 or parts[0] != 'move': print(0) return src, dst = parts[1], parts[2] if src not in current_files: print(0) return typ = current_files.pop(src) current_files[dst] = typ names = list(current_files.keys()) if len(names) != n: print(0) return nums = [] for name in names: if not name.isdigit() or (len(name) > 1 and name[0] == '0'): print(0) return num = int(name) if num < 1 or num > n: print(0) return nums.append(num) if sorted(nums) != list(range(1, n + 1)): print(0) return for name, typ in current_files.items(): num = int(name) if typ == '1' and num > e: print(0) return if typ == '0' and num <= e: print(0) return print(1) if __name__ == "__main__": main()
true
818/E
818
E
PyPy 3
TESTS
2
155
1,740,800
93169752
import sys def get_primes(n: int): from itertools import chain from array import array primes = {2, 3} is_prime = (array('b', (0, 0, 1, 1, 0, 1, 0)) + array('b', (1, 0, 0, 0, 1, 0))*((n-1)//6)) for i in chain.from_iterable((range(5, n+1, 6), range(7, n+1, 6))): if is_prime[i]: primes.add(i) for j in range(i*3, n+1, i*2): is_prime[j] = 0 return is_prime, primes n, k = map(int, input().split()) cards = list(map(int, input().split())) _, primes = get_primes(32000) div, div_cnt = [], [] for p in primes: if k % p == 0: div.append(p) div_cnt.append(0) while k % p == 0: div_cnt[-1] += 1 k //= p if k > 1: div.append(k) div_cnt.append(1) m = len(div) acc = [[0]*m for _ in range(n+1)] for i, x in enumerate(cards, start=1): for j in range(m): acc[i][j] += acc[i-1][j] while x % div[j] == 0: acc[i][j] += 1 x //= div[j] ans = 0 j = 0 for i in range(n): while j <= n and any(acc[j][k]-acc[i][k] < div_cnt[k] for k in range(m)): j += 1 if j > n: break ans += n - j + 1 print(ans)
135
77
13,414,400
170114604
R,G=lambda:map(int,input().split()),range n,k=R();a=[0]+[*R()];z,l,p=0,1,1 for r in G(1,n+1): p=p*a[r]%k if p==0: p=1;i=r while p*a[i]%k:p=p*a[i]%k;i-=1 z+=(n-r+1)*(i-l+1);l=i+1 print(z)
Educational Codeforces Round 24
ICPC
2,017
2
256
Card Game Again
Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number ai is written on the i-th card in the deck. After receiving the deck and the magic number, Vova removes x (possibly x = 0) cards from the top of the deck, y (possibly y = 0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards x + 1, x + 2, ... n - y - 1, n - y from the original deck. Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by k. So Vova received a deck (possibly not a valid one) and a number k, and now he wonders, how many ways are there to choose x and y so the deck he will get after removing x cards from the top and y cards from the bottom is valid?
The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers written on the cards.
Print the number of ways to choose x and y so the resulting deck is valid.
null
In the first example the possible values of x and y are: 1. x = 0, y = 0; 2. x = 1, y = 0; 3. x = 2, y = 0; 4. x = 0, y = 1.
[{"input": "3 4\n6 2 8", "output": "4"}, {"input": "3 6\n9 1 14", "output": "1"}]
1,900
["binary search", "data structures", "number theory", "two pointers"]
135
[{"input": "3 4\r\n6 2 8\r\n", "output": "4\r\n"}, {"input": "3 6\r\n9 1 14\r\n", "output": "1\r\n"}, {"input": "5 1\r\n1 3 1 3 1\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 5 5 5 5\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 4 4 4 4\r\n", "output": "15\r\n"}, {"input": "100 1\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": "5050\r\n"}, {"input": "100 1\r\n3 3 2 1 1 2 1 2 3 4 1 5 2 4 5 1 1 3 2 3 4 2 1 3 4 4 5 5 1 5 2 5 3 3 1 1 1 3 2 2 3 4 4 4 4 3 1 3 5 3 3 3 3 2 3 2 2 3 3 1 2 4 3 2 2 5 3 1 5 2 2 5 1 2 1 1 5 1 5 2 4 5 3 4 2 5 4 2 2 5 5 5 3 3 5 3 4 3 3 1\r\n", "output": "5050\r\n"}, {"input": "100 5\r\n4 4 3 2 4 4 1 2 2 1 5 3 2 5 5 3 2 3 4 5 2 2 3 4 2 4 3 1 2 3 5 5 1 3 3 5 2 3 3 4 1 3 1 5 4 4 2 1 5 1 4 4 1 5 1 1 5 5 5 4 1 3 1 2 3 2 4 5 5 1 3 4 3 3 1 2 2 4 1 5 1 1 2 4 4 4 5 5 5 3 4 3 3 3 3 2 1 1 5 5\r\n", "output": "4713\r\n"}, {"input": "100 6\r\n4 4 1 1 1 1 3 3 5 5 4 2 2 4 3 4 4 5 5 4 5 1 3 1 5 4 5 1 2 5 5 2 2 4 2 4 4 2 5 5 3 3 1 3 3 5 2 3 1 4 1 4 4 1 5 5 1 2 3 2 3 3 5 3 4 2 3 4 3 1 5 3 5 5 3 5 4 4 3 1 1 2 1 2 1 3 2 4 3 2 1 4 3 1 1 5 1 5 4 3\r\n", "output": "4580\r\n"}, {"input": "100 72\r\n8 8 7 9 6 1 4 5 3 7 5 10 5 4 1 3 4 1 3 1 6 6 4 5 4 5 6 1 10 7 9 1 6 10 6 6 9 3 3 4 5 9 4 9 8 1 5 9 3 7 1 8 5 2 1 1 7 7 7 6 6 4 2 9 10 2 8 3 1 1 4 8 5 9 7 10 9 4 2 3 7 7 6 7 8 5 1 3 8 5 1 8 9 10 3 7 1 8 10 5\r\n", "output": "4549\r\n"}, {"input": "100 72\r\n3 2 1 3 3 3 4 3 5 5 2 5 1 2 2 2 1 4 1 5 1 4 5 4 3 1 4 3 4 4 1 4 4 3 4 1 4 4 5 2 2 3 3 5 4 5 4 2 4 3 1 1 1 4 5 5 3 1 5 3 4 4 5 3 5 1 4 3 2 2 1 4 2 1 3 2 4 2 1 4 4 1 3 4 4 4 1 5 5 2 5 2 3 1 5 1 1 1 2 3\r\n", "output": "4123\r\n"}, {"input": "2 999634589\r\n31607 31627\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1\r\n", "output": "0\r\n"}, {"input": "1 3\r\n1\r\n", "output": "0\r\n"}, {"input": "1 4\r\n1\r\n", "output": "0\r\n"}, {"input": "1 5\r\n3\r\n", "output": "0\r\n"}, {"input": "1 6\r\n4\r\n", "output": "0\r\n"}, {"input": "1 7\r\n2\r\n", "output": "0\r\n"}, {"input": "1 8\r\n3\r\n", "output": "0\r\n"}, {"input": "1 9\r\n5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n3\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n", "output": "3\r\n"}, {"input": "2 2\r\n2 2\r\n", "output": "3\r\n"}, {"input": "2 3\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2 4\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2 5\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 6\r\n2 1\r\n", "output": "0\r\n"}, {"input": "2 7\r\n1 4\r\n", "output": "0\r\n"}, {"input": "2 8\r\n5 3\r\n", "output": "0\r\n"}, {"input": "2 9\r\n2 2\r\n", "output": "0\r\n"}, {"input": "2 10\r\n6 1\r\n", "output": "0\r\n"}, {"input": "3 1\r\n1 1 1\r\n", "output": "6\r\n"}, {"input": "3 2\r\n2 2 1\r\n", "output": "5\r\n"}, {"input": "3 3\r\n2 1 2\r\n", "output": "0\r\n"}, {"input": "3 4\r\n2 2 2\r\n", "output": "3\r\n"}, {"input": "3 5\r\n1 1 2\r\n", "output": "0\r\n"}, {"input": "3 6\r\n4 3 2\r\n", "output": "3\r\n"}, {"input": "3 7\r\n3 4 1\r\n", "output": "0\r\n"}, {"input": "3 8\r\n5 1 4\r\n", "output": "0\r\n"}, {"input": "3 9\r\n3 2 1\r\n", "output": "0\r\n"}, {"input": "3 10\r\n6 5 5\r\n", "output": "2\r\n"}, {"input": "4 1\r\n1 1 1 1\r\n", "output": "10\r\n"}, {"input": "4 2\r\n2 2 1 2\r\n", "output": "9\r\n"}, {"input": "4 3\r\n2 1 1 1\r\n", "output": "0\r\n"}, {"input": "4 4\r\n2 2 1 1\r\n", "output": "3\r\n"}, {"input": "4 5\r\n2 3 2 1\r\n", "output": "0\r\n"}, {"input": "4 6\r\n1 1 3 3\r\n", "output": "0\r\n"}, {"input": "4 7\r\n1 1 2 2\r\n", "output": "0\r\n"}, {"input": "4 8\r\n5 4 5 5\r\n", "output": "0\r\n"}, {"input": "4 9\r\n1 1 4 2\r\n", "output": "0\r\n"}, {"input": "4 10\r\n2 6 2 1\r\n", "output": "0\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n", "output": "15\r\n"}, {"input": "5 2\r\n2 2 1 2 1\r\n", "output": "13\r\n"}, {"input": "5 3\r\n2 1 1 2 1\r\n", "output": "0\r\n"}, {"input": "5 4\r\n2 2 1 3 1\r\n", "output": "4\r\n"}, {"input": "5 5\r\n2 3 1 1 3\r\n", "output": "0\r\n"}, {"input": "5 6\r\n3 4 3 4 3\r\n", "output": "10\r\n"}, {"input": "5 7\r\n3 1 3 2 4\r\n", "output": "0\r\n"}, {"input": "5 8\r\n2 2 3 3 1\r\n", "output": "0\r\n"}, {"input": "5 9\r\n3 1 3 3 4\r\n", "output": "7\r\n"}, {"input": "5 10\r\n3 6 6 1 5\r\n", "output": "3\r\n"}, {"input": "6 1\r\n1 1 1 1 1 1\r\n", "output": "21\r\n"}, {"input": "6 2\r\n1 2 2 1 1 1\r\n", "output": "14\r\n"}, {"input": "6 3\r\n2 2 2 2 1 2\r\n", "output": "0\r\n"}, {"input": "6 4\r\n1 3 3 3 3 2\r\n", "output": "0\r\n"}, {"input": "6 5\r\n2 3 3 2 1 2\r\n", "output": "0\r\n"}, {"input": "6 6\r\n1 2 4 1 4 4\r\n", "output": "0\r\n"}, {"input": "6 7\r\n2 2 4 3 2 1\r\n", "output": "0\r\n"}, {"input": "6 8\r\n3 2 3 5 5 3\r\n", "output": "0\r\n"}, {"input": "6 9\r\n1 4 1 2 1 1\r\n", "output": "0\r\n"}, {"input": "6 10\r\n1 2 5 6 6 6\r\n", "output": "11\r\n"}, {"input": "7 1\r\n1 1 1 1 1 1 1\r\n", "output": "28\r\n"}, {"input": "7 2\r\n1 1 2 2 2 2 1\r\n", "output": "24\r\n"}, {"input": "7 3\r\n2 2 1 1 2 2 2\r\n", "output": "0\r\n"}, {"input": "7 4\r\n3 2 1 2 1 1 1\r\n", "output": "8\r\n"}, {"input": "7 5\r\n2 3 3 3 2 3 2\r\n", "output": "0\r\n"}, {"input": "7 6\r\n3 4 4 1 4 3 2\r\n", "output": "15\r\n"}, {"input": "7 7\r\n4 2 4 4 1 4 4\r\n", "output": "0\r\n"}, {"input": "7 8\r\n4 4 2 4 2 5 3\r\n", "output": "18\r\n"}, {"input": "7 9\r\n2 1 3 4 4 5 4\r\n", "output": "0\r\n"}, {"input": "7 10\r\n6 3 3 5 3 6 1\r\n", "output": "10\r\n"}, {"input": "8 1\r\n1 1 1 1 1 1 1 1\r\n", "output": "36\r\n"}, {"input": "8 2\r\n1 1 1 1 1 1 1 2\r\n", "output": "8\r\n"}, {"input": "8 3\r\n1 1 2 2 1 1 2 2\r\n", "output": "0\r\n"}, {"input": "8 4\r\n2 3 2 3 3 3 2 3\r\n", "output": "10\r\n"}, {"input": "8 5\r\n1 3 1 2 2 2 1 3\r\n", "output": "0\r\n"}, {"input": "8 6\r\n4 2 4 2 1 2 1 4\r\n", "output": "0\r\n"}, {"input": "8 7\r\n2 2 1 4 4 4 2 2\r\n", "output": "0\r\n"}, {"input": "8 8\r\n5 2 1 2 4 2 2 4\r\n", "output": "21\r\n"}, {"input": "8 9\r\n4 4 2 2 5 5 4 1\r\n", "output": "0\r\n"}, {"input": "8 10\r\n2 1 4 4 3 4 4 6\r\n", "output": "0\r\n"}, {"input": "9 1\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "45\r\n"}, {"input": "9 2\r\n1 1 1 2 1 1 2 2 2\r\n", "output": "36\r\n"}, {"input": "9 3\r\n1 1 1 2 2 1 1 2 1\r\n", "output": "0\r\n"}, {"input": "9 4\r\n1 1 2 1 2 1 1 1 1\r\n", "output": "15\r\n"}, {"input": "9 5\r\n3 2 3 2 3 1 1 3 2\r\n", "output": "0\r\n"}, {"input": "9 6\r\n2 1 1 3 2 4 1 2 2\r\n", "output": "21\r\n"}, {"input": "9 7\r\n4 3 2 1 2 3 3 4 4\r\n", "output": "0\r\n"}, {"input": "9 8\r\n5 5 2 1 3 1 3 1 3\r\n", "output": "0\r\n"}, {"input": "9 9\r\n2 4 1 4 4 3 3 4 1\r\n", "output": "18\r\n"}, {"input": "9 10\r\n4 3 2 5 2 2 2 2 6\r\n", "output": "23\r\n"}, {"input": "10 1\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "55\r\n"}, {"input": "10 2\r\n2 2 2 2 2 2 2 1 2 1\r\n", "output": "53\r\n"}, {"input": "10 3\r\n2 2 1 1 2 2 2 2 1 2\r\n", "output": "0\r\n"}, {"input": "10 4\r\n1 1 2 3 3 1 2 2 2 3\r\n", "output": "26\r\n"}, {"input": "10 5\r\n3 3 2 2 3 1 1 1 3 1\r\n", "output": "0\r\n"}, {"input": "10 6\r\n4 4 4 3 2 1 1 1 2 4\r\n", "output": "27\r\n"}, {"input": "10 7\r\n4 2 2 2 3 3 2 4 4 3\r\n", "output": "0\r\n"}, {"input": "10 8\r\n5 4 1 4 3 2 1 2 3 3\r\n", "output": "24\r\n"}, {"input": "10 9\r\n1 2 3 4 5 2 3 5 5 4\r\n", "output": "12\r\n"}, {"input": "10 10\r\n5 3 2 5 1 2 5 1 5 1\r\n", "output": "35\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "1 100000000\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1000000000\r\n", "output": "1\r\n"}]
false
stdio
null
true
818/E
818
E
PyPy 3
TESTS
2
124
0
66638926
n,k=map(int,input().split()) l=list(map(int,input().split())) pf=[] needed=[] i=2 while (i*i)<=k: if k%i==0: pf.append(i) c=0 while k%i==0: k//=i c+=1 needed.append(c) i+=1 if k>1: pf.append(k) needed.append(1) pfl=len(pf) cnt=[[0]*n for i in range(pfl)] for i in range(n): for j in range(len(pf)): c=0 while l[i]%pf[j]==0: c+=1 l[i]//=pf[j] cnt[j][i]=c have=[sum(i) for i in cnt] pos=n def ok(): for i in range(len(pf)): if have[i]<needed[i]: return False return True if not ok(): print(0) quit() for i in range(n-1,-1,-1): for j in range(len(pf)): have[j]-=cnt[j][i] if not ok(): for j in range(len(pf)): have[j]+=cnt[j][i] break pos=i ans=n-pos+1 for x in range(n): if pos==x: pos+=1 else: for j in range(len(pf)): have[j]-=cnt[j][x] while pos<n: if ok(): break else: for i in range(len(pf)): have[i]+=cnt[i][pos] pos+=1 if ok(): ans+=n-pos+1 else: break print(ans)
135
373
31,744,000
127711452
import bisect import sys input = sys.stdin.readline def prime_factorize(n): ans = [] for i in range(2, int(n ** (1 / 2)) + 1): while True: if n % i: break ans.append(i) n //= i if n == 1: break if not n == 1: ans.append(n) return ans n, k = map(int, input().split()) a = list(map(int, input().split())) s = list(set(prime_factorize(k))) l = len(s) cnt = [] for i in s: cnt0 = [0] * (n + 1) c = 0 for j in range(n): aj = a[j] while not aj % i: aj //= i c += 1 cnt0[j + 1] = c cnt.append(cnt0) t = [] for i in s: c = 0 while not k % i: k //= i c += 1 t.append(c) ans = 0 for i in range(1, n + 1): m = i for j in range(l): m = min(m, bisect.bisect_left(cnt[j], cnt[j][i] - t[j] + 0.5)) ans += m print(ans)
Educational Codeforces Round 24
ICPC
2,017
2
256
Card Game Again
Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number ai is written on the i-th card in the deck. After receiving the deck and the magic number, Vova removes x (possibly x = 0) cards from the top of the deck, y (possibly y = 0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards x + 1, x + 2, ... n - y - 1, n - y from the original deck. Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by k. So Vova received a deck (possibly not a valid one) and a number k, and now he wonders, how many ways are there to choose x and y so the deck he will get after removing x cards from the top and y cards from the bottom is valid?
The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers written on the cards.
Print the number of ways to choose x and y so the resulting deck is valid.
null
In the first example the possible values of x and y are: 1. x = 0, y = 0; 2. x = 1, y = 0; 3. x = 2, y = 0; 4. x = 0, y = 1.
[{"input": "3 4\n6 2 8", "output": "4"}, {"input": "3 6\n9 1 14", "output": "1"}]
1,900
["binary search", "data structures", "number theory", "two pointers"]
135
[{"input": "3 4\r\n6 2 8\r\n", "output": "4\r\n"}, {"input": "3 6\r\n9 1 14\r\n", "output": "1\r\n"}, {"input": "5 1\r\n1 3 1 3 1\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 5 5 5 5\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 4 4 4 4\r\n", "output": "15\r\n"}, {"input": "100 1\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": "5050\r\n"}, {"input": "100 1\r\n3 3 2 1 1 2 1 2 3 4 1 5 2 4 5 1 1 3 2 3 4 2 1 3 4 4 5 5 1 5 2 5 3 3 1 1 1 3 2 2 3 4 4 4 4 3 1 3 5 3 3 3 3 2 3 2 2 3 3 1 2 4 3 2 2 5 3 1 5 2 2 5 1 2 1 1 5 1 5 2 4 5 3 4 2 5 4 2 2 5 5 5 3 3 5 3 4 3 3 1\r\n", "output": "5050\r\n"}, {"input": "100 5\r\n4 4 3 2 4 4 1 2 2 1 5 3 2 5 5 3 2 3 4 5 2 2 3 4 2 4 3 1 2 3 5 5 1 3 3 5 2 3 3 4 1 3 1 5 4 4 2 1 5 1 4 4 1 5 1 1 5 5 5 4 1 3 1 2 3 2 4 5 5 1 3 4 3 3 1 2 2 4 1 5 1 1 2 4 4 4 5 5 5 3 4 3 3 3 3 2 1 1 5 5\r\n", "output": "4713\r\n"}, {"input": "100 6\r\n4 4 1 1 1 1 3 3 5 5 4 2 2 4 3 4 4 5 5 4 5 1 3 1 5 4 5 1 2 5 5 2 2 4 2 4 4 2 5 5 3 3 1 3 3 5 2 3 1 4 1 4 4 1 5 5 1 2 3 2 3 3 5 3 4 2 3 4 3 1 5 3 5 5 3 5 4 4 3 1 1 2 1 2 1 3 2 4 3 2 1 4 3 1 1 5 1 5 4 3\r\n", "output": "4580\r\n"}, {"input": "100 72\r\n8 8 7 9 6 1 4 5 3 7 5 10 5 4 1 3 4 1 3 1 6 6 4 5 4 5 6 1 10 7 9 1 6 10 6 6 9 3 3 4 5 9 4 9 8 1 5 9 3 7 1 8 5 2 1 1 7 7 7 6 6 4 2 9 10 2 8 3 1 1 4 8 5 9 7 10 9 4 2 3 7 7 6 7 8 5 1 3 8 5 1 8 9 10 3 7 1 8 10 5\r\n", "output": "4549\r\n"}, {"input": "100 72\r\n3 2 1 3 3 3 4 3 5 5 2 5 1 2 2 2 1 4 1 5 1 4 5 4 3 1 4 3 4 4 1 4 4 3 4 1 4 4 5 2 2 3 3 5 4 5 4 2 4 3 1 1 1 4 5 5 3 1 5 3 4 4 5 3 5 1 4 3 2 2 1 4 2 1 3 2 4 2 1 4 4 1 3 4 4 4 1 5 5 2 5 2 3 1 5 1 1 1 2 3\r\n", "output": "4123\r\n"}, {"input": "2 999634589\r\n31607 31627\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1\r\n", "output": "0\r\n"}, {"input": "1 3\r\n1\r\n", "output": "0\r\n"}, {"input": "1 4\r\n1\r\n", "output": "0\r\n"}, {"input": "1 5\r\n3\r\n", "output": "0\r\n"}, {"input": "1 6\r\n4\r\n", "output": "0\r\n"}, {"input": "1 7\r\n2\r\n", "output": "0\r\n"}, {"input": "1 8\r\n3\r\n", "output": "0\r\n"}, {"input": "1 9\r\n5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n3\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n", "output": "3\r\n"}, {"input": "2 2\r\n2 2\r\n", "output": "3\r\n"}, {"input": "2 3\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2 4\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2 5\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 6\r\n2 1\r\n", "output": "0\r\n"}, {"input": "2 7\r\n1 4\r\n", "output": "0\r\n"}, {"input": "2 8\r\n5 3\r\n", "output": "0\r\n"}, {"input": "2 9\r\n2 2\r\n", "output": "0\r\n"}, {"input": "2 10\r\n6 1\r\n", "output": "0\r\n"}, {"input": "3 1\r\n1 1 1\r\n", "output": "6\r\n"}, {"input": "3 2\r\n2 2 1\r\n", "output": "5\r\n"}, {"input": "3 3\r\n2 1 2\r\n", "output": "0\r\n"}, {"input": "3 4\r\n2 2 2\r\n", "output": "3\r\n"}, {"input": "3 5\r\n1 1 2\r\n", "output": "0\r\n"}, {"input": "3 6\r\n4 3 2\r\n", "output": "3\r\n"}, {"input": "3 7\r\n3 4 1\r\n", "output": "0\r\n"}, {"input": "3 8\r\n5 1 4\r\n", "output": "0\r\n"}, {"input": "3 9\r\n3 2 1\r\n", "output": "0\r\n"}, {"input": "3 10\r\n6 5 5\r\n", "output": "2\r\n"}, {"input": "4 1\r\n1 1 1 1\r\n", "output": "10\r\n"}, {"input": "4 2\r\n2 2 1 2\r\n", "output": "9\r\n"}, {"input": "4 3\r\n2 1 1 1\r\n", "output": "0\r\n"}, {"input": "4 4\r\n2 2 1 1\r\n", "output": "3\r\n"}, {"input": "4 5\r\n2 3 2 1\r\n", "output": "0\r\n"}, {"input": "4 6\r\n1 1 3 3\r\n", "output": "0\r\n"}, {"input": "4 7\r\n1 1 2 2\r\n", "output": "0\r\n"}, {"input": "4 8\r\n5 4 5 5\r\n", "output": "0\r\n"}, {"input": "4 9\r\n1 1 4 2\r\n", "output": "0\r\n"}, {"input": "4 10\r\n2 6 2 1\r\n", "output": "0\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n", "output": "15\r\n"}, {"input": "5 2\r\n2 2 1 2 1\r\n", "output": "13\r\n"}, {"input": "5 3\r\n2 1 1 2 1\r\n", "output": "0\r\n"}, {"input": "5 4\r\n2 2 1 3 1\r\n", "output": "4\r\n"}, {"input": "5 5\r\n2 3 1 1 3\r\n", "output": "0\r\n"}, {"input": "5 6\r\n3 4 3 4 3\r\n", "output": "10\r\n"}, {"input": "5 7\r\n3 1 3 2 4\r\n", "output": "0\r\n"}, {"input": "5 8\r\n2 2 3 3 1\r\n", "output": "0\r\n"}, {"input": "5 9\r\n3 1 3 3 4\r\n", "output": "7\r\n"}, {"input": "5 10\r\n3 6 6 1 5\r\n", "output": "3\r\n"}, {"input": "6 1\r\n1 1 1 1 1 1\r\n", "output": "21\r\n"}, {"input": "6 2\r\n1 2 2 1 1 1\r\n", "output": "14\r\n"}, {"input": "6 3\r\n2 2 2 2 1 2\r\n", "output": "0\r\n"}, {"input": "6 4\r\n1 3 3 3 3 2\r\n", "output": "0\r\n"}, {"input": "6 5\r\n2 3 3 2 1 2\r\n", "output": "0\r\n"}, {"input": "6 6\r\n1 2 4 1 4 4\r\n", "output": "0\r\n"}, {"input": "6 7\r\n2 2 4 3 2 1\r\n", "output": "0\r\n"}, {"input": "6 8\r\n3 2 3 5 5 3\r\n", "output": "0\r\n"}, {"input": "6 9\r\n1 4 1 2 1 1\r\n", "output": "0\r\n"}, {"input": "6 10\r\n1 2 5 6 6 6\r\n", "output": "11\r\n"}, {"input": "7 1\r\n1 1 1 1 1 1 1\r\n", "output": "28\r\n"}, {"input": "7 2\r\n1 1 2 2 2 2 1\r\n", "output": "24\r\n"}, {"input": "7 3\r\n2 2 1 1 2 2 2\r\n", "output": "0\r\n"}, {"input": "7 4\r\n3 2 1 2 1 1 1\r\n", "output": "8\r\n"}, {"input": "7 5\r\n2 3 3 3 2 3 2\r\n", "output": "0\r\n"}, {"input": "7 6\r\n3 4 4 1 4 3 2\r\n", "output": "15\r\n"}, {"input": "7 7\r\n4 2 4 4 1 4 4\r\n", "output": "0\r\n"}, {"input": "7 8\r\n4 4 2 4 2 5 3\r\n", "output": "18\r\n"}, {"input": "7 9\r\n2 1 3 4 4 5 4\r\n", "output": "0\r\n"}, {"input": "7 10\r\n6 3 3 5 3 6 1\r\n", "output": "10\r\n"}, {"input": "8 1\r\n1 1 1 1 1 1 1 1\r\n", "output": "36\r\n"}, {"input": "8 2\r\n1 1 1 1 1 1 1 2\r\n", "output": "8\r\n"}, {"input": "8 3\r\n1 1 2 2 1 1 2 2\r\n", "output": "0\r\n"}, {"input": "8 4\r\n2 3 2 3 3 3 2 3\r\n", "output": "10\r\n"}, {"input": "8 5\r\n1 3 1 2 2 2 1 3\r\n", "output": "0\r\n"}, {"input": "8 6\r\n4 2 4 2 1 2 1 4\r\n", "output": "0\r\n"}, {"input": "8 7\r\n2 2 1 4 4 4 2 2\r\n", "output": "0\r\n"}, {"input": "8 8\r\n5 2 1 2 4 2 2 4\r\n", "output": "21\r\n"}, {"input": "8 9\r\n4 4 2 2 5 5 4 1\r\n", "output": "0\r\n"}, {"input": "8 10\r\n2 1 4 4 3 4 4 6\r\n", "output": "0\r\n"}, {"input": "9 1\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "45\r\n"}, {"input": "9 2\r\n1 1 1 2 1 1 2 2 2\r\n", "output": "36\r\n"}, {"input": "9 3\r\n1 1 1 2 2 1 1 2 1\r\n", "output": "0\r\n"}, {"input": "9 4\r\n1 1 2 1 2 1 1 1 1\r\n", "output": "15\r\n"}, {"input": "9 5\r\n3 2 3 2 3 1 1 3 2\r\n", "output": "0\r\n"}, {"input": "9 6\r\n2 1 1 3 2 4 1 2 2\r\n", "output": "21\r\n"}, {"input": "9 7\r\n4 3 2 1 2 3 3 4 4\r\n", "output": "0\r\n"}, {"input": "9 8\r\n5 5 2 1 3 1 3 1 3\r\n", "output": "0\r\n"}, {"input": "9 9\r\n2 4 1 4 4 3 3 4 1\r\n", "output": "18\r\n"}, {"input": "9 10\r\n4 3 2 5 2 2 2 2 6\r\n", "output": "23\r\n"}, {"input": "10 1\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "55\r\n"}, {"input": "10 2\r\n2 2 2 2 2 2 2 1 2 1\r\n", "output": "53\r\n"}, {"input": "10 3\r\n2 2 1 1 2 2 2 2 1 2\r\n", "output": "0\r\n"}, {"input": "10 4\r\n1 1 2 3 3 1 2 2 2 3\r\n", "output": "26\r\n"}, {"input": "10 5\r\n3 3 2 2 3 1 1 1 3 1\r\n", "output": "0\r\n"}, {"input": "10 6\r\n4 4 4 3 2 1 1 1 2 4\r\n", "output": "27\r\n"}, {"input": "10 7\r\n4 2 2 2 3 3 2 4 4 3\r\n", "output": "0\r\n"}, {"input": "10 8\r\n5 4 1 4 3 2 1 2 3 3\r\n", "output": "24\r\n"}, {"input": "10 9\r\n1 2 3 4 5 2 3 5 5 4\r\n", "output": "12\r\n"}, {"input": "10 10\r\n5 3 2 5 1 2 5 1 5 1\r\n", "output": "35\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "1 100000000\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1000000000\r\n", "output": "1\r\n"}]
false
stdio
null
true
818/E
818
E
PyPy 3-64
TESTS
2
77
0
181886867
def fact(n): res=n a=[] i=2 while i*i<=res: if res%i==0: cnt=0 while res%i==0: cnt+=1 res//=i a.append((i,cnt)) i+=1 if res!=1: a.append((res,1)) return a n,k=map(int,input().split()) a=list(map(int,input().split())) if k==1: print((n+1)*(n+2)//2) exit() def calc(c,m): right=[n+1]*n R=0 tmp=0 for i in range(n): while tmp<m: if R==n: return right tmp+=c[R] R+=1 right[i]=R tmp-=c[i] return right Right=[0]*n for p,e in fact(k): c=[0]*n for i in range(n): while a[i]%p==0: a[i]//=p c[i]+=1 res=calc(c,e) for i in range(n): Right[i]=max(Right[i],res[i]) print((n+1)*n-sum(Right))
135
1,809
14,950,400
90465157
def gcd(a,b): if a == 0: return b return gcd(b%a,a) n,k = [int(x) for x in input().split()] a = [gcd(int(x),k) for x in input().split()] if k == 1: print(((n+1)*(n+2))//2-n-1) else: s = 0 e = 0 total = ((n+1)*(n+2))//2-1-n #print(total) #extra = {} c = 1 while e < n: flag = False while c%k != 0 and e < n: total -= e-s c *= a[e] e += 1 while c%k == 0 and s < e: c //= a[s] s += 1 total -= e-s print(total)
Educational Codeforces Round 24
ICPC
2,017
2
256
Card Game Again
Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number ai is written on the i-th card in the deck. After receiving the deck and the magic number, Vova removes x (possibly x = 0) cards from the top of the deck, y (possibly y = 0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards x + 1, x + 2, ... n - y - 1, n - y from the original deck. Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by k. So Vova received a deck (possibly not a valid one) and a number k, and now he wonders, how many ways are there to choose x and y so the deck he will get after removing x cards from the top and y cards from the bottom is valid?
The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers written on the cards.
Print the number of ways to choose x and y so the resulting deck is valid.
null
In the first example the possible values of x and y are: 1. x = 0, y = 0; 2. x = 1, y = 0; 3. x = 2, y = 0; 4. x = 0, y = 1.
[{"input": "3 4\n6 2 8", "output": "4"}, {"input": "3 6\n9 1 14", "output": "1"}]
1,900
["binary search", "data structures", "number theory", "two pointers"]
135
[{"input": "3 4\r\n6 2 8\r\n", "output": "4\r\n"}, {"input": "3 6\r\n9 1 14\r\n", "output": "1\r\n"}, {"input": "5 1\r\n1 3 1 3 1\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 5 5 5 5\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 4 4 4 4\r\n", "output": "15\r\n"}, {"input": "100 1\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": "5050\r\n"}, {"input": "100 1\r\n3 3 2 1 1 2 1 2 3 4 1 5 2 4 5 1 1 3 2 3 4 2 1 3 4 4 5 5 1 5 2 5 3 3 1 1 1 3 2 2 3 4 4 4 4 3 1 3 5 3 3 3 3 2 3 2 2 3 3 1 2 4 3 2 2 5 3 1 5 2 2 5 1 2 1 1 5 1 5 2 4 5 3 4 2 5 4 2 2 5 5 5 3 3 5 3 4 3 3 1\r\n", "output": "5050\r\n"}, {"input": "100 5\r\n4 4 3 2 4 4 1 2 2 1 5 3 2 5 5 3 2 3 4 5 2 2 3 4 2 4 3 1 2 3 5 5 1 3 3 5 2 3 3 4 1 3 1 5 4 4 2 1 5 1 4 4 1 5 1 1 5 5 5 4 1 3 1 2 3 2 4 5 5 1 3 4 3 3 1 2 2 4 1 5 1 1 2 4 4 4 5 5 5 3 4 3 3 3 3 2 1 1 5 5\r\n", "output": "4713\r\n"}, {"input": "100 6\r\n4 4 1 1 1 1 3 3 5 5 4 2 2 4 3 4 4 5 5 4 5 1 3 1 5 4 5 1 2 5 5 2 2 4 2 4 4 2 5 5 3 3 1 3 3 5 2 3 1 4 1 4 4 1 5 5 1 2 3 2 3 3 5 3 4 2 3 4 3 1 5 3 5 5 3 5 4 4 3 1 1 2 1 2 1 3 2 4 3 2 1 4 3 1 1 5 1 5 4 3\r\n", "output": "4580\r\n"}, {"input": "100 72\r\n8 8 7 9 6 1 4 5 3 7 5 10 5 4 1 3 4 1 3 1 6 6 4 5 4 5 6 1 10 7 9 1 6 10 6 6 9 3 3 4 5 9 4 9 8 1 5 9 3 7 1 8 5 2 1 1 7 7 7 6 6 4 2 9 10 2 8 3 1 1 4 8 5 9 7 10 9 4 2 3 7 7 6 7 8 5 1 3 8 5 1 8 9 10 3 7 1 8 10 5\r\n", "output": "4549\r\n"}, {"input": "100 72\r\n3 2 1 3 3 3 4 3 5 5 2 5 1 2 2 2 1 4 1 5 1 4 5 4 3 1 4 3 4 4 1 4 4 3 4 1 4 4 5 2 2 3 3 5 4 5 4 2 4 3 1 1 1 4 5 5 3 1 5 3 4 4 5 3 5 1 4 3 2 2 1 4 2 1 3 2 4 2 1 4 4 1 3 4 4 4 1 5 5 2 5 2 3 1 5 1 1 1 2 3\r\n", "output": "4123\r\n"}, {"input": "2 999634589\r\n31607 31627\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1\r\n", "output": "0\r\n"}, {"input": "1 3\r\n1\r\n", "output": "0\r\n"}, {"input": "1 4\r\n1\r\n", "output": "0\r\n"}, {"input": "1 5\r\n3\r\n", "output": "0\r\n"}, {"input": "1 6\r\n4\r\n", "output": "0\r\n"}, {"input": "1 7\r\n2\r\n", "output": "0\r\n"}, {"input": "1 8\r\n3\r\n", "output": "0\r\n"}, {"input": "1 9\r\n5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n3\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n", "output": "3\r\n"}, {"input": "2 2\r\n2 2\r\n", "output": "3\r\n"}, {"input": "2 3\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2 4\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2 5\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 6\r\n2 1\r\n", "output": "0\r\n"}, {"input": "2 7\r\n1 4\r\n", "output": "0\r\n"}, {"input": "2 8\r\n5 3\r\n", "output": "0\r\n"}, {"input": "2 9\r\n2 2\r\n", "output": "0\r\n"}, {"input": "2 10\r\n6 1\r\n", "output": "0\r\n"}, {"input": "3 1\r\n1 1 1\r\n", "output": "6\r\n"}, {"input": "3 2\r\n2 2 1\r\n", "output": "5\r\n"}, {"input": "3 3\r\n2 1 2\r\n", "output": "0\r\n"}, {"input": "3 4\r\n2 2 2\r\n", "output": "3\r\n"}, {"input": "3 5\r\n1 1 2\r\n", "output": "0\r\n"}, {"input": "3 6\r\n4 3 2\r\n", "output": "3\r\n"}, {"input": "3 7\r\n3 4 1\r\n", "output": "0\r\n"}, {"input": "3 8\r\n5 1 4\r\n", "output": "0\r\n"}, {"input": "3 9\r\n3 2 1\r\n", "output": "0\r\n"}, {"input": "3 10\r\n6 5 5\r\n", "output": "2\r\n"}, {"input": "4 1\r\n1 1 1 1\r\n", "output": "10\r\n"}, {"input": "4 2\r\n2 2 1 2\r\n", "output": "9\r\n"}, {"input": "4 3\r\n2 1 1 1\r\n", "output": "0\r\n"}, {"input": "4 4\r\n2 2 1 1\r\n", "output": "3\r\n"}, {"input": "4 5\r\n2 3 2 1\r\n", "output": "0\r\n"}, {"input": "4 6\r\n1 1 3 3\r\n", "output": "0\r\n"}, {"input": "4 7\r\n1 1 2 2\r\n", "output": "0\r\n"}, {"input": "4 8\r\n5 4 5 5\r\n", "output": "0\r\n"}, {"input": "4 9\r\n1 1 4 2\r\n", "output": "0\r\n"}, {"input": "4 10\r\n2 6 2 1\r\n", "output": "0\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n", "output": "15\r\n"}, {"input": "5 2\r\n2 2 1 2 1\r\n", "output": "13\r\n"}, {"input": "5 3\r\n2 1 1 2 1\r\n", "output": "0\r\n"}, {"input": "5 4\r\n2 2 1 3 1\r\n", "output": "4\r\n"}, {"input": "5 5\r\n2 3 1 1 3\r\n", "output": "0\r\n"}, {"input": "5 6\r\n3 4 3 4 3\r\n", "output": "10\r\n"}, {"input": "5 7\r\n3 1 3 2 4\r\n", "output": "0\r\n"}, {"input": "5 8\r\n2 2 3 3 1\r\n", "output": "0\r\n"}, {"input": "5 9\r\n3 1 3 3 4\r\n", "output": "7\r\n"}, {"input": "5 10\r\n3 6 6 1 5\r\n", "output": "3\r\n"}, {"input": "6 1\r\n1 1 1 1 1 1\r\n", "output": "21\r\n"}, {"input": "6 2\r\n1 2 2 1 1 1\r\n", "output": "14\r\n"}, {"input": "6 3\r\n2 2 2 2 1 2\r\n", "output": "0\r\n"}, {"input": "6 4\r\n1 3 3 3 3 2\r\n", "output": "0\r\n"}, {"input": "6 5\r\n2 3 3 2 1 2\r\n", "output": "0\r\n"}, {"input": "6 6\r\n1 2 4 1 4 4\r\n", "output": "0\r\n"}, {"input": "6 7\r\n2 2 4 3 2 1\r\n", "output": "0\r\n"}, {"input": "6 8\r\n3 2 3 5 5 3\r\n", "output": "0\r\n"}, {"input": "6 9\r\n1 4 1 2 1 1\r\n", "output": "0\r\n"}, {"input": "6 10\r\n1 2 5 6 6 6\r\n", "output": "11\r\n"}, {"input": "7 1\r\n1 1 1 1 1 1 1\r\n", "output": "28\r\n"}, {"input": "7 2\r\n1 1 2 2 2 2 1\r\n", "output": "24\r\n"}, {"input": "7 3\r\n2 2 1 1 2 2 2\r\n", "output": "0\r\n"}, {"input": "7 4\r\n3 2 1 2 1 1 1\r\n", "output": "8\r\n"}, {"input": "7 5\r\n2 3 3 3 2 3 2\r\n", "output": "0\r\n"}, {"input": "7 6\r\n3 4 4 1 4 3 2\r\n", "output": "15\r\n"}, {"input": "7 7\r\n4 2 4 4 1 4 4\r\n", "output": "0\r\n"}, {"input": "7 8\r\n4 4 2 4 2 5 3\r\n", "output": "18\r\n"}, {"input": "7 9\r\n2 1 3 4 4 5 4\r\n", "output": "0\r\n"}, {"input": "7 10\r\n6 3 3 5 3 6 1\r\n", "output": "10\r\n"}, {"input": "8 1\r\n1 1 1 1 1 1 1 1\r\n", "output": "36\r\n"}, {"input": "8 2\r\n1 1 1 1 1 1 1 2\r\n", "output": "8\r\n"}, {"input": "8 3\r\n1 1 2 2 1 1 2 2\r\n", "output": "0\r\n"}, {"input": "8 4\r\n2 3 2 3 3 3 2 3\r\n", "output": "10\r\n"}, {"input": "8 5\r\n1 3 1 2 2 2 1 3\r\n", "output": "0\r\n"}, {"input": "8 6\r\n4 2 4 2 1 2 1 4\r\n", "output": "0\r\n"}, {"input": "8 7\r\n2 2 1 4 4 4 2 2\r\n", "output": "0\r\n"}, {"input": "8 8\r\n5 2 1 2 4 2 2 4\r\n", "output": "21\r\n"}, {"input": "8 9\r\n4 4 2 2 5 5 4 1\r\n", "output": "0\r\n"}, {"input": "8 10\r\n2 1 4 4 3 4 4 6\r\n", "output": "0\r\n"}, {"input": "9 1\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "45\r\n"}, {"input": "9 2\r\n1 1 1 2 1 1 2 2 2\r\n", "output": "36\r\n"}, {"input": "9 3\r\n1 1 1 2 2 1 1 2 1\r\n", "output": "0\r\n"}, {"input": "9 4\r\n1 1 2 1 2 1 1 1 1\r\n", "output": "15\r\n"}, {"input": "9 5\r\n3 2 3 2 3 1 1 3 2\r\n", "output": "0\r\n"}, {"input": "9 6\r\n2 1 1 3 2 4 1 2 2\r\n", "output": "21\r\n"}, {"input": "9 7\r\n4 3 2 1 2 3 3 4 4\r\n", "output": "0\r\n"}, {"input": "9 8\r\n5 5 2 1 3 1 3 1 3\r\n", "output": "0\r\n"}, {"input": "9 9\r\n2 4 1 4 4 3 3 4 1\r\n", "output": "18\r\n"}, {"input": "9 10\r\n4 3 2 5 2 2 2 2 6\r\n", "output": "23\r\n"}, {"input": "10 1\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "55\r\n"}, {"input": "10 2\r\n2 2 2 2 2 2 2 1 2 1\r\n", "output": "53\r\n"}, {"input": "10 3\r\n2 2 1 1 2 2 2 2 1 2\r\n", "output": "0\r\n"}, {"input": "10 4\r\n1 1 2 3 3 1 2 2 2 3\r\n", "output": "26\r\n"}, {"input": "10 5\r\n3 3 2 2 3 1 1 1 3 1\r\n", "output": "0\r\n"}, {"input": "10 6\r\n4 4 4 3 2 1 1 1 2 4\r\n", "output": "27\r\n"}, {"input": "10 7\r\n4 2 2 2 3 3 2 4 4 3\r\n", "output": "0\r\n"}, {"input": "10 8\r\n5 4 1 4 3 2 1 2 3 3\r\n", "output": "24\r\n"}, {"input": "10 9\r\n1 2 3 4 5 2 3 5 5 4\r\n", "output": "12\r\n"}, {"input": "10 10\r\n5 3 2 5 1 2 5 1 5 1\r\n", "output": "35\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "1 100000000\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1000000000\r\n", "output": "1\r\n"}]
false
stdio
null
true
858/E
858
E
Python 3
TESTS
0
46
204,800
30954475
n = int(input()) s = {} for i in range(n): name, test = tuple(input().split()) s[name] = test ex = [] us = [] kol_1 = list(s.values()).count('1') for name, test in s.items(): if test == '1': if name.isdigit() and name[0] != '0' and int(name) in range(1, kol_1 + 1): ex.append(name) else: if name.isdigit() and name[0] != '0' and int(name) in range(kol_1 + 1, n + 1): us.append(name) min_k = n - len(ex) - len(us) ex.sort() us.sort() all_1 = [str(i) for i in range(1, kol_1 + 1)] all_0 = [str(i) for i in range(kol_1 + 1, n + 1)] print(min_k) for name, test in s.items(): if test == '1': if name in ex: all_1.remove(name) ex.remove(name) else: m = list(set(all_1) - set(ex))[0] print("move " + name + " " + str(m)) all_1.remove(m) else: if name in us: all_0.remove(name) us.remove(name) else: m = list(set(all_0) - set(us))[0] print("move " + name + " " + str(m)) all_0.remove(m)
165
295
27,136,000
230751905
n = int(input()) t = [1] + [0] * n b, a = d = [], [] h, s = [], [] for i in range(n): f, k = input().split() d[int(k)].append(f) m = len(a) for i in a: if i.isdigit() and i[0] != '0': j = int(i) if 0 < j <= m: t[j] = 1 elif m < j <= n: t[j] = -1 else: s.append(i) else: s.append(i) for i in b: if i.isdigit() and i[0] != '0': j = int(i) if m < j <= n: t[j] = 1 elif 0 < j <= m: t[j] = -1 else: s.append(i) else: s.append(i) x = [j for j in range(1, m + 1) if t[j] < 0] y = [j for j in range(m + 1, n + 1) if t[j] < 0] u = [j for j in range(1, m + 1) if not t[j]] v = [j for j in range(m + 1, n + 1) if not t[j]] if not s and (x or y): s = ['0'] if y: i = y.pop() v.append(i) else: i = x.pop() u.append(i) h.append(str(i) + ' 0') t[i] = 0 while x or y: if v and x: i = x.pop() j = v.pop() t[j] = 1 h.append(str(i) + ' ' + str(j)) u.append(i) else: u, v, x, y = v, u, y, x k = 1 for j in s: while t[k] == 1: k += 1 h.append(j + ' ' + str(k)) k += 1 d = '\nmove ' print(str(len(h)) + d + d.join(h) if h else 0)
Технокубок 2018 - Отборочный Раунд 1
CF
2,017
2
256
Tests Renumeration
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website. Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic. Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests. Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only. The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command. Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run: - all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples; - all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests.
The first line contains single integer n (1 ≤ n ≤ 105) — the number of files with tests. n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct.
In the first line print the minimum number of lines in Vladimir's script file. After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6.
null
null
[{"input": "5\n01 0\n2 1\n2extra 0\n3 1\n99 0", "output": "4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3"}, {"input": "2\n1 0\n2 1", "output": "3\nmove 1 3\nmove 2 1\nmove 3 2"}, {"input": "5\n1 0\n11 1\n111 0\n1111 1\n11111 0", "output": "5\nmove 1 5\nmove 11 1\nmove 1111 2\nmove 111 4\nmove 11111 3"}]
2,200
["greedy", "implementation"]
165
[{"input": "5\r\n01 0\r\n2 1\r\n2extra 0\r\n3 1\r\n99 0\r\n", "output": "4\r\nmove 3 1\r\nmove 01 5\r\nmove 2extra 4\r\nmove 99 3\r\n"}, {"input": "2\r\n1 0\r\n2 1\r\n", "output": "3\r\nmove 1 dytuig\r\nmove 2 1\r\nmove dytuig 2\r\n"}, {"input": "5\r\n1 0\r\n11 1\r\n111 0\r\n1111 1\r\n11111 0\r\n", "output": "5\r\nmove 1 5\r\nmove 11 1\r\nmove 1111 2\r\nmove 111 4\r\nmove 11111 3\r\n"}, {"input": "4\r\nir7oz8 1\r\nvj4v5t 1\r\nkwkahb 1\r\nj5s8o1 0\r\n", "output": "4\r\nmove ir7oz8 1\r\nmove vj4v5t 2\r\nmove kwkahb 3\r\nmove j5s8o1 4\r\n"}, {"input": "4\r\n3 1\r\n1o0bp2 0\r\n9tn379 0\r\nv04v6j 1\r\n", "output": "4\r\nmove 3 1\r\nmove v04v6j 2\r\nmove 1o0bp2 4\r\nmove 9tn379 3\r\n"}, {"input": "4\r\n1 0\r\nsc7czx 0\r\nfr4033 1\r\n3 0\r\n", "output": "3\r\nmove 1 4\r\nmove fr4033 1\r\nmove sc7czx 2\r\n"}, {"input": "4\r\n4 0\r\n1 0\r\n2 0\r\nizfotg 1\r\n", "output": "2\r\nmove 1 3\r\nmove izfotg 1\r\n"}, {"input": "4\r\n2 0\r\n3 0\r\n1 1\r\n4 1\r\n", "output": "3\r\nmove 2 0b9r8j\r\nmove 4 2\r\nmove 0b9r8j 4\r\n"}, {"input": "5\r\npuusew 1\r\npvoy4h 0\r\nwdzx4r 0\r\n1z84cx 0\r\nozsuvd 0\r\n", "output": "5\r\nmove puusew 1\r\nmove pvoy4h 5\r\nmove wdzx4r 4\r\nmove 1z84cx 3\r\nmove ozsuvd 2\r\n"}, {"input": "5\r\n949pnr 1\r\n9sxhcr 0\r\n5 1\r\nx8srx3 1\r\ncl7ppd 1\r\n", "output": "5\r\nmove 5 1\r\nmove 949pnr 2\r\nmove x8srx3 3\r\nmove cl7ppd 4\r\nmove 9sxhcr 5\r\n"}, {"input": "5\r\n2 0\r\n1 0\r\np2gcxf 1\r\nwfyoiq 1\r\nzjw3vg 1\r\n", "output": "5\r\nmove 2 5\r\nmove 1 4\r\nmove p2gcxf 1\r\nmove wfyoiq 2\r\nmove zjw3vg 3\r\n"}, {"input": "5\r\nogvgi7 0\r\n3 1\r\n4 1\r\n1 1\r\nm5nhux 0\r\n", "output": "3\r\nmove 4 2\r\nmove ogvgi7 5\r\nmove m5nhux 4\r\n"}, {"input": "5\r\nt6kdte 1\r\n2 1\r\n4 1\r\n5 1\r\n3 1\r\n", "output": "1\r\nmove t6kdte 1\r\n"}, {"input": "5\r\n2 0\r\n3 1\r\n4 0\r\n1 1\r\n5 1\r\n", "output": "3\r\nmove 2 p6w7mu\r\nmove 5 2\r\nmove p6w7mu 5\r\n"}, {"input": "1\r\nsd84r7 1\r\n", "output": "1\r\nmove sd84r7 1\r\n"}, {"input": "1\r\n1 0\r\n", "output": "0\r\n"}, {"input": "2\r\n5xzjm4 0\r\njoa6mr 1\r\n", "output": "2\r\nmove joa6mr 1\r\nmove 5xzjm4 2\r\n"}, {"input": "2\r\n1 0\r\nxdkh5a 1\r\n", "output": "2\r\nmove 1 2\r\nmove xdkh5a 1\r\n"}, {"input": "2\r\n1 0\r\n2 0\r\n", "output": "0\r\n"}, {"input": "3\r\nz1nwrd 1\r\nt0xrja 0\r\n106qy1 0\r\n", "output": "3\r\nmove z1nwrd 1\r\nmove t0xrja 3\r\nmove 106qy1 2\r\n"}, {"input": "3\r\nt4hdos 0\r\ndhje0g 0\r\n3 0\r\n", "output": "2\r\nmove t4hdos 2\r\nmove dhje0g 1\r\n"}, {"input": "3\r\n3 0\r\n26mp5s 0\r\n1 1\r\n", "output": "1\r\nmove 26mp5s 2\r\n"}, {"input": "3\r\n2 1\r\n1 0\r\n3 0\r\n", "output": "3\r\nmove 2 1ntx05\r\nmove 1 2\r\nmove 1ntx05 1\r\n"}, {"input": "1\r\nprzvln 0\r\n", "output": "1\r\nmove przvln 1\r\n"}, {"input": "2\r\nkfsipl 0\r\n1jj1ol 0\r\n", "output": "2\r\nmove kfsipl 2\r\nmove 1jj1ol 1\r\n"}, {"input": "3\r\n2x7a4g 0\r\n27lqe6 0\r\nzfo3sp 0\r\n", "output": "3\r\nmove 2x7a4g 3\r\nmove 27lqe6 2\r\nmove zfo3sp 1\r\n"}, {"input": "1\r\nxzp9ni 1\r\n", "output": "1\r\nmove xzp9ni 1\r\n"}, {"input": "1\r\nabbdf7 1\r\n", "output": "1\r\nmove abbdf7 1\r\n"}, {"input": "2\r\ndbif39 1\r\ne8dkf8 0\r\n", "output": "2\r\nmove dbif39 1\r\nmove e8dkf8 2\r\n"}, {"input": "2\r\n2 0\r\njkwekx 1\r\n", "output": "1\r\nmove jkwekx 1\r\n"}, {"input": "3\r\nn3pmj8 0\r\n2alui6 0\r\ne7lf4u 1\r\n", "output": "3\r\nmove e7lf4u 1\r\nmove n3pmj8 3\r\nmove 2alui6 2\r\n"}, {"input": "3\r\ndr1lp8 0\r\n1 0\r\n6a2egk 1\r\n", "output": "3\r\nmove 1 3\r\nmove 6a2egk 1\r\nmove dr1lp8 2\r\n"}, {"input": "4\r\nyi9ta0 1\r\nmeljgm 0\r\nf7bqon 0\r\n5bbvun 0\r\n", "output": "4\r\nmove yi9ta0 1\r\nmove meljgm 4\r\nmove f7bqon 3\r\nmove 5bbvun 2\r\n"}, {"input": "4\r\n0la3gu 0\r\nzhrmyb 1\r\n3iprc0 0\r\n3 0\r\n", "output": "3\r\nmove zhrmyb 1\r\nmove 0la3gu 4\r\nmove 3iprc0 2\r\n"}, {"input": "1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n17dgbb 0\r\n2 1\r\n", "output": "2\r\nmove 2 1\r\nmove 17dgbb 2\r\n"}, {"input": "2\r\n1 0\r\n2 1\r\n", "output": "3\r\nmove 1 xrjgjv\r\nmove 2 1\r\nmove xrjgjv 2\r\n"}, {"input": "3\r\nscrn8k 0\r\n3 1\r\nycvm9s 0\r\n", "output": "3\r\nmove 3 1\r\nmove scrn8k 3\r\nmove ycvm9s 2\r\n"}, {"input": "3\r\nt0dfz3 0\r\n3 0\r\n1 1\r\n", "output": "1\r\nmove t0dfz3 2\r\n"}, {"input": "4\r\nkgw83p 0\r\np3p3ch 0\r\n4 1\r\n0te9lv 0\r\n", "output": "4\r\nmove 4 1\r\nmove kgw83p 4\r\nmove p3p3ch 3\r\nmove 0te9lv 2\r\n"}, {"input": "4\r\n3 1\r\nnj94jx 0\r\n3a5ad1 0\r\n1 0\r\n", "output": "4\r\nmove 1 4\r\nmove 3 1\r\nmove nj94jx 3\r\nmove 3a5ad1 2\r\n"}, {"input": "2\r\no9z069 1\r\n5hools 1\r\n", "output": "2\r\nmove o9z069 1\r\nmove 5hools 2\r\n"}, {"input": "2\r\nyzzyab 1\r\n728oq0 1\r\n", "output": "2\r\nmove yzzyab 1\r\nmove 728oq0 2\r\n"}, {"input": "2\r\nqy2kmc 1\r\nqb4crj 1\r\n", "output": "2\r\nmove qy2kmc 1\r\nmove qb4crj 2\r\n"}, {"input": "3\r\nunw560 1\r\n0iswxk 0\r\ndonjp9 1\r\n", "output": "3\r\nmove unw560 1\r\nmove donjp9 2\r\nmove 0iswxk 3\r\n"}, {"input": "3\r\n2 0\r\nuv8c54 1\r\n508bb0 1\r\n", "output": "3\r\nmove 2 3\r\nmove uv8c54 1\r\nmove 508bb0 2\r\n"}, {"input": "3\r\n9afh0z 1\r\n0qcaht 1\r\n3 0\r\n", "output": "2\r\nmove 9afh0z 1\r\nmove 0qcaht 2\r\n"}, {"input": "4\r\n2kk04q 0\r\nkdktvk 1\r\nc4i5k8 1\r\nawaock 0\r\n", "output": "4\r\nmove kdktvk 1\r\nmove c4i5k8 2\r\nmove 2kk04q 4\r\nmove awaock 3\r\n"}, {"input": "4\r\n2 0\r\nmqbjos 0\r\n6mhijg 1\r\n6wum8y 1\r\n", "output": "4\r\nmove 2 4\r\nmove 6mhijg 1\r\nmove 6wum8y 2\r\nmove mqbjos 3\r\n"}, {"input": "4\r\n4 0\r\npa613p 1\r\nuuizq7 1\r\n2 0\r\n", "output": "3\r\nmove 2 3\r\nmove pa613p 1\r\nmove uuizq7 2\r\n"}, {"input": "5\r\nw0g96a 1\r\nv99tdi 0\r\nmywrle 0\r\nweh22w 1\r\n9hywt4 0\r\n", "output": "5\r\nmove w0g96a 1\r\nmove weh22w 2\r\nmove v99tdi 5\r\nmove mywrle 4\r\nmove 9hywt4 3\r\n"}, {"input": "5\r\n5 0\r\n12qcjd 1\r\nuthzbz 0\r\nb3670z 0\r\nl2u93o 1\r\n", "output": "4\r\nmove 12qcjd 1\r\nmove l2u93o 2\r\nmove uthzbz 4\r\nmove b3670z 3\r\n"}, {"input": "5\r\n0jc7xb 1\r\n2 0\r\n1m7l9s 0\r\n9xzkau 1\r\n1 0\r\n", "output": "5\r\nmove 2 5\r\nmove 1 4\r\nmove 0jc7xb 1\r\nmove 9xzkau 2\r\nmove 1m7l9s 3\r\n"}, {"input": "2\r\n1 1\r\nvinxur 1\r\n", "output": "1\r\nmove vinxur 2\r\n"}, {"input": "2\r\n1qe46n 1\r\n1 1\r\n", "output": "1\r\nmove 1qe46n 2\r\n"}, {"input": "2\r\n1 1\r\ng5jlzp 1\r\n", "output": "1\r\nmove g5jlzp 2\r\n"}, {"input": "3\r\nc8p28p 1\r\n2 1\r\nvk4gdf 0\r\n", "output": "2\r\nmove c8p28p 1\r\nmove vk4gdf 3\r\n"}, {"input": "3\r\n2 1\r\n3 0\r\nhs9j9t 1\r\n", "output": "1\r\nmove hs9j9t 1\r\n"}, {"input": "3\r\n2 1\r\n1 0\r\nomitxh 1\r\n", "output": "2\r\nmove 1 3\r\nmove omitxh 1\r\n"}, {"input": "4\r\n4 1\r\nu9do88 1\r\n787at9 0\r\nfcud6k 0\r\n", "output": "4\r\nmove 4 1\r\nmove u9do88 2\r\nmove 787at9 4\r\nmove fcud6k 3\r\n"}, {"input": "4\r\n3 0\r\nqvw4ow 1\r\nne0ng9 0\r\n1 1\r\n", "output": "2\r\nmove qvw4ow 2\r\nmove ne0ng9 4\r\n"}, {"input": "4\r\ng6ugrm 1\r\n1 1\r\n3 0\r\n2 0\r\n", "output": "2\r\nmove 2 4\r\nmove g6ugrm 2\r\n"}, {"input": "5\r\n5 1\r\nz9zr7d 0\r\ne8rwo4 1\r\nrfpjp6 0\r\ngz6dhj 0\r\n", "output": "5\r\nmove 5 1\r\nmove e8rwo4 2\r\nmove z9zr7d 5\r\nmove rfpjp6 4\r\nmove gz6dhj 3\r\n"}, {"input": "5\r\n5sn77g 0\r\nsetddt 1\r\nbz16cb 0\r\n4 1\r\n2 0\r\n", "output": "5\r\nmove 4 1\r\nmove 2 5\r\nmove setddt 2\r\nmove 5sn77g 4\r\nmove bz16cb 3\r\n"}, {"input": "5\r\n1 1\r\nx2miqh 1\r\n3 0\r\n2 0\r\n1rq643 0\r\n", "output": "3\r\nmove 2 5\r\nmove x2miqh 2\r\nmove 1rq643 4\r\n"}, {"input": "2\r\n1 1\r\n2 1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n2 1\r\n", "output": "0\r\n"}, {"input": "2\r\n2 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1\r\nav5vex 0\r\n1 1\r\n", "output": "2\r\nmove 3 2\r\nmove av5vex 3\r\n"}, {"input": "3\r\n3 1\r\n1 0\r\n2 1\r\n", "output": "3\r\nmove 3 fopgrb\r\nmove 1 3\r\nmove fopgrb 1\r\n"}, {"input": "3\r\n3 1\r\n1 0\r\n2 1\r\n", "output": "3\r\nmove 3 wzgsm0\r\nmove 1 3\r\nmove wzgsm0 1\r\n"}, {"input": "4\r\ny9144q 0\r\n3 1\r\n2 1\r\ns0bdnf 0\r\n", "output": "3\r\nmove 3 1\r\nmove y9144q 4\r\nmove s0bdnf 3\r\n"}, {"input": "4\r\n4 1\r\n1 0\r\n3 1\r\nmod9zl 0\r\n", "output": "4\r\nmove 4 2\r\nmove 1 4\r\nmove 3 1\r\nmove mod9zl 3\r\n"}, {"input": "4\r\n4 1\r\n3 1\r\n1 0\r\n2 0\r\n", "output": "5\r\nmove 4 ow3q4a\r\nmove 1 4\r\nmove 3 1\r\nmove 2 3\r\nmove ow3q4a 2\r\n"}, {"input": "5\r\n1 1\r\nnoidnv 0\r\n3 1\r\nx3xiiz 0\r\n1lfa9v 0\r\n", "output": "4\r\nmove 3 2\r\nmove noidnv 5\r\nmove x3xiiz 4\r\nmove 1lfa9v 3\r\n"}, {"input": "5\r\n1 1\r\nvsyajx 0\r\n783b38 0\r\n4 0\r\n2 1\r\n", "output": "2\r\nmove vsyajx 5\r\nmove 783b38 3\r\n"}, {"input": "5\r\n3 1\r\n5 0\r\ncvfl8i 0\r\n4 1\r\n2 0\r\n", "output": "4\r\nmove 3 1\r\nmove 2 3\r\nmove 4 2\r\nmove cvfl8i 4\r\n"}, {"input": "3\r\nbxo0pe 1\r\nbt50pa 1\r\n2tx68t 1\r\n", "output": "3\r\nmove bxo0pe 1\r\nmove bt50pa 2\r\nmove 2tx68t 3\r\n"}, {"input": "3\r\nj9rnac 1\r\noetwfz 1\r\nd6n3ww 1\r\n", "output": "3\r\nmove j9rnac 1\r\nmove oetwfz 2\r\nmove d6n3ww 3\r\n"}, {"input": "3\r\naf2f6j 1\r\nmjni5l 1\r\njvyxgc 1\r\n", "output": "3\r\nmove af2f6j 1\r\nmove mjni5l 2\r\nmove jvyxgc 3\r\n"}, {"input": "3\r\nr2qlj2 1\r\nt8wf1y 1\r\nigids8 1\r\n", "output": "3\r\nmove r2qlj2 1\r\nmove t8wf1y 2\r\nmove igids8 3\r\n"}, {"input": "4\r\nuilh9a 0\r\n4lxxh9 1\r\nkqdpzy 1\r\nn1d7hd 1\r\n", "output": "4\r\nmove 4lxxh9 1\r\nmove kqdpzy 2\r\nmove n1d7hd 3\r\nmove uilh9a 4\r\n"}, {"input": "4\r\n3 0\r\niipymv 1\r\nvakd5b 1\r\n2ktczv 1\r\n", "output": "4\r\nmove 3 4\r\nmove iipymv 1\r\nmove vakd5b 2\r\nmove 2ktczv 3\r\n"}, {"input": "4\r\nq4b449 1\r\n3 0\r\ncjg1x2 1\r\ne878er 1\r\n", "output": "4\r\nmove 3 4\r\nmove q4b449 1\r\nmove cjg1x2 2\r\nmove e878er 3\r\n"}, {"input": "4\r\n9f4aoa 1\r\n4 0\r\nf4m1ec 1\r\nqyr2h6 1\r\n", "output": "3\r\nmove 9f4aoa 1\r\nmove f4m1ec 2\r\nmove qyr2h6 3\r\n"}, {"input": "5\r\n73s1nt 1\r\nsbngv2 0\r\n4n3qri 1\r\nbyhzp8 1\r\nadpjs4 0\r\n", "output": "5\r\nmove 73s1nt 1\r\nmove 4n3qri 2\r\nmove byhzp8 3\r\nmove sbngv2 5\r\nmove adpjs4 4\r\n"}, {"input": "5\r\n7ajg8o 1\r\np7cqxy 1\r\n3qrp34 0\r\nh93m07 1\r\n2 0\r\n", "output": "5\r\nmove 2 5\r\nmove 7ajg8o 1\r\nmove p7cqxy 2\r\nmove h93m07 3\r\nmove 3qrp34 4\r\n"}, {"input": "5\r\ny0wnwz 1\r\n5 0\r\n0totai 1\r\n1 0\r\nym8xwz 1\r\n", "output": "4\r\nmove 1 4\r\nmove y0wnwz 1\r\nmove 0totai 2\r\nmove ym8xwz 3\r\n"}, {"input": "5\r\n5 0\r\n4 0\r\n5nvzu4 1\r\nvkpzzk 1\r\nzamzcz 1\r\n", "output": "3\r\nmove 5nvzu4 1\r\nmove vkpzzk 2\r\nmove zamzcz 3\r\n"}, {"input": "6\r\np1wjw9 1\r\nueksby 0\r\nu1ixfc 1\r\nj3lk2e 1\r\n36iskv 0\r\n9imqi1 0\r\n", "output": "6\r\nmove p1wjw9 1\r\nmove u1ixfc 2\r\nmove j3lk2e 3\r\nmove ueksby 6\r\nmove 36iskv 5\r\nmove 9imqi1 4\r\n"}, {"input": "6\r\n6slonw 1\r\nptk9mc 1\r\n57a4nq 0\r\nhiq2f7 1\r\n2 0\r\nc0gtv3 0\r\n", "output": "6\r\nmove 2 6\r\nmove 6slonw 1\r\nmove ptk9mc 2\r\nmove hiq2f7 3\r\nmove 57a4nq 5\r\nmove c0gtv3 4\r\n"}, {"input": "6\r\n5 0\r\n2 0\r\ncbhvyf 1\r\nl1z5mg 0\r\nwkwhby 1\r\nx7fdh9 1\r\n", "output": "5\r\nmove 2 6\r\nmove cbhvyf 1\r\nmove wkwhby 2\r\nmove x7fdh9 3\r\nmove l1z5mg 4\r\n"}, {"input": "6\r\n1t68ks 1\r\npkbj1g 1\r\n5 0\r\n5pw8wm 1\r\n1 0\r\n4 0\r\n", "output": "4\r\nmove 1 6\r\nmove 1t68ks 1\r\nmove pkbj1g 2\r\nmove 5pw8wm 3\r\n"}, {"input": "3\r\n1 1\r\n7ph5fw 1\r\ntfxz1j 1\r\n", "output": "2\r\nmove 7ph5fw 2\r\nmove tfxz1j 3\r\n"}, {"input": "3\r\norwsz0 1\r\nmbt097 1\r\n3 1\r\n", "output": "2\r\nmove orwsz0 1\r\nmove mbt097 2\r\n"}, {"input": "3\r\n1 1\r\nzwfnx2 1\r\n7g8t6z 1\r\n", "output": "2\r\nmove zwfnx2 2\r\nmove 7g8t6z 3\r\n"}, {"input": "3\r\nqmf7iz 1\r\ndjwdce 1\r\n1 1\r\n", "output": "2\r\nmove qmf7iz 2\r\nmove djwdce 3\r\n"}, {"input": "4\r\n4i2i2a 0\r\n4 1\r\npf618n 1\r\nlx6nmh 1\r\n", "output": "4\r\nmove 4 1\r\nmove pf618n 2\r\nmove lx6nmh 3\r\nmove 4i2i2a 4\r\n"}, {"input": "4\r\nxpteku 1\r\n1 0\r\n4 1\r\n73xpqz 1\r\n", "output": "4\r\nmove 4 2\r\nmove 1 4\r\nmove xpteku 1\r\nmove 73xpqz 3\r\n"}, {"input": "4\r\n1wp56i 1\r\n2 1\r\n1 0\r\n6m76jb 1\r\n", "output": "3\r\nmove 1 4\r\nmove 1wp56i 1\r\nmove 6m76jb 3\r\n"}, {"input": "4\r\n3 1\r\nyumiqt 1\r\n1 0\r\nt19jus 1\r\n", "output": "3\r\nmove 1 4\r\nmove yumiqt 1\r\nmove t19jus 2\r\n"}, {"input": "5\r\nynagvf 1\r\n3 1\r\nojz4mm 1\r\ndovec3 0\r\nnc1jye 0\r\n", "output": "4\r\nmove ynagvf 1\r\nmove ojz4mm 2\r\nmove dovec3 5\r\nmove nc1jye 4\r\n"}, {"input": "5\r\n5 1\r\nwje9ts 1\r\nkytn5q 1\r\n7frk8z 0\r\n3 0\r\n", "output": "5\r\nmove 5 1\r\nmove 3 5\r\nmove wje9ts 2\r\nmove kytn5q 3\r\nmove 7frk8z 4\r\n"}, {"input": "5\r\n1 0\r\n4 1\r\n3 0\r\nlog9cm 1\r\nu5m0ls 1\r\n", "output": "5\r\nmove 4 2\r\nmove 1 5\r\nmove 3 4\r\nmove log9cm 1\r\nmove u5m0ls 3\r\n"}, {"input": "5\r\nh015vv 1\r\n3 1\r\n1 0\r\n9w2keb 1\r\n2 0\r\n", "output": "4\r\nmove 1 5\r\nmove 2 4\r\nmove h015vv 1\r\nmove 9w2keb 2\r\n"}, {"input": "6\r\n0zluka 0\r\nqp7q8l 1\r\nwglqu8 1\r\n9i7kta 0\r\nnwf8m3 0\r\n3 1\r\n", "output": "5\r\nmove qp7q8l 1\r\nmove wglqu8 2\r\nmove 0zluka 6\r\nmove 9i7kta 5\r\nmove nwf8m3 4\r\n"}, {"input": "6\r\n3 1\r\n1h3t85 1\r\n5 0\r\nrf2ikt 0\r\n3vhl6e 1\r\n5l3oka 0\r\n", "output": "4\r\nmove 1h3t85 1\r\nmove 3vhl6e 2\r\nmove rf2ikt 6\r\nmove 5l3oka 4\r\n"}, {"input": "6\r\n2 0\r\n3 0\r\nw9h0pv 1\r\n5 1\r\nq92z4i 0\r\n6qb4ia 1\r\n", "output": "6\r\nmove 5 1\r\nmove 2 6\r\nmove 3 5\r\nmove w9h0pv 2\r\nmove 6qb4ia 3\r\nmove q92z4i 4\r\n"}, {"input": "6\r\n4 1\r\n410jiy 1\r\n1 0\r\n6 0\r\nxc98l2 1\r\n5 0\r\n", "output": "4\r\nmove 4 2\r\nmove 1 4\r\nmove 410jiy 1\r\nmove xc98l2 3\r\n"}, {"input": "3\r\n1 1\r\nc9qyld 1\r\n3 1\r\n", "output": "1\r\nmove c9qyld 2\r\n"}, {"input": "3\r\ngdm5ri 1\r\n1 1\r\n2 1\r\n", "output": "1\r\nmove gdm5ri 3\r\n"}, {"input": "3\r\n3 1\r\n2 1\r\ni19lnk 1\r\n", "output": "1\r\nmove i19lnk 1\r\n"}, {"input": "3\r\ncxbbpd 1\r\n3 1\r\n1 1\r\n", "output": "1\r\nmove cxbbpd 2\r\n"}, {"input": "4\r\nwy6i6o 0\r\n1 1\r\n3 1\r\niy1dq6 1\r\n", "output": "2\r\nmove iy1dq6 2\r\nmove wy6i6o 4\r\n"}, {"input": "4\r\n4 1\r\nwgh8s0 1\r\n1 0\r\n2 1\r\n", "output": "3\r\nmove 4 3\r\nmove 1 4\r\nmove wgh8s0 1\r\n"}, {"input": "4\r\nhex0ur 1\r\n4 1\r\n3 0\r\n2 1\r\n", "output": "3\r\nmove 4 1\r\nmove 3 4\r\nmove hex0ur 3\r\n"}, {"input": "4\r\n4 1\r\n1 1\r\n3 0\r\n4soxj3 1\r\n", "output": "3\r\nmove 4 2\r\nmove 3 4\r\nmove 4soxj3 3\r\n"}, {"input": "5\r\n5sbtul 1\r\n2 1\r\n8i2duz 0\r\n5 1\r\n4b85z6 0\r\n", "output": "4\r\nmove 5 1\r\nmove 5sbtul 3\r\nmove 8i2duz 5\r\nmove 4b85z6 4\r\n"}, {"input": "5\r\n3 1\r\n4 0\r\nejo0a4 1\r\ngqzdbk 0\r\n1 1\r\n", "output": "2\r\nmove ejo0a4 2\r\nmove gqzdbk 5\r\n"}, {"input": "5\r\n2y4agr 1\r\n5 0\r\n3 0\r\n1 1\r\n4 1\r\n", "output": "3\r\nmove 4 2\r\nmove 3 4\r\nmove 2y4agr 3\r\n"}, {"input": "5\r\n2 0\r\n1 1\r\nq4hyeg 1\r\n5 0\r\n4 1\r\n", "output": "3\r\nmove 4 3\r\nmove 2 4\r\nmove q4hyeg 2\r\n"}, {"input": "6\r\n5 1\r\nrdm6fu 0\r\n4 1\r\noclx1h 0\r\n7l3kg1 1\r\nq25te0 0\r\n", "output": "6\r\nmove 5 1\r\nmove 4 2\r\nmove 7l3kg1 3\r\nmove rdm6fu 6\r\nmove oclx1h 5\r\nmove q25te0 4\r\n"}, {"input": "6\r\n1 0\r\np4tuyt 0\r\n5 1\r\n2 1\r\nwrrcmu 1\r\n3r4wqz 0\r\n", "output": "5\r\nmove 5 3\r\nmove 1 6\r\nmove wrrcmu 1\r\nmove p4tuyt 5\r\nmove 3r4wqz 4\r\n"}, {"input": "6\r\n5 1\r\n6 0\r\nxhfzge 0\r\n3 1\r\n1 0\r\n1n9mqv 1\r\n", "output": "4\r\nmove 5 2\r\nmove 1 5\r\nmove 1n9mqv 1\r\nmove xhfzge 4\r\n"}, {"input": "6\r\nhmpfsz 1\r\n6 0\r\n5 1\r\n4 0\r\n1 0\r\n3 1\r\n", "output": "3\r\nmove 5 2\r\nmove 1 5\r\nmove hmpfsz 1\r\n"}, {"input": "3\r\n1 1\r\n3 1\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n2 1\r\n3 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n2 1\r\n1 1\r\n3 1\r\n", "output": "0\r\n"}, {"input": "3\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "0\r\n"}, {"input": "4\r\n3 1\r\n1 1\r\n4 1\r\nd1cks2 0\r\n", "output": "2\r\nmove 4 2\r\nmove d1cks2 4\r\n"}, {"input": "4\r\n4 0\r\n3 1\r\n1 1\r\n2 1\r\n", "output": "0\r\n"}, {"input": "4\r\n2 1\r\n4 1\r\n1 0\r\n3 1\r\n", "output": "3\r\nmove 4 e15gvb\r\nmove 1 4\r\nmove e15gvb 1\r\n"}, {"input": "4\r\n4 1\r\n1 1\r\n3 1\r\n2 0\r\n", "output": "3\r\nmove 4 7l41cc\r\nmove 2 4\r\nmove 7l41cc 2\r\n"}, {"input": "5\r\n4 1\r\nhvshea 0\r\naio11n 0\r\n2 1\r\n3 1\r\n", "output": "3\r\nmove 4 1\r\nmove hvshea 5\r\nmove aio11n 4\r\n"}, {"input": "5\r\n5 0\r\nts7a1c 0\r\n4 1\r\n1 1\r\n2 1\r\n", "output": "2\r\nmove 4 3\r\nmove ts7a1c 4\r\n"}, {"input": "5\r\n4 0\r\n3 1\r\n5 0\r\n2 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "5\r\n3 1\r\n5 0\r\n4 1\r\n1 1\r\n2 0\r\n", "output": "3\r\nmove 4 kmnhgt\r\nmove 2 4\r\nmove kmnhgt 2\r\n"}, {"input": "6\r\neik3kw 0\r\n5 1\r\nzoonoj 0\r\n2 1\r\n1 1\r\nivzfie 0\r\n", "output": "4\r\nmove 5 3\r\nmove eik3kw 6\r\nmove zoonoj 5\r\nmove ivzfie 4\r\n"}, {"input": "6\r\n7igwk9 0\r\n6 1\r\n5 1\r\ndx2yu0 0\r\n2 0\r\n1 1\r\n", "output": "5\r\nmove 6 3\r\nmove 2 6\r\nmove 5 2\r\nmove 7igwk9 5\r\nmove dx2yu0 4\r\n"}, {"input": "6\r\nc3py3h 0\r\n2 1\r\n4 0\r\n3 0\r\n1 1\r\n5 1\r\n", "output": "3\r\nmove 3 6\r\nmove 5 3\r\nmove c3py3h 5\r\n"}, {"input": "6\r\n1 1\r\n3 0\r\n2 1\r\n6 1\r\n4 0\r\n5 0\r\n", "output": "3\r\nmove 3 4r6zp7\r\nmove 6 3\r\nmove 4r6zp7 6\r\n"}, {"input": "20\r\nphp8vy 1\r\nkeeona 0\r\n8 0\r\nwzf4eb 0\r\n16 1\r\n9 0\r\nf2548d 0\r\n11 0\r\nyszsig 0\r\nyyf4q2 0\r\n1pon1p 1\r\njvpwuo 0\r\nd9stsx 0\r\ne14bkx 1\r\n5 0\r\n17 0\r\nsbklx4 0\r\nsfms2u 1\r\n6 0\r\n18 1\r\n", "output": "16\r\nmove 16 1\r\nmove 18 2\r\nmove 5 20\r\nmove 6 19\r\nmove php8vy 3\r\nmove 1pon1p 4\r\nmove e14bkx 5\r\nmove sfms2u 6\r\nmove keeona 18\r\nmove wzf4eb 16\r\nmove f2548d 15\r\nmove yszsig 14\r\nmove yyf4q2 13\r\nmove jvpwuo 12\r\nmove d9stsx 10\r\nmove sbklx4 7\r\n"}, {"input": "4\r\n3 1\r\n4 1\r\n1 0\r\n2 0\r\n", "output": "5\r\nmove 3 41nqph\r\nmove 1 3\r\nmove 4 1\r\nmove 2 4\r\nmove 41nqph 2\r\n"}, {"input": "1\r\n01 1\r\n", "output": "1\r\nmove 01 1\r\n"}, {"input": "2\r\n01 0\r\n02 1\r\n", "output": "2\r\nmove 02 1\r\nmove 01 2\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: n = int(f.readline()) files = [] type1_count = 0 for _ in range(n): line = f.readline().strip() name, typ = line.split() files.append((name, typ)) if typ == '1': type1_count += 1 e = type1_count cnt = 0 valid_numbers = set() for name, typ in files: if name.isdigit() and (len(name) == 1 or name[0] != '0'): num = int(name) if 1 <= num <= n: valid_numbers.add(num) if typ == '1': if not name.isdigit() or (len(name) > 1 and name[0] == '0'): cnt += 1 continue num = int(name) if not (1 <= num <= e): cnt += 1 else: if not name.isdigit() or (len(name) > 1 and name[0] == '0'): cnt += 1 continue num = int(name) if not (e + 1 <= num <= n): cnt += 1 initial_free = n - len(valid_numbers) minimal_steps = cnt + 1 if (initial_free == 0 and cnt > 0) else cnt with open(submission_path) as f: lines = f.read().splitlines() if not lines: print(0) return try: k = int(lines[0]) except: print(0) return if k != minimal_steps: print(0) return moves = lines[1:] if len(moves) != k: print(0) return current_files = {name: typ for name, typ in files} for move in moves: parts = move.split() if len(parts) != 3 or parts[0] != 'move': print(0) return src, dst = parts[1], parts[2] if src not in current_files: print(0) return typ = current_files.pop(src) current_files[dst] = typ names = list(current_files.keys()) if len(names) != n: print(0) return nums = [] for name in names: if not name.isdigit() or (len(name) > 1 and name[0] == '0'): print(0) return num = int(name) if num < 1 or num > n: print(0) return nums.append(num) if sorted(nums) != list(range(1, n + 1)): print(0) return for name, typ in current_files.items(): num = int(name) if typ == '1' and num > e: print(0) return if typ == '0' and num <= e: print(0) return print(1) if __name__ == "__main__": main()
true
789/B
789
B
PyPy 3
TESTS
14
218
10,752,000
92449543
import math b1,q,l,m=list(map(int,input().split())) a=list(map(int,input().split())) if abs(b1)>l: print(0) elif b1==0: if b1 in a: print(0) else: print('inf') elif q==1: if b1 in a: print(0) else: print('inf') elif q==-1: if b1 in a and -b1 in a: print(0) else: print('inf') elif q==0: if 0 not in a: print('inf') elif b1 in a: print(0) else: print(1) else: n=int(math.log(abs(l)/abs(b1))/math.log(abs(q)))+1 if n<=0: print(0) else: for i in range(m): x=a[i]/b1 c=int(math.log(abs(x))/math.log(abs(q))) if b1*(q**c)==a[i] and c<=(n-1) and c>=0: n=n-1 if n<=0: print(0) else: print(n)
116
93
12,902,400
25933157
b, q, l, m = list(map(int, input().split())) a = set(list(map(int, input().split()))) ans = 0 boo = False i = 0 while (i < 34) and (abs(b) <= l): if (b not in a): ans += 1 if i > 31: boo = True b *= q i += 1 if boo: print('inf') else: print(ans)
Codeforces Round 407 (Div. 2)
CF
2,017
1
256
Masha and geometric depression
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board.
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
null
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123.
[{"input": "3 2 30 4\n6 14 25 48", "output": "3"}, {"input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0"}, {"input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf"}]
1,700
["brute force", "implementation", "math"]
116
[{"input": "3 2 30 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "123 1 2143435 4\r\n123 11 -5453 141245\r\n", "output": "0"}, {"input": "123 1 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "3 2 25 2\r\n379195692 -69874783\r\n", "output": "4"}, {"input": "3 2 30 3\r\n-691070108 -934106649 -220744807\r\n", "output": "4"}, {"input": "3 3 104 17\r\n9 -73896485 -290898562 5254410 409659728 -916522518 -435516126 94354167 262981034 -375897180 -80186684 -173062070 -288705544 -699097793 -11447747 320434295 503414250\r\n", "output": "3"}, {"input": "-1000000000 -1000000000 1 1\r\n232512888\r\n", "output": "0"}, {"input": "11 0 228 5\r\n-1 0 1 5 -11245\r\n", "output": "1"}, {"input": "11 0 228 5\r\n-1 -17 1 5 -11245\r\n", "output": "inf"}, {"input": "0 0 2143435 5\r\n-1 -153 1 5 -11245\r\n", "output": "inf"}, {"input": "123 0 2143435 4\r\n5433 0 123 -645\r\n", "output": "0"}, {"input": "123 -1 2143435 5\r\n-123 0 12 5 -11245\r\n", "output": "inf"}, {"input": "123 0 21 4\r\n543453 -123 6 1424\r\n", "output": "0"}, {"input": "3 2 115 16\r\n24 48 12 96 3 720031148 -367712651 -838596957 558177735 -963046495 -313322487 -465018432 -618984128 -607173835 144854086 178041956\r\n", "output": "1"}, {"input": "-3 0 92055 36\r\n-92974174 -486557474 -663622151 695596393 177960746 -563227474 -364263320 -676254242 -614140218 71456762 -764104225 705056581 -106398436 332755134 -199942822 -732751692 658942664 677739866 886535704 183687802 -784248291 -22550621 -938674499 637055091 -704750213 780395802 778342470 -999059668 -794361783 796469192 215667969 354336794 -60195289 -885080928 -290279020 201221317\r\n", "output": "inf"}, {"input": "0 -3 2143435 5\r\n-1 0 1 5 -11245\r\n", "output": "0"}, {"input": "123 -1 2143435 5\r\n-123 0 123 -5453 141245\r\n", "output": "0"}, {"input": "123 0 2143435 4\r\n5433 0 -123 -645\r\n", "output": "1"}, {"input": "11 0 2 5\r\n-1 0 1 5 -11245\r\n", "output": "0"}, {"input": "2 2 4 1\r\n2\r\n", "output": "1"}, {"input": "1 -2 1000000000 1\r\n0\r\n", "output": "30"}, {"input": "0 8 10 1\r\n5\r\n", "output": "inf"}, {"input": "-1000 0 10 1\r\n5\r\n", "output": "0"}, {"input": "0 2 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "0 8 5 1\r\n9\r\n", "output": "inf"}, {"input": "-10 1 5 1\r\n100\r\n", "output": "0"}, {"input": "123 -1 2143435 4\r\n54343 -13 6 123\r\n", "output": "inf"}, {"input": "-5 -1 10 1\r\n-5\r\n", "output": "inf"}, {"input": "2 0 1 1\r\n2\r\n", "output": "0"}, {"input": "0 5 8 1\r\n10\r\n", "output": "inf"}, {"input": "0 5 100 2\r\n34 56\r\n", "output": "inf"}, {"input": "15 -1 15 4\r\n15 -15 1 2\r\n", "output": "0"}, {"input": "10 -1 2 1\r\n1\r\n", "output": "0"}, {"input": "2 0 2 1\r\n2\r\n", "output": "inf"}, {"input": "4 0 4 1\r\n0\r\n", "output": "1"}, {"input": "10 10 10 1\r\n123\r\n", "output": "1"}, {"input": "2 2 4 1\r\n3\r\n", "output": "2"}, {"input": "0 1 1 1\r\n0\r\n", "output": "0"}, {"input": "3 2 30 1\r\n3\r\n", "output": "3"}, {"input": "1000000000 100000 1000000000 4\r\n5433 13 6 0\r\n", "output": "1"}, {"input": "-2 0 1 1\r\n1\r\n", "output": "0"}, {"input": "2 -1 10 1\r\n2\r\n", "output": "inf"}, {"input": "1 -1 2 1\r\n1\r\n", "output": "inf"}, {"input": "0 10 10 1\r\n2\r\n", "output": "inf"}, {"input": "0 35 2 1\r\n3\r\n", "output": "inf"}, {"input": "3 1 3 1\r\n5\r\n", "output": "inf"}, {"input": "3 2 3 4\r\n6 14 25 48\r\n", "output": "1"}, {"input": "0 69 12 1\r\n1\r\n", "output": "inf"}, {"input": "100 0 100000 1\r\n100\r\n", "output": "inf"}, {"input": "0 4 1000 3\r\n5 6 7\r\n", "output": "inf"}, {"input": "0 2 100 1\r\n5\r\n", "output": "inf"}, {"input": "3 2 24 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "0 4 1 1\r\n2\r\n", "output": "inf"}, {"input": "1 5 10000 1\r\n125\r\n", "output": "5"}, {"input": "2 -1 1 1\r\n1\r\n", "output": "0"}, {"input": "0 3 100 1\r\n5\r\n", "output": "inf"}, {"input": "0 3 3 1\r\n1\r\n", "output": "inf"}, {"input": "0 2 5 1\r\n1\r\n", "output": "inf"}, {"input": "5 -1 100 1\r\n5\r\n", "output": "inf"}, {"input": "-20 0 10 1\r\n0\r\n", "output": "0"}, {"input": "3 0 1 1\r\n3\r\n", "output": "0"}, {"input": "2 -1 3 1\r\n2\r\n", "output": "inf"}, {"input": "1 1 1000000000 1\r\n100\r\n", "output": "inf"}, {"input": "5 -1 3 1\r\n0\r\n", "output": "0"}, {"input": "0 5 10 1\r\n2\r\n", "output": "inf"}, {"input": "123 0 125 1\r\n123\r\n", "output": "inf"}, {"input": "2 -1 100 1\r\n2\r\n", "output": "inf"}, {"input": "5 2 100 1\r\n5\r\n", "output": "4"}, {"input": "-5 0 1 1\r\n1\r\n", "output": "0"}, {"input": "-3 0 1 1\r\n-3\r\n", "output": "0"}, {"input": "2 -2 10 1\r\n1\r\n", "output": "3"}, {"input": "0 2 30 4\r\n6 14 25 48\r\n", "output": "inf"}, {"input": "1 -1 1 1\r\n1\r\n", "output": "inf"}, {"input": "2 -1 6 1\r\n2\r\n", "output": "inf"}, {"input": "-3 1 100 1\r\n-3\r\n", "output": "0"}, {"input": "1 0 2 1\r\n1\r\n", "output": "inf"}, {"input": "1000000000 999999998 1000000000 1\r\n0\r\n", "output": "1"}, {"input": "1 0 2143435 4\r\n1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "-1000 0 100 1\r\n-1000\r\n", "output": "0"}, {"input": "100 10 2 1\r\n100\r\n", "output": "0"}, {"input": "-3 1 100 1\r\n3\r\n", "output": "inf"}, {"input": "123 -1 10000 1\r\n123\r\n", "output": "inf"}, {"input": "1 -1 2143435 4\r\n1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "5 1 5 5\r\n1 2 3 4 0\r\n", "output": "inf"}, {"input": "-100 -1 1 1\r\n1\r\n", "output": "0"}, {"input": "10 -1 3 2\r\n10 8\r\n", "output": "0"}, {"input": "-10 0 5 1\r\n0\r\n", "output": "0"}, {"input": "3 0 3 1\r\n0\r\n", "output": "1"}, {"input": "2 0 2 1\r\n-1\r\n", "output": "inf"}, {"input": "5 0 20 1\r\n5\r\n", "output": "inf"}, {"input": "-4 1 1 1\r\n0\r\n", "output": "0"}, {"input": "11 0 1111 1\r\n11\r\n", "output": "inf"}, {"input": "2 0 3 1\r\n2\r\n", "output": "inf"}, {"input": "-1 -1 2143435 4\r\n-1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "-100 0 50 1\r\n0\r\n", "output": "0"}, {"input": "5 1 2 1\r\n2\r\n", "output": "0"}, {"input": "3 0 3 1\r\n4\r\n", "output": "inf"}, {"input": "0 23 3 1\r\n3\r\n", "output": "inf"}, {"input": "-1000 0 100 1\r\n2\r\n", "output": "0"}, {"input": "1 -1 10 1\r\n1\r\n", "output": "inf"}]
false
stdio
null
true
750/B
750
B
PyPy 3-64
TESTS
28
61
0
207347320
def main(): n = int(input().strip()) north = 0 verdict = None for _ in range(n): dir = input().strip().split() s = int(dir[0]) dir = dir[1] if verdict is not None: continue if north % 40000 == 0 and dir != "South": verdict = "NO" continue elif north % 20000 == 0 and north % 40000 != 0 and dir != "North": verdict = "NO" continue if dir == "South": north += s if dir == "North": north -= s if verdict != None: print(verdict) else: if north % 40000 == 0: verdict = "YES" else: verdict = "NO" print(verdict) if __name__ == "__main__": main()
140
62
4,710,400
23434950
""" Author : Arif Ahmad Date : Algo : Difficulty : """ def main(): n = int(input()) ans = "YES" pos = 0 for i in range(n): t, direction = input().split() t = int(t) if (pos==0 and direction!='South') or (pos==20000 and direction!='North'): ans = "NO" break if direction == 'East' or direction == 'West': continue if direction == 'South': pos += t if pos > 20000: ans = "NO" break else: pos -= t if pos < 0: ans = "NO" break if pos != 0: ans = "NO" print(ans) if __name__ == '__main__': main()
Good Bye 2016
CF
2,016
2
256
New Year and North Pole
In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers. Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move ti kilometers in the direction represented by a string diri that is one of: "North", "South", "West", "East". Limak isn’t sure whether the description is valid. You must help him to check the following conditions: - If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South. - If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North. - The journey must end on the North Pole. Check if the above conditions are satisfied and print "YES" or "NO" on a single line.
The first line of the input contains a single integer n (1 ≤ n ≤ 50). The i-th of next n lines contains an integer ti and a string diri (1 ≤ ti ≤ 106, $${ dir } _ { i } \in \{ \mathrm { N o r t h, ~ S o u t h, ~ W e s t, ~ E a s t } \}$$) — the length and the direction of the i-th part of the journey, according to the description Limak got.
Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes.
null
Drawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole.
[{"input": "5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North", "output": "YES"}, {"input": "2\n15000 South\n4000 East", "output": "NO"}, {"input": "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North", "output": "YES"}, {"input": "3\n20000 South\n10 East\n20000 North", "output": "NO"}, {"input": "2\n1000 North\n1000 South", "output": "NO"}, {"input": "4\n50 South\n50 North\n15000 South\n15000 North", "output": "YES"}]
1,300
["geometry", "implementation"]
140
[{"input": "5\r\n7500 South\r\n10000 East\r\n3500 North\r\n4444 West\r\n4000 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n15000 South\r\n4000 East\r\n", "output": "NO\r\n"}, {"input": "5\r\n20000 South\r\n1000 North\r\n1000000 West\r\n9000 North\r\n10000 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n20000 South\r\n10 East\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n1000 North\r\n1000 South\r\n", "output": "NO\r\n"}, {"input": "4\r\n50 South\r\n50 North\r\n15000 South\r\n15000 North\r\n", "output": "YES\r\n"}, {"input": "1\r\n1 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n1 East\r\n", "output": "NO\r\n"}, {"input": "2\r\n1000000 South\r\n1000000 North\r\n", "output": "NO\r\n"}, {"input": "1\r\n149 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n16277 East\r\n", "output": "NO\r\n"}, {"input": "1\r\n19701 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n3125 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n6549 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n2677 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n6101 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n9525 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n5653 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n15072 South\r\n15072 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n11200 South\r\n11200 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n14624 South\r\n14624 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n18048 South\r\n15452 West\r\n", "output": "NO\r\n"}, {"input": "2\r\n1472 West\r\n4930 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n17600 South\r\n17600 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n8320 East\r\n16589 East\r\n", "output": "NO\r\n"}, {"input": "2\r\n4448 South\r\n4448 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n576 South\r\n576 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n14186 South\r\n2291 West\r\n14186 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n10314 South\r\n15961 North\r\n5647 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n1035 East\r\n18143 South\r\n18143 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n17163 South\r\n7620 East\r\n17163 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n587 South\r\n17098 North\r\n16511 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n16715 North\r\n6576 West\r\n12132 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n7435 South\r\n245 North\r\n7190 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n3563 South\r\n2427 South\r\n5990 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n6987 South\r\n11904 East\r\n19951 East\r\n", "output": "NO\r\n"}, {"input": "4\r\n13301 South\r\n5948 East\r\n9265 East\r\n6891 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n16725 South\r\n8129 South\r\n19530 West\r\n24854 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n149 South\r\n17607 West\r\n18306 South\r\n18455 North\r\n", "output": "YES\r\n"}, {"input": "4\r\n16277 South\r\n19789 North\r\n4379 South\r\n867 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n19701 South\r\n13458 South\r\n3156 North\r\n30003 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n3125 South\r\n15640 East\r\n6125 East\r\n19535 South\r\n", "output": "NO\r\n"}, {"input": "4\r\n6549 East\r\n5118 North\r\n12198 East\r\n5118 South\r\n", "output": "NO\r\n"}, {"input": "4\r\n2677 East\r\n1891 West\r\n10974 West\r\n7511 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n6102 South\r\n8265 East\r\n13943 South\r\n20045 North\r\n", "output": "NO\r\n"}, {"input": "5\r\n12416 South\r\n18116 North\r\n10553 West\r\n18435 West\r\n5700 South\r\n", "output": "NO\r\n"}, {"input": "5\r\n15840 South\r\n7594 South\r\n13522 South\r\n2423 South\r\n3334 West\r\n", "output": "NO\r\n"}, {"input": "5\r\n19264 East\r\n13968 East\r\n19595 North\r\n19115 North\r\n38710 South\r\n", "output": "NO\r\n"}, {"input": "5\r\n15392 South\r\n3445 North\r\n18372 East\r\n10399 North\r\n4403 South\r\n", "output": "NO\r\n"}, {"input": "5\r\n18816 South\r\n5627 West\r\n14045 East\r\n7091 East\r\n18816 North\r\n", "output": "YES\r\n"}, {"input": "5\r\n2240 South\r\n15104 North\r\n118 West\r\n11079 East\r\n12864 South\r\n", "output": "NO\r\n"}, {"input": "5\r\n5664 South\r\n1478 South\r\n18894 South\r\n2363 West\r\n26036 North\r\n", "output": "NO\r\n"}, {"input": "5\r\n1792 South\r\n10956 East\r\n9159 South\r\n19055 West\r\n10951 North\r\n", "output": "YES\r\n"}, {"input": "5\r\n12512 South\r\n13137 North\r\n7936 North\r\n7235 South\r\n1326 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n14635 North\r\n14477 South\r\n17250 North\r\n14170 East\r\n15166 South\r\n2242 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n10763 North\r\n3954 West\r\n7515 North\r\n18158 West\r\n6644 South\r\n11634 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n14187 South\r\n13432 North\r\n6292 East\r\n14850 West\r\n10827 South\r\n9639 East\r\n", "output": "NO\r\n"}, {"input": "6\r\n10315 South\r\n15614 South\r\n5069 West\r\n6134 South\r\n7713 North\r\n24350 North\r\n", "output": "NO\r\n"}, {"input": "6\r\n1035 South\r\n9283 East\r\n15333 South\r\n2826 South\r\n19191 North\r\n3 North\r\n", "output": "YES\r\n"}, {"input": "6\r\n17163 West\r\n11465 North\r\n14110 South\r\n6814 North\r\n3373 East\r\n4169 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n587 South\r\n942 West\r\n183 North\r\n18098 North\r\n260 East\r\n17694 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n16715 West\r\n3124 East\r\n3152 East\r\n14790 East\r\n11738 West\r\n11461 East\r\n", "output": "NO\r\n"}, {"input": "6\r\n7435 South\r\n12602 South\r\n1929 East\r\n6074 East\r\n15920 West\r\n20037 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n13750 South\r\n6645 South\r\n18539 East\r\n5713 North\r\n1580 North\r\n10012 West\r\n13102 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n9878 West\r\n8827 East\r\n1508 West\r\n9702 North\r\n5763 North\r\n9755 North\r\n10034 South\r\n", "output": "NO\r\n"}, {"input": "7\r\n13302 West\r\n2496 North\r\n284 West\r\n6394 East\r\n9945 North\r\n12603 West\r\n12275 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n16726 East\r\n19270 West\r\n6357 South\r\n17678 East\r\n14127 East\r\n12347 South\r\n6005 East\r\n", "output": "NO\r\n"}, {"input": "7\r\n150 South\r\n1452 North\r\n9326 North\r\n1666 West\r\n18309 East\r\n19386 East\r\n8246 West\r\n", "output": "NO\r\n"}, {"input": "7\r\n16278 South\r\n10929 South\r\n8103 East\r\n18358 West\r\n2492 West\r\n11834 South\r\n39041 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n19702 South\r\n13111 East\r\n6880 East\r\n9642 South\r\n6674 West\r\n18874 East\r\n1112 North\r\n", "output": "NO\r\n"}, {"input": "7\r\n3126 South\r\n6780 North\r\n9848 West\r\n6334 North\r\n10856 West\r\n14425 West\r\n10649 East\r\n", "output": "NO\r\n"}, {"input": "7\r\n6550 South\r\n8962 West\r\n15921 South\r\n17618 North\r\n15038 South\r\n1465 North\r\n18426 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n12864 South\r\n3005 West\r\n16723 West\r\n17257 West\r\n12187 East\r\n12976 South\r\n1598 North\r\n24242 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n8992 South\r\n12483 North\r\n15500 South\r\n1245 South\r\n9073 East\r\n12719 East\r\n3839 East\r\n7130 South\r\n", "output": "NO\r\n"}, {"input": "8\r\n12416 North\r\n14665 South\r\n14277 North\r\n2129 South\r\n13255 East\r\n19759 South\r\n10272 West\r\n9860 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n15840 South\r\n4142 East\r\n17246 North\r\n13413 North\r\n4733 West\r\n15311 North\r\n12514 South\r\n17616 South\r\n", "output": "NO\r\n"}, {"input": "8\r\n19264 South\r\n10516 North\r\n3319 East\r\n17401 East\r\n1620 West\r\n2350 West\r\n6243 North\r\n2505 North\r\n", "output": "YES\r\n"}, {"input": "8\r\n15392 South\r\n7290 West\r\n2096 West\r\n14093 East\r\n5802 South\r\n2094 North\r\n8484 East\r\n19100 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n6113 South\r\n16767 East\r\n5064 South\r\n5377 West\r\n17280 South\r\n1838 West\r\n2213 West\r\n28457 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n2241 West\r\n18949 South\r\n11137 South\r\n2069 West\r\n14166 South\r\n1581 South\r\n4455 South\r\n50288 North\r\n", "output": "NO\r\n"}, {"input": "8\r\n5665 South\r\n8426 East\r\n9914 North\r\n13353 South\r\n18349 North\r\n4429 East\r\n18184 North\r\n27429 South\r\n", "output": "NO\r\n"}, {"input": "9\r\n11979 South\r\n2470 East\r\n10716 North\r\n12992 East\r\n15497 West\r\n15940 North\r\n8107 West\r\n18934 East\r\n6993 South\r\n", "output": "NO\r\n"}, {"input": "9\r\n8107 South\r\n4652 North\r\n9493 North\r\n16980 West\r\n12383 West\r\n2980 West\r\n17644 South\r\n11043 West\r\n11447 North\r\n", "output": "NO\r\n"}, {"input": "9\r\n18827 South\r\n18321 West\r\n8270 East\r\n968 West\r\n16565 West\r\n15427 North\r\n4077 North\r\n18960 North\r\n19006 West\r\n", "output": "NO\r\n"}, {"input": "9\r\n14955 West\r\n503 North\r\n18535 West\r\n4956 South\r\n8044 South\r\n2467 East\r\n13615 East\r\n6877 East\r\n3460 North\r\n", "output": "NO\r\n"}, {"input": "9\r\n18379 South\r\n9980 South\r\n17311 West\r\n8944 South\r\n4930 South\r\n18019 South\r\n48 West\r\n14794 South\r\n75046 North\r\n", "output": "NO\r\n"}, {"input": "9\r\n14507 East\r\n12162 East\r\n16088 South\r\n5636 North\r\n9112 North\r\n5058 East\r\n9585 South\r\n2712 East\r\n10925 North\r\n", "output": "NO\r\n"}, {"input": "9\r\n5227 East\r\n8936 North\r\n6353 North\r\n16920 North\r\n591 North\r\n4802 South\r\n8722 North\r\n3333 West\r\n36720 South\r\n", "output": "NO\r\n"}, {"input": "9\r\n1355 North\r\n15309 West\r\n17834 North\r\n13612 East\r\n17477 North\r\n4546 North\r\n18260 East\r\n15442 North\r\n56654 South\r\n", "output": "NO\r\n"}, {"input": "9\r\n4779 South\r\n4787 East\r\n3907 East\r\n4896 East\r\n1659 East\r\n4289 West\r\n4693 West\r\n3359 East\r\n4779 North\r\n", "output": "YES\r\n"}, {"input": "1\r\n80000 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n40000 South\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "1\r\n40000 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n20001 South\r\n20001 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n10000 South\r\n20000 South\r\n10000 North\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n10 South\r\n20 North\r\n10 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1000 South\r\n1001 North\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20000 South\r\n20000 West\r\n", "output": "NO\r\n"}, {"input": "3\r\n10000 South\r\n20000 South\r\n10000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 East\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20000 West\r\n20000 West\r\n", "output": "NO\r\n"}, {"input": "2\r\n80000 South\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n19999 South\r\n20001 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n500 South\r\n1000 North\r\n500 North\r\n", "output": "NO\r\n"}, {"input": "1\r\n400000 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n40000 South\r\n80000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n100 West\r\n100 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n40000 South\r\n40000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n30000 South\r\n10000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20000 South\r\n40000 North\r\n", "output": "NO\r\n"}, {"input": "10\r\n20000 South\r\n20000 North\r\n20000 South\r\n20000 North\r\n20000 South\r\n20000 North\r\n20000 South\r\n20000 North\r\n20000 South\r\n20000 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n40001 South\r\n40001 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n40001 South\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n50000 South\r\n50000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n30000 South\r\n30000 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n10000 South\r\n50000 North\r\n", "output": "NO\r\n"}, {"input": "4\r\n15000 South\r\n15000 South\r\n15000 North\r\n15000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n50 South\r\n100 North\r\n50 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20001 South\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n5 South\r\n6 North\r\n1 South\r\n", "output": "NO\r\n"}, {"input": "1\r\n20000 South\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 South\r\n20000 South\r\n1 North\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n30000 South\r\n30000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n2 North\r\n1 South\r\n", "output": "NO\r\n"}, {"input": "2\r\n60000 South\r\n60000 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n50000 South\r\n10000 North\r\n", "output": "NO\r\n"}, {"input": "1\r\n5 North\r\n", "output": "NO\r\n"}, {"input": "2\r\n20010 South\r\n19990 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n20000 South\r\n1 South\r\n20000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n2 North\r\n39999 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n10 South\r\n20 North\r\n10 South\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n2 North\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n2000 South\r\n19000 South\r\n19000 South\r\n", "output": "NO\r\n"}, {"input": "6\r\n15000 South\r\n15000 South\r\n15000 South\r\n15000 North\r\n15000 North\r\n15000 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n1 North\r\n1 East\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 West\r\n1 North\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 South\r\n123456 West\r\n1 North\r\n", "output": "YES\r\n"}]
false
stdio
null
true
808/D
808
D
PyPy 3-64
TESTS
44
155
27,136,000
168410800
from collections import defaultdict from bisect import bisect_left def values():return tuple(map(int,input().split())) def inlst():return list(map(int,input().split())) def inp():return int(input()) def solve(n,l,s): st = set() t=s//2 d=defaultdict(int) d2 = defaultdict(int) for i in l: d[i]+=1 tmp=0 for i in l: d[i]-=1 d2[i]+=1 if t==tmp:return "YES" if t-tmp>0 and d[t-tmp]>0:return "YES" if tmp -t> 0 and d2[ tmp-t] > 0: return "YES" tmp += i return "NO" n=inp() l=inlst() s=sum(l) if (s//2)*2!=s:print("NO") else:print((solve(n,l,s)))
115
108
18,022,400
166889423
n = int(input()) arr = list(map(int, input().split())) def solve(n, a): s = sum(a) if n == 1 or s & 1: print('NO') return half = s // 2 def judge(a): pre, st = 0, {0} for num in a: st.add(num) pre += num if pre - half in st: return True return False print('YES' if judge(a) or judge(a[::-1]) else 'NO') solve(n, arr)
Educational Codeforces Round 21
ICPC
2,017
2
256
Array Division
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position). Inserting an element in the same position he was erased from is also considered moving. Can Vasya divide the array after choosing the right element to move and its new position?
The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array. The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array.
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
null
In the first example Vasya can move the second element to the end of the array. In the second example no move can make the division possible. In the third example Vasya can move the fourth element by one position to the left.
[{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}]
1,900
["binary search", "data structures", "implementation"]
115
[{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "output": "NO\r\n"}, {"input": "8\r\n9 5 5 10 4 9 5 8\r\n", "output": "NO\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "YES\r\n"}, {"input": "15\r\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8\r\n", "output": "NO\r\n"}, {"input": "20\r\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13\r\n", "output": "NO\r\n"}, {"input": "20\r\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 10 6\r\n", "output": "NO\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": "YES\r\n"}, {"input": "100\r\n89 38 63 73 77 4 99 74 30 5 69 57 97 37 88 71 36 59 19 63 46 20 33 58 61 98 100 31 33 53 99 96 34 17 44 95 54 52 22 77 67 88 20 88 26 43 12 23 96 94 14 7 57 86 56 54 32 8 3 43 97 56 74 22 5 100 12 60 93 12 44 68 31 63 7 71 21 29 19 38 50 47 97 43 50 59 88 40 51 61 20 68 32 66 70 48 19 55 91 53\r\n", "output": "NO\r\n"}, {"input": "100\r\n80 100 88 52 25 87 85 8 92 62 35 66 74 39 58 41 55 53 23 73 90 72 36 44 97 67 16 54 3 8 25 34 84 47 77 39 93 19 49 20 29 44 21 48 21 56 82 59 8 31 94 95 84 54 72 20 95 91 85 1 67 19 76 28 31 63 87 98 55 28 16 20 36 91 93 39 94 69 80 97 100 96 68 26 91 45 22 84 20 36 20 92 53 75 58 51 60 26 76 25\r\n", "output": "NO\r\n"}, {"input": "100\r\n27 95 57 29 91 85 83 36 72 86 39 5 79 61 78 93 100 97 73 23 82 66 41 92 38 92 100 96 48 56 66 47 5 32 69 13 95 23 46 62 99 83 57 66 98 82 81 57 37 37 81 64 45 76 72 43 99 76 86 22 37 39 93 80 99 36 53 83 3 32 52 9 78 34 47 100 33 72 19 40 29 56 77 32 79 72 15 88 100 98 56 50 22 81 88 92 58 70 21 19\r\n", "output": "NO\r\n"}, {"input": "100\r\n35 31 83 11 7 94 57 58 30 26 2 99 33 58 98 6 3 52 13 66 21 53 26 94 100 5 1 3 91 13 97 49 86 25 63 90 88 98 57 57 34 81 32 16 65 94 59 83 44 14 46 18 28 89 75 95 87 57 52 18 46 80 31 43 38 54 69 75 82 9 64 96 75 40 96 52 67 85 86 38 95 55 16 57 17 20 22 7 63 3 12 16 42 87 46 12 51 95 67 80\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 4 3 100 100 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n6 100 100 3 4 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n4 2 3 7 1 1\r\n", "output": "YES\r\n"}, {"input": "4\r\n6 1 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n228 114 114\r\n", "output": "YES\r\n"}, {"input": "3\r\n229 232 444\r\n", "output": "NO\r\n"}, {"input": "3\r\n322 324 555\r\n", "output": "NO\r\n"}, {"input": "3\r\n69 34 5\r\n", "output": "NO\r\n"}, {"input": "6\r\n5 4 1 2 2 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n545 237 546\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 3 1 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 2 10 2 2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n5 4 6 5 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 6 1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 1 8 5 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n73 67 16 51 56 71 37 49 90 6\r\n", "output": "NO\r\n"}, {"input": "1\r\n10\r\n", "output": "NO\r\n"}, {"input": "1\r\n1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n8 2 7 5 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n2\r\n", "output": "NO\r\n"}, {"input": "16\r\n9 10 2 1 6 7 6 5 8 3 2 10 8 4 9 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4\r\n", "output": "YES\r\n"}, {"input": "19\r\n9 9 3 2 4 5 5 7 8 10 8 10 1 2 2 6 5 3 3\r\n", "output": "NO\r\n"}, {"input": "11\r\n7 2 1 8 8 2 4 10 8 7 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n10 20 30 40 99 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n3 7 9 2 10 1 9 6 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n9 3\r\n", "output": "NO\r\n"}, {"input": "7\r\n1 2 3 12 1 2 3\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 4 4 5 8 5\r\n", "output": "YES\r\n"}, {"input": "18\r\n2 10 3 6 6 6 10 8 8 1 10 9 9 3 1 9 7 4\r\n", "output": "YES\r\n"}, {"input": "20\r\n9 6 6 10 4 4 8 7 4 10 10 2 10 5 9 5 3 10 1 9\r\n", "output": "NO\r\n"}, {"input": "12\r\n3 8 10 2 4 4 6 9 5 10 10 3\r\n", "output": "YES\r\n"}, {"input": "11\r\n9 2 7 7 7 3 7 5 4 10 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 4 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n7 1\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 5 6 7 6\r\n", "output": "YES\r\n"}, {"input": "11\r\n4 3 10 3 7 8 4 9 2 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n705032704 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 5 6 8 3 1 7 3\r\n", "output": "YES\r\n"}, {"input": "20\r\n8 6 3 6 3 5 10 2 6 1 7 6 9 10 8 3 5 9 3 8\r\n", "output": "YES\r\n"}, {"input": "11\r\n2 4 8 3 4 7 9 10 5 3 3\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 4 2 24 6 4 2\r\n", "output": "YES\r\n"}, {"input": "17\r\n7 1 1 1 8 9 1 10 8 8 7 9 7 9 1 6 5\r\n", "output": "NO\r\n"}, {"input": "7\r\n7 10 1 2 6 2 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 10 40 10 10\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 3 13\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 10 2 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n7 4 5 62 20 20 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n1 5 2 20 10 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n5 6\r\n", "output": "NO\r\n"}, {"input": "14\r\n5 2 9 7 5 8 3 2 2 4 9 1 3 10\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 2 2 5 5\r\n", "output": "NO\r\n"}, {"input": "11\r\n1 1 1 1 1 10 1 1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "9\r\n8 4 13 19 11 1 8 2 8\r\n", "output": "YES\r\n"}, {"input": "6\r\n14 16 14 14 15 11\r\n", "output": "YES\r\n"}, {"input": "9\r\n14 19 1 13 11 3 1 1 7\r\n", "output": "YES\r\n"}, {"input": "6\r\n16 13 3 7 4 15\r\n", "output": "YES\r\n"}, {"input": "4\r\n11 7 12 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 1 3 6 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 4 8 11 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 10 3 4\r\n", "output": "YES\r\n"}, {"input": "6\r\n8 15 12 14 15 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 4 4 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 3 1 6 4\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 12 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 4 13\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1 1 1 1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n19 6 5 13 6 13\r\n", "output": "YES\r\n"}, {"input": "8\r\n2 2 2 5 1 2 3 3\r\n", "output": "YES\r\n"}]
false
stdio
null
true
671/A
671
A
PyPy 3-64
TESTS
51
966
50,278,400
144871073
import sys input = sys.stdin.buffer.readline def dist(r1, r2, s1, s2): distance = (r1-s1)**2+(r2-s2)**2 return distance**0.5 def process(ax, ay, bx, by, tx, ty, A): n = len(A) answer = 0 maybe1 = [] maybe2 = [] for i in range(n): x, y = A[i] answer+=2*dist(tx, ty, x, y) d1 = dist(ax, ay, x, y)-dist(tx, ty, x, y) d2 = dist(bx, by, x, y)-dist(tx, ty, x, y) maybe1.append([d1, 0, i]) maybe2.append([d2, 1, i]) maybe1.sort() maybe2.sort() answer1 = answer+maybe1[0][0] answer2 = answer+maybe2[0][0] L1 = [x for x in maybe2 if x[2] != maybe1[0][2]] L2 = [x for x in maybe1 if x[2] != maybe2[0][2]] if len(L1) > 0: answer3 = answer+maybe1[0][0]+L1[0][0] else: answer3 = answer if len(L2) > 0: answer4 = answer+maybe2[0][0]+L2[0][0] else: answer4 = answer return min(answer1, answer2, answer3, answer4) ax, ay, bx, by, tx, ty = [int(x) for x in input().split()] n = int(input()) A = [] for i in range(n): x, y = [int(x) for x in input().split()] A.append([x, y]) print(process(ax, ay, bx, by, tx, ty, A))
148
608
36,352,000
225170582
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb alph = 'abcdefghijklmnopqrstuvwxyz' #pow(x,mod-2,mod) def cal(a,b): return (abs(a[0]-b[0])**2+abs(b[1]-a[1])**2)**0.5 Ax,Ay,Bx,By,Cx,Cy = map(int,input().split()) N = int(input()) P = [list(map(int,input().split())) for _ in range(N)] ans = float('inf') A,B,C = [cal(i,[Ax,Ay]) for i in P],[cal(i,[Bx,By]) for i in P],[cal(i,[Cx,Cy]) for i in P] su = sum(C)*2 for i in range(N): ans = min(ans,su-C[i]+A[i],su-C[i]+B[i]) K = [] for i in range(N): K.append([B[i]-C[i],i]) K.sort() # print(K) if N>=2: Min1,Min2 = K[0][1],K[1][1] for a in range(N): b = Min1 if a==Min1:b = Min2 num = su-C[a]-C[b]+A[a]+B[b] # print(a,b,num) ans = min(ans,num) print(ans)
Codeforces Round 352 (Div. 1)
CF
2,016
2
256
Recycling Bottles
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can carry only one bottle at once each. For both Adil and Bera the process looks as follows: 1. Choose to stop or to continue to collect bottles. 2. If the choice was to continue then choose some bottle and walk towards it. 3. Pick this bottle and walk to the recycling bin. 4. Go to step 1. Adil and Bera may move independently. They are allowed to pick bottles simultaneously, all bottles may be picked by any of the two, it's allowed that one of them stays still while the other one continues to pick bottles. They want to organize the process such that the total distance they walk (the sum of distance walked by Adil and distance walked by Bera) is minimum possible. Of course, at the end all bottles should lie in the recycling bin.
First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively. The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground. Then follow n lines, each of them contains two integers xi and yi (0 ≤ xi, yi ≤ 109) — position of the i-th bottle. It's guaranteed that positions of Adil, Bera, recycling bin and all bottles are distinct.
Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if $$\frac{|a-b|}{\max(1,b)} \leq 10^{-6}$$.
null
Consider the first sample. Adil will use the following path: $$(3,1)\rightarrow(2,1)\rightarrow(0,0)\rightarrow(1,1)\rightarrow(0,0)$$. Bera will use the following path: $$(1,2)\rightarrow(2,3)\rightarrow(0,0)$$. Adil's path will be $$1 + \sqrt{5} + \sqrt{2} + \sqrt{2}$$ units long, while Bera's path will be $$\sqrt{2} + \sqrt{13}$$ units long.
[{"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "output": "11.084259940083"}, {"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "output": "33.121375178000"}]
1,800
["dp", "geometry", "greedy", "implementation"]
148
[{"input": "3 1 1 2 0 0\r\n3\r\n1 1\r\n2 1\r\n2 3\r\n", "output": "11.084259940083\r\n"}, {"input": "5 0 4 2 2 0\r\n5\r\n5 2\r\n3 0\r\n5 5\r\n3 5\r\n3 3\r\n", "output": "33.121375178000\r\n"}, {"input": "107 50 116 37 104 118\r\n12\r\n16 78\r\n95 113\r\n112 84\r\n5 88\r\n54 85\r\n112 80\r\n19 98\r\n25 14\r\n48 76\r\n95 70\r\n77 94\r\n38 32\r\n", "output": "1576.895607473206\r\n"}, {"input": "446799 395535 281981 494983 755701 57488\r\n20\r\n770380 454998\r\n147325 211816\r\n818964 223521\r\n408463 253399\r\n49120 253709\r\n478114 283776\r\n909705 631953\r\n303154 889956\r\n126532 258846\r\n597028 708070\r\n147061 192478\r\n39515 879057\r\n911737 878857\r\n26966 701951\r\n616099 715301\r\n998385 735514\r\n277633 346417\r\n642301 188888\r\n617247 256225\r\n668067 352814\r\n", "output": "22423982.398765542000\r\n"}, {"input": "0 0 214409724 980408402 975413181 157577991\r\n4\r\n390610378 473484159\r\n920351980 785918656\r\n706277914 753279807\r\n159291646 213569247\r\n", "output": "4854671149.842136400000\r\n"}, {"input": "214409724 980408402 0 0 975413181 157577991\r\n4\r\n390610378 473484159\r\n920351980 785918656\r\n706277914 753279807\r\n159291646 213569247\r\n", "output": "4854671149.842136400000\r\n"}, {"input": "383677880 965754167 658001115 941943959 0 0\r\n10\r\n9412 5230\r\n4896 7518\r\n3635 6202\r\n2365 1525\r\n241 1398\r\n7004 5166\r\n1294 9162\r\n3898 6706\r\n6135 8199\r\n4195 4410\r\n", "output": "1039303750.884648200000\r\n"}, {"input": "825153337 326797826 774256604 103765336 0 0\r\n21\r\n6537 9734\r\n3998 8433\r\n560 7638\r\n1937 2557\r\n3487 244\r\n8299 4519\r\n73 9952\r\n2858 3719\r\n9267 5675\r\n9584 7636\r\n9234 1049\r\n7415 6018\r\n7653 9345\r\n7752 9628\r\n7476 8917\r\n7207 2352\r\n2602 4612\r\n1971 3307\r\n5530 3694\r\n2393 8573\r\n7506 9810\r\n", "output": "781520533.726828810000\r\n"}, {"input": "214409724 980408402 975413181 157577991 0 0\r\n4\r\n3721 6099\r\n5225 4247\r\n940 340\r\n8612 7341\r\n", "output": "988090959.937532070000\r\n"}, {"input": "235810013 344493922 0 0 975204641 211157253\r\n18\r\n977686151 621301932\r\n408277582 166435161\r\n595105725 194278844\r\n967498841 705149530\r\n551735395 659209387\r\n492239556 317614998\r\n741520864 843275770\r\n585383143 903832112\r\n272581169 285871890\r\n339100580 134101148\r\n920610054 824829107\r\n657996186 852771589\r\n948065129 573712142\r\n615254670 698346010\r\n365251531 883011553\r\n304877602 625498272\r\n418150850 280945187\r\n731399551 643859052\r\n", "output": "20756961047.556908000000\r\n"}, {"input": "0 0 1 1 2 2\r\n1\r\n1 3\r\n", "output": "3.414213562373\r\n"}, {"input": "10000 1000 151 121 10 10\r\n2\r\n1 1\r\n2 2\r\n", "output": "227.449066182313\r\n"}, {"input": "5 5 10 10 15 15\r\n2\r\n1 1\r\n11 11\r\n", "output": "32.526911934581\r\n"}, {"input": "1000000 1000000 1 1 0 0\r\n1\r\n2 2\r\n", "output": "4.242640687119\r\n"}, {"input": "100 0 0 1 0 0\r\n2\r\n1 1\r\n1 2\r\n", "output": "6.478708664619\r\n"}, {"input": "0 0 1000000000 1000000000 1 1\r\n2\r\n0 1\r\n1 0\r\n", "output": "4.000000000000\r\n"}, {"input": "1000 1000 0 0 1 1\r\n1\r\n2 2\r\n", "output": "4.242640687119\r\n"}, {"input": "1 0 1000000 0 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "7.892922226992\r\n"}, {"input": "3 0 100 100 0 0\r\n2\r\n1 0\r\n2 0\r\n", "output": "5.000000000000\r\n"}, {"input": "0 100 0 101 0 0\r\n1\r\n0 99\r\n", "output": "100.000000000000\r\n"}, {"input": "1000 1000 3 3 0 0\r\n2\r\n1 0\r\n0 1\r\n", "output": "6.605551275464\r\n"}, {"input": "0 5 0 6 0 7\r\n1\r\n0 100\r\n", "output": "187.000000000000\r\n"}, {"input": "1 1 1000000 1000000 0 0\r\n2\r\n1 2\r\n2 1\r\n", "output": "7.708203932499\r\n"}, {"input": "1 0 10000000 1000000 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "7.892922226992\r\n"}, {"input": "2 2 10 2 6 5\r\n2\r\n6 2\r\n5 5\r\n", "output": "9.000000000000\r\n"}, {"input": "100000001 100000001 100000000 100000000 1 1\r\n1\r\n1 0\r\n", "output": "141421356.530202720000\r\n"}, {"input": "1000 1000 1001 1001 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "1417.041989497841\r\n"}, {"input": "1000000000 1000000000 999999999 999999999 1 1\r\n4\r\n1 2\r\n1 3\r\n2 2\r\n2 3\r\n", "output": "1414213568.487842800000\r\n"}, {"input": "0 100 1 1 1 0\r\n2\r\n2 1\r\n0 1\r\n", "output": "5.242640687119\r\n"}, {"input": "0 100 0 1 0 0\r\n5\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n0 6\r\n", "output": "39.000000000000\r\n"}, {"input": "100 0 0 100 0 0\r\n2\r\n0 1\r\n1 0\r\n", "output": "102.000000000000\r\n"}, {"input": "0 0 1000000 1000000 0 1\r\n2\r\n1 1\r\n2 2\r\n", "output": "6.886349517373\r\n"}, {"input": "0 0 1000 1000 1 0\r\n2\r\n1 1\r\n1 2\r\n", "output": "6.236067977500\r\n"}, {"input": "1 0 100000 100000 0 0\r\n1\r\n2 0\r\n", "output": "3.000000000000\r\n"}, {"input": "5 5 5 4 4 5\r\n2\r\n3 4\r\n3 5\r\n", "output": "5.414213562373\r\n"}, {"input": "10000 10000 9000 9000 0 0\r\n3\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "12736.407342732093\r\n"}, {"input": "1 1 1000 1000 0 0\r\n3\r\n2 2\r\n3 3\r\n4 4\r\n", "output": "24.041630560343\r\n"}, {"input": "7 0 8 0 0 0\r\n2\r\n1 0\r\n1 1\r\n", "output": "9.496976092671\r\n"}, {"input": "1 3 3 3 2 1\r\n2\r\n2 3\r\n3 1\r\n", "output": "5.000000000000\r\n"}, {"input": "1 2 3 4 5 6\r\n1\r\n1 1\r\n", "output": "7.403124237433\r\n"}, {"input": "1000000000 1000000000 0 0 1 1\r\n5\r\n2 2\r\n2 3\r\n2 4\r\n2 5\r\n2 6\r\n", "output": "33.294904485247\r\n"}, {"input": "2 1 1 2 0 0\r\n1\r\n1 1\r\n", "output": "2.414213562373\r\n"}, {"input": "1 0 100000 0 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "7.892922226992\r\n"}, {"input": "0 100 1 100 1 0\r\n2\r\n2 1\r\n0 1\r\n", "output": "103.242640687119\r\n"}, {"input": "0 0 2 0 1 5\r\n2\r\n1 0\r\n1 20\r\n", "output": "36.000000000000\r\n"}, {"input": "1000 1000 999 999 0 0\r\n2\r\n1 0\r\n0 1\r\n", "output": "1415.092419071783\r\n"}, {"input": "5 0 1000 1000 2 0\r\n2\r\n4 0\r\n6 7\r\n", "output": "19.124515496597\r\n"}, {"input": "10000 0 1000000 0 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "10003.657054289499\r\n"}, {"input": "0 100 0 101 0 0\r\n2\r\n0 1\r\n0 2\r\n", "output": "102.000000000000\r\n"}, {"input": "0 0 10000 10000 1 0\r\n2\r\n2 0\r\n3 0\r\n", "output": "7.000000000000\r\n"}, {"input": "3 1 1 2 0 0\r\n1\r\n1 1\r\n", "output": "2.414213562373\r\n"}, {"input": "1000 0 0 1000 0 0\r\n2\r\n1 0\r\n0 1\r\n", "output": "1002.000000000000\r\n"}, {"input": "1 1 1000000 1000000 0 0\r\n2\r\n2 1\r\n1 2\r\n", "output": "7.708203932499\r\n"}, {"input": "1000 1000 2000 2000 1 1\r\n3\r\n2 2\r\n1 2\r\n3 3\r\n", "output": "1417.627775935468\r\n"}, {"input": "0 0 1000000000 1000000000 1 1\r\n4\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n", "output": "29.698484809835\r\n"}, {"input": "10000000 1 2 1 1 1\r\n3\r\n1 3\r\n1 4\r\n1 5\r\n", "output": "18.123105625618\r\n"}, {"input": "3 7 5 7 4 4\r\n2\r\n4 6\r\n4 0\r\n", "output": "11.414213562373\r\n"}, {"input": "0 0 3 0 1 5\r\n2\r\n1 0\r\n1 20\r\n", "output": "36.000000000000\r\n"}, {"input": "0 0 0 1 1000 3\r\n2\r\n1000 2\r\n1000 1\r\n", "output": "1004.000000000000\r\n"}, {"input": "1000000000 0 0 1 0 0\r\n2\r\n0 2\r\n0 3\r\n", "output": "9.000000000000\r\n"}, {"input": "0 1000000000 1000000000 0 0 0\r\n1\r\n1 1\r\n", "output": "1000000000.414213500000\r\n"}, {"input": "1000 1000 1000 1001 0 0\r\n2\r\n0 1\r\n1 1\r\n", "output": "1416.213562373095\r\n"}, {"input": "1002 0 1001 0 0 0\r\n1\r\n1000 0\r\n", "output": "1001.000000000000\r\n"}, {"input": "1002 0 1001 0 0 0\r\n2\r\n2 0\r\n1 0\r\n", "output": "1003.000000000000\r\n"}, {"input": "3 0 0 100 0 0\r\n2\r\n1 0\r\n2 0\r\n", "output": "5.000000000000\r\n"}, {"input": "10 10 0 0 0 1\r\n2\r\n1 0\r\n1 1\r\n", "output": "4.414213562373\r\n"}, {"input": "1000 1000 1001 1001 0 0\r\n2\r\n0 1\r\n1 1\r\n", "output": "1416.213562373095\r\n"}, {"input": "0 100 0 200 0 0\r\n2\r\n0 1\r\n0 2\r\n", "output": "102.000000000000\r\n"}, {"input": "100 100 0 0 1 1\r\n1\r\n2 2\r\n", "output": "4.242640687119\r\n"}, {"input": "123123 154345 123123 123123 2 2\r\n3\r\n3 3\r\n4 4\r\n5 5\r\n", "output": "174127.873294312070\r\n"}, {"input": "0 1 0 2 0 0\r\n1\r\n1 0\r\n", "output": "2.414213562373\r\n"}, {"input": "1 2 3 4 1000 1000\r\n1\r\n156 608\r\n", "output": "1553.668251715911\r\n"}, {"input": "0 0 10 0 5 0\r\n3\r\n4 1\r\n5 1\r\n6 1\r\n", "output": "10.365746312737\r\n"}, {"input": "0 0 0 1 1000000000 999999999\r\n1\r\n1000000000 1000000000\r\n", "output": "1414213562.665988200000\r\n"}, {"input": "1231231 2342342 123124 123151 12315 12312\r\n1\r\n354345 234234\r\n", "output": "664238.053973730540\r\n"}, {"input": "0 0 1000000 0 1 1\r\n2\r\n0 1\r\n3 0\r\n", "output": "6.472135955000\r\n"}, {"input": "1000 1000 2000 2000 1 1\r\n1\r\n2 2\r\n", "output": "1412.799348810722\r\n"}, {"input": "10 20 10 0 10 10\r\n2\r\n10 11\r\n10 9\r\n", "output": "12.000000000000\r\n"}, {"input": "1000000000 1 1 1000000000 0 0\r\n1\r\n2 2\r\n", "output": "1000000000.828427200000\r\n"}, {"input": "0 0 1000 1000 1 0\r\n2\r\n2 0\r\n3 0\r\n", "output": "7.000000000000\r\n"}, {"input": "1000 0 100000000 100000000 0 0\r\n2\r\n999 0\r\n1100 0\r\n", "output": "3198.000000000000\r\n"}, {"input": "2 2 1000000000 1000000000 0 0\r\n3\r\n1 1\r\n5 5\r\n100 100\r\n", "output": "296.984848098350\r\n"}, {"input": "2 0 4 0 0 0\r\n1\r\n3 0\r\n", "output": "4.000000000000\r\n"}, {"input": "2 2 1000 1000 0 0\r\n2\r\n1 1\r\n1 2\r\n", "output": "6.064495102246\r\n"}, {"input": "0 0 1000000000 1000000000 0 1\r\n3\r\n1 0\r\n2 0\r\n3 0\r\n", "output": "13.210904837709\r\n"}, {"input": "1 10000 10000 1 0 0\r\n2\r\n1 100\r\n100 1\r\n", "output": "10200.014999625020\r\n"}, {"input": "5 0 6 0 0 0\r\n2\r\n2 0\r\n0 2\r\n", "output": "9.000000000000\r\n"}, {"input": "2 4 1000000000 1000000000 0 0\r\n4\r\n2 3\r\n2 1\r\n3 2\r\n1 2\r\n", "output": "20.760925736391\r\n"}, {"input": "0 100 1 1 0 0\r\n2\r\n0 1\r\n3 1\r\n", "output": "7.162277660168\r\n"}, {"input": "0 0 10 0 8 2\r\n1\r\n6 0\r\n", "output": "6.828427124746\r\n"}, {"input": "0 9 0 8 0 1\r\n1\r\n0 0\r\n", "output": "9.000000000000\r\n"}, {"input": "100 0 0 100 0 0\r\n2\r\n40 0\r\n0 40\r\n", "output": "180.000000000000\r\n"}, {"input": "0 0 0 1 1000 3\r\n2\r\n1000 1\r\n1000 2\r\n", "output": "1004.000000000000\r\n"}, {"input": "1 1 123123 123123 2 2\r\n3\r\n3 3\r\n4 4\r\n5 5\r\n", "output": "18.384776310850\r\n"}, {"input": "999999999 999999999 1000000000 1000000000 1 1\r\n1\r\n1 0\r\n", "output": "1414213561.251774800000\r\n"}, {"input": "3 2 1 1 0 0\r\n1\r\n2 2\r\n", "output": "3.828427124746\r\n"}, {"input": "0 0 1 1 100 100\r\n2\r\n101 101\r\n102 102\r\n", "output": "148.492424049175\r\n"}, {"input": "1 15 4 10 1 1\r\n2\r\n1 10\r\n4 5\r\n", "output": "22.000000000000\r\n"}, {"input": "100 0 0 100 0 0\r\n2\r\n60 0\r\n0 40\r\n", "output": "180.000000000000\r\n"}, {"input": "0 0 0 1000 1 0\r\n4\r\n0 1\r\n0 2\r\n0 3\r\n0 4\r\n", "output": "21.457116088945\r\n"}, {"input": "0 0 100 0 3 0\r\n1\r\n2 0\r\n", "output": "3.000000000000\r\n"}, {"input": "0 0 100 0 98 2\r\n1\r\n98 0\r\n", "output": "4.000000000000\r\n"}, {"input": "1 1 2 2 3 3\r\n1\r\n0 0\r\n", "output": "5.656854249492\r\n"}, {"input": "2 2 1 1 0 0\r\n1\r\n1 2\r\n", "output": "3.236067977500\r\n"}, {"input": "10000000 1 2 1 1 1\r\n3\r\n1 40\r\n1 20\r\n1 5\r\n", "output": "124.012818406262\r\n"}, {"input": "1000 1000 1001 1000 0 0\r\n3\r\n1 1\r\n1 2\r\n1 3\r\n", "output": "1421.848684511914\r\n"}, {"input": "10000 10000 9999 9999 0 0\r\n3\r\n0 1\r\n0 2\r\n0 3\r\n", "output": "14147.600248963827\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(output_path) as f: correct = f.read().strip() with open(submission_path) as f: submission = f.read().strip() try: correct_val = float(correct) submission_val = float(submission) except: print(0) return delta = abs(correct_val - submission_val) denominator = max(1.0, abs(correct_val)) if delta <= 1e-6 * denominator: print(1) else: print(0) if __name__ == "__main__": main()
true
997/A
997
A
Python 3
TESTS
10
140
1,024,000
112276250
n,x,y=map(int,input().split()) s=input() c=0 ans1,ans2=0,0 for i in range(n-1): if s[i]=='0' and s[i+1]=='1': c+=1 ans1=x*c+y ans2=c*y if s[n-1]=='0': ans2+=y print(min(ans1,ans2))
115
62
2,457,600
205180262
''' https://codeforces.com/problemset/problem/997/A 输入 n(1≤n≤3e5) x(0≤x≤1e9) y(0≤y≤1e9) 和长为 n 的 01 字符串 s。 你可以执行任意次操作,每次选择其中一种操作执行。 1. 花费 x,reverse s 的一个子串,例如 1110 -> 0111。 2. 花费 y,flip s 的一个子串,例如 1110 -> 0001。 目标:使 s 中只有 1。 输出最少花费。 输入 5 1 10 01000 输出 11 输入 5 10 1 01000 输出 2 输入 7 2 3 1111111 输出 0 ''' def _n(): return int(input()) def _nA(): return list(map(int, input().split())) def _nS(): return input().split() def solve(): n, x, y = _nA() c, t = 0, 0 for i in input(): if i == '0': t += 1 elif t: c += 1 t = 0 c += (t > 0) if c == 0: return 0 if x < y: return (c-1)*x+y else: return c*y print(solve())
Codeforces Round 493 (Div. 1)
CF
2,018
1
256
Convert to Ones
You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones. Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$. You can apply the following operations any number of times: - Choose some substring of string $$$a$$$ (for example, you can choose entire string) and reverse it, paying $$$x$$$ coins for it (for example, «0101101» $$$\to$$$ «0111001»); - Choose some substring of string $$$a$$$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $$$y$$$ coins for it (for example, «0101101» $$$\to$$$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones?
The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $$$a$$$ of length $$$n$$$, consisting of zeros and ones.
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations.
null
In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «10000» $$$\to$$$ «11111». The total cost of operations is $$$1 + 10 = 11$$$. In the second sample, at first you need to invert substring $$$[1 \dots 1]$$$, and then you need to invert substring $$$[3 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «11000» $$$\to$$$ «11111». The overall cost is $$$1 + 1 = 2$$$. In the third example, string already consists only of ones, so the answer is $$$0$$$.
[{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}]
1,500
["brute force", "greedy", "implementation", "math"]
115
[{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 261764879\r\n0\r\n", "output": "261764879\r\n"}, {"input": "1 491511050 399084767\r\n1\r\n", "output": "0\r\n"}, {"input": "2 163093925 214567542\r\n00\r\n", "output": "214567542\r\n"}, {"input": "2 340351106 646854722\r\n10\r\n", "output": "646854722\r\n"}, {"input": "2 222640995 489207317\r\n01\r\n", "output": "489207317\r\n"}, {"input": "2 399898176 552898277\r\n11\r\n", "output": "0\r\n"}, {"input": "2 690218164 577155357\r\n00\r\n", "output": "577155357\r\n"}, {"input": "2 827538051 754412538\r\n10\r\n", "output": "754412538\r\n"}, {"input": "2 636702427 259825230\r\n01\r\n", "output": "259825230\r\n"}, {"input": "2 108926899 102177825\r\n11\r\n", "output": "0\r\n"}, {"input": "3 368381052 440077270\r\n000\r\n", "output": "440077270\r\n"}, {"input": "3 505700940 617334451\r\n100\r\n", "output": "617334451\r\n"}, {"input": "3 499624340 643020827\r\n010\r\n", "output": "1142645167\r\n"}, {"input": "3 75308005 971848814\r\n110\r\n", "output": "971848814\r\n"}, {"input": "3 212627893 854138703\r\n001\r\n", "output": "854138703\r\n"}, {"input": "3 31395883 981351561\r\n101\r\n", "output": "981351561\r\n"}, {"input": "3 118671447 913685773\r\n011\r\n", "output": "913685773\r\n"}, {"input": "3 255991335 385910245\r\n111\r\n", "output": "0\r\n"}, {"input": "3 688278514 268200134\r\n000\r\n", "output": "268200134\r\n"}, {"input": "3 825598402 445457315\r\n100\r\n", "output": "445457315\r\n"}, {"input": "3 300751942 45676507\r\n010\r\n", "output": "91353014\r\n"}, {"input": "3 517900980 438071829\r\n110\r\n", "output": "438071829\r\n"}, {"input": "3 400190869 280424424\r\n001\r\n", "output": "280424424\r\n"}, {"input": "3 577448050 344115384\r\n101\r\n", "output": "344115384\r\n"}, {"input": "3 481435271 459737939\r\n011\r\n", "output": "459737939\r\n"}, {"input": "3 931962412 913722450\r\n111\r\n", "output": "0\r\n"}, {"input": "4 522194562 717060616\r\n0000\r\n", "output": "717060616\r\n"}, {"input": "4 659514449 894317797\r\n1000\r\n", "output": "894317797\r\n"}, {"input": "4 71574977 796834337\r\n0100\r\n", "output": "868409314\r\n"}, {"input": "4 248832158 934154224\r\n1100\r\n", "output": "934154224\r\n"}, {"input": "4 71474110 131122047\r\n0010\r\n", "output": "202596157\r\n"}, {"input": "4 308379228 503761290\r\n1010\r\n", "output": "812140518\r\n"}, {"input": "4 272484957 485636409\r\n0110\r\n", "output": "758121366\r\n"}, {"input": "4 662893590 704772137\r\n1110\r\n", "output": "704772137\r\n"}, {"input": "4 545183479 547124732\r\n0001\r\n", "output": "547124732\r\n"}, {"input": "4 684444619 722440661\r\n1001\r\n", "output": "722440661\r\n"}, {"input": "4 477963686 636258459\r\n0101\r\n", "output": "1114222145\r\n"}, {"input": "4 360253575 773578347\r\n1101\r\n", "output": "773578347\r\n"}, {"input": "4 832478048 910898234\r\n0011\r\n", "output": "910898234\r\n"}, {"input": "4 343185412 714767937\r\n1011\r\n", "output": "714767937\r\n"}, {"input": "4 480505300 892025118\r\n0111\r\n", "output": "892025118\r\n"}, {"input": "4 322857895 774315007\r\n1111\r\n", "output": "0\r\n"}, {"input": "4 386548854 246539479\r\n0000\r\n", "output": "246539479\r\n"}, {"input": "4 523868742 128829368\r\n1000\r\n", "output": "128829368\r\n"}, {"input": "4 956155921 11119257\r\n0100\r\n", "output": "22238514\r\n"}, {"input": "4 188376438 93475808\r\n1100\r\n", "output": "93475808\r\n"}, {"input": "4 754947032 158668188\r\n0010\r\n", "output": "317336376\r\n"}, {"input": "4 927391856 637236921\r\n1010\r\n", "output": "1274473842\r\n"}, {"input": "4 359679035 109461393\r\n0110\r\n", "output": "218922786\r\n"}, {"input": "4 991751283 202031630\r\n1110\r\n", "output": "202031630\r\n"}, {"input": "4 339351517 169008463\r\n0001\r\n", "output": "169008463\r\n"}, {"input": "4 771638697 346265644\r\n1001\r\n", "output": "346265644\r\n"}, {"input": "4 908958584 523522825\r\n0101\r\n", "output": "1047045650\r\n"}, {"input": "4 677682252 405812714\r\n1101\r\n", "output": "405812714\r\n"}, {"input": "4 815002139 288102603\r\n0011\r\n", "output": "288102603\r\n"}, {"input": "4 952322026 760327076\r\n1011\r\n", "output": "760327076\r\n"}, {"input": "4 663334158 312481698\r\n0111\r\n", "output": "312481698\r\n"}, {"input": "4 840591339 154834293\r\n1111\r\n", "output": "0\r\n"}, {"input": "14 3 11\r\n10110100011001\r\n", "output": "20\r\n"}, {"input": "19 1 1\r\n1010101010101010101\r\n", "output": "9\r\n"}, {"input": "1 10 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 100 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 1000 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 10 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "7 3 2\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 10\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 3 2\r\n1\r\n", "output": "0\r\n"}, {"input": "2 10 1\r\n11\r\n", "output": "0\r\n"}, {"input": "4 148823922 302792601\r\n1010\r\n", "output": "451616523\r\n"}, {"input": "1 2 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n00011\r\n", "output": "3\r\n"}, {"input": "1 5 0\r\n1\r\n", "output": "0\r\n"}, {"input": "7 2 3\r\n1001001\r\n", "output": "5\r\n"}, {"input": "10 1 1000000000\r\n1111010111\r\n", "output": "1000000001\r\n"}, {"input": "25 999999998 999999999\r\n1011001110101010100111001\r\n", "output": "7999999985\r\n"}, {"input": "2 0 1\r\n00\r\n", "output": "1\r\n"}, {"input": "2 1 100\r\n10\r\n", "output": "100\r\n"}, {"input": "7 20 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "0\r\n"}, {"input": "3 1 10\r\n010\r\n", "output": "11\r\n"}, {"input": "2 1 0\r\n11\r\n", "output": "0\r\n"}, {"input": "7 100 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 1000\r\n10101\r\n", "output": "1001\r\n"}, {"input": "5 2 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "1 1000 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 799543940 488239239\r\n1\r\n", "output": "0\r\n"}, {"input": "6 1 1000\r\n010101\r\n", "output": "1002\r\n"}, {"input": "5 11 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n10101\r\n", "output": "5\r\n"}, {"input": "3 10 1\r\n111\r\n", "output": "0\r\n"}, {"input": "7 9 10\r\n1001011\r\n", "output": "19\r\n"}, {"input": "5 5 6\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 1000000000 0\r\n1\r\n", "output": "0\r\n"}, {"input": "4 0 1\r\n0101\r\n", "output": "1\r\n"}, {"input": "8 2 3\r\n10101010\r\n", "output": "9\r\n"}, {"input": "6 3 100\r\n010101\r\n", "output": "106\r\n"}, {"input": "3 3 2\r\n111\r\n", "output": "0\r\n"}, {"input": "1 20 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n01\r\n", "output": "2\r\n"}]
false
stdio
null
true
671/A
671
A
Python 3
TESTS
48
763
5,529,600
26649746
from math import sqrt ax, ay, bx, by, tx, ty = map(int, input().split()) n = int(input()) d = 0 mina = (2*10**9,0,0) mina2 = (2*10**9,0,0) minb = (2*10**9,0,0) minb2 = (2*10**9,0,0) for _ in range(n): x, y = map(int, input().split()) dt = sqrt((x-tx)**2+(y-ty)**2) d += 2*dt da = sqrt((ax-x)**2+(ay-y)**2) dat = (da-dt,x,y) if dat[0] < mina[0]: mina, mina2 = dat, mina else: mina2 = dat db = sqrt((bx-x)**2+(by-y)**2) dbt = (db-dt,x,y) if dbt[0] < minb[0]: minb, minb2 = dbt, minb else: minb2 = dbt if mina[0] < 0 and minb[0] < 0: if mina[1] != minb[1] or mina[2] != minb[2]: d += mina[0] + minb[0] else: d += min(mina[0]+minb2[0],mina2[0]+minb[0]) else: d += min(mina[0],minb[0]) print(d)
148
685
12,902,400
179410672
ax,ay,bx,by,tx,ty=map(int,input().split()) n=int(input()) a,b=[],[] res=0 for i in range(n): x, y=map(int, input().split()) lt=((tx-x)*(tx-x)+(ty-y)*(ty-y))**0.5 la=((ax-x)*(ax-x)+(ay-y)*(ay-y))**0.5 lb=((bx-x)*(bx-x)+(by-y)*(by-y))**0.5 a+=[(la-lt,i)] b+=[(lb-lt,i)] res+=lt a.sort();b.sort() res*=2 if a[0][1]==b[0][1] and n>1: res+=min(a[0][0],b[0][0],a[0][0]+b[1][0],a[1][0]+b[0][0]) else: if a[0][1]==b[0][1]: res+=min(a[0][0],b[0][0]) else: res+=min(a[0][0],b[0][0],a[0][0]+b[0][0]) print(res)
Codeforces Round 352 (Div. 1)
CF
2,016
2
256
Recycling Bottles
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can carry only one bottle at once each. For both Adil and Bera the process looks as follows: 1. Choose to stop or to continue to collect bottles. 2. If the choice was to continue then choose some bottle and walk towards it. 3. Pick this bottle and walk to the recycling bin. 4. Go to step 1. Adil and Bera may move independently. They are allowed to pick bottles simultaneously, all bottles may be picked by any of the two, it's allowed that one of them stays still while the other one continues to pick bottles. They want to organize the process such that the total distance they walk (the sum of distance walked by Adil and distance walked by Bera) is minimum possible. Of course, at the end all bottles should lie in the recycling bin.
First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively. The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground. Then follow n lines, each of them contains two integers xi and yi (0 ≤ xi, yi ≤ 109) — position of the i-th bottle. It's guaranteed that positions of Adil, Bera, recycling bin and all bottles are distinct.
Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if $$\frac{|a-b|}{\max(1,b)} \leq 10^{-6}$$.
null
Consider the first sample. Adil will use the following path: $$(3,1)\rightarrow(2,1)\rightarrow(0,0)\rightarrow(1,1)\rightarrow(0,0)$$. Bera will use the following path: $$(1,2)\rightarrow(2,3)\rightarrow(0,0)$$. Adil's path will be $$1 + \sqrt{5} + \sqrt{2} + \sqrt{2}$$ units long, while Bera's path will be $$\sqrt{2} + \sqrt{13}$$ units long.
[{"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "output": "11.084259940083"}, {"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "output": "33.121375178000"}]
1,800
["dp", "geometry", "greedy", "implementation"]
148
[{"input": "3 1 1 2 0 0\r\n3\r\n1 1\r\n2 1\r\n2 3\r\n", "output": "11.084259940083\r\n"}, {"input": "5 0 4 2 2 0\r\n5\r\n5 2\r\n3 0\r\n5 5\r\n3 5\r\n3 3\r\n", "output": "33.121375178000\r\n"}, {"input": "107 50 116 37 104 118\r\n12\r\n16 78\r\n95 113\r\n112 84\r\n5 88\r\n54 85\r\n112 80\r\n19 98\r\n25 14\r\n48 76\r\n95 70\r\n77 94\r\n38 32\r\n", "output": "1576.895607473206\r\n"}, {"input": "446799 395535 281981 494983 755701 57488\r\n20\r\n770380 454998\r\n147325 211816\r\n818964 223521\r\n408463 253399\r\n49120 253709\r\n478114 283776\r\n909705 631953\r\n303154 889956\r\n126532 258846\r\n597028 708070\r\n147061 192478\r\n39515 879057\r\n911737 878857\r\n26966 701951\r\n616099 715301\r\n998385 735514\r\n277633 346417\r\n642301 188888\r\n617247 256225\r\n668067 352814\r\n", "output": "22423982.398765542000\r\n"}, {"input": "0 0 214409724 980408402 975413181 157577991\r\n4\r\n390610378 473484159\r\n920351980 785918656\r\n706277914 753279807\r\n159291646 213569247\r\n", "output": "4854671149.842136400000\r\n"}, {"input": "214409724 980408402 0 0 975413181 157577991\r\n4\r\n390610378 473484159\r\n920351980 785918656\r\n706277914 753279807\r\n159291646 213569247\r\n", "output": "4854671149.842136400000\r\n"}, {"input": "383677880 965754167 658001115 941943959 0 0\r\n10\r\n9412 5230\r\n4896 7518\r\n3635 6202\r\n2365 1525\r\n241 1398\r\n7004 5166\r\n1294 9162\r\n3898 6706\r\n6135 8199\r\n4195 4410\r\n", "output": "1039303750.884648200000\r\n"}, {"input": "825153337 326797826 774256604 103765336 0 0\r\n21\r\n6537 9734\r\n3998 8433\r\n560 7638\r\n1937 2557\r\n3487 244\r\n8299 4519\r\n73 9952\r\n2858 3719\r\n9267 5675\r\n9584 7636\r\n9234 1049\r\n7415 6018\r\n7653 9345\r\n7752 9628\r\n7476 8917\r\n7207 2352\r\n2602 4612\r\n1971 3307\r\n5530 3694\r\n2393 8573\r\n7506 9810\r\n", "output": "781520533.726828810000\r\n"}, {"input": "214409724 980408402 975413181 157577991 0 0\r\n4\r\n3721 6099\r\n5225 4247\r\n940 340\r\n8612 7341\r\n", "output": "988090959.937532070000\r\n"}, {"input": "235810013 344493922 0 0 975204641 211157253\r\n18\r\n977686151 621301932\r\n408277582 166435161\r\n595105725 194278844\r\n967498841 705149530\r\n551735395 659209387\r\n492239556 317614998\r\n741520864 843275770\r\n585383143 903832112\r\n272581169 285871890\r\n339100580 134101148\r\n920610054 824829107\r\n657996186 852771589\r\n948065129 573712142\r\n615254670 698346010\r\n365251531 883011553\r\n304877602 625498272\r\n418150850 280945187\r\n731399551 643859052\r\n", "output": "20756961047.556908000000\r\n"}, {"input": "0 0 1 1 2 2\r\n1\r\n1 3\r\n", "output": "3.414213562373\r\n"}, {"input": "10000 1000 151 121 10 10\r\n2\r\n1 1\r\n2 2\r\n", "output": "227.449066182313\r\n"}, {"input": "5 5 10 10 15 15\r\n2\r\n1 1\r\n11 11\r\n", "output": "32.526911934581\r\n"}, {"input": "1000000 1000000 1 1 0 0\r\n1\r\n2 2\r\n", "output": "4.242640687119\r\n"}, {"input": "100 0 0 1 0 0\r\n2\r\n1 1\r\n1 2\r\n", "output": "6.478708664619\r\n"}, {"input": "0 0 1000000000 1000000000 1 1\r\n2\r\n0 1\r\n1 0\r\n", "output": "4.000000000000\r\n"}, {"input": "1000 1000 0 0 1 1\r\n1\r\n2 2\r\n", "output": "4.242640687119\r\n"}, {"input": "1 0 1000000 0 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "7.892922226992\r\n"}, {"input": "3 0 100 100 0 0\r\n2\r\n1 0\r\n2 0\r\n", "output": "5.000000000000\r\n"}, {"input": "0 100 0 101 0 0\r\n1\r\n0 99\r\n", "output": "100.000000000000\r\n"}, {"input": "1000 1000 3 3 0 0\r\n2\r\n1 0\r\n0 1\r\n", "output": "6.605551275464\r\n"}, {"input": "0 5 0 6 0 7\r\n1\r\n0 100\r\n", "output": "187.000000000000\r\n"}, {"input": "1 1 1000000 1000000 0 0\r\n2\r\n1 2\r\n2 1\r\n", "output": "7.708203932499\r\n"}, {"input": "1 0 10000000 1000000 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "7.892922226992\r\n"}, {"input": "2 2 10 2 6 5\r\n2\r\n6 2\r\n5 5\r\n", "output": "9.000000000000\r\n"}, {"input": "100000001 100000001 100000000 100000000 1 1\r\n1\r\n1 0\r\n", "output": "141421356.530202720000\r\n"}, {"input": "1000 1000 1001 1001 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "1417.041989497841\r\n"}, {"input": "1000000000 1000000000 999999999 999999999 1 1\r\n4\r\n1 2\r\n1 3\r\n2 2\r\n2 3\r\n", "output": "1414213568.487842800000\r\n"}, {"input": "0 100 1 1 1 0\r\n2\r\n2 1\r\n0 1\r\n", "output": "5.242640687119\r\n"}, {"input": "0 100 0 1 0 0\r\n5\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n0 6\r\n", "output": "39.000000000000\r\n"}, {"input": "100 0 0 100 0 0\r\n2\r\n0 1\r\n1 0\r\n", "output": "102.000000000000\r\n"}, {"input": "0 0 1000000 1000000 0 1\r\n2\r\n1 1\r\n2 2\r\n", "output": "6.886349517373\r\n"}, {"input": "0 0 1000 1000 1 0\r\n2\r\n1 1\r\n1 2\r\n", "output": "6.236067977500\r\n"}, {"input": "1 0 100000 100000 0 0\r\n1\r\n2 0\r\n", "output": "3.000000000000\r\n"}, {"input": "5 5 5 4 4 5\r\n2\r\n3 4\r\n3 5\r\n", "output": "5.414213562373\r\n"}, {"input": "10000 10000 9000 9000 0 0\r\n3\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "12736.407342732093\r\n"}, {"input": "1 1 1000 1000 0 0\r\n3\r\n2 2\r\n3 3\r\n4 4\r\n", "output": "24.041630560343\r\n"}, {"input": "7 0 8 0 0 0\r\n2\r\n1 0\r\n1 1\r\n", "output": "9.496976092671\r\n"}, {"input": "1 3 3 3 2 1\r\n2\r\n2 3\r\n3 1\r\n", "output": "5.000000000000\r\n"}, {"input": "1 2 3 4 5 6\r\n1\r\n1 1\r\n", "output": "7.403124237433\r\n"}, {"input": "1000000000 1000000000 0 0 1 1\r\n5\r\n2 2\r\n2 3\r\n2 4\r\n2 5\r\n2 6\r\n", "output": "33.294904485247\r\n"}, {"input": "2 1 1 2 0 0\r\n1\r\n1 1\r\n", "output": "2.414213562373\r\n"}, {"input": "1 0 100000 0 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "7.892922226992\r\n"}, {"input": "0 100 1 100 1 0\r\n2\r\n2 1\r\n0 1\r\n", "output": "103.242640687119\r\n"}, {"input": "0 0 2 0 1 5\r\n2\r\n1 0\r\n1 20\r\n", "output": "36.000000000000\r\n"}, {"input": "1000 1000 999 999 0 0\r\n2\r\n1 0\r\n0 1\r\n", "output": "1415.092419071783\r\n"}, {"input": "5 0 1000 1000 2 0\r\n2\r\n4 0\r\n6 7\r\n", "output": "19.124515496597\r\n"}, {"input": "10000 0 1000000 0 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "10003.657054289499\r\n"}, {"input": "0 100 0 101 0 0\r\n2\r\n0 1\r\n0 2\r\n", "output": "102.000000000000\r\n"}, {"input": "0 0 10000 10000 1 0\r\n2\r\n2 0\r\n3 0\r\n", "output": "7.000000000000\r\n"}, {"input": "3 1 1 2 0 0\r\n1\r\n1 1\r\n", "output": "2.414213562373\r\n"}, {"input": "1000 0 0 1000 0 0\r\n2\r\n1 0\r\n0 1\r\n", "output": "1002.000000000000\r\n"}, {"input": "1 1 1000000 1000000 0 0\r\n2\r\n2 1\r\n1 2\r\n", "output": "7.708203932499\r\n"}, {"input": "1000 1000 2000 2000 1 1\r\n3\r\n2 2\r\n1 2\r\n3 3\r\n", "output": "1417.627775935468\r\n"}, {"input": "0 0 1000000000 1000000000 1 1\r\n4\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n", "output": "29.698484809835\r\n"}, {"input": "10000000 1 2 1 1 1\r\n3\r\n1 3\r\n1 4\r\n1 5\r\n", "output": "18.123105625618\r\n"}, {"input": "3 7 5 7 4 4\r\n2\r\n4 6\r\n4 0\r\n", "output": "11.414213562373\r\n"}, {"input": "0 0 3 0 1 5\r\n2\r\n1 0\r\n1 20\r\n", "output": "36.000000000000\r\n"}, {"input": "0 0 0 1 1000 3\r\n2\r\n1000 2\r\n1000 1\r\n", "output": "1004.000000000000\r\n"}, {"input": "1000000000 0 0 1 0 0\r\n2\r\n0 2\r\n0 3\r\n", "output": "9.000000000000\r\n"}, {"input": "0 1000000000 1000000000 0 0 0\r\n1\r\n1 1\r\n", "output": "1000000000.414213500000\r\n"}, {"input": "1000 1000 1000 1001 0 0\r\n2\r\n0 1\r\n1 1\r\n", "output": "1416.213562373095\r\n"}, {"input": "1002 0 1001 0 0 0\r\n1\r\n1000 0\r\n", "output": "1001.000000000000\r\n"}, {"input": "1002 0 1001 0 0 0\r\n2\r\n2 0\r\n1 0\r\n", "output": "1003.000000000000\r\n"}, {"input": "3 0 0 100 0 0\r\n2\r\n1 0\r\n2 0\r\n", "output": "5.000000000000\r\n"}, {"input": "10 10 0 0 0 1\r\n2\r\n1 0\r\n1 1\r\n", "output": "4.414213562373\r\n"}, {"input": "1000 1000 1001 1001 0 0\r\n2\r\n0 1\r\n1 1\r\n", "output": "1416.213562373095\r\n"}, {"input": "0 100 0 200 0 0\r\n2\r\n0 1\r\n0 2\r\n", "output": "102.000000000000\r\n"}, {"input": "100 100 0 0 1 1\r\n1\r\n2 2\r\n", "output": "4.242640687119\r\n"}, {"input": "123123 154345 123123 123123 2 2\r\n3\r\n3 3\r\n4 4\r\n5 5\r\n", "output": "174127.873294312070\r\n"}, {"input": "0 1 0 2 0 0\r\n1\r\n1 0\r\n", "output": "2.414213562373\r\n"}, {"input": "1 2 3 4 1000 1000\r\n1\r\n156 608\r\n", "output": "1553.668251715911\r\n"}, {"input": "0 0 10 0 5 0\r\n3\r\n4 1\r\n5 1\r\n6 1\r\n", "output": "10.365746312737\r\n"}, {"input": "0 0 0 1 1000000000 999999999\r\n1\r\n1000000000 1000000000\r\n", "output": "1414213562.665988200000\r\n"}, {"input": "1231231 2342342 123124 123151 12315 12312\r\n1\r\n354345 234234\r\n", "output": "664238.053973730540\r\n"}, {"input": "0 0 1000000 0 1 1\r\n2\r\n0 1\r\n3 0\r\n", "output": "6.472135955000\r\n"}, {"input": "1000 1000 2000 2000 1 1\r\n1\r\n2 2\r\n", "output": "1412.799348810722\r\n"}, {"input": "10 20 10 0 10 10\r\n2\r\n10 11\r\n10 9\r\n", "output": "12.000000000000\r\n"}, {"input": "1000000000 1 1 1000000000 0 0\r\n1\r\n2 2\r\n", "output": "1000000000.828427200000\r\n"}, {"input": "0 0 1000 1000 1 0\r\n2\r\n2 0\r\n3 0\r\n", "output": "7.000000000000\r\n"}, {"input": "1000 0 100000000 100000000 0 0\r\n2\r\n999 0\r\n1100 0\r\n", "output": "3198.000000000000\r\n"}, {"input": "2 2 1000000000 1000000000 0 0\r\n3\r\n1 1\r\n5 5\r\n100 100\r\n", "output": "296.984848098350\r\n"}, {"input": "2 0 4 0 0 0\r\n1\r\n3 0\r\n", "output": "4.000000000000\r\n"}, {"input": "2 2 1000 1000 0 0\r\n2\r\n1 1\r\n1 2\r\n", "output": "6.064495102246\r\n"}, {"input": "0 0 1000000000 1000000000 0 1\r\n3\r\n1 0\r\n2 0\r\n3 0\r\n", "output": "13.210904837709\r\n"}, {"input": "1 10000 10000 1 0 0\r\n2\r\n1 100\r\n100 1\r\n", "output": "10200.014999625020\r\n"}, {"input": "5 0 6 0 0 0\r\n2\r\n2 0\r\n0 2\r\n", "output": "9.000000000000\r\n"}, {"input": "2 4 1000000000 1000000000 0 0\r\n4\r\n2 3\r\n2 1\r\n3 2\r\n1 2\r\n", "output": "20.760925736391\r\n"}, {"input": "0 100 1 1 0 0\r\n2\r\n0 1\r\n3 1\r\n", "output": "7.162277660168\r\n"}, {"input": "0 0 10 0 8 2\r\n1\r\n6 0\r\n", "output": "6.828427124746\r\n"}, {"input": "0 9 0 8 0 1\r\n1\r\n0 0\r\n", "output": "9.000000000000\r\n"}, {"input": "100 0 0 100 0 0\r\n2\r\n40 0\r\n0 40\r\n", "output": "180.000000000000\r\n"}, {"input": "0 0 0 1 1000 3\r\n2\r\n1000 1\r\n1000 2\r\n", "output": "1004.000000000000\r\n"}, {"input": "1 1 123123 123123 2 2\r\n3\r\n3 3\r\n4 4\r\n5 5\r\n", "output": "18.384776310850\r\n"}, {"input": "999999999 999999999 1000000000 1000000000 1 1\r\n1\r\n1 0\r\n", "output": "1414213561.251774800000\r\n"}, {"input": "3 2 1 1 0 0\r\n1\r\n2 2\r\n", "output": "3.828427124746\r\n"}, {"input": "0 0 1 1 100 100\r\n2\r\n101 101\r\n102 102\r\n", "output": "148.492424049175\r\n"}, {"input": "1 15 4 10 1 1\r\n2\r\n1 10\r\n4 5\r\n", "output": "22.000000000000\r\n"}, {"input": "100 0 0 100 0 0\r\n2\r\n60 0\r\n0 40\r\n", "output": "180.000000000000\r\n"}, {"input": "0 0 0 1000 1 0\r\n4\r\n0 1\r\n0 2\r\n0 3\r\n0 4\r\n", "output": "21.457116088945\r\n"}, {"input": "0 0 100 0 3 0\r\n1\r\n2 0\r\n", "output": "3.000000000000\r\n"}, {"input": "0 0 100 0 98 2\r\n1\r\n98 0\r\n", "output": "4.000000000000\r\n"}, {"input": "1 1 2 2 3 3\r\n1\r\n0 0\r\n", "output": "5.656854249492\r\n"}, {"input": "2 2 1 1 0 0\r\n1\r\n1 2\r\n", "output": "3.236067977500\r\n"}, {"input": "10000000 1 2 1 1 1\r\n3\r\n1 40\r\n1 20\r\n1 5\r\n", "output": "124.012818406262\r\n"}, {"input": "1000 1000 1001 1000 0 0\r\n3\r\n1 1\r\n1 2\r\n1 3\r\n", "output": "1421.848684511914\r\n"}, {"input": "10000 10000 9999 9999 0 0\r\n3\r\n0 1\r\n0 2\r\n0 3\r\n", "output": "14147.600248963827\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(output_path) as f: correct = f.read().strip() with open(submission_path) as f: submission = f.read().strip() try: correct_val = float(correct) submission_val = float(submission) except: print(0) return delta = abs(correct_val - submission_val) denominator = max(1.0, abs(correct_val)) if delta <= 1e-6 * denominator: print(1) else: print(0) if __name__ == "__main__": main()
true
789/B
789
B
Python 3
TESTS
13
77
15,564,800
28802508
import sys def ans(n): print(n) sys.exit() def check(n): global w return ((abs(n) <= l) and (n not in w)) b1, q, l, m = map(int, input().split()) w = set(map(int, input().split())) inf = 'inf' #possiblity for answering inf if b1 == 0: if (0 not in w): ans(inf) else: ans(0) # b1 != 0 if q == 0: if check(0): ans(inf) elif check(b1): ans(1) else: ans(0) # q != 0 if q == 1: if check(b1): ans(inf) else: ans(0) if q == -1: if check(b1) or check(-b1): ans(inf) else: ans(0) #no more inf # |q| > 1 cnt = 0 while abs(b1) <= 1000001000: cnt += check(b1) b1 *= q ans(cnt)
116
93
13,004,800
28874811
b,q,l,m=map(int,input().split()) a=set(list(map(int,input().split()))) c=0 for i in range(100): if abs(b)>l: break if b not in a: c+=1 b*=q if c<32: print (c) else: print('inf')
Codeforces Round 407 (Div. 2)
CF
2,017
1
256
Masha and geometric depression
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board.
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
null
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123.
[{"input": "3 2 30 4\n6 14 25 48", "output": "3"}, {"input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0"}, {"input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf"}]
1,700
["brute force", "implementation", "math"]
116
[{"input": "3 2 30 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "123 1 2143435 4\r\n123 11 -5453 141245\r\n", "output": "0"}, {"input": "123 1 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "3 2 25 2\r\n379195692 -69874783\r\n", "output": "4"}, {"input": "3 2 30 3\r\n-691070108 -934106649 -220744807\r\n", "output": "4"}, {"input": "3 3 104 17\r\n9 -73896485 -290898562 5254410 409659728 -916522518 -435516126 94354167 262981034 -375897180 -80186684 -173062070 -288705544 -699097793 -11447747 320434295 503414250\r\n", "output": "3"}, {"input": "-1000000000 -1000000000 1 1\r\n232512888\r\n", "output": "0"}, {"input": "11 0 228 5\r\n-1 0 1 5 -11245\r\n", "output": "1"}, {"input": "11 0 228 5\r\n-1 -17 1 5 -11245\r\n", "output": "inf"}, {"input": "0 0 2143435 5\r\n-1 -153 1 5 -11245\r\n", "output": "inf"}, {"input": "123 0 2143435 4\r\n5433 0 123 -645\r\n", "output": "0"}, {"input": "123 -1 2143435 5\r\n-123 0 12 5 -11245\r\n", "output": "inf"}, {"input": "123 0 21 4\r\n543453 -123 6 1424\r\n", "output": "0"}, {"input": "3 2 115 16\r\n24 48 12 96 3 720031148 -367712651 -838596957 558177735 -963046495 -313322487 -465018432 -618984128 -607173835 144854086 178041956\r\n", "output": "1"}, {"input": "-3 0 92055 36\r\n-92974174 -486557474 -663622151 695596393 177960746 -563227474 -364263320 -676254242 -614140218 71456762 -764104225 705056581 -106398436 332755134 -199942822 -732751692 658942664 677739866 886535704 183687802 -784248291 -22550621 -938674499 637055091 -704750213 780395802 778342470 -999059668 -794361783 796469192 215667969 354336794 -60195289 -885080928 -290279020 201221317\r\n", "output": "inf"}, {"input": "0 -3 2143435 5\r\n-1 0 1 5 -11245\r\n", "output": "0"}, {"input": "123 -1 2143435 5\r\n-123 0 123 -5453 141245\r\n", "output": "0"}, {"input": "123 0 2143435 4\r\n5433 0 -123 -645\r\n", "output": "1"}, {"input": "11 0 2 5\r\n-1 0 1 5 -11245\r\n", "output": "0"}, {"input": "2 2 4 1\r\n2\r\n", "output": "1"}, {"input": "1 -2 1000000000 1\r\n0\r\n", "output": "30"}, {"input": "0 8 10 1\r\n5\r\n", "output": "inf"}, {"input": "-1000 0 10 1\r\n5\r\n", "output": "0"}, {"input": "0 2 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "0 8 5 1\r\n9\r\n", "output": "inf"}, {"input": "-10 1 5 1\r\n100\r\n", "output": "0"}, {"input": "123 -1 2143435 4\r\n54343 -13 6 123\r\n", "output": "inf"}, {"input": "-5 -1 10 1\r\n-5\r\n", "output": "inf"}, {"input": "2 0 1 1\r\n2\r\n", "output": "0"}, {"input": "0 5 8 1\r\n10\r\n", "output": "inf"}, {"input": "0 5 100 2\r\n34 56\r\n", "output": "inf"}, {"input": "15 -1 15 4\r\n15 -15 1 2\r\n", "output": "0"}, {"input": "10 -1 2 1\r\n1\r\n", "output": "0"}, {"input": "2 0 2 1\r\n2\r\n", "output": "inf"}, {"input": "4 0 4 1\r\n0\r\n", "output": "1"}, {"input": "10 10 10 1\r\n123\r\n", "output": "1"}, {"input": "2 2 4 1\r\n3\r\n", "output": "2"}, {"input": "0 1 1 1\r\n0\r\n", "output": "0"}, {"input": "3 2 30 1\r\n3\r\n", "output": "3"}, {"input": "1000000000 100000 1000000000 4\r\n5433 13 6 0\r\n", "output": "1"}, {"input": "-2 0 1 1\r\n1\r\n", "output": "0"}, {"input": "2 -1 10 1\r\n2\r\n", "output": "inf"}, {"input": "1 -1 2 1\r\n1\r\n", "output": "inf"}, {"input": "0 10 10 1\r\n2\r\n", "output": "inf"}, {"input": "0 35 2 1\r\n3\r\n", "output": "inf"}, {"input": "3 1 3 1\r\n5\r\n", "output": "inf"}, {"input": "3 2 3 4\r\n6 14 25 48\r\n", "output": "1"}, {"input": "0 69 12 1\r\n1\r\n", "output": "inf"}, {"input": "100 0 100000 1\r\n100\r\n", "output": "inf"}, {"input": "0 4 1000 3\r\n5 6 7\r\n", "output": "inf"}, {"input": "0 2 100 1\r\n5\r\n", "output": "inf"}, {"input": "3 2 24 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "0 4 1 1\r\n2\r\n", "output": "inf"}, {"input": "1 5 10000 1\r\n125\r\n", "output": "5"}, {"input": "2 -1 1 1\r\n1\r\n", "output": "0"}, {"input": "0 3 100 1\r\n5\r\n", "output": "inf"}, {"input": "0 3 3 1\r\n1\r\n", "output": "inf"}, {"input": "0 2 5 1\r\n1\r\n", "output": "inf"}, {"input": "5 -1 100 1\r\n5\r\n", "output": "inf"}, {"input": "-20 0 10 1\r\n0\r\n", "output": "0"}, {"input": "3 0 1 1\r\n3\r\n", "output": "0"}, {"input": "2 -1 3 1\r\n2\r\n", "output": "inf"}, {"input": "1 1 1000000000 1\r\n100\r\n", "output": "inf"}, {"input": "5 -1 3 1\r\n0\r\n", "output": "0"}, {"input": "0 5 10 1\r\n2\r\n", "output": "inf"}, {"input": "123 0 125 1\r\n123\r\n", "output": "inf"}, {"input": "2 -1 100 1\r\n2\r\n", "output": "inf"}, {"input": "5 2 100 1\r\n5\r\n", "output": "4"}, {"input": "-5 0 1 1\r\n1\r\n", "output": "0"}, {"input": "-3 0 1 1\r\n-3\r\n", "output": "0"}, {"input": "2 -2 10 1\r\n1\r\n", "output": "3"}, {"input": "0 2 30 4\r\n6 14 25 48\r\n", "output": "inf"}, {"input": "1 -1 1 1\r\n1\r\n", "output": "inf"}, {"input": "2 -1 6 1\r\n2\r\n", "output": "inf"}, {"input": "-3 1 100 1\r\n-3\r\n", "output": "0"}, {"input": "1 0 2 1\r\n1\r\n", "output": "inf"}, {"input": "1000000000 999999998 1000000000 1\r\n0\r\n", "output": "1"}, {"input": "1 0 2143435 4\r\n1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "-1000 0 100 1\r\n-1000\r\n", "output": "0"}, {"input": "100 10 2 1\r\n100\r\n", "output": "0"}, {"input": "-3 1 100 1\r\n3\r\n", "output": "inf"}, {"input": "123 -1 10000 1\r\n123\r\n", "output": "inf"}, {"input": "1 -1 2143435 4\r\n1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "5 1 5 5\r\n1 2 3 4 0\r\n", "output": "inf"}, {"input": "-100 -1 1 1\r\n1\r\n", "output": "0"}, {"input": "10 -1 3 2\r\n10 8\r\n", "output": "0"}, {"input": "-10 0 5 1\r\n0\r\n", "output": "0"}, {"input": "3 0 3 1\r\n0\r\n", "output": "1"}, {"input": "2 0 2 1\r\n-1\r\n", "output": "inf"}, {"input": "5 0 20 1\r\n5\r\n", "output": "inf"}, {"input": "-4 1 1 1\r\n0\r\n", "output": "0"}, {"input": "11 0 1111 1\r\n11\r\n", "output": "inf"}, {"input": "2 0 3 1\r\n2\r\n", "output": "inf"}, {"input": "-1 -1 2143435 4\r\n-1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "-100 0 50 1\r\n0\r\n", "output": "0"}, {"input": "5 1 2 1\r\n2\r\n", "output": "0"}, {"input": "3 0 3 1\r\n4\r\n", "output": "inf"}, {"input": "0 23 3 1\r\n3\r\n", "output": "inf"}, {"input": "-1000 0 100 1\r\n2\r\n", "output": "0"}, {"input": "1 -1 10 1\r\n1\r\n", "output": "inf"}]
false
stdio
null
true
997/A
997
A
Python 3
TESTS
30
233
1,433,600
84404889
n,h,m=list(map(int,input().split())) s = input() if h<m: p=0 for i in range(n-1): if s[i]=='0' and s[i+1]=='1': p+=1 if s[i]=='1' and s[i+1]=='0': p+=1 if s.count('0')>0: print((p//2)*h+m) else: print((p//2)*h) else: k=0 p=0 for i in range(n): if s[i]=='0': p+=1 if (s[i]=='1' or i==n-1) and p>0: p=0 k+=1 print(k*m)
115
77
1,433,600
205174627
n, x, y = map(int, input().split()) s = '1'+input().strip() c = s.count('10') print(0 if c == 0 else y * c if y <= x else (x * c + y - x))
Codeforces Round 493 (Div. 1)
CF
2,018
1
256
Convert to Ones
You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones. Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$. You can apply the following operations any number of times: - Choose some substring of string $$$a$$$ (for example, you can choose entire string) and reverse it, paying $$$x$$$ coins for it (for example, «0101101» $$$\to$$$ «0111001»); - Choose some substring of string $$$a$$$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $$$y$$$ coins for it (for example, «0101101» $$$\to$$$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones?
The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $$$a$$$ of length $$$n$$$, consisting of zeros and ones.
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations.
null
In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «10000» $$$\to$$$ «11111». The total cost of operations is $$$1 + 10 = 11$$$. In the second sample, at first you need to invert substring $$$[1 \dots 1]$$$, and then you need to invert substring $$$[3 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «11000» $$$\to$$$ «11111». The overall cost is $$$1 + 1 = 2$$$. In the third example, string already consists only of ones, so the answer is $$$0$$$.
[{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}]
1,500
["brute force", "greedy", "implementation", "math"]
115
[{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 261764879\r\n0\r\n", "output": "261764879\r\n"}, {"input": "1 491511050 399084767\r\n1\r\n", "output": "0\r\n"}, {"input": "2 163093925 214567542\r\n00\r\n", "output": "214567542\r\n"}, {"input": "2 340351106 646854722\r\n10\r\n", "output": "646854722\r\n"}, {"input": "2 222640995 489207317\r\n01\r\n", "output": "489207317\r\n"}, {"input": "2 399898176 552898277\r\n11\r\n", "output": "0\r\n"}, {"input": "2 690218164 577155357\r\n00\r\n", "output": "577155357\r\n"}, {"input": "2 827538051 754412538\r\n10\r\n", "output": "754412538\r\n"}, {"input": "2 636702427 259825230\r\n01\r\n", "output": "259825230\r\n"}, {"input": "2 108926899 102177825\r\n11\r\n", "output": "0\r\n"}, {"input": "3 368381052 440077270\r\n000\r\n", "output": "440077270\r\n"}, {"input": "3 505700940 617334451\r\n100\r\n", "output": "617334451\r\n"}, {"input": "3 499624340 643020827\r\n010\r\n", "output": "1142645167\r\n"}, {"input": "3 75308005 971848814\r\n110\r\n", "output": "971848814\r\n"}, {"input": "3 212627893 854138703\r\n001\r\n", "output": "854138703\r\n"}, {"input": "3 31395883 981351561\r\n101\r\n", "output": "981351561\r\n"}, {"input": "3 118671447 913685773\r\n011\r\n", "output": "913685773\r\n"}, {"input": "3 255991335 385910245\r\n111\r\n", "output": "0\r\n"}, {"input": "3 688278514 268200134\r\n000\r\n", "output": "268200134\r\n"}, {"input": "3 825598402 445457315\r\n100\r\n", "output": "445457315\r\n"}, {"input": "3 300751942 45676507\r\n010\r\n", "output": "91353014\r\n"}, {"input": "3 517900980 438071829\r\n110\r\n", "output": "438071829\r\n"}, {"input": "3 400190869 280424424\r\n001\r\n", "output": "280424424\r\n"}, {"input": "3 577448050 344115384\r\n101\r\n", "output": "344115384\r\n"}, {"input": "3 481435271 459737939\r\n011\r\n", "output": "459737939\r\n"}, {"input": "3 931962412 913722450\r\n111\r\n", "output": "0\r\n"}, {"input": "4 522194562 717060616\r\n0000\r\n", "output": "717060616\r\n"}, {"input": "4 659514449 894317797\r\n1000\r\n", "output": "894317797\r\n"}, {"input": "4 71574977 796834337\r\n0100\r\n", "output": "868409314\r\n"}, {"input": "4 248832158 934154224\r\n1100\r\n", "output": "934154224\r\n"}, {"input": "4 71474110 131122047\r\n0010\r\n", "output": "202596157\r\n"}, {"input": "4 308379228 503761290\r\n1010\r\n", "output": "812140518\r\n"}, {"input": "4 272484957 485636409\r\n0110\r\n", "output": "758121366\r\n"}, {"input": "4 662893590 704772137\r\n1110\r\n", "output": "704772137\r\n"}, {"input": "4 545183479 547124732\r\n0001\r\n", "output": "547124732\r\n"}, {"input": "4 684444619 722440661\r\n1001\r\n", "output": "722440661\r\n"}, {"input": "4 477963686 636258459\r\n0101\r\n", "output": "1114222145\r\n"}, {"input": "4 360253575 773578347\r\n1101\r\n", "output": "773578347\r\n"}, {"input": "4 832478048 910898234\r\n0011\r\n", "output": "910898234\r\n"}, {"input": "4 343185412 714767937\r\n1011\r\n", "output": "714767937\r\n"}, {"input": "4 480505300 892025118\r\n0111\r\n", "output": "892025118\r\n"}, {"input": "4 322857895 774315007\r\n1111\r\n", "output": "0\r\n"}, {"input": "4 386548854 246539479\r\n0000\r\n", "output": "246539479\r\n"}, {"input": "4 523868742 128829368\r\n1000\r\n", "output": "128829368\r\n"}, {"input": "4 956155921 11119257\r\n0100\r\n", "output": "22238514\r\n"}, {"input": "4 188376438 93475808\r\n1100\r\n", "output": "93475808\r\n"}, {"input": "4 754947032 158668188\r\n0010\r\n", "output": "317336376\r\n"}, {"input": "4 927391856 637236921\r\n1010\r\n", "output": "1274473842\r\n"}, {"input": "4 359679035 109461393\r\n0110\r\n", "output": "218922786\r\n"}, {"input": "4 991751283 202031630\r\n1110\r\n", "output": "202031630\r\n"}, {"input": "4 339351517 169008463\r\n0001\r\n", "output": "169008463\r\n"}, {"input": "4 771638697 346265644\r\n1001\r\n", "output": "346265644\r\n"}, {"input": "4 908958584 523522825\r\n0101\r\n", "output": "1047045650\r\n"}, {"input": "4 677682252 405812714\r\n1101\r\n", "output": "405812714\r\n"}, {"input": "4 815002139 288102603\r\n0011\r\n", "output": "288102603\r\n"}, {"input": "4 952322026 760327076\r\n1011\r\n", "output": "760327076\r\n"}, {"input": "4 663334158 312481698\r\n0111\r\n", "output": "312481698\r\n"}, {"input": "4 840591339 154834293\r\n1111\r\n", "output": "0\r\n"}, {"input": "14 3 11\r\n10110100011001\r\n", "output": "20\r\n"}, {"input": "19 1 1\r\n1010101010101010101\r\n", "output": "9\r\n"}, {"input": "1 10 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 100 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 1000 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 10 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "7 3 2\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 10\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 3 2\r\n1\r\n", "output": "0\r\n"}, {"input": "2 10 1\r\n11\r\n", "output": "0\r\n"}, {"input": "4 148823922 302792601\r\n1010\r\n", "output": "451616523\r\n"}, {"input": "1 2 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n00011\r\n", "output": "3\r\n"}, {"input": "1 5 0\r\n1\r\n", "output": "0\r\n"}, {"input": "7 2 3\r\n1001001\r\n", "output": "5\r\n"}, {"input": "10 1 1000000000\r\n1111010111\r\n", "output": "1000000001\r\n"}, {"input": "25 999999998 999999999\r\n1011001110101010100111001\r\n", "output": "7999999985\r\n"}, {"input": "2 0 1\r\n00\r\n", "output": "1\r\n"}, {"input": "2 1 100\r\n10\r\n", "output": "100\r\n"}, {"input": "7 20 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "0\r\n"}, {"input": "3 1 10\r\n010\r\n", "output": "11\r\n"}, {"input": "2 1 0\r\n11\r\n", "output": "0\r\n"}, {"input": "7 100 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 1000\r\n10101\r\n", "output": "1001\r\n"}, {"input": "5 2 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "1 1000 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 799543940 488239239\r\n1\r\n", "output": "0\r\n"}, {"input": "6 1 1000\r\n010101\r\n", "output": "1002\r\n"}, {"input": "5 11 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n10101\r\n", "output": "5\r\n"}, {"input": "3 10 1\r\n111\r\n", "output": "0\r\n"}, {"input": "7 9 10\r\n1001011\r\n", "output": "19\r\n"}, {"input": "5 5 6\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 1000000000 0\r\n1\r\n", "output": "0\r\n"}, {"input": "4 0 1\r\n0101\r\n", "output": "1\r\n"}, {"input": "8 2 3\r\n10101010\r\n", "output": "9\r\n"}, {"input": "6 3 100\r\n010101\r\n", "output": "106\r\n"}, {"input": "3 3 2\r\n111\r\n", "output": "0\r\n"}, {"input": "1 20 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n01\r\n", "output": "2\r\n"}]
false
stdio
null
true
814/A
814
A
Python 3
TESTS
19
93
6,963,200
89375436
n,k=map(int,input().split()) lsta=list(map(int,input().split())) lstb=list(map(int,input().split())) lst=[] for i in lsta: if(i not in lst): lst.append(i) else: if(i!=0): print("NO") exit() lst=[] for i in lstb: if (i not in lst): lst.append(i) else: if (i != 0): print("NO") exit() if(k>=2): print("YES") exit() last=-1 ct=0 fnd=0 ctz=0 indx=-1 for i in range(n): if(lsta[i]==0): ctz+=1 indx=i if(lsta[i]==0 and ct<k): ct+=1 continue if(last==-1): last=lsta[i] continue if(lsta[i]<=last): fnd=1 break else: last=lsta[i] if(fnd==1): print("YES") elif(ctz>=2): print("YES") else: if(indx!=n-1): if(lsta[indx-1]<lstb[0] and lsta[indx+1]>lstb[0]): print("NO") else: print("YES") else: if (lsta[indx-1] < lstb[0] ): print("NO") else: print("YES")
96
46
0
136176990
n,k=[int(x) for x in input().split()] a=[int(x) for x in input().split()] b=[int(x) for x in input().split()] if a.count(0)>=2: print('YES') else: a[a.index(0)]=b[0] if sorted(a)==a: print('NO') else: print('YES')
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An abandoned sentiment from past
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.
The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements. The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in a and b more than once in total.
Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.
null
In the first sample: - Sequence a is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in b are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
[{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}]
900
["constructive algorithms", "greedy", "implementation", "sortings"]
96
[{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\r\n80\r\n", "output": "No\r\n"}, {"input": "100 1\r\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\r\n58\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n2 1 0 4\r\n3\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n199 0\r\n200\r\n", "output": "No\r\n"}, {"input": "3 2\r\n115 0 0\r\n145 191\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n196 197 198 0 200\r\n199\r\n", "output": "No\r\n"}, {"input": "5 1\r\n92 0 97 99 100\r\n93\r\n", "output": "No\r\n"}, {"input": "3 1\r\n3 87 0\r\n81\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 92 192\r\n118\r\n", "output": "Yes\r\n"}, {"input": "10 1\r\n1 3 0 7 35 46 66 72 83 90\r\n22\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 0 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113\r\n67\r\n", "output": "No\r\n"}, {"input": "100 5\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 0 99 100\r\n98 64 55 52 29\r\n", "output": "Yes\r\n"}, {"input": "100 5\r\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\r\n121 199 62 193 27\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 0 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n11\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n1\r\n", "output": "No\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 0\r\n100\r\n", "output": "No\r\n"}, {"input": "100 1\r\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\r\n65\r\n", "output": "Yes\r\n"}, {"input": "100 2\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 0 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n48 1\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\r\n69\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\r\n129\r\n", "output": "No\r\n"}, {"input": "5 2\r\n0 2 7 0 10\r\n1 8\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 4 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 3\r\n4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n1\r\n", "output": "No\r\n"}, {"input": "2 1\r\n0 5\r\n7\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 0 12 13\r\n1\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n0 2 3 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 0 3 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "7 2\r\n1 2 3 0 0 6 7\r\n4 5\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "2 2\r\n0 0\r\n1 2\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n1 0 0\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 4 0\r\n5 2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 1\r\n2\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 4 5\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 2 3\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 5 0\r\n6\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 0 2\r\n7\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n4 5 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 12 0 14\r\n13\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 2 0 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 11 14\r\n12\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 3 0 4\r\n2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 5\r\n1\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 7\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 5 4\r\n6\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n11 0 0 14\r\n13 12\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n1 0\r\n2\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 0 3 2\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 2 3 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 2 0\r\n5\r\n", "output": "No\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 5 7\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 0 11\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n7 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 3 0 5 0\r\n6 4\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n0 1 0\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n6 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 3\r\n6\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 2 0 0 5\r\n4 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n2 0 0 8\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 0 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 2\r\n11 0 0 200\r\n100 199\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n5 0\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 5\r\n10\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 0 0 5 6\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 3 0 5\r\n2 4\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 4 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n5 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 7\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "3 3\r\n0 0 0\r\n1 4 3\r\n", "output": "Yes\r\n"}, {"input": "5 5\r\n0 0 0 0 0\r\n5 4 3 2 1\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n3 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 4 0 8 9 10\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 3 5 6\r\n9\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 2 0 0\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 4 5 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 0 4\r\n5\r\n", "output": "Yes\r\n"}]
false
stdio
null
true
814/A
814
A
Python 3
TESTS
19
62
0
27765647
# x = input().split() n , k = map(int , input().split()) x = [int(i) for i in input().split()] y = [int(i) for i in input().split()] hitcresce = 1 if k > 1: print('Yes') exit() x.append(999) aux = 0 for i in range(1,n): if x[i-1]!= 0: aux = x[i-1] if x[i] != 0 and x[i] < aux : hitcresce = 0 break if (hitcresce == 0): print('Yes') exit() for i in range(n): if x[i] == 0: if (x[i-1] < y[0] and y[0] < x[i+1]): print('No') else: print('Yes') break
96
46
0
146234207
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) if k == 1: i = a.index(0) a[i] = b[0] x = sorted(a) if a == x: print("NO") else: print("YES") else: b = sorted(b, reverse=True) x = 0 for i in range(0, n): if a[i] == 0: a[i] = b[x] x += 1 print("YES")
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An abandoned sentiment from past
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.
The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements. The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in a and b more than once in total.
Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.
null
In the first sample: - Sequence a is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in b are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
[{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}]
900
["constructive algorithms", "greedy", "implementation", "sortings"]
96
[{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\r\n80\r\n", "output": "No\r\n"}, {"input": "100 1\r\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\r\n58\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n2 1 0 4\r\n3\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n199 0\r\n200\r\n", "output": "No\r\n"}, {"input": "3 2\r\n115 0 0\r\n145 191\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n196 197 198 0 200\r\n199\r\n", "output": "No\r\n"}, {"input": "5 1\r\n92 0 97 99 100\r\n93\r\n", "output": "No\r\n"}, {"input": "3 1\r\n3 87 0\r\n81\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 92 192\r\n118\r\n", "output": "Yes\r\n"}, {"input": "10 1\r\n1 3 0 7 35 46 66 72 83 90\r\n22\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 0 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113\r\n67\r\n", "output": "No\r\n"}, {"input": "100 5\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 0 99 100\r\n98 64 55 52 29\r\n", "output": "Yes\r\n"}, {"input": "100 5\r\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\r\n121 199 62 193 27\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 0 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n11\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n1\r\n", "output": "No\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 0\r\n100\r\n", "output": "No\r\n"}, {"input": "100 1\r\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\r\n65\r\n", "output": "Yes\r\n"}, {"input": "100 2\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 0 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n48 1\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\r\n69\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\r\n129\r\n", "output": "No\r\n"}, {"input": "5 2\r\n0 2 7 0 10\r\n1 8\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 4 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 3\r\n4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n1\r\n", "output": "No\r\n"}, {"input": "2 1\r\n0 5\r\n7\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 0 12 13\r\n1\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n0 2 3 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 0 3 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "7 2\r\n1 2 3 0 0 6 7\r\n4 5\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "2 2\r\n0 0\r\n1 2\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n1 0 0\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 4 0\r\n5 2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 1\r\n2\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 4 5\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 2 3\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 5 0\r\n6\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 0 2\r\n7\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n4 5 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 12 0 14\r\n13\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 2 0 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 11 14\r\n12\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 3 0 4\r\n2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 5\r\n1\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 7\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 5 4\r\n6\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n11 0 0 14\r\n13 12\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n1 0\r\n2\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 0 3 2\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 2 3 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 2 0\r\n5\r\n", "output": "No\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 5 7\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 0 11\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n7 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 3 0 5 0\r\n6 4\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n0 1 0\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n6 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 3\r\n6\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 2 0 0 5\r\n4 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n2 0 0 8\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 0 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 2\r\n11 0 0 200\r\n100 199\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n5 0\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 5\r\n10\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 0 0 5 6\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 3 0 5\r\n2 4\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 4 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n5 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 7\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "3 3\r\n0 0 0\r\n1 4 3\r\n", "output": "Yes\r\n"}, {"input": "5 5\r\n0 0 0 0 0\r\n5 4 3 2 1\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n3 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 4 0 8 9 10\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 3 5 6\r\n9\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 2 0 0\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 4 5 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 0 4\r\n5\r\n", "output": "Yes\r\n"}]
false
stdio
null
true
789/B
789
B
Python 3
PRETESTS
13
108
15,564,800
25903897
b, q, l, m = map(int, input().split()) A = set(map(int, input().split())) if b == 0: print(0 if 0 in A else "inf") elif q == 0: if 0 in A: print(1 if b not in A and abs(b) <= l else 0) else: print("inf") elif q == 1: print(0 if b in A or abs(b) > l else 'inf') elif q == -1: print(0 if (-b in A and b in A) or abs(b) > l else 'inf') else: ans = 0 while abs(b) <= l: ans += b not in A b *= q print(ans)
116
93
13,824,000
25912881
import sys def solve(): b1, q, L, m = map(int, input().split()) a = [int(i) for i in input().split()] a = set(a) if b1 == 0: print(0 if b1 in a else 'inf') return if q == 1: if abs(b1) > L or b1 in a: print(0) else: print('inf') elif q == -1: if abs(b1) > L or (b1 in a and -b1 in a): print(0) else: print('inf') elif q == 0: if abs(b1) > L: print(0) elif 0 in a: print(0 if b1 in a else 1) else: print('inf') else: b = b1 ans = 0 while abs(b) <= L: if b not in a: ans += 1 b *= q print(ans) def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None if __name__ == '__main__': solve()
Codeforces Round 407 (Div. 2)
CF
2,017
1
256
Masha and geometric depression
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board.
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
null
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123.
[{"input": "3 2 30 4\n6 14 25 48", "output": "3"}, {"input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0"}, {"input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf"}]
1,700
["brute force", "implementation", "math"]
116
[{"input": "3 2 30 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "123 1 2143435 4\r\n123 11 -5453 141245\r\n", "output": "0"}, {"input": "123 1 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "3 2 25 2\r\n379195692 -69874783\r\n", "output": "4"}, {"input": "3 2 30 3\r\n-691070108 -934106649 -220744807\r\n", "output": "4"}, {"input": "3 3 104 17\r\n9 -73896485 -290898562 5254410 409659728 -916522518 -435516126 94354167 262981034 -375897180 -80186684 -173062070 -288705544 -699097793 -11447747 320434295 503414250\r\n", "output": "3"}, {"input": "-1000000000 -1000000000 1 1\r\n232512888\r\n", "output": "0"}, {"input": "11 0 228 5\r\n-1 0 1 5 -11245\r\n", "output": "1"}, {"input": "11 0 228 5\r\n-1 -17 1 5 -11245\r\n", "output": "inf"}, {"input": "0 0 2143435 5\r\n-1 -153 1 5 -11245\r\n", "output": "inf"}, {"input": "123 0 2143435 4\r\n5433 0 123 -645\r\n", "output": "0"}, {"input": "123 -1 2143435 5\r\n-123 0 12 5 -11245\r\n", "output": "inf"}, {"input": "123 0 21 4\r\n543453 -123 6 1424\r\n", "output": "0"}, {"input": "3 2 115 16\r\n24 48 12 96 3 720031148 -367712651 -838596957 558177735 -963046495 -313322487 -465018432 -618984128 -607173835 144854086 178041956\r\n", "output": "1"}, {"input": "-3 0 92055 36\r\n-92974174 -486557474 -663622151 695596393 177960746 -563227474 -364263320 -676254242 -614140218 71456762 -764104225 705056581 -106398436 332755134 -199942822 -732751692 658942664 677739866 886535704 183687802 -784248291 -22550621 -938674499 637055091 -704750213 780395802 778342470 -999059668 -794361783 796469192 215667969 354336794 -60195289 -885080928 -290279020 201221317\r\n", "output": "inf"}, {"input": "0 -3 2143435 5\r\n-1 0 1 5 -11245\r\n", "output": "0"}, {"input": "123 -1 2143435 5\r\n-123 0 123 -5453 141245\r\n", "output": "0"}, {"input": "123 0 2143435 4\r\n5433 0 -123 -645\r\n", "output": "1"}, {"input": "11 0 2 5\r\n-1 0 1 5 -11245\r\n", "output": "0"}, {"input": "2 2 4 1\r\n2\r\n", "output": "1"}, {"input": "1 -2 1000000000 1\r\n0\r\n", "output": "30"}, {"input": "0 8 10 1\r\n5\r\n", "output": "inf"}, {"input": "-1000 0 10 1\r\n5\r\n", "output": "0"}, {"input": "0 2 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "0 8 5 1\r\n9\r\n", "output": "inf"}, {"input": "-10 1 5 1\r\n100\r\n", "output": "0"}, {"input": "123 -1 2143435 4\r\n54343 -13 6 123\r\n", "output": "inf"}, {"input": "-5 -1 10 1\r\n-5\r\n", "output": "inf"}, {"input": "2 0 1 1\r\n2\r\n", "output": "0"}, {"input": "0 5 8 1\r\n10\r\n", "output": "inf"}, {"input": "0 5 100 2\r\n34 56\r\n", "output": "inf"}, {"input": "15 -1 15 4\r\n15 -15 1 2\r\n", "output": "0"}, {"input": "10 -1 2 1\r\n1\r\n", "output": "0"}, {"input": "2 0 2 1\r\n2\r\n", "output": "inf"}, {"input": "4 0 4 1\r\n0\r\n", "output": "1"}, {"input": "10 10 10 1\r\n123\r\n", "output": "1"}, {"input": "2 2 4 1\r\n3\r\n", "output": "2"}, {"input": "0 1 1 1\r\n0\r\n", "output": "0"}, {"input": "3 2 30 1\r\n3\r\n", "output": "3"}, {"input": "1000000000 100000 1000000000 4\r\n5433 13 6 0\r\n", "output": "1"}, {"input": "-2 0 1 1\r\n1\r\n", "output": "0"}, {"input": "2 -1 10 1\r\n2\r\n", "output": "inf"}, {"input": "1 -1 2 1\r\n1\r\n", "output": "inf"}, {"input": "0 10 10 1\r\n2\r\n", "output": "inf"}, {"input": "0 35 2 1\r\n3\r\n", "output": "inf"}, {"input": "3 1 3 1\r\n5\r\n", "output": "inf"}, {"input": "3 2 3 4\r\n6 14 25 48\r\n", "output": "1"}, {"input": "0 69 12 1\r\n1\r\n", "output": "inf"}, {"input": "100 0 100000 1\r\n100\r\n", "output": "inf"}, {"input": "0 4 1000 3\r\n5 6 7\r\n", "output": "inf"}, {"input": "0 2 100 1\r\n5\r\n", "output": "inf"}, {"input": "3 2 24 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "0 4 1 1\r\n2\r\n", "output": "inf"}, {"input": "1 5 10000 1\r\n125\r\n", "output": "5"}, {"input": "2 -1 1 1\r\n1\r\n", "output": "0"}, {"input": "0 3 100 1\r\n5\r\n", "output": "inf"}, {"input": "0 3 3 1\r\n1\r\n", "output": "inf"}, {"input": "0 2 5 1\r\n1\r\n", "output": "inf"}, {"input": "5 -1 100 1\r\n5\r\n", "output": "inf"}, {"input": "-20 0 10 1\r\n0\r\n", "output": "0"}, {"input": "3 0 1 1\r\n3\r\n", "output": "0"}, {"input": "2 -1 3 1\r\n2\r\n", "output": "inf"}, {"input": "1 1 1000000000 1\r\n100\r\n", "output": "inf"}, {"input": "5 -1 3 1\r\n0\r\n", "output": "0"}, {"input": "0 5 10 1\r\n2\r\n", "output": "inf"}, {"input": "123 0 125 1\r\n123\r\n", "output": "inf"}, {"input": "2 -1 100 1\r\n2\r\n", "output": "inf"}, {"input": "5 2 100 1\r\n5\r\n", "output": "4"}, {"input": "-5 0 1 1\r\n1\r\n", "output": "0"}, {"input": "-3 0 1 1\r\n-3\r\n", "output": "0"}, {"input": "2 -2 10 1\r\n1\r\n", "output": "3"}, {"input": "0 2 30 4\r\n6 14 25 48\r\n", "output": "inf"}, {"input": "1 -1 1 1\r\n1\r\n", "output": "inf"}, {"input": "2 -1 6 1\r\n2\r\n", "output": "inf"}, {"input": "-3 1 100 1\r\n-3\r\n", "output": "0"}, {"input": "1 0 2 1\r\n1\r\n", "output": "inf"}, {"input": "1000000000 999999998 1000000000 1\r\n0\r\n", "output": "1"}, {"input": "1 0 2143435 4\r\n1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "-1000 0 100 1\r\n-1000\r\n", "output": "0"}, {"input": "100 10 2 1\r\n100\r\n", "output": "0"}, {"input": "-3 1 100 1\r\n3\r\n", "output": "inf"}, {"input": "123 -1 10000 1\r\n123\r\n", "output": "inf"}, {"input": "1 -1 2143435 4\r\n1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "5 1 5 5\r\n1 2 3 4 0\r\n", "output": "inf"}, {"input": "-100 -1 1 1\r\n1\r\n", "output": "0"}, {"input": "10 -1 3 2\r\n10 8\r\n", "output": "0"}, {"input": "-10 0 5 1\r\n0\r\n", "output": "0"}, {"input": "3 0 3 1\r\n0\r\n", "output": "1"}, {"input": "2 0 2 1\r\n-1\r\n", "output": "inf"}, {"input": "5 0 20 1\r\n5\r\n", "output": "inf"}, {"input": "-4 1 1 1\r\n0\r\n", "output": "0"}, {"input": "11 0 1111 1\r\n11\r\n", "output": "inf"}, {"input": "2 0 3 1\r\n2\r\n", "output": "inf"}, {"input": "-1 -1 2143435 4\r\n-1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "-100 0 50 1\r\n0\r\n", "output": "0"}, {"input": "5 1 2 1\r\n2\r\n", "output": "0"}, {"input": "3 0 3 1\r\n4\r\n", "output": "inf"}, {"input": "0 23 3 1\r\n3\r\n", "output": "inf"}, {"input": "-1000 0 100 1\r\n2\r\n", "output": "0"}, {"input": "1 -1 10 1\r\n1\r\n", "output": "inf"}]
false
stdio
null
true
868/C
868
C
Python 3
TESTS
27
452
512,000
32357058
# -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random """ created by shhuan at 2017/10/5 15:00 """ N, K = map(int, input().split()) problems = collections.defaultdict(set) for i in range(N): row = tuple([int(x) for x in input().split()]) k = sum(row) if k == 0: print('YES') exit(0) elif k < K: for i in range(K): if row[i] == 0: problems[i].add(row) if not problems: print('NO') exit(0) for p1 in problems[0]: p2s = [problems[i] for i in range(1, K) if p1[i] == 1] if p2s: p2 = p2s[0] for i in range(1, len(p2s)): p2 &= p2s[i] if p2: # print(p1, p2) print("YES") exit(0) print("NO")
143
109
4,812,800
187539064
import sys readline=sys.stdin.readline N,K=map(int,readline().split()) cnt=[0]*(1<<K) lst=[] for n in range(N): bit=0 for i,b in enumerate(list(map(int,readline().split()))): if b: bit|=1<<i cnt[bit]+=1 if cnt[bit]<=2: lst.append(bit) le=len(lst) ans="NO" if 0 in lst: ans="YES" for i in range(le): for j in range(i+1,le): if lst[i]&lst[j]==0: ans="YES" print(ans)
Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
256
Qualification Rounds
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset. k experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems. Determine if Snark and Philip can make an interesting problemset!
The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams. Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise.
Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
null
In the first example you can't make any interesting problemset, because the first team knows all problems. In the second example you can choose the first and the third problems.
[{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}]
1,500
["bitmasks", "brute force", "constructive algorithms", "dp"]
143
[{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n1 0 1\r\n0 1 1\r\n1 0 0\r\n1 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 0 1\r\n1 1 0 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 1 0\r\n0 0 0 0\r\n0 0 1 0\r\n1 0 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n0 0\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 1\r\n1 0 0\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 0\r\n1 1 0 0\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 1\r\n1\r\n1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n0 1 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 1\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 0 1\r\n1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 1 1 0\r\n1 1 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 0\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "6 3\r\n0 1 1\r\n1 0 1\r\n1 1 1\r\n0 1 0\r\n1 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n0 0 0 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 1 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "6 3\r\n1 0 0\r\n1 1 1\r\n1 1 1\r\n0 1 0\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 0 0\r\n1 1 1 1\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "1 3\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 1\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 1 0\r\n1 1 1\r\n0 0 1\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n1 1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n0 1 0 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n1 1 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 1 1\r\n1 0 1 0\r\n1 1 0 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 0 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n1 0\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 0 1\r\n0 0 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n1 1 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "8 4\r\n0 0 0 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 1\r\n1 1 1 0\r\n0 1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n0 0 0 1\r\n1 1 1 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n1 0 1\r\n0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 0 1\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 0 0\r\n1 0 1 0\r\n0 1 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 0 0 0\r\n1 0 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 0 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 0 1\r\n0 1 1 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 1 1\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 0\r\n", "output": "YES\r\n"}]
false
stdio
null
true
828/B
828
B
PyPy 3
TESTS
92
155
102,400
57581086
from sys import stdin,stdout n,m = (int(i) for i in stdin.readline().split()) x1,x2,y1,y2 = 10**6,0,0,0 c = 0 flag = False for i in range(n): st = stdin.readline() if st.count('B') > 0: c += st.count('B') if not(flag): y1 = i flag = True if x1 > st.index('B'): x1 = st.index('B') if x2 < st.rindex('B'): x2 = st.rindex('B')+1 y2 = i + 1 #print(x1,x2,y1,y2) height = y2 - y1 widht = x2 - x1 #print(widht,height) if c == 0: stdout.write('1') else: if max(widht,height) > min(n,m): stdout.write('-1') else: stdout.write(str(max(widht,height)**2-c))
128
46
0
162978311
n, m = map(int, input().split(' ')) x_min, x_max, y_min, y_max = n, -1, m, -1 B_cnt = 0 for i in range(n): s = input() for j in range(m): if s[j]=='B': B_cnt += 1 x_max, x_min = max(x_max, i), min(x_min, i) y_max, y_min = max(y_max, j), min(y_min, j) num = max((y_max-y_min+1), (x_max-x_min+1)) res = num*num-B_cnt if B_cnt == 0:print(1) elif (num>n or num>m):print(-1) else:print(res)
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Black Square
Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
null
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third example all cells are colored white, so it's sufficient to color any cell black.
[{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}]
1,300
["implementation"]
128
[{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "-1\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "2 4\r\nWWWW\r\nWBWW\r\n", "output": "0\r\n"}, {"input": "4 5\r\nWWWWW\r\nBBWWW\r\nBBWWW\r\nWWWWW\r\n", "output": "0\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "10 5\r\nWWWWB\r\nWWWWW\r\nWWWBB\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "12\r\n"}, {"input": "5 10\r\nWWWWWWWWWW\r\nWWWWBWBBWW\r\nWWWWWWWWWW\r\nWWWWBWWWWW\r\nWWWWWWBWWW\r\n", "output": "11\r\n"}, {"input": "20 10\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWBBWBWWWW\r\nWWBWWBWWWW\r\nWWWWBWWWWW\r\nWWWWBWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\n", "output": "9\r\n"}, {"input": "10 20\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWBW\r\nWWWWWWWWWWWWWWWWWBWW\r\nWWWWWWWWWWWWWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nWW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nWW\r\nWB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWB\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBW\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nBW\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nWW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBB\r\nWB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nWW\r\n", "output": "1\r\n"}, {"input": "1 2\r\nWB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nW\r\nW\r\n", "output": "1\r\n"}, {"input": "2 1\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "20 10\r\nWWBWWWBBWW\r\nWWWWWBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWBBBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWBWWWWWBWW\r\nWBWWBWWWBW\r\nWWBWBWWWWW\r\nWWWBWWBBWW\r\nWWBBWBWBWW\r\nBBWWWWWBWW\r\nWWBWWBBBWW\r\nWWWBWBBWWW\r\nWWWBBWBWWW\r\nWWWWWWWWWW\r\nWWWBWWWWWW\r\nWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "10 20\r\nWWWWWWWBWWWWWWWBWWWB\r\nWWWBWWWBWWWWWWWWWWWW\r\nBWWWWWWWWWWWWWWWWWBB\r\nWWWWWWBWWBWWBWWWBWWW\r\nWWWWWWWWBWWBWWWBWWWW\r\nWBWWWWWWWBWWWWWWWWWW\r\nWWWBWBWWBWWWWWBBWWWB\r\nWWBBWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWBWWWWBW\r\nWWWWWWWWWWWWBWWBWWWB\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "-1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "1 5\r\nWBBWW\r\n", "output": "-1\r\n"}, {"input": "20 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWBW\r\nWBB\r\nWWW\r\n", "output": "1\r\n"}, {"input": "4 6\r\nWWWWWW\r\nWWWBWW\r\nWWWWWB\r\nWWWWWW\r\n", "output": "7\r\n"}, {"input": "5 5\r\nWBWBW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "7\r\n"}, {"input": "3 3\r\nBBB\r\nBBB\r\nBBB\r\n", "output": "0\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWBWW\r\n", "output": "23\r\n"}, {"input": "5 4\r\nWWBW\r\nBWWB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "13\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWWW\r\nWBBW\r\n", "output": "12\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWBWW\r\n", "output": "34\r\n"}, {"input": "3 3\r\nBBW\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "3 3\r\nBWB\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "6 6\r\nWBWWWW\r\nBWWWBW\r\nWWWWWW\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "21\r\n"}, {"input": "3 3\r\nWWW\r\nWBW\r\nWWW\r\n", "output": "0\r\n"}, {"input": "3 3\r\nBBB\r\nWWW\r\nWWW\r\n", "output": "6\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWBWW\r\nWBBBW\r\nWWBWW\r\nWWBWW\r\n", "output": "18\r\n"}, {"input": "5 2\r\nWB\r\nWB\r\nWB\r\nWW\r\nWW\r\n", "output": "-1\r\n"}, {"input": "4 7\r\nBBBBBWW\r\nWWWWWWW\r\nWWWWWWW\r\nWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWBB\r\nWWWW\r\n", "output": "6\r\n"}, {"input": "4 4\r\nWWWW\r\nWBWW\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "2 5\r\nWWWWW\r\nBBBWW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWBW\r\nWWWWWW\r\nWWWWWW\r\nWWBWWW\r\n", "output": "33\r\n"}, {"input": "3 3\r\nWBW\r\nWBW\r\nWBW\r\n", "output": "6\r\n"}, {"input": "3 5\r\nWWBBB\r\nBWBBB\r\nWWBBB\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWB\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "22\r\n"}, {"input": "5 5\r\nBWWWB\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nBWWWW\r\n", "output": "22\r\n"}, {"input": "4 5\r\nWWWWW\r\nBWWWW\r\nBBBWW\r\nWWWWW\r\n", "output": "5\r\n"}, {"input": "4 4\r\nBBBB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "12\r\n"}, {"input": "4 6\r\nWWWWWW\r\nBWWWWW\r\nBWWWWW\r\nBBBBBB\r\n", "output": "-1\r\n"}, {"input": "3 6\r\nWWWWWW\r\nBBBWWW\r\nWWWWWW\r\n", "output": "6\r\n"}, {"input": "5 2\r\nWW\r\nBW\r\nBW\r\nBB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nBBBBB\r\nWWWWW\r\nWWWWW\r\n", "output": "20\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nWWWWB\r\nWBWWW\r\nWWWWW\r\n", "output": "14\r\n"}, {"input": "1 5\r\nWWBWW\r\n", "output": "0\r\n"}, {"input": "1 3\r\nBBB\r\n", "output": "-1\r\n"}, {"input": "2 4\r\nWWBW\r\nBWBW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nBBBBBB\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "30\r\n"}, {"input": "4 4\r\nWWWW\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWB\r\n", "output": "0\r\n"}, {"input": "5 1\r\nB\r\nB\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "2 3\r\nWBW\r\nWBW\r\n", "output": "2\r\n"}, {"input": "5 2\r\nWW\r\nWB\r\nWB\r\nWB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "23\r\n"}]
false
stdio
null
true
616/A
616
A
Python 3
TESTS
19
109
10,137,600
86735086
from sys import stdin,stdout # from collections import deque,Counter,defaultdict # from itertools import permutations,combinations,combinations_with_replacement # from operator import itemgetter # import heapq # from functools import reduce def ii():return int(stdin.readline()) def mi():return map(int,stdin.readline().split()) def li():return list(mi()) def si():return stdin.readline() s1 = si().rjust(10**6,'0') s2 = si().rjust(10**6,'0') if s1>s2: print('>') elif s1<s2: print('<') else: print('=')
120
46
3,584,000
176467571
a,b=input(),input() m=max(len(a),len(b)) a,b=a.zfill(m),b.zfill(m) print('>' if a>b else ('<' if a<b else '='))
Educational Codeforces Round 5
ICPC
2,016
2
256
Comparing Two Long Integers
You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. 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. Don't use the function input() in Python2 instead of it use the function raw_input().
The first line contains a non-negative integer a. The second line contains a non-negative integer b. The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits.
Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=".
null
null
[{"input": "9\n10", "output": "<"}, {"input": "11\n10", "output": ">"}, {"input": "00012345\n12345", "output": "="}, {"input": "0123\n9", "output": ">"}, {"input": "0123\n111", "output": ">"}]
900
["implementation", "strings"]
120
[{"input": "9\r\n10\r\n", "output": "<\r\n"}, {"input": "11\r\n10\r\n", "output": ">\r\n"}, {"input": "00012345\r\n12345\r\n", "output": "=\r\n"}, {"input": "0123\r\n9\r\n", "output": ">\r\n"}, {"input": "0123\r\n111\r\n", "output": ">\r\n"}, {"input": "9\r\n9\r\n", "output": "=\r\n"}, {"input": "0\r\n0000\r\n", "output": "=\r\n"}, {"input": "1213121\r\n1213121\r\n", "output": "=\r\n"}, {"input": "8631749422082281871941140403034638286979613893271246118706788645620907151504874585597378422393911017\r\n1460175633701201615285047975806206470993708143873675499262156511814213451040881275819636625899967479\r\n", "output": ">\r\n"}, {"input": "6421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798\r\n8\r\n", "output": ">\r\n"}, {"input": "9\r\n3549746075165939381145061479392284958612916596558639332310874529760172204736013341477640605383578772\r\n", "output": "<\r\n"}, {"input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": "=\r\n"}, {"input": "0000000001\r\n2\r\n", "output": "<\r\n"}, {"input": "1000000000000000000000000000000000\r\n1000000000000000000000000000000001\r\n", "output": "<\r\n"}, {"input": "123456123456123456123456123456123456123456123456123456123456123456\r\n123456123456123456123456123456123456123456123456123456123456123456123456123456\r\n", "output": "<\r\n"}, {"input": "1111111111111111111111111111111111111111\r\n2222222222222222222222222222222222222222\r\n", "output": "<\r\n"}, {"input": "123456789999999\r\n123456789999999\r\n", "output": "=\r\n"}, {"input": "111111111111111111111111111111\r\n222222222222222222222222222222\r\n", "output": "<\r\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111\r\n1111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": "=\r\n"}, {"input": "587345873489573457357834\r\n47957438573458347574375348\r\n", "output": "<\r\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333\r\n", "output": "<\r\n"}, {"input": "11111111111111111111111111111111111\r\n44444444444444444444444444444444444\r\n", "output": "<\r\n"}, {"input": "11111111111111111111111111111111111\r\n22222222222222222222222222222222222\r\n", "output": "<\r\n"}, {"input": "9999999999999999999999999999999999999999999999999999999999999999999\r\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999\r\n", "output": "<\r\n"}, {"input": "1\r\n2\r\n", "output": "<\r\n"}, {"input": "9\r\n0\r\n", "output": ">\r\n"}, {"input": "222222222222222222222222222222222222222222222222222222222\r\n22222222222222222222222222222222222222222222222222222222222\r\n", "output": "<\r\n"}, {"input": "66646464222222222222222222222222222222222222222222222222222222222222222\r\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": "<\r\n"}, {"input": "222222222222222222222222222222222222222222222222222\r\n111111111111111111111111111111111111111111111111111111111111111\r\n", "output": "<\r\n"}, {"input": "11111111111111111111111111111111111111\r\n44444444444444444444444444444444444444\r\n", "output": "<\r\n"}, {"input": "01\r\n2\r\n", "output": "<\r\n"}, {"input": "00\r\n01\r\n", "output": "<\r\n"}, {"input": "99999999999999999999999999999999999999999999999\r\n99999999999999999999999999999999999999999999999\r\n", "output": "=\r\n"}, {"input": "43278947323248843213443272432\r\n793439250984509434324323453435435\r\n", "output": "<\r\n"}, {"input": "0\r\n1\r\n", "output": "<\r\n"}, {"input": "010\r\n011\r\n", "output": "<\r\n"}, {"input": "999999999999999999999999999999999999999999999999\r\n999999999999999999999999999999999999999999999999\r\n", "output": "=\r\n"}, {"input": "0001001\r\n0001010\r\n", "output": "<\r\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111\r\n1111111111111111111111111111111111111111111111111111111111111\r\n", "output": "=\r\n"}, {"input": "00000\r\n00\r\n", "output": "=\r\n"}, {"input": "999999999999999999999999999\r\n999999999999999999999999999\r\n", "output": "=\r\n"}, {"input": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\r\n999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\r\n", "output": "=\r\n"}, {"input": "001\r\n000000000010\r\n", "output": "<\r\n"}, {"input": "01\r\n10\r\n", "output": "<\r\n"}, {"input": "555555555555555555555555555555555555555555555555555555555555\r\n555555555555555555555555555555555555555555555555555555555555\r\n", "output": "=\r\n"}, {"input": "5555555555555555555555555555555555555555555555555\r\n5555555555555555555555555555555555555555555555555\r\n", "output": "=\r\n"}, {"input": "01\r\n02\r\n", "output": "<\r\n"}, {"input": "001111\r\n0001111\r\n", "output": "=\r\n"}, {"input": "55555555555555555555555555555555555555555555555555\r\n55555555555555555555555555555555555555555555555555\r\n", "output": "=\r\n"}, {"input": "1029301293019283091283091283091280391283\r\n1029301293019283091283091283091280391283\r\n", "output": "=\r\n"}, {"input": "001\r\n2\r\n", "output": "<\r\n"}, {"input": "000000000\r\n000000000\r\n", "output": "=\r\n"}, {"input": "000000\r\n10\r\n", "output": "<\r\n"}, {"input": "000000000000000\r\n001\r\n", "output": "<\r\n"}, {"input": "0000001\r\n2\r\n", "output": "<\r\n"}, {"input": "0000\r\n123\r\n", "output": "<\r\n"}, {"input": "951\r\n960\r\n", "output": "<\r\n"}, {"input": "002\r\n0001\r\n", "output": ">\r\n"}, {"input": "0000001\r\n01\r\n", "output": "=\r\n"}, {"input": "99999999999999999999999999999999999999999999999999999999999999\r\n99999999999999999999999999999999999999999999999999999999999999\r\n", "output": "=\r\n"}, {"input": "12345678901234567890123456789012345678901234567890123456789012\r\n12345678901234567890123456789012345678901234567890123456789012\r\n", "output": "=\r\n"}, {"input": "02\r\n01\r\n", "output": ">\r\n"}, {"input": "00000111111\r\n00000110111\r\n", "output": ">\r\n"}, {"input": "0123\r\n123\r\n", "output": "=\r\n"}, {"input": "123771237912798378912\r\n91239712798379812897389123123123123\r\n", "output": "<\r\n"}, {"input": "00001\r\n002\r\n", "output": "<\r\n"}, {"input": "0000000000000000000000000000000000000000000000000000000000000\r\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n", "output": "=\r\n"}, {"input": "000000001\r\n00002\r\n", "output": "<\r\n"}, {"input": "00002\r\n00003\r\n", "output": "<\r\n"}, {"input": "000123456\r\n123457\r\n", "output": "<\r\n"}, {"input": "01\r\n00\r\n", "output": ">\r\n"}, {"input": "00\r\n0\r\n", "output": "=\r\n"}, {"input": "10\r\n11\r\n", "output": "<\r\n"}, {"input": "0011\r\n12\r\n", "output": "<\r\n"}, {"input": "00\r\n1\r\n", "output": "<\r\n"}, {"input": "0\r\n0\r\n", "output": "=\r\n"}, {"input": "00\r\n10\r\n", "output": "<\r\n"}, {"input": "011\r\n10\r\n", "output": ">\r\n"}, {"input": "00011111111111111111111111111111111111000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000011000\r\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112091\r\n", "output": "<\r\n"}, {"input": "0000001\r\n00\r\n", "output": ">\r\n"}, {"input": "01\r\n1\r\n", "output": "=\r\n"}, {"input": "010\r\n001\r\n", "output": ">\r\n"}, {"input": "100\r\n111\r\n", "output": "<\r\n"}, {"input": "1\r\n0\r\n", "output": ">\r\n"}, {"input": "000000\r\n000000000000000000000\r\n", "output": "=\r\n"}, {"input": "010101\r\n010101\r\n", "output": "=\r\n"}, {"input": "00000000000000000001111111111111111111111111111111111111111111111111111111\r\n11111111111111111111111\r\n", "output": ">\r\n"}, {"input": "0000000\r\n0\r\n", "output": "=\r\n"}, {"input": "187923712738712879387912839182381\r\n871279397127389781927389718923789178923897123\r\n", "output": "<\r\n"}, {"input": "0010\r\n030\r\n", "output": "<\r\n"}]
false
stdio
null
true
616/A
616
A
Python 3
TESTS
19
46
3,174,400
154828326
import sys input = sys.stdin.readline a,b=[input().rjust(10**6,'0') for i in range(2)] print ('>' if a > b else '<' if a<b else '=')
120
46
3,993,600
201632626
exec('a, b = '+ 2 * 'input().rjust(10 ** 6, "0"),') print('<>='[(a == b) + (a >= b)])
Educational Codeforces Round 5
ICPC
2,016
2
256
Comparing Two Long Integers
You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. 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. Don't use the function input() in Python2 instead of it use the function raw_input().
The first line contains a non-negative integer a. The second line contains a non-negative integer b. The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits.
Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=".
null
null
[{"input": "9\n10", "output": "<"}, {"input": "11\n10", "output": ">"}, {"input": "00012345\n12345", "output": "="}, {"input": "0123\n9", "output": ">"}, {"input": "0123\n111", "output": ">"}]
900
["implementation", "strings"]
120
[{"input": "9\r\n10\r\n", "output": "<\r\n"}, {"input": "11\r\n10\r\n", "output": ">\r\n"}, {"input": "00012345\r\n12345\r\n", "output": "=\r\n"}, {"input": "0123\r\n9\r\n", "output": ">\r\n"}, {"input": "0123\r\n111\r\n", "output": ">\r\n"}, {"input": "9\r\n9\r\n", "output": "=\r\n"}, {"input": "0\r\n0000\r\n", "output": "=\r\n"}, {"input": "1213121\r\n1213121\r\n", "output": "=\r\n"}, {"input": "8631749422082281871941140403034638286979613893271246118706788645620907151504874585597378422393911017\r\n1460175633701201615285047975806206470993708143873675499262156511814213451040881275819636625899967479\r\n", "output": ">\r\n"}, {"input": "6421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798\r\n8\r\n", "output": ">\r\n"}, {"input": "9\r\n3549746075165939381145061479392284958612916596558639332310874529760172204736013341477640605383578772\r\n", "output": "<\r\n"}, {"input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": "=\r\n"}, {"input": "0000000001\r\n2\r\n", "output": "<\r\n"}, {"input": "1000000000000000000000000000000000\r\n1000000000000000000000000000000001\r\n", "output": "<\r\n"}, {"input": "123456123456123456123456123456123456123456123456123456123456123456\r\n123456123456123456123456123456123456123456123456123456123456123456123456123456\r\n", "output": "<\r\n"}, {"input": "1111111111111111111111111111111111111111\r\n2222222222222222222222222222222222222222\r\n", "output": "<\r\n"}, {"input": "123456789999999\r\n123456789999999\r\n", "output": "=\r\n"}, {"input": "111111111111111111111111111111\r\n222222222222222222222222222222\r\n", "output": "<\r\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111\r\n1111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": "=\r\n"}, {"input": "587345873489573457357834\r\n47957438573458347574375348\r\n", "output": "<\r\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333\r\n", "output": "<\r\n"}, {"input": "11111111111111111111111111111111111\r\n44444444444444444444444444444444444\r\n", "output": "<\r\n"}, {"input": "11111111111111111111111111111111111\r\n22222222222222222222222222222222222\r\n", "output": "<\r\n"}, {"input": "9999999999999999999999999999999999999999999999999999999999999999999\r\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999\r\n", "output": "<\r\n"}, {"input": "1\r\n2\r\n", "output": "<\r\n"}, {"input": "9\r\n0\r\n", "output": ">\r\n"}, {"input": "222222222222222222222222222222222222222222222222222222222\r\n22222222222222222222222222222222222222222222222222222222222\r\n", "output": "<\r\n"}, {"input": "66646464222222222222222222222222222222222222222222222222222222222222222\r\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": "<\r\n"}, {"input": "222222222222222222222222222222222222222222222222222\r\n111111111111111111111111111111111111111111111111111111111111111\r\n", "output": "<\r\n"}, {"input": "11111111111111111111111111111111111111\r\n44444444444444444444444444444444444444\r\n", "output": "<\r\n"}, {"input": "01\r\n2\r\n", "output": "<\r\n"}, {"input": "00\r\n01\r\n", "output": "<\r\n"}, {"input": "99999999999999999999999999999999999999999999999\r\n99999999999999999999999999999999999999999999999\r\n", "output": "=\r\n"}, {"input": "43278947323248843213443272432\r\n793439250984509434324323453435435\r\n", "output": "<\r\n"}, {"input": "0\r\n1\r\n", "output": "<\r\n"}, {"input": "010\r\n011\r\n", "output": "<\r\n"}, {"input": "999999999999999999999999999999999999999999999999\r\n999999999999999999999999999999999999999999999999\r\n", "output": "=\r\n"}, {"input": "0001001\r\n0001010\r\n", "output": "<\r\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111\r\n1111111111111111111111111111111111111111111111111111111111111\r\n", "output": "=\r\n"}, {"input": "00000\r\n00\r\n", "output": "=\r\n"}, {"input": "999999999999999999999999999\r\n999999999999999999999999999\r\n", "output": "=\r\n"}, {"input": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\r\n999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\r\n", "output": "=\r\n"}, {"input": "001\r\n000000000010\r\n", "output": "<\r\n"}, {"input": "01\r\n10\r\n", "output": "<\r\n"}, {"input": "555555555555555555555555555555555555555555555555555555555555\r\n555555555555555555555555555555555555555555555555555555555555\r\n", "output": "=\r\n"}, {"input": "5555555555555555555555555555555555555555555555555\r\n5555555555555555555555555555555555555555555555555\r\n", "output": "=\r\n"}, {"input": "01\r\n02\r\n", "output": "<\r\n"}, {"input": "001111\r\n0001111\r\n", "output": "=\r\n"}, {"input": "55555555555555555555555555555555555555555555555555\r\n55555555555555555555555555555555555555555555555555\r\n", "output": "=\r\n"}, {"input": "1029301293019283091283091283091280391283\r\n1029301293019283091283091283091280391283\r\n", "output": "=\r\n"}, {"input": "001\r\n2\r\n", "output": "<\r\n"}, {"input": "000000000\r\n000000000\r\n", "output": "=\r\n"}, {"input": "000000\r\n10\r\n", "output": "<\r\n"}, {"input": "000000000000000\r\n001\r\n", "output": "<\r\n"}, {"input": "0000001\r\n2\r\n", "output": "<\r\n"}, {"input": "0000\r\n123\r\n", "output": "<\r\n"}, {"input": "951\r\n960\r\n", "output": "<\r\n"}, {"input": "002\r\n0001\r\n", "output": ">\r\n"}, {"input": "0000001\r\n01\r\n", "output": "=\r\n"}, {"input": "99999999999999999999999999999999999999999999999999999999999999\r\n99999999999999999999999999999999999999999999999999999999999999\r\n", "output": "=\r\n"}, {"input": "12345678901234567890123456789012345678901234567890123456789012\r\n12345678901234567890123456789012345678901234567890123456789012\r\n", "output": "=\r\n"}, {"input": "02\r\n01\r\n", "output": ">\r\n"}, {"input": "00000111111\r\n00000110111\r\n", "output": ">\r\n"}, {"input": "0123\r\n123\r\n", "output": "=\r\n"}, {"input": "123771237912798378912\r\n91239712798379812897389123123123123\r\n", "output": "<\r\n"}, {"input": "00001\r\n002\r\n", "output": "<\r\n"}, {"input": "0000000000000000000000000000000000000000000000000000000000000\r\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n", "output": "=\r\n"}, {"input": "000000001\r\n00002\r\n", "output": "<\r\n"}, {"input": "00002\r\n00003\r\n", "output": "<\r\n"}, {"input": "000123456\r\n123457\r\n", "output": "<\r\n"}, {"input": "01\r\n00\r\n", "output": ">\r\n"}, {"input": "00\r\n0\r\n", "output": "=\r\n"}, {"input": "10\r\n11\r\n", "output": "<\r\n"}, {"input": "0011\r\n12\r\n", "output": "<\r\n"}, {"input": "00\r\n1\r\n", "output": "<\r\n"}, {"input": "0\r\n0\r\n", "output": "=\r\n"}, {"input": "00\r\n10\r\n", "output": "<\r\n"}, {"input": "011\r\n10\r\n", "output": ">\r\n"}, {"input": "00011111111111111111111111111111111111000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000011000\r\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112091\r\n", "output": "<\r\n"}, {"input": "0000001\r\n00\r\n", "output": ">\r\n"}, {"input": "01\r\n1\r\n", "output": "=\r\n"}, {"input": "010\r\n001\r\n", "output": ">\r\n"}, {"input": "100\r\n111\r\n", "output": "<\r\n"}, {"input": "1\r\n0\r\n", "output": ">\r\n"}, {"input": "000000\r\n000000000000000000000\r\n", "output": "=\r\n"}, {"input": "010101\r\n010101\r\n", "output": "=\r\n"}, {"input": "00000000000000000001111111111111111111111111111111111111111111111111111111\r\n11111111111111111111111\r\n", "output": ">\r\n"}, {"input": "0000000\r\n0\r\n", "output": "=\r\n"}, {"input": "187923712738712879387912839182381\r\n871279397127389781927389718923789178923897123\r\n", "output": "<\r\n"}, {"input": "0010\r\n030\r\n", "output": "<\r\n"}]
false
stdio
null
true
808/D
808
D
PyPy 3
TESTS
33
389
33,382,400
77057737
# | # _` | __ \ _` | __| _ \ __ \ _` | _` | # ( | | | ( | ( ( | | | ( | ( | # \__,_| _| _| \__,_| \___| \___/ _| _| \__,_| \__,_| import sys def read_line(): return sys.stdin.readline()[:-1] def read_int(): return int(sys.stdin.readline()) def read_int_line(): return [int(v) for v in sys.stdin.readline().split()] n = read_int() a = read_int_line() d = {} d[0] = n+2 pref = [0]*(n+1) for i in range(1,n+1): pref[i]=pref[i-1]+a[i-1] if a[i-1] not in d: d[a[i-1]] = i tot = pref[n] req = tot//2 f = False for i in range(1,n+1): if pref[i]>req: if pref[i]-req in d: if d[pref[i]-req] < i: f = True a = a[::-1] d = {} d[0] = n+2 pref = [0]*(n+1) for i in range(1,n+1): pref[i]=pref[i-1]+a[i-1] if a[i-1] not in d: d[a[i-1]] = i tot = pref[n] req = tot//2 f1 = False for i in range(1,n+1): if pref[i]>req: if pref[i]-req in d: if d[pref[i]-req] < i: f1 = True if (f or f1) and tot%2==0: print("YES") else: print("NO")
115
109
17,920,000
166893879
''' https://codeforces.com/problemset/problem/808/D 输入 n(≤1e5) 和长为 n 的数组 a(1≤a[i]≤1e9)。 你可以选择一个 a[i],将其移除并插入到 a 的任意位置。 你能否在执行至多一次上述操作的限制下,将 a 划分成左右两部分,且这两部分的元素和相等? 能则输出 YES,不能则输出 NO。 输入 3 1 3 2 输出 YES 解释 把 3 移到末尾,得到 [1,2,3],sum([1,2]) = sum([3]) = 3 输入 5 1 2 3 4 5 输出 NO 输入 5 2 2 3 4 5 输出 YES 解释 把 4 往左移一位,得到 [2,2,4,3,5],sum([2,2,4]) = sum([3,5]) = 8 ''' def solve(a): pre = 0 dic = set() for v in a: pre += v if pre == s - pre: return True if (2 * pre - s) & 1 == 0 and (2 * pre - s) // 2 in dic: return True dic.add(v) return False n = int(input()) a = list(map(int, input().split())) s = sum(a) if s & 1: print("NO") else: print("YES" if solve(a) or solve(a[::-1]) else "NO")
Educational Codeforces Round 21
ICPC
2,017
2
256
Array Division
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position). Inserting an element in the same position he was erased from is also considered moving. Can Vasya divide the array after choosing the right element to move and its new position?
The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array. The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array.
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
null
In the first example Vasya can move the second element to the end of the array. In the second example no move can make the division possible. In the third example Vasya can move the fourth element by one position to the left.
[{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}]
1,900
["binary search", "data structures", "implementation"]
115
[{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "output": "NO\r\n"}, {"input": "8\r\n9 5 5 10 4 9 5 8\r\n", "output": "NO\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "YES\r\n"}, {"input": "15\r\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8\r\n", "output": "NO\r\n"}, {"input": "20\r\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13\r\n", "output": "NO\r\n"}, {"input": "20\r\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 10 6\r\n", "output": "NO\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": "YES\r\n"}, {"input": "100\r\n89 38 63 73 77 4 99 74 30 5 69 57 97 37 88 71 36 59 19 63 46 20 33 58 61 98 100 31 33 53 99 96 34 17 44 95 54 52 22 77 67 88 20 88 26 43 12 23 96 94 14 7 57 86 56 54 32 8 3 43 97 56 74 22 5 100 12 60 93 12 44 68 31 63 7 71 21 29 19 38 50 47 97 43 50 59 88 40 51 61 20 68 32 66 70 48 19 55 91 53\r\n", "output": "NO\r\n"}, {"input": "100\r\n80 100 88 52 25 87 85 8 92 62 35 66 74 39 58 41 55 53 23 73 90 72 36 44 97 67 16 54 3 8 25 34 84 47 77 39 93 19 49 20 29 44 21 48 21 56 82 59 8 31 94 95 84 54 72 20 95 91 85 1 67 19 76 28 31 63 87 98 55 28 16 20 36 91 93 39 94 69 80 97 100 96 68 26 91 45 22 84 20 36 20 92 53 75 58 51 60 26 76 25\r\n", "output": "NO\r\n"}, {"input": "100\r\n27 95 57 29 91 85 83 36 72 86 39 5 79 61 78 93 100 97 73 23 82 66 41 92 38 92 100 96 48 56 66 47 5 32 69 13 95 23 46 62 99 83 57 66 98 82 81 57 37 37 81 64 45 76 72 43 99 76 86 22 37 39 93 80 99 36 53 83 3 32 52 9 78 34 47 100 33 72 19 40 29 56 77 32 79 72 15 88 100 98 56 50 22 81 88 92 58 70 21 19\r\n", "output": "NO\r\n"}, {"input": "100\r\n35 31 83 11 7 94 57 58 30 26 2 99 33 58 98 6 3 52 13 66 21 53 26 94 100 5 1 3 91 13 97 49 86 25 63 90 88 98 57 57 34 81 32 16 65 94 59 83 44 14 46 18 28 89 75 95 87 57 52 18 46 80 31 43 38 54 69 75 82 9 64 96 75 40 96 52 67 85 86 38 95 55 16 57 17 20 22 7 63 3 12 16 42 87 46 12 51 95 67 80\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 4 3 100 100 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n6 100 100 3 4 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n4 2 3 7 1 1\r\n", "output": "YES\r\n"}, {"input": "4\r\n6 1 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n228 114 114\r\n", "output": "YES\r\n"}, {"input": "3\r\n229 232 444\r\n", "output": "NO\r\n"}, {"input": "3\r\n322 324 555\r\n", "output": "NO\r\n"}, {"input": "3\r\n69 34 5\r\n", "output": "NO\r\n"}, {"input": "6\r\n5 4 1 2 2 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n545 237 546\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 3 1 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 2 10 2 2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n5 4 6 5 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 6 1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 1 8 5 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n73 67 16 51 56 71 37 49 90 6\r\n", "output": "NO\r\n"}, {"input": "1\r\n10\r\n", "output": "NO\r\n"}, {"input": "1\r\n1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n8 2 7 5 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n2\r\n", "output": "NO\r\n"}, {"input": "16\r\n9 10 2 1 6 7 6 5 8 3 2 10 8 4 9 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4\r\n", "output": "YES\r\n"}, {"input": "19\r\n9 9 3 2 4 5 5 7 8 10 8 10 1 2 2 6 5 3 3\r\n", "output": "NO\r\n"}, {"input": "11\r\n7 2 1 8 8 2 4 10 8 7 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n10 20 30 40 99 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n3 7 9 2 10 1 9 6 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n9 3\r\n", "output": "NO\r\n"}, {"input": "7\r\n1 2 3 12 1 2 3\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 4 4 5 8 5\r\n", "output": "YES\r\n"}, {"input": "18\r\n2 10 3 6 6 6 10 8 8 1 10 9 9 3 1 9 7 4\r\n", "output": "YES\r\n"}, {"input": "20\r\n9 6 6 10 4 4 8 7 4 10 10 2 10 5 9 5 3 10 1 9\r\n", "output": "NO\r\n"}, {"input": "12\r\n3 8 10 2 4 4 6 9 5 10 10 3\r\n", "output": "YES\r\n"}, {"input": "11\r\n9 2 7 7 7 3 7 5 4 10 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 4 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n7 1\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 5 6 7 6\r\n", "output": "YES\r\n"}, {"input": "11\r\n4 3 10 3 7 8 4 9 2 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n705032704 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 5 6 8 3 1 7 3\r\n", "output": "YES\r\n"}, {"input": "20\r\n8 6 3 6 3 5 10 2 6 1 7 6 9 10 8 3 5 9 3 8\r\n", "output": "YES\r\n"}, {"input": "11\r\n2 4 8 3 4 7 9 10 5 3 3\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 4 2 24 6 4 2\r\n", "output": "YES\r\n"}, {"input": "17\r\n7 1 1 1 8 9 1 10 8 8 7 9 7 9 1 6 5\r\n", "output": "NO\r\n"}, {"input": "7\r\n7 10 1 2 6 2 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 10 40 10 10\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 3 13\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 10 2 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n7 4 5 62 20 20 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n1 5 2 20 10 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n5 6\r\n", "output": "NO\r\n"}, {"input": "14\r\n5 2 9 7 5 8 3 2 2 4 9 1 3 10\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 2 2 5 5\r\n", "output": "NO\r\n"}, {"input": "11\r\n1 1 1 1 1 10 1 1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "9\r\n8 4 13 19 11 1 8 2 8\r\n", "output": "YES\r\n"}, {"input": "6\r\n14 16 14 14 15 11\r\n", "output": "YES\r\n"}, {"input": "9\r\n14 19 1 13 11 3 1 1 7\r\n", "output": "YES\r\n"}, {"input": "6\r\n16 13 3 7 4 15\r\n", "output": "YES\r\n"}, {"input": "4\r\n11 7 12 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 1 3 6 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 4 8 11 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 10 3 4\r\n", "output": "YES\r\n"}, {"input": "6\r\n8 15 12 14 15 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 4 4 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 3 1 6 4\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 12 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 4 13\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1 1 1 1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n19 6 5 13 6 13\r\n", "output": "YES\r\n"}, {"input": "8\r\n2 2 2 5 1 2 3 3\r\n", "output": "YES\r\n"}]
false
stdio
null
true
808/D
808
D
Python 3
TESTS
54
421
9,625,600
50763092
n = int(input()) l = input() a = [] yes = False for i in l.split(): a.append(int(i)) x = 0 b = [] ma = [] mb = [] for i in range(len(a)): x += a[i] b.append(x) if not(ma == []): if ma[-1] < a[i]: ma.append(a[i]) else: ma += [ma[-1]] else: ma += [a[0]] if not(mb == []): if mb[-1] < a[n-i-1]: mb.append(a[n-i-1]) else: mb += [mb[-1]] else: mb += [a[-1]] if x%2 == 0: half = x/2 for i in range(n): num = b[i] if num == half: yes = True break elif num > half and num - ma[i] <= half: for j in range(0, i): if num - a[j] == half: yes = True break elif num < half and num + mb[i] >= half: for j in range(i+2, n): if num + a[j] == half: yes = True break if yes == True: break else: yes = False if yes: print("YES") else: print("NO")
115
124
18,841,600
166882089
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 def solve(n, a): s = sum(a) if s & 1 or n == 1: return print('NO') half = s // 2 def judge(a): pre = set() p = 0 for i in a: pre.add(i) p += i if p == half: return True elif p > half: if (p - half) in pre: return True return False print('YES' if judge(a) or judge(a[::-1]) else 'NO') if __name__ == '__main__': n = int(input()) a = list(map(int, input().split())) solve(n, a)
Educational Codeforces Round 21
ICPC
2,017
2
256
Array Division
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position). Inserting an element in the same position he was erased from is also considered moving. Can Vasya divide the array after choosing the right element to move and its new position?
The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array. The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array.
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
null
In the first example Vasya can move the second element to the end of the array. In the second example no move can make the division possible. In the third example Vasya can move the fourth element by one position to the left.
[{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}]
1,900
["binary search", "data structures", "implementation"]
115
[{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "output": "NO\r\n"}, {"input": "8\r\n9 5 5 10 4 9 5 8\r\n", "output": "NO\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "YES\r\n"}, {"input": "15\r\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8\r\n", "output": "NO\r\n"}, {"input": "20\r\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13\r\n", "output": "NO\r\n"}, {"input": "20\r\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 10 6\r\n", "output": "NO\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": "YES\r\n"}, {"input": "100\r\n89 38 63 73 77 4 99 74 30 5 69 57 97 37 88 71 36 59 19 63 46 20 33 58 61 98 100 31 33 53 99 96 34 17 44 95 54 52 22 77 67 88 20 88 26 43 12 23 96 94 14 7 57 86 56 54 32 8 3 43 97 56 74 22 5 100 12 60 93 12 44 68 31 63 7 71 21 29 19 38 50 47 97 43 50 59 88 40 51 61 20 68 32 66 70 48 19 55 91 53\r\n", "output": "NO\r\n"}, {"input": "100\r\n80 100 88 52 25 87 85 8 92 62 35 66 74 39 58 41 55 53 23 73 90 72 36 44 97 67 16 54 3 8 25 34 84 47 77 39 93 19 49 20 29 44 21 48 21 56 82 59 8 31 94 95 84 54 72 20 95 91 85 1 67 19 76 28 31 63 87 98 55 28 16 20 36 91 93 39 94 69 80 97 100 96 68 26 91 45 22 84 20 36 20 92 53 75 58 51 60 26 76 25\r\n", "output": "NO\r\n"}, {"input": "100\r\n27 95 57 29 91 85 83 36 72 86 39 5 79 61 78 93 100 97 73 23 82 66 41 92 38 92 100 96 48 56 66 47 5 32 69 13 95 23 46 62 99 83 57 66 98 82 81 57 37 37 81 64 45 76 72 43 99 76 86 22 37 39 93 80 99 36 53 83 3 32 52 9 78 34 47 100 33 72 19 40 29 56 77 32 79 72 15 88 100 98 56 50 22 81 88 92 58 70 21 19\r\n", "output": "NO\r\n"}, {"input": "100\r\n35 31 83 11 7 94 57 58 30 26 2 99 33 58 98 6 3 52 13 66 21 53 26 94 100 5 1 3 91 13 97 49 86 25 63 90 88 98 57 57 34 81 32 16 65 94 59 83 44 14 46 18 28 89 75 95 87 57 52 18 46 80 31 43 38 54 69 75 82 9 64 96 75 40 96 52 67 85 86 38 95 55 16 57 17 20 22 7 63 3 12 16 42 87 46 12 51 95 67 80\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 4 3 100 100 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n6 100 100 3 4 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n4 2 3 7 1 1\r\n", "output": "YES\r\n"}, {"input": "4\r\n6 1 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n228 114 114\r\n", "output": "YES\r\n"}, {"input": "3\r\n229 232 444\r\n", "output": "NO\r\n"}, {"input": "3\r\n322 324 555\r\n", "output": "NO\r\n"}, {"input": "3\r\n69 34 5\r\n", "output": "NO\r\n"}, {"input": "6\r\n5 4 1 2 2 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n545 237 546\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 3 1 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 2 10 2 2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n5 4 6 5 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 6 1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 1 8 5 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n73 67 16 51 56 71 37 49 90 6\r\n", "output": "NO\r\n"}, {"input": "1\r\n10\r\n", "output": "NO\r\n"}, {"input": "1\r\n1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n8 2 7 5 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n2\r\n", "output": "NO\r\n"}, {"input": "16\r\n9 10 2 1 6 7 6 5 8 3 2 10 8 4 9 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4\r\n", "output": "YES\r\n"}, {"input": "19\r\n9 9 3 2 4 5 5 7 8 10 8 10 1 2 2 6 5 3 3\r\n", "output": "NO\r\n"}, {"input": "11\r\n7 2 1 8 8 2 4 10 8 7 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n10 20 30 40 99 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n3 7 9 2 10 1 9 6 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n9 3\r\n", "output": "NO\r\n"}, {"input": "7\r\n1 2 3 12 1 2 3\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 4 4 5 8 5\r\n", "output": "YES\r\n"}, {"input": "18\r\n2 10 3 6 6 6 10 8 8 1 10 9 9 3 1 9 7 4\r\n", "output": "YES\r\n"}, {"input": "20\r\n9 6 6 10 4 4 8 7 4 10 10 2 10 5 9 5 3 10 1 9\r\n", "output": "NO\r\n"}, {"input": "12\r\n3 8 10 2 4 4 6 9 5 10 10 3\r\n", "output": "YES\r\n"}, {"input": "11\r\n9 2 7 7 7 3 7 5 4 10 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 4 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n7 1\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 5 6 7 6\r\n", "output": "YES\r\n"}, {"input": "11\r\n4 3 10 3 7 8 4 9 2 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n705032704 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 5 6 8 3 1 7 3\r\n", "output": "YES\r\n"}, {"input": "20\r\n8 6 3 6 3 5 10 2 6 1 7 6 9 10 8 3 5 9 3 8\r\n", "output": "YES\r\n"}, {"input": "11\r\n2 4 8 3 4 7 9 10 5 3 3\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 4 2 24 6 4 2\r\n", "output": "YES\r\n"}, {"input": "17\r\n7 1 1 1 8 9 1 10 8 8 7 9 7 9 1 6 5\r\n", "output": "NO\r\n"}, {"input": "7\r\n7 10 1 2 6 2 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 10 40 10 10\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 3 13\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 10 2 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n7 4 5 62 20 20 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n1 5 2 20 10 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n5 6\r\n", "output": "NO\r\n"}, {"input": "14\r\n5 2 9 7 5 8 3 2 2 4 9 1 3 10\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 2 2 5 5\r\n", "output": "NO\r\n"}, {"input": "11\r\n1 1 1 1 1 10 1 1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "9\r\n8 4 13 19 11 1 8 2 8\r\n", "output": "YES\r\n"}, {"input": "6\r\n14 16 14 14 15 11\r\n", "output": "YES\r\n"}, {"input": "9\r\n14 19 1 13 11 3 1 1 7\r\n", "output": "YES\r\n"}, {"input": "6\r\n16 13 3 7 4 15\r\n", "output": "YES\r\n"}, {"input": "4\r\n11 7 12 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 1 3 6 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 4 8 11 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 10 3 4\r\n", "output": "YES\r\n"}, {"input": "6\r\n8 15 12 14 15 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 4 4 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 3 1 6 4\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 12 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 4 13\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1 1 1 1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n19 6 5 13 6 13\r\n", "output": "YES\r\n"}, {"input": "8\r\n2 2 2 5 1 2 3 3\r\n", "output": "YES\r\n"}]
false
stdio
null
true
828/B
828
B
PyPy 3
TESTS
50
156
1,843,200
69073928
#!/usr/bin/env python3 # -*- coding: utf-8 -*- n,m=map(int,input().split()) a=[] for i in range(n): t=input() a.append(t) L=m R=0 U=n D=0 for i in range(n): for j in range(m): if a[i][j]=='B': L=min(L,j) R=max(R,j) U=min(U,i) D=max(D,i) len=D-U+1 wid=R-L+1 subL=(U-0)+(n-D-1) subW=(L-0)+(m-R-1) flag=1 if len>wid: sub=len-wid if sub<=L: L-=sub else: sub-=L L=0 if sub<=(m-R-1): R+=sub else: flag=0 elif len<wid: sub=wid-len if sub<=U: U-=sub else: sub-=U U=0 if sub<=(n-D-1): D+=sub else: flag=0 if flag: if U==n and L==m: U=0 L=0 ans=0 i=U while i<=D: j=L while j<=R: if a[i][j]=='W': ans+=1 j+=1 i+=1 print(ans) else: print(-1)
128
46
0
167514035
n, m = map(int, input().split(' ')) min_j, max_j, min_i, max_i = m, -1, n, -1 count = 0 for i in range(n): s = input() for j in range(m): if s[j]=='B': count += 1 min_j = min(min_j, j) max_j = max(max_j, j) min_i = min(min_i, i) max_i = max(max_i, i) num = max(max_j-min_j+1, max_i-min_i+1) if num>n or num>m: print(-1) elif count==0: print(1) else: need = num*num - count print(need)
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Black Square
Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
null
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third example all cells are colored white, so it's sufficient to color any cell black.
[{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}]
1,300
["implementation"]
128
[{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "-1\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "2 4\r\nWWWW\r\nWBWW\r\n", "output": "0\r\n"}, {"input": "4 5\r\nWWWWW\r\nBBWWW\r\nBBWWW\r\nWWWWW\r\n", "output": "0\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "10 5\r\nWWWWB\r\nWWWWW\r\nWWWBB\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "12\r\n"}, {"input": "5 10\r\nWWWWWWWWWW\r\nWWWWBWBBWW\r\nWWWWWWWWWW\r\nWWWWBWWWWW\r\nWWWWWWBWWW\r\n", "output": "11\r\n"}, {"input": "20 10\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWBBWBWWWW\r\nWWBWWBWWWW\r\nWWWWBWWWWW\r\nWWWWBWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\n", "output": "9\r\n"}, {"input": "10 20\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWBW\r\nWWWWWWWWWWWWWWWWWBWW\r\nWWWWWWWWWWWWWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nWW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nWW\r\nWB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWB\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBW\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nBW\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nWW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBB\r\nWB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nWW\r\n", "output": "1\r\n"}, {"input": "1 2\r\nWB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nW\r\nW\r\n", "output": "1\r\n"}, {"input": "2 1\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "20 10\r\nWWBWWWBBWW\r\nWWWWWBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWBBBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWBWWWWWBWW\r\nWBWWBWWWBW\r\nWWBWBWWWWW\r\nWWWBWWBBWW\r\nWWBBWBWBWW\r\nBBWWWWWBWW\r\nWWBWWBBBWW\r\nWWWBWBBWWW\r\nWWWBBWBWWW\r\nWWWWWWWWWW\r\nWWWBWWWWWW\r\nWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "10 20\r\nWWWWWWWBWWWWWWWBWWWB\r\nWWWBWWWBWWWWWWWWWWWW\r\nBWWWWWWWWWWWWWWWWWBB\r\nWWWWWWBWWBWWBWWWBWWW\r\nWWWWWWWWBWWBWWWBWWWW\r\nWBWWWWWWWBWWWWWWWWWW\r\nWWWBWBWWBWWWWWBBWWWB\r\nWWBBWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWBWWWWBW\r\nWWWWWWWWWWWWBWWBWWWB\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "-1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "1 5\r\nWBBWW\r\n", "output": "-1\r\n"}, {"input": "20 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWBW\r\nWBB\r\nWWW\r\n", "output": "1\r\n"}, {"input": "4 6\r\nWWWWWW\r\nWWWBWW\r\nWWWWWB\r\nWWWWWW\r\n", "output": "7\r\n"}, {"input": "5 5\r\nWBWBW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "7\r\n"}, {"input": "3 3\r\nBBB\r\nBBB\r\nBBB\r\n", "output": "0\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWBWW\r\n", "output": "23\r\n"}, {"input": "5 4\r\nWWBW\r\nBWWB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "13\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWWW\r\nWBBW\r\n", "output": "12\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWBWW\r\n", "output": "34\r\n"}, {"input": "3 3\r\nBBW\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "3 3\r\nBWB\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "6 6\r\nWBWWWW\r\nBWWWBW\r\nWWWWWW\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "21\r\n"}, {"input": "3 3\r\nWWW\r\nWBW\r\nWWW\r\n", "output": "0\r\n"}, {"input": "3 3\r\nBBB\r\nWWW\r\nWWW\r\n", "output": "6\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWBWW\r\nWBBBW\r\nWWBWW\r\nWWBWW\r\n", "output": "18\r\n"}, {"input": "5 2\r\nWB\r\nWB\r\nWB\r\nWW\r\nWW\r\n", "output": "-1\r\n"}, {"input": "4 7\r\nBBBBBWW\r\nWWWWWWW\r\nWWWWWWW\r\nWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWBB\r\nWWWW\r\n", "output": "6\r\n"}, {"input": "4 4\r\nWWWW\r\nWBWW\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "2 5\r\nWWWWW\r\nBBBWW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWBW\r\nWWWWWW\r\nWWWWWW\r\nWWBWWW\r\n", "output": "33\r\n"}, {"input": "3 3\r\nWBW\r\nWBW\r\nWBW\r\n", "output": "6\r\n"}, {"input": "3 5\r\nWWBBB\r\nBWBBB\r\nWWBBB\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWB\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "22\r\n"}, {"input": "5 5\r\nBWWWB\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nBWWWW\r\n", "output": "22\r\n"}, {"input": "4 5\r\nWWWWW\r\nBWWWW\r\nBBBWW\r\nWWWWW\r\n", "output": "5\r\n"}, {"input": "4 4\r\nBBBB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "12\r\n"}, {"input": "4 6\r\nWWWWWW\r\nBWWWWW\r\nBWWWWW\r\nBBBBBB\r\n", "output": "-1\r\n"}, {"input": "3 6\r\nWWWWWW\r\nBBBWWW\r\nWWWWWW\r\n", "output": "6\r\n"}, {"input": "5 2\r\nWW\r\nBW\r\nBW\r\nBB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nBBBBB\r\nWWWWW\r\nWWWWW\r\n", "output": "20\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nWWWWB\r\nWBWWW\r\nWWWWW\r\n", "output": "14\r\n"}, {"input": "1 5\r\nWWBWW\r\n", "output": "0\r\n"}, {"input": "1 3\r\nBBB\r\n", "output": "-1\r\n"}, {"input": "2 4\r\nWWBW\r\nBWBW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nBBBBBB\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "30\r\n"}, {"input": "4 4\r\nWWWW\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWB\r\n", "output": "0\r\n"}, {"input": "5 1\r\nB\r\nB\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "2 3\r\nWBW\r\nWBW\r\n", "output": "2\r\n"}, {"input": "5 2\r\nWW\r\nWB\r\nWB\r\nWB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "23\r\n"}]
false
stdio
null
true
895/A
895
A
Python 3
TESTS
51
139
6,860,800
32759875
n=int(input()) vals=list(map(int,input().split())) print(min([360]+[abs(360-2*sum(vals[j:j+i])) for i in range(n//2+1) for j in range(n)]))
93
46
0
168430109
n = int(input()) l = list(map(int,input().split())) l1 = [] for j in range(n): tot=0 i = j-1 while i>-2: i+=1 tot += l[i] if tot>=180: if (abs(180-tot))>(abs(180-(tot-l[i]))): tot-=l[i] break if i==n-1: i=-1 l1.append(abs(180-tot)) final = min(l1) print(2*final)
Codeforces Round 448 (Div. 2)
CF
2,017
1
256
Pizza Separation
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut. The second line contains n integers ai (1 ≤ ai ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
null
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0. Picture explaning fourth sample: Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
1,200
["brute force", "implementation"]
93
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", "output": "0\r\n"}, {"input": "3\r\n120 120 120\r\n", "output": "120\r\n"}, {"input": "5\r\n110 90 70 50 40\r\n", "output": "40\r\n"}, {"input": "2\r\n170 190\r\n", "output": "20\r\n"}, {"input": "15\r\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10\r\n", "output": "10\r\n"}, {"input": "5\r\n30 60 180 60 30\r\n", "output": "0\r\n"}, {"input": "2\r\n359 1\r\n", "output": "358\r\n"}, {"input": "5\r\n100 100 30 100 30\r\n", "output": "40\r\n"}, {"input": "5\r\n36 34 35 11 244\r\n", "output": "128\r\n"}, {"input": "5\r\n96 94 95 71 4\r\n", "output": "18\r\n"}, {"input": "2\r\n85 275\r\n", "output": "190\r\n"}, {"input": "3\r\n281 67 12\r\n", "output": "202\r\n"}, {"input": "5\r\n211 113 25 9 2\r\n", "output": "62\r\n"}, {"input": "13\r\n286 58 6 1 1 1 1 1 1 1 1 1 1\r\n", "output": "212\r\n"}, {"input": "15\r\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "20\r\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "92\r\n"}, {"input": "50\r\n148 53 32 11 4 56 8 2 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "3\r\n1 1 358\r\n", "output": "356\r\n"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341\r\n", "output": "322\r\n"}, {"input": "33\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 328\r\n", "output": "296\r\n"}, {"input": "70\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 291\r\n", "output": "222\r\n"}, {"input": "130\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231\r\n", "output": "102\r\n"}, {"input": "200\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 161\r\n", "output": "0\r\n"}, {"input": "222\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 139\r\n", "output": "0\r\n"}, {"input": "10\r\n8 3 11 4 1 10 10 1 8 304\r\n", "output": "248\r\n"}, {"input": "12\r\n8 7 7 3 11 2 10 1 10 8 10 283\r\n", "output": "206\r\n"}, {"input": "13\r\n10 8 9 10 5 9 4 1 10 11 1 7 275\r\n", "output": "190\r\n"}, {"input": "14\r\n1 6 3 11 9 5 9 8 5 6 7 3 7 280\r\n", "output": "200\r\n"}, {"input": "15\r\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275\r\n", "output": "190\r\n"}, {"input": "30\r\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189\r\n", "output": "18\r\n"}, {"input": "70\r\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "29\r\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189\r\n", "output": "18\r\n"}, {"input": "35\r\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168\r\n", "output": "0\r\n"}, {"input": "60\r\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5\r\n", "output": "0\r\n"}, {"input": "71\r\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "63\r\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "81\r\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 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": "47\r\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68\r\n", "output": "0\r\n"}, {"input": "100\r\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "120\r\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 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 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": "200\r\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "220\r\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "6\r\n27 15 28 34 41 215\r\n", "output": "70\r\n"}, {"input": "7\r\n41 38 41 31 22 41 146\r\n", "output": "14\r\n"}, {"input": "8\r\n24 27 34 23 29 23 30 170\r\n", "output": "20\r\n"}, {"input": "9\r\n11 11 20 20 33 32 35 26 172\r\n", "output": "6\r\n"}, {"input": "10\r\n36 13 28 13 33 34 23 25 34 121\r\n", "output": "0\r\n"}, {"input": "11\r\n19 37 13 41 37 15 32 12 19 35 100\r\n", "output": "10\r\n"}, {"input": "12\r\n37 25 34 38 21 24 34 38 11 29 28 41\r\n", "output": "2\r\n"}, {"input": "13\r\n24 40 20 26 25 29 39 29 35 28 19 18 28\r\n", "output": "2\r\n"}, {"input": "14\r\n11 21 40 19 28 34 13 16 23 30 34 22 25 44\r\n", "output": "4\r\n"}, {"input": "3\r\n95 91 174\r\n", "output": "12\r\n"}, {"input": "4\r\n82 75 78 125\r\n", "output": "46\r\n"}, {"input": "6\r\n87 75 88 94 15 1\r\n", "output": "4\r\n"}, {"input": "10\r\n27 52 58 64 45 64 1 19 2 28\r\n", "output": "12\r\n"}, {"input": "50\r\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1\r\n", "output": "0\r\n"}, {"input": "100\r\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3\r\n", "output": "0\r\n"}, {"input": "150\r\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1\r\n", "output": "0\r\n"}, {"input": "200\r\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2\r\n", "output": "0\r\n"}, {"input": "5\r\n35 80 45 100 100\r\n", "output": "40\r\n"}, {"input": "4\r\n90 179 90 1\r\n", "output": "2\r\n"}, {"input": "5\r\n50 50 20 160 80\r\n", "output": "0\r\n"}, {"input": "5\r\n30 175 30 5 120\r\n", "output": "10\r\n"}, {"input": "4\r\n170 30 10 150\r\n", "output": "20\r\n"}, {"input": "6\r\n90 30 90 30 90 30\r\n", "output": "60\r\n"}, {"input": "4\r\n70 80 110 100\r\n", "output": "20\r\n"}, {"input": "7\r\n35 45 70 100 10 10 90\r\n", "output": "0\r\n"}, {"input": "6\r\n50 90 10 90 20 100\r\n", "output": "20\r\n"}, {"input": "6\r\n10 155 162 1 26 6\r\n", "output": "18\r\n"}, {"input": "7\r\n80 90 80 45 10 10 45\r\n", "output": "20\r\n"}, {"input": "4\r\n18 36 162 144\r\n", "output": "36\r\n"}, {"input": "5\r\n20 50 50 160 80\r\n", "output": "40\r\n"}, {"input": "5\r\n10 30 140 20 160\r\n", "output": "0\r\n"}, {"input": "6\r\n90 80 60 50 40 40\r\n", "output": "20\r\n"}, {"input": "9\r\n40 20 20 20 20 20 20 40 160\r\n", "output": "40\r\n"}, {"input": "4\r\n90 54 90 126\r\n", "output": "72\r\n"}, {"input": "4\r\n150 170 30 10\r\n", "output": "20\r\n"}, {"input": "8\r\n130 12 13 85 41 67 5 7\r\n", "output": "26\r\n"}, {"input": "7\r\n70 170 20 10 30 30 30\r\n", "output": "20\r\n"}, {"input": "8\r\n100 100 50 50 15 15 15 15\r\n", "output": "40\r\n"}, {"input": "4\r\n100 70 80 110\r\n", "output": "20\r\n"}, {"input": "5\r\n160 130 40 20 10\r\n", "output": "20\r\n"}, {"input": "4\r\n20 149 151 40\r\n", "output": "22\r\n"}, {"input": "4\r\n100 10 100 150\r\n", "output": "60\r\n"}, {"input": "6\r\n19 64 105 168 1 3\r\n", "output": "16\r\n"}, {"input": "8\r\n10 10 70 70 90 90 10 10\r\n", "output": "0\r\n"}]
false
stdio
null
true
868/C
868
C
Python 3
TESTS
128
624
307,200
31020889
from sys import stdin, stdout n, k = map(int, stdin.readline().split()) used = {} sze = 2 ** k for i in range(n): values = list(map(int, stdin.readline().split())) if ''.join(list(map(str, values))) in used: used[''.join(list(map(str, values)))] += 1 else: used[''.join(list(map(str, values)))] = 1 label = 0 if '0' * k in used and used['0' * k]: label = 1 for i in range(sze): for j in range(sze): a = bin(i)[2:] b = bin(j)[2:] a = '0' * (k - len(a)) + a b = '0' * (k - len(b)) + b if a in used and b in used and (a != b or used[a] > 1): result = [0 for i in range(k)] for i in range(k): result[i] += int(a[i]) result[i] += int(b[i]) if max(result) <= 1: label = 1 if label: stdout.write('YES') else: stdout.write('NO')
143
124
3,891,200
211054545
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb N,M = map(int,input().split()) s = set() for _ in range(N): S = input().split()[::-1] num = 0 for i in range(M): num+=2**i*int(S[i]) s.add(num) if 0 in s:exit(print("YES")) for i in s: for j in s: if i&j==0:exit(print("YES")) print("NO")
Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
256
Qualification Rounds
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset. k experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems. Determine if Snark and Philip can make an interesting problemset!
The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams. Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise.
Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
null
In the first example you can't make any interesting problemset, because the first team knows all problems. In the second example you can choose the first and the third problems.
[{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}]
1,500
["bitmasks", "brute force", "constructive algorithms", "dp"]
143
[{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n1 0 1\r\n0 1 1\r\n1 0 0\r\n1 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 0 1\r\n1 1 0 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 1 0\r\n0 0 0 0\r\n0 0 1 0\r\n1 0 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n0 0\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 1\r\n1 0 0\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 0\r\n1 1 0 0\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 1\r\n1\r\n1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n0 1 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 1\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 0 1\r\n1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 1 1 0\r\n1 1 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 0\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "6 3\r\n0 1 1\r\n1 0 1\r\n1 1 1\r\n0 1 0\r\n1 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n0 0 0 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 1 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "6 3\r\n1 0 0\r\n1 1 1\r\n1 1 1\r\n0 1 0\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 0 0\r\n1 1 1 1\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "1 3\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 1\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 1 0\r\n1 1 1\r\n0 0 1\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n1 1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n0 1 0 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n1 1 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 1 1\r\n1 0 1 0\r\n1 1 0 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 0 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n1 0\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 0 1\r\n0 0 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n1 1 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "8 4\r\n0 0 0 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 1\r\n1 1 1 0\r\n0 1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n0 0 0 1\r\n1 1 1 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n1 0 1\r\n0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 0 1\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 0 0\r\n1 0 1 0\r\n0 1 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 0 0 0\r\n1 0 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 0 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 0 1\r\n0 1 1 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 1 1\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 0\r\n", "output": "YES\r\n"}]
false
stdio
null
true
808/D
808
D
Python 3
TESTS
46
1,357
8,806,400
70497527
def bs(a, be, en, v): while be + 1 < en: mid = (be + en) // 2 if a[mid] == v: return True elif a[mid] < v: be = mid else: en = mid return False def solve(inp, ps, n): su = ps[-1] if su % 2: return False su //= 2 if bs(ps, 0, n, su): return True for i in range(n): if bs(ps, i, n, su + inp[i]): return True for i in range(n): if bs(ps, 0, i, su - inp[i]): return True return False if __name__ == '__main__': n = int(input()) inp = list(map(int, input().split())) ps = [0] * n for i in range(n): ps[i] = ps[i-1] + inp[i] print('YES' if solve(inp, ps, n) else 'No')
115
124
19,763,200
166889527
from itertools import accumulate if __name__=='__main__': n=int(input()) nums=list(map(int,input().split())) total=sum(nums) if total & 1: print('NO') quit() s=0 presum={v:i for i,v in enumerate(accumulate(nums))} for i,n in enumerate(nums): l=total//2-n r=total//2+n if (l in presum and presum[l]<i) or (r in presum and presum[r]>=i): print('YES') quit() print('NO')
Educational Codeforces Round 21
ICPC
2,017
2
256
Array Division
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position). Inserting an element in the same position he was erased from is also considered moving. Can Vasya divide the array after choosing the right element to move and its new position?
The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array. The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array.
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
null
In the first example Vasya can move the second element to the end of the array. In the second example no move can make the division possible. In the third example Vasya can move the fourth element by one position to the left.
[{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}]
1,900
["binary search", "data structures", "implementation"]
115
[{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "output": "NO\r\n"}, {"input": "8\r\n9 5 5 10 4 9 5 8\r\n", "output": "NO\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "YES\r\n"}, {"input": "15\r\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8\r\n", "output": "NO\r\n"}, {"input": "20\r\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13\r\n", "output": "NO\r\n"}, {"input": "20\r\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 10 6\r\n", "output": "NO\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": "YES\r\n"}, {"input": "100\r\n89 38 63 73 77 4 99 74 30 5 69 57 97 37 88 71 36 59 19 63 46 20 33 58 61 98 100 31 33 53 99 96 34 17 44 95 54 52 22 77 67 88 20 88 26 43 12 23 96 94 14 7 57 86 56 54 32 8 3 43 97 56 74 22 5 100 12 60 93 12 44 68 31 63 7 71 21 29 19 38 50 47 97 43 50 59 88 40 51 61 20 68 32 66 70 48 19 55 91 53\r\n", "output": "NO\r\n"}, {"input": "100\r\n80 100 88 52 25 87 85 8 92 62 35 66 74 39 58 41 55 53 23 73 90 72 36 44 97 67 16 54 3 8 25 34 84 47 77 39 93 19 49 20 29 44 21 48 21 56 82 59 8 31 94 95 84 54 72 20 95 91 85 1 67 19 76 28 31 63 87 98 55 28 16 20 36 91 93 39 94 69 80 97 100 96 68 26 91 45 22 84 20 36 20 92 53 75 58 51 60 26 76 25\r\n", "output": "NO\r\n"}, {"input": "100\r\n27 95 57 29 91 85 83 36 72 86 39 5 79 61 78 93 100 97 73 23 82 66 41 92 38 92 100 96 48 56 66 47 5 32 69 13 95 23 46 62 99 83 57 66 98 82 81 57 37 37 81 64 45 76 72 43 99 76 86 22 37 39 93 80 99 36 53 83 3 32 52 9 78 34 47 100 33 72 19 40 29 56 77 32 79 72 15 88 100 98 56 50 22 81 88 92 58 70 21 19\r\n", "output": "NO\r\n"}, {"input": "100\r\n35 31 83 11 7 94 57 58 30 26 2 99 33 58 98 6 3 52 13 66 21 53 26 94 100 5 1 3 91 13 97 49 86 25 63 90 88 98 57 57 34 81 32 16 65 94 59 83 44 14 46 18 28 89 75 95 87 57 52 18 46 80 31 43 38 54 69 75 82 9 64 96 75 40 96 52 67 85 86 38 95 55 16 57 17 20 22 7 63 3 12 16 42 87 46 12 51 95 67 80\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 4 3 100 100 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n6 100 100 3 4 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n4 2 3 7 1 1\r\n", "output": "YES\r\n"}, {"input": "4\r\n6 1 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n228 114 114\r\n", "output": "YES\r\n"}, {"input": "3\r\n229 232 444\r\n", "output": "NO\r\n"}, {"input": "3\r\n322 324 555\r\n", "output": "NO\r\n"}, {"input": "3\r\n69 34 5\r\n", "output": "NO\r\n"}, {"input": "6\r\n5 4 1 2 2 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n545 237 546\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 3 1 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 2 10 2 2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n5 4 6 5 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 6 1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 1 8 5 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n73 67 16 51 56 71 37 49 90 6\r\n", "output": "NO\r\n"}, {"input": "1\r\n10\r\n", "output": "NO\r\n"}, {"input": "1\r\n1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n8 2 7 5 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n2\r\n", "output": "NO\r\n"}, {"input": "16\r\n9 10 2 1 6 7 6 5 8 3 2 10 8 4 9 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4\r\n", "output": "YES\r\n"}, {"input": "19\r\n9 9 3 2 4 5 5 7 8 10 8 10 1 2 2 6 5 3 3\r\n", "output": "NO\r\n"}, {"input": "11\r\n7 2 1 8 8 2 4 10 8 7 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n10 20 30 40 99 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n3 7 9 2 10 1 9 6 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n9 3\r\n", "output": "NO\r\n"}, {"input": "7\r\n1 2 3 12 1 2 3\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 4 4 5 8 5\r\n", "output": "YES\r\n"}, {"input": "18\r\n2 10 3 6 6 6 10 8 8 1 10 9 9 3 1 9 7 4\r\n", "output": "YES\r\n"}, {"input": "20\r\n9 6 6 10 4 4 8 7 4 10 10 2 10 5 9 5 3 10 1 9\r\n", "output": "NO\r\n"}, {"input": "12\r\n3 8 10 2 4 4 6 9 5 10 10 3\r\n", "output": "YES\r\n"}, {"input": "11\r\n9 2 7 7 7 3 7 5 4 10 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 4 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n7 1\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 5 6 7 6\r\n", "output": "YES\r\n"}, {"input": "11\r\n4 3 10 3 7 8 4 9 2 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n705032704 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 5 6 8 3 1 7 3\r\n", "output": "YES\r\n"}, {"input": "20\r\n8 6 3 6 3 5 10 2 6 1 7 6 9 10 8 3 5 9 3 8\r\n", "output": "YES\r\n"}, {"input": "11\r\n2 4 8 3 4 7 9 10 5 3 3\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 4 2 24 6 4 2\r\n", "output": "YES\r\n"}, {"input": "17\r\n7 1 1 1 8 9 1 10 8 8 7 9 7 9 1 6 5\r\n", "output": "NO\r\n"}, {"input": "7\r\n7 10 1 2 6 2 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 10 40 10 10\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 3 13\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 10 2 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n7 4 5 62 20 20 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n1 5 2 20 10 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n5 6\r\n", "output": "NO\r\n"}, {"input": "14\r\n5 2 9 7 5 8 3 2 2 4 9 1 3 10\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 2 2 5 5\r\n", "output": "NO\r\n"}, {"input": "11\r\n1 1 1 1 1 10 1 1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "9\r\n8 4 13 19 11 1 8 2 8\r\n", "output": "YES\r\n"}, {"input": "6\r\n14 16 14 14 15 11\r\n", "output": "YES\r\n"}, {"input": "9\r\n14 19 1 13 11 3 1 1 7\r\n", "output": "YES\r\n"}, {"input": "6\r\n16 13 3 7 4 15\r\n", "output": "YES\r\n"}, {"input": "4\r\n11 7 12 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 1 3 6 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 4 8 11 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 10 3 4\r\n", "output": "YES\r\n"}, {"input": "6\r\n8 15 12 14 15 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 4 4 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 3 1 6 4\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 12 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 4 13\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1 1 1 1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n19 6 5 13 6 13\r\n", "output": "YES\r\n"}, {"input": "8\r\n2 2 2 5 1 2 3 3\r\n", "output": "YES\r\n"}]
false
stdio
null
true
814/A
814
A
PyPy 3
TESTS
31
514
11,878,400
77459847
import math as mt import sys,string,bisect input=sys.stdin.readline import random from collections import deque,defaultdict L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) d=defaultdict(list) n,k=M() a=L() b=L() m=max(a) mi=min(a) p=-10**10 key=0 c=0 for i in range(n): if(a[i]==0): c+=1 if(c==1): key=i if(c==2): print("YES") exit() if(a[i]!=0): if(a[i]<p): print("YES") exit() else: p=a[i] #print(key) if(key+1<n): if(b[0]<a[key+1]): print("No") else: print("Yes") else: if(b[0]>a[-2]): print("No") else: print("Yes")
96
46
0
154074711
def read(): return map(int, input().split()) n, k = read() a = list(read()) b = list(sorted(read())) for i in range(n): if a[i] == 0: a[i] = b.pop() print("No" if sorted(a) == a else "Yes")
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An abandoned sentiment from past
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.
The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements. The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in a and b more than once in total.
Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.
null
In the first sample: - Sequence a is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in b are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
[{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}]
900
["constructive algorithms", "greedy", "implementation", "sortings"]
96
[{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\r\n80\r\n", "output": "No\r\n"}, {"input": "100 1\r\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\r\n58\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n2 1 0 4\r\n3\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n199 0\r\n200\r\n", "output": "No\r\n"}, {"input": "3 2\r\n115 0 0\r\n145 191\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n196 197 198 0 200\r\n199\r\n", "output": "No\r\n"}, {"input": "5 1\r\n92 0 97 99 100\r\n93\r\n", "output": "No\r\n"}, {"input": "3 1\r\n3 87 0\r\n81\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 92 192\r\n118\r\n", "output": "Yes\r\n"}, {"input": "10 1\r\n1 3 0 7 35 46 66 72 83 90\r\n22\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 0 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113\r\n67\r\n", "output": "No\r\n"}, {"input": "100 5\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 0 99 100\r\n98 64 55 52 29\r\n", "output": "Yes\r\n"}, {"input": "100 5\r\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\r\n121 199 62 193 27\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 0 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n11\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n1\r\n", "output": "No\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 0\r\n100\r\n", "output": "No\r\n"}, {"input": "100 1\r\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\r\n65\r\n", "output": "Yes\r\n"}, {"input": "100 2\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 0 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n48 1\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\r\n69\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\r\n129\r\n", "output": "No\r\n"}, {"input": "5 2\r\n0 2 7 0 10\r\n1 8\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 4 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 3\r\n4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n1\r\n", "output": "No\r\n"}, {"input": "2 1\r\n0 5\r\n7\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 0 12 13\r\n1\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n0 2 3 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 0 3 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "7 2\r\n1 2 3 0 0 6 7\r\n4 5\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "2 2\r\n0 0\r\n1 2\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n1 0 0\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 4 0\r\n5 2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 1\r\n2\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 4 5\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 2 3\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 5 0\r\n6\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 0 2\r\n7\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n4 5 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 12 0 14\r\n13\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 2 0 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 11 14\r\n12\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 3 0 4\r\n2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 5\r\n1\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 7\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 5 4\r\n6\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n11 0 0 14\r\n13 12\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n1 0\r\n2\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 0 3 2\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 2 3 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 2 0\r\n5\r\n", "output": "No\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 5 7\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 0 11\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n7 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 3 0 5 0\r\n6 4\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n0 1 0\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n6 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 3\r\n6\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 2 0 0 5\r\n4 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n2 0 0 8\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 0 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 2\r\n11 0 0 200\r\n100 199\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n5 0\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 5\r\n10\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 0 0 5 6\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 3 0 5\r\n2 4\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 4 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n5 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 7\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "3 3\r\n0 0 0\r\n1 4 3\r\n", "output": "Yes\r\n"}, {"input": "5 5\r\n0 0 0 0 0\r\n5 4 3 2 1\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n3 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 4 0 8 9 10\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 3 5 6\r\n9\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 2 0 0\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 4 5 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 0 4\r\n5\r\n", "output": "Yes\r\n"}]
false
stdio
null
true
127/B
127
B
PyPy 3
TESTS
72
93
0
219386243
n = int(input()) l = list(map(int, input().split())) s, a = list(set(l)), [] f = 0 for i in range(len(s)): c = l.count(s[i]) f += (c // 4) if c % 4 != 0 and c > 1: a.append((c % 4) // 2) for i in range(len(a) - 1): m = min(a[i], a[i + 1]) f += m a[i + 1] -= m print(f)
93
46
0
139822547
n = int(input()) arr = input().split() final = [] for i in arr: final.append(int(i)) npairs = 0 for i in set(final): count = final.count(i) npairs += count // 2 print(npairs // 2)
Codeforces Beta Round 93 (Div. 2 Only)
CF
2,011
1
256
Canvas Frames
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the sticks or glue them together. To make a h × w-sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w. Specifically, to make a square frame (when h = w), he needs four sticks of the same length. Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.
The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100).
Print the single number — the maximum number of frames Nicholas can make for his future canvases.
null
null
[{"input": "5\n2 4 3 2 3", "output": "1"}, {"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3"}, {"input": "4\n3 3 3 5", "output": "0"}]
1,000
["implementation"]
93
[{"input": "5\r\n2 4 3 2 3\r\n", "output": "1"}, {"input": "13\r\n2 2 4 4 4 4 6 6 6 7 7 9 9\r\n", "output": "3"}, {"input": "4\r\n3 3 3 5\r\n", "output": "0"}, {"input": "2\r\n3 5\r\n", "output": "0"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0"}, {"input": "14\r\n2 4 2 6 2 3 4 1 4 5 4 3 4 1\r\n", "output": "2"}, {"input": "33\r\n1 2 2 6 10 10 33 11 17 32 25 6 7 29 11 32 33 8 13 17 17 6 11 11 11 8 10 26 29 26 32 33 36\r\n", "output": "5"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n10\r\n", "output": "0"}, {"input": "2\r\n1 1\r\n", "output": "0"}, {"input": "3\r\n1 1 1\r\n", "output": "0"}, {"input": "3\r\n1 2 2\r\n", "output": "0"}, {"input": "3\r\n3 2 1\r\n", "output": "0"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1"}, {"input": "4\r\n1 2 1 2\r\n", "output": "1"}, {"input": "4\r\n1 100 1 100\r\n", "output": "1"}, {"input": "4\r\n10 100 100 10\r\n", "output": "1"}, {"input": "4\r\n1 2 3 3\r\n", "output": "0"}, {"input": "4\r\n8 5 9 13\r\n", "output": "0"}, {"input": "4\r\n100 100 100 100\r\n", "output": "1"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1"}, {"input": "5\r\n1 4 4 1 1\r\n", "output": "1"}, {"input": "5\r\n1 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 1 100 100 100\r\n", "output": "1"}, {"input": "5\r\n100 100 100 100 100\r\n", "output": "1"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "1"}, {"input": "6\r\n1 1 5 1 1 5\r\n", "output": "1"}, {"input": "6\r\n1 100 100 1 1 1\r\n", "output": "1"}, {"input": "6\r\n100 1 1 100 1 100\r\n", "output": "1"}, {"input": "6\r\n1 2 3 2 3 1\r\n", "output": "1"}, {"input": "6\r\n1 50 1 100 50 100\r\n", "output": "1"}, {"input": "6\r\n10 10 10 12 13 14\r\n", "output": "0"}, {"input": "7\r\n1 1 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 2 1 2 1 2\r\n", "output": "1"}, {"input": "7\r\n1 1 2 2 1 2 3\r\n", "output": "1"}, {"input": "7\r\n1 3 2 2 3 1 4\r\n", "output": "1"}, {"input": "7\r\n1 3 4 3 5 4 6\r\n", "output": "1"}, {"input": "7\r\n7 6 5 4 3 2 1\r\n", "output": "0"}, {"input": "8\r\n1 2 1 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 2 1 1 2 2 2\r\n", "output": "1"}, {"input": "8\r\n1 2 2 2 3 1 1 3\r\n", "output": "1"}, {"input": "8\r\n1 2 3 4 1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n1 1 1 1 2 3 2 3\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 5 5 5\r\n", "output": "1"}, {"input": "8\r\n1 2 1 3 4 1 5 6\r\n", "output": "0"}, {"input": "8\r\n1 2 3 4 5 6 1 7\r\n", "output": "0"}, {"input": "8\r\n8 6 3 4 5 2 1 7\r\n", "output": "0"}, {"input": "8\r\n100 100 100 100 100 100 100 100\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "10\r\n19 9 14 14 19 5 5 18 10 17\r\n", "output": "1"}, {"input": "10\r\n72 86 73 25 84 29 33 34 20 29\r\n", "output": "0"}, {"input": "10\r\n93 93 99 98 91 96 92 98 94 98\r\n", "output": "1"}, {"input": "13\r\n35 6 21 30 67 55 70 39 75 72 11 13 69\r\n", "output": "0"}, {"input": "17\r\n90 97 12 56 94 11 49 96 22 7 15 48 71 71 94 72 100\r\n", "output": "1"}, {"input": "18\r\n39 72 67 28 69 41 43 51 66 99 4 57 68 93 28 27 37 27\r\n", "output": "1"}, {"input": "23\r\n88 82 2 67 4 6 67 83 77 58 48 64 86 37 96 83 35 46 13 79 72 18 35\r\n", "output": "1"}, {"input": "30\r\n43 34 38 50 47 24 26 20 7 5 26 29 98 87 90 46 10 53 88 61 90 39 78 81 65 13 72 95 53 27\r\n", "output": "1"}, {"input": "33\r\n1 3 34 55 38 58 64 26 66 44 50 63 46 62 62 99 73 87 35 20 30 38 39 85 49 24 93 68 8 25 86 30 51\r\n", "output": "1"}, {"input": "38\r\n65 69 80 93 28 36 40 81 53 75 55 50 82 95 8 51 66 65 50 4 40 92 18 70 38 68 42 100 34 57 98 79 95 84 82 35 100 89\r\n", "output": "3"}, {"input": "40\r\n4 2 62 38 76 68 19 71 44 91 76 31 3 63 56 62 93 98 10 61 52 59 81 46 23 27 36 26 24 38 37 66 15 16 78 41 95 82 73 90\r\n", "output": "1"}, {"input": "43\r\n62 31 14 43 67 2 60 77 64 70 91 9 3 43 76 7 56 84 5 20 88 50 47 42 7 39 8 56 71 24 49 59 70 61 81 17 76 44 80 61 77 5 96\r\n", "output": "4"}, {"input": "49\r\n75 64 7 2 1 66 31 84 78 53 34 5 40 90 7 62 86 54 99 77 8 92 30 3 18 18 61 38 38 11 79 88 84 89 50 94 72 8 54 85 100 1 19 4 97 91 13 39 91\r\n", "output": "4"}, {"input": "57\r\n83 94 42 57 19 9 40 25 56 92 9 38 58 66 43 19 50 10 100 3 49 96 77 36 20 3 48 15 38 19 99 100 66 14 52 13 16 73 65 99 29 85 75 18 97 64 57 82 70 19 16 25 40 11 9 22 89\r\n", "output": "6"}, {"input": "67\r\n36 22 22 86 52 53 36 68 46 82 99 37 15 43 57 35 33 99 22 96 7 8 80 93 70 70 55 51 61 74 6 28 85 72 84 42 29 1 4 71 7 40 61 95 93 36 42 61 16 40 10 85 31 86 93 19 44 20 52 66 10 22 40 53 25 29 23\r\n", "output": "8"}, {"input": "74\r\n90 26 58 69 87 23 44 9 32 25 33 13 79 84 52 90 4 7 93 77 29 85 22 1 96 69 98 16 76 87 57 16 44 41 57 28 18 70 77 83 37 17 59 87 27 19 89 63 14 84 77 40 46 77 82 73 86 73 30 58 6 30 70 36 31 12 43 50 93 3 3 57 38 91\r\n", "output": "7"}, {"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": "25"}, {"input": "100\r\n1 9 3 5 10 10 9 8 10 1 7 6 5 6 7 9 1 5 8 3 2 3 3 10 2 3 10 7 10 3 6 3 2 10 1 10 2 3 4 3 3 1 7 5 10 2 3 8 9 2 5 4 7 2 5 9 2 1 7 9 9 8 4 4 6 1 6 6 4 7 2 3 1 1 1 6 9 1 2 9 3 7 6 10 3 6 2 5 2 5 3 9 10 6 4 2 9 9 4 5\r\n", "output": "23"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "7\r\n13 13 13 13 6 2 3\r\n", "output": "1"}, {"input": "8\r\n1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n100 100 99 99 5\r\n", "output": "1"}, {"input": "8\r\n2 2 2 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 6 7 7\r\n", "output": "0"}, {"input": "8\r\n4 4 4 4 4 4 4 4\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 2 2\r\n", "output": "2"}, {"input": "4\r\n100 100 100 99\r\n", "output": "0"}, {"input": "4\r\n2 2 2 2\r\n", "output": "1"}, {"input": "5\r\n100 100 99 99 2\r\n", "output": "1"}, {"input": "9\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n2 2 3 4 4\r\n", "output": "1"}, {"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": "25"}, {"input": "13\r\n1 2 3 4 5 6 7 8 9 10 11 12 13\r\n", "output": "0"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "4\r\n4 4 4 4\r\n", "output": "1"}, {"input": "5\r\n1 1 2 3 3\r\n", "output": "1"}, {"input": "5\r\n30 30 30 1 1\r\n", "output": "1"}]
false
stdio
null
true
868/C
868
C
PyPy 3
TESTS
54
858
29,491,200
90725810
from collections import defaultdict One = { 0: [1], 1: [0] } Two = { 0: [1,2,3], 1: [0,2], 2: [0,1], 3: [0] } Three = { 0:[1,2,3,4,5,6,7], 1:[0,2,4,6], 2:[0,1,4,5], 3:[0,4], 4:[0,1,2,3], 5:[0,2], 6:[0,1], 7:[0] } Four = { 0: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 1: [0, 2, 4, 6, 8, 10, 12, 14], 2: [0, 1, 4, 5, 8, 9, 12, 13], 3: [0, 4, 8, 12], 4: [0, 1, 2, 3, 8, 9, 10, 11], 5: [0, 2, 8, 10], 6: [0, 1, 8, 9], 7: [0, 8], 8: [0, 1, 2, 3, 4, 5, 6, 7], 9: [0, 2, 4, 6], 10: [0, 1, 4, 5], 11: [0, 4], 12: [0, 1, 2, 3], 13: [0, 2], 14: [0, 1], 15: [0] } n,k = map(int,input().split()) List = [] for i in range(n): temp = "".join([x for x in input().split()]) List.append(int(temp,2)) Dict = defaultdict(int) for i in List: Dict[i] += 1 if(Dict[0]>1): print("YES") else: flag= 0 if(k==4): for i in range(n): if(List[i]): for j in Four[List[i]]: if(Dict[j]): print("YES") flag = 1 break if(flag): break if(not flag): print("NO") elif(k==3): for i in range(n): if(List[i]): for j in Three[List[i]]: if(Dict[j]): print("YES") flag = 1 break if(flag): break if(not flag): print("NO") elif(k == 2): for i in range(n): if(List[i]): for j in Two[List[i]]: if(Dict[j]): print("YES") flag = 1 break if(flag): break if(not flag): print("NO") else: for i in range(n): if(List[i]): for j in One[List[i]]: if(Dict[j]): print("YES") flag = 1 break if(flag): break if(not flag): print("NO")
143
124
5,120,000
209526956
import sys class FastIO: def __init__(self): return @staticmethod def _read(): return sys.stdin.readline().strip() def read_int(self): return int(self._read()) def read_float(self): return float(self._read()) def read_ints(self): return map(int, self._read().split()) def read_floats(self): return map(float, self._read().split()) def read_ints_minus_one(self): return map(lambda x: int(x) - 1, self._read().split()) def read_list_ints(self): return list(map(int, self._read().split())) def read_list_floats(self): return list(map(float, self._read().split())) def read_list_ints_minus_one(self): return list(map(lambda x: int(x) - 1, self._read().split())) def read_str(self): return self._read() def read_list_strs(self): return self._read().split() def read_list_str(self): return list(self._read()) @staticmethod def st(x): return sys.stdout.write(str(x) + '\n') @staticmethod def lst(x): return sys.stdout.write(" ".join(str(w) for w in x) + '\n') @staticmethod def round_5(f): res = int(f) if f - res >= 0.5: res += 1 return res @staticmethod def max(a, b): return a if a > b else b @staticmethod def min(a, b): return a if a < b else b class Solution: def __init__(self): return @staticmethod def main(ac=FastIO()): n, k = ac.read_ints() dct = set() for _ in range(n): lst = ac.read_list_ints() num = 0 for x in lst: num *= 2 num += x dct.add(num) if 0 in dct: ac.st("Yes") return lst = list(dct) m = len(lst) for i in range(m): for j in range(i + 1, m): if lst[i] & lst[j] == 0: ac.st("Yes") return ac.st("NO") return Solution().main()
Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
256
Qualification Rounds
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset. k experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems. Determine if Snark and Philip can make an interesting problemset!
The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams. Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise.
Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
null
In the first example you can't make any interesting problemset, because the first team knows all problems. In the second example you can choose the first and the third problems.
[{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}]
1,500
["bitmasks", "brute force", "constructive algorithms", "dp"]
143
[{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n1 0 1\r\n0 1 1\r\n1 0 0\r\n1 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 0 1\r\n1 1 0 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 1 0\r\n0 0 0 0\r\n0 0 1 0\r\n1 0 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n0 0\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 1\r\n1 0 0\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 0\r\n1 1 0 0\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 1\r\n1\r\n1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n0 1 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 1\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 0 1\r\n1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 1 1 0\r\n1 1 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 0\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "6 3\r\n0 1 1\r\n1 0 1\r\n1 1 1\r\n0 1 0\r\n1 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n0 0 0 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 1 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "6 3\r\n1 0 0\r\n1 1 1\r\n1 1 1\r\n0 1 0\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 0 0\r\n1 1 1 1\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "1 3\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 1\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 1 0\r\n1 1 1\r\n0 0 1\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n1 1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n0 1 0 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n1 1 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 1 1\r\n1 0 1 0\r\n1 1 0 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 0 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n1 0\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 0 1\r\n0 0 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n1 1 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "8 4\r\n0 0 0 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 1\r\n1 1 1 0\r\n0 1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n0 0 0 1\r\n1 1 1 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n1 0 1\r\n0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 0 1\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 0 0\r\n1 0 1 0\r\n0 1 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 0 0 0\r\n1 0 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 0 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 0 1\r\n0 1 1 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 1 1\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 0\r\n", "output": "YES\r\n"}]
false
stdio
null
true
868/C
868
C
PyPy 3
TESTS
54
936
35,020,800
123839267
from collections import Counter def f(g): st=Counter(g) l=list(st.keys()) for i in range(len(l)): c=0 if st[l[i]]>=2: c=1 for j in range(i+c): t=list(map(lambda x,y:x+y,l[i],l[j])) if max(t)==2: continue else: return "YES" return "NO" n,k=map(int,input().strip().split()) g=[] for i in range(n): g.append(tuple(map(int,input().strip().split()))) print(f(g))
143
140
0
212247968
n,m=map(int,input().split()) l=set() z="NO" for i in range(n): l.add(("".join(input().split()))) l=list(l) r=len(l) for i in range(1,(1<<r)):#subset freq=[0]*m y=0 for j in range(r):#chack sub if i&(1<<j): y+=1 for k in range(m): freq[k]+=int(l[j][k]) for u in freq: if u>y//2: break else: z="YES" break print(z)
Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
256
Qualification Rounds
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset. k experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems. Determine if Snark and Philip can make an interesting problemset!
The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams. Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise.
Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
null
In the first example you can't make any interesting problemset, because the first team knows all problems. In the second example you can choose the first and the third problems.
[{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}]
1,500
["bitmasks", "brute force", "constructive algorithms", "dp"]
143
[{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n1 0 1\r\n0 1 1\r\n1 0 0\r\n1 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 0 1\r\n1 1 0 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 1 0\r\n0 0 0 0\r\n0 0 1 0\r\n1 0 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n0 0\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 1\r\n1 0 0\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 0\r\n1 1 0 0\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 1\r\n1\r\n1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n0 1 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 1\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 0 1\r\n1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 1 1 0\r\n1 1 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 0\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "6 3\r\n0 1 1\r\n1 0 1\r\n1 1 1\r\n0 1 0\r\n1 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n0 0 0 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 1 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "6 3\r\n1 0 0\r\n1 1 1\r\n1 1 1\r\n0 1 0\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 0 0\r\n1 1 1 1\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "1 3\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 1\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 1 0\r\n1 1 1\r\n0 0 1\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n1 1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n0 1 0 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n1 1 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 1 1\r\n1 0 1 0\r\n1 1 0 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 0 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n1 0\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 0 1\r\n0 0 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n1 1 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "8 4\r\n0 0 0 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 1\r\n1 1 1 0\r\n0 1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n0 0 0 1\r\n1 1 1 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n1 0 1\r\n0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 0 1\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 0 0\r\n1 0 1 0\r\n0 1 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 0 0 0\r\n1 0 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 0 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 0 1\r\n0 1 1 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 1 1\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 0\r\n", "output": "YES\r\n"}]
false
stdio
null
true
828/B
828
B
Python 3
TESTS
21
62
0
29677001
# If the path be beautiful, let us not ask where it leads. [n, m] = [int(x) for x in input().split()] maximum = [] first, last, count = -1, -1, 0 for i in range(n): line = input() if 'B' in line: count += line.count('B') maximum.append(line.rindex('B') - line.index('B') + 1) if first == -1: first = i last = i maximum.append(last-first+1) if last == -1: print(1) else: length = max(maximum) if length <= n and length <= m: print(length*length - count) else: print(-1)
128
62
307,200
29962376
def main(): (n, m) = (int(x) for x in input().split()) L = [None] * n for i in range(n): L[i] = input() print(solver(n, m, L)) def solver(n, m, L): tr = topRow(n, m, L) if tr == -1: return 1 br = bottomRow(n, m, L) lc = leftCol(n, m, L) rc = rightCol(n, m, L) colSize = rc - lc + 1 rowSize = br - tr + 1 if colSize > n or rowSize > m: return -1 if colSize > rowSize: if br >= colSize: squareTop = br - colSize + 1 squareBottom = br else: squareTop = 0 squareBottom = colSize - 1 squareLeft = lc squareRight = rc elif colSize < rowSize: if rc >= rowSize: squareLeft = rc - rowSize + 1 squareRight = rc else: squareLeft = 0 squareRight = rowSize - 1 squareTop = tr squareBottom = br else: squareTop = tr squareBottom = br squareLeft = lc squareRight = rc count = 0 for i in range(squareTop, squareBottom + 1): for j in range(squareLeft, squareRight + 1): if L[i][j] == 'W': count += 1 return count def topRow(n, m, L): for i in range(n): if 'B' in L[i]: return i return -1 def bottomRow(n, m, L): for i in range(n - 1, -1, -1): if 'B' in L[i]: return i return -1 def leftCol(n, m, L): for j in range(m): for i in range(n): if L[i][j] == 'B': return j return -1 def rightCol(n, m, L): for j in range(m - 1, -1, -1): for i in range(n): if L[i][j] == 'B': return j return -1 grid1 = [['W', 'W', 'W', 'W'], ['W', 'W', 'W', 'B'], ['W', 'W', 'W', 'B'], ['W', 'W', 'B', 'B'], ['W', 'W', 'W', 'W']] #print(solver(5, 4, grid1)) main()
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Black Square
Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
null
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third example all cells are colored white, so it's sufficient to color any cell black.
[{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}]
1,300
["implementation"]
128
[{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "-1\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "2 4\r\nWWWW\r\nWBWW\r\n", "output": "0\r\n"}, {"input": "4 5\r\nWWWWW\r\nBBWWW\r\nBBWWW\r\nWWWWW\r\n", "output": "0\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "10 5\r\nWWWWB\r\nWWWWW\r\nWWWBB\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "12\r\n"}, {"input": "5 10\r\nWWWWWWWWWW\r\nWWWWBWBBWW\r\nWWWWWWWWWW\r\nWWWWBWWWWW\r\nWWWWWWBWWW\r\n", "output": "11\r\n"}, {"input": "20 10\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWBBWBWWWW\r\nWWBWWBWWWW\r\nWWWWBWWWWW\r\nWWWWBWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\n", "output": "9\r\n"}, {"input": "10 20\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWBW\r\nWWWWWWWWWWWWWWWWWBWW\r\nWWWWWWWWWWWWWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nWW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nWW\r\nWB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWB\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBW\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nBW\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nWW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBB\r\nWB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nWW\r\n", "output": "1\r\n"}, {"input": "1 2\r\nWB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nW\r\nW\r\n", "output": "1\r\n"}, {"input": "2 1\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "20 10\r\nWWBWWWBBWW\r\nWWWWWBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWBBBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWBWWWWWBWW\r\nWBWWBWWWBW\r\nWWBWBWWWWW\r\nWWWBWWBBWW\r\nWWBBWBWBWW\r\nBBWWWWWBWW\r\nWWBWWBBBWW\r\nWWWBWBBWWW\r\nWWWBBWBWWW\r\nWWWWWWWWWW\r\nWWWBWWWWWW\r\nWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "10 20\r\nWWWWWWWBWWWWWWWBWWWB\r\nWWWBWWWBWWWWWWWWWWWW\r\nBWWWWWWWWWWWWWWWWWBB\r\nWWWWWWBWWBWWBWWWBWWW\r\nWWWWWWWWBWWBWWWBWWWW\r\nWBWWWWWWWBWWWWWWWWWW\r\nWWWBWBWWBWWWWWBBWWWB\r\nWWBBWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWBWWWWBW\r\nWWWWWWWWWWWWBWWBWWWB\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "-1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "1 5\r\nWBBWW\r\n", "output": "-1\r\n"}, {"input": "20 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWBW\r\nWBB\r\nWWW\r\n", "output": "1\r\n"}, {"input": "4 6\r\nWWWWWW\r\nWWWBWW\r\nWWWWWB\r\nWWWWWW\r\n", "output": "7\r\n"}, {"input": "5 5\r\nWBWBW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "7\r\n"}, {"input": "3 3\r\nBBB\r\nBBB\r\nBBB\r\n", "output": "0\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWBWW\r\n", "output": "23\r\n"}, {"input": "5 4\r\nWWBW\r\nBWWB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "13\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWWW\r\nWBBW\r\n", "output": "12\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWBWW\r\n", "output": "34\r\n"}, {"input": "3 3\r\nBBW\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "3 3\r\nBWB\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "6 6\r\nWBWWWW\r\nBWWWBW\r\nWWWWWW\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "21\r\n"}, {"input": "3 3\r\nWWW\r\nWBW\r\nWWW\r\n", "output": "0\r\n"}, {"input": "3 3\r\nBBB\r\nWWW\r\nWWW\r\n", "output": "6\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWBWW\r\nWBBBW\r\nWWBWW\r\nWWBWW\r\n", "output": "18\r\n"}, {"input": "5 2\r\nWB\r\nWB\r\nWB\r\nWW\r\nWW\r\n", "output": "-1\r\n"}, {"input": "4 7\r\nBBBBBWW\r\nWWWWWWW\r\nWWWWWWW\r\nWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWBB\r\nWWWW\r\n", "output": "6\r\n"}, {"input": "4 4\r\nWWWW\r\nWBWW\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "2 5\r\nWWWWW\r\nBBBWW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWBW\r\nWWWWWW\r\nWWWWWW\r\nWWBWWW\r\n", "output": "33\r\n"}, {"input": "3 3\r\nWBW\r\nWBW\r\nWBW\r\n", "output": "6\r\n"}, {"input": "3 5\r\nWWBBB\r\nBWBBB\r\nWWBBB\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWB\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "22\r\n"}, {"input": "5 5\r\nBWWWB\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nBWWWW\r\n", "output": "22\r\n"}, {"input": "4 5\r\nWWWWW\r\nBWWWW\r\nBBBWW\r\nWWWWW\r\n", "output": "5\r\n"}, {"input": "4 4\r\nBBBB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "12\r\n"}, {"input": "4 6\r\nWWWWWW\r\nBWWWWW\r\nBWWWWW\r\nBBBBBB\r\n", "output": "-1\r\n"}, {"input": "3 6\r\nWWWWWW\r\nBBBWWW\r\nWWWWWW\r\n", "output": "6\r\n"}, {"input": "5 2\r\nWW\r\nBW\r\nBW\r\nBB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nBBBBB\r\nWWWWW\r\nWWWWW\r\n", "output": "20\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nWWWWB\r\nWBWWW\r\nWWWWW\r\n", "output": "14\r\n"}, {"input": "1 5\r\nWWBWW\r\n", "output": "0\r\n"}, {"input": "1 3\r\nBBB\r\n", "output": "-1\r\n"}, {"input": "2 4\r\nWWBW\r\nBWBW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nBBBBBB\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "30\r\n"}, {"input": "4 4\r\nWWWW\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWB\r\n", "output": "0\r\n"}, {"input": "5 1\r\nB\r\nB\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "2 3\r\nWBW\r\nWBW\r\n", "output": "2\r\n"}, {"input": "5 2\r\nWW\r\nWB\r\nWB\r\nWB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "23\r\n"}]
false
stdio
null
true
814/A
814
A
Python 3
TESTS
27
62
5,632,000
34001933
l1=input() l1=l1.split() n=int(l1[0]) k=int(l1[1]) a=input() a=a.split() b=input() b=b.split() for i in range(n): a[i]=int(a[i]) for i in range(k): b[i]=int(b[i]) def Increasing(a): fb='NO' fp="NO" for i in range(len(a)-1): if a[i]>a[i+1]: fb='YES' if a[i]<a[i+1]: fp="YES" f=[fb,fp] if "NO" in f: return "NO" return "YES" def Check1(a,b): f='NO' t=a.count(0) if t>2: return "YES" if t<2: i=a.index(0) a[i]=b[0] return Increasing(a) if t==2: aa=a.copy() i=aa.index(0) aa[i]=b[0] i=aa.index(0) aa[i]=b[1] ######## i=a.index(0) a[i]=b[1] i=a.index(0) a[i]=b[0] f=Increasing(a),Increasing(aa) if 'YES' in f: return "YES" return "NO" print(Check1(a,b))
96
46
0
161548968
a_length, b_length = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) b.sort(reverse=True) j = 0 for i in range(a_length): if a[i] == 0: a[i] = b[j] j += 1 if a == sorted(a): print('NO') else: print('YES')
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An abandoned sentiment from past
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.
The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements. The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in a and b more than once in total.
Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.
null
In the first sample: - Sequence a is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in b are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
[{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}]
900
["constructive algorithms", "greedy", "implementation", "sortings"]
96
[{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\r\n80\r\n", "output": "No\r\n"}, {"input": "100 1\r\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\r\n58\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n2 1 0 4\r\n3\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n199 0\r\n200\r\n", "output": "No\r\n"}, {"input": "3 2\r\n115 0 0\r\n145 191\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n196 197 198 0 200\r\n199\r\n", "output": "No\r\n"}, {"input": "5 1\r\n92 0 97 99 100\r\n93\r\n", "output": "No\r\n"}, {"input": "3 1\r\n3 87 0\r\n81\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 92 192\r\n118\r\n", "output": "Yes\r\n"}, {"input": "10 1\r\n1 3 0 7 35 46 66 72 83 90\r\n22\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 0 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113\r\n67\r\n", "output": "No\r\n"}, {"input": "100 5\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 0 99 100\r\n98 64 55 52 29\r\n", "output": "Yes\r\n"}, {"input": "100 5\r\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\r\n121 199 62 193 27\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 0 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n11\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n1\r\n", "output": "No\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 0\r\n100\r\n", "output": "No\r\n"}, {"input": "100 1\r\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\r\n65\r\n", "output": "Yes\r\n"}, {"input": "100 2\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 0 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n48 1\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\r\n69\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\r\n129\r\n", "output": "No\r\n"}, {"input": "5 2\r\n0 2 7 0 10\r\n1 8\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 4 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 3\r\n4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n1\r\n", "output": "No\r\n"}, {"input": "2 1\r\n0 5\r\n7\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 0 12 13\r\n1\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n0 2 3 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 0 3 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "7 2\r\n1 2 3 0 0 6 7\r\n4 5\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "2 2\r\n0 0\r\n1 2\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n1 0 0\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 4 0\r\n5 2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 1\r\n2\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 4 5\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 2 3\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 5 0\r\n6\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 0 2\r\n7\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n4 5 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 12 0 14\r\n13\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 2 0 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 11 14\r\n12\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 3 0 4\r\n2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 5\r\n1\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 7\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 5 4\r\n6\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n11 0 0 14\r\n13 12\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n1 0\r\n2\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 0 3 2\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 2 3 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 2 0\r\n5\r\n", "output": "No\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 5 7\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 0 11\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n7 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 3 0 5 0\r\n6 4\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n0 1 0\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n6 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 3\r\n6\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 2 0 0 5\r\n4 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n2 0 0 8\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 0 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 2\r\n11 0 0 200\r\n100 199\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n5 0\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 5\r\n10\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 0 0 5 6\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 3 0 5\r\n2 4\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 4 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n5 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 7\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "3 3\r\n0 0 0\r\n1 4 3\r\n", "output": "Yes\r\n"}, {"input": "5 5\r\n0 0 0 0 0\r\n5 4 3 2 1\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n3 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 4 0 8 9 10\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 3 5 6\r\n9\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 2 0 0\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 4 5 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 0 4\r\n5\r\n", "output": "Yes\r\n"}]
false
stdio
null
true
127/B
127
B
Python 3
TESTS
69
78
204,800
121238118
from collections import defaultdict n = int(input()) arr = list(map(int,input().split())) dict = defaultdict(int) flag = False ans = 0 for x in arr: dict[x]+=1 if (dict[x]==2 or dict[x]==4) and flag==True: ans+=1 flag=False dict[x] = 0 if dict[x]==2 and flag==False: flag=True print(ans)
93
46
0
142645114
n=int(input()) ch=str(input()) l=[] l2=ch.split() for i in range (n) : l.append(l2[i]) s=set(l2) c=[] for i in s : c.append(l.count(i)) cpt=0 for i in range (len(c)) : cpt+=c[i]//2 print(cpt//2)
Codeforces Beta Round 93 (Div. 2 Only)
CF
2,011
1
256
Canvas Frames
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the sticks or glue them together. To make a h × w-sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w. Specifically, to make a square frame (when h = w), he needs four sticks of the same length. Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.
The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100).
Print the single number — the maximum number of frames Nicholas can make for his future canvases.
null
null
[{"input": "5\n2 4 3 2 3", "output": "1"}, {"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3"}, {"input": "4\n3 3 3 5", "output": "0"}]
1,000
["implementation"]
93
[{"input": "5\r\n2 4 3 2 3\r\n", "output": "1"}, {"input": "13\r\n2 2 4 4 4 4 6 6 6 7 7 9 9\r\n", "output": "3"}, {"input": "4\r\n3 3 3 5\r\n", "output": "0"}, {"input": "2\r\n3 5\r\n", "output": "0"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0"}, {"input": "14\r\n2 4 2 6 2 3 4 1 4 5 4 3 4 1\r\n", "output": "2"}, {"input": "33\r\n1 2 2 6 10 10 33 11 17 32 25 6 7 29 11 32 33 8 13 17 17 6 11 11 11 8 10 26 29 26 32 33 36\r\n", "output": "5"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n10\r\n", "output": "0"}, {"input": "2\r\n1 1\r\n", "output": "0"}, {"input": "3\r\n1 1 1\r\n", "output": "0"}, {"input": "3\r\n1 2 2\r\n", "output": "0"}, {"input": "3\r\n3 2 1\r\n", "output": "0"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1"}, {"input": "4\r\n1 2 1 2\r\n", "output": "1"}, {"input": "4\r\n1 100 1 100\r\n", "output": "1"}, {"input": "4\r\n10 100 100 10\r\n", "output": "1"}, {"input": "4\r\n1 2 3 3\r\n", "output": "0"}, {"input": "4\r\n8 5 9 13\r\n", "output": "0"}, {"input": "4\r\n100 100 100 100\r\n", "output": "1"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1"}, {"input": "5\r\n1 4 4 1 1\r\n", "output": "1"}, {"input": "5\r\n1 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 1 100 100 100\r\n", "output": "1"}, {"input": "5\r\n100 100 100 100 100\r\n", "output": "1"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "1"}, {"input": "6\r\n1 1 5 1 1 5\r\n", "output": "1"}, {"input": "6\r\n1 100 100 1 1 1\r\n", "output": "1"}, {"input": "6\r\n100 1 1 100 1 100\r\n", "output": "1"}, {"input": "6\r\n1 2 3 2 3 1\r\n", "output": "1"}, {"input": "6\r\n1 50 1 100 50 100\r\n", "output": "1"}, {"input": "6\r\n10 10 10 12 13 14\r\n", "output": "0"}, {"input": "7\r\n1 1 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 2 1 2 1 2\r\n", "output": "1"}, {"input": "7\r\n1 1 2 2 1 2 3\r\n", "output": "1"}, {"input": "7\r\n1 3 2 2 3 1 4\r\n", "output": "1"}, {"input": "7\r\n1 3 4 3 5 4 6\r\n", "output": "1"}, {"input": "7\r\n7 6 5 4 3 2 1\r\n", "output": "0"}, {"input": "8\r\n1 2 1 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 2 1 1 2 2 2\r\n", "output": "1"}, {"input": "8\r\n1 2 2 2 3 1 1 3\r\n", "output": "1"}, {"input": "8\r\n1 2 3 4 1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n1 1 1 1 2 3 2 3\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 5 5 5\r\n", "output": "1"}, {"input": "8\r\n1 2 1 3 4 1 5 6\r\n", "output": "0"}, {"input": "8\r\n1 2 3 4 5 6 1 7\r\n", "output": "0"}, {"input": "8\r\n8 6 3 4 5 2 1 7\r\n", "output": "0"}, {"input": "8\r\n100 100 100 100 100 100 100 100\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "10\r\n19 9 14 14 19 5 5 18 10 17\r\n", "output": "1"}, {"input": "10\r\n72 86 73 25 84 29 33 34 20 29\r\n", "output": "0"}, {"input": "10\r\n93 93 99 98 91 96 92 98 94 98\r\n", "output": "1"}, {"input": "13\r\n35 6 21 30 67 55 70 39 75 72 11 13 69\r\n", "output": "0"}, {"input": "17\r\n90 97 12 56 94 11 49 96 22 7 15 48 71 71 94 72 100\r\n", "output": "1"}, {"input": "18\r\n39 72 67 28 69 41 43 51 66 99 4 57 68 93 28 27 37 27\r\n", "output": "1"}, {"input": "23\r\n88 82 2 67 4 6 67 83 77 58 48 64 86 37 96 83 35 46 13 79 72 18 35\r\n", "output": "1"}, {"input": "30\r\n43 34 38 50 47 24 26 20 7 5 26 29 98 87 90 46 10 53 88 61 90 39 78 81 65 13 72 95 53 27\r\n", "output": "1"}, {"input": "33\r\n1 3 34 55 38 58 64 26 66 44 50 63 46 62 62 99 73 87 35 20 30 38 39 85 49 24 93 68 8 25 86 30 51\r\n", "output": "1"}, {"input": "38\r\n65 69 80 93 28 36 40 81 53 75 55 50 82 95 8 51 66 65 50 4 40 92 18 70 38 68 42 100 34 57 98 79 95 84 82 35 100 89\r\n", "output": "3"}, {"input": "40\r\n4 2 62 38 76 68 19 71 44 91 76 31 3 63 56 62 93 98 10 61 52 59 81 46 23 27 36 26 24 38 37 66 15 16 78 41 95 82 73 90\r\n", "output": "1"}, {"input": "43\r\n62 31 14 43 67 2 60 77 64 70 91 9 3 43 76 7 56 84 5 20 88 50 47 42 7 39 8 56 71 24 49 59 70 61 81 17 76 44 80 61 77 5 96\r\n", "output": "4"}, {"input": "49\r\n75 64 7 2 1 66 31 84 78 53 34 5 40 90 7 62 86 54 99 77 8 92 30 3 18 18 61 38 38 11 79 88 84 89 50 94 72 8 54 85 100 1 19 4 97 91 13 39 91\r\n", "output": "4"}, {"input": "57\r\n83 94 42 57 19 9 40 25 56 92 9 38 58 66 43 19 50 10 100 3 49 96 77 36 20 3 48 15 38 19 99 100 66 14 52 13 16 73 65 99 29 85 75 18 97 64 57 82 70 19 16 25 40 11 9 22 89\r\n", "output": "6"}, {"input": "67\r\n36 22 22 86 52 53 36 68 46 82 99 37 15 43 57 35 33 99 22 96 7 8 80 93 70 70 55 51 61 74 6 28 85 72 84 42 29 1 4 71 7 40 61 95 93 36 42 61 16 40 10 85 31 86 93 19 44 20 52 66 10 22 40 53 25 29 23\r\n", "output": "8"}, {"input": "74\r\n90 26 58 69 87 23 44 9 32 25 33 13 79 84 52 90 4 7 93 77 29 85 22 1 96 69 98 16 76 87 57 16 44 41 57 28 18 70 77 83 37 17 59 87 27 19 89 63 14 84 77 40 46 77 82 73 86 73 30 58 6 30 70 36 31 12 43 50 93 3 3 57 38 91\r\n", "output": "7"}, {"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": "25"}, {"input": "100\r\n1 9 3 5 10 10 9 8 10 1 7 6 5 6 7 9 1 5 8 3 2 3 3 10 2 3 10 7 10 3 6 3 2 10 1 10 2 3 4 3 3 1 7 5 10 2 3 8 9 2 5 4 7 2 5 9 2 1 7 9 9 8 4 4 6 1 6 6 4 7 2 3 1 1 1 6 9 1 2 9 3 7 6 10 3 6 2 5 2 5 3 9 10 6 4 2 9 9 4 5\r\n", "output": "23"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "7\r\n13 13 13 13 6 2 3\r\n", "output": "1"}, {"input": "8\r\n1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n100 100 99 99 5\r\n", "output": "1"}, {"input": "8\r\n2 2 2 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 6 7 7\r\n", "output": "0"}, {"input": "8\r\n4 4 4 4 4 4 4 4\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 2 2\r\n", "output": "2"}, {"input": "4\r\n100 100 100 99\r\n", "output": "0"}, {"input": "4\r\n2 2 2 2\r\n", "output": "1"}, {"input": "5\r\n100 100 99 99 2\r\n", "output": "1"}, {"input": "9\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n2 2 3 4 4\r\n", "output": "1"}, {"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": "25"}, {"input": "13\r\n1 2 3 4 5 6 7 8 9 10 11 12 13\r\n", "output": "0"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "4\r\n4 4 4 4\r\n", "output": "1"}, {"input": "5\r\n1 1 2 3 3\r\n", "output": "1"}, {"input": "5\r\n30 30 30 1 1\r\n", "output": "1"}]
false
stdio
null
true
828/B
828
B
Python 3
TESTS
21
61
307,200
109625291
n, m = list(map(int, input().split())) sheet = [] for i in range(n): sheet.append(input()) min_row = 101 max_row = -1 min_col = 101 max_col = -1 for i in range(n): for j in range(m): if sheet[i][j] == 'B': min_row = min(min_row, i) max_row = max(max_row, i) min_col = min(min_col, j) max_col = max(max_col, j) l = max_row - min_row + 1 b = max_col - min_col + 1 # print(min_row, max_row) # print(min_col, max_col) if min_row == 101 and max_row == -1 and min_col == 101 and max_col == -1: print(1) else: impossible=False if l < b: d = b - l if min_row - d >= 0: min_row = min_row - d else: d = d - (min_row - 0) min_row = 0 if max_row + d < n: max_row = max_row + d else: impossible=True elif l > b: d = l - b if min_col - d >= 0: min_col = min_col - d d = 0 else: d = d - (min_col - 0) min_col = 0 if max_col + d < m: max_col = max_col + d else: impossible=True if not impossible: count = 0 for row in range(min_row, max_row+1): for col in range(min_col, max_col+1): if sheet[row][col] == 'W': count +=1 print(count) else: print("-1")
128
62
4,608,000
28722692
n, m = map(int, input().split()) a = [input() for i in range(n)] x1 = y1 = 10 ** 10 x2 = y2 = -1 cnt = 0 for i in range(n): for j in range(m): if a[i][j] == 'B': x1 = min(x1, i) x2 = max(x2, i) y1 = min(y1, j) y2 = max(y2, j) cnt += 1 dx = x2 - x1 + 1 dy = y2 - y1 + 1 if cnt == 0: ans = 1 elif max(dx, dy) <= min(n, m): ans = max(dx, dy)**2 - cnt else: ans = -1 print(ans)
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Black Square
Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
null
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third example all cells are colored white, so it's sufficient to color any cell black.
[{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}]
1,300
["implementation"]
128
[{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "-1\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "2 4\r\nWWWW\r\nWBWW\r\n", "output": "0\r\n"}, {"input": "4 5\r\nWWWWW\r\nBBWWW\r\nBBWWW\r\nWWWWW\r\n", "output": "0\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "10 5\r\nWWWWB\r\nWWWWW\r\nWWWBB\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "12\r\n"}, {"input": "5 10\r\nWWWWWWWWWW\r\nWWWWBWBBWW\r\nWWWWWWWWWW\r\nWWWWBWWWWW\r\nWWWWWWBWWW\r\n", "output": "11\r\n"}, {"input": "20 10\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWBBWBWWWW\r\nWWBWWBWWWW\r\nWWWWBWWWWW\r\nWWWWBWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\n", "output": "9\r\n"}, {"input": "10 20\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWBW\r\nWWWWWWWWWWWWWWWWWBWW\r\nWWWWWWWWWWWWWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nWW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nWW\r\nWB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWB\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBW\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nBW\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nWW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBB\r\nWB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nWW\r\n", "output": "1\r\n"}, {"input": "1 2\r\nWB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nW\r\nW\r\n", "output": "1\r\n"}, {"input": "2 1\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "20 10\r\nWWBWWWBBWW\r\nWWWWWBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWBBBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWBWWWWWBWW\r\nWBWWBWWWBW\r\nWWBWBWWWWW\r\nWWWBWWBBWW\r\nWWBBWBWBWW\r\nBBWWWWWBWW\r\nWWBWWBBBWW\r\nWWWBWBBWWW\r\nWWWBBWBWWW\r\nWWWWWWWWWW\r\nWWWBWWWWWW\r\nWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "10 20\r\nWWWWWWWBWWWWWWWBWWWB\r\nWWWBWWWBWWWWWWWWWWWW\r\nBWWWWWWWWWWWWWWWWWBB\r\nWWWWWWBWWBWWBWWWBWWW\r\nWWWWWWWWBWWBWWWBWWWW\r\nWBWWWWWWWBWWWWWWWWWW\r\nWWWBWBWWBWWWWWBBWWWB\r\nWWBBWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWBWWWWBW\r\nWWWWWWWWWWWWBWWBWWWB\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "-1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "1 5\r\nWBBWW\r\n", "output": "-1\r\n"}, {"input": "20 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWBW\r\nWBB\r\nWWW\r\n", "output": "1\r\n"}, {"input": "4 6\r\nWWWWWW\r\nWWWBWW\r\nWWWWWB\r\nWWWWWW\r\n", "output": "7\r\n"}, {"input": "5 5\r\nWBWBW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "7\r\n"}, {"input": "3 3\r\nBBB\r\nBBB\r\nBBB\r\n", "output": "0\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWBWW\r\n", "output": "23\r\n"}, {"input": "5 4\r\nWWBW\r\nBWWB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "13\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWWW\r\nWBBW\r\n", "output": "12\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWBWW\r\n", "output": "34\r\n"}, {"input": "3 3\r\nBBW\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "3 3\r\nBWB\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "6 6\r\nWBWWWW\r\nBWWWBW\r\nWWWWWW\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "21\r\n"}, {"input": "3 3\r\nWWW\r\nWBW\r\nWWW\r\n", "output": "0\r\n"}, {"input": "3 3\r\nBBB\r\nWWW\r\nWWW\r\n", "output": "6\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWBWW\r\nWBBBW\r\nWWBWW\r\nWWBWW\r\n", "output": "18\r\n"}, {"input": "5 2\r\nWB\r\nWB\r\nWB\r\nWW\r\nWW\r\n", "output": "-1\r\n"}, {"input": "4 7\r\nBBBBBWW\r\nWWWWWWW\r\nWWWWWWW\r\nWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWBB\r\nWWWW\r\n", "output": "6\r\n"}, {"input": "4 4\r\nWWWW\r\nWBWW\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "2 5\r\nWWWWW\r\nBBBWW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWBW\r\nWWWWWW\r\nWWWWWW\r\nWWBWWW\r\n", "output": "33\r\n"}, {"input": "3 3\r\nWBW\r\nWBW\r\nWBW\r\n", "output": "6\r\n"}, {"input": "3 5\r\nWWBBB\r\nBWBBB\r\nWWBBB\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWB\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "22\r\n"}, {"input": "5 5\r\nBWWWB\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nBWWWW\r\n", "output": "22\r\n"}, {"input": "4 5\r\nWWWWW\r\nBWWWW\r\nBBBWW\r\nWWWWW\r\n", "output": "5\r\n"}, {"input": "4 4\r\nBBBB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "12\r\n"}, {"input": "4 6\r\nWWWWWW\r\nBWWWWW\r\nBWWWWW\r\nBBBBBB\r\n", "output": "-1\r\n"}, {"input": "3 6\r\nWWWWWW\r\nBBBWWW\r\nWWWWWW\r\n", "output": "6\r\n"}, {"input": "5 2\r\nWW\r\nBW\r\nBW\r\nBB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nBBBBB\r\nWWWWW\r\nWWWWW\r\n", "output": "20\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nWWWWB\r\nWBWWW\r\nWWWWW\r\n", "output": "14\r\n"}, {"input": "1 5\r\nWWBWW\r\n", "output": "0\r\n"}, {"input": "1 3\r\nBBB\r\n", "output": "-1\r\n"}, {"input": "2 4\r\nWWBW\r\nBWBW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nBBBBBB\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "30\r\n"}, {"input": "4 4\r\nWWWW\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWB\r\n", "output": "0\r\n"}, {"input": "5 1\r\nB\r\nB\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "2 3\r\nWBW\r\nWBW\r\n", "output": "2\r\n"}, {"input": "5 2\r\nWW\r\nWB\r\nWB\r\nWB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "23\r\n"}]
false
stdio
null
true
127/B
127
B
Python 3
TESTS
40
78
7,065,600
38907404
n = int(input()) a = list(map(int,input().split())) hm = [0]*110 for i in a: hm[i]+=1 c = 0 for i in range(110): if(hm[i]>=4): c+=hm[i]//4 hm[i]-=c*hm[i] elif(hm[i]>=2): for j in range(i+1,110): if(hm[j]>=2 and hm[j]<4): c+=1 hm[i]-=2 hm[j]-=2 break print(c)
93
46
0
148727054
n = int(input()) L = list(map(int,input().split())) izmeri= {} atbildes = 0 for skaitlis in L: if skaitlis in izmeri: izmeri[skaitlis] +=1 else: izmeri[skaitlis] = 1 for x in izmeri : atbildes += izmeri[x]//2 print(atbildes//2)
Codeforces Beta Round 93 (Div. 2 Only)
CF
2,011
1
256
Canvas Frames
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the sticks or glue them together. To make a h × w-sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w. Specifically, to make a square frame (when h = w), he needs four sticks of the same length. Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.
The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100).
Print the single number — the maximum number of frames Nicholas can make for his future canvases.
null
null
[{"input": "5\n2 4 3 2 3", "output": "1"}, {"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3"}, {"input": "4\n3 3 3 5", "output": "0"}]
1,000
["implementation"]
93
[{"input": "5\r\n2 4 3 2 3\r\n", "output": "1"}, {"input": "13\r\n2 2 4 4 4 4 6 6 6 7 7 9 9\r\n", "output": "3"}, {"input": "4\r\n3 3 3 5\r\n", "output": "0"}, {"input": "2\r\n3 5\r\n", "output": "0"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0"}, {"input": "14\r\n2 4 2 6 2 3 4 1 4 5 4 3 4 1\r\n", "output": "2"}, {"input": "33\r\n1 2 2 6 10 10 33 11 17 32 25 6 7 29 11 32 33 8 13 17 17 6 11 11 11 8 10 26 29 26 32 33 36\r\n", "output": "5"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n10\r\n", "output": "0"}, {"input": "2\r\n1 1\r\n", "output": "0"}, {"input": "3\r\n1 1 1\r\n", "output": "0"}, {"input": "3\r\n1 2 2\r\n", "output": "0"}, {"input": "3\r\n3 2 1\r\n", "output": "0"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1"}, {"input": "4\r\n1 2 1 2\r\n", "output": "1"}, {"input": "4\r\n1 100 1 100\r\n", "output": "1"}, {"input": "4\r\n10 100 100 10\r\n", "output": "1"}, {"input": "4\r\n1 2 3 3\r\n", "output": "0"}, {"input": "4\r\n8 5 9 13\r\n", "output": "0"}, {"input": "4\r\n100 100 100 100\r\n", "output": "1"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1"}, {"input": "5\r\n1 4 4 1 1\r\n", "output": "1"}, {"input": "5\r\n1 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 1 100 100 100\r\n", "output": "1"}, {"input": "5\r\n100 100 100 100 100\r\n", "output": "1"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "1"}, {"input": "6\r\n1 1 5 1 1 5\r\n", "output": "1"}, {"input": "6\r\n1 100 100 1 1 1\r\n", "output": "1"}, {"input": "6\r\n100 1 1 100 1 100\r\n", "output": "1"}, {"input": "6\r\n1 2 3 2 3 1\r\n", "output": "1"}, {"input": "6\r\n1 50 1 100 50 100\r\n", "output": "1"}, {"input": "6\r\n10 10 10 12 13 14\r\n", "output": "0"}, {"input": "7\r\n1 1 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 2 1 2 1 2\r\n", "output": "1"}, {"input": "7\r\n1 1 2 2 1 2 3\r\n", "output": "1"}, {"input": "7\r\n1 3 2 2 3 1 4\r\n", "output": "1"}, {"input": "7\r\n1 3 4 3 5 4 6\r\n", "output": "1"}, {"input": "7\r\n7 6 5 4 3 2 1\r\n", "output": "0"}, {"input": "8\r\n1 2 1 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 2 1 1 2 2 2\r\n", "output": "1"}, {"input": "8\r\n1 2 2 2 3 1 1 3\r\n", "output": "1"}, {"input": "8\r\n1 2 3 4 1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n1 1 1 1 2 3 2 3\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 5 5 5\r\n", "output": "1"}, {"input": "8\r\n1 2 1 3 4 1 5 6\r\n", "output": "0"}, {"input": "8\r\n1 2 3 4 5 6 1 7\r\n", "output": "0"}, {"input": "8\r\n8 6 3 4 5 2 1 7\r\n", "output": "0"}, {"input": "8\r\n100 100 100 100 100 100 100 100\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "10\r\n19 9 14 14 19 5 5 18 10 17\r\n", "output": "1"}, {"input": "10\r\n72 86 73 25 84 29 33 34 20 29\r\n", "output": "0"}, {"input": "10\r\n93 93 99 98 91 96 92 98 94 98\r\n", "output": "1"}, {"input": "13\r\n35 6 21 30 67 55 70 39 75 72 11 13 69\r\n", "output": "0"}, {"input": "17\r\n90 97 12 56 94 11 49 96 22 7 15 48 71 71 94 72 100\r\n", "output": "1"}, {"input": "18\r\n39 72 67 28 69 41 43 51 66 99 4 57 68 93 28 27 37 27\r\n", "output": "1"}, {"input": "23\r\n88 82 2 67 4 6 67 83 77 58 48 64 86 37 96 83 35 46 13 79 72 18 35\r\n", "output": "1"}, {"input": "30\r\n43 34 38 50 47 24 26 20 7 5 26 29 98 87 90 46 10 53 88 61 90 39 78 81 65 13 72 95 53 27\r\n", "output": "1"}, {"input": "33\r\n1 3 34 55 38 58 64 26 66 44 50 63 46 62 62 99 73 87 35 20 30 38 39 85 49 24 93 68 8 25 86 30 51\r\n", "output": "1"}, {"input": "38\r\n65 69 80 93 28 36 40 81 53 75 55 50 82 95 8 51 66 65 50 4 40 92 18 70 38 68 42 100 34 57 98 79 95 84 82 35 100 89\r\n", "output": "3"}, {"input": "40\r\n4 2 62 38 76 68 19 71 44 91 76 31 3 63 56 62 93 98 10 61 52 59 81 46 23 27 36 26 24 38 37 66 15 16 78 41 95 82 73 90\r\n", "output": "1"}, {"input": "43\r\n62 31 14 43 67 2 60 77 64 70 91 9 3 43 76 7 56 84 5 20 88 50 47 42 7 39 8 56 71 24 49 59 70 61 81 17 76 44 80 61 77 5 96\r\n", "output": "4"}, {"input": "49\r\n75 64 7 2 1 66 31 84 78 53 34 5 40 90 7 62 86 54 99 77 8 92 30 3 18 18 61 38 38 11 79 88 84 89 50 94 72 8 54 85 100 1 19 4 97 91 13 39 91\r\n", "output": "4"}, {"input": "57\r\n83 94 42 57 19 9 40 25 56 92 9 38 58 66 43 19 50 10 100 3 49 96 77 36 20 3 48 15 38 19 99 100 66 14 52 13 16 73 65 99 29 85 75 18 97 64 57 82 70 19 16 25 40 11 9 22 89\r\n", "output": "6"}, {"input": "67\r\n36 22 22 86 52 53 36 68 46 82 99 37 15 43 57 35 33 99 22 96 7 8 80 93 70 70 55 51 61 74 6 28 85 72 84 42 29 1 4 71 7 40 61 95 93 36 42 61 16 40 10 85 31 86 93 19 44 20 52 66 10 22 40 53 25 29 23\r\n", "output": "8"}, {"input": "74\r\n90 26 58 69 87 23 44 9 32 25 33 13 79 84 52 90 4 7 93 77 29 85 22 1 96 69 98 16 76 87 57 16 44 41 57 28 18 70 77 83 37 17 59 87 27 19 89 63 14 84 77 40 46 77 82 73 86 73 30 58 6 30 70 36 31 12 43 50 93 3 3 57 38 91\r\n", "output": "7"}, {"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": "25"}, {"input": "100\r\n1 9 3 5 10 10 9 8 10 1 7 6 5 6 7 9 1 5 8 3 2 3 3 10 2 3 10 7 10 3 6 3 2 10 1 10 2 3 4 3 3 1 7 5 10 2 3 8 9 2 5 4 7 2 5 9 2 1 7 9 9 8 4 4 6 1 6 6 4 7 2 3 1 1 1 6 9 1 2 9 3 7 6 10 3 6 2 5 2 5 3 9 10 6 4 2 9 9 4 5\r\n", "output": "23"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "7\r\n13 13 13 13 6 2 3\r\n", "output": "1"}, {"input": "8\r\n1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n100 100 99 99 5\r\n", "output": "1"}, {"input": "8\r\n2 2 2 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 6 7 7\r\n", "output": "0"}, {"input": "8\r\n4 4 4 4 4 4 4 4\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 2 2\r\n", "output": "2"}, {"input": "4\r\n100 100 100 99\r\n", "output": "0"}, {"input": "4\r\n2 2 2 2\r\n", "output": "1"}, {"input": "5\r\n100 100 99 99 2\r\n", "output": "1"}, {"input": "9\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n2 2 3 4 4\r\n", "output": "1"}, {"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": "25"}, {"input": "13\r\n1 2 3 4 5 6 7 8 9 10 11 12 13\r\n", "output": "0"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "4\r\n4 4 4 4\r\n", "output": "1"}, {"input": "5\r\n1 1 2 3 3\r\n", "output": "1"}, {"input": "5\r\n30 30 30 1 1\r\n", "output": "1"}]
false
stdio
null
true
828/B
828
B
Python 3
TESTS
21
62
5,529,600
28438413
n, m = map(int, input().split()) f = [input() for _ in range(n)] first, last = (n + 1, m + 1), (-1, -1) black = 0 for i in range(n): for j in range(m): if f[i][j] == "B": first = min(first, (i, j)) last = max(last, (i, j)) black += 1 h = last[0] - first[0] + 1 w = last[1] - first[1] + 1 if last == (-1, -1): print(1) else: if max(h, w) > n or max(h, w) > m: print(-1) else: print(max(h, w) * max(h, w) - black)
128
62
4,608,000
28781017
(n, m) = (int(i) for i in input().split()) top = -1 left = 101 right = -1 down = -1 cnt = 0 for i in range(n): read = input() for j in range(m): cur = read[j]=='B' if not cur: continue cnt += 1 if top==-1: top = i if j<left: left = j if j>right: right = j down = i stor = max(down-top, right-left)+1 if n<stor or m<stor: print(-1) else: print(stor**2 - cnt)
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Black Square
Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
null
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third example all cells are colored white, so it's sufficient to color any cell black.
[{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}]
1,300
["implementation"]
128
[{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "-1\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "2 4\r\nWWWW\r\nWBWW\r\n", "output": "0\r\n"}, {"input": "4 5\r\nWWWWW\r\nBBWWW\r\nBBWWW\r\nWWWWW\r\n", "output": "0\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "10 5\r\nWWWWB\r\nWWWWW\r\nWWWBB\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "12\r\n"}, {"input": "5 10\r\nWWWWWWWWWW\r\nWWWWBWBBWW\r\nWWWWWWWWWW\r\nWWWWBWWWWW\r\nWWWWWWBWWW\r\n", "output": "11\r\n"}, {"input": "20 10\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWBBWBWWWW\r\nWWBWWBWWWW\r\nWWWWBWWWWW\r\nWWWWBWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\n", "output": "9\r\n"}, {"input": "10 20\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWBW\r\nWWWWWWWWWWWWWWWWWBWW\r\nWWWWWWWWWWWWWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nWW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nWW\r\nWB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWB\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBW\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nBW\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nWW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBB\r\nWB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nWW\r\n", "output": "1\r\n"}, {"input": "1 2\r\nWB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nW\r\nW\r\n", "output": "1\r\n"}, {"input": "2 1\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "20 10\r\nWWBWWWBBWW\r\nWWWWWBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWBBBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWBWWWWWBWW\r\nWBWWBWWWBW\r\nWWBWBWWWWW\r\nWWWBWWBBWW\r\nWWBBWBWBWW\r\nBBWWWWWBWW\r\nWWBWWBBBWW\r\nWWWBWBBWWW\r\nWWWBBWBWWW\r\nWWWWWWWWWW\r\nWWWBWWWWWW\r\nWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "10 20\r\nWWWWWWWBWWWWWWWBWWWB\r\nWWWBWWWBWWWWWWWWWWWW\r\nBWWWWWWWWWWWWWWWWWBB\r\nWWWWWWBWWBWWBWWWBWWW\r\nWWWWWWWWBWWBWWWBWWWW\r\nWBWWWWWWWBWWWWWWWWWW\r\nWWWBWBWWBWWWWWBBWWWB\r\nWWBBWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWBWWWWBW\r\nWWWWWWWWWWWWBWWBWWWB\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "-1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "1 5\r\nWBBWW\r\n", "output": "-1\r\n"}, {"input": "20 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWBW\r\nWBB\r\nWWW\r\n", "output": "1\r\n"}, {"input": "4 6\r\nWWWWWW\r\nWWWBWW\r\nWWWWWB\r\nWWWWWW\r\n", "output": "7\r\n"}, {"input": "5 5\r\nWBWBW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "7\r\n"}, {"input": "3 3\r\nBBB\r\nBBB\r\nBBB\r\n", "output": "0\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWBWW\r\n", "output": "23\r\n"}, {"input": "5 4\r\nWWBW\r\nBWWB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "13\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWWW\r\nWBBW\r\n", "output": "12\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWBWW\r\n", "output": "34\r\n"}, {"input": "3 3\r\nBBW\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "3 3\r\nBWB\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "6 6\r\nWBWWWW\r\nBWWWBW\r\nWWWWWW\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "21\r\n"}, {"input": "3 3\r\nWWW\r\nWBW\r\nWWW\r\n", "output": "0\r\n"}, {"input": "3 3\r\nBBB\r\nWWW\r\nWWW\r\n", "output": "6\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWBWW\r\nWBBBW\r\nWWBWW\r\nWWBWW\r\n", "output": "18\r\n"}, {"input": "5 2\r\nWB\r\nWB\r\nWB\r\nWW\r\nWW\r\n", "output": "-1\r\n"}, {"input": "4 7\r\nBBBBBWW\r\nWWWWWWW\r\nWWWWWWW\r\nWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWBB\r\nWWWW\r\n", "output": "6\r\n"}, {"input": "4 4\r\nWWWW\r\nWBWW\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "2 5\r\nWWWWW\r\nBBBWW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWBW\r\nWWWWWW\r\nWWWWWW\r\nWWBWWW\r\n", "output": "33\r\n"}, {"input": "3 3\r\nWBW\r\nWBW\r\nWBW\r\n", "output": "6\r\n"}, {"input": "3 5\r\nWWBBB\r\nBWBBB\r\nWWBBB\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWB\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "22\r\n"}, {"input": "5 5\r\nBWWWB\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nBWWWW\r\n", "output": "22\r\n"}, {"input": "4 5\r\nWWWWW\r\nBWWWW\r\nBBBWW\r\nWWWWW\r\n", "output": "5\r\n"}, {"input": "4 4\r\nBBBB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "12\r\n"}, {"input": "4 6\r\nWWWWWW\r\nBWWWWW\r\nBWWWWW\r\nBBBBBB\r\n", "output": "-1\r\n"}, {"input": "3 6\r\nWWWWWW\r\nBBBWWW\r\nWWWWWW\r\n", "output": "6\r\n"}, {"input": "5 2\r\nWW\r\nBW\r\nBW\r\nBB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nBBBBB\r\nWWWWW\r\nWWWWW\r\n", "output": "20\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nWWWWB\r\nWBWWW\r\nWWWWW\r\n", "output": "14\r\n"}, {"input": "1 5\r\nWWBWW\r\n", "output": "0\r\n"}, {"input": "1 3\r\nBBB\r\n", "output": "-1\r\n"}, {"input": "2 4\r\nWWBW\r\nBWBW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nBBBBBB\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "30\r\n"}, {"input": "4 4\r\nWWWW\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWB\r\n", "output": "0\r\n"}, {"input": "5 1\r\nB\r\nB\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "2 3\r\nWBW\r\nWBW\r\n", "output": "2\r\n"}, {"input": "5 2\r\nWW\r\nWB\r\nWB\r\nWB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "23\r\n"}]
false
stdio
null
true
962/A
962
A
Python 3
TESTS
10
171
19,660,800
37295648
numberOfDays = input() numberOfProblems = [int(x) for x in input().split()] sumOfnumberOfProblemsArray = sum(numberOfProblems) if sumOfnumberOfProblemsArray % 2 == 0: halfSize = sumOfnumberOfProblemsArray / 2 else: halfSize = sumOfnumberOfProblemsArray / 2 + 1 halfSize = round(halfSize) helper = 0 for i in range(0, len(numberOfProblems)): helper += numberOfProblems[i] if helper >= halfSize: print(i + 1) break
106
93
13,516,800
138027483
n = int(input()) a = [*map(int, input().split())] S = sum(a); s = 0 for i in range(n): s += a[i] if 2*s >= S: print(i+1) break
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Equator
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first. On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems. Determine the index of day when Polycarp will celebrate the equator.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
Print the index of the day when Polycarp will celebrate the equator.
null
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
[{"input": "4\n1 3 2 1", "output": "2"}, {"input": "6\n2 2 2 2 2 2", "output": "3"}]
1,300
["implementation"]
106
[{"input": "4\r\n1 3 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n2 2 2 2 2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n10000\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 1 1 3\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 3\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "2\r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n"}, {"input": "3\r\n2 1 2\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 4 3 5\r\n", "output": "4\r\n"}, {"input": "5\r\n2 2 2 4 3\r\n", "output": "4\r\n"}, {"input": "4\r\n1 2 3 1\r\n", "output": "3\r\n"}, {"input": "6\r\n7 3 10 7 3 11\r\n", "output": "4\r\n"}, {"input": "2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "4\r\n1 3 2 3\r\n", "output": "3\r\n"}, {"input": "2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "3\r\n32 10 23\r\n", "output": "2\r\n"}, {"input": "7\r\n1 1 1 1 1 1 1\r\n", "output": "4\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "3\r\n"}, {"input": "6\r\n3 3 3 2 4 4\r\n", "output": "4\r\n"}, {"input": "9\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 3 1 1\r\n", "output": "3\r\n"}, {"input": "4\r\n1 1 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 1 3\r\n", "output": "3\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "2\r\n"}, {"input": "4\r\n2 3 3 3\r\n", "output": "3\r\n"}, {"input": "4\r\n3 2 3 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 1 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 1 4\r\n", "output": "3\r\n"}, {"input": "2\r\n6 7\r\n", "output": "2\r\n"}, {"input": "4\r\n3 3 4 3\r\n", "output": "3\r\n"}, {"input": "4\r\n1 1 2 5\r\n", "output": "4\r\n"}, {"input": "4\r\n1 8 7 3\r\n", "output": "3\r\n"}, {"input": "6\r\n2 2 2 2 2 3\r\n", "output": "4\r\n"}, {"input": "3\r\n2 2 5\r\n", "output": "3\r\n"}, {"input": "4\r\n1 1 2 1\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 2 2 3\r\n", "output": "4\r\n"}, {"input": "5\r\n9 5 3 4 8\r\n", "output": "3\r\n"}, {"input": "3\r\n3 3 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 2 2\r\n", "output": "3\r\n"}, {"input": "3\r\n1 3 5\r\n", "output": "3\r\n"}, {"input": "4\r\n1 1 3 6\r\n", "output": "4\r\n"}, {"input": "6\r\n1 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 1 3\r\n", "output": "2\r\n"}, {"input": "5\r\n3 4 5 1 2\r\n", "output": "3\r\n"}, {"input": "11\r\n1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "6\r\n"}, {"input": "5\r\n3 1 2 5 2\r\n", "output": "4\r\n"}, {"input": "4\r\n1 1 1 4\r\n", "output": "4\r\n"}, {"input": "4\r\n2 6 1 10\r\n", "output": "4\r\n"}, {"input": "4\r\n2 2 3 2\r\n", "output": "3\r\n"}, {"input": "4\r\n4 2 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n1 1 1 1 1 4\r\n", "output": "5\r\n"}, {"input": "3\r\n3 2 2\r\n", "output": "2\r\n"}, {"input": "6\r\n1 3 5 1 7 4\r\n", "output": "5\r\n"}, {"input": "5\r\n1 2 4 8 16\r\n", "output": "5\r\n"}, {"input": "5\r\n1 2 4 4 4\r\n", "output": "4\r\n"}, {"input": "6\r\n4 2 1 2 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n3 2 1 5\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 4 7\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 1 1 3\r\n", "output": "4\r\n"}, {"input": "3\r\n3 1 5\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 3 7\r\n", "output": "4\r\n"}, {"input": "3\r\n1 4 6\r\n", "output": "3\r\n"}, {"input": "4\r\n2 1 2 2\r\n", "output": "3\r\n"}, {"input": "2\r\n4 5\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 1 2 1\r\n", "output": "3\r\n"}, {"input": "3\r\n2 3 6\r\n", "output": "3\r\n"}, {"input": "6\r\n1 1 4 1 1 5\r\n", "output": "4\r\n"}, {"input": "5\r\n2 2 2 2 1\r\n", "output": "3\r\n"}, {"input": "2\r\n5 6\r\n", "output": "2\r\n"}, {"input": "4\r\n2 2 1 4\r\n", "output": "3\r\n"}, {"input": "5\r\n2 2 3 4 4\r\n", "output": "4\r\n"}, {"input": "4\r\n3 1 1 2\r\n", "output": "2\r\n"}, {"input": "5\r\n3 4 1 4 5\r\n", "output": "4\r\n"}, {"input": "4\r\n1 3 1 6\r\n", "output": "4\r\n"}, {"input": "5\r\n1 1 1 2 2\r\n", "output": "4\r\n"}, {"input": "4\r\n1 4 2 4\r\n", "output": "3\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 8\r\n", "output": "9\r\n"}, {"input": "4\r\n1 4 5 1\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 1 1 5\r\n", "output": "5\r\n"}, {"input": "4\r\n1 3 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 2 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 3 2 4\r\n", "output": "3\r\n"}, {"input": "5\r\n2 2 1 2 2\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 2\r\n", "output": "2\r\n"}, {"input": "3\r\n6 5 2\r\n", "output": "2\r\n"}, {"input": "69\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\r\n", "output": "35\r\n"}, {"input": "6\r\n1 1 1 1 1 2\r\n", "output": "4\r\n"}, {"input": "5\r\n1 2 5 4 5\r\n", "output": "4\r\n"}, {"input": "2\r\n9 10\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 5\r\n", "output": "3\r\n"}, {"input": "4\r\n3 4 3 5\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 3 3\r\n", "output": "3\r\n"}, {"input": "4\r\n7 1 3 4\r\n", "output": "2\r\n"}, {"input": "3\r\n100 100 1\r\n", "output": "2\r\n"}, {"input": "4\r\n5 2 2 2\r\n", "output": "2\r\n"}]
false
stdio
null
true
356/C
356
C
Python 3
TESTS
65
405
10,649,600
5635395
n = int(input()) A = [0, 0, 0, 0, 0] B = map(int, input().split(' ')) for i in B: A[i] += 1 res = min(A[1], A[2]) A[1] -= res A[2] -= res res += 2 * (A[1] // 3) A[3] += A[1] // 3 A[1] %= 3 res += 2 * (A[2] // 3) A[3] += 2 * (A[2] // 3) A[2] %= 3 assert(A[1] == 0 or A[2] == 0) if (A[1] == 1): if (A[3] > 0): res += 1 #; A[1] = 0; A[3] -= 1; A[4] += 1 elif (A[4] > 1): res += 2 #; A[1] = 0; A[4] -= 2; A[3] += 3 else: print(-1) exit() elif (A[1] == 2): if (A[4] > 0): res += 2 #; A[1] = 0; A[4] -= 1; A[3] += 1 elif (A[3] > 1): res += 2 #; A[1] = 0; A[3] -= 2; A[4] += 2 else: print(-1) exit() if (A[2] == 1): if (A[4] > 0): res += 1 #; A[4] -= 1; A[2] = 0; A[3] += 1 elif (A[3] > 1): res += 2; #; A[2] = 0; A[3] -= 2; A[4] += 2 else: print(-1) exit() elif (A[2] == 2): res += 2 #; A[2] = 0; A[4] += 1 print(res)
141
607
14,745,600
42135284
#! /usr/bin/env python n = int(input()) counts = [0] * 5 nums = [int(x) for x in input().split()] for x in nums: counts[x] += 1 s = sum(nums) if s > 2 and s != 5: ans = 0 if counts[1] >= counts[2]: ans += counts[2] counts[3] += counts[2] counts[1] -= counts[2] ans += 2 * (counts[1] // 3) counts[3] += counts[1] // 3 counts[1] %= 3 if counts[3] > 0: ans += counts[1] elif counts[1] != 0: ans += 2 else: ans += counts[1] counts[2] -= counts[1] ans += 2 * (counts[2] // 3) counts[2] %= 3 if counts[4] > 0: ans += counts[2] elif counts[2] != 0: ans += 2 print(ans) else: print(-1) # Made By Mostafa_Khaled
Codeforces Round 207 (Div. 1)
CF
2,013
1
256
Compartments
A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip. The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student. However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number. After all the swaps each compartment should either have no student left, or have a company of three or four students.
The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train.
If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places.
null
null
[{"input": "5\n1 2 2 4 3", "output": "2"}, {"input": "3\n4 1 1", "output": "2"}, {"input": "4\n0 3 0 4", "output": "0"}]
2,100
["combinatorics", "constructive algorithms", "greedy", "implementation"]
141
[{"input": "5\r\n1 2 2 4 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n0 3 0 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 4 3 3 1\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 4\r\n", "output": "1\r\n"}, {"input": "10\r\n2 1 2 3 4 1 3 4 4 4\r\n", "output": "2\r\n"}, {"input": "10\r\n2 3 3 1 3 1 3 2 2 4\r\n", "output": "3\r\n"}, {"input": "120\r\n1 1 1 1 1 1 1 4 4 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 4 1 1 4 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 2 4 1 1 3 1 1 1 2 1 0 3 1 1 1 2 1 4 1 1 1 1 1 1 1 1 1 1\r\n", "output": "69\r\n"}, {"input": "10\r\n2 4 1 3 1 2 2 2 2 2\r\n", "output": "5\r\n"}, {"input": "10\r\n3 4 2 2 1 1 3 1 1 2\r\n", "output": "4\r\n"}, {"input": "20\r\n4 1 4 4 2 1 4 3 2 3 1 1 2 2 2 4 4 2 4 2\r\n", "output": "6\r\n"}, {"input": "20\r\n4 3 4 2 1 1 3 1 4 2 1 4 3 3 4 3 1 1 1 3\r\n", "output": "6\r\n"}, {"input": "20\r\n4 1 1 1 4 2 3 3 2 1 1 4 4 3 1 1 2 4 2 3\r\n", "output": "6\r\n"}, {"input": "20\r\n4 4 2 4 3 2 3 1 4 1 1 4 1 4 3 4 4 3 3 3\r\n", "output": "4\r\n"}, {"input": "20\r\n4 2 3 3 1 3 2 3 1 4 4 4 2 1 4 2 1 3 4 4\r\n", "output": "4\r\n"}, {"input": "23\r\n2 3 1 1 1 1 4 3 2 2 3 3 4 1 4 2 4 1 4 2 3 1 1\r\n", "output": "7\r\n"}, {"input": "27\r\n0 2 4 1 4 2 1 2 3 4 2 4 1 2 3 2 3 2 2 1 0 4 3 0 3 0 1\r\n", "output": "7\r\n"}, {"input": "28\r\n2 0 4 2 3 4 1 1 4 3 0 3 0 3 2 3 2 4 1 2 4 3 3 3 0 1 0 1\r\n", "output": "5\r\n"}, {"input": "24\r\n4 2 4 3 1 3 4 1 3 4 2 4 0 2 3 4 1 1 4 3 1 2 2 4\r\n", "output": "5\r\n"}, {"input": "19\r\n2 4 4 2 0 0 1 4 1 0 2 2 4 2 0 1 1 1 4\r\n", "output": "5\r\n"}, {"input": "16\r\n3 3 3 1 3 0 1 4 4 4 1 4 3 1 1 4\r\n", "output": "4\r\n"}, {"input": "17\r\n3 3 1 0 1 3 1 1 1 3 0 2 2 2 3 2 2\r\n", "output": "5\r\n"}, {"input": "12\r\n2 2 2 1 1 0 2 0 1 1 2 1\r\n", "output": "5\r\n"}, {"input": "15\r\n4 0 1 0 0 4 1 1 0 4 1 4 4 1 0\r\n", "output": "4\r\n"}, {"input": "20\r\n0 4 4 0 0 0 2 3 3 3 2 0 3 2 3 2 4 4 2 4\r\n", "output": "4\r\n"}, {"input": "23\r\n1 1 3 2 0 3 1 2 2 2 1 3 3 4 1 0 0 3 1 2 2 0 3\r\n", "output": "6\r\n"}, {"input": "15\r\n0 2 4 2 0 4 4 2 4 4 1 2 4 2 2\r\n", "output": "5\r\n"}, {"input": "17\r\n0 4 3 0 2 2 4 2 4 4 2 4 2 1 0 0 0\r\n", "output": "4\r\n"}, {"input": "21\r\n0 3 2 3 0 2 3 4 3 0 1 3 2 2 3 3 3 0 2 2 0\r\n", "output": "5\r\n"}, {"input": "21\r\n1 1 3 1 0 3 3 3 3 0 1 3 0 3 1 1 1 3 2 0 0\r\n", "output": "5\r\n"}, {"input": "13\r\n1 1 1 2 1 1 4 1 3 1 1 1 0\r\n", "output": "7\r\n"}, {"input": "14\r\n4 2 4 4 0 4 4 0 1 0 0 4 3 4\r\n", "output": "1\r\n"}, {"input": "13\r\n2 1 2 2 3 4 0 2 2 2 2 2 2\r\n", "output": "7\r\n"}, {"input": "10\r\n2 2 2 0 0 0 0 0 2 2\r\n", "output": "4\r\n"}, {"input": "11\r\n2 2 2 2 0 2 2 2 2 2 2\r\n", "output": "8\r\n"}, {"input": "11\r\n1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "8\r\n"}, {"input": "16\r\n0 0 1 1 1 1 1 1 1 1 1 0 1 1 0 1\r\n", "output": "8\r\n"}, {"input": "17\r\n1 1 4 1 1 0 1 1 1 1 0 1 0 1 0 0 1\r\n", "output": "8\r\n"}, {"input": "14\r\n1 0 0 1 1 1 0 1 1 1 1 1 3 0\r\n", "output": "6\r\n"}, {"input": "9\r\n1 1 1 2 1 1 1 1 1\r\n", "output": "6\r\n"}, {"input": "13\r\n2 2 0 4 2 2 2 2 2 1 2 2 2\r\n", "output": "7\r\n"}, {"input": "19\r\n2 2 3 2 0 0 1 1 2 0 0 2 1 2 2 2 0 2 2\r\n", "output": "9\r\n"}, {"input": "29\r\n3 1 3 3 0 2 2 3 3 2 0 3 3 2 3 0 3 3 0 2 2 2 3 2 0 3 2 2 3\r\n", "output": "7\r\n"}, {"input": "27\r\n0 1 2 2 3 3 2 0 2 3 2 0 2 3 2 2 2 2 3 3 1 3 2 3 1 2 2\r\n", "output": "11\r\n"}, {"input": "29\r\n3 3 2 0 1 1 1 2 2 2 1 3 2 0 2 3 3 2 2 3 2 2 2 2 1 2 2 2 4\r\n", "output": "12\r\n"}, {"input": "13\r\n4 1 1 4 1 1 1 1 1 1 1 1 1\r\n", "output": "8\r\n"}, {"input": "30\r\n1 1 1 3 3 4 0 1 1 1 1 1 1 3 0 0 0 1 1 1 1 3 1 1 1 1 3 1 1 1\r\n", "output": "14\r\n"}, {"input": "32\r\n1 4 4 3 1 4 4 4 1 1 1 1 1 4 1 1 1 4 1 1 1 1 2 1 1 4 4 1 1 1 1 4\r\n", "output": "14\r\n"}, {"input": "48\r\n1 3 1 1 1 1 1 1 2 1 1 2 1 1 4 1 1 1 2 2 2 1 3 1 1 1 1 2 1 2 2 1 1 1 1 1 3 0 2 3 1 1 3 1 0 1 2 1\r\n", "output": "24\r\n"}, {"input": "49\r\n2 2 1 2 2 2 2 2 2 2 2 2 1 2 1 3 4 2 2 2 2 4 1 1 2 1 2 2 2 2 2 4 0 0 2 0 1 1 2 1 2 2 2 2 4 4 2 2 1\r\n", "output": "24\r\n"}, {"input": "165\r\n1 1 1 1 1 1 1 1 0 2 2 2 1 1 1 1 1 4 4 1 1 2 2 1 2 1 2 2 2 1 2 2 3 1 1 2 1 1 2 2 4 1 2 2 2 4 1 1 1 4 2 2 1 1 1 1 1 2 1 1 1 2 1 1 1 1 4 2 2 1 1 1 1 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 1 2 2 1 1 1 2 1 4 2 2 2 1 1 1 1 2 3 2 1 2 1 1 2 1 1 1 1 1 2 1 2 1 1 0 1 2 1 1 1 1 1 3 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 3 4 1 1 1\r\n", "output": "84\r\n"}, {"input": "197\r\n1 4 4 4 1 4 1 1 0 1 4 4 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 4 1 1 1 1 1 4 1 1 1 2 1 1 4 4 4 4 4 4 1 1 1 4 1 4 4 4 4 4 1 1 1 1 1 4 4 1 4 0 4 1 4 4 1 4 4 4 2 1 1 4 4 2 1 1 1 4 1 4 1 4 4 4 1 1 4 4 4 1 1 0 1 4 1 4 0 4 3 1 1 1 4 1 4 4 4 1 4 1 4 3 1 4 4 4 1 1 4 0 4 1 1 4 1 4 4 1 4 1 1 1 4 1 4 1 1 3 4 1 4 4 1 1 1 1 4 1 1 3 4 1 1 0 1 4 4 1 4 4 1 4 4 1 1 0 2 1 4 1 4 1 1 1 1 1 4 4 1 1 0 4 2 4 1 4 1 4 4\r\n", "output": "69\r\n"}, {"input": "177\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 4 2 2 2 2 4 2 0 2 2 2 2 2 3 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 4 2 2 2 2 2 2 4 2 2 2 2 2 3 2 1 2 2 2 2 2 2 4 4 2 2 2 4 2 2 2 2 2 2 2 2 4 2 4 2 2 4 2 2 2 2 2 2 2 2 0 2 3 2 2 2 2 2 2 2 0 2 2 4 2 2 2 2 3 2 2\r\n", "output": "103\r\n"}, {"input": "166\r\n2 3 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 3 2 2 2 2 2 2 2 2 2 4 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 3 2 2 2 2 2 2 2 2 2 3 2 0 2 0 3 2 2 2 0 2 0 2 2 2 2 2 2 3 0 2 2 2 2 2 3 3 2 2 2 3 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 2 2 2 3 2 2 2 2\r\n", "output": "93\r\n"}, {"input": "172\r\n2 2 2 0 1 3 2 1 0 3 3 1 0 1 2 3 4 2 2 4 2 1 4 0 3 2 2 3 3 3 0 0 3 1 1 0 1 2 2 0 1 4 4 0 3 3 2 0 1 4 4 1 4 2 2 3 0 1 2 2 1 1 4 4 4 4 0 1 0 2 4 0 2 0 0 2 2 1 4 2 2 2 2 2 0 2 3 0 2 1 0 2 1 0 2 2 0 2 2 0 2 2 2 1 1 0 2 1 2 1 0 2 2 0 2 2 3 2 4 2 4 3 2 3 1 2 2 4 0 2 0 2 2 1 0 1 2 1 4 1 0 3 2 2 1 0 0 2 0 4 2 2 0 0 4 1 3 2 1 1 0 2 3 2 0 2 2 2 2 2 3 0\r\n", "output": "53\r\n"}, {"input": "141\r\n2 1 1 1 1 1 4 2 3 1 1 1 1 1 1 4 1 1 1 1 1 1 1 4 4 1 1 1 1 2 1 4 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 2 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 0 1 3 1 1 1 1 1 4 4 1 3 4 1 1 1 1 1 1 1 1 1 4 2 1 0 1 1 4 1 1 1 1 2 1 0 1 1 2 1 1 1 1 4 4 1 2 4 4 1 1 3 1 1 1 3 1 1 4 4 1 1 1 4 1 1 1 1 1 1 2 0 1 0 0 1 0 4\r\n", "output": "69\r\n"}, {"input": "108\r\n2 2 1 4 2 2 1 2 2 2 2 2 2 4 2 2 4 2 4 2 2 2 2 4 2 4 2 2 2 1 2 1 2 2 2 4 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 4 2 2 2 2 4 2 2 2 1 2 2 2 2 2 4 1 2 2\r\n", "output": "61\r\n"}, {"input": "138\r\n3 1 3 1 3 3 3 1 1 1 1 1 1 3 3 1 1 1 3 3 1 1 3 1 1 1 1 1 1 1 3 3 3 1 3 1 1 1 1 1 3 1 1 3 1 3 1 3 1 1 1 1 3 1 3 1 1 3 1 1 1 3 1 1 1 1 1 1 1 1 3 1 1 1 1 3 1 3 1 3 3 3 3 3 3 1 1 1 3 1 1 3 1 1 1 1 1 1 1 1 3 1 1 3 3 1 3 3 1 3 1 1 1 3 1 1 1 1 1 1 3 1 1 1 1 3 1 1 1 3 1 1 3 1 1 3 1 1\r\n", "output": "62\r\n"}, {"input": "81\r\n2 2 2 3 2 3 2 2 2 2 2 3 2 2 2 2 2 2 0 2 4 2 3 4 2 3 2 3 2 0 2 2 0 2 2 3 2 2 4 3 3 2 2 2 2 2 2 2 3 2 2 2 2 2 2 3 3 2 2 3 2 0 2 0 2 2 2 2 2 2 4 0 2 3 2 4 2 2 2 2 2\r\n", "output": "38\r\n"}, {"input": "115\r\n2 2 2 2 4 2 2 2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 4 2 4 2 4 2 2 2 2 2 2 2 2 2 2 2 4 4 3 2 2 2 2 2 2 2 4 2 2 2 3 2 2 2 2 2 2 4 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 3 2 2 2 2 2 4 4 4 2 2\r\n", "output": "65\r\n"}, {"input": "146\r\n1 1 1 1 1 4 1 1 0 1 4 4 1 4 1 1 1 1 1 4 1 1 1 1 1 1 1 4 1 1 1 1 4 1 4 1 1 1 0 1 4 1 4 1 4 4 1 1 1 1 1 1 1 1 1 4 4 1 1 4 1 4 4 4 1 1 4 4 1 4 1 1 1 1 0 1 1 1 1 1 1 4 1 4 1 1 4 1 1 4 4 4 1 1 4 1 1 1 1 1 1 1 4 1 1 1 4 1 4 1 1 1 1 1 1 1 4 1 1 4 4 4 1 1 1 1 1 1 1 4 1 1 1 1 4 1 4 1 1 1 4 4 4 4 1 1\r\n", "output": "68\r\n"}, {"input": "198\r\n1 2 1 2 2 1 2 1 1 1 3 2 1 1 2 1 2 2 1 1 1 4 1 1 1 1 0 1 1 1 1 4 1 1 3 1 2 1 1 1 2 1 2 0 1 1 1 1 1 1 1 1 1 2 4 4 1 0 1 1 1 1 1 1 1 1 2 1 1 1 4 0 1 2 1 2 1 1 2 2 1 1 1 1 3 2 2 2 1 1 4 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 1 3 1 3 1 1 0 1 4 1 2 2 1 1 1 2 2 1 1 1 1 3 2 1 2 1 1 2 1 2 1 2 1 0 4 1 2 1 1 1 1 3 1 1 2 0 1 1 1 1 1 3 2 1 2 1 1 0 1 1 3 1 1 2 1 1 1 1 1 1 4 4 1 1 0 1 1 1 2 1 1 1 3 0 2 1 2 1 1 1 1 1\r\n", "output": "97\r\n"}, {"input": "200\r\n4 1 1 4 3 1 1 3 1 1 1 4 3 3 3 2 3 3 1 3 3 4 4 2 2 2 3 1 2 2 2 3 1 1 3 2 2 4 1 3 4 3 2 4 2 2 4 2 2 3 4 2 3 2 2 1 2 4 4 2 4 4 2 3 2 4 1 4 2 1 3 4 1 3 1 1 2 1 4 1 3 3 3 4 1 4 4 1 4 4 2 3 1 3 3 2 2 1 4 2 4 4 3 3 3 1 3 4 3 1 1 1 1 4 2 1 2 3 2 2 2 3 2 1 2 1 1 1 2 4 1 3 3 3 2 3 3 2 3 4 4 3 3 4 3 2 1 4 1 4 2 1 3 2 4 4 1 4 1 1 1 3 2 3 4 2 2 4 1 4 4 4 4 3 1 3 1 4 3 2 1 2 1 1 2 4 1 3 3 4 4 2 2 4 4 3 2 1 2 4\r\n", "output": "50\r\n"}, {"input": "200\r\n2 1 1 2 2 2 2 1 1 2 2 2 1 1 2 2 2 2 1 1 1 2 2 2 2 2 2 1 2 2 1 1 1 1 2 1 2 2 1 2 2 2 2 1 2 2 1 1 1 1 2 2 1 1 1 1 1 2 2 2 2 1 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 1 1 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 1 2 2 1 1 2 2 2 1 2 2 0 1 2 1 1 2 2 2 1 2 2 1 1 1 2 2 2 1 2 1 2 1 2 1 1 2 2 1 1 1 1 1 2 2 1 1 1 1 1 2 1 2 2 1 1 1 1 1 1 2 2 1 1 1 1 2 2 1 1 1 2 2 2 2 1 1 1 1 1 1 2 1 1 2 2 1 1 2 1 0\r\n", "output": "100\r\n"}, {"input": "6\r\n1 1 1 2 2 1\r\n", "output": "4\r\n"}, {"input": "10\r\n3 3 1 1 2 1 1 1 2 2\r\n", "output": "5\r\n"}, {"input": "10\r\n1 1 1 2 1 2 2 1 2 1\r\n", "output": "6\r\n"}, {"input": "15\r\n1 2 2 1 2 3 2 1 2 1 1 1 2 1 1\r\n", "output": "8\r\n"}, {"input": "13\r\n2 1 2 2 1 0 1 2 1 1 1 1 2\r\n", "output": "7\r\n"}, {"input": "3\r\n4 4 1\r\n", "output": "2\r\n"}, {"input": "5\r\n4 4 4 4 1\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 3 4\r\n", "output": "2\r\n"}, {"input": "7\r\n1 1 1 3 3 3 3\r\n", "output": "2\r\n"}, {"input": "6\r\n2 2 2 4 4 4\r\n", "output": "2\r\n"}, {"input": "3\r\n2 3 3\r\n", "output": "2\r\n"}, {"input": "9\r\n1 1 1 1 3 3 3 3 3\r\n", "output": "3\r\n"}, {"input": "3\r\n1 4 4\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 2\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 3\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 2 2 2\r\n", "output": "4\r\n"}, {"input": "6\r\n2 2 2 2 2 4\r\n", "output": "4\r\n"}, {"input": "3\r\n2 2 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 4\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 3 3\r\n", "output": "2\r\n"}, {"input": "4\r\n3 3 3 2\r\n", "output": "2\r\n"}, {"input": "1\r\n4\r\n", "output": "0\r\n"}]
false
stdio
null
true
814/A
814
A
PyPy 3
TESTS
14
155
0
67440550
n,k = map(int,input().split()) a=[int(i)for i in input().split()] b=[int(i)for i in input().split()] b.sort() if k>1 : print("Yes") elif k==1: for q, i in enumerate(a): if i == 0: a[q] = b[0] if (a.index(max(a)) -a.index(min(a)))==n-1: print("No") else: print("Yes")
96
46
0
168484105
a,b=map(int,input().split()) x=list(map(int,input().split())) y=list(map(int,input().split())) y.sort() j=b-1 #print for i in range(a): if x[i]==0: x[i]=y[j] j=j-1 t=sorted(x) c=0 for i in range(a): if t[i]!=x[i]: print("Yes") c=1 break if(c==0): print("No")
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An abandoned sentiment from past
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.
The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements. The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in a and b more than once in total.
Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.
null
In the first sample: - Sequence a is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in b are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
[{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}]
900
["constructive algorithms", "greedy", "implementation", "sortings"]
96
[{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\r\n80\r\n", "output": "No\r\n"}, {"input": "100 1\r\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\r\n58\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n2 1 0 4\r\n3\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n199 0\r\n200\r\n", "output": "No\r\n"}, {"input": "3 2\r\n115 0 0\r\n145 191\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n196 197 198 0 200\r\n199\r\n", "output": "No\r\n"}, {"input": "5 1\r\n92 0 97 99 100\r\n93\r\n", "output": "No\r\n"}, {"input": "3 1\r\n3 87 0\r\n81\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 92 192\r\n118\r\n", "output": "Yes\r\n"}, {"input": "10 1\r\n1 3 0 7 35 46 66 72 83 90\r\n22\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 0 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113\r\n67\r\n", "output": "No\r\n"}, {"input": "100 5\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 0 99 100\r\n98 64 55 52 29\r\n", "output": "Yes\r\n"}, {"input": "100 5\r\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\r\n121 199 62 193 27\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 0 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n11\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n1\r\n", "output": "No\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 0\r\n100\r\n", "output": "No\r\n"}, {"input": "100 1\r\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\r\n65\r\n", "output": "Yes\r\n"}, {"input": "100 2\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 0 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n48 1\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\r\n69\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\r\n129\r\n", "output": "No\r\n"}, {"input": "5 2\r\n0 2 7 0 10\r\n1 8\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 4 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 3\r\n4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n1\r\n", "output": "No\r\n"}, {"input": "2 1\r\n0 5\r\n7\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 0 12 13\r\n1\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n0 2 3 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 0 3 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "7 2\r\n1 2 3 0 0 6 7\r\n4 5\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "2 2\r\n0 0\r\n1 2\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n1 0 0\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 4 0\r\n5 2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 1\r\n2\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 4 5\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 2 3\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 5 0\r\n6\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 0 2\r\n7\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n4 5 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 12 0 14\r\n13\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 2 0 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 11 14\r\n12\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 3 0 4\r\n2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 5\r\n1\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 7\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 5 4\r\n6\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n11 0 0 14\r\n13 12\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n1 0\r\n2\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 0 3 2\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 2 3 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 2 0\r\n5\r\n", "output": "No\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 5 7\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 0 11\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n7 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 3 0 5 0\r\n6 4\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n0 1 0\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n6 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 3\r\n6\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 2 0 0 5\r\n4 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n2 0 0 8\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 0 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 2\r\n11 0 0 200\r\n100 199\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n5 0\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 5\r\n10\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 0 0 5 6\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 3 0 5\r\n2 4\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 4 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n5 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 7\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "3 3\r\n0 0 0\r\n1 4 3\r\n", "output": "Yes\r\n"}, {"input": "5 5\r\n0 0 0 0 0\r\n5 4 3 2 1\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n3 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 4 0 8 9 10\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 3 5 6\r\n9\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 2 0 0\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 4 5 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 0 4\r\n5\r\n", "output": "Yes\r\n"}]
false
stdio
null
true
895/A
895
A
Python 3
TESTS
50
124
0
58705023
n = int(input()) s = list(map(int,input().split())) s.extend(s) r = 360 a = 0 b1,b2 = 0,0 for i in range(2*n): a+=s[i] b2+=1 if a<180: r = min(r,abs(a-180)) elif a==180: r = 0 break else: a -=s[b1] r = min(r,abs(a-180)) b1+=1 print(r*2)
93
46
0
227768233
def main(): N = 1000 SUMA = 0 NUMEROS = [0] * N tam = int(input()) ANSI = 365 # Read numbers from one line, split by spaces, and convert each to an integer input_values = list(map(int, input().split())) for i in range(1, tam + 1): NUMEROS[i] = input_values[i - 1] for i in range(1, tam + 1): SUMA = 0 for j in range(i, tam + 1): SUMA += NUMEROS[j] ANSI = min(ANSI, abs(360 - SUMA * 2)) print(ANSI) if __name__ == "__main__": main()
Codeforces Round 448 (Div. 2)
CF
2,017
1
256
Pizza Separation
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut. The second line contains n integers ai (1 ≤ ai ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
null
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0. Picture explaning fourth sample: Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
1,200
["brute force", "implementation"]
93
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", "output": "0\r\n"}, {"input": "3\r\n120 120 120\r\n", "output": "120\r\n"}, {"input": "5\r\n110 90 70 50 40\r\n", "output": "40\r\n"}, {"input": "2\r\n170 190\r\n", "output": "20\r\n"}, {"input": "15\r\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10\r\n", "output": "10\r\n"}, {"input": "5\r\n30 60 180 60 30\r\n", "output": "0\r\n"}, {"input": "2\r\n359 1\r\n", "output": "358\r\n"}, {"input": "5\r\n100 100 30 100 30\r\n", "output": "40\r\n"}, {"input": "5\r\n36 34 35 11 244\r\n", "output": "128\r\n"}, {"input": "5\r\n96 94 95 71 4\r\n", "output": "18\r\n"}, {"input": "2\r\n85 275\r\n", "output": "190\r\n"}, {"input": "3\r\n281 67 12\r\n", "output": "202\r\n"}, {"input": "5\r\n211 113 25 9 2\r\n", "output": "62\r\n"}, {"input": "13\r\n286 58 6 1 1 1 1 1 1 1 1 1 1\r\n", "output": "212\r\n"}, {"input": "15\r\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "20\r\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "92\r\n"}, {"input": "50\r\n148 53 32 11 4 56 8 2 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "3\r\n1 1 358\r\n", "output": "356\r\n"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341\r\n", "output": "322\r\n"}, {"input": "33\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 328\r\n", "output": "296\r\n"}, {"input": "70\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 291\r\n", "output": "222\r\n"}, {"input": "130\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231\r\n", "output": "102\r\n"}, {"input": "200\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 161\r\n", "output": "0\r\n"}, {"input": "222\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 139\r\n", "output": "0\r\n"}, {"input": "10\r\n8 3 11 4 1 10 10 1 8 304\r\n", "output": "248\r\n"}, {"input": "12\r\n8 7 7 3 11 2 10 1 10 8 10 283\r\n", "output": "206\r\n"}, {"input": "13\r\n10 8 9 10 5 9 4 1 10 11 1 7 275\r\n", "output": "190\r\n"}, {"input": "14\r\n1 6 3 11 9 5 9 8 5 6 7 3 7 280\r\n", "output": "200\r\n"}, {"input": "15\r\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275\r\n", "output": "190\r\n"}, {"input": "30\r\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189\r\n", "output": "18\r\n"}, {"input": "70\r\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "29\r\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189\r\n", "output": "18\r\n"}, {"input": "35\r\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168\r\n", "output": "0\r\n"}, {"input": "60\r\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5\r\n", "output": "0\r\n"}, {"input": "71\r\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "63\r\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "81\r\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 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": "47\r\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68\r\n", "output": "0\r\n"}, {"input": "100\r\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "120\r\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 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 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": "200\r\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "220\r\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "6\r\n27 15 28 34 41 215\r\n", "output": "70\r\n"}, {"input": "7\r\n41 38 41 31 22 41 146\r\n", "output": "14\r\n"}, {"input": "8\r\n24 27 34 23 29 23 30 170\r\n", "output": "20\r\n"}, {"input": "9\r\n11 11 20 20 33 32 35 26 172\r\n", "output": "6\r\n"}, {"input": "10\r\n36 13 28 13 33 34 23 25 34 121\r\n", "output": "0\r\n"}, {"input": "11\r\n19 37 13 41 37 15 32 12 19 35 100\r\n", "output": "10\r\n"}, {"input": "12\r\n37 25 34 38 21 24 34 38 11 29 28 41\r\n", "output": "2\r\n"}, {"input": "13\r\n24 40 20 26 25 29 39 29 35 28 19 18 28\r\n", "output": "2\r\n"}, {"input": "14\r\n11 21 40 19 28 34 13 16 23 30 34 22 25 44\r\n", "output": "4\r\n"}, {"input": "3\r\n95 91 174\r\n", "output": "12\r\n"}, {"input": "4\r\n82 75 78 125\r\n", "output": "46\r\n"}, {"input": "6\r\n87 75 88 94 15 1\r\n", "output": "4\r\n"}, {"input": "10\r\n27 52 58 64 45 64 1 19 2 28\r\n", "output": "12\r\n"}, {"input": "50\r\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1\r\n", "output": "0\r\n"}, {"input": "100\r\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3\r\n", "output": "0\r\n"}, {"input": "150\r\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1\r\n", "output": "0\r\n"}, {"input": "200\r\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2\r\n", "output": "0\r\n"}, {"input": "5\r\n35 80 45 100 100\r\n", "output": "40\r\n"}, {"input": "4\r\n90 179 90 1\r\n", "output": "2\r\n"}, {"input": "5\r\n50 50 20 160 80\r\n", "output": "0\r\n"}, {"input": "5\r\n30 175 30 5 120\r\n", "output": "10\r\n"}, {"input": "4\r\n170 30 10 150\r\n", "output": "20\r\n"}, {"input": "6\r\n90 30 90 30 90 30\r\n", "output": "60\r\n"}, {"input": "4\r\n70 80 110 100\r\n", "output": "20\r\n"}, {"input": "7\r\n35 45 70 100 10 10 90\r\n", "output": "0\r\n"}, {"input": "6\r\n50 90 10 90 20 100\r\n", "output": "20\r\n"}, {"input": "6\r\n10 155 162 1 26 6\r\n", "output": "18\r\n"}, {"input": "7\r\n80 90 80 45 10 10 45\r\n", "output": "20\r\n"}, {"input": "4\r\n18 36 162 144\r\n", "output": "36\r\n"}, {"input": "5\r\n20 50 50 160 80\r\n", "output": "40\r\n"}, {"input": "5\r\n10 30 140 20 160\r\n", "output": "0\r\n"}, {"input": "6\r\n90 80 60 50 40 40\r\n", "output": "20\r\n"}, {"input": "9\r\n40 20 20 20 20 20 20 40 160\r\n", "output": "40\r\n"}, {"input": "4\r\n90 54 90 126\r\n", "output": "72\r\n"}, {"input": "4\r\n150 170 30 10\r\n", "output": "20\r\n"}, {"input": "8\r\n130 12 13 85 41 67 5 7\r\n", "output": "26\r\n"}, {"input": "7\r\n70 170 20 10 30 30 30\r\n", "output": "20\r\n"}, {"input": "8\r\n100 100 50 50 15 15 15 15\r\n", "output": "40\r\n"}, {"input": "4\r\n100 70 80 110\r\n", "output": "20\r\n"}, {"input": "5\r\n160 130 40 20 10\r\n", "output": "20\r\n"}, {"input": "4\r\n20 149 151 40\r\n", "output": "22\r\n"}, {"input": "4\r\n100 10 100 150\r\n", "output": "60\r\n"}, {"input": "6\r\n19 64 105 168 1 3\r\n", "output": "16\r\n"}, {"input": "8\r\n10 10 70 70 90 90 10 10\r\n", "output": "0\r\n"}]
false
stdio
null
true
682/B
682
B
Python 3
TESTS
66
186
7,270,400
68034178
import sys #n = int(input()) #a = list(input().split()) #a.sort() #m = [] #for x in a: # for y in x: # m.append(y) # # #for i in range(len(m) + 1): # try: # # if len(m) == 1: # del m[i] # m.insert(i, str(1)) # break # # # if int(m[i + 1]) - int(m[i]) >= 2: # del m[i + 1] # m.insert(i + 1, str(int(m[i]) + 1)) # # except: # pass # ##print(a) # #print(int(max(m)) + 1) n = int(input()) a = list(input().split()) a.sort() mass = 1 for i in range(len(a)): if int(a[i]) >= mass: mass += 1 print(mass)
127
93
11,571,200
177394199
n=int(input()) a=[int(s) for s in input().split()] k=1 a=sorted(a) for i in range(n): if k<=a[i]: k+=1 print(k)
Codeforces Round 358 (Div. 2)
CF
2,016
1
256
Alyona and Mex
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≤ bi ≤ ai for every 1 ≤ i ≤ n. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array. The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.
Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.
null
In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements.
[{"input": "5\n1 3 3 3 6", "output": "5"}, {"input": "2\n2 1", "output": "3"}]
1,200
["sortings"]
127
[{"input": "5\r\n1 3 3 3 6\r\n", "output": "5\r\n"}, {"input": "2\r\n2 1\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n", "output": "2\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "2\r\n"}, {"input": "1\r\n2\r\n", "output": "2\r\n"}, {"input": "2\r\n1 1\r\n", "output": "2\r\n"}, {"input": "2\r\n1 3\r\n", "output": "3\r\n"}, {"input": "2\r\n2 2\r\n", "output": "3\r\n"}, {"input": "2\r\n2 3\r\n", "output": "3\r\n"}, {"input": "2\r\n3 3\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 4\r\n", "output": "3\r\n"}, {"input": "3\r\n2 1 2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "4\r\n"}, {"input": "3\r\n2 4 1\r\n", "output": "4\r\n"}, {"input": "3\r\n3 3 1\r\n", "output": "4\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 1 4\r\n", "output": "4\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 2 2\r\n", "output": "4\r\n"}, {"input": "3\r\n4 2 2\r\n", "output": "4\r\n"}, {"input": "3\r\n2 3 3\r\n", "output": "4\r\n"}, {"input": "3\r\n4 2 3\r\n", "output": "4\r\n"}, {"input": "3\r\n4 4 2\r\n", "output": "4\r\n"}, {"input": "3\r\n3 3 3\r\n", "output": "4\r\n"}, {"input": "3\r\n4 3 3\r\n", "output": "4\r\n"}, {"input": "3\r\n4 3 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 4 4\r\n", "output": "4\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 2 1\r\n", "output": "3\r\n"}, {"input": "4\r\n1 1 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 1 1\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n1 3 2 1\r\n", "output": "4\r\n"}, {"input": "4\r\n2 1 4 1\r\n", "output": "4\r\n"}, {"input": "4\r\n3 3 1 1\r\n", "output": "4\r\n"}, {"input": "4\r\n1 3 4 1\r\n", "output": "4\r\n"}, {"input": "4\r\n1 1 4 4\r\n", "output": "4\r\n"}, {"input": "4\r\n2 2 2 1\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 2 3\r\n", "output": "4\r\n"}, {"input": "4\r\n2 4 1 2\r\n", "output": "4\r\n"}, {"input": "4\r\n3 3 1 2\r\n", "output": "4\r\n"}, {"input": "4\r\n2 3 4 1\r\n", "output": "5\r\n"}, {"input": "4\r\n1 4 2 4\r\n", "output": "5\r\n"}, {"input": "4\r\n3 1 3 3\r\n", "output": "4\r\n"}, {"input": "4\r\n3 4 3 1\r\n", "output": "5\r\n"}, {"input": "4\r\n1 4 4 3\r\n", "output": "5\r\n"}, {"input": "4\r\n4 1 4 4\r\n", "output": "5\r\n"}, {"input": "4\r\n2 2 2 2\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 3 2\r\n", "output": "4\r\n"}, {"input": "4\r\n2 2 2 4\r\n", "output": "4\r\n"}, {"input": "4\r\n2 2 3 3\r\n", "output": "4\r\n"}, {"input": "4\r\n2 2 3 4\r\n", "output": "5\r\n"}, {"input": "4\r\n2 4 4 2\r\n", "output": "5\r\n"}, {"input": "4\r\n2 3 3 3\r\n", "output": "4\r\n"}, {"input": "4\r\n2 4 3 3\r\n", "output": "5\r\n"}, {"input": "4\r\n4 4 2 3\r\n", "output": "5\r\n"}, {"input": "4\r\n4 4 4 2\r\n", "output": "5\r\n"}, {"input": "4\r\n3 3 3 3\r\n", "output": "4\r\n"}, {"input": "4\r\n3 3 3 4\r\n", "output": "5\r\n"}, {"input": "4\r\n4 3 3 4\r\n", "output": "5\r\n"}, {"input": "4\r\n4 4 3 4\r\n", "output": "5\r\n"}, {"input": "4\r\n4 4 4 4\r\n", "output": "5\r\n"}, {"input": "11\r\n1 1 1 1 1 1 1 1 1 3 3\r\n", "output": "4\r\n"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8\r\n", "output": "9\r\n"}, {"input": "4\r\n2 2 2 3\r\n", "output": "4\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "3\r\n"}, {"input": "15\r\n1 2 2 20 23 25 28 60 66 71 76 77 79 99 100\r\n", "output": "15\r\n"}, {"input": "7\r\n1 2 2 2 5 5 1\r\n", "output": "5\r\n"}, {"input": "4\r\n1 1 1 2\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 1 1 10000\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "3\r\n"}, {"input": "7\r\n1 3 3 3 3 3 6\r\n", "output": "5\r\n"}, {"input": "4\r\n1 1 1 3\r\n", "output": "3\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 100\r\n", "output": "3\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 1 3 4\r\n", "output": "4\r\n"}, {"input": "8\r\n1 1 1 1 2 2 3 40\r\n", "output": "5\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "7\r\n1 2 2 2 2 2 4\r\n", "output": "4\r\n"}, {"input": "10\r\n1 1 1 10000000 10000000 10000000 10000000 10000000 10000000 10000000\r\n", "output": "9\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 2 3\r\n", "output": "4\r\n"}, {"input": "4\r\n8 8 8 8\r\n", "output": "5\r\n"}, {"input": "5\r\n5 6 6 6 7\r\n", "output": "6\r\n"}]
false
stdio
null
true
814/A
814
A
PyPy 3
TESTS
16
93
20,172,800
128382571
def possible(n,k,a,b): i = 0 j = 0 while i < n: if a[i] == 0: a[i] = b[j] j += 1 i += 1 if a == sorted(a): return False else: return True def reversepossible(n,k,a,b): b.reverse() i = 0 j = 0 while i < n: if a[i] == 0: a[i] = b[j] j += 1 i += 1 if a == sorted(a): return False else: return True n,k = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) flag = False if reversepossible(n,k,a,b): print("Yes") elif possible(n,k,a,b): print("Yes") else: print("No")
96
46
0
174774083
isValid = False x1 = list(map(int, input().split())) x2 = list(map(int, input().split())) x3 = list(map(int, input().split())) for i in range(len(x2)): if(i<len(x2)-1): if(x2[i] > x2[i+1] and x2[i] != 0): if(x2[i] != 0 and x2[i+1] != 0): isValid = True break else: for j in range(len(x3)): if(x2[i] > x3[j]): isValid = True break elif(x2[i] == 0): for j in range(len(x3)): if(x3[j] > x2[i+1]): isValid = True break # isValid = True # break # elif(x2[i+1] == 0): # for j in range(len(x3)): # if(x2[i] > x3[j]): if(isValid): print("YES") else: print("NO")
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An abandoned sentiment from past
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.
The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements. The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in a and b more than once in total.
Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.
null
In the first sample: - Sequence a is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in b are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
[{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}]
900
["constructive algorithms", "greedy", "implementation", "sortings"]
96
[{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\r\n80\r\n", "output": "No\r\n"}, {"input": "100 1\r\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\r\n58\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n2 1 0 4\r\n3\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n199 0\r\n200\r\n", "output": "No\r\n"}, {"input": "3 2\r\n115 0 0\r\n145 191\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n196 197 198 0 200\r\n199\r\n", "output": "No\r\n"}, {"input": "5 1\r\n92 0 97 99 100\r\n93\r\n", "output": "No\r\n"}, {"input": "3 1\r\n3 87 0\r\n81\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 92 192\r\n118\r\n", "output": "Yes\r\n"}, {"input": "10 1\r\n1 3 0 7 35 46 66 72 83 90\r\n22\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 0 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113\r\n67\r\n", "output": "No\r\n"}, {"input": "100 5\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 0 99 100\r\n98 64 55 52 29\r\n", "output": "Yes\r\n"}, {"input": "100 5\r\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\r\n121 199 62 193 27\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 0 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n11\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n1\r\n", "output": "No\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 0\r\n100\r\n", "output": "No\r\n"}, {"input": "100 1\r\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\r\n65\r\n", "output": "Yes\r\n"}, {"input": "100 2\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 0 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n48 1\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\r\n69\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\r\n129\r\n", "output": "No\r\n"}, {"input": "5 2\r\n0 2 7 0 10\r\n1 8\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 4 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 3\r\n4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n1\r\n", "output": "No\r\n"}, {"input": "2 1\r\n0 5\r\n7\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 0 12 13\r\n1\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n0 2 3 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 0 3 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "7 2\r\n1 2 3 0 0 6 7\r\n4 5\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "2 2\r\n0 0\r\n1 2\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n1 0 0\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 4 0\r\n5 2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 1\r\n2\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 4 5\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 2 3\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 5 0\r\n6\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 0 2\r\n7\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n4 5 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 12 0 14\r\n13\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 2 0 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 11 14\r\n12\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 3 0 4\r\n2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 5\r\n1\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 7\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 5 4\r\n6\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n11 0 0 14\r\n13 12\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n1 0\r\n2\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 0 3 2\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 2 3 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 2 0\r\n5\r\n", "output": "No\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 5 7\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 0 11\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n7 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 3 0 5 0\r\n6 4\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n0 1 0\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n6 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 3\r\n6\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 2 0 0 5\r\n4 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n2 0 0 8\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 0 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 2\r\n11 0 0 200\r\n100 199\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n5 0\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 5\r\n10\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 0 0 5 6\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 3 0 5\r\n2 4\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 4 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n5 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 7\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "3 3\r\n0 0 0\r\n1 4 3\r\n", "output": "Yes\r\n"}, {"input": "5 5\r\n0 0 0 0 0\r\n5 4 3 2 1\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n3 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 4 0 8 9 10\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 3 5 6\r\n9\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 2 0 0\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 4 5 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 0 4\r\n5\r\n", "output": "Yes\r\n"}]
false
stdio
null
true
789/B
789
B
Python 3
TESTS
19
92
13,107,200
25917516
b, q, l, m = map(int, input().split()) b = abs(b) q = abs(q) a = set(list(map(int, input().split()))) if (b == 0): print("inf") else: if q == 0: if b > l: print(0) else: if 0 in a: if b in a: print(0) else: print(1) else: print("inf") elif q == 1: if b > l or b in a: print(0) else: print("inf") else: ans = 0 while b <= l: if not b in a: ans += 1 b *= q print(ans)
116
93
15,564,800
25914081
s, r, m, n = map(int, input().split()) bad = set(map(int, input().split())) cnt = 0 if abs(s) > m: print(0) elif s == 0: if 0 in bad: print(0) else: print('inf') elif r == 0 and s != 0: if 0 in bad or m < 0: if s in bad: print(0) else: print(1) else: print('inf') elif r == 1: if s in bad: print(0) else: print('inf') elif r == -1: if (s in bad) and (-s in bad): print(0) else: print('inf') elif -1 <= r <= 1 and r != 0: print('inf') else: while abs(s) <= m: if s not in bad: cnt += 1 s *= r print(cnt)
Codeforces Round 407 (Div. 2)
CF
2,017
1
256
Masha and geometric depression
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board.
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
null
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123.
[{"input": "3 2 30 4\n6 14 25 48", "output": "3"}, {"input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0"}, {"input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf"}]
1,700
["brute force", "implementation", "math"]
116
[{"input": "3 2 30 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "123 1 2143435 4\r\n123 11 -5453 141245\r\n", "output": "0"}, {"input": "123 1 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "3 2 25 2\r\n379195692 -69874783\r\n", "output": "4"}, {"input": "3 2 30 3\r\n-691070108 -934106649 -220744807\r\n", "output": "4"}, {"input": "3 3 104 17\r\n9 -73896485 -290898562 5254410 409659728 -916522518 -435516126 94354167 262981034 -375897180 -80186684 -173062070 -288705544 -699097793 -11447747 320434295 503414250\r\n", "output": "3"}, {"input": "-1000000000 -1000000000 1 1\r\n232512888\r\n", "output": "0"}, {"input": "11 0 228 5\r\n-1 0 1 5 -11245\r\n", "output": "1"}, {"input": "11 0 228 5\r\n-1 -17 1 5 -11245\r\n", "output": "inf"}, {"input": "0 0 2143435 5\r\n-1 -153 1 5 -11245\r\n", "output": "inf"}, {"input": "123 0 2143435 4\r\n5433 0 123 -645\r\n", "output": "0"}, {"input": "123 -1 2143435 5\r\n-123 0 12 5 -11245\r\n", "output": "inf"}, {"input": "123 0 21 4\r\n543453 -123 6 1424\r\n", "output": "0"}, {"input": "3 2 115 16\r\n24 48 12 96 3 720031148 -367712651 -838596957 558177735 -963046495 -313322487 -465018432 -618984128 -607173835 144854086 178041956\r\n", "output": "1"}, {"input": "-3 0 92055 36\r\n-92974174 -486557474 -663622151 695596393 177960746 -563227474 -364263320 -676254242 -614140218 71456762 -764104225 705056581 -106398436 332755134 -199942822 -732751692 658942664 677739866 886535704 183687802 -784248291 -22550621 -938674499 637055091 -704750213 780395802 778342470 -999059668 -794361783 796469192 215667969 354336794 -60195289 -885080928 -290279020 201221317\r\n", "output": "inf"}, {"input": "0 -3 2143435 5\r\n-1 0 1 5 -11245\r\n", "output": "0"}, {"input": "123 -1 2143435 5\r\n-123 0 123 -5453 141245\r\n", "output": "0"}, {"input": "123 0 2143435 4\r\n5433 0 -123 -645\r\n", "output": "1"}, {"input": "11 0 2 5\r\n-1 0 1 5 -11245\r\n", "output": "0"}, {"input": "2 2 4 1\r\n2\r\n", "output": "1"}, {"input": "1 -2 1000000000 1\r\n0\r\n", "output": "30"}, {"input": "0 8 10 1\r\n5\r\n", "output": "inf"}, {"input": "-1000 0 10 1\r\n5\r\n", "output": "0"}, {"input": "0 2 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "0 8 5 1\r\n9\r\n", "output": "inf"}, {"input": "-10 1 5 1\r\n100\r\n", "output": "0"}, {"input": "123 -1 2143435 4\r\n54343 -13 6 123\r\n", "output": "inf"}, {"input": "-5 -1 10 1\r\n-5\r\n", "output": "inf"}, {"input": "2 0 1 1\r\n2\r\n", "output": "0"}, {"input": "0 5 8 1\r\n10\r\n", "output": "inf"}, {"input": "0 5 100 2\r\n34 56\r\n", "output": "inf"}, {"input": "15 -1 15 4\r\n15 -15 1 2\r\n", "output": "0"}, {"input": "10 -1 2 1\r\n1\r\n", "output": "0"}, {"input": "2 0 2 1\r\n2\r\n", "output": "inf"}, {"input": "4 0 4 1\r\n0\r\n", "output": "1"}, {"input": "10 10 10 1\r\n123\r\n", "output": "1"}, {"input": "2 2 4 1\r\n3\r\n", "output": "2"}, {"input": "0 1 1 1\r\n0\r\n", "output": "0"}, {"input": "3 2 30 1\r\n3\r\n", "output": "3"}, {"input": "1000000000 100000 1000000000 4\r\n5433 13 6 0\r\n", "output": "1"}, {"input": "-2 0 1 1\r\n1\r\n", "output": "0"}, {"input": "2 -1 10 1\r\n2\r\n", "output": "inf"}, {"input": "1 -1 2 1\r\n1\r\n", "output": "inf"}, {"input": "0 10 10 1\r\n2\r\n", "output": "inf"}, {"input": "0 35 2 1\r\n3\r\n", "output": "inf"}, {"input": "3 1 3 1\r\n5\r\n", "output": "inf"}, {"input": "3 2 3 4\r\n6 14 25 48\r\n", "output": "1"}, {"input": "0 69 12 1\r\n1\r\n", "output": "inf"}, {"input": "100 0 100000 1\r\n100\r\n", "output": "inf"}, {"input": "0 4 1000 3\r\n5 6 7\r\n", "output": "inf"}, {"input": "0 2 100 1\r\n5\r\n", "output": "inf"}, {"input": "3 2 24 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "0 4 1 1\r\n2\r\n", "output": "inf"}, {"input": "1 5 10000 1\r\n125\r\n", "output": "5"}, {"input": "2 -1 1 1\r\n1\r\n", "output": "0"}, {"input": "0 3 100 1\r\n5\r\n", "output": "inf"}, {"input": "0 3 3 1\r\n1\r\n", "output": "inf"}, {"input": "0 2 5 1\r\n1\r\n", "output": "inf"}, {"input": "5 -1 100 1\r\n5\r\n", "output": "inf"}, {"input": "-20 0 10 1\r\n0\r\n", "output": "0"}, {"input": "3 0 1 1\r\n3\r\n", "output": "0"}, {"input": "2 -1 3 1\r\n2\r\n", "output": "inf"}, {"input": "1 1 1000000000 1\r\n100\r\n", "output": "inf"}, {"input": "5 -1 3 1\r\n0\r\n", "output": "0"}, {"input": "0 5 10 1\r\n2\r\n", "output": "inf"}, {"input": "123 0 125 1\r\n123\r\n", "output": "inf"}, {"input": "2 -1 100 1\r\n2\r\n", "output": "inf"}, {"input": "5 2 100 1\r\n5\r\n", "output": "4"}, {"input": "-5 0 1 1\r\n1\r\n", "output": "0"}, {"input": "-3 0 1 1\r\n-3\r\n", "output": "0"}, {"input": "2 -2 10 1\r\n1\r\n", "output": "3"}, {"input": "0 2 30 4\r\n6 14 25 48\r\n", "output": "inf"}, {"input": "1 -1 1 1\r\n1\r\n", "output": "inf"}, {"input": "2 -1 6 1\r\n2\r\n", "output": "inf"}, {"input": "-3 1 100 1\r\n-3\r\n", "output": "0"}, {"input": "1 0 2 1\r\n1\r\n", "output": "inf"}, {"input": "1000000000 999999998 1000000000 1\r\n0\r\n", "output": "1"}, {"input": "1 0 2143435 4\r\n1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "-1000 0 100 1\r\n-1000\r\n", "output": "0"}, {"input": "100 10 2 1\r\n100\r\n", "output": "0"}, {"input": "-3 1 100 1\r\n3\r\n", "output": "inf"}, {"input": "123 -1 10000 1\r\n123\r\n", "output": "inf"}, {"input": "1 -1 2143435 4\r\n1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "5 1 5 5\r\n1 2 3 4 0\r\n", "output": "inf"}, {"input": "-100 -1 1 1\r\n1\r\n", "output": "0"}, {"input": "10 -1 3 2\r\n10 8\r\n", "output": "0"}, {"input": "-10 0 5 1\r\n0\r\n", "output": "0"}, {"input": "3 0 3 1\r\n0\r\n", "output": "1"}, {"input": "2 0 2 1\r\n-1\r\n", "output": "inf"}, {"input": "5 0 20 1\r\n5\r\n", "output": "inf"}, {"input": "-4 1 1 1\r\n0\r\n", "output": "0"}, {"input": "11 0 1111 1\r\n11\r\n", "output": "inf"}, {"input": "2 0 3 1\r\n2\r\n", "output": "inf"}, {"input": "-1 -1 2143435 4\r\n-1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "-100 0 50 1\r\n0\r\n", "output": "0"}, {"input": "5 1 2 1\r\n2\r\n", "output": "0"}, {"input": "3 0 3 1\r\n4\r\n", "output": "inf"}, {"input": "0 23 3 1\r\n3\r\n", "output": "inf"}, {"input": "-1000 0 100 1\r\n2\r\n", "output": "0"}, {"input": "1 -1 10 1\r\n1\r\n", "output": "inf"}]
false
stdio
null
true
127/B
127
B
Python 3
TESTS
40
46
307,200
212524838
from collections import Counter from heapq import * n = int(input()) C = Counter(list(map(int, input().split()))) minHeap = [] for k, v in C.items(): if v < 2: continue if v%2==0: heappush(minHeap, (v, k)) else: heappush(minHeap, (v-1, k)) ans = 0 while minHeap: c, l = heappop(minHeap) if c > 2: ans += c//4 c = 2 heappush(minHeap, (c, l)) else: if minHeap: heappop(minHeap) ans += 1 print(ans)
93
46
0
151613716
f= int(input()) y=input().split() k=0 for i in range(0,f): for j in range(i+1,f): if (y[i]==y[j] and y[i]!=0 and y[j]!=0): y[i]=0 y[j]=0 k=k+1 break print(k//2)
Codeforces Beta Round 93 (Div. 2 Only)
CF
2,011
1
256
Canvas Frames
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the sticks or glue them together. To make a h × w-sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w. Specifically, to make a square frame (when h = w), he needs four sticks of the same length. Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.
The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100).
Print the single number — the maximum number of frames Nicholas can make for his future canvases.
null
null
[{"input": "5\n2 4 3 2 3", "output": "1"}, {"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3"}, {"input": "4\n3 3 3 5", "output": "0"}]
1,000
["implementation"]
93
[{"input": "5\r\n2 4 3 2 3\r\n", "output": "1"}, {"input": "13\r\n2 2 4 4 4 4 6 6 6 7 7 9 9\r\n", "output": "3"}, {"input": "4\r\n3 3 3 5\r\n", "output": "0"}, {"input": "2\r\n3 5\r\n", "output": "0"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0"}, {"input": "14\r\n2 4 2 6 2 3 4 1 4 5 4 3 4 1\r\n", "output": "2"}, {"input": "33\r\n1 2 2 6 10 10 33 11 17 32 25 6 7 29 11 32 33 8 13 17 17 6 11 11 11 8 10 26 29 26 32 33 36\r\n", "output": "5"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n10\r\n", "output": "0"}, {"input": "2\r\n1 1\r\n", "output": "0"}, {"input": "3\r\n1 1 1\r\n", "output": "0"}, {"input": "3\r\n1 2 2\r\n", "output": "0"}, {"input": "3\r\n3 2 1\r\n", "output": "0"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1"}, {"input": "4\r\n1 2 1 2\r\n", "output": "1"}, {"input": "4\r\n1 100 1 100\r\n", "output": "1"}, {"input": "4\r\n10 100 100 10\r\n", "output": "1"}, {"input": "4\r\n1 2 3 3\r\n", "output": "0"}, {"input": "4\r\n8 5 9 13\r\n", "output": "0"}, {"input": "4\r\n100 100 100 100\r\n", "output": "1"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1"}, {"input": "5\r\n1 4 4 1 1\r\n", "output": "1"}, {"input": "5\r\n1 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 1 100 100 100\r\n", "output": "1"}, {"input": "5\r\n100 100 100 100 100\r\n", "output": "1"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "1"}, {"input": "6\r\n1 1 5 1 1 5\r\n", "output": "1"}, {"input": "6\r\n1 100 100 1 1 1\r\n", "output": "1"}, {"input": "6\r\n100 1 1 100 1 100\r\n", "output": "1"}, {"input": "6\r\n1 2 3 2 3 1\r\n", "output": "1"}, {"input": "6\r\n1 50 1 100 50 100\r\n", "output": "1"}, {"input": "6\r\n10 10 10 12 13 14\r\n", "output": "0"}, {"input": "7\r\n1 1 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 2 1 2 1 2\r\n", "output": "1"}, {"input": "7\r\n1 1 2 2 1 2 3\r\n", "output": "1"}, {"input": "7\r\n1 3 2 2 3 1 4\r\n", "output": "1"}, {"input": "7\r\n1 3 4 3 5 4 6\r\n", "output": "1"}, {"input": "7\r\n7 6 5 4 3 2 1\r\n", "output": "0"}, {"input": "8\r\n1 2 1 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 2 1 1 2 2 2\r\n", "output": "1"}, {"input": "8\r\n1 2 2 2 3 1 1 3\r\n", "output": "1"}, {"input": "8\r\n1 2 3 4 1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n1 1 1 1 2 3 2 3\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 5 5 5\r\n", "output": "1"}, {"input": "8\r\n1 2 1 3 4 1 5 6\r\n", "output": "0"}, {"input": "8\r\n1 2 3 4 5 6 1 7\r\n", "output": "0"}, {"input": "8\r\n8 6 3 4 5 2 1 7\r\n", "output": "0"}, {"input": "8\r\n100 100 100 100 100 100 100 100\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "10\r\n19 9 14 14 19 5 5 18 10 17\r\n", "output": "1"}, {"input": "10\r\n72 86 73 25 84 29 33 34 20 29\r\n", "output": "0"}, {"input": "10\r\n93 93 99 98 91 96 92 98 94 98\r\n", "output": "1"}, {"input": "13\r\n35 6 21 30 67 55 70 39 75 72 11 13 69\r\n", "output": "0"}, {"input": "17\r\n90 97 12 56 94 11 49 96 22 7 15 48 71 71 94 72 100\r\n", "output": "1"}, {"input": "18\r\n39 72 67 28 69 41 43 51 66 99 4 57 68 93 28 27 37 27\r\n", "output": "1"}, {"input": "23\r\n88 82 2 67 4 6 67 83 77 58 48 64 86 37 96 83 35 46 13 79 72 18 35\r\n", "output": "1"}, {"input": "30\r\n43 34 38 50 47 24 26 20 7 5 26 29 98 87 90 46 10 53 88 61 90 39 78 81 65 13 72 95 53 27\r\n", "output": "1"}, {"input": "33\r\n1 3 34 55 38 58 64 26 66 44 50 63 46 62 62 99 73 87 35 20 30 38 39 85 49 24 93 68 8 25 86 30 51\r\n", "output": "1"}, {"input": "38\r\n65 69 80 93 28 36 40 81 53 75 55 50 82 95 8 51 66 65 50 4 40 92 18 70 38 68 42 100 34 57 98 79 95 84 82 35 100 89\r\n", "output": "3"}, {"input": "40\r\n4 2 62 38 76 68 19 71 44 91 76 31 3 63 56 62 93 98 10 61 52 59 81 46 23 27 36 26 24 38 37 66 15 16 78 41 95 82 73 90\r\n", "output": "1"}, {"input": "43\r\n62 31 14 43 67 2 60 77 64 70 91 9 3 43 76 7 56 84 5 20 88 50 47 42 7 39 8 56 71 24 49 59 70 61 81 17 76 44 80 61 77 5 96\r\n", "output": "4"}, {"input": "49\r\n75 64 7 2 1 66 31 84 78 53 34 5 40 90 7 62 86 54 99 77 8 92 30 3 18 18 61 38 38 11 79 88 84 89 50 94 72 8 54 85 100 1 19 4 97 91 13 39 91\r\n", "output": "4"}, {"input": "57\r\n83 94 42 57 19 9 40 25 56 92 9 38 58 66 43 19 50 10 100 3 49 96 77 36 20 3 48 15 38 19 99 100 66 14 52 13 16 73 65 99 29 85 75 18 97 64 57 82 70 19 16 25 40 11 9 22 89\r\n", "output": "6"}, {"input": "67\r\n36 22 22 86 52 53 36 68 46 82 99 37 15 43 57 35 33 99 22 96 7 8 80 93 70 70 55 51 61 74 6 28 85 72 84 42 29 1 4 71 7 40 61 95 93 36 42 61 16 40 10 85 31 86 93 19 44 20 52 66 10 22 40 53 25 29 23\r\n", "output": "8"}, {"input": "74\r\n90 26 58 69 87 23 44 9 32 25 33 13 79 84 52 90 4 7 93 77 29 85 22 1 96 69 98 16 76 87 57 16 44 41 57 28 18 70 77 83 37 17 59 87 27 19 89 63 14 84 77 40 46 77 82 73 86 73 30 58 6 30 70 36 31 12 43 50 93 3 3 57 38 91\r\n", "output": "7"}, {"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": "25"}, {"input": "100\r\n1 9 3 5 10 10 9 8 10 1 7 6 5 6 7 9 1 5 8 3 2 3 3 10 2 3 10 7 10 3 6 3 2 10 1 10 2 3 4 3 3 1 7 5 10 2 3 8 9 2 5 4 7 2 5 9 2 1 7 9 9 8 4 4 6 1 6 6 4 7 2 3 1 1 1 6 9 1 2 9 3 7 6 10 3 6 2 5 2 5 3 9 10 6 4 2 9 9 4 5\r\n", "output": "23"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "7\r\n13 13 13 13 6 2 3\r\n", "output": "1"}, {"input": "8\r\n1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n100 100 99 99 5\r\n", "output": "1"}, {"input": "8\r\n2 2 2 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 6 7 7\r\n", "output": "0"}, {"input": "8\r\n4 4 4 4 4 4 4 4\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 2 2\r\n", "output": "2"}, {"input": "4\r\n100 100 100 99\r\n", "output": "0"}, {"input": "4\r\n2 2 2 2\r\n", "output": "1"}, {"input": "5\r\n100 100 99 99 2\r\n", "output": "1"}, {"input": "9\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n2 2 3 4 4\r\n", "output": "1"}, {"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": "25"}, {"input": "13\r\n1 2 3 4 5 6 7 8 9 10 11 12 13\r\n", "output": "0"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "4\r\n4 4 4 4\r\n", "output": "1"}, {"input": "5\r\n1 1 2 3 3\r\n", "output": "1"}, {"input": "5\r\n30 30 30 1 1\r\n", "output": "1"}]
false
stdio
null
true
682/B
682
B
Python 3
TESTS
66
187
7,475,200
101859467
if __name__ == '__main__': stack = [] amount = int(input()) array = input().split(" ") array.sort() for nr in array: if int(nr) > len(stack): stack.append(1) print(len(stack)+1)
127
93
13,209,600
226023931
n = int(input()) arr = list(map(int, input().split())) # Sort the array arr.sort() # Initialize the mex mex = 1 # Check each element in the array for a in arr: if a >= mex: mex += 1 print(mex)
Codeforces Round 358 (Div. 2)
CF
2,016
1
256
Alyona and Mex
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≤ bi ≤ ai for every 1 ≤ i ≤ n. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array. The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.
Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.
null
In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements.
[{"input": "5\n1 3 3 3 6", "output": "5"}, {"input": "2\n2 1", "output": "3"}]
1,200
["sortings"]
127
[{"input": "5\r\n1 3 3 3 6\r\n", "output": "5\r\n"}, {"input": "2\r\n2 1\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n", "output": "2\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "2\r\n"}, {"input": "1\r\n2\r\n", "output": "2\r\n"}, {"input": "2\r\n1 1\r\n", "output": "2\r\n"}, {"input": "2\r\n1 3\r\n", "output": "3\r\n"}, {"input": "2\r\n2 2\r\n", "output": "3\r\n"}, {"input": "2\r\n2 3\r\n", "output": "3\r\n"}, {"input": "2\r\n3 3\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 4\r\n", "output": "3\r\n"}, {"input": "3\r\n2 1 2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "4\r\n"}, {"input": "3\r\n2 4 1\r\n", "output": "4\r\n"}, {"input": "3\r\n3 3 1\r\n", "output": "4\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 1 4\r\n", "output": "4\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 2 2\r\n", "output": "4\r\n"}, {"input": "3\r\n4 2 2\r\n", "output": "4\r\n"}, {"input": "3\r\n2 3 3\r\n", "output": "4\r\n"}, {"input": "3\r\n4 2 3\r\n", "output": "4\r\n"}, {"input": "3\r\n4 4 2\r\n", "output": "4\r\n"}, {"input": "3\r\n3 3 3\r\n", "output": "4\r\n"}, {"input": "3\r\n4 3 3\r\n", "output": "4\r\n"}, {"input": "3\r\n4 3 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 4 4\r\n", "output": "4\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 2 1\r\n", "output": "3\r\n"}, {"input": "4\r\n1 1 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 1 1\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n1 3 2 1\r\n", "output": "4\r\n"}, {"input": "4\r\n2 1 4 1\r\n", "output": "4\r\n"}, {"input": "4\r\n3 3 1 1\r\n", "output": "4\r\n"}, {"input": "4\r\n1 3 4 1\r\n", "output": "4\r\n"}, {"input": "4\r\n1 1 4 4\r\n", "output": "4\r\n"}, {"input": "4\r\n2 2 2 1\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 2 3\r\n", "output": "4\r\n"}, {"input": "4\r\n2 4 1 2\r\n", "output": "4\r\n"}, {"input": "4\r\n3 3 1 2\r\n", "output": "4\r\n"}, {"input": "4\r\n2 3 4 1\r\n", "output": "5\r\n"}, {"input": "4\r\n1 4 2 4\r\n", "output": "5\r\n"}, {"input": "4\r\n3 1 3 3\r\n", "output": "4\r\n"}, {"input": "4\r\n3 4 3 1\r\n", "output": "5\r\n"}, {"input": "4\r\n1 4 4 3\r\n", "output": "5\r\n"}, {"input": "4\r\n4 1 4 4\r\n", "output": "5\r\n"}, {"input": "4\r\n2 2 2 2\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 3 2\r\n", "output": "4\r\n"}, {"input": "4\r\n2 2 2 4\r\n", "output": "4\r\n"}, {"input": "4\r\n2 2 3 3\r\n", "output": "4\r\n"}, {"input": "4\r\n2 2 3 4\r\n", "output": "5\r\n"}, {"input": "4\r\n2 4 4 2\r\n", "output": "5\r\n"}, {"input": "4\r\n2 3 3 3\r\n", "output": "4\r\n"}, {"input": "4\r\n2 4 3 3\r\n", "output": "5\r\n"}, {"input": "4\r\n4 4 2 3\r\n", "output": "5\r\n"}, {"input": "4\r\n4 4 4 2\r\n", "output": "5\r\n"}, {"input": "4\r\n3 3 3 3\r\n", "output": "4\r\n"}, {"input": "4\r\n3 3 3 4\r\n", "output": "5\r\n"}, {"input": "4\r\n4 3 3 4\r\n", "output": "5\r\n"}, {"input": "4\r\n4 4 3 4\r\n", "output": "5\r\n"}, {"input": "4\r\n4 4 4 4\r\n", "output": "5\r\n"}, {"input": "11\r\n1 1 1 1 1 1 1 1 1 3 3\r\n", "output": "4\r\n"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8\r\n", "output": "9\r\n"}, {"input": "4\r\n2 2 2 3\r\n", "output": "4\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "3\r\n"}, {"input": "15\r\n1 2 2 20 23 25 28 60 66 71 76 77 79 99 100\r\n", "output": "15\r\n"}, {"input": "7\r\n1 2 2 2 5 5 1\r\n", "output": "5\r\n"}, {"input": "4\r\n1 1 1 2\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 1 1 10000\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "3\r\n"}, {"input": "7\r\n1 3 3 3 3 3 6\r\n", "output": "5\r\n"}, {"input": "4\r\n1 1 1 3\r\n", "output": "3\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 100\r\n", "output": "3\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 1 3 4\r\n", "output": "4\r\n"}, {"input": "8\r\n1 1 1 1 2 2 3 40\r\n", "output": "5\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "7\r\n1 2 2 2 2 2 4\r\n", "output": "4\r\n"}, {"input": "10\r\n1 1 1 10000000 10000000 10000000 10000000 10000000 10000000 10000000\r\n", "output": "9\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 2 3\r\n", "output": "4\r\n"}, {"input": "4\r\n8 8 8 8\r\n", "output": "5\r\n"}, {"input": "5\r\n5 6 6 6 7\r\n", "output": "6\r\n"}]
false
stdio
null
true
868/C
868
C
Python 3
TESTS
61
530
6,963,200
34596255
import math def l(n,list): for i in list: if i>=n: return True return False n,k=map(int,input().split()) a=[1]*k c=[] for i in range(n): b=list(map(int,input().split())) c.append(b.count(0)) for j in range(k): a[j]=(a[j] and b[j]) if not(1 in a) and (l(math.ceil(k/2),c)) : print('YES') else: print('NO')
143
155
9,011,200
158133096
import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### n,K = na() from collections import defaultdict d = defaultdict(int) for i in range(n): d[input()] += 1 s = [] for i in d: x = list(map(int,i.split())) if d[i] >= 2: s.append(x) s.append(x) else: s.append(x) m = len(s) ans = 0 for i in range(m): for j in range(i+1,m): for k in range(j+1,m): for l in range(k+1,m): z = [0]*K for t in range(K): z[t] += s[i][t] z[t] += s[j][t] z[t] += s[k][t] z[t] += s[l][t] f = 1 for t in range(K): if z[t] > 2: f = 0 break if f: ans = 1 break if ans: break if ans: break if ans: break for i in range(m): for j in range(i+1,m): for k in range(j+1,m): z = [0]*K for t in range(K): z[t] += s[i][t] z[t] += s[j][t] z[t] += s[k][t] f = 1 for t in range(K): if z[t] > 1: f = 0 break if f: ans = 1 break if ans: break if ans: break for i in range(m): for j in range(i+1,m): z = [0]*K for t in range(K): z[t] += s[i][t] z[t] += s[j][t] f = 1 for t in range(K): if z[t] > 1: f = 0 break if f: ans = 1 break if ans: break for i in range(m): z = [0]*K for t in range(K): z[t] += s[i][t] f = 1 for t in range(K): if z[t] > 0: f = 0 break if f: ans = 1 break if ans: YES() else: NO()
Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
256
Qualification Rounds
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset. k experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems. Determine if Snark and Philip can make an interesting problemset!
The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams. Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise.
Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
null
In the first example you can't make any interesting problemset, because the first team knows all problems. In the second example you can choose the first and the third problems.
[{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}]
1,500
["bitmasks", "brute force", "constructive algorithms", "dp"]
143
[{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n1 0 1\r\n0 1 1\r\n1 0 0\r\n1 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 0 1\r\n1 1 0 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 1 0\r\n0 0 0 0\r\n0 0 1 0\r\n1 0 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n0 0\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 1\r\n1 0 0\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 0\r\n1 1 0 0\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 1\r\n1\r\n1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n0 1 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 1\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 0 1\r\n1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 1 1 0\r\n1 1 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 0\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "6 3\r\n0 1 1\r\n1 0 1\r\n1 1 1\r\n0 1 0\r\n1 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n0 0 0 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 1 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "6 3\r\n1 0 0\r\n1 1 1\r\n1 1 1\r\n0 1 0\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 0 0\r\n1 1 1 1\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "1 3\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 1\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 1 0\r\n1 1 1\r\n0 0 1\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n1 1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n0 1 0 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n1 1 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 1 1\r\n1 0 1 0\r\n1 1 0 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 0 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n1 0\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 0 1\r\n0 0 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n1 1 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "8 4\r\n0 0 0 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 1\r\n1 1 1 0\r\n0 1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n0 0 0 1\r\n1 1 1 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n1 0 1\r\n0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 0 1\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 0 0\r\n1 0 1 0\r\n0 1 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 0 0 0\r\n1 0 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 0 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 0 1\r\n0 1 1 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 1 1\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 0\r\n", "output": "YES\r\n"}]
false
stdio
null
true
814/A
814
A
PyPy 3
TESTS
16
93
0
27632944
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split()))[::-1] cnt2 = 0 for i in range(n): if a[i] == 0: a[i] = b[cnt2] cnt2 += 1 if a == sorted(a): print("No") else: print("Yes")
96
46
0
183853588
n,k=map(int,input().split()) first=list(map(int,input().split())) duplicate=[] increasing=True result=True second=list(map(int,input().split())) second_num=0 for i in range (len(second)-1): if second[i]<second[i+1]: temporary=second[i] second[i]=second[i+1] second[i+1]=temporary for i in range(len(first)): if first[i]==0: first[i]=second[second_num] second_num+=1 for i in first: if i not in duplicate: duplicate.append(i) else: result=False for i in range(len(first)-1): if first[i]>first[i+1]: increasing=False if increasing==True or result==False: print("No") elif increasing==False and result==True: print("Yes")
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An abandoned sentiment from past
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.
The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements. The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in a and b more than once in total.
Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.
null
In the first sample: - Sequence a is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in b are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
[{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}]
900
["constructive algorithms", "greedy", "implementation", "sortings"]
96
[{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\r\n80\r\n", "output": "No\r\n"}, {"input": "100 1\r\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\r\n58\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n2 1 0 4\r\n3\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n199 0\r\n200\r\n", "output": "No\r\n"}, {"input": "3 2\r\n115 0 0\r\n145 191\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n196 197 198 0 200\r\n199\r\n", "output": "No\r\n"}, {"input": "5 1\r\n92 0 97 99 100\r\n93\r\n", "output": "No\r\n"}, {"input": "3 1\r\n3 87 0\r\n81\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 92 192\r\n118\r\n", "output": "Yes\r\n"}, {"input": "10 1\r\n1 3 0 7 35 46 66 72 83 90\r\n22\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 0 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113\r\n67\r\n", "output": "No\r\n"}, {"input": "100 5\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 0 99 100\r\n98 64 55 52 29\r\n", "output": "Yes\r\n"}, {"input": "100 5\r\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\r\n121 199 62 193 27\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 0 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n11\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n1\r\n", "output": "No\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 0\r\n100\r\n", "output": "No\r\n"}, {"input": "100 1\r\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\r\n65\r\n", "output": "Yes\r\n"}, {"input": "100 2\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 0 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n48 1\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\r\n69\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\r\n129\r\n", "output": "No\r\n"}, {"input": "5 2\r\n0 2 7 0 10\r\n1 8\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 4 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 3\r\n4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n1\r\n", "output": "No\r\n"}, {"input": "2 1\r\n0 5\r\n7\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 0 12 13\r\n1\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n0 2 3 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 0 3 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "7 2\r\n1 2 3 0 0 6 7\r\n4 5\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "2 2\r\n0 0\r\n1 2\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n1 0 0\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 4 0\r\n5 2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 1\r\n2\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 4 5\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 2 3\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 5 0\r\n6\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 0 2\r\n7\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n4 5 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 12 0 14\r\n13\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 2 0 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 11 14\r\n12\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 3 0 4\r\n2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 5\r\n1\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 7\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 5 4\r\n6\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n11 0 0 14\r\n13 12\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n1 0\r\n2\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 0 3 2\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 2 3 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 2 0\r\n5\r\n", "output": "No\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 5 7\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 0 11\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n7 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 3 0 5 0\r\n6 4\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n0 1 0\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n6 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 3\r\n6\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 2 0 0 5\r\n4 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n2 0 0 8\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 0 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 2\r\n11 0 0 200\r\n100 199\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n5 0\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 5\r\n10\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 0 0 5 6\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 3 0 5\r\n2 4\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 4 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n5 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 7\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "3 3\r\n0 0 0\r\n1 4 3\r\n", "output": "Yes\r\n"}, {"input": "5 5\r\n0 0 0 0 0\r\n5 4 3 2 1\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n3 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 4 0 8 9 10\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 3 5 6\r\n9\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 2 0 0\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 4 5 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 0 4\r\n5\r\n", "output": "Yes\r\n"}]
false
stdio
null
true
814/A
814
A
Python 3
TESTS
16
93
307,200
99707439
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split()))[::-1] j = 0 for i in range(n): if a[i]==0: a[i]=b[j] j+=1 if a==sorted(a): print("No") else: print("Yes")
96
46
0
186457386
n,k = input().split() L = [int(a) for a in input().split(" ",int(n)-1)] l1 = [int(a) for a in input().split(" ",int(k)-1)] a=0 l1.sort(reverse=True) for i in range(int(n)): if L[i]==0: L[i]=l1[a] a+=1 if a>len(l1): break l2=L[:] l2.sort() if l2==L: print("NO") else: print("YES")
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An abandoned sentiment from past
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.
The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements. The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in a and b more than once in total.
Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.
null
In the first sample: - Sequence a is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in b are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
[{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}]
900
["constructive algorithms", "greedy", "implementation", "sortings"]
96
[{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\r\n80\r\n", "output": "No\r\n"}, {"input": "100 1\r\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\r\n58\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n2 1 0 4\r\n3\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n199 0\r\n200\r\n", "output": "No\r\n"}, {"input": "3 2\r\n115 0 0\r\n145 191\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n196 197 198 0 200\r\n199\r\n", "output": "No\r\n"}, {"input": "5 1\r\n92 0 97 99 100\r\n93\r\n", "output": "No\r\n"}, {"input": "3 1\r\n3 87 0\r\n81\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 92 192\r\n118\r\n", "output": "Yes\r\n"}, {"input": "10 1\r\n1 3 0 7 35 46 66 72 83 90\r\n22\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 0 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113\r\n67\r\n", "output": "No\r\n"}, {"input": "100 5\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 0 99 100\r\n98 64 55 52 29\r\n", "output": "Yes\r\n"}, {"input": "100 5\r\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\r\n121 199 62 193 27\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 0 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n11\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n1\r\n", "output": "No\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 0\r\n100\r\n", "output": "No\r\n"}, {"input": "100 1\r\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\r\n65\r\n", "output": "Yes\r\n"}, {"input": "100 2\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 0 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n48 1\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\r\n69\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\r\n129\r\n", "output": "No\r\n"}, {"input": "5 2\r\n0 2 7 0 10\r\n1 8\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 4 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 3\r\n4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n1\r\n", "output": "No\r\n"}, {"input": "2 1\r\n0 5\r\n7\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 0 12 13\r\n1\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n0 2 3 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 0 3 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "7 2\r\n1 2 3 0 0 6 7\r\n4 5\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "2 2\r\n0 0\r\n1 2\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n1 0 0\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 4 0\r\n5 2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 1\r\n2\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 4 5\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 2 3\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 5 0\r\n6\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 0 2\r\n7\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n4 5 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 12 0 14\r\n13\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 2 0 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 11 14\r\n12\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 3 0 4\r\n2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 5\r\n1\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 7\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 5 4\r\n6\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n11 0 0 14\r\n13 12\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n1 0\r\n2\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 0 3 2\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 2 3 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 2 0\r\n5\r\n", "output": "No\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 5 7\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 0 11\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n7 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 3 0 5 0\r\n6 4\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n0 1 0\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n6 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 3\r\n6\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 2 0 0 5\r\n4 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n2 0 0 8\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 0 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 2\r\n11 0 0 200\r\n100 199\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n5 0\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 5\r\n10\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 0 0 5 6\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 3 0 5\r\n2 4\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 4 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n5 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 7\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "3 3\r\n0 0 0\r\n1 4 3\r\n", "output": "Yes\r\n"}, {"input": "5 5\r\n0 0 0 0 0\r\n5 4 3 2 1\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n3 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 4 0 8 9 10\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 3 5 6\r\n9\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 2 0 0\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 4 5 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 0 4\r\n5\r\n", "output": "Yes\r\n"}]
false
stdio
null
true
814/A
814
A
Python 3
TESTS
16
62
0
27659026
n, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] c = [int(x) for x in input().split()] j = 1 for i in range(n): if a[i] == 0: a[i] = c[-j] j += 1 ans = 'No' for i in range(n - 1): if a[i] > a[i + 1]: ans = 'Yes' print(ans)
96
46
0
189449479
n, k = (int(i) for i in input().split()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] for i in range(n): if a[i] == 0: a[i] = max(b) del b[b.index(max(b))] print(('YES', 'NO')[sorted(a) == a])
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An abandoned sentiment from past
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.
The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements. The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in a and b more than once in total.
Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.
null
In the first sample: - Sequence a is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in b are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
[{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}]
900
["constructive algorithms", "greedy", "implementation", "sortings"]
96
[{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\r\n80\r\n", "output": "No\r\n"}, {"input": "100 1\r\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\r\n58\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n2 1 0 4\r\n3\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n199 0\r\n200\r\n", "output": "No\r\n"}, {"input": "3 2\r\n115 0 0\r\n145 191\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n196 197 198 0 200\r\n199\r\n", "output": "No\r\n"}, {"input": "5 1\r\n92 0 97 99 100\r\n93\r\n", "output": "No\r\n"}, {"input": "3 1\r\n3 87 0\r\n81\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 92 192\r\n118\r\n", "output": "Yes\r\n"}, {"input": "10 1\r\n1 3 0 7 35 46 66 72 83 90\r\n22\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 0 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113\r\n67\r\n", "output": "No\r\n"}, {"input": "100 5\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 0 99 100\r\n98 64 55 52 29\r\n", "output": "Yes\r\n"}, {"input": "100 5\r\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\r\n121 199 62 193 27\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 0 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n11\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n1\r\n", "output": "No\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 0\r\n100\r\n", "output": "No\r\n"}, {"input": "100 1\r\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\r\n65\r\n", "output": "Yes\r\n"}, {"input": "100 2\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 0 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n48 1\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\r\n69\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\r\n129\r\n", "output": "No\r\n"}, {"input": "5 2\r\n0 2 7 0 10\r\n1 8\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 4 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 3\r\n4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n1\r\n", "output": "No\r\n"}, {"input": "2 1\r\n0 5\r\n7\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 0 12 13\r\n1\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n0 2 3 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 0 3 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "7 2\r\n1 2 3 0 0 6 7\r\n4 5\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "2 2\r\n0 0\r\n1 2\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n1 0 0\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 4 0\r\n5 2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 1\r\n2\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 4 5\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 2 3\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 5 0\r\n6\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 0 2\r\n7\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n4 5 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 12 0 14\r\n13\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 2 0 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 11 14\r\n12\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 3 0 4\r\n2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 5\r\n1\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 7\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 5 4\r\n6\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n11 0 0 14\r\n13 12\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n1 0\r\n2\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 0 3 2\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 2 3 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 2 0\r\n5\r\n", "output": "No\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 5 7\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 0 11\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n7 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 3 0 5 0\r\n6 4\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n0 1 0\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n6 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 3\r\n6\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 2 0 0 5\r\n4 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n2 0 0 8\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 0 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 2\r\n11 0 0 200\r\n100 199\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n5 0\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 5\r\n10\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 0 0 5 6\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 3 0 5\r\n2 4\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 4 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n5 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 7\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "3 3\r\n0 0 0\r\n1 4 3\r\n", "output": "Yes\r\n"}, {"input": "5 5\r\n0 0 0 0 0\r\n5 4 3 2 1\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n3 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 4 0 8 9 10\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 3 5 6\r\n9\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 2 0 0\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 4 5 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 0 4\r\n5\r\n", "output": "Yes\r\n"}]
false
stdio
null
true
660/A
660
A
PyPy 3
TESTS
12
109
2,457,600
106014524
from math import gcd n=int(input());arr=list(map(int,input().split()));ans=[] cnt=0 for i in range(n-1): if gcd(arr[i],arr[i+1])>1: ans.append(arr[i]) ans.append(1213);cnt+=1 else:ans.append(arr[i]) ans.append(arr[-1]) print(cnt) print(*ans)
93
46
0
140663013
n=int(input()) l=list(map(int,input().split())) def gcd(a,b): if b==0: return a return gcd(b,a%b) ls=[] c=0 for i in range(n-1): ls.append(l[i]) if gcd(l[i],l[i+1])!=1: c+=1 ls.append(1) ls.append(l[n-1]) print(c) print(*ls)
Educational Codeforces Round 11
ICPC
2,016
1
256
Co-prime Array
You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want not greater than 109 in any place in the array. An array is co-prime if any two adjacent numbers of it are co-prime. In the number theory, two integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.
The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.
Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime. The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array a by adding k elements to it. If there are multiple answers you can print any one of them.
null
null
[{"input": "3\n2 7 28", "output": "1\n2 7 9 28"}]
1,200
["greedy", "implementation", "math", "number theory"]
93
[{"input": "3\r\n2 7 28\r\n", "output": "1\r\n2 7 1 28\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n548\r\n"}, {"input": "1\r\n963837006\r\n", "output": "0\r\n963837006\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n1 1 1 1 1 1 1 1 1 1\r\n"}, {"input": "10\r\n26 723 970 13 422 968 875 329 234 983\r\n", "output": "2\r\n26 723 970 13 422 1 968 875 1 329 234 983\r\n"}, {"input": "10\r\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396\r\n", "output": "7\r\n319645572 1 758298525 1 812547177 1 459359946 1 355467212 1 304450522 807957797 916787906 1 239781206 1 242840396\r\n"}, {"input": "100\r\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1\r\n", "output": "19\r\n1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1\r\n"}, {"input": "100\r\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917\r\n", "output": "38\r\n591 1 417 1 888 251 792 1 847 685 3 182 461 102 1 348 1 555 956 771 901 712 1 878 1 580 631 342 1 333 1 285 899 525 1 725 537 718 929 653 84 1 788 1 104 355 624 803 1 253 853 201 995 536 1 184 65 1 205 1 540 1 652 549 1 777 248 405 677 950 431 580 1 600 1 846 1 328 429 134 983 526 103 500 963 400 23 1 276 1 704 1 570 757 410 1 658 507 620 1 984 1 244 1 486 1 454 1 802 411 985 303 635 283 96 1 597 1 855 1 775 139 839 1 839 61 219 986 1 776 1 72 1 729 1 69 20 917\r\n"}, {"input": "5\r\n472882027 472882027 472882027 472882027 472882027\r\n", "output": "4\r\n472882027 1 472882027 1 472882027 1 472882027 1 472882027\r\n"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "1\r\n1000000000 1 1000000000\r\n"}, {"input": "2\r\n8 6\r\n", "output": "1\r\n8 1 6\r\n"}, {"input": "3\r\n100000000 1000000000 1000000000\r\n", "output": "2\r\n100000000 1 1000000000 1 1000000000\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n1 2 3 4 5\r\n"}, {"input": "20\r\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000\r\n", "output": "19\r\n2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000\r\n"}, {"input": "2\r\n223092870 23\r\n", "output": "1\r\n223092870 1 23\r\n"}, {"input": "2\r\n100000003 100000003\r\n", "output": "1\r\n100000003 1 100000003\r\n"}, {"input": "2\r\n999999937 999999937\r\n", "output": "1\r\n999999937 1 999999937\r\n"}, {"input": "4\r\n999 999999937 999999937 999\r\n", "output": "1\r\n999 999999937 1 999999937 999\r\n"}, {"input": "2\r\n999999929 999999929\r\n", "output": "1\r\n999999929 1 999999929\r\n"}, {"input": "2\r\n1049459 2098918\r\n", "output": "1\r\n1049459 1 2098918\r\n"}, {"input": "2\r\n352229 704458\r\n", "output": "1\r\n352229 1 704458\r\n"}, {"input": "2\r\n7293 4011\r\n", "output": "1\r\n7293 1 4011\r\n"}, {"input": "2\r\n5565651 3999930\r\n", "output": "1\r\n5565651 1 3999930\r\n"}, {"input": "2\r\n997 997\r\n", "output": "1\r\n997 1 997\r\n"}, {"input": "3\r\n9994223 9994223 9994223\r\n", "output": "2\r\n9994223 1 9994223 1 9994223\r\n"}, {"input": "2\r\n99999998 1000000000\r\n", "output": "1\r\n99999998 1 1000000000\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "2\r\n1000000000 1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n130471 130471\r\n", "output": "1\r\n130471 1 130471\r\n"}, {"input": "3\r\n1000000000 2 2\r\n", "output": "2\r\n1000000000 1 2 1 2\r\n"}, {"input": "2\r\n223092870 66526\r\n", "output": "1\r\n223092870 1 66526\r\n"}, {"input": "14\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491 436077930 570018449\r\n", "output": "10\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491 436077930 1 570018449\r\n"}, {"input": "2\r\n3996017 3996017\r\n", "output": "1\r\n3996017 1 3996017\r\n"}, {"input": "2\r\n999983 999983\r\n", "output": "1\r\n999983 1 999983\r\n"}, {"input": "2\r\n618575685 773990454\r\n", "output": "1\r\n618575685 1 773990454\r\n"}, {"input": "3\r\n9699690 3 7\r\n", "output": "1\r\n9699690 1 3 7\r\n"}, {"input": "2\r\n999999999 999999996\r\n", "output": "1\r\n999999999 1 999999996\r\n"}, {"input": "2\r\n99999910 99999910\r\n", "output": "1\r\n99999910 1 99999910\r\n"}, {"input": "12\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491\r\n", "output": "9\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491\r\n"}, {"input": "3\r\n999999937 999999937 999999937\r\n", "output": "2\r\n999999937 1 999999937 1 999999937\r\n"}, {"input": "2\r\n99839 99839\r\n", "output": "1\r\n99839 1 99839\r\n"}, {"input": "3\r\n19999909 19999909 19999909\r\n", "output": "2\r\n19999909 1 19999909 1 19999909\r\n"}, {"input": "4\r\n1 1000000000 1 1000000000\r\n", "output": "0\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n64006 64006\r\n", "output": "1\r\n64006 1 64006\r\n"}, {"input": "2\r\n1956955 1956955\r\n", "output": "1\r\n1956955 1 1956955\r\n"}, {"input": "3\r\n1 1000000000 1000000000\r\n", "output": "1\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n982451707 982451707\r\n", "output": "1\r\n982451707 1 982451707\r\n"}, {"input": "2\r\n999999733 999999733\r\n", "output": "1\r\n999999733 1 999999733\r\n"}, {"input": "3\r\n999999733 999999733 999999733\r\n", "output": "2\r\n999999733 1 999999733 1 999999733\r\n"}, {"input": "2\r\n3257 3257\r\n", "output": "1\r\n3257 1 3257\r\n"}, {"input": "2\r\n223092870 181598\r\n", "output": "1\r\n223092870 1 181598\r\n"}, {"input": "3\r\n959919409 105935 105935\r\n", "output": "2\r\n959919409 1 105935 1 105935\r\n"}, {"input": "2\r\n510510 510510\r\n", "output": "1\r\n510510 1 510510\r\n"}, {"input": "3\r\n223092870 1000000000 1000000000\r\n", "output": "2\r\n223092870 1 1000000000 1 1000000000\r\n"}, {"input": "14\r\n1000000000 2 1000000000 3 1000000000 6 1000000000 1000000000 15 1000000000 1000000000 1000000000 100000000 1000\r\n", "output": "11\r\n1000000000 1 2 1 1000000000 3 1000000000 1 6 1 1000000000 1 1000000000 1 15 1 1000000000 1 1000000000 1 1000000000 1 100000000 1 1000\r\n"}, {"input": "7\r\n1 982451653 982451653 1 982451653 982451653 982451653\r\n", "output": "3\r\n1 982451653 1 982451653 1 982451653 1 982451653 1 982451653\r\n"}, {"input": "2\r\n100000007 100000007\r\n", "output": "1\r\n100000007 1 100000007\r\n"}, {"input": "3\r\n999999757 999999757 999999757\r\n", "output": "2\r\n999999757 1 999999757 1 999999757\r\n"}, {"input": "3\r\n99999989 99999989 99999989\r\n", "output": "2\r\n99999989 1 99999989 1 99999989\r\n"}, {"input": "5\r\n2 4 982451707 982451707 3\r\n", "output": "2\r\n2 1 4 982451707 1 982451707 3\r\n"}, {"input": "2\r\n20000014 20000014\r\n", "output": "1\r\n20000014 1 20000014\r\n"}, {"input": "2\r\n99999989 99999989\r\n", "output": "1\r\n99999989 1 99999989\r\n"}, {"input": "2\r\n111546435 111546435\r\n", "output": "1\r\n111546435 1 111546435\r\n"}, {"input": "2\r\n55288874 33538046\r\n", "output": "1\r\n55288874 1 33538046\r\n"}, {"input": "5\r\n179424673 179424673 179424673 179424673 179424673\r\n", "output": "4\r\n179424673 1 179424673 1 179424673 1 179424673 1 179424673\r\n"}, {"input": "2\r\n199999978 199999978\r\n", "output": "1\r\n199999978 1 199999978\r\n"}, {"input": "2\r\n1000000000 2\r\n", "output": "1\r\n1000000000 1 2\r\n"}, {"input": "3\r\n19999897 19999897 19999897\r\n", "output": "2\r\n19999897 1 19999897 1 19999897\r\n"}, {"input": "2\r\n19999982 19999982\r\n", "output": "1\r\n19999982 1 19999982\r\n"}, {"input": "2\r\n10000007 10000007\r\n", "output": "1\r\n10000007 1 10000007\r\n"}, {"input": "3\r\n999999937 999999937 2\r\n", "output": "1\r\n999999937 1 999999937 2\r\n"}, {"input": "5\r\n2017 2017 2017 2017 2017\r\n", "output": "4\r\n2017 1 2017 1 2017 1 2017 1 2017\r\n"}, {"input": "2\r\n19999909 39999818\r\n", "output": "1\r\n19999909 1 39999818\r\n"}, {"input": "2\r\n62615533 7919\r\n", "output": "1\r\n62615533 1 7919\r\n"}, {"input": "5\r\n39989 39989 33 31 29\r\n", "output": "1\r\n39989 1 39989 33 31 29\r\n"}, {"input": "2\r\n1000000000 100000\r\n", "output": "1\r\n1000000000 1 100000\r\n"}, {"input": "2\r\n1938 10010\r\n", "output": "1\r\n1938 1 10010\r\n"}, {"input": "2\r\n199999 199999\r\n", "output": "1\r\n199999 1 199999\r\n"}, {"input": "2\r\n107273 107273\r\n", "output": "1\r\n107273 1 107273\r\n"}, {"input": "3\r\n49999 49999 49999\r\n", "output": "2\r\n49999 1 49999 1 49999\r\n"}, {"input": "2\r\n1999966 1999958\r\n", "output": "1\r\n1999966 1 1999958\r\n"}, {"input": "2\r\n86020 300846\r\n", "output": "1\r\n86020 1 300846\r\n"}, {"input": "2\r\n999999997 213\r\n", "output": "1\r\n999999997 1 213\r\n"}, {"input": "2\r\n200000014 200000434\r\n", "output": "1\r\n200000014 1 200000434\r\n"}]
false
stdio
import sys import math 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()) a = list(map(int, f.readline().split())) # Read submission output with open(submission_path) as f: lines = f.readlines() if len(lines) < 2: print(0) return try: k_sub = int(lines[0].strip()) array_sub = list(map(int, lines[1].strip().split())) except: print(0) return # Check array_sub length if len(array_sub) != n + k_sub: print(0) return # Read reference output's k_ref with open(output_path) as f: k_ref = int(f.readline().strip()) # Check k_sub equals k_ref if k_sub != k_ref: print(0) return # Check original array is a subsequence of array_sub i = 0 for num in array_sub: if i < len(a) and num == a[i]: i += 1 if i != len(a): print(0) return # Check all adjacent pairs are coprime for j in range(len(array_sub)-1): x = array_sub[j] y = array_sub[j+1] if math.gcd(x, y) != 1: print(0) return # All checks passed print(1) if __name__ == "__main__": main()
true
997/A
997
A
PyPy 3
TESTS
7
155
3,276,800
58482763
n,x,y = map(int,input().split()) a = input() count = 0 for i in range(n-1): if a[i] == '0' and a[i+1] == '1': count+=1 elif a[i] == '0' and i == n-2: count+=1 if count == 0: print(0) else: print((count-1)*min(x,y)+y)
115
77
2,560,000
205518974
n, x, y = map(int, input().split(' ')) s = input() cnt = 0 i = 0 # 1010 # 0110 # 0001 # 1111 # 0110 while i < len(s): if s[i] == '0': cnt += 1 while i < len(s) and s[i] == '0': i += 1 i += 1 if cnt > 0: if x < y: print((cnt - 1) * x + y) else: print(cnt * y) else: print(0)
Codeforces Round 493 (Div. 1)
CF
2,018
1
256
Convert to Ones
You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones. Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$. You can apply the following operations any number of times: - Choose some substring of string $$$a$$$ (for example, you can choose entire string) and reverse it, paying $$$x$$$ coins for it (for example, «0101101» $$$\to$$$ «0111001»); - Choose some substring of string $$$a$$$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $$$y$$$ coins for it (for example, «0101101» $$$\to$$$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones?
The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $$$a$$$ of length $$$n$$$, consisting of zeros and ones.
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations.
null
In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «10000» $$$\to$$$ «11111». The total cost of operations is $$$1 + 10 = 11$$$. In the second sample, at first you need to invert substring $$$[1 \dots 1]$$$, and then you need to invert substring $$$[3 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «11000» $$$\to$$$ «11111». The overall cost is $$$1 + 1 = 2$$$. In the third example, string already consists only of ones, so the answer is $$$0$$$.
[{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}]
1,500
["brute force", "greedy", "implementation", "math"]
115
[{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 261764879\r\n0\r\n", "output": "261764879\r\n"}, {"input": "1 491511050 399084767\r\n1\r\n", "output": "0\r\n"}, {"input": "2 163093925 214567542\r\n00\r\n", "output": "214567542\r\n"}, {"input": "2 340351106 646854722\r\n10\r\n", "output": "646854722\r\n"}, {"input": "2 222640995 489207317\r\n01\r\n", "output": "489207317\r\n"}, {"input": "2 399898176 552898277\r\n11\r\n", "output": "0\r\n"}, {"input": "2 690218164 577155357\r\n00\r\n", "output": "577155357\r\n"}, {"input": "2 827538051 754412538\r\n10\r\n", "output": "754412538\r\n"}, {"input": "2 636702427 259825230\r\n01\r\n", "output": "259825230\r\n"}, {"input": "2 108926899 102177825\r\n11\r\n", "output": "0\r\n"}, {"input": "3 368381052 440077270\r\n000\r\n", "output": "440077270\r\n"}, {"input": "3 505700940 617334451\r\n100\r\n", "output": "617334451\r\n"}, {"input": "3 499624340 643020827\r\n010\r\n", "output": "1142645167\r\n"}, {"input": "3 75308005 971848814\r\n110\r\n", "output": "971848814\r\n"}, {"input": "3 212627893 854138703\r\n001\r\n", "output": "854138703\r\n"}, {"input": "3 31395883 981351561\r\n101\r\n", "output": "981351561\r\n"}, {"input": "3 118671447 913685773\r\n011\r\n", "output": "913685773\r\n"}, {"input": "3 255991335 385910245\r\n111\r\n", "output": "0\r\n"}, {"input": "3 688278514 268200134\r\n000\r\n", "output": "268200134\r\n"}, {"input": "3 825598402 445457315\r\n100\r\n", "output": "445457315\r\n"}, {"input": "3 300751942 45676507\r\n010\r\n", "output": "91353014\r\n"}, {"input": "3 517900980 438071829\r\n110\r\n", "output": "438071829\r\n"}, {"input": "3 400190869 280424424\r\n001\r\n", "output": "280424424\r\n"}, {"input": "3 577448050 344115384\r\n101\r\n", "output": "344115384\r\n"}, {"input": "3 481435271 459737939\r\n011\r\n", "output": "459737939\r\n"}, {"input": "3 931962412 913722450\r\n111\r\n", "output": "0\r\n"}, {"input": "4 522194562 717060616\r\n0000\r\n", "output": "717060616\r\n"}, {"input": "4 659514449 894317797\r\n1000\r\n", "output": "894317797\r\n"}, {"input": "4 71574977 796834337\r\n0100\r\n", "output": "868409314\r\n"}, {"input": "4 248832158 934154224\r\n1100\r\n", "output": "934154224\r\n"}, {"input": "4 71474110 131122047\r\n0010\r\n", "output": "202596157\r\n"}, {"input": "4 308379228 503761290\r\n1010\r\n", "output": "812140518\r\n"}, {"input": "4 272484957 485636409\r\n0110\r\n", "output": "758121366\r\n"}, {"input": "4 662893590 704772137\r\n1110\r\n", "output": "704772137\r\n"}, {"input": "4 545183479 547124732\r\n0001\r\n", "output": "547124732\r\n"}, {"input": "4 684444619 722440661\r\n1001\r\n", "output": "722440661\r\n"}, {"input": "4 477963686 636258459\r\n0101\r\n", "output": "1114222145\r\n"}, {"input": "4 360253575 773578347\r\n1101\r\n", "output": "773578347\r\n"}, {"input": "4 832478048 910898234\r\n0011\r\n", "output": "910898234\r\n"}, {"input": "4 343185412 714767937\r\n1011\r\n", "output": "714767937\r\n"}, {"input": "4 480505300 892025118\r\n0111\r\n", "output": "892025118\r\n"}, {"input": "4 322857895 774315007\r\n1111\r\n", "output": "0\r\n"}, {"input": "4 386548854 246539479\r\n0000\r\n", "output": "246539479\r\n"}, {"input": "4 523868742 128829368\r\n1000\r\n", "output": "128829368\r\n"}, {"input": "4 956155921 11119257\r\n0100\r\n", "output": "22238514\r\n"}, {"input": "4 188376438 93475808\r\n1100\r\n", "output": "93475808\r\n"}, {"input": "4 754947032 158668188\r\n0010\r\n", "output": "317336376\r\n"}, {"input": "4 927391856 637236921\r\n1010\r\n", "output": "1274473842\r\n"}, {"input": "4 359679035 109461393\r\n0110\r\n", "output": "218922786\r\n"}, {"input": "4 991751283 202031630\r\n1110\r\n", "output": "202031630\r\n"}, {"input": "4 339351517 169008463\r\n0001\r\n", "output": "169008463\r\n"}, {"input": "4 771638697 346265644\r\n1001\r\n", "output": "346265644\r\n"}, {"input": "4 908958584 523522825\r\n0101\r\n", "output": "1047045650\r\n"}, {"input": "4 677682252 405812714\r\n1101\r\n", "output": "405812714\r\n"}, {"input": "4 815002139 288102603\r\n0011\r\n", "output": "288102603\r\n"}, {"input": "4 952322026 760327076\r\n1011\r\n", "output": "760327076\r\n"}, {"input": "4 663334158 312481698\r\n0111\r\n", "output": "312481698\r\n"}, {"input": "4 840591339 154834293\r\n1111\r\n", "output": "0\r\n"}, {"input": "14 3 11\r\n10110100011001\r\n", "output": "20\r\n"}, {"input": "19 1 1\r\n1010101010101010101\r\n", "output": "9\r\n"}, {"input": "1 10 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 100 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 1000 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 10 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "7 3 2\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 10\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 3 2\r\n1\r\n", "output": "0\r\n"}, {"input": "2 10 1\r\n11\r\n", "output": "0\r\n"}, {"input": "4 148823922 302792601\r\n1010\r\n", "output": "451616523\r\n"}, {"input": "1 2 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n00011\r\n", "output": "3\r\n"}, {"input": "1 5 0\r\n1\r\n", "output": "0\r\n"}, {"input": "7 2 3\r\n1001001\r\n", "output": "5\r\n"}, {"input": "10 1 1000000000\r\n1111010111\r\n", "output": "1000000001\r\n"}, {"input": "25 999999998 999999999\r\n1011001110101010100111001\r\n", "output": "7999999985\r\n"}, {"input": "2 0 1\r\n00\r\n", "output": "1\r\n"}, {"input": "2 1 100\r\n10\r\n", "output": "100\r\n"}, {"input": "7 20 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "0\r\n"}, {"input": "3 1 10\r\n010\r\n", "output": "11\r\n"}, {"input": "2 1 0\r\n11\r\n", "output": "0\r\n"}, {"input": "7 100 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 1000\r\n10101\r\n", "output": "1001\r\n"}, {"input": "5 2 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "1 1000 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 799543940 488239239\r\n1\r\n", "output": "0\r\n"}, {"input": "6 1 1000\r\n010101\r\n", "output": "1002\r\n"}, {"input": "5 11 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n10101\r\n", "output": "5\r\n"}, {"input": "3 10 1\r\n111\r\n", "output": "0\r\n"}, {"input": "7 9 10\r\n1001011\r\n", "output": "19\r\n"}, {"input": "5 5 6\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 1000000000 0\r\n1\r\n", "output": "0\r\n"}, {"input": "4 0 1\r\n0101\r\n", "output": "1\r\n"}, {"input": "8 2 3\r\n10101010\r\n", "output": "9\r\n"}, {"input": "6 3 100\r\n010101\r\n", "output": "106\r\n"}, {"input": "3 3 2\r\n111\r\n", "output": "0\r\n"}, {"input": "1 20 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n01\r\n", "output": "2\r\n"}]
false
stdio
null
true
660/A
660
A
Python 3
TESTS
14
62
6,963,200
123542744
def mdcEuclidiano(x, y): while(y): x, y = y, x % y return x def achaBigMC(x,y): t = True num = x+1 while(t): if(mdcEuclidiano(x, num) == 1 and mdcEuclidiano(num, y) == 1): t = False else: num +=1 return num tam = int(input()) k = 0 arraySaida = "" numeros = str(input()).split() for x in range(tam-1): if(mdcEuclidiano(int(numeros[x]), int(numeros[x+1])) != 1): novo = achaBigMC(int(numeros[x]), int(numeros[x+1])) arraySaida += numeros[x] + " " arraySaida += str(novo) + " " k+=1 else: arraySaida += str(numeros[x]) + " " arraySaida += numeros[tam -1] print(k) print(arraySaida)
93
46
0
155232013
from math import gcd tam = int(input()) seq = [int(n) for n in input().split()] correta = [seq[0]] i = 1 while i < len(seq): mdc = gcd(seq[i], correta[-1]) if mdc == 1: correta.append(seq[i]) i += 1 else: correta.append(1) correta = [str(n) for n in correta] print(len(correta) - tam) print(' '.join(correta))
Educational Codeforces Round 11
ICPC
2,016
1
256
Co-prime Array
You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want not greater than 109 in any place in the array. An array is co-prime if any two adjacent numbers of it are co-prime. In the number theory, two integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.
The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.
Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime. The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array a by adding k elements to it. If there are multiple answers you can print any one of them.
null
null
[{"input": "3\n2 7 28", "output": "1\n2 7 9 28"}]
1,200
["greedy", "implementation", "math", "number theory"]
93
[{"input": "3\r\n2 7 28\r\n", "output": "1\r\n2 7 1 28\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n548\r\n"}, {"input": "1\r\n963837006\r\n", "output": "0\r\n963837006\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n1 1 1 1 1 1 1 1 1 1\r\n"}, {"input": "10\r\n26 723 970 13 422 968 875 329 234 983\r\n", "output": "2\r\n26 723 970 13 422 1 968 875 1 329 234 983\r\n"}, {"input": "10\r\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396\r\n", "output": "7\r\n319645572 1 758298525 1 812547177 1 459359946 1 355467212 1 304450522 807957797 916787906 1 239781206 1 242840396\r\n"}, {"input": "100\r\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1\r\n", "output": "19\r\n1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1\r\n"}, {"input": "100\r\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917\r\n", "output": "38\r\n591 1 417 1 888 251 792 1 847 685 3 182 461 102 1 348 1 555 956 771 901 712 1 878 1 580 631 342 1 333 1 285 899 525 1 725 537 718 929 653 84 1 788 1 104 355 624 803 1 253 853 201 995 536 1 184 65 1 205 1 540 1 652 549 1 777 248 405 677 950 431 580 1 600 1 846 1 328 429 134 983 526 103 500 963 400 23 1 276 1 704 1 570 757 410 1 658 507 620 1 984 1 244 1 486 1 454 1 802 411 985 303 635 283 96 1 597 1 855 1 775 139 839 1 839 61 219 986 1 776 1 72 1 729 1 69 20 917\r\n"}, {"input": "5\r\n472882027 472882027 472882027 472882027 472882027\r\n", "output": "4\r\n472882027 1 472882027 1 472882027 1 472882027 1 472882027\r\n"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "1\r\n1000000000 1 1000000000\r\n"}, {"input": "2\r\n8 6\r\n", "output": "1\r\n8 1 6\r\n"}, {"input": "3\r\n100000000 1000000000 1000000000\r\n", "output": "2\r\n100000000 1 1000000000 1 1000000000\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n1 2 3 4 5\r\n"}, {"input": "20\r\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000\r\n", "output": "19\r\n2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000\r\n"}, {"input": "2\r\n223092870 23\r\n", "output": "1\r\n223092870 1 23\r\n"}, {"input": "2\r\n100000003 100000003\r\n", "output": "1\r\n100000003 1 100000003\r\n"}, {"input": "2\r\n999999937 999999937\r\n", "output": "1\r\n999999937 1 999999937\r\n"}, {"input": "4\r\n999 999999937 999999937 999\r\n", "output": "1\r\n999 999999937 1 999999937 999\r\n"}, {"input": "2\r\n999999929 999999929\r\n", "output": "1\r\n999999929 1 999999929\r\n"}, {"input": "2\r\n1049459 2098918\r\n", "output": "1\r\n1049459 1 2098918\r\n"}, {"input": "2\r\n352229 704458\r\n", "output": "1\r\n352229 1 704458\r\n"}, {"input": "2\r\n7293 4011\r\n", "output": "1\r\n7293 1 4011\r\n"}, {"input": "2\r\n5565651 3999930\r\n", "output": "1\r\n5565651 1 3999930\r\n"}, {"input": "2\r\n997 997\r\n", "output": "1\r\n997 1 997\r\n"}, {"input": "3\r\n9994223 9994223 9994223\r\n", "output": "2\r\n9994223 1 9994223 1 9994223\r\n"}, {"input": "2\r\n99999998 1000000000\r\n", "output": "1\r\n99999998 1 1000000000\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "2\r\n1000000000 1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n130471 130471\r\n", "output": "1\r\n130471 1 130471\r\n"}, {"input": "3\r\n1000000000 2 2\r\n", "output": "2\r\n1000000000 1 2 1 2\r\n"}, {"input": "2\r\n223092870 66526\r\n", "output": "1\r\n223092870 1 66526\r\n"}, {"input": "14\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491 436077930 570018449\r\n", "output": "10\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491 436077930 1 570018449\r\n"}, {"input": "2\r\n3996017 3996017\r\n", "output": "1\r\n3996017 1 3996017\r\n"}, {"input": "2\r\n999983 999983\r\n", "output": "1\r\n999983 1 999983\r\n"}, {"input": "2\r\n618575685 773990454\r\n", "output": "1\r\n618575685 1 773990454\r\n"}, {"input": "3\r\n9699690 3 7\r\n", "output": "1\r\n9699690 1 3 7\r\n"}, {"input": "2\r\n999999999 999999996\r\n", "output": "1\r\n999999999 1 999999996\r\n"}, {"input": "2\r\n99999910 99999910\r\n", "output": "1\r\n99999910 1 99999910\r\n"}, {"input": "12\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491\r\n", "output": "9\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491\r\n"}, {"input": "3\r\n999999937 999999937 999999937\r\n", "output": "2\r\n999999937 1 999999937 1 999999937\r\n"}, {"input": "2\r\n99839 99839\r\n", "output": "1\r\n99839 1 99839\r\n"}, {"input": "3\r\n19999909 19999909 19999909\r\n", "output": "2\r\n19999909 1 19999909 1 19999909\r\n"}, {"input": "4\r\n1 1000000000 1 1000000000\r\n", "output": "0\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n64006 64006\r\n", "output": "1\r\n64006 1 64006\r\n"}, {"input": "2\r\n1956955 1956955\r\n", "output": "1\r\n1956955 1 1956955\r\n"}, {"input": "3\r\n1 1000000000 1000000000\r\n", "output": "1\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n982451707 982451707\r\n", "output": "1\r\n982451707 1 982451707\r\n"}, {"input": "2\r\n999999733 999999733\r\n", "output": "1\r\n999999733 1 999999733\r\n"}, {"input": "3\r\n999999733 999999733 999999733\r\n", "output": "2\r\n999999733 1 999999733 1 999999733\r\n"}, {"input": "2\r\n3257 3257\r\n", "output": "1\r\n3257 1 3257\r\n"}, {"input": "2\r\n223092870 181598\r\n", "output": "1\r\n223092870 1 181598\r\n"}, {"input": "3\r\n959919409 105935 105935\r\n", "output": "2\r\n959919409 1 105935 1 105935\r\n"}, {"input": "2\r\n510510 510510\r\n", "output": "1\r\n510510 1 510510\r\n"}, {"input": "3\r\n223092870 1000000000 1000000000\r\n", "output": "2\r\n223092870 1 1000000000 1 1000000000\r\n"}, {"input": "14\r\n1000000000 2 1000000000 3 1000000000 6 1000000000 1000000000 15 1000000000 1000000000 1000000000 100000000 1000\r\n", "output": "11\r\n1000000000 1 2 1 1000000000 3 1000000000 1 6 1 1000000000 1 1000000000 1 15 1 1000000000 1 1000000000 1 1000000000 1 100000000 1 1000\r\n"}, {"input": "7\r\n1 982451653 982451653 1 982451653 982451653 982451653\r\n", "output": "3\r\n1 982451653 1 982451653 1 982451653 1 982451653 1 982451653\r\n"}, {"input": "2\r\n100000007 100000007\r\n", "output": "1\r\n100000007 1 100000007\r\n"}, {"input": "3\r\n999999757 999999757 999999757\r\n", "output": "2\r\n999999757 1 999999757 1 999999757\r\n"}, {"input": "3\r\n99999989 99999989 99999989\r\n", "output": "2\r\n99999989 1 99999989 1 99999989\r\n"}, {"input": "5\r\n2 4 982451707 982451707 3\r\n", "output": "2\r\n2 1 4 982451707 1 982451707 3\r\n"}, {"input": "2\r\n20000014 20000014\r\n", "output": "1\r\n20000014 1 20000014\r\n"}, {"input": "2\r\n99999989 99999989\r\n", "output": "1\r\n99999989 1 99999989\r\n"}, {"input": "2\r\n111546435 111546435\r\n", "output": "1\r\n111546435 1 111546435\r\n"}, {"input": "2\r\n55288874 33538046\r\n", "output": "1\r\n55288874 1 33538046\r\n"}, {"input": "5\r\n179424673 179424673 179424673 179424673 179424673\r\n", "output": "4\r\n179424673 1 179424673 1 179424673 1 179424673 1 179424673\r\n"}, {"input": "2\r\n199999978 199999978\r\n", "output": "1\r\n199999978 1 199999978\r\n"}, {"input": "2\r\n1000000000 2\r\n", "output": "1\r\n1000000000 1 2\r\n"}, {"input": "3\r\n19999897 19999897 19999897\r\n", "output": "2\r\n19999897 1 19999897 1 19999897\r\n"}, {"input": "2\r\n19999982 19999982\r\n", "output": "1\r\n19999982 1 19999982\r\n"}, {"input": "2\r\n10000007 10000007\r\n", "output": "1\r\n10000007 1 10000007\r\n"}, {"input": "3\r\n999999937 999999937 2\r\n", "output": "1\r\n999999937 1 999999937 2\r\n"}, {"input": "5\r\n2017 2017 2017 2017 2017\r\n", "output": "4\r\n2017 1 2017 1 2017 1 2017 1 2017\r\n"}, {"input": "2\r\n19999909 39999818\r\n", "output": "1\r\n19999909 1 39999818\r\n"}, {"input": "2\r\n62615533 7919\r\n", "output": "1\r\n62615533 1 7919\r\n"}, {"input": "5\r\n39989 39989 33 31 29\r\n", "output": "1\r\n39989 1 39989 33 31 29\r\n"}, {"input": "2\r\n1000000000 100000\r\n", "output": "1\r\n1000000000 1 100000\r\n"}, {"input": "2\r\n1938 10010\r\n", "output": "1\r\n1938 1 10010\r\n"}, {"input": "2\r\n199999 199999\r\n", "output": "1\r\n199999 1 199999\r\n"}, {"input": "2\r\n107273 107273\r\n", "output": "1\r\n107273 1 107273\r\n"}, {"input": "3\r\n49999 49999 49999\r\n", "output": "2\r\n49999 1 49999 1 49999\r\n"}, {"input": "2\r\n1999966 1999958\r\n", "output": "1\r\n1999966 1 1999958\r\n"}, {"input": "2\r\n86020 300846\r\n", "output": "1\r\n86020 1 300846\r\n"}, {"input": "2\r\n999999997 213\r\n", "output": "1\r\n999999997 1 213\r\n"}, {"input": "2\r\n200000014 200000434\r\n", "output": "1\r\n200000014 1 200000434\r\n"}]
false
stdio
import sys import math 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()) a = list(map(int, f.readline().split())) # Read submission output with open(submission_path) as f: lines = f.readlines() if len(lines) < 2: print(0) return try: k_sub = int(lines[0].strip()) array_sub = list(map(int, lines[1].strip().split())) except: print(0) return # Check array_sub length if len(array_sub) != n + k_sub: print(0) return # Read reference output's k_ref with open(output_path) as f: k_ref = int(f.readline().strip()) # Check k_sub equals k_ref if k_sub != k_ref: print(0) return # Check original array is a subsequence of array_sub i = 0 for num in array_sub: if i < len(a) and num == a[i]: i += 1 if i != len(a): print(0) return # Check all adjacent pairs are coprime for j in range(len(array_sub)-1): x = array_sub[j] y = array_sub[j+1] if math.gcd(x, y) != 1: print(0) return # All checks passed print(1) if __name__ == "__main__": main()
true
789/B
789
B
Python 3
TESTS
19
78
15,974,400
25921383
b1, q, l, m = map(int, input().split()) a = set(map(int, input().split())) b1 = abs(b1) q = abs(q) ans = 0 k = 0 while b1 <= l: if not (b1 in a): ans += 1 k += 1 b1 *= q if k > m + 3: if ans == 0 or ans == 1: print(ans) else: print("inf") exit() print(ans)
116
93
15,667,200
25926860
b, q, l, m = map(int, input().split()) A = set(map(int, input().split())) ans = 0 for _ in range(100): if abs(b) > l: break if b not in A: ans += 1 b *= q if ans > 40: print("inf") else: print(ans)
Codeforces Round 407 (Div. 2)
CF
2,017
1
256
Masha and geometric depression
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board.
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
null
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123.
[{"input": "3 2 30 4\n6 14 25 48", "output": "3"}, {"input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0"}, {"input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf"}]
1,700
["brute force", "implementation", "math"]
116
[{"input": "3 2 30 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "123 1 2143435 4\r\n123 11 -5453 141245\r\n", "output": "0"}, {"input": "123 1 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "3 2 25 2\r\n379195692 -69874783\r\n", "output": "4"}, {"input": "3 2 30 3\r\n-691070108 -934106649 -220744807\r\n", "output": "4"}, {"input": "3 3 104 17\r\n9 -73896485 -290898562 5254410 409659728 -916522518 -435516126 94354167 262981034 -375897180 -80186684 -173062070 -288705544 -699097793 -11447747 320434295 503414250\r\n", "output": "3"}, {"input": "-1000000000 -1000000000 1 1\r\n232512888\r\n", "output": "0"}, {"input": "11 0 228 5\r\n-1 0 1 5 -11245\r\n", "output": "1"}, {"input": "11 0 228 5\r\n-1 -17 1 5 -11245\r\n", "output": "inf"}, {"input": "0 0 2143435 5\r\n-1 -153 1 5 -11245\r\n", "output": "inf"}, {"input": "123 0 2143435 4\r\n5433 0 123 -645\r\n", "output": "0"}, {"input": "123 -1 2143435 5\r\n-123 0 12 5 -11245\r\n", "output": "inf"}, {"input": "123 0 21 4\r\n543453 -123 6 1424\r\n", "output": "0"}, {"input": "3 2 115 16\r\n24 48 12 96 3 720031148 -367712651 -838596957 558177735 -963046495 -313322487 -465018432 -618984128 -607173835 144854086 178041956\r\n", "output": "1"}, {"input": "-3 0 92055 36\r\n-92974174 -486557474 -663622151 695596393 177960746 -563227474 -364263320 -676254242 -614140218 71456762 -764104225 705056581 -106398436 332755134 -199942822 -732751692 658942664 677739866 886535704 183687802 -784248291 -22550621 -938674499 637055091 -704750213 780395802 778342470 -999059668 -794361783 796469192 215667969 354336794 -60195289 -885080928 -290279020 201221317\r\n", "output": "inf"}, {"input": "0 -3 2143435 5\r\n-1 0 1 5 -11245\r\n", "output": "0"}, {"input": "123 -1 2143435 5\r\n-123 0 123 -5453 141245\r\n", "output": "0"}, {"input": "123 0 2143435 4\r\n5433 0 -123 -645\r\n", "output": "1"}, {"input": "11 0 2 5\r\n-1 0 1 5 -11245\r\n", "output": "0"}, {"input": "2 2 4 1\r\n2\r\n", "output": "1"}, {"input": "1 -2 1000000000 1\r\n0\r\n", "output": "30"}, {"input": "0 8 10 1\r\n5\r\n", "output": "inf"}, {"input": "-1000 0 10 1\r\n5\r\n", "output": "0"}, {"input": "0 2 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "0 8 5 1\r\n9\r\n", "output": "inf"}, {"input": "-10 1 5 1\r\n100\r\n", "output": "0"}, {"input": "123 -1 2143435 4\r\n54343 -13 6 123\r\n", "output": "inf"}, {"input": "-5 -1 10 1\r\n-5\r\n", "output": "inf"}, {"input": "2 0 1 1\r\n2\r\n", "output": "0"}, {"input": "0 5 8 1\r\n10\r\n", "output": "inf"}, {"input": "0 5 100 2\r\n34 56\r\n", "output": "inf"}, {"input": "15 -1 15 4\r\n15 -15 1 2\r\n", "output": "0"}, {"input": "10 -1 2 1\r\n1\r\n", "output": "0"}, {"input": "2 0 2 1\r\n2\r\n", "output": "inf"}, {"input": "4 0 4 1\r\n0\r\n", "output": "1"}, {"input": "10 10 10 1\r\n123\r\n", "output": "1"}, {"input": "2 2 4 1\r\n3\r\n", "output": "2"}, {"input": "0 1 1 1\r\n0\r\n", "output": "0"}, {"input": "3 2 30 1\r\n3\r\n", "output": "3"}, {"input": "1000000000 100000 1000000000 4\r\n5433 13 6 0\r\n", "output": "1"}, {"input": "-2 0 1 1\r\n1\r\n", "output": "0"}, {"input": "2 -1 10 1\r\n2\r\n", "output": "inf"}, {"input": "1 -1 2 1\r\n1\r\n", "output": "inf"}, {"input": "0 10 10 1\r\n2\r\n", "output": "inf"}, {"input": "0 35 2 1\r\n3\r\n", "output": "inf"}, {"input": "3 1 3 1\r\n5\r\n", "output": "inf"}, {"input": "3 2 3 4\r\n6 14 25 48\r\n", "output": "1"}, {"input": "0 69 12 1\r\n1\r\n", "output": "inf"}, {"input": "100 0 100000 1\r\n100\r\n", "output": "inf"}, {"input": "0 4 1000 3\r\n5 6 7\r\n", "output": "inf"}, {"input": "0 2 100 1\r\n5\r\n", "output": "inf"}, {"input": "3 2 24 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "0 4 1 1\r\n2\r\n", "output": "inf"}, {"input": "1 5 10000 1\r\n125\r\n", "output": "5"}, {"input": "2 -1 1 1\r\n1\r\n", "output": "0"}, {"input": "0 3 100 1\r\n5\r\n", "output": "inf"}, {"input": "0 3 3 1\r\n1\r\n", "output": "inf"}, {"input": "0 2 5 1\r\n1\r\n", "output": "inf"}, {"input": "5 -1 100 1\r\n5\r\n", "output": "inf"}, {"input": "-20 0 10 1\r\n0\r\n", "output": "0"}, {"input": "3 0 1 1\r\n3\r\n", "output": "0"}, {"input": "2 -1 3 1\r\n2\r\n", "output": "inf"}, {"input": "1 1 1000000000 1\r\n100\r\n", "output": "inf"}, {"input": "5 -1 3 1\r\n0\r\n", "output": "0"}, {"input": "0 5 10 1\r\n2\r\n", "output": "inf"}, {"input": "123 0 125 1\r\n123\r\n", "output": "inf"}, {"input": "2 -1 100 1\r\n2\r\n", "output": "inf"}, {"input": "5 2 100 1\r\n5\r\n", "output": "4"}, {"input": "-5 0 1 1\r\n1\r\n", "output": "0"}, {"input": "-3 0 1 1\r\n-3\r\n", "output": "0"}, {"input": "2 -2 10 1\r\n1\r\n", "output": "3"}, {"input": "0 2 30 4\r\n6 14 25 48\r\n", "output": "inf"}, {"input": "1 -1 1 1\r\n1\r\n", "output": "inf"}, {"input": "2 -1 6 1\r\n2\r\n", "output": "inf"}, {"input": "-3 1 100 1\r\n-3\r\n", "output": "0"}, {"input": "1 0 2 1\r\n1\r\n", "output": "inf"}, {"input": "1000000000 999999998 1000000000 1\r\n0\r\n", "output": "1"}, {"input": "1 0 2143435 4\r\n1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "-1000 0 100 1\r\n-1000\r\n", "output": "0"}, {"input": "100 10 2 1\r\n100\r\n", "output": "0"}, {"input": "-3 1 100 1\r\n3\r\n", "output": "inf"}, {"input": "123 -1 10000 1\r\n123\r\n", "output": "inf"}, {"input": "1 -1 2143435 4\r\n1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "5 1 5 5\r\n1 2 3 4 0\r\n", "output": "inf"}, {"input": "-100 -1 1 1\r\n1\r\n", "output": "0"}, {"input": "10 -1 3 2\r\n10 8\r\n", "output": "0"}, {"input": "-10 0 5 1\r\n0\r\n", "output": "0"}, {"input": "3 0 3 1\r\n0\r\n", "output": "1"}, {"input": "2 0 2 1\r\n-1\r\n", "output": "inf"}, {"input": "5 0 20 1\r\n5\r\n", "output": "inf"}, {"input": "-4 1 1 1\r\n0\r\n", "output": "0"}, {"input": "11 0 1111 1\r\n11\r\n", "output": "inf"}, {"input": "2 0 3 1\r\n2\r\n", "output": "inf"}, {"input": "-1 -1 2143435 4\r\n-1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "-100 0 50 1\r\n0\r\n", "output": "0"}, {"input": "5 1 2 1\r\n2\r\n", "output": "0"}, {"input": "3 0 3 1\r\n4\r\n", "output": "inf"}, {"input": "0 23 3 1\r\n3\r\n", "output": "inf"}, {"input": "-1000 0 100 1\r\n2\r\n", "output": "0"}, {"input": "1 -1 10 1\r\n1\r\n", "output": "inf"}]
false
stdio
null
true
660/A
660
A
PyPy 3-64
TESTS
14
61
1,536,000
204355182
import math n = int(input()) arr = list(map(int, input().split())) ans = [arr[0]] for i in range(1, n): tmp = ans[-1] if math.gcd(tmp, arr[i]) == 1: ans.append(arr[i]) else: temp = tmp+1 while True: if math.gcd(tmp, temp) == 1 and math.gcd(temp, arr[i]) == 1: ans.append(temp) ans.append(arr[i]) break else: temp = temp+1 print(len(ans)-n) print(' '.join(list(map(str, ans))))
93
46
0
161637033
'https://codeforces.com/contest/660/problem/A' def computeGCD(x, y): while(y): x,y=y,x%y return abs(x) n=int(input()) ans=0 num1=[] num=list(map(int,input().split())) for i in range(1,n): if(computeGCD(num[i-1],num[i])==1): num1.append(num[i-1]) else: num1.append(num[i-1]) num1.append(1) ans+=1 num1.append(num[n-1]) print(ans) print(*num1)
Educational Codeforces Round 11
ICPC
2,016
1
256
Co-prime Array
You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want not greater than 109 in any place in the array. An array is co-prime if any two adjacent numbers of it are co-prime. In the number theory, two integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.
The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.
Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime. The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array a by adding k elements to it. If there are multiple answers you can print any one of them.
null
null
[{"input": "3\n2 7 28", "output": "1\n2 7 9 28"}]
1,200
["greedy", "implementation", "math", "number theory"]
93
[{"input": "3\r\n2 7 28\r\n", "output": "1\r\n2 7 1 28\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n548\r\n"}, {"input": "1\r\n963837006\r\n", "output": "0\r\n963837006\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n1 1 1 1 1 1 1 1 1 1\r\n"}, {"input": "10\r\n26 723 970 13 422 968 875 329 234 983\r\n", "output": "2\r\n26 723 970 13 422 1 968 875 1 329 234 983\r\n"}, {"input": "10\r\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396\r\n", "output": "7\r\n319645572 1 758298525 1 812547177 1 459359946 1 355467212 1 304450522 807957797 916787906 1 239781206 1 242840396\r\n"}, {"input": "100\r\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1\r\n", "output": "19\r\n1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1\r\n"}, {"input": "100\r\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917\r\n", "output": "38\r\n591 1 417 1 888 251 792 1 847 685 3 182 461 102 1 348 1 555 956 771 901 712 1 878 1 580 631 342 1 333 1 285 899 525 1 725 537 718 929 653 84 1 788 1 104 355 624 803 1 253 853 201 995 536 1 184 65 1 205 1 540 1 652 549 1 777 248 405 677 950 431 580 1 600 1 846 1 328 429 134 983 526 103 500 963 400 23 1 276 1 704 1 570 757 410 1 658 507 620 1 984 1 244 1 486 1 454 1 802 411 985 303 635 283 96 1 597 1 855 1 775 139 839 1 839 61 219 986 1 776 1 72 1 729 1 69 20 917\r\n"}, {"input": "5\r\n472882027 472882027 472882027 472882027 472882027\r\n", "output": "4\r\n472882027 1 472882027 1 472882027 1 472882027 1 472882027\r\n"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "1\r\n1000000000 1 1000000000\r\n"}, {"input": "2\r\n8 6\r\n", "output": "1\r\n8 1 6\r\n"}, {"input": "3\r\n100000000 1000000000 1000000000\r\n", "output": "2\r\n100000000 1 1000000000 1 1000000000\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n1 2 3 4 5\r\n"}, {"input": "20\r\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000\r\n", "output": "19\r\n2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000\r\n"}, {"input": "2\r\n223092870 23\r\n", "output": "1\r\n223092870 1 23\r\n"}, {"input": "2\r\n100000003 100000003\r\n", "output": "1\r\n100000003 1 100000003\r\n"}, {"input": "2\r\n999999937 999999937\r\n", "output": "1\r\n999999937 1 999999937\r\n"}, {"input": "4\r\n999 999999937 999999937 999\r\n", "output": "1\r\n999 999999937 1 999999937 999\r\n"}, {"input": "2\r\n999999929 999999929\r\n", "output": "1\r\n999999929 1 999999929\r\n"}, {"input": "2\r\n1049459 2098918\r\n", "output": "1\r\n1049459 1 2098918\r\n"}, {"input": "2\r\n352229 704458\r\n", "output": "1\r\n352229 1 704458\r\n"}, {"input": "2\r\n7293 4011\r\n", "output": "1\r\n7293 1 4011\r\n"}, {"input": "2\r\n5565651 3999930\r\n", "output": "1\r\n5565651 1 3999930\r\n"}, {"input": "2\r\n997 997\r\n", "output": "1\r\n997 1 997\r\n"}, {"input": "3\r\n9994223 9994223 9994223\r\n", "output": "2\r\n9994223 1 9994223 1 9994223\r\n"}, {"input": "2\r\n99999998 1000000000\r\n", "output": "1\r\n99999998 1 1000000000\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "2\r\n1000000000 1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n130471 130471\r\n", "output": "1\r\n130471 1 130471\r\n"}, {"input": "3\r\n1000000000 2 2\r\n", "output": "2\r\n1000000000 1 2 1 2\r\n"}, {"input": "2\r\n223092870 66526\r\n", "output": "1\r\n223092870 1 66526\r\n"}, {"input": "14\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491 436077930 570018449\r\n", "output": "10\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491 436077930 1 570018449\r\n"}, {"input": "2\r\n3996017 3996017\r\n", "output": "1\r\n3996017 1 3996017\r\n"}, {"input": "2\r\n999983 999983\r\n", "output": "1\r\n999983 1 999983\r\n"}, {"input": "2\r\n618575685 773990454\r\n", "output": "1\r\n618575685 1 773990454\r\n"}, {"input": "3\r\n9699690 3 7\r\n", "output": "1\r\n9699690 1 3 7\r\n"}, {"input": "2\r\n999999999 999999996\r\n", "output": "1\r\n999999999 1 999999996\r\n"}, {"input": "2\r\n99999910 99999910\r\n", "output": "1\r\n99999910 1 99999910\r\n"}, {"input": "12\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491\r\n", "output": "9\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491\r\n"}, {"input": "3\r\n999999937 999999937 999999937\r\n", "output": "2\r\n999999937 1 999999937 1 999999937\r\n"}, {"input": "2\r\n99839 99839\r\n", "output": "1\r\n99839 1 99839\r\n"}, {"input": "3\r\n19999909 19999909 19999909\r\n", "output": "2\r\n19999909 1 19999909 1 19999909\r\n"}, {"input": "4\r\n1 1000000000 1 1000000000\r\n", "output": "0\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n64006 64006\r\n", "output": "1\r\n64006 1 64006\r\n"}, {"input": "2\r\n1956955 1956955\r\n", "output": "1\r\n1956955 1 1956955\r\n"}, {"input": "3\r\n1 1000000000 1000000000\r\n", "output": "1\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n982451707 982451707\r\n", "output": "1\r\n982451707 1 982451707\r\n"}, {"input": "2\r\n999999733 999999733\r\n", "output": "1\r\n999999733 1 999999733\r\n"}, {"input": "3\r\n999999733 999999733 999999733\r\n", "output": "2\r\n999999733 1 999999733 1 999999733\r\n"}, {"input": "2\r\n3257 3257\r\n", "output": "1\r\n3257 1 3257\r\n"}, {"input": "2\r\n223092870 181598\r\n", "output": "1\r\n223092870 1 181598\r\n"}, {"input": "3\r\n959919409 105935 105935\r\n", "output": "2\r\n959919409 1 105935 1 105935\r\n"}, {"input": "2\r\n510510 510510\r\n", "output": "1\r\n510510 1 510510\r\n"}, {"input": "3\r\n223092870 1000000000 1000000000\r\n", "output": "2\r\n223092870 1 1000000000 1 1000000000\r\n"}, {"input": "14\r\n1000000000 2 1000000000 3 1000000000 6 1000000000 1000000000 15 1000000000 1000000000 1000000000 100000000 1000\r\n", "output": "11\r\n1000000000 1 2 1 1000000000 3 1000000000 1 6 1 1000000000 1 1000000000 1 15 1 1000000000 1 1000000000 1 1000000000 1 100000000 1 1000\r\n"}, {"input": "7\r\n1 982451653 982451653 1 982451653 982451653 982451653\r\n", "output": "3\r\n1 982451653 1 982451653 1 982451653 1 982451653 1 982451653\r\n"}, {"input": "2\r\n100000007 100000007\r\n", "output": "1\r\n100000007 1 100000007\r\n"}, {"input": "3\r\n999999757 999999757 999999757\r\n", "output": "2\r\n999999757 1 999999757 1 999999757\r\n"}, {"input": "3\r\n99999989 99999989 99999989\r\n", "output": "2\r\n99999989 1 99999989 1 99999989\r\n"}, {"input": "5\r\n2 4 982451707 982451707 3\r\n", "output": "2\r\n2 1 4 982451707 1 982451707 3\r\n"}, {"input": "2\r\n20000014 20000014\r\n", "output": "1\r\n20000014 1 20000014\r\n"}, {"input": "2\r\n99999989 99999989\r\n", "output": "1\r\n99999989 1 99999989\r\n"}, {"input": "2\r\n111546435 111546435\r\n", "output": "1\r\n111546435 1 111546435\r\n"}, {"input": "2\r\n55288874 33538046\r\n", "output": "1\r\n55288874 1 33538046\r\n"}, {"input": "5\r\n179424673 179424673 179424673 179424673 179424673\r\n", "output": "4\r\n179424673 1 179424673 1 179424673 1 179424673 1 179424673\r\n"}, {"input": "2\r\n199999978 199999978\r\n", "output": "1\r\n199999978 1 199999978\r\n"}, {"input": "2\r\n1000000000 2\r\n", "output": "1\r\n1000000000 1 2\r\n"}, {"input": "3\r\n19999897 19999897 19999897\r\n", "output": "2\r\n19999897 1 19999897 1 19999897\r\n"}, {"input": "2\r\n19999982 19999982\r\n", "output": "1\r\n19999982 1 19999982\r\n"}, {"input": "2\r\n10000007 10000007\r\n", "output": "1\r\n10000007 1 10000007\r\n"}, {"input": "3\r\n999999937 999999937 2\r\n", "output": "1\r\n999999937 1 999999937 2\r\n"}, {"input": "5\r\n2017 2017 2017 2017 2017\r\n", "output": "4\r\n2017 1 2017 1 2017 1 2017 1 2017\r\n"}, {"input": "2\r\n19999909 39999818\r\n", "output": "1\r\n19999909 1 39999818\r\n"}, {"input": "2\r\n62615533 7919\r\n", "output": "1\r\n62615533 1 7919\r\n"}, {"input": "5\r\n39989 39989 33 31 29\r\n", "output": "1\r\n39989 1 39989 33 31 29\r\n"}, {"input": "2\r\n1000000000 100000\r\n", "output": "1\r\n1000000000 1 100000\r\n"}, {"input": "2\r\n1938 10010\r\n", "output": "1\r\n1938 1 10010\r\n"}, {"input": "2\r\n199999 199999\r\n", "output": "1\r\n199999 1 199999\r\n"}, {"input": "2\r\n107273 107273\r\n", "output": "1\r\n107273 1 107273\r\n"}, {"input": "3\r\n49999 49999 49999\r\n", "output": "2\r\n49999 1 49999 1 49999\r\n"}, {"input": "2\r\n1999966 1999958\r\n", "output": "1\r\n1999966 1 1999958\r\n"}, {"input": "2\r\n86020 300846\r\n", "output": "1\r\n86020 1 300846\r\n"}, {"input": "2\r\n999999997 213\r\n", "output": "1\r\n999999997 1 213\r\n"}, {"input": "2\r\n200000014 200000434\r\n", "output": "1\r\n200000014 1 200000434\r\n"}]
false
stdio
import sys import math 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()) a = list(map(int, f.readline().split())) # Read submission output with open(submission_path) as f: lines = f.readlines() if len(lines) < 2: print(0) return try: k_sub = int(lines[0].strip()) array_sub = list(map(int, lines[1].strip().split())) except: print(0) return # Check array_sub length if len(array_sub) != n + k_sub: print(0) return # Read reference output's k_ref with open(output_path) as f: k_ref = int(f.readline().strip()) # Check k_sub equals k_ref if k_sub != k_ref: print(0) return # Check original array is a subsequence of array_sub i = 0 for num in array_sub: if i < len(a) and num == a[i]: i += 1 if i != len(a): print(0) return # Check all adjacent pairs are coprime for j in range(len(array_sub)-1): x = array_sub[j] y = array_sub[j+1] if math.gcd(x, y) != 1: print(0) return # All checks passed print(1) if __name__ == "__main__": main()
true
660/A
660
A
PyPy 3-64
TESTS
14
77
4,812,800
152705274
from math import gcd n = int(input()) count = 0 a = list(map(int, input().split())) i = 0 k = len(a) while i < k-1: if gcd(a[i], a[i+1]) == 1: i += 1 else: l = a[i]+1 while gcd(a[i], l) != 1 or gcd(a[i+1], l) != 1: l += 1 count += 1 a.insert(i+1, l) k = len(a) print(count) for num in a: print(num, end = ' ')
93
46
0
175063273
import math n=int(input()) a=list(map(int,input().split())) Ans=0 for i in range(n-1): if math.gcd(a[i],a[i+1])!=1: Ans+=1 print(Ans) for i in range(n-1): print(a[i],end=' ') if math.gcd(a[i],a[i+1])!=1: print(1,end=' ') print(a[n-1])
Educational Codeforces Round 11
ICPC
2,016
1
256
Co-prime Array
You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want not greater than 109 in any place in the array. An array is co-prime if any two adjacent numbers of it are co-prime. In the number theory, two integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.
The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.
Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime. The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array a by adding k elements to it. If there are multiple answers you can print any one of them.
null
null
[{"input": "3\n2 7 28", "output": "1\n2 7 9 28"}]
1,200
["greedy", "implementation", "math", "number theory"]
93
[{"input": "3\r\n2 7 28\r\n", "output": "1\r\n2 7 1 28\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n548\r\n"}, {"input": "1\r\n963837006\r\n", "output": "0\r\n963837006\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n1 1 1 1 1 1 1 1 1 1\r\n"}, {"input": "10\r\n26 723 970 13 422 968 875 329 234 983\r\n", "output": "2\r\n26 723 970 13 422 1 968 875 1 329 234 983\r\n"}, {"input": "10\r\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396\r\n", "output": "7\r\n319645572 1 758298525 1 812547177 1 459359946 1 355467212 1 304450522 807957797 916787906 1 239781206 1 242840396\r\n"}, {"input": "100\r\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1\r\n", "output": "19\r\n1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1\r\n"}, {"input": "100\r\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917\r\n", "output": "38\r\n591 1 417 1 888 251 792 1 847 685 3 182 461 102 1 348 1 555 956 771 901 712 1 878 1 580 631 342 1 333 1 285 899 525 1 725 537 718 929 653 84 1 788 1 104 355 624 803 1 253 853 201 995 536 1 184 65 1 205 1 540 1 652 549 1 777 248 405 677 950 431 580 1 600 1 846 1 328 429 134 983 526 103 500 963 400 23 1 276 1 704 1 570 757 410 1 658 507 620 1 984 1 244 1 486 1 454 1 802 411 985 303 635 283 96 1 597 1 855 1 775 139 839 1 839 61 219 986 1 776 1 72 1 729 1 69 20 917\r\n"}, {"input": "5\r\n472882027 472882027 472882027 472882027 472882027\r\n", "output": "4\r\n472882027 1 472882027 1 472882027 1 472882027 1 472882027\r\n"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "1\r\n1000000000 1 1000000000\r\n"}, {"input": "2\r\n8 6\r\n", "output": "1\r\n8 1 6\r\n"}, {"input": "3\r\n100000000 1000000000 1000000000\r\n", "output": "2\r\n100000000 1 1000000000 1 1000000000\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n1 2 3 4 5\r\n"}, {"input": "20\r\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000\r\n", "output": "19\r\n2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000\r\n"}, {"input": "2\r\n223092870 23\r\n", "output": "1\r\n223092870 1 23\r\n"}, {"input": "2\r\n100000003 100000003\r\n", "output": "1\r\n100000003 1 100000003\r\n"}, {"input": "2\r\n999999937 999999937\r\n", "output": "1\r\n999999937 1 999999937\r\n"}, {"input": "4\r\n999 999999937 999999937 999\r\n", "output": "1\r\n999 999999937 1 999999937 999\r\n"}, {"input": "2\r\n999999929 999999929\r\n", "output": "1\r\n999999929 1 999999929\r\n"}, {"input": "2\r\n1049459 2098918\r\n", "output": "1\r\n1049459 1 2098918\r\n"}, {"input": "2\r\n352229 704458\r\n", "output": "1\r\n352229 1 704458\r\n"}, {"input": "2\r\n7293 4011\r\n", "output": "1\r\n7293 1 4011\r\n"}, {"input": "2\r\n5565651 3999930\r\n", "output": "1\r\n5565651 1 3999930\r\n"}, {"input": "2\r\n997 997\r\n", "output": "1\r\n997 1 997\r\n"}, {"input": "3\r\n9994223 9994223 9994223\r\n", "output": "2\r\n9994223 1 9994223 1 9994223\r\n"}, {"input": "2\r\n99999998 1000000000\r\n", "output": "1\r\n99999998 1 1000000000\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "2\r\n1000000000 1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n130471 130471\r\n", "output": "1\r\n130471 1 130471\r\n"}, {"input": "3\r\n1000000000 2 2\r\n", "output": "2\r\n1000000000 1 2 1 2\r\n"}, {"input": "2\r\n223092870 66526\r\n", "output": "1\r\n223092870 1 66526\r\n"}, {"input": "14\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491 436077930 570018449\r\n", "output": "10\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491 436077930 1 570018449\r\n"}, {"input": "2\r\n3996017 3996017\r\n", "output": "1\r\n3996017 1 3996017\r\n"}, {"input": "2\r\n999983 999983\r\n", "output": "1\r\n999983 1 999983\r\n"}, {"input": "2\r\n618575685 773990454\r\n", "output": "1\r\n618575685 1 773990454\r\n"}, {"input": "3\r\n9699690 3 7\r\n", "output": "1\r\n9699690 1 3 7\r\n"}, {"input": "2\r\n999999999 999999996\r\n", "output": "1\r\n999999999 1 999999996\r\n"}, {"input": "2\r\n99999910 99999910\r\n", "output": "1\r\n99999910 1 99999910\r\n"}, {"input": "12\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491\r\n", "output": "9\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491\r\n"}, {"input": "3\r\n999999937 999999937 999999937\r\n", "output": "2\r\n999999937 1 999999937 1 999999937\r\n"}, {"input": "2\r\n99839 99839\r\n", "output": "1\r\n99839 1 99839\r\n"}, {"input": "3\r\n19999909 19999909 19999909\r\n", "output": "2\r\n19999909 1 19999909 1 19999909\r\n"}, {"input": "4\r\n1 1000000000 1 1000000000\r\n", "output": "0\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n64006 64006\r\n", "output": "1\r\n64006 1 64006\r\n"}, {"input": "2\r\n1956955 1956955\r\n", "output": "1\r\n1956955 1 1956955\r\n"}, {"input": "3\r\n1 1000000000 1000000000\r\n", "output": "1\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n982451707 982451707\r\n", "output": "1\r\n982451707 1 982451707\r\n"}, {"input": "2\r\n999999733 999999733\r\n", "output": "1\r\n999999733 1 999999733\r\n"}, {"input": "3\r\n999999733 999999733 999999733\r\n", "output": "2\r\n999999733 1 999999733 1 999999733\r\n"}, {"input": "2\r\n3257 3257\r\n", "output": "1\r\n3257 1 3257\r\n"}, {"input": "2\r\n223092870 181598\r\n", "output": "1\r\n223092870 1 181598\r\n"}, {"input": "3\r\n959919409 105935 105935\r\n", "output": "2\r\n959919409 1 105935 1 105935\r\n"}, {"input": "2\r\n510510 510510\r\n", "output": "1\r\n510510 1 510510\r\n"}, {"input": "3\r\n223092870 1000000000 1000000000\r\n", "output": "2\r\n223092870 1 1000000000 1 1000000000\r\n"}, {"input": "14\r\n1000000000 2 1000000000 3 1000000000 6 1000000000 1000000000 15 1000000000 1000000000 1000000000 100000000 1000\r\n", "output": "11\r\n1000000000 1 2 1 1000000000 3 1000000000 1 6 1 1000000000 1 1000000000 1 15 1 1000000000 1 1000000000 1 1000000000 1 100000000 1 1000\r\n"}, {"input": "7\r\n1 982451653 982451653 1 982451653 982451653 982451653\r\n", "output": "3\r\n1 982451653 1 982451653 1 982451653 1 982451653 1 982451653\r\n"}, {"input": "2\r\n100000007 100000007\r\n", "output": "1\r\n100000007 1 100000007\r\n"}, {"input": "3\r\n999999757 999999757 999999757\r\n", "output": "2\r\n999999757 1 999999757 1 999999757\r\n"}, {"input": "3\r\n99999989 99999989 99999989\r\n", "output": "2\r\n99999989 1 99999989 1 99999989\r\n"}, {"input": "5\r\n2 4 982451707 982451707 3\r\n", "output": "2\r\n2 1 4 982451707 1 982451707 3\r\n"}, {"input": "2\r\n20000014 20000014\r\n", "output": "1\r\n20000014 1 20000014\r\n"}, {"input": "2\r\n99999989 99999989\r\n", "output": "1\r\n99999989 1 99999989\r\n"}, {"input": "2\r\n111546435 111546435\r\n", "output": "1\r\n111546435 1 111546435\r\n"}, {"input": "2\r\n55288874 33538046\r\n", "output": "1\r\n55288874 1 33538046\r\n"}, {"input": "5\r\n179424673 179424673 179424673 179424673 179424673\r\n", "output": "4\r\n179424673 1 179424673 1 179424673 1 179424673 1 179424673\r\n"}, {"input": "2\r\n199999978 199999978\r\n", "output": "1\r\n199999978 1 199999978\r\n"}, {"input": "2\r\n1000000000 2\r\n", "output": "1\r\n1000000000 1 2\r\n"}, {"input": "3\r\n19999897 19999897 19999897\r\n", "output": "2\r\n19999897 1 19999897 1 19999897\r\n"}, {"input": "2\r\n19999982 19999982\r\n", "output": "1\r\n19999982 1 19999982\r\n"}, {"input": "2\r\n10000007 10000007\r\n", "output": "1\r\n10000007 1 10000007\r\n"}, {"input": "3\r\n999999937 999999937 2\r\n", "output": "1\r\n999999937 1 999999937 2\r\n"}, {"input": "5\r\n2017 2017 2017 2017 2017\r\n", "output": "4\r\n2017 1 2017 1 2017 1 2017 1 2017\r\n"}, {"input": "2\r\n19999909 39999818\r\n", "output": "1\r\n19999909 1 39999818\r\n"}, {"input": "2\r\n62615533 7919\r\n", "output": "1\r\n62615533 1 7919\r\n"}, {"input": "5\r\n39989 39989 33 31 29\r\n", "output": "1\r\n39989 1 39989 33 31 29\r\n"}, {"input": "2\r\n1000000000 100000\r\n", "output": "1\r\n1000000000 1 100000\r\n"}, {"input": "2\r\n1938 10010\r\n", "output": "1\r\n1938 1 10010\r\n"}, {"input": "2\r\n199999 199999\r\n", "output": "1\r\n199999 1 199999\r\n"}, {"input": "2\r\n107273 107273\r\n", "output": "1\r\n107273 1 107273\r\n"}, {"input": "3\r\n49999 49999 49999\r\n", "output": "2\r\n49999 1 49999 1 49999\r\n"}, {"input": "2\r\n1999966 1999958\r\n", "output": "1\r\n1999966 1 1999958\r\n"}, {"input": "2\r\n86020 300846\r\n", "output": "1\r\n86020 1 300846\r\n"}, {"input": "2\r\n999999997 213\r\n", "output": "1\r\n999999997 1 213\r\n"}, {"input": "2\r\n200000014 200000434\r\n", "output": "1\r\n200000014 1 200000434\r\n"}]
false
stdio
import sys import math 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()) a = list(map(int, f.readline().split())) # Read submission output with open(submission_path) as f: lines = f.readlines() if len(lines) < 2: print(0) return try: k_sub = int(lines[0].strip()) array_sub = list(map(int, lines[1].strip().split())) except: print(0) return # Check array_sub length if len(array_sub) != n + k_sub: print(0) return # Read reference output's k_ref with open(output_path) as f: k_ref = int(f.readline().strip()) # Check k_sub equals k_ref if k_sub != k_ref: print(0) return # Check original array is a subsequence of array_sub i = 0 for num in array_sub: if i < len(a) and num == a[i]: i += 1 if i != len(a): print(0) return # Check all adjacent pairs are coprime for j in range(len(array_sub)-1): x = array_sub[j] y = array_sub[j+1] if math.gcd(x, y) != 1: print(0) return # All checks passed print(1) if __name__ == "__main__": main()
true
828/B
828
B
Python 3
TESTS
91
124
102,400
47422321
bl,wt='B W'.split() def gd(f,l): """get delta""" return 2*int(l>f)-1 def fe(v,zf,zl,xf,xl,iv):#iv is vertical """find edge""" dz=gd(zf,zl) dx=gd(xf,xl) for c in range(zf,zl,dz): for d in range(xf,xl,dx): t=v[c][d] if iv else v[d][c] if t==bl: return c def cir(v,t,b,l,r): """count of white cell in region""" s=0 for c in range(t,b+1): for d in range(l,r+1): if v[c][d]==wt: s+=1 return s def pes(v,h,w,t,b,l,r): """possible extention square""" lw,lh=r-l+1,b-t+1 ld,lm=abs(lw-lh),max(lw,lh) ps=lm*ld if lw<lh: pf,pl,pm=l-ld,r+ld,w elif lw>lh: pf,pl,pm=t-ld,b+ld,h else: return 0 if pf>=0 or pl<pm: return ps return -1 def ge(v,h,w): """get edges""" t=fe(v,0,h,0,w,1) b=fe(v,h-1,-1,0,w,1) l=fe(v,0,w,0,h,0) r=fe(v,w-1,-1,0,h,0) #print('top={} bottom={} left={} right={}'.format(t,b,l,r)) return t,b,l,r def wp(v,h,w): """get count of white cell for paint""" t,b,l,r=ge(v,h,w) if t==None: return 1 si=cir(v,t,b,l,r) so=pes(v,h,w,t,b,l,r) if so<0: return -1 return si+so h,w=[int(c) for c in input().split()] v=[] for c in range(h): v.append(input()) print(wp(v,h,w))
128
62
4,608,000
28825584
n,m = input().split(" ") n = int(n) m = int(m) c = 0 u_black, b_black, l_black, r_black = n,0,m,0 for i in range(0,n): row = str(input()) for j in range(0,m): if row[j] == "B": u_black = min(u_black,i) b_black = max(b_black,i) l_black = min(l_black,j) r_black = max(r_black,j) c = c + 1 length = max(b_black - u_black + 1, r_black - l_black + 1) if c == 0: print(1) elif length > m or length > n: print(-1) else : print((length*length)-c)
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Black Square
Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
null
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third example all cells are colored white, so it's sufficient to color any cell black.
[{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}]
1,300
["implementation"]
128
[{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "-1\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "2 4\r\nWWWW\r\nWBWW\r\n", "output": "0\r\n"}, {"input": "4 5\r\nWWWWW\r\nBBWWW\r\nBBWWW\r\nWWWWW\r\n", "output": "0\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "10 5\r\nWWWWB\r\nWWWWW\r\nWWWBB\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "12\r\n"}, {"input": "5 10\r\nWWWWWWWWWW\r\nWWWWBWBBWW\r\nWWWWWWWWWW\r\nWWWWBWWWWW\r\nWWWWWWBWWW\r\n", "output": "11\r\n"}, {"input": "20 10\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWBBWBWWWW\r\nWWBWWBWWWW\r\nWWWWBWWWWW\r\nWWWWBWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\n", "output": "9\r\n"}, {"input": "10 20\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWBW\r\nWWWWWWWWWWWWWWWWWBWW\r\nWWWWWWWWWWWWWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nWW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nWW\r\nWB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWB\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBW\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nBW\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nWW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBB\r\nWB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nWW\r\n", "output": "1\r\n"}, {"input": "1 2\r\nWB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nW\r\nW\r\n", "output": "1\r\n"}, {"input": "2 1\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "20 10\r\nWWBWWWBBWW\r\nWWWWWBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWBBBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWBWWWWWBWW\r\nWBWWBWWWBW\r\nWWBWBWWWWW\r\nWWWBWWBBWW\r\nWWBBWBWBWW\r\nBBWWWWWBWW\r\nWWBWWBBBWW\r\nWWWBWBBWWW\r\nWWWBBWBWWW\r\nWWWWWWWWWW\r\nWWWBWWWWWW\r\nWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "10 20\r\nWWWWWWWBWWWWWWWBWWWB\r\nWWWBWWWBWWWWWWWWWWWW\r\nBWWWWWWWWWWWWWWWWWBB\r\nWWWWWWBWWBWWBWWWBWWW\r\nWWWWWWWWBWWBWWWBWWWW\r\nWBWWWWWWWBWWWWWWWWWW\r\nWWWBWBWWBWWWWWBBWWWB\r\nWWBBWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWBWWWWBW\r\nWWWWWWWWWWWWBWWBWWWB\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "-1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "1 5\r\nWBBWW\r\n", "output": "-1\r\n"}, {"input": "20 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWBW\r\nWBB\r\nWWW\r\n", "output": "1\r\n"}, {"input": "4 6\r\nWWWWWW\r\nWWWBWW\r\nWWWWWB\r\nWWWWWW\r\n", "output": "7\r\n"}, {"input": "5 5\r\nWBWBW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "7\r\n"}, {"input": "3 3\r\nBBB\r\nBBB\r\nBBB\r\n", "output": "0\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWBWW\r\n", "output": "23\r\n"}, {"input": "5 4\r\nWWBW\r\nBWWB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "13\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWWW\r\nWBBW\r\n", "output": "12\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWBWW\r\n", "output": "34\r\n"}, {"input": "3 3\r\nBBW\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "3 3\r\nBWB\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "6 6\r\nWBWWWW\r\nBWWWBW\r\nWWWWWW\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "21\r\n"}, {"input": "3 3\r\nWWW\r\nWBW\r\nWWW\r\n", "output": "0\r\n"}, {"input": "3 3\r\nBBB\r\nWWW\r\nWWW\r\n", "output": "6\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWBWW\r\nWBBBW\r\nWWBWW\r\nWWBWW\r\n", "output": "18\r\n"}, {"input": "5 2\r\nWB\r\nWB\r\nWB\r\nWW\r\nWW\r\n", "output": "-1\r\n"}, {"input": "4 7\r\nBBBBBWW\r\nWWWWWWW\r\nWWWWWWW\r\nWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWBB\r\nWWWW\r\n", "output": "6\r\n"}, {"input": "4 4\r\nWWWW\r\nWBWW\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "2 5\r\nWWWWW\r\nBBBWW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWBW\r\nWWWWWW\r\nWWWWWW\r\nWWBWWW\r\n", "output": "33\r\n"}, {"input": "3 3\r\nWBW\r\nWBW\r\nWBW\r\n", "output": "6\r\n"}, {"input": "3 5\r\nWWBBB\r\nBWBBB\r\nWWBBB\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWB\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "22\r\n"}, {"input": "5 5\r\nBWWWB\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nBWWWW\r\n", "output": "22\r\n"}, {"input": "4 5\r\nWWWWW\r\nBWWWW\r\nBBBWW\r\nWWWWW\r\n", "output": "5\r\n"}, {"input": "4 4\r\nBBBB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "12\r\n"}, {"input": "4 6\r\nWWWWWW\r\nBWWWWW\r\nBWWWWW\r\nBBBBBB\r\n", "output": "-1\r\n"}, {"input": "3 6\r\nWWWWWW\r\nBBBWWW\r\nWWWWWW\r\n", "output": "6\r\n"}, {"input": "5 2\r\nWW\r\nBW\r\nBW\r\nBB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nBBBBB\r\nWWWWW\r\nWWWWW\r\n", "output": "20\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nWWWWB\r\nWBWWW\r\nWWWWW\r\n", "output": "14\r\n"}, {"input": "1 5\r\nWWBWW\r\n", "output": "0\r\n"}, {"input": "1 3\r\nBBB\r\n", "output": "-1\r\n"}, {"input": "2 4\r\nWWBW\r\nBWBW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nBBBBBB\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "30\r\n"}, {"input": "4 4\r\nWWWW\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWB\r\n", "output": "0\r\n"}, {"input": "5 1\r\nB\r\nB\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "2 3\r\nWBW\r\nWBW\r\n", "output": "2\r\n"}, {"input": "5 2\r\nWW\r\nWB\r\nWB\r\nWB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "23\r\n"}]
false
stdio
null
true
828/B
828
B
Python 3
TESTS
91
77
5,632,000
28435728
n,m = map(int,input().split()) minr = m maxr = -1 minc = n maxc = -1 black = 0 for i in range(n): line = input() for j in range(m): if line[j] == 'B': black += 1 if i < minc: minc = i if i > maxc: maxc = i if j < minr: minr = j if j > maxr: maxr = j if black == 0: print(1) else: dr = maxr-minr+1 dc = maxc-minc+1 if dr > dc: if minc + dr <= n: print(dr*dr-black) elif maxc-dr >= -1: print(dr*dr-black) else: print(-1) else: if minr + dc <= m: print(dc*dc-black) elif maxr - dc >= -1: print(dc*dc-black) else: print(-1)
128
62
4,915,200
28862034
import sys import math inp = input() sqr = [] for line in sys.stdin: s = list(line.rstrip()) sqr.append(s) r = -1 l = math.inf d = -1 u = math.inf for i, line in enumerate(sqr): for j, b in enumerate(line): if b == 'B': if i < u: u = i if i+1 > d: d = i + 1 if j < l: l = j if j+1 > r: r = j + 1 ans = -1 if r != -1: ver = d - u hor = r - l if ver < hor: while ver < hor: if u > 0: u -= 1 ver += 1 elif d < len(sqr): d += 1 ver += 1 else: break else: ans = 0 elif ver > hor: while ver > hor: if l > 0: l -= 1 hor += 1 elif r < len(sqr[0]): r += 1 hor += 1 else: break else: ans = 0 else: ans = 0 else: ans = 1 if ans == 0: for i in range(u,d): for j in range(l,r): if sqr[i][j] == 'W': ans += 1 print(ans)
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Black Square
Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
null
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third example all cells are colored white, so it's sufficient to color any cell black.
[{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}]
1,300
["implementation"]
128
[{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "-1\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "2 4\r\nWWWW\r\nWBWW\r\n", "output": "0\r\n"}, {"input": "4 5\r\nWWWWW\r\nBBWWW\r\nBBWWW\r\nWWWWW\r\n", "output": "0\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "10 5\r\nWWWWB\r\nWWWWW\r\nWWWBB\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "12\r\n"}, {"input": "5 10\r\nWWWWWWWWWW\r\nWWWWBWBBWW\r\nWWWWWWWWWW\r\nWWWWBWWWWW\r\nWWWWWWBWWW\r\n", "output": "11\r\n"}, {"input": "20 10\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWBBWBWWWW\r\nWWBWWBWWWW\r\nWWWWBWWWWW\r\nWWWWBWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\n", "output": "9\r\n"}, {"input": "10 20\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWBW\r\nWWWWWWWWWWWWWWWWWBWW\r\nWWWWWWWWWWWWWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nWW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nWW\r\nWB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWB\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBW\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nBW\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nWW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBB\r\nWB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nWW\r\n", "output": "1\r\n"}, {"input": "1 2\r\nWB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nW\r\nW\r\n", "output": "1\r\n"}, {"input": "2 1\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "20 10\r\nWWBWWWBBWW\r\nWWWWWBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWBBBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWBWWWWWBWW\r\nWBWWBWWWBW\r\nWWBWBWWWWW\r\nWWWBWWBBWW\r\nWWBBWBWBWW\r\nBBWWWWWBWW\r\nWWBWWBBBWW\r\nWWWBWBBWWW\r\nWWWBBWBWWW\r\nWWWWWWWWWW\r\nWWWBWWWWWW\r\nWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "10 20\r\nWWWWWWWBWWWWWWWBWWWB\r\nWWWBWWWBWWWWWWWWWWWW\r\nBWWWWWWWWWWWWWWWWWBB\r\nWWWWWWBWWBWWBWWWBWWW\r\nWWWWWWWWBWWBWWWBWWWW\r\nWBWWWWWWWBWWWWWWWWWW\r\nWWWBWBWWBWWWWWBBWWWB\r\nWWBBWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWBWWWWBW\r\nWWWWWWWWWWWWBWWBWWWB\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "-1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "1 5\r\nWBBWW\r\n", "output": "-1\r\n"}, {"input": "20 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWBW\r\nWBB\r\nWWW\r\n", "output": "1\r\n"}, {"input": "4 6\r\nWWWWWW\r\nWWWBWW\r\nWWWWWB\r\nWWWWWW\r\n", "output": "7\r\n"}, {"input": "5 5\r\nWBWBW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "7\r\n"}, {"input": "3 3\r\nBBB\r\nBBB\r\nBBB\r\n", "output": "0\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWBWW\r\n", "output": "23\r\n"}, {"input": "5 4\r\nWWBW\r\nBWWB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "13\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWWW\r\nWBBW\r\n", "output": "12\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWBWW\r\n", "output": "34\r\n"}, {"input": "3 3\r\nBBW\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "3 3\r\nBWB\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "6 6\r\nWBWWWW\r\nBWWWBW\r\nWWWWWW\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "21\r\n"}, {"input": "3 3\r\nWWW\r\nWBW\r\nWWW\r\n", "output": "0\r\n"}, {"input": "3 3\r\nBBB\r\nWWW\r\nWWW\r\n", "output": "6\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWBWW\r\nWBBBW\r\nWWBWW\r\nWWBWW\r\n", "output": "18\r\n"}, {"input": "5 2\r\nWB\r\nWB\r\nWB\r\nWW\r\nWW\r\n", "output": "-1\r\n"}, {"input": "4 7\r\nBBBBBWW\r\nWWWWWWW\r\nWWWWWWW\r\nWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWBB\r\nWWWW\r\n", "output": "6\r\n"}, {"input": "4 4\r\nWWWW\r\nWBWW\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "2 5\r\nWWWWW\r\nBBBWW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWBW\r\nWWWWWW\r\nWWWWWW\r\nWWBWWW\r\n", "output": "33\r\n"}, {"input": "3 3\r\nWBW\r\nWBW\r\nWBW\r\n", "output": "6\r\n"}, {"input": "3 5\r\nWWBBB\r\nBWBBB\r\nWWBBB\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWB\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "22\r\n"}, {"input": "5 5\r\nBWWWB\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nBWWWW\r\n", "output": "22\r\n"}, {"input": "4 5\r\nWWWWW\r\nBWWWW\r\nBBBWW\r\nWWWWW\r\n", "output": "5\r\n"}, {"input": "4 4\r\nBBBB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "12\r\n"}, {"input": "4 6\r\nWWWWWW\r\nBWWWWW\r\nBWWWWW\r\nBBBBBB\r\n", "output": "-1\r\n"}, {"input": "3 6\r\nWWWWWW\r\nBBBWWW\r\nWWWWWW\r\n", "output": "6\r\n"}, {"input": "5 2\r\nWW\r\nBW\r\nBW\r\nBB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nBBBBB\r\nWWWWW\r\nWWWWW\r\n", "output": "20\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nWWWWB\r\nWBWWW\r\nWWWWW\r\n", "output": "14\r\n"}, {"input": "1 5\r\nWWBWW\r\n", "output": "0\r\n"}, {"input": "1 3\r\nBBB\r\n", "output": "-1\r\n"}, {"input": "2 4\r\nWWBW\r\nBWBW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nBBBBBB\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "30\r\n"}, {"input": "4 4\r\nWWWW\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWB\r\n", "output": "0\r\n"}, {"input": "5 1\r\nB\r\nB\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "2 3\r\nWBW\r\nWBW\r\n", "output": "2\r\n"}, {"input": "5 2\r\nWW\r\nWB\r\nWB\r\nWB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "23\r\n"}]
false
stdio
null
true
828/B
828
B
Python 3
TESTS
91
77
5,632,000
28444181
n, m = map(int, input().split()) l = [] for i in range(n): l.append(list(input())) minX, minY, maxX, maxY = n, m, -1, -1 zero = True for i in range(n): for j in range(m): if l[i][j] == 'B': zero = False if i > maxX: maxX = i if i < minX: minX = i if j > maxY: maxY = j if j < minY: minY = j h, b = maxX - minX + 1, maxY - minY + 1 poss = False if zero: print(1) else: if b>h: diff = b - h if maxX+diff < n: maxX += diff poss = True elif minX-diff >= 0: minX -= diff poss = True elif h>b: diff = h - b if maxY+diff < m: maxY += diff poss = True elif minY-diff >= 0: minY -= diff poss = True else: poss = True count = 0 if not poss: print(-1) else: for i in range(minX, maxX + 1): for j in range(minY, maxY + 1): if l[i][j]!='B': l[i][j] = 'B' count += 1 print(count)
128
62
5,529,600
28464798
n,m=map(int,input().split()) x1,y1,x2,y2,c=m,n,0,0,0 for i in range(n): s=input() for j in range(m): if s[j]=='B': if x1>j:x1=j if x2<j:x2=j if y1>i:y1=i if y2<i:y2=i c+=1 if c==0: print(1) else: w=x2-x1+1 h=y2-y1+1 h=max(w,h) if h>n or h>m: print(-1) else: print(h*h-c)
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Black Square
Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
null
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third example all cells are colored white, so it's sufficient to color any cell black.
[{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}]
1,300
["implementation"]
128
[{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "-1\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "2 4\r\nWWWW\r\nWBWW\r\n", "output": "0\r\n"}, {"input": "4 5\r\nWWWWW\r\nBBWWW\r\nBBWWW\r\nWWWWW\r\n", "output": "0\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "10 5\r\nWWWWB\r\nWWWWW\r\nWWWBB\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "12\r\n"}, {"input": "5 10\r\nWWWWWWWWWW\r\nWWWWBWBBWW\r\nWWWWWWWWWW\r\nWWWWBWWWWW\r\nWWWWWWBWWW\r\n", "output": "11\r\n"}, {"input": "20 10\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWBBWBWWWW\r\nWWBWWBWWWW\r\nWWWWBWWWWW\r\nWWWWBWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\n", "output": "9\r\n"}, {"input": "10 20\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWBW\r\nWWWWWWWWWWWWWWWWWBWW\r\nWWWWWWWWWWWWWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nWW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nWW\r\nWB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWB\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBW\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nBW\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nWW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBB\r\nWB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nWW\r\n", "output": "1\r\n"}, {"input": "1 2\r\nWB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nW\r\nW\r\n", "output": "1\r\n"}, {"input": "2 1\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "20 10\r\nWWBWWWBBWW\r\nWWWWWBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWBBBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWBWWWWWBWW\r\nWBWWBWWWBW\r\nWWBWBWWWWW\r\nWWWBWWBBWW\r\nWWBBWBWBWW\r\nBBWWWWWBWW\r\nWWBWWBBBWW\r\nWWWBWBBWWW\r\nWWWBBWBWWW\r\nWWWWWWWWWW\r\nWWWBWWWWWW\r\nWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "10 20\r\nWWWWWWWBWWWWWWWBWWWB\r\nWWWBWWWBWWWWWWWWWWWW\r\nBWWWWWWWWWWWWWWWWWBB\r\nWWWWWWBWWBWWBWWWBWWW\r\nWWWWWWWWBWWBWWWBWWWW\r\nWBWWWWWWWBWWWWWWWWWW\r\nWWWBWBWWBWWWWWBBWWWB\r\nWWBBWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWBWWWWBW\r\nWWWWWWWWWWWWBWWBWWWB\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "-1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "1 5\r\nWBBWW\r\n", "output": "-1\r\n"}, {"input": "20 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWBW\r\nWBB\r\nWWW\r\n", "output": "1\r\n"}, {"input": "4 6\r\nWWWWWW\r\nWWWBWW\r\nWWWWWB\r\nWWWWWW\r\n", "output": "7\r\n"}, {"input": "5 5\r\nWBWBW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "7\r\n"}, {"input": "3 3\r\nBBB\r\nBBB\r\nBBB\r\n", "output": "0\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWBWW\r\n", "output": "23\r\n"}, {"input": "5 4\r\nWWBW\r\nBWWB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "13\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWWW\r\nWBBW\r\n", "output": "12\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWBWW\r\n", "output": "34\r\n"}, {"input": "3 3\r\nBBW\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "3 3\r\nBWB\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "6 6\r\nWBWWWW\r\nBWWWBW\r\nWWWWWW\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "21\r\n"}, {"input": "3 3\r\nWWW\r\nWBW\r\nWWW\r\n", "output": "0\r\n"}, {"input": "3 3\r\nBBB\r\nWWW\r\nWWW\r\n", "output": "6\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWBWW\r\nWBBBW\r\nWWBWW\r\nWWBWW\r\n", "output": "18\r\n"}, {"input": "5 2\r\nWB\r\nWB\r\nWB\r\nWW\r\nWW\r\n", "output": "-1\r\n"}, {"input": "4 7\r\nBBBBBWW\r\nWWWWWWW\r\nWWWWWWW\r\nWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWBB\r\nWWWW\r\n", "output": "6\r\n"}, {"input": "4 4\r\nWWWW\r\nWBWW\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "2 5\r\nWWWWW\r\nBBBWW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWBW\r\nWWWWWW\r\nWWWWWW\r\nWWBWWW\r\n", "output": "33\r\n"}, {"input": "3 3\r\nWBW\r\nWBW\r\nWBW\r\n", "output": "6\r\n"}, {"input": "3 5\r\nWWBBB\r\nBWBBB\r\nWWBBB\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWB\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "22\r\n"}, {"input": "5 5\r\nBWWWB\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nBWWWW\r\n", "output": "22\r\n"}, {"input": "4 5\r\nWWWWW\r\nBWWWW\r\nBBBWW\r\nWWWWW\r\n", "output": "5\r\n"}, {"input": "4 4\r\nBBBB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "12\r\n"}, {"input": "4 6\r\nWWWWWW\r\nBWWWWW\r\nBWWWWW\r\nBBBBBB\r\n", "output": "-1\r\n"}, {"input": "3 6\r\nWWWWWW\r\nBBBWWW\r\nWWWWWW\r\n", "output": "6\r\n"}, {"input": "5 2\r\nWW\r\nBW\r\nBW\r\nBB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nBBBBB\r\nWWWWW\r\nWWWWW\r\n", "output": "20\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nWWWWB\r\nWBWWW\r\nWWWWW\r\n", "output": "14\r\n"}, {"input": "1 5\r\nWWBWW\r\n", "output": "0\r\n"}, {"input": "1 3\r\nBBB\r\n", "output": "-1\r\n"}, {"input": "2 4\r\nWWBW\r\nBWBW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nBBBBBB\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "30\r\n"}, {"input": "4 4\r\nWWWW\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWB\r\n", "output": "0\r\n"}, {"input": "5 1\r\nB\r\nB\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "2 3\r\nWBW\r\nWBW\r\n", "output": "2\r\n"}, {"input": "5 2\r\nWW\r\nWB\r\nWB\r\nWB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "23\r\n"}]
false
stdio
null
true
828/B
828
B
Python 3
TESTS
91
62
0
29514098
n, m = map(int, input().split()) g = [input() for i in range(n)] b, r1, r2, c1, c2 = 0, n, -1, m, -1 for i in range(n): for j in range(m): if g[i][j] == 'B': b += 1 r1 = min(r1, i) r2 = max(r2, i) c1 = min(c1, j) c2 = max(c2, j) s = max(r2 - r1 + 1, c2 - c1 + 1) if b == 0: print(1) elif r1 > n - s and r2 < s - 1 or c1 > m - s and c2 < s - 1: print(-1) else: print(s ** 2 - b)
128
62
5,529,600
28474588
rows,cols = [int(i) for i in input().strip().split()] b_present = False l,r,u,d = cols,cols,rows,-1 b_cnt = 0 for i in range(rows): col = input().strip() if 'B' in col: b_present = True l = min(l,col.index('B')) u = min(u,i) r = min(r,col[::-1].index('B')) d = max(d,i) b_cnt += col.count('B') if not b_present: print(1) else: r = cols - r - 1 #print(l,r,u,d) if r - l + 1 > rows or d - u + 1 > cols: print(-1) else: print(max((r - l + 1),(d - u + 1)) * max((r - l + 1),(d - u + 1)) - b_cnt)
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Black Square
Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
null
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third example all cells are colored white, so it's sufficient to color any cell black.
[{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}]
1,300
["implementation"]
128
[{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "-1\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "2 4\r\nWWWW\r\nWBWW\r\n", "output": "0\r\n"}, {"input": "4 5\r\nWWWWW\r\nBBWWW\r\nBBWWW\r\nWWWWW\r\n", "output": "0\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "10 5\r\nWWWWB\r\nWWWWW\r\nWWWBB\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "12\r\n"}, {"input": "5 10\r\nWWWWWWWWWW\r\nWWWWBWBBWW\r\nWWWWWWWWWW\r\nWWWWBWWWWW\r\nWWWWWWBWWW\r\n", "output": "11\r\n"}, {"input": "20 10\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWBBWBWWWW\r\nWWBWWBWWWW\r\nWWWWBWWWWW\r\nWWWWBWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\n", "output": "9\r\n"}, {"input": "10 20\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWBW\r\nWWWWWWWWWWWWWWWWWBWW\r\nWWWWWWWWWWWWWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nWW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nWW\r\nWB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWB\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBW\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nBW\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nWW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBB\r\nWB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nWW\r\n", "output": "1\r\n"}, {"input": "1 2\r\nWB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nW\r\nW\r\n", "output": "1\r\n"}, {"input": "2 1\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "20 10\r\nWWBWWWBBWW\r\nWWWWWBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWBBBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWBWWWWWBWW\r\nWBWWBWWWBW\r\nWWBWBWWWWW\r\nWWWBWWBBWW\r\nWWBBWBWBWW\r\nBBWWWWWBWW\r\nWWBWWBBBWW\r\nWWWBWBBWWW\r\nWWWBBWBWWW\r\nWWWWWWWWWW\r\nWWWBWWWWWW\r\nWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "10 20\r\nWWWWWWWBWWWWWWWBWWWB\r\nWWWBWWWBWWWWWWWWWWWW\r\nBWWWWWWWWWWWWWWWWWBB\r\nWWWWWWBWWBWWBWWWBWWW\r\nWWWWWWWWBWWBWWWBWWWW\r\nWBWWWWWWWBWWWWWWWWWW\r\nWWWBWBWWBWWWWWBBWWWB\r\nWWBBWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWBWWWWBW\r\nWWWWWWWWWWWWBWWBWWWB\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "-1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "1 5\r\nWBBWW\r\n", "output": "-1\r\n"}, {"input": "20 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWBW\r\nWBB\r\nWWW\r\n", "output": "1\r\n"}, {"input": "4 6\r\nWWWWWW\r\nWWWBWW\r\nWWWWWB\r\nWWWWWW\r\n", "output": "7\r\n"}, {"input": "5 5\r\nWBWBW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "7\r\n"}, {"input": "3 3\r\nBBB\r\nBBB\r\nBBB\r\n", "output": "0\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWBWW\r\n", "output": "23\r\n"}, {"input": "5 4\r\nWWBW\r\nBWWB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "13\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWWW\r\nWBBW\r\n", "output": "12\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWBWW\r\n", "output": "34\r\n"}, {"input": "3 3\r\nBBW\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "3 3\r\nBWB\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "6 6\r\nWBWWWW\r\nBWWWBW\r\nWWWWWW\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "21\r\n"}, {"input": "3 3\r\nWWW\r\nWBW\r\nWWW\r\n", "output": "0\r\n"}, {"input": "3 3\r\nBBB\r\nWWW\r\nWWW\r\n", "output": "6\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWBWW\r\nWBBBW\r\nWWBWW\r\nWWBWW\r\n", "output": "18\r\n"}, {"input": "5 2\r\nWB\r\nWB\r\nWB\r\nWW\r\nWW\r\n", "output": "-1\r\n"}, {"input": "4 7\r\nBBBBBWW\r\nWWWWWWW\r\nWWWWWWW\r\nWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWBB\r\nWWWW\r\n", "output": "6\r\n"}, {"input": "4 4\r\nWWWW\r\nWBWW\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "2 5\r\nWWWWW\r\nBBBWW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWBW\r\nWWWWWW\r\nWWWWWW\r\nWWBWWW\r\n", "output": "33\r\n"}, {"input": "3 3\r\nWBW\r\nWBW\r\nWBW\r\n", "output": "6\r\n"}, {"input": "3 5\r\nWWBBB\r\nBWBBB\r\nWWBBB\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWB\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "22\r\n"}, {"input": "5 5\r\nBWWWB\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nBWWWW\r\n", "output": "22\r\n"}, {"input": "4 5\r\nWWWWW\r\nBWWWW\r\nBBBWW\r\nWWWWW\r\n", "output": "5\r\n"}, {"input": "4 4\r\nBBBB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "12\r\n"}, {"input": "4 6\r\nWWWWWW\r\nBWWWWW\r\nBWWWWW\r\nBBBBBB\r\n", "output": "-1\r\n"}, {"input": "3 6\r\nWWWWWW\r\nBBBWWW\r\nWWWWWW\r\n", "output": "6\r\n"}, {"input": "5 2\r\nWW\r\nBW\r\nBW\r\nBB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nBBBBB\r\nWWWWW\r\nWWWWW\r\n", "output": "20\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nWWWWB\r\nWBWWW\r\nWWWWW\r\n", "output": "14\r\n"}, {"input": "1 5\r\nWWBWW\r\n", "output": "0\r\n"}, {"input": "1 3\r\nBBB\r\n", "output": "-1\r\n"}, {"input": "2 4\r\nWWBW\r\nBWBW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nBBBBBB\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "30\r\n"}, {"input": "4 4\r\nWWWW\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWB\r\n", "output": "0\r\n"}, {"input": "5 1\r\nB\r\nB\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "2 3\r\nWBW\r\nWBW\r\n", "output": "2\r\n"}, {"input": "5 2\r\nWW\r\nWB\r\nWB\r\nWB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "23\r\n"}]
false
stdio
null
true
828/B
828
B
Python 3
TESTS
61
62
4,915,200
28628279
def getRowsContainingB(matrix): beginningRow = -1 endingRow = -2 for i in range(len(matrix)): for c in matrix[i]: if c == "B": if beginningRow == -1: beginningRow = endingRow = i else: endingRow = i return (endingRow - beginningRow) + 1 def getColumnsContainingB(matrix): beginningColumn = -1 endingColumn = -2 for i in range(len(matrix[0])): for vector in matrix: if vector[i] == "B": if beginningColumn == - 1: beginningColumn = endingColumn = i else: endingColumn = i return (endingColumn - beginningColumn) + 1 def getNumberOfB(matrix): counter = 0 for v in matrix: for c in v: if c == "B": counter += 1 return counter if __name__ == "__main__": (n, m) = map(int, input().split()) matrix = [] for _ in range(n): matrix.append(list(input())) rows = getRowsContainingB(matrix) columns = getColumnsContainingB(matrix) sqrRoot = rows if rows > columns else columns if sqrRoot == 0: print(1) elif (sqrRoot ** 2) <= (n * m): print(sqrRoot ** 2 - getNumberOfB(matrix)) else: print(-1)
128
62
5,529,600
28492131
sheet = [] nm = input().split(' ') n= int(nm[0]) m = int(nm[1]) countB = 0 minr = minc = 101 maxr = maxc = -1 for i in range(n): sheet.append(input()) for j in range(len(sheet[i])): if sheet[i][j]=='B': countB+=1 if i<minr: minr = i if i>maxr: maxr = i if j<minc: minc = j if j>maxc: maxc = j # print(countB) # print(str(minr)+" "+str(maxr)+" "+str(minc)+" "+str(maxc)) if minr==101 and maxr==-1: print(1) else: L = 0 if (maxr-minr+1)>(maxc-minc+1): L = maxr-minr+1 else: L = maxc-minc+1 if L>n or L>m: print(-1) else: size = L*L print(size-countB)
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Black Square
Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
null
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third example all cells are colored white, so it's sufficient to color any cell black.
[{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}]
1,300
["implementation"]
128
[{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "-1\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "2 4\r\nWWWW\r\nWBWW\r\n", "output": "0\r\n"}, {"input": "4 5\r\nWWWWW\r\nBBWWW\r\nBBWWW\r\nWWWWW\r\n", "output": "0\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "10 5\r\nWWWWB\r\nWWWWW\r\nWWWBB\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "12\r\n"}, {"input": "5 10\r\nWWWWWWWWWW\r\nWWWWBWBBWW\r\nWWWWWWWWWW\r\nWWWWBWWWWW\r\nWWWWWWBWWW\r\n", "output": "11\r\n"}, {"input": "20 10\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWBBWBWWWW\r\nWWBWWBWWWW\r\nWWWWBWWWWW\r\nWWWWBWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\n", "output": "9\r\n"}, {"input": "10 20\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWWWWWWBW\r\nWWWWWWWWWWWWWWWWWBWW\r\nWWWWWWWWWWWWWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "1 1\r\nW\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nWW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nWW\r\nWB\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWW\r\nBB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nWB\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nWB\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBW\r\nWW\r\n", "output": "0\r\n"}, {"input": "2 2\r\nBW\r\nWB\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBW\r\nBB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nWW\r\n", "output": "2\r\n"}, {"input": "2 2\r\nBB\r\nWB\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBW\r\n", "output": "1\r\n"}, {"input": "2 2\r\nBB\r\nBB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nWW\r\n", "output": "1\r\n"}, {"input": "1 2\r\nWB\r\n", "output": "0\r\n"}, {"input": "1 2\r\nBW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nW\r\nW\r\n", "output": "1\r\n"}, {"input": "2 1\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nW\r\n", "output": "0\r\n"}, {"input": "2 1\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "20 10\r\nWWBWWWBBWW\r\nWWWWWBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWBBBWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWWWWWWWWWW\r\nWBWWWWWBWW\r\nWBWWBWWWBW\r\nWWBWBWWWWW\r\nWWWBWWBBWW\r\nWWBBWBWBWW\r\nBBWWWWWBWW\r\nWWBWWBBBWW\r\nWWWBWBBWWW\r\nWWWBBWBWWW\r\nWWWWWWWWWW\r\nWWWBWWWWWW\r\nWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "10 20\r\nWWWWWWWBWWWWWWWBWWWB\r\nWWWBWWWBWWWWWWWWWWWW\r\nBWWWWWWWWWWWWWWWWWBB\r\nWWWWWWBWWBWWBWWWBWWW\r\nWWWWWWWWBWWBWWWBWWWW\r\nWBWWWWWWWBWWWWWWWWWW\r\nWWWBWBWWBWWWWWBBWWWB\r\nWWBBWWWWWWWWWWWWWWWW\r\nWWWWWWWWWWWWWBWWWWBW\r\nWWWWWWWWWWWWBWWBWWWB\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "0\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "0\r\n"}, {"input": "1 100\r\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "1 100\r\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\r\n", "output": "-1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "0\r\n"}, {"input": "100 1\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "1 5\r\nWBBWW\r\n", "output": "-1\r\n"}, {"input": "20 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nB\r\nB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWBW\r\nWBB\r\nWWW\r\n", "output": "1\r\n"}, {"input": "4 6\r\nWWWWWW\r\nWWWBWW\r\nWWWWWB\r\nWWWWWW\r\n", "output": "7\r\n"}, {"input": "5 5\r\nWBWBW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n", "output": "7\r\n"}, {"input": "3 3\r\nBBB\r\nBBB\r\nBBB\r\n", "output": "0\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWBWW\r\n", "output": "23\r\n"}, {"input": "5 4\r\nWWBW\r\nBWWB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "13\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWWW\r\nWBBW\r\n", "output": "12\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWBWW\r\n", "output": "34\r\n"}, {"input": "3 3\r\nBBW\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "3 3\r\nBWB\r\nWWW\r\nBWW\r\n", "output": "6\r\n"}, {"input": "6 6\r\nWBWWWW\r\nBWWWBW\r\nWWWWWW\r\nWWBWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "21\r\n"}, {"input": "3 3\r\nWWW\r\nWBW\r\nWWW\r\n", "output": "0\r\n"}, {"input": "3 3\r\nBBB\r\nWWW\r\nWWW\r\n", "output": "6\r\n"}, {"input": "5 5\r\nWWBWW\r\nWWBWW\r\nWBBBW\r\nWWBWW\r\nWWBWW\r\n", "output": "18\r\n"}, {"input": "5 2\r\nWB\r\nWB\r\nWB\r\nWW\r\nWW\r\n", "output": "-1\r\n"}, {"input": "4 7\r\nBBBBBWW\r\nWWWWWWW\r\nWWWWWWW\r\nWWWWWWW\r\n", "output": "-1\r\n"}, {"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWW\r\nWWBB\r\nWWWW\r\n", "output": "6\r\n"}, {"input": "4 4\r\nWWWW\r\nWBWW\r\nWWWW\r\nWWWW\r\n", "output": "0\r\n"}, {"input": "2 5\r\nWWWWW\r\nBBBWW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nWWBWWW\r\nWWWWWW\r\nWWWWBW\r\nWWWWWW\r\nWWWWWW\r\nWWBWWW\r\n", "output": "33\r\n"}, {"input": "3 3\r\nWBW\r\nWBW\r\nWBW\r\n", "output": "6\r\n"}, {"input": "3 5\r\nWWBBB\r\nBWBBB\r\nWWBBB\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWB\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "22\r\n"}, {"input": "5 5\r\nBWWWB\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nBWWWW\r\n", "output": "22\r\n"}, {"input": "4 5\r\nWWWWW\r\nBWWWW\r\nBBBWW\r\nWWWWW\r\n", "output": "5\r\n"}, {"input": "4 4\r\nBBBB\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "12\r\n"}, {"input": "4 6\r\nWWWWWW\r\nBWWWWW\r\nBWWWWW\r\nBBBBBB\r\n", "output": "-1\r\n"}, {"input": "3 6\r\nWWWWWW\r\nBBBWWW\r\nWWWWWW\r\n", "output": "6\r\n"}, {"input": "5 2\r\nWW\r\nBW\r\nBW\r\nBB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nBBBBB\r\nWWWWW\r\nWWWWW\r\n", "output": "20\r\n"}, {"input": "5 5\r\nWWWWW\r\nWWWWW\r\nWWWWB\r\nWBWWW\r\nWWWWW\r\n", "output": "14\r\n"}, {"input": "1 5\r\nWWBWW\r\n", "output": "0\r\n"}, {"input": "1 3\r\nBBB\r\n", "output": "-1\r\n"}, {"input": "2 4\r\nWWBW\r\nBWBW\r\n", "output": "-1\r\n"}, {"input": "6 6\r\nBBBBBB\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\nWWWWWW\r\n", "output": "30\r\n"}, {"input": "4 4\r\nWWWW\r\nWWWW\r\nWWWW\r\nWWWW\r\n", "output": "1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWB\r\n", "output": "0\r\n"}, {"input": "5 1\r\nB\r\nB\r\nW\r\nW\r\nW\r\n", "output": "-1\r\n"}, {"input": "2 3\r\nWBW\r\nWBW\r\n", "output": "2\r\n"}, {"input": "5 2\r\nWW\r\nWB\r\nWB\r\nWB\r\nWW\r\n", "output": "-1\r\n"}, {"input": "5 5\r\nWWWWW\r\nBWWWW\r\nWWWWB\r\nWWWWW\r\nWWWWW\r\n", "output": "23\r\n"}]
false
stdio
null
true
895/A
895
A
PyPy 3
TESTS
51
124
23,142,400
32676792
n = int(input()) a = [int(z) for z in input().split()] ans = 360 for i in range(n): tmp = 0 j = i while j < n and tmp < 180: tmp += a[j] j += 1 ans = min(ans, abs(360 - tmp - tmp)) print(ans)
93
62
5,529,600
33005485
def findAngel(ang, n): summ = 0 i = -1 while (summ < 180): i += 1 summ += ang[i] #print(i, summ) return summ n = int(input()) a = [int(i) for i in input().split()] i = 0 summ = 0 minSumm = 360 while ((abs(360-2*summ) != 0) and (i < n)): summ = findAngel([a[i]] + a[i + 1:len(a)] + a[0:i], n) i += 1 if (summ < minSumm): minSumm = summ print(abs(360-2*minSumm))
Codeforces Round 448 (Div. 2)
CF
2,017
1
256
Pizza Separation
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut. The second line contains n integers ai (1 ≤ ai ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
null
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0. Picture explaning fourth sample: Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
1,200
["brute force", "implementation"]
93
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", "output": "0\r\n"}, {"input": "3\r\n120 120 120\r\n", "output": "120\r\n"}, {"input": "5\r\n110 90 70 50 40\r\n", "output": "40\r\n"}, {"input": "2\r\n170 190\r\n", "output": "20\r\n"}, {"input": "15\r\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10\r\n", "output": "10\r\n"}, {"input": "5\r\n30 60 180 60 30\r\n", "output": "0\r\n"}, {"input": "2\r\n359 1\r\n", "output": "358\r\n"}, {"input": "5\r\n100 100 30 100 30\r\n", "output": "40\r\n"}, {"input": "5\r\n36 34 35 11 244\r\n", "output": "128\r\n"}, {"input": "5\r\n96 94 95 71 4\r\n", "output": "18\r\n"}, {"input": "2\r\n85 275\r\n", "output": "190\r\n"}, {"input": "3\r\n281 67 12\r\n", "output": "202\r\n"}, {"input": "5\r\n211 113 25 9 2\r\n", "output": "62\r\n"}, {"input": "13\r\n286 58 6 1 1 1 1 1 1 1 1 1 1\r\n", "output": "212\r\n"}, {"input": "15\r\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "20\r\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "92\r\n"}, {"input": "50\r\n148 53 32 11 4 56 8 2 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "3\r\n1 1 358\r\n", "output": "356\r\n"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341\r\n", "output": "322\r\n"}, {"input": "33\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 328\r\n", "output": "296\r\n"}, {"input": "70\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 291\r\n", "output": "222\r\n"}, {"input": "130\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231\r\n", "output": "102\r\n"}, {"input": "200\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 161\r\n", "output": "0\r\n"}, {"input": "222\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 139\r\n", "output": "0\r\n"}, {"input": "10\r\n8 3 11 4 1 10 10 1 8 304\r\n", "output": "248\r\n"}, {"input": "12\r\n8 7 7 3 11 2 10 1 10 8 10 283\r\n", "output": "206\r\n"}, {"input": "13\r\n10 8 9 10 5 9 4 1 10 11 1 7 275\r\n", "output": "190\r\n"}, {"input": "14\r\n1 6 3 11 9 5 9 8 5 6 7 3 7 280\r\n", "output": "200\r\n"}, {"input": "15\r\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275\r\n", "output": "190\r\n"}, {"input": "30\r\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189\r\n", "output": "18\r\n"}, {"input": "70\r\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "29\r\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189\r\n", "output": "18\r\n"}, {"input": "35\r\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168\r\n", "output": "0\r\n"}, {"input": "60\r\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5\r\n", "output": "0\r\n"}, {"input": "71\r\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "63\r\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "81\r\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 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": "47\r\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68\r\n", "output": "0\r\n"}, {"input": "100\r\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "120\r\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 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 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": "200\r\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "220\r\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "6\r\n27 15 28 34 41 215\r\n", "output": "70\r\n"}, {"input": "7\r\n41 38 41 31 22 41 146\r\n", "output": "14\r\n"}, {"input": "8\r\n24 27 34 23 29 23 30 170\r\n", "output": "20\r\n"}, {"input": "9\r\n11 11 20 20 33 32 35 26 172\r\n", "output": "6\r\n"}, {"input": "10\r\n36 13 28 13 33 34 23 25 34 121\r\n", "output": "0\r\n"}, {"input": "11\r\n19 37 13 41 37 15 32 12 19 35 100\r\n", "output": "10\r\n"}, {"input": "12\r\n37 25 34 38 21 24 34 38 11 29 28 41\r\n", "output": "2\r\n"}, {"input": "13\r\n24 40 20 26 25 29 39 29 35 28 19 18 28\r\n", "output": "2\r\n"}, {"input": "14\r\n11 21 40 19 28 34 13 16 23 30 34 22 25 44\r\n", "output": "4\r\n"}, {"input": "3\r\n95 91 174\r\n", "output": "12\r\n"}, {"input": "4\r\n82 75 78 125\r\n", "output": "46\r\n"}, {"input": "6\r\n87 75 88 94 15 1\r\n", "output": "4\r\n"}, {"input": "10\r\n27 52 58 64 45 64 1 19 2 28\r\n", "output": "12\r\n"}, {"input": "50\r\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1\r\n", "output": "0\r\n"}, {"input": "100\r\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3\r\n", "output": "0\r\n"}, {"input": "150\r\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1\r\n", "output": "0\r\n"}, {"input": "200\r\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2\r\n", "output": "0\r\n"}, {"input": "5\r\n35 80 45 100 100\r\n", "output": "40\r\n"}, {"input": "4\r\n90 179 90 1\r\n", "output": "2\r\n"}, {"input": "5\r\n50 50 20 160 80\r\n", "output": "0\r\n"}, {"input": "5\r\n30 175 30 5 120\r\n", "output": "10\r\n"}, {"input": "4\r\n170 30 10 150\r\n", "output": "20\r\n"}, {"input": "6\r\n90 30 90 30 90 30\r\n", "output": "60\r\n"}, {"input": "4\r\n70 80 110 100\r\n", "output": "20\r\n"}, {"input": "7\r\n35 45 70 100 10 10 90\r\n", "output": "0\r\n"}, {"input": "6\r\n50 90 10 90 20 100\r\n", "output": "20\r\n"}, {"input": "6\r\n10 155 162 1 26 6\r\n", "output": "18\r\n"}, {"input": "7\r\n80 90 80 45 10 10 45\r\n", "output": "20\r\n"}, {"input": "4\r\n18 36 162 144\r\n", "output": "36\r\n"}, {"input": "5\r\n20 50 50 160 80\r\n", "output": "40\r\n"}, {"input": "5\r\n10 30 140 20 160\r\n", "output": "0\r\n"}, {"input": "6\r\n90 80 60 50 40 40\r\n", "output": "20\r\n"}, {"input": "9\r\n40 20 20 20 20 20 20 40 160\r\n", "output": "40\r\n"}, {"input": "4\r\n90 54 90 126\r\n", "output": "72\r\n"}, {"input": "4\r\n150 170 30 10\r\n", "output": "20\r\n"}, {"input": "8\r\n130 12 13 85 41 67 5 7\r\n", "output": "26\r\n"}, {"input": "7\r\n70 170 20 10 30 30 30\r\n", "output": "20\r\n"}, {"input": "8\r\n100 100 50 50 15 15 15 15\r\n", "output": "40\r\n"}, {"input": "4\r\n100 70 80 110\r\n", "output": "20\r\n"}, {"input": "5\r\n160 130 40 20 10\r\n", "output": "20\r\n"}, {"input": "4\r\n20 149 151 40\r\n", "output": "22\r\n"}, {"input": "4\r\n100 10 100 150\r\n", "output": "60\r\n"}, {"input": "6\r\n19 64 105 168 1 3\r\n", "output": "16\r\n"}, {"input": "8\r\n10 10 70 70 90 90 10 10\r\n", "output": "0\r\n"}]
false
stdio
null
true
808/D
808
D
Python 3
TESTS
34
187
20,275,200
218747359
# LUOGU_RID: 120798760 n = int(input()) a = list(map(int, input().split())) mp = {} mpp = {} sum_val = 0 sum1 = 0 for i in range(n): sum_val += a[i] if a[i] in mpp: mpp[a[i]] += 1 else: mpp[a[i]] = 1 if sum_val % 2 == 1: print("NO") else: exp = sum_val // 2 for i in range(n): sum1 += a[i] if a[i] in mp: mp[a[i]] += 1 else: mp[a[i]] = 1 mpp[a[i]] -= 1 if sum1 == exp: print("YES") break if sum1 < exp: if (exp - sum1) in mpp: print("YES") break if sum1 > exp: if (sum1 - exp) in mp: print("YES") break else: print("NO")
115
140
20,787,200
219378803
n = int(input()) l = list(map(int,input().split())) dic = dict() sum = 0 for i,j in enumerate(l): sum += j dic[sum] = i if sum % 2 == 1: print("NO") exit() for i,j in enumerate(l): v = sum // 2 - j if v in dic and dic[v] < i: print("YES") exit() v = sum / 2 + j if v in dic and dic[v] >= i: print("YES") exit() print("NO")# 1692310808.353773
Educational Codeforces Round 21
ICPC
2,017
2
256
Array Division
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position). Inserting an element in the same position he was erased from is also considered moving. Can Vasya divide the array after choosing the right element to move and its new position?
The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array. The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array.
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
null
In the first example Vasya can move the second element to the end of the array. In the second example no move can make the division possible. In the third example Vasya can move the fourth element by one position to the left.
[{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}]
1,900
["binary search", "data structures", "implementation"]
115
[{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "output": "NO\r\n"}, {"input": "8\r\n9 5 5 10 4 9 5 8\r\n", "output": "NO\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "YES\r\n"}, {"input": "15\r\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8\r\n", "output": "NO\r\n"}, {"input": "20\r\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13\r\n", "output": "NO\r\n"}, {"input": "20\r\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 10 6\r\n", "output": "NO\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": "YES\r\n"}, {"input": "100\r\n89 38 63 73 77 4 99 74 30 5 69 57 97 37 88 71 36 59 19 63 46 20 33 58 61 98 100 31 33 53 99 96 34 17 44 95 54 52 22 77 67 88 20 88 26 43 12 23 96 94 14 7 57 86 56 54 32 8 3 43 97 56 74 22 5 100 12 60 93 12 44 68 31 63 7 71 21 29 19 38 50 47 97 43 50 59 88 40 51 61 20 68 32 66 70 48 19 55 91 53\r\n", "output": "NO\r\n"}, {"input": "100\r\n80 100 88 52 25 87 85 8 92 62 35 66 74 39 58 41 55 53 23 73 90 72 36 44 97 67 16 54 3 8 25 34 84 47 77 39 93 19 49 20 29 44 21 48 21 56 82 59 8 31 94 95 84 54 72 20 95 91 85 1 67 19 76 28 31 63 87 98 55 28 16 20 36 91 93 39 94 69 80 97 100 96 68 26 91 45 22 84 20 36 20 92 53 75 58 51 60 26 76 25\r\n", "output": "NO\r\n"}, {"input": "100\r\n27 95 57 29 91 85 83 36 72 86 39 5 79 61 78 93 100 97 73 23 82 66 41 92 38 92 100 96 48 56 66 47 5 32 69 13 95 23 46 62 99 83 57 66 98 82 81 57 37 37 81 64 45 76 72 43 99 76 86 22 37 39 93 80 99 36 53 83 3 32 52 9 78 34 47 100 33 72 19 40 29 56 77 32 79 72 15 88 100 98 56 50 22 81 88 92 58 70 21 19\r\n", "output": "NO\r\n"}, {"input": "100\r\n35 31 83 11 7 94 57 58 30 26 2 99 33 58 98 6 3 52 13 66 21 53 26 94 100 5 1 3 91 13 97 49 86 25 63 90 88 98 57 57 34 81 32 16 65 94 59 83 44 14 46 18 28 89 75 95 87 57 52 18 46 80 31 43 38 54 69 75 82 9 64 96 75 40 96 52 67 85 86 38 95 55 16 57 17 20 22 7 63 3 12 16 42 87 46 12 51 95 67 80\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 4 3 100 100 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n6 100 100 3 4 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n4 2 3 7 1 1\r\n", "output": "YES\r\n"}, {"input": "4\r\n6 1 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n228 114 114\r\n", "output": "YES\r\n"}, {"input": "3\r\n229 232 444\r\n", "output": "NO\r\n"}, {"input": "3\r\n322 324 555\r\n", "output": "NO\r\n"}, {"input": "3\r\n69 34 5\r\n", "output": "NO\r\n"}, {"input": "6\r\n5 4 1 2 2 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n545 237 546\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 3 1 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 2 10 2 2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n5 4 6 5 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 6 1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 1 8 5 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n73 67 16 51 56 71 37 49 90 6\r\n", "output": "NO\r\n"}, {"input": "1\r\n10\r\n", "output": "NO\r\n"}, {"input": "1\r\n1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n8 2 7 5 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n2\r\n", "output": "NO\r\n"}, {"input": "16\r\n9 10 2 1 6 7 6 5 8 3 2 10 8 4 9 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4\r\n", "output": "YES\r\n"}, {"input": "19\r\n9 9 3 2 4 5 5 7 8 10 8 10 1 2 2 6 5 3 3\r\n", "output": "NO\r\n"}, {"input": "11\r\n7 2 1 8 8 2 4 10 8 7 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n10 20 30 40 99 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n3 7 9 2 10 1 9 6 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n9 3\r\n", "output": "NO\r\n"}, {"input": "7\r\n1 2 3 12 1 2 3\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 4 4 5 8 5\r\n", "output": "YES\r\n"}, {"input": "18\r\n2 10 3 6 6 6 10 8 8 1 10 9 9 3 1 9 7 4\r\n", "output": "YES\r\n"}, {"input": "20\r\n9 6 6 10 4 4 8 7 4 10 10 2 10 5 9 5 3 10 1 9\r\n", "output": "NO\r\n"}, {"input": "12\r\n3 8 10 2 4 4 6 9 5 10 10 3\r\n", "output": "YES\r\n"}, {"input": "11\r\n9 2 7 7 7 3 7 5 4 10 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 4 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n7 1\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 5 6 7 6\r\n", "output": "YES\r\n"}, {"input": "11\r\n4 3 10 3 7 8 4 9 2 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n705032704 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 5 6 8 3 1 7 3\r\n", "output": "YES\r\n"}, {"input": "20\r\n8 6 3 6 3 5 10 2 6 1 7 6 9 10 8 3 5 9 3 8\r\n", "output": "YES\r\n"}, {"input": "11\r\n2 4 8 3 4 7 9 10 5 3 3\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 4 2 24 6 4 2\r\n", "output": "YES\r\n"}, {"input": "17\r\n7 1 1 1 8 9 1 10 8 8 7 9 7 9 1 6 5\r\n", "output": "NO\r\n"}, {"input": "7\r\n7 10 1 2 6 2 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 10 40 10 10\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 3 13\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 10 2 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n7 4 5 62 20 20 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n1 5 2 20 10 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n5 6\r\n", "output": "NO\r\n"}, {"input": "14\r\n5 2 9 7 5 8 3 2 2 4 9 1 3 10\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 2 2 5 5\r\n", "output": "NO\r\n"}, {"input": "11\r\n1 1 1 1 1 10 1 1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "9\r\n8 4 13 19 11 1 8 2 8\r\n", "output": "YES\r\n"}, {"input": "6\r\n14 16 14 14 15 11\r\n", "output": "YES\r\n"}, {"input": "9\r\n14 19 1 13 11 3 1 1 7\r\n", "output": "YES\r\n"}, {"input": "6\r\n16 13 3 7 4 15\r\n", "output": "YES\r\n"}, {"input": "4\r\n11 7 12 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 1 3 6 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 4 8 11 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 10 3 4\r\n", "output": "YES\r\n"}, {"input": "6\r\n8 15 12 14 15 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 4 4 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 3 1 6 4\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 12 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 4 13\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1 1 1 1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n19 6 5 13 6 13\r\n", "output": "YES\r\n"}, {"input": "8\r\n2 2 2 5 1 2 3 3\r\n", "output": "YES\r\n"}]
false
stdio
null
true
808/D
808
D
Python 3
TESTS
34
202
20,275,200
218747578
# LUOGU_RID: 120799086 n = int(input()) a = list(map(int, input().split())) mpl = {} mpr = {} sum_val = 0 ans = 0 for i in range(n): sum_val += a[i] if a[i] in mpr: mpr[a[i]] += 1 else: mpr[a[i]] = 1 if sum_val % 2 == 1: print("NO") else: flag = 0 sum_val //= 2 for i in range(n): ans += a[i] if ans == sum_val: flag = 1 break if a[i] in mpl: mpl[a[i]] += 1 else: mpl[a[i]] = 1 mpr[a[i]] -= 1 if ans > sum_val and (ans - sum_val) in mpl: flag = 1 break if ans < sum_val and (sum_val - ans) in mpr: flag = 1 break if flag: print("YES") else: print("NO")
115
140
21,196,800
172169944
n = int(input()) a = map(int, input().split(' ')) a = list(a) mp = {} dis = -sum(a) a = list(map(lambda x: x * 2, a)) for x in a: if -x not in mp: mp[-x] = 0 mp[-x] += 1 tag = False if dis in mp: tag = True for x in a: dis += x if x not in mp: mp[x] = 0 mp[x] += 1 mp[-x] -= 1 if mp[-x] == 0: mp.pop(-x) if dis in mp: tag = True if tag: print("YES") else: print("NO")
Educational Codeforces Round 21
ICPC
2,017
2
256
Array Division
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position). Inserting an element in the same position he was erased from is also considered moving. Can Vasya divide the array after choosing the right element to move and its new position?
The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array. The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array.
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
null
In the first example Vasya can move the second element to the end of the array. In the second example no move can make the division possible. In the third example Vasya can move the fourth element by one position to the left.
[{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}]
1,900
["binary search", "data structures", "implementation"]
115
[{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "output": "NO\r\n"}, {"input": "8\r\n9 5 5 10 4 9 5 8\r\n", "output": "NO\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "YES\r\n"}, {"input": "15\r\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8\r\n", "output": "NO\r\n"}, {"input": "20\r\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13\r\n", "output": "NO\r\n"}, {"input": "20\r\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 10 6\r\n", "output": "NO\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": "YES\r\n"}, {"input": "100\r\n89 38 63 73 77 4 99 74 30 5 69 57 97 37 88 71 36 59 19 63 46 20 33 58 61 98 100 31 33 53 99 96 34 17 44 95 54 52 22 77 67 88 20 88 26 43 12 23 96 94 14 7 57 86 56 54 32 8 3 43 97 56 74 22 5 100 12 60 93 12 44 68 31 63 7 71 21 29 19 38 50 47 97 43 50 59 88 40 51 61 20 68 32 66 70 48 19 55 91 53\r\n", "output": "NO\r\n"}, {"input": "100\r\n80 100 88 52 25 87 85 8 92 62 35 66 74 39 58 41 55 53 23 73 90 72 36 44 97 67 16 54 3 8 25 34 84 47 77 39 93 19 49 20 29 44 21 48 21 56 82 59 8 31 94 95 84 54 72 20 95 91 85 1 67 19 76 28 31 63 87 98 55 28 16 20 36 91 93 39 94 69 80 97 100 96 68 26 91 45 22 84 20 36 20 92 53 75 58 51 60 26 76 25\r\n", "output": "NO\r\n"}, {"input": "100\r\n27 95 57 29 91 85 83 36 72 86 39 5 79 61 78 93 100 97 73 23 82 66 41 92 38 92 100 96 48 56 66 47 5 32 69 13 95 23 46 62 99 83 57 66 98 82 81 57 37 37 81 64 45 76 72 43 99 76 86 22 37 39 93 80 99 36 53 83 3 32 52 9 78 34 47 100 33 72 19 40 29 56 77 32 79 72 15 88 100 98 56 50 22 81 88 92 58 70 21 19\r\n", "output": "NO\r\n"}, {"input": "100\r\n35 31 83 11 7 94 57 58 30 26 2 99 33 58 98 6 3 52 13 66 21 53 26 94 100 5 1 3 91 13 97 49 86 25 63 90 88 98 57 57 34 81 32 16 65 94 59 83 44 14 46 18 28 89 75 95 87 57 52 18 46 80 31 43 38 54 69 75 82 9 64 96 75 40 96 52 67 85 86 38 95 55 16 57 17 20 22 7 63 3 12 16 42 87 46 12 51 95 67 80\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 4 3 100 100 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n6 100 100 3 4 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n4 2 3 7 1 1\r\n", "output": "YES\r\n"}, {"input": "4\r\n6 1 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n228 114 114\r\n", "output": "YES\r\n"}, {"input": "3\r\n229 232 444\r\n", "output": "NO\r\n"}, {"input": "3\r\n322 324 555\r\n", "output": "NO\r\n"}, {"input": "3\r\n69 34 5\r\n", "output": "NO\r\n"}, {"input": "6\r\n5 4 1 2 2 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n545 237 546\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 3 1 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 2 10 2 2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n5 4 6 5 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 6 1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 1 8 5 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n73 67 16 51 56 71 37 49 90 6\r\n", "output": "NO\r\n"}, {"input": "1\r\n10\r\n", "output": "NO\r\n"}, {"input": "1\r\n1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n8 2 7 5 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n2\r\n", "output": "NO\r\n"}, {"input": "16\r\n9 10 2 1 6 7 6 5 8 3 2 10 8 4 9 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4\r\n", "output": "YES\r\n"}, {"input": "19\r\n9 9 3 2 4 5 5 7 8 10 8 10 1 2 2 6 5 3 3\r\n", "output": "NO\r\n"}, {"input": "11\r\n7 2 1 8 8 2 4 10 8 7 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n10 20 30 40 99 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n3 7 9 2 10 1 9 6 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n9 3\r\n", "output": "NO\r\n"}, {"input": "7\r\n1 2 3 12 1 2 3\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 4 4 5 8 5\r\n", "output": "YES\r\n"}, {"input": "18\r\n2 10 3 6 6 6 10 8 8 1 10 9 9 3 1 9 7 4\r\n", "output": "YES\r\n"}, {"input": "20\r\n9 6 6 10 4 4 8 7 4 10 10 2 10 5 9 5 3 10 1 9\r\n", "output": "NO\r\n"}, {"input": "12\r\n3 8 10 2 4 4 6 9 5 10 10 3\r\n", "output": "YES\r\n"}, {"input": "11\r\n9 2 7 7 7 3 7 5 4 10 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 4 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n7 1\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 5 6 7 6\r\n", "output": "YES\r\n"}, {"input": "11\r\n4 3 10 3 7 8 4 9 2 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n705032704 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 5 6 8 3 1 7 3\r\n", "output": "YES\r\n"}, {"input": "20\r\n8 6 3 6 3 5 10 2 6 1 7 6 9 10 8 3 5 9 3 8\r\n", "output": "YES\r\n"}, {"input": "11\r\n2 4 8 3 4 7 9 10 5 3 3\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 4 2 24 6 4 2\r\n", "output": "YES\r\n"}, {"input": "17\r\n7 1 1 1 8 9 1 10 8 8 7 9 7 9 1 6 5\r\n", "output": "NO\r\n"}, {"input": "7\r\n7 10 1 2 6 2 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 10 40 10 10\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 3 13\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 10 2 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n7 4 5 62 20 20 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n1 5 2 20 10 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n5 6\r\n", "output": "NO\r\n"}, {"input": "14\r\n5 2 9 7 5 8 3 2 2 4 9 1 3 10\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 2 2 5 5\r\n", "output": "NO\r\n"}, {"input": "11\r\n1 1 1 1 1 10 1 1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "9\r\n8 4 13 19 11 1 8 2 8\r\n", "output": "YES\r\n"}, {"input": "6\r\n14 16 14 14 15 11\r\n", "output": "YES\r\n"}, {"input": "9\r\n14 19 1 13 11 3 1 1 7\r\n", "output": "YES\r\n"}, {"input": "6\r\n16 13 3 7 4 15\r\n", "output": "YES\r\n"}, {"input": "4\r\n11 7 12 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 1 3 6 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 4 8 11 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 10 3 4\r\n", "output": "YES\r\n"}, {"input": "6\r\n8 15 12 14 15 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 4 4 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 3 1 6 4\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 12 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 4 13\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1 1 1 1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n19 6 5 13 6 13\r\n", "output": "YES\r\n"}, {"input": "8\r\n2 2 2 5 1 2 3 3\r\n", "output": "YES\r\n"}]
false
stdio
null
true
808/D
808
D
Python 3
TESTS
34
249
21,504,000
125002880
import math import sys def main(arr): left={} right={} for e in arr: if e not in right: right[e]=0 right[e]+=1 prefix=[arr[0]] for i in range(1,len(arr)): prefix.append(arr[i]+prefix[-1]) s=prefix[-1] for i in range(len(arr)): if arr[i] not in left: left[arr[i]]=0 left[arr[i]]+=1 right[arr[i]]-=1 a=prefix[i] b=s-prefix[i] if prefix[i] == s-prefix[i]: return 'YES' else: if a>b: if (a-b)/2 in left: return 'YES' else: if (b-a)/2 in right: return "YES" return "NO" n=int(input()) arr=list(map(int,input().split())) print(main(arr))
115
155
19,353,600
214509456
import sys def ainput(): return sys.stdin.readline() n=int(ainput()) ls=[0]+list(map(int,ainput().split())) s=sum(ls)/2 if sum(ls)%2!=0: print('No') exit() res=0 z={} z[0]=1 for i in range(1,n+1): res+=ls[i] z[ls[i]]=1 if (res-s) in z: print('Yes') break else: z.clear() z[0]=1 res=0 for i in range(n,0,-1): res+=ls[i] z[ls[i]] = 1 if (res-s) in z: print('Yes') break else: print('No')
Educational Codeforces Round 21
ICPC
2,017
2
256
Array Division
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position). Inserting an element in the same position he was erased from is also considered moving. Can Vasya divide the array after choosing the right element to move and its new position?
The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array. The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array.
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
null
In the first example Vasya can move the second element to the end of the array. In the second example no move can make the division possible. In the third example Vasya can move the fourth element by one position to the left.
[{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}]
1,900
["binary search", "data structures", "implementation"]
115
[{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "output": "NO\r\n"}, {"input": "8\r\n9 5 5 10 4 9 5 8\r\n", "output": "NO\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "YES\r\n"}, {"input": "15\r\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8\r\n", "output": "NO\r\n"}, {"input": "20\r\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13\r\n", "output": "NO\r\n"}, {"input": "20\r\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 10 6\r\n", "output": "NO\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": "YES\r\n"}, {"input": "100\r\n89 38 63 73 77 4 99 74 30 5 69 57 97 37 88 71 36 59 19 63 46 20 33 58 61 98 100 31 33 53 99 96 34 17 44 95 54 52 22 77 67 88 20 88 26 43 12 23 96 94 14 7 57 86 56 54 32 8 3 43 97 56 74 22 5 100 12 60 93 12 44 68 31 63 7 71 21 29 19 38 50 47 97 43 50 59 88 40 51 61 20 68 32 66 70 48 19 55 91 53\r\n", "output": "NO\r\n"}, {"input": "100\r\n80 100 88 52 25 87 85 8 92 62 35 66 74 39 58 41 55 53 23 73 90 72 36 44 97 67 16 54 3 8 25 34 84 47 77 39 93 19 49 20 29 44 21 48 21 56 82 59 8 31 94 95 84 54 72 20 95 91 85 1 67 19 76 28 31 63 87 98 55 28 16 20 36 91 93 39 94 69 80 97 100 96 68 26 91 45 22 84 20 36 20 92 53 75 58 51 60 26 76 25\r\n", "output": "NO\r\n"}, {"input": "100\r\n27 95 57 29 91 85 83 36 72 86 39 5 79 61 78 93 100 97 73 23 82 66 41 92 38 92 100 96 48 56 66 47 5 32 69 13 95 23 46 62 99 83 57 66 98 82 81 57 37 37 81 64 45 76 72 43 99 76 86 22 37 39 93 80 99 36 53 83 3 32 52 9 78 34 47 100 33 72 19 40 29 56 77 32 79 72 15 88 100 98 56 50 22 81 88 92 58 70 21 19\r\n", "output": "NO\r\n"}, {"input": "100\r\n35 31 83 11 7 94 57 58 30 26 2 99 33 58 98 6 3 52 13 66 21 53 26 94 100 5 1 3 91 13 97 49 86 25 63 90 88 98 57 57 34 81 32 16 65 94 59 83 44 14 46 18 28 89 75 95 87 57 52 18 46 80 31 43 38 54 69 75 82 9 64 96 75 40 96 52 67 85 86 38 95 55 16 57 17 20 22 7 63 3 12 16 42 87 46 12 51 95 67 80\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 4 3 100 100 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n6 100 100 3 4 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n4 2 3 7 1 1\r\n", "output": "YES\r\n"}, {"input": "4\r\n6 1 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n228 114 114\r\n", "output": "YES\r\n"}, {"input": "3\r\n229 232 444\r\n", "output": "NO\r\n"}, {"input": "3\r\n322 324 555\r\n", "output": "NO\r\n"}, {"input": "3\r\n69 34 5\r\n", "output": "NO\r\n"}, {"input": "6\r\n5 4 1 2 2 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n545 237 546\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 3 1 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 2 10 2 2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n5 4 6 5 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 6 1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 1 8 5 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n73 67 16 51 56 71 37 49 90 6\r\n", "output": "NO\r\n"}, {"input": "1\r\n10\r\n", "output": "NO\r\n"}, {"input": "1\r\n1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n8 2 7 5 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n2\r\n", "output": "NO\r\n"}, {"input": "16\r\n9 10 2 1 6 7 6 5 8 3 2 10 8 4 9 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4\r\n", "output": "YES\r\n"}, {"input": "19\r\n9 9 3 2 4 5 5 7 8 10 8 10 1 2 2 6 5 3 3\r\n", "output": "NO\r\n"}, {"input": "11\r\n7 2 1 8 8 2 4 10 8 7 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n10 20 30 40 99 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n3 7 9 2 10 1 9 6 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n9 3\r\n", "output": "NO\r\n"}, {"input": "7\r\n1 2 3 12 1 2 3\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 4 4 5 8 5\r\n", "output": "YES\r\n"}, {"input": "18\r\n2 10 3 6 6 6 10 8 8 1 10 9 9 3 1 9 7 4\r\n", "output": "YES\r\n"}, {"input": "20\r\n9 6 6 10 4 4 8 7 4 10 10 2 10 5 9 5 3 10 1 9\r\n", "output": "NO\r\n"}, {"input": "12\r\n3 8 10 2 4 4 6 9 5 10 10 3\r\n", "output": "YES\r\n"}, {"input": "11\r\n9 2 7 7 7 3 7 5 4 10 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 4 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n7 1\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 5 6 7 6\r\n", "output": "YES\r\n"}, {"input": "11\r\n4 3 10 3 7 8 4 9 2 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n705032704 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 5 6 8 3 1 7 3\r\n", "output": "YES\r\n"}, {"input": "20\r\n8 6 3 6 3 5 10 2 6 1 7 6 9 10 8 3 5 9 3 8\r\n", "output": "YES\r\n"}, {"input": "11\r\n2 4 8 3 4 7 9 10 5 3 3\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 4 2 24 6 4 2\r\n", "output": "YES\r\n"}, {"input": "17\r\n7 1 1 1 8 9 1 10 8 8 7 9 7 9 1 6 5\r\n", "output": "NO\r\n"}, {"input": "7\r\n7 10 1 2 6 2 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 10 40 10 10\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 3 13\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 10 2 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n7 4 5 62 20 20 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n1 5 2 20 10 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n5 6\r\n", "output": "NO\r\n"}, {"input": "14\r\n5 2 9 7 5 8 3 2 2 4 9 1 3 10\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 2 2 5 5\r\n", "output": "NO\r\n"}, {"input": "11\r\n1 1 1 1 1 10 1 1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "9\r\n8 4 13 19 11 1 8 2 8\r\n", "output": "YES\r\n"}, {"input": "6\r\n14 16 14 14 15 11\r\n", "output": "YES\r\n"}, {"input": "9\r\n14 19 1 13 11 3 1 1 7\r\n", "output": "YES\r\n"}, {"input": "6\r\n16 13 3 7 4 15\r\n", "output": "YES\r\n"}, {"input": "4\r\n11 7 12 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 1 3 6 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 4 8 11 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 10 3 4\r\n", "output": "YES\r\n"}, {"input": "6\r\n8 15 12 14 15 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 4 4 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 3 1 6 4\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 12 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 4 13\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1 1 1 1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n19 6 5 13 6 13\r\n", "output": "YES\r\n"}, {"input": "8\r\n2 2 2 5 1 2 3 3\r\n", "output": "YES\r\n"}]
false
stdio
null
true
808/D
808
D
Python 3
TESTS
34
233
11,980,800
32036203
import math def f(): n=int(input()) s1=0 s2=0 m1={} m2={} A=list(map(int,input().split())) if n==1: print("NO") return for i in A: s2+=i if i in m2: m2[i]+=1 else: m2[i]=1 for i in A: if (s1-s2)%2==0: d=(s1-s2)//2 if d<0 and -d in m2: print("YES") return elif d in m1: print("YES") return s1+=i s2-=i if i in m1: m1[i]+=1 else: m1[i]=1 m2[i]-=1 print("NO") return f()
115
171
7,987,200
160513950
n = int(input()) arr = list(map(int, input().split())) total = sum(arr) if (total&1) == 1 : print("NO") exit(0) def solve(arr) : st = set() s = 0 for i in arr : st.add(i) s += i if (s >= total//2) : if (s-total//2) in st : print("YES") exit(0) solve(arr) solve(arr[::-1]) print("NO")
Educational Codeforces Round 21
ICPC
2,017
2
256
Array Division
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position). Inserting an element in the same position he was erased from is also considered moving. Can Vasya divide the array after choosing the right element to move and its new position?
The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array. The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array.
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
null
In the first example Vasya can move the second element to the end of the array. In the second example no move can make the division possible. In the third example Vasya can move the fourth element by one position to the left.
[{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}]
1,900
["binary search", "data structures", "implementation"]
115
[{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "output": "NO\r\n"}, {"input": "8\r\n9 5 5 10 4 9 5 8\r\n", "output": "NO\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "YES\r\n"}, {"input": "15\r\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8\r\n", "output": "NO\r\n"}, {"input": "20\r\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13\r\n", "output": "NO\r\n"}, {"input": "20\r\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 10 6\r\n", "output": "NO\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": "YES\r\n"}, {"input": "100\r\n89 38 63 73 77 4 99 74 30 5 69 57 97 37 88 71 36 59 19 63 46 20 33 58 61 98 100 31 33 53 99 96 34 17 44 95 54 52 22 77 67 88 20 88 26 43 12 23 96 94 14 7 57 86 56 54 32 8 3 43 97 56 74 22 5 100 12 60 93 12 44 68 31 63 7 71 21 29 19 38 50 47 97 43 50 59 88 40 51 61 20 68 32 66 70 48 19 55 91 53\r\n", "output": "NO\r\n"}, {"input": "100\r\n80 100 88 52 25 87 85 8 92 62 35 66 74 39 58 41 55 53 23 73 90 72 36 44 97 67 16 54 3 8 25 34 84 47 77 39 93 19 49 20 29 44 21 48 21 56 82 59 8 31 94 95 84 54 72 20 95 91 85 1 67 19 76 28 31 63 87 98 55 28 16 20 36 91 93 39 94 69 80 97 100 96 68 26 91 45 22 84 20 36 20 92 53 75 58 51 60 26 76 25\r\n", "output": "NO\r\n"}, {"input": "100\r\n27 95 57 29 91 85 83 36 72 86 39 5 79 61 78 93 100 97 73 23 82 66 41 92 38 92 100 96 48 56 66 47 5 32 69 13 95 23 46 62 99 83 57 66 98 82 81 57 37 37 81 64 45 76 72 43 99 76 86 22 37 39 93 80 99 36 53 83 3 32 52 9 78 34 47 100 33 72 19 40 29 56 77 32 79 72 15 88 100 98 56 50 22 81 88 92 58 70 21 19\r\n", "output": "NO\r\n"}, {"input": "100\r\n35 31 83 11 7 94 57 58 30 26 2 99 33 58 98 6 3 52 13 66 21 53 26 94 100 5 1 3 91 13 97 49 86 25 63 90 88 98 57 57 34 81 32 16 65 94 59 83 44 14 46 18 28 89 75 95 87 57 52 18 46 80 31 43 38 54 69 75 82 9 64 96 75 40 96 52 67 85 86 38 95 55 16 57 17 20 22 7 63 3 12 16 42 87 46 12 51 95 67 80\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 4 3 100 100 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n6 100 100 3 4 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n4 2 3 7 1 1\r\n", "output": "YES\r\n"}, {"input": "4\r\n6 1 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n228 114 114\r\n", "output": "YES\r\n"}, {"input": "3\r\n229 232 444\r\n", "output": "NO\r\n"}, {"input": "3\r\n322 324 555\r\n", "output": "NO\r\n"}, {"input": "3\r\n69 34 5\r\n", "output": "NO\r\n"}, {"input": "6\r\n5 4 1 2 2 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n545 237 546\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 3 1 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 2 10 2 2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n5 4 6 5 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 6 1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 1 8 5 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n73 67 16 51 56 71 37 49 90 6\r\n", "output": "NO\r\n"}, {"input": "1\r\n10\r\n", "output": "NO\r\n"}, {"input": "1\r\n1\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n8 2 7 5 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n2\r\n", "output": "NO\r\n"}, {"input": "16\r\n9 10 2 1 6 7 6 5 8 3 2 10 8 4 9 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4\r\n", "output": "YES\r\n"}, {"input": "19\r\n9 9 3 2 4 5 5 7 8 10 8 10 1 2 2 6 5 3 3\r\n", "output": "NO\r\n"}, {"input": "11\r\n7 2 1 8 8 2 4 10 8 7 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n10 20 30 40 99 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n3 7 9 2 10 1 9 6 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n9 3\r\n", "output": "NO\r\n"}, {"input": "7\r\n1 2 3 12 1 2 3\r\n", "output": "YES\r\n"}, {"input": "6\r\n2 4 4 5 8 5\r\n", "output": "YES\r\n"}, {"input": "18\r\n2 10 3 6 6 6 10 8 8 1 10 9 9 3 1 9 7 4\r\n", "output": "YES\r\n"}, {"input": "20\r\n9 6 6 10 4 4 8 7 4 10 10 2 10 5 9 5 3 10 1 9\r\n", "output": "NO\r\n"}, {"input": "12\r\n3 8 10 2 4 4 6 9 5 10 10 3\r\n", "output": "YES\r\n"}, {"input": "11\r\n9 2 7 7 7 3 7 5 4 10 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 4 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 4\r\n", "output": "YES\r\n"}, {"input": "2\r\n7 1\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 5 6 7 6\r\n", "output": "YES\r\n"}, {"input": "11\r\n4 3 10 3 7 8 4 9 2 1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n705032704 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 5 6 8 3 1 7 3\r\n", "output": "YES\r\n"}, {"input": "20\r\n8 6 3 6 3 5 10 2 6 1 7 6 9 10 8 3 5 9 3 8\r\n", "output": "YES\r\n"}, {"input": "11\r\n2 4 8 3 4 7 9 10 5 3 3\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 4 2 24 6 4 2\r\n", "output": "YES\r\n"}, {"input": "17\r\n7 1 1 1 8 9 1 10 8 8 7 9 7 9 1 6 5\r\n", "output": "NO\r\n"}, {"input": "7\r\n7 10 1 2 6 2 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n10 10 40 10 10\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 3 13\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 2 10 2 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n7 4 5 62 20 20 6\r\n", "output": "YES\r\n"}, {"input": "6\r\n1 5 2 20 10 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n5 6\r\n", "output": "NO\r\n"}, {"input": "14\r\n5 2 9 7 5 8 3 2 2 4 9 1 3 10\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 2 2 5 5\r\n", "output": "NO\r\n"}, {"input": "11\r\n1 1 1 1 1 10 1 1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "9\r\n8 4 13 19 11 1 8 2 8\r\n", "output": "YES\r\n"}, {"input": "6\r\n14 16 14 14 15 11\r\n", "output": "YES\r\n"}, {"input": "9\r\n14 19 1 13 11 3 1 1 7\r\n", "output": "YES\r\n"}, {"input": "6\r\n16 13 3 7 4 15\r\n", "output": "YES\r\n"}, {"input": "4\r\n11 7 12 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 1 3 6 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 4 8 11 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 10 3 4\r\n", "output": "YES\r\n"}, {"input": "6\r\n8 15 12 14 15 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 4 4 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 3 1 6 4\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 12 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 4 13\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1 1 1 1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n19 6 5 13 6 13\r\n", "output": "YES\r\n"}, {"input": "8\r\n2 2 2 5 1 2 3 3\r\n", "output": "YES\r\n"}]
false
stdio
null
true
660/A
660
A
PyPy 3
TESTS
37
155
1,228,800
78349294
import io, os import sys from math import gcd from atexit import register input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline sys.stdout = io.BytesIO() register(lambda: os.write(1, sys.stdout.getvalue())) tokens = [] tokens_next = 0 def nextStr(): global tokens, tokens_next while tokens_next >= len(tokens): tokens = input().split() tokens_next = 0 tokens_next += 1 return tokens[tokens_next - 1] def nextInt(): return int(nextStr()) def nextIntArr(n): return [nextInt() for i in range(n)] def print(s, end='\n'): sys.stdout.write((str(s) + end).encode()) n = nextInt() a = nextIntArr(n) res = [] for i in range(n): if i == 0: res.append(a[i]) continue if gcd(a[i], a[i - 1]) != 1: res.append(999983) res.append(a[i]) print(len(res) - n) print(' '.join(map(str, res)))
93
46
0
179333013
def gcd(a, b): if b == 0: return a return gcd(b, a % b) input() valores = list(map(int, input().split(" "))) adicionados = 0 resultado = [] for i in range(len(valores) - 1): mdc = gcd(valores[i], valores[i + 1]) resultado.append(valores[i]) if mdc != 1: resultado.append(1) adicionados += 1 resultado.append(valores[-1]) print(adicionados) print(*resultado)
Educational Codeforces Round 11
ICPC
2,016
1
256
Co-prime Array
You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want not greater than 109 in any place in the array. An array is co-prime if any two adjacent numbers of it are co-prime. In the number theory, two integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.
The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.
Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime. The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array a by adding k elements to it. If there are multiple answers you can print any one of them.
null
null
[{"input": "3\n2 7 28", "output": "1\n2 7 9 28"}]
1,200
["greedy", "implementation", "math", "number theory"]
93
[{"input": "3\r\n2 7 28\r\n", "output": "1\r\n2 7 1 28\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n548\r\n"}, {"input": "1\r\n963837006\r\n", "output": "0\r\n963837006\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n1 1 1 1 1 1 1 1 1 1\r\n"}, {"input": "10\r\n26 723 970 13 422 968 875 329 234 983\r\n", "output": "2\r\n26 723 970 13 422 1 968 875 1 329 234 983\r\n"}, {"input": "10\r\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396\r\n", "output": "7\r\n319645572 1 758298525 1 812547177 1 459359946 1 355467212 1 304450522 807957797 916787906 1 239781206 1 242840396\r\n"}, {"input": "100\r\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1\r\n", "output": "19\r\n1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1\r\n"}, {"input": "100\r\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917\r\n", "output": "38\r\n591 1 417 1 888 251 792 1 847 685 3 182 461 102 1 348 1 555 956 771 901 712 1 878 1 580 631 342 1 333 1 285 899 525 1 725 537 718 929 653 84 1 788 1 104 355 624 803 1 253 853 201 995 536 1 184 65 1 205 1 540 1 652 549 1 777 248 405 677 950 431 580 1 600 1 846 1 328 429 134 983 526 103 500 963 400 23 1 276 1 704 1 570 757 410 1 658 507 620 1 984 1 244 1 486 1 454 1 802 411 985 303 635 283 96 1 597 1 855 1 775 139 839 1 839 61 219 986 1 776 1 72 1 729 1 69 20 917\r\n"}, {"input": "5\r\n472882027 472882027 472882027 472882027 472882027\r\n", "output": "4\r\n472882027 1 472882027 1 472882027 1 472882027 1 472882027\r\n"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "1\r\n1000000000 1 1000000000\r\n"}, {"input": "2\r\n8 6\r\n", "output": "1\r\n8 1 6\r\n"}, {"input": "3\r\n100000000 1000000000 1000000000\r\n", "output": "2\r\n100000000 1 1000000000 1 1000000000\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n1 2 3 4 5\r\n"}, {"input": "20\r\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000\r\n", "output": "19\r\n2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000\r\n"}, {"input": "2\r\n223092870 23\r\n", "output": "1\r\n223092870 1 23\r\n"}, {"input": "2\r\n100000003 100000003\r\n", "output": "1\r\n100000003 1 100000003\r\n"}, {"input": "2\r\n999999937 999999937\r\n", "output": "1\r\n999999937 1 999999937\r\n"}, {"input": "4\r\n999 999999937 999999937 999\r\n", "output": "1\r\n999 999999937 1 999999937 999\r\n"}, {"input": "2\r\n999999929 999999929\r\n", "output": "1\r\n999999929 1 999999929\r\n"}, {"input": "2\r\n1049459 2098918\r\n", "output": "1\r\n1049459 1 2098918\r\n"}, {"input": "2\r\n352229 704458\r\n", "output": "1\r\n352229 1 704458\r\n"}, {"input": "2\r\n7293 4011\r\n", "output": "1\r\n7293 1 4011\r\n"}, {"input": "2\r\n5565651 3999930\r\n", "output": "1\r\n5565651 1 3999930\r\n"}, {"input": "2\r\n997 997\r\n", "output": "1\r\n997 1 997\r\n"}, {"input": "3\r\n9994223 9994223 9994223\r\n", "output": "2\r\n9994223 1 9994223 1 9994223\r\n"}, {"input": "2\r\n99999998 1000000000\r\n", "output": "1\r\n99999998 1 1000000000\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "2\r\n1000000000 1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n130471 130471\r\n", "output": "1\r\n130471 1 130471\r\n"}, {"input": "3\r\n1000000000 2 2\r\n", "output": "2\r\n1000000000 1 2 1 2\r\n"}, {"input": "2\r\n223092870 66526\r\n", "output": "1\r\n223092870 1 66526\r\n"}, {"input": "14\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491 436077930 570018449\r\n", "output": "10\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491 436077930 1 570018449\r\n"}, {"input": "2\r\n3996017 3996017\r\n", "output": "1\r\n3996017 1 3996017\r\n"}, {"input": "2\r\n999983 999983\r\n", "output": "1\r\n999983 1 999983\r\n"}, {"input": "2\r\n618575685 773990454\r\n", "output": "1\r\n618575685 1 773990454\r\n"}, {"input": "3\r\n9699690 3 7\r\n", "output": "1\r\n9699690 1 3 7\r\n"}, {"input": "2\r\n999999999 999999996\r\n", "output": "1\r\n999999999 1 999999996\r\n"}, {"input": "2\r\n99999910 99999910\r\n", "output": "1\r\n99999910 1 99999910\r\n"}, {"input": "12\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491\r\n", "output": "9\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491\r\n"}, {"input": "3\r\n999999937 999999937 999999937\r\n", "output": "2\r\n999999937 1 999999937 1 999999937\r\n"}, {"input": "2\r\n99839 99839\r\n", "output": "1\r\n99839 1 99839\r\n"}, {"input": "3\r\n19999909 19999909 19999909\r\n", "output": "2\r\n19999909 1 19999909 1 19999909\r\n"}, {"input": "4\r\n1 1000000000 1 1000000000\r\n", "output": "0\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n64006 64006\r\n", "output": "1\r\n64006 1 64006\r\n"}, {"input": "2\r\n1956955 1956955\r\n", "output": "1\r\n1956955 1 1956955\r\n"}, {"input": "3\r\n1 1000000000 1000000000\r\n", "output": "1\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n982451707 982451707\r\n", "output": "1\r\n982451707 1 982451707\r\n"}, {"input": "2\r\n999999733 999999733\r\n", "output": "1\r\n999999733 1 999999733\r\n"}, {"input": "3\r\n999999733 999999733 999999733\r\n", "output": "2\r\n999999733 1 999999733 1 999999733\r\n"}, {"input": "2\r\n3257 3257\r\n", "output": "1\r\n3257 1 3257\r\n"}, {"input": "2\r\n223092870 181598\r\n", "output": "1\r\n223092870 1 181598\r\n"}, {"input": "3\r\n959919409 105935 105935\r\n", "output": "2\r\n959919409 1 105935 1 105935\r\n"}, {"input": "2\r\n510510 510510\r\n", "output": "1\r\n510510 1 510510\r\n"}, {"input": "3\r\n223092870 1000000000 1000000000\r\n", "output": "2\r\n223092870 1 1000000000 1 1000000000\r\n"}, {"input": "14\r\n1000000000 2 1000000000 3 1000000000 6 1000000000 1000000000 15 1000000000 1000000000 1000000000 100000000 1000\r\n", "output": "11\r\n1000000000 1 2 1 1000000000 3 1000000000 1 6 1 1000000000 1 1000000000 1 15 1 1000000000 1 1000000000 1 1000000000 1 100000000 1 1000\r\n"}, {"input": "7\r\n1 982451653 982451653 1 982451653 982451653 982451653\r\n", "output": "3\r\n1 982451653 1 982451653 1 982451653 1 982451653 1 982451653\r\n"}, {"input": "2\r\n100000007 100000007\r\n", "output": "1\r\n100000007 1 100000007\r\n"}, {"input": "3\r\n999999757 999999757 999999757\r\n", "output": "2\r\n999999757 1 999999757 1 999999757\r\n"}, {"input": "3\r\n99999989 99999989 99999989\r\n", "output": "2\r\n99999989 1 99999989 1 99999989\r\n"}, {"input": "5\r\n2 4 982451707 982451707 3\r\n", "output": "2\r\n2 1 4 982451707 1 982451707 3\r\n"}, {"input": "2\r\n20000014 20000014\r\n", "output": "1\r\n20000014 1 20000014\r\n"}, {"input": "2\r\n99999989 99999989\r\n", "output": "1\r\n99999989 1 99999989\r\n"}, {"input": "2\r\n111546435 111546435\r\n", "output": "1\r\n111546435 1 111546435\r\n"}, {"input": "2\r\n55288874 33538046\r\n", "output": "1\r\n55288874 1 33538046\r\n"}, {"input": "5\r\n179424673 179424673 179424673 179424673 179424673\r\n", "output": "4\r\n179424673 1 179424673 1 179424673 1 179424673 1 179424673\r\n"}, {"input": "2\r\n199999978 199999978\r\n", "output": "1\r\n199999978 1 199999978\r\n"}, {"input": "2\r\n1000000000 2\r\n", "output": "1\r\n1000000000 1 2\r\n"}, {"input": "3\r\n19999897 19999897 19999897\r\n", "output": "2\r\n19999897 1 19999897 1 19999897\r\n"}, {"input": "2\r\n19999982 19999982\r\n", "output": "1\r\n19999982 1 19999982\r\n"}, {"input": "2\r\n10000007 10000007\r\n", "output": "1\r\n10000007 1 10000007\r\n"}, {"input": "3\r\n999999937 999999937 2\r\n", "output": "1\r\n999999937 1 999999937 2\r\n"}, {"input": "5\r\n2017 2017 2017 2017 2017\r\n", "output": "4\r\n2017 1 2017 1 2017 1 2017 1 2017\r\n"}, {"input": "2\r\n19999909 39999818\r\n", "output": "1\r\n19999909 1 39999818\r\n"}, {"input": "2\r\n62615533 7919\r\n", "output": "1\r\n62615533 1 7919\r\n"}, {"input": "5\r\n39989 39989 33 31 29\r\n", "output": "1\r\n39989 1 39989 33 31 29\r\n"}, {"input": "2\r\n1000000000 100000\r\n", "output": "1\r\n1000000000 1 100000\r\n"}, {"input": "2\r\n1938 10010\r\n", "output": "1\r\n1938 1 10010\r\n"}, {"input": "2\r\n199999 199999\r\n", "output": "1\r\n199999 1 199999\r\n"}, {"input": "2\r\n107273 107273\r\n", "output": "1\r\n107273 1 107273\r\n"}, {"input": "3\r\n49999 49999 49999\r\n", "output": "2\r\n49999 1 49999 1 49999\r\n"}, {"input": "2\r\n1999966 1999958\r\n", "output": "1\r\n1999966 1 1999958\r\n"}, {"input": "2\r\n86020 300846\r\n", "output": "1\r\n86020 1 300846\r\n"}, {"input": "2\r\n999999997 213\r\n", "output": "1\r\n999999997 1 213\r\n"}, {"input": "2\r\n200000014 200000434\r\n", "output": "1\r\n200000014 1 200000434\r\n"}]
false
stdio
import sys import math 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()) a = list(map(int, f.readline().split())) # Read submission output with open(submission_path) as f: lines = f.readlines() if len(lines) < 2: print(0) return try: k_sub = int(lines[0].strip()) array_sub = list(map(int, lines[1].strip().split())) except: print(0) return # Check array_sub length if len(array_sub) != n + k_sub: print(0) return # Read reference output's k_ref with open(output_path) as f: k_ref = int(f.readline().strip()) # Check k_sub equals k_ref if k_sub != k_ref: print(0) return # Check original array is a subsequence of array_sub i = 0 for num in array_sub: if i < len(a) and num == a[i]: i += 1 if i != len(a): print(0) return # Check all adjacent pairs are coprime for j in range(len(array_sub)-1): x = array_sub[j] y = array_sub[j+1] if math.gcd(x, y) != 1: print(0) return # All checks passed print(1) if __name__ == "__main__": main()
true
603/A
603
A
PyPy 3
TESTS
9
78
20,889,600
35743305
n = int(input()) s = input() cnt = 1 last = s[0] for i in range(1, len(s)): if s[i] != last: cnt += 1 last = s[i] if s.count('111') or s.count('000') or s.count('00') > 1 or s.count('11') > 1: print(cnt+2) elif s.count('11') or s.count('00'): print(cnt+1) else: print(cnt)
116
61
102,400
204916976
n,s=int(input()),input() print(min(n,s.count('01')+s.count('10')+3))
Codeforces Round 334 (Div. 1)
CF
2,015
2
256
Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not. Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.
The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000). The following line contains a binary string of length n representing Kevin's results on the USAICO.
Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.
null
In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'. In the second sample, Kevin can flip the entire string and still have the same score.
[{"input": "8\n10000011", "output": "5"}, {"input": "2\n01", "output": "2"}]
1,600
["dp", "greedy", "math"]
116
[{"input": "8\r\n10000011\r\n", "output": "5\r\n"}, {"input": "2\r\n01\r\n", "output": "2\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "75\r\n010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "75\r\n"}, {"input": "11\r\n00000000000\r\n", "output": "3\r\n"}, {"input": "56\r\n10101011010101010101010101010101010101011010101010101010\r\n", "output": "56\r\n"}, {"input": "50\r\n01011010110101010101010101010101010101010101010100\r\n", "output": "49\r\n"}, {"input": "7\r\n0110100\r\n", "output": "7\r\n"}, {"input": "8\r\n11011111\r\n", "output": "5\r\n"}, {"input": "6\r\n000000\r\n", "output": "3\r\n"}, {"input": "5\r\n01000\r\n", "output": "5\r\n"}, {"input": "59\r\n10101010101010101010101010101010101010101010101010101010101\r\n", "output": "59\r\n"}, {"input": "88\r\n1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "88\r\n"}, {"input": "93\r\n010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "93\r\n"}, {"input": "70\r\n0101010101010101010101010101010101010101010101010101010101010101010101\r\n", "output": "70\r\n"}, {"input": "78\r\n010101010101010101010101010101101010101010101010101010101010101010101010101010\r\n", "output": "78\r\n"}, {"input": "83\r\n10101010101010101010101010101010101010101010101010110101010101010101010101010101010\r\n", "output": "83\r\n"}, {"input": "87\r\n101010101010101010101010101010101010101010101010101010101010101010101010101010010101010\r\n", "output": "87\r\n"}, {"input": "65\r\n01010101101010101010101010101010101010101010101010101010101010101\r\n", "output": "65\r\n"}, {"input": "69\r\n010101010101010101101010101010101010101010101010101010101010101010101\r\n", "output": "69\r\n"}, {"input": "74\r\n01010101010101010101010101010101010101010101010101010101010101000101010101\r\n", "output": "74\r\n"}, {"input": "77\r\n01010101010101001010101010101010100101010101010101010101010101010101010101010\r\n", "output": "77\r\n"}, {"input": "60\r\n101010110101010101010101010110101010101010101010101010101010\r\n", "output": "60\r\n"}, {"input": "89\r\n01010101010101010101010101010101010101010101010101010101101010101010101010100101010101010\r\n", "output": "89\r\n"}, {"input": "68\r\n01010101010101010101010101010101010100101010100101010101010100101010\r\n", "output": "67\r\n"}, {"input": "73\r\n0101010101010101010101010101010101010101010111011010101010101010101010101\r\n", "output": "72\r\n"}, {"input": "55\r\n1010101010101010010101010101101010101010101010100101010\r\n", "output": "54\r\n"}, {"input": "85\r\n1010101010101010101010101010010101010101010101101010101010101010101011010101010101010\r\n", "output": "84\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n1111111111\r\n", "output": "3\r\n"}, {"input": "2\r\n10\r\n", "output": "2\r\n"}, {"input": "2\r\n11\r\n", "output": "2\r\n"}, {"input": "2\r\n00\r\n", "output": "2\r\n"}, {"input": "3\r\n000\r\n", "output": "3\r\n"}, {"input": "3\r\n001\r\n", "output": "3\r\n"}, {"input": "3\r\n010\r\n", "output": "3\r\n"}, {"input": "3\r\n011\r\n", "output": "3\r\n"}, {"input": "3\r\n100\r\n", "output": "3\r\n"}, {"input": "3\r\n101\r\n", "output": "3\r\n"}, {"input": "3\r\n110\r\n", "output": "3\r\n"}, {"input": "3\r\n111\r\n", "output": "3\r\n"}, {"input": "4\r\n0000\r\n", "output": "3\r\n"}, {"input": "4\r\n0001\r\n", "output": "4\r\n"}, {"input": "4\r\n0010\r\n", "output": "4\r\n"}, {"input": "4\r\n0011\r\n", "output": "4\r\n"}, {"input": "4\r\n0100\r\n", "output": "4\r\n"}, {"input": "4\r\n0101\r\n", "output": "4\r\n"}, {"input": "4\r\n0110\r\n", "output": "4\r\n"}, {"input": "4\r\n0111\r\n", "output": "4\r\n"}, {"input": "4\r\n1000\r\n", "output": "4\r\n"}, {"input": "4\r\n1001\r\n", "output": "4\r\n"}, {"input": "4\r\n1010\r\n", "output": "4\r\n"}, {"input": "4\r\n1011\r\n", "output": "4\r\n"}, {"input": "4\r\n1100\r\n", "output": "4\r\n"}, {"input": "4\r\n1101\r\n", "output": "4\r\n"}, {"input": "4\r\n1110\r\n", "output": "4\r\n"}, {"input": "4\r\n1111\r\n", "output": "3\r\n"}, {"input": "5\r\n00000\r\n", "output": "3\r\n"}, {"input": "5\r\n00001\r\n", "output": "4\r\n"}, {"input": "5\r\n00010\r\n", "output": "5\r\n"}, {"input": "5\r\n00011\r\n", "output": "4\r\n"}, {"input": "5\r\n00100\r\n", "output": "5\r\n"}, {"input": "5\r\n00101\r\n", "output": "5\r\n"}, {"input": "5\r\n00110\r\n", "output": "5\r\n"}, {"input": "5\r\n00111\r\n", "output": "4\r\n"}, {"input": "5\r\n01000\r\n", "output": "5\r\n"}, {"input": "5\r\n01001\r\n", "output": "5\r\n"}, {"input": "5\r\n01010\r\n", "output": "5\r\n"}, {"input": "5\r\n01011\r\n", "output": "5\r\n"}, {"input": "5\r\n01100\r\n", "output": "5\r\n"}, {"input": "5\r\n01101\r\n", "output": "5\r\n"}, {"input": "5\r\n01110\r\n", "output": "5\r\n"}, {"input": "5\r\n01111\r\n", "output": "4\r\n"}, {"input": "5\r\n10000\r\n", "output": "4\r\n"}, {"input": "5\r\n10001\r\n", "output": "5\r\n"}, {"input": "5\r\n10010\r\n", "output": "5\r\n"}, {"input": "5\r\n10100\r\n", "output": "5\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "5\r\n10110\r\n", "output": "5\r\n"}, {"input": "5\r\n10111\r\n", "output": "5\r\n"}, {"input": "5\r\n11000\r\n", "output": "4\r\n"}, {"input": "5\r\n11001\r\n", "output": "5\r\n"}, {"input": "5\r\n11010\r\n", "output": "5\r\n"}, {"input": "5\r\n11011\r\n", "output": "5\r\n"}, {"input": "5\r\n11100\r\n", "output": "4\r\n"}, {"input": "5\r\n11101\r\n", "output": "5\r\n"}, {"input": "5\r\n11110\r\n", "output": "4\r\n"}, {"input": "5\r\n11111\r\n", "output": "3\r\n"}]
false
stdio
null
true
127/B
127
B
PyPy 3-64
TESTS
23
62
0
192241219
n = int(input()) a = list(map(int , input().split())) c2 = [] c4 = [] for i in a : if(i in c2 or i in c4): continue else: if(a.count(i) >= 2): c2.append(i) c4.append(a.count(i) // 2) print(sum(c4) // 2)
93
46
0
155514969
n = int(input()) a = list(map(int,input().split())) d = dict.fromkeys(a,0) for i in a: d[i]+=1 s = 0 for i in d: d[i]//=2 s+=d[i] print(s//2)
Codeforces Beta Round 93 (Div. 2 Only)
CF
2,011
1
256
Canvas Frames
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the sticks or glue them together. To make a h × w-sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w. Specifically, to make a square frame (when h = w), he needs four sticks of the same length. Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.
The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100).
Print the single number — the maximum number of frames Nicholas can make for his future canvases.
null
null
[{"input": "5\n2 4 3 2 3", "output": "1"}, {"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3"}, {"input": "4\n3 3 3 5", "output": "0"}]
1,000
["implementation"]
93
[{"input": "5\r\n2 4 3 2 3\r\n", "output": "1"}, {"input": "13\r\n2 2 4 4 4 4 6 6 6 7 7 9 9\r\n", "output": "3"}, {"input": "4\r\n3 3 3 5\r\n", "output": "0"}, {"input": "2\r\n3 5\r\n", "output": "0"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0"}, {"input": "14\r\n2 4 2 6 2 3 4 1 4 5 4 3 4 1\r\n", "output": "2"}, {"input": "33\r\n1 2 2 6 10 10 33 11 17 32 25 6 7 29 11 32 33 8 13 17 17 6 11 11 11 8 10 26 29 26 32 33 36\r\n", "output": "5"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n10\r\n", "output": "0"}, {"input": "2\r\n1 1\r\n", "output": "0"}, {"input": "3\r\n1 1 1\r\n", "output": "0"}, {"input": "3\r\n1 2 2\r\n", "output": "0"}, {"input": "3\r\n3 2 1\r\n", "output": "0"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1"}, {"input": "4\r\n1 2 1 2\r\n", "output": "1"}, {"input": "4\r\n1 100 1 100\r\n", "output": "1"}, {"input": "4\r\n10 100 100 10\r\n", "output": "1"}, {"input": "4\r\n1 2 3 3\r\n", "output": "0"}, {"input": "4\r\n8 5 9 13\r\n", "output": "0"}, {"input": "4\r\n100 100 100 100\r\n", "output": "1"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1"}, {"input": "5\r\n1 4 4 1 1\r\n", "output": "1"}, {"input": "5\r\n1 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 1 100 100 100\r\n", "output": "1"}, {"input": "5\r\n100 100 100 100 100\r\n", "output": "1"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "1"}, {"input": "6\r\n1 1 5 1 1 5\r\n", "output": "1"}, {"input": "6\r\n1 100 100 1 1 1\r\n", "output": "1"}, {"input": "6\r\n100 1 1 100 1 100\r\n", "output": "1"}, {"input": "6\r\n1 2 3 2 3 1\r\n", "output": "1"}, {"input": "6\r\n1 50 1 100 50 100\r\n", "output": "1"}, {"input": "6\r\n10 10 10 12 13 14\r\n", "output": "0"}, {"input": "7\r\n1 1 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 2 1 2 1 2\r\n", "output": "1"}, {"input": "7\r\n1 1 2 2 1 2 3\r\n", "output": "1"}, {"input": "7\r\n1 3 2 2 3 1 4\r\n", "output": "1"}, {"input": "7\r\n1 3 4 3 5 4 6\r\n", "output": "1"}, {"input": "7\r\n7 6 5 4 3 2 1\r\n", "output": "0"}, {"input": "8\r\n1 2 1 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 2 1 1 2 2 2\r\n", "output": "1"}, {"input": "8\r\n1 2 2 2 3 1 1 3\r\n", "output": "1"}, {"input": "8\r\n1 2 3 4 1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n1 1 1 1 2 3 2 3\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 5 5 5\r\n", "output": "1"}, {"input": "8\r\n1 2 1 3 4 1 5 6\r\n", "output": "0"}, {"input": "8\r\n1 2 3 4 5 6 1 7\r\n", "output": "0"}, {"input": "8\r\n8 6 3 4 5 2 1 7\r\n", "output": "0"}, {"input": "8\r\n100 100 100 100 100 100 100 100\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "10\r\n19 9 14 14 19 5 5 18 10 17\r\n", "output": "1"}, {"input": "10\r\n72 86 73 25 84 29 33 34 20 29\r\n", "output": "0"}, {"input": "10\r\n93 93 99 98 91 96 92 98 94 98\r\n", "output": "1"}, {"input": "13\r\n35 6 21 30 67 55 70 39 75 72 11 13 69\r\n", "output": "0"}, {"input": "17\r\n90 97 12 56 94 11 49 96 22 7 15 48 71 71 94 72 100\r\n", "output": "1"}, {"input": "18\r\n39 72 67 28 69 41 43 51 66 99 4 57 68 93 28 27 37 27\r\n", "output": "1"}, {"input": "23\r\n88 82 2 67 4 6 67 83 77 58 48 64 86 37 96 83 35 46 13 79 72 18 35\r\n", "output": "1"}, {"input": "30\r\n43 34 38 50 47 24 26 20 7 5 26 29 98 87 90 46 10 53 88 61 90 39 78 81 65 13 72 95 53 27\r\n", "output": "1"}, {"input": "33\r\n1 3 34 55 38 58 64 26 66 44 50 63 46 62 62 99 73 87 35 20 30 38 39 85 49 24 93 68 8 25 86 30 51\r\n", "output": "1"}, {"input": "38\r\n65 69 80 93 28 36 40 81 53 75 55 50 82 95 8 51 66 65 50 4 40 92 18 70 38 68 42 100 34 57 98 79 95 84 82 35 100 89\r\n", "output": "3"}, {"input": "40\r\n4 2 62 38 76 68 19 71 44 91 76 31 3 63 56 62 93 98 10 61 52 59 81 46 23 27 36 26 24 38 37 66 15 16 78 41 95 82 73 90\r\n", "output": "1"}, {"input": "43\r\n62 31 14 43 67 2 60 77 64 70 91 9 3 43 76 7 56 84 5 20 88 50 47 42 7 39 8 56 71 24 49 59 70 61 81 17 76 44 80 61 77 5 96\r\n", "output": "4"}, {"input": "49\r\n75 64 7 2 1 66 31 84 78 53 34 5 40 90 7 62 86 54 99 77 8 92 30 3 18 18 61 38 38 11 79 88 84 89 50 94 72 8 54 85 100 1 19 4 97 91 13 39 91\r\n", "output": "4"}, {"input": "57\r\n83 94 42 57 19 9 40 25 56 92 9 38 58 66 43 19 50 10 100 3 49 96 77 36 20 3 48 15 38 19 99 100 66 14 52 13 16 73 65 99 29 85 75 18 97 64 57 82 70 19 16 25 40 11 9 22 89\r\n", "output": "6"}, {"input": "67\r\n36 22 22 86 52 53 36 68 46 82 99 37 15 43 57 35 33 99 22 96 7 8 80 93 70 70 55 51 61 74 6 28 85 72 84 42 29 1 4 71 7 40 61 95 93 36 42 61 16 40 10 85 31 86 93 19 44 20 52 66 10 22 40 53 25 29 23\r\n", "output": "8"}, {"input": "74\r\n90 26 58 69 87 23 44 9 32 25 33 13 79 84 52 90 4 7 93 77 29 85 22 1 96 69 98 16 76 87 57 16 44 41 57 28 18 70 77 83 37 17 59 87 27 19 89 63 14 84 77 40 46 77 82 73 86 73 30 58 6 30 70 36 31 12 43 50 93 3 3 57 38 91\r\n", "output": "7"}, {"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": "25"}, {"input": "100\r\n1 9 3 5 10 10 9 8 10 1 7 6 5 6 7 9 1 5 8 3 2 3 3 10 2 3 10 7 10 3 6 3 2 10 1 10 2 3 4 3 3 1 7 5 10 2 3 8 9 2 5 4 7 2 5 9 2 1 7 9 9 8 4 4 6 1 6 6 4 7 2 3 1 1 1 6 9 1 2 9 3 7 6 10 3 6 2 5 2 5 3 9 10 6 4 2 9 9 4 5\r\n", "output": "23"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "7\r\n13 13 13 13 6 2 3\r\n", "output": "1"}, {"input": "8\r\n1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n100 100 99 99 5\r\n", "output": "1"}, {"input": "8\r\n2 2 2 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 6 7 7\r\n", "output": "0"}, {"input": "8\r\n4 4 4 4 4 4 4 4\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 2 2\r\n", "output": "2"}, {"input": "4\r\n100 100 100 99\r\n", "output": "0"}, {"input": "4\r\n2 2 2 2\r\n", "output": "1"}, {"input": "5\r\n100 100 99 99 2\r\n", "output": "1"}, {"input": "9\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n2 2 3 4 4\r\n", "output": "1"}, {"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": "25"}, {"input": "13\r\n1 2 3 4 5 6 7 8 9 10 11 12 13\r\n", "output": "0"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "4\r\n4 4 4 4\r\n", "output": "1"}, {"input": "5\r\n1 1 2 3 3\r\n", "output": "1"}, {"input": "5\r\n30 30 30 1 1\r\n", "output": "1"}]
false
stdio
null
true
858/C
858
C
Python 3
TESTS
41
62
5,529,600
30433231
s=input() a=0 b='' c=['a', 'e', 'i', 'o','u'] S='' f=0 for i in range(len(s)): if a==0 and s[i] not in c : b=s[i] f=0 if a==2 and f==1 and s[i] not in c: S+=' ' a=0 b='' f=0 if a < 3 and s[i] not in c and s[i]!=b: a+=1 f=1 if a==3 and f==1: S+=' ' a=0 b='' else: if a!=0 and s[i] not in c: if s[i]==b: a+=1 else: S+=' ' a=0 if s[i] not in c : a+=1 b=s[i] else: a=0 b='' S+=s[i] print(S)
108
46
0
226365615
s = list(input()) same = True block = 0 vowels = ["a", "e", "i", "o", "u"] spaces = [] for a in range(len(s)): if s[a] in vowels: block = 0 same = True else: block += 1 if block > 1 and s[a] != s[a-1]: same = False if block >= 3 and not same: spaces.append(a) block = 1 same = True for a in spaces[::-1]: s.insert(a, " ") print("".join(s))
Технокубок 2018 - Отборочный Раунд 1
CF
2,017
1
256
Did you mean...
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them. Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block. For example: - the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo". When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos. Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Print the given word without any changes if there are no typos. If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
null
null
[{"input": "hellno", "output": "hell no"}, {"input": "abacaba", "output": "abacaba"}, {"input": "asdfasdf", "output": "asd fasd f"}]
1,500
["dp", "greedy", "implementation"]
108
[{"input": "hellno\r\n", "output": "hell no \r\n"}, {"input": "abacaba\r\n", "output": "abacaba \r\n"}, {"input": "asdfasdf\r\n", "output": "asd fasd f \r\n"}, {"input": "ooo\r\n", "output": "ooo \r\n"}, {"input": "moyaoborona\r\n", "output": "moyaoborona \r\n"}, {"input": "jxegxxx\r\n", "output": "jxegx xx \r\n"}, {"input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz\r\n", "output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz \r\n"}, {"input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte\r\n", "output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te \r\n"}, {"input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz\r\n", "output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz \r\n"}, {"input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf\r\n", "output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf \r\n"}, {"input": "mvjajoyeg\r\n", "output": "mv jajoyeg \r\n"}, {"input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq\r\n", "output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q \r\n"}, {"input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef\r\n", "output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef \r\n"}, {"input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj\r\n", "output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j \r\n"}, {"input": "hzxkuwqxonsulnndlhygvmallghjerwp\r\n", "output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p \r\n"}, {"input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd\r\n", "output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d \r\n"}, {"input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr\r\n", "output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r \r\n"}, {"input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu\r\n", "output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu \r\n"}, {"input": "a\r\n", "output": "a \r\n"}, {"input": "b\r\n", "output": "b \r\n"}, {"input": "aa\r\n", "output": "aa \r\n"}, {"input": "ab\r\n", "output": "ab \r\n"}, {"input": "ba\r\n", "output": "ba \r\n"}, {"input": "bb\r\n", "output": "bb \r\n"}, {"input": "aaa\r\n", "output": "aaa \r\n"}, {"input": "aab\r\n", "output": "aab \r\n"}, {"input": "aba\r\n", "output": "aba \r\n"}, {"input": "abb\r\n", "output": "abb \r\n"}, {"input": "baa\r\n", "output": "baa \r\n"}, {"input": "bab\r\n", "output": "bab \r\n"}, {"input": "bba\r\n", "output": "bba \r\n"}, {"input": "bbb\r\n", "output": "bbb \r\n"}, {"input": "bbc\r\n", "output": "bb c \r\n"}, {"input": "bcb\r\n", "output": "bc b \r\n"}, {"input": "cbb\r\n", "output": "cb b \r\n"}, {"input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc\r\n", "output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc \r\n"}, {"input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb\r\n", "output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b \r\n"}, {"input": "helllllooooo\r\n", "output": "helllllooooo \r\n"}, {"input": "bbbzxxx\r\n", "output": "bbb zx xx \r\n"}, {"input": "ffff\r\n", "output": "ffff \r\n"}, {"input": "cdddddddddddddddddd\r\n", "output": "cd ddddddddddddddddd \r\n"}, {"input": "bbbc\r\n", "output": "bbb c \r\n"}, {"input": "lll\r\n", "output": "lll \r\n"}, {"input": "bbbbb\r\n", "output": "bbbbb \r\n"}, {"input": "llll\r\n", "output": "llll \r\n"}, {"input": "bbbbbbccc\r\n", "output": "bbbbbb ccc \r\n"}, {"input": "lllllb\r\n", "output": "lllll b \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "lllll\r\n", "output": "lllll \r\n"}, {"input": "bbbbbbbbbc\r\n", "output": "bbbbbbbbb c \r\n"}, {"input": "helllllno\r\n", "output": "helllll no \r\n"}, {"input": "nnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnn \r\n"}, {"input": "bbbbbccc\r\n", "output": "bbbbb ccc \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "nnnnnnnnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnnnnnnnn \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "hhhh\r\n", "output": "hhhh \r\n"}, {"input": "nnnnnnnnnnnnnnnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnnnnnnnnnnnnnnn \r\n"}, {"input": "zzzzzzzzzz\r\n", "output": "zzzzzzzzzz \r\n"}, {"input": "dddd\r\n", "output": "dddd \r\n"}, {"input": "heffffffgggggghhhhhh\r\n", "output": "heffffff gggggg hhhhhh \r\n"}, {"input": "bcddd\r\n", "output": "bc ddd \r\n"}, {"input": "x\r\n", "output": "x \r\n"}, {"input": "nnn\r\n", "output": "nnn \r\n"}, {"input": "xxxxxxxx\r\n", "output": "xxxxxxxx \r\n"}, {"input": "cclcc\r\n", "output": "cc lc c \r\n"}, {"input": "tttttttttttttt\r\n", "output": "tttttttttttttt \r\n"}, {"input": "xxxxxxx\r\n", "output": "xxxxxxx \r\n"}, {"input": "ccccb\r\n", "output": "cccc b \r\n"}, {"input": "bcecccc\r\n", "output": "bcecccc \r\n"}, {"input": "jjja\r\n", "output": "jjja \r\n"}, {"input": "zzz\r\n", "output": "zzz \r\n"}, {"input": "xxxxxxxxxzzzzzzzzzzzz\r\n", "output": "xxxxxxxxx zzzzzzzzzzzz \r\n"}, {"input": "alllewww\r\n", "output": "alllewww \r\n"}, {"input": "bbbbbbbbb\r\n", "output": "bbbbbbbbb \r\n"}, {"input": "jjj\r\n", "output": "jjj \r\n"}, {"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\r\n", "output": "bbbbbbbbbbbbbbbbbbbbbbbbb \r\n"}, {"input": "kkkkkkkkkklllllllllllllll\r\n", "output": "kkkkkkkkkk lllllllllllllll \r\n"}, {"input": "helllllllllllo\r\n", "output": "helllllllllllo \r\n"}, {"input": "ttttsttttt\r\n", "output": "tttt st tttt \r\n"}, {"input": "tttttttsssssss\r\n", "output": "ttttttt sssssss \r\n"}, {"input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss\r\n", "output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss \r\n"}, {"input": "xxxxx\r\n", "output": "xxxxx \r\n"}, {"input": "bbbhbbb\r\n", "output": "bbb hb bb \r\n"}, {"input": "bbbbbbbb\r\n", "output": "bbbbbbbb \r\n"}]
false
stdio
null
true
845/A
845
A
Python 3
TESTS
16
62
0
29679665
n=int(input()) s=input() i=0 b=[] j=0 l=1 chsl=0 while i < len(s): if s[i]==' ': b.append(chsl) l=1 j+=1 chsl=0 else : chsl=chsl+int(s[i])*l l=l*10 i+=1 b.append(chsl) b.sort() if int(b[n-1])==int(b[n]) : print('NO') else: print('YES')
88
46
0
29845502
n = int(input()) ranks = [int(x) for x in input().split()] ranks.sort() if ranks[n-1] == ranks[n]: print('NO') else: print('YES')
Educational Codeforces Round 27
ICPC
2,017
1
256
Chess Tourney
Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins. Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?
The first line contains one integer n (1 ≤ n ≤ 100). The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).
If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
null
null
[{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}]
1,100
["implementation", "sortings"]
88
[{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 3\r\n", "output": "YES\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "NO\r\n"}, {"input": "35\r\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 10 10 6 7 8 9\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 1 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n10 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3 3 3\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 4 6 7\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 5 4 5 8 3 1 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4 1 4 10 9\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 8 10 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 3 4 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 3 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7 7 8 9 10 11 12 19\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 5 6 7\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 2 2 3 3 3 3\r\n", "output": "YES\r\n"}, {"input": "51\r\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 3 3 2 3 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n5 3 3 6\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 2 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7 19 19 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n6 6 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 1 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3 3 1 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n4 5 6 4 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2 3 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n100 99 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 6 5 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 6 7 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n6 5 3 3 1 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 5 6 8 6\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 7 4 5 319 19\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4 4 3 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 3 4 5 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 4 5 3 6 7 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 3 4 4 5 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 4 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 5 4 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 4 5 6 7 8 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 4 5 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 2 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 1 1 1 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2 3 5 6 7 8 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n4 3 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2 4 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 6\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 2 4 5 5 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 3 4 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4 4 2 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 7 1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 2 2 2\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 1 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n8 6\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 7 6 7 3 1 9 4 6 10 8 2 5 7\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 9 2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 3 3\r\n", "output": "NO\r\n"}]
false
stdio
null
true
815/A
815
A
PyPy 3
TESTS
18
171
26,521,600
89630219
n, m = list(map(int, input().split())) a = [] all_equals = True for i in range(n): row = list(map(int, input().split())) a.append(row) if row.count(a[0][0]) != len(row): all_equals = False def remove_cols(): ans = 0 min_col = [0] * m for i in range(m): min_col[i] = 1000 for j in range(n): min_col[i] = min(min_col[i], a[j][i]) ans += min_col[i] for j in range(n): a[j][i] -= min_col[i] return ans, min_col def remove_rows(): ans = 0 min_row = [] for i in range(n): min_row.append(min(a[i])) ans += min_row[-1] for j in range(m): a[i][j] -= min_row[i] return ans, min_row if all_equals and m < n: ans1, min_col = remove_cols() ans, min_row = remove_rows() else: ans, min_row = remove_rows() ans1, min_col = remove_cols() ans += ans1 for row in a: for ai in row: if ai != 0: print(-1) exit() print(ans) for i in range(n): for j in range(min_row[i]): print("row", i + 1) for i in range(m): for j in range(min_col[i]): print("col", i + 1)
177
170
5,222,400
157587945
n, m = map(int, input().split()) a = [list(map(int, input().split()))for i in range(n)] row = 'row' col = 'col' if n > m: row, col = col, row n, m = m, n a = list(map(list, zip(*a))) z = [] for i in range(n): x = min(a[i]) for j in range(m): a[i][j] -= x z += [(row, i + 1)] * x for i in range(1, n): if a[i] != a[i - 1]: print('-1') exit() for j in range(m): z += [(col, j + 1)] * a[0][j] print(len(z)) for i in z: print(*i)
Codeforces Round 419 (Div. 1)
CF
2,017
2
512
Karen and Game
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j. Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!
The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500).
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: - row x, (1 ≤ x ≤ n) describing a move of the form "choose the x-th row". - col x, (1 ≤ x ≤ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them.
null
In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center. In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
[{"input": "3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "output": "4\nrow 1\nrow 1\ncol 4\nrow 3"}, {"input": "3 3\n0 0 0\n0 1 0\n0 0 0", "output": "-1"}, {"input": "3 3\n1 1 1\n1 1 1\n1 1 1", "output": "3\nrow 1\nrow 2\nrow 3"}]
1,700
["brute force", "greedy", "implementation"]
177
[{"input": "3 5\r\n2 2 2 3 2\r\n0 0 0 1 0\r\n1 1 1 2 1\r\n", "output": "4\r\nrow 1\r\nrow 1\r\ncol 4\r\nrow 3\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "3\r\nrow 1\r\nrow 2\r\nrow 3\r\n"}, {"input": "3 5\r\n2 4 2 2 3\r\n0 2 0 0 1\r\n1 3 1 1 2\r\n", "output": "6\r\nrow 1\r\nrow 1\r\ncol 2\r\ncol 2\r\ncol 5\r\nrow 3\r\n"}, {"input": "3 5\r\n0 0 0 0 0\r\n0 0 0 0 0\r\n0 0 0 0 1\r\n", "output": "-1\r\n"}, {"input": "9 10\r\n14 5 6 4 8 9 4 14 14 13\r\n13 4 5 3 7 8 3 13 13 12\r\n16 7 8 6 10 11 6 16 16 15\r\n10 1 2 0 4 5 0 10 10 9\r\n11 2 3 1 5 6 1 11 11 10\r\n10 1 2 0 4 5 0 10 10 9\r\n12 3 4 2 6 7 2 12 12 11\r\n13 4 5 3 7 8 3 13 13 12\r\n13 4 5 3 7 8 3 13 13 12\r\n", "output": "73\nrow 1\nrow 1\nrow 1\nrow 1\nrow 2\nrow 2\nrow 2\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 5\nrow 7\nrow 7\nrow 8\nrow 8\nrow 8\nrow 9\nrow 9\nrow 9\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 2\ncol 3\ncol 3\ncol 5\ncol 5\ncol 5\ncol 5\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\n"}, {"input": "10 10\r\n30 30 30 33 30 33 30 33 30 33\r\n431 431 431 434 431 434 431 434 431 434\r\n19 19 19 22 19 22 19 22 19 22\r\n24 24 24 27 24 27 24 27 24 27\r\n5 5 5 8 5 8 5 8 5 8\r\n0 0 0 3 0 3 0 3 0 3\r\n0 0 0 3 0 3 0 3 0 3\r\n0 0 0 3 0 3 0 3 0 3\r\n0 0 0 3 0 3 0 3 0 3\r\n0 0 0 3 0 3 0 3 0 3\r\n", "output": "521\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\ncol 4\ncol 4\ncol 4\ncol 6\ncol 6\ncol 6\ncol 8\ncol 8\ncol 8\ncol 10\ncol 10\ncol 10\n"}, {"input": "1 1\r\n0\r\n", "output": "0\r\n"}, {"input": "1 1\r\n500\r\n", "output": "500\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\n"}, {"input": "10 10\r\n1 1 1 1 1 1 1 1 1 1\r\n1 1 1 1 1 1 1 1 1 1\r\n1 1 1 1 1 1 1 1 1 1\r\n1 1 1 1 1 1 1 1 1 1\r\n0 0 0 0 0 0 0 0 0 0\r\n1 1 1 1 1 1 1 1 1 1\r\n1 1 1 1 1 1 1 1 1 1\r\n1 1 1 1 1 1 1 1 1 1\r\n1 1 1 1 1 1 1 1 1 1\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "9\r\nrow 1\r\nrow 2\r\nrow 3\r\nrow 4\r\nrow 6\r\nrow 7\r\nrow 8\r\nrow 9\r\nrow 10\r\n"}, {"input": "10 10\r\n1 1 1 1 1 1 0 1 1 1\r\n1 1 1 1 1 1 0 1 1 1\r\n1 1 1 1 1 1 0 1 1 1\r\n1 1 1 1 1 1 0 1 1 1\r\n1 1 1 1 1 1 0 1 1 1\r\n1 1 1 1 1 1 0 1 1 1\r\n1 1 1 1 1 1 0 1 1 1\r\n1 1 1 1 1 1 0 1 1 1\r\n1 1 1 1 1 1 0 1 1 1\r\n1 1 1 1 1 1 0 1 1 1\r\n", "output": "9\r\ncol 1\r\ncol 2\r\ncol 3\r\ncol 4\r\ncol 5\r\ncol 6\r\ncol 8\r\ncol 9\r\ncol 10\r\n"}, {"input": "10 11\r\n8 7 10 15 5 13 12 9 14 11 6\r\n6 5 8 13 3 11 10 7 12 9 4\r\n10 9 12 17 7 15 14 11 16 13 8\r\n9 8 11 16 6 14 13 10 15 12 7\r\n12 11 14 19 9 17 16 13 18 15 10\r\n14 13 16 21 11 19 18 15 20 17 12\r\n7 6 9 14 4 12 11 8 13 10 5\r\n5 4 7 12 2 10 9 6 11 8 3\r\n11 10 13 18 8 16 15 12 17 14 9\r\n13 12 15 20 10 18 17 14 19 16 11\r\n", "output": "120\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 2\nrow 2\nrow 2\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 7\nrow 7\nrow 7\nrow 7\nrow 8\nrow 8\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\ncol 1\ncol 1\ncol 1\ncol 2\ncol 2\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 8\ncol 8\ncol 8\ncol 8\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 11\n"}, {"input": "5 3\r\n2 2 2\r\n2 2 2\r\n2 2 2\r\n1 1 1\r\n2 2 2\r\n", "output": "7\r\ncol 1\r\ncol 2\r\ncol 3\r\nrow 1\r\nrow 2\r\nrow 3\r\nrow 5\r\n"}, {"input": "3 5\r\n2 2 2 1 2\r\n2 2 2 1 2\r\n2 2 2 1 2\r\n", "output": "7\r\nrow 1\r\nrow 2\r\nrow 3\r\ncol 1\r\ncol 2\r\ncol 3\r\ncol 5\r\n"}, {"input": "1 100\r\n396 314 350 362 287 349 266 289 297 305 235 226 256 385 302 304 253 192 298 238 360 366 163 340 247 395 318 260 252 281 178 188 252 379 212 187 354 232 225 159 290 335 387 234 383 215 356 182 323 280 195 209 263 215 322 262 334 157 189 214 195 386 220 209 177 193 368 174 270 329 388 237 260 343 230 173 254 371 327 266 193 178 161 209 335 310 323 323 353 172 368 307 329 234 363 264 334 266 305 209\r\n", "output": "11960\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 5\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 12\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 13\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 14\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 15\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 16\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 17\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 18\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 19\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 20\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 21\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 22\ncol 23\ncol 23\ncol 23\ncol 23\ncol 23\ncol 23\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 24\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 25\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 26\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 27\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 28\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 29\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 30\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 31\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 32\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 33\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 34\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 35\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 36\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 37\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 38\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 39\ncol 40\ncol 40\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 41\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 42\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 43\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 44\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 45\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 46\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 47\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 48\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 49\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 50\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 51\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 52\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 53\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 54\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 55\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 56\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 57\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 59\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 60\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 61\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 62\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 63\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 64\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 65\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 66\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 67\ncol 68\ncol 68\ncol 68\ncol 68\ncol 68\ncol 68\ncol 68\ncol 68\ncol 68\ncol 68\ncol 68\ncol 68\ncol 68\ncol 68\ncol 68\ncol 68\ncol 68\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 69\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 70\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 71\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 72\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 73\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 74\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 75\ncol 76\ncol 76\ncol 76\ncol 76\ncol 76\ncol 76\ncol 76\ncol 76\ncol 76\ncol 76\ncol 76\ncol 76\ncol 76\ncol 76\ncol 76\ncol 76\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 77\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 78\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 79\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 80\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 81\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 82\ncol 83\ncol 83\ncol 83\ncol 83\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 84\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 85\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 86\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 87\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 88\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 89\ncol 90\ncol 90\ncol 90\ncol 90\ncol 90\ncol 90\ncol 90\ncol 90\ncol 90\ncol 90\ncol 90\ncol 90\ncol 90\ncol 90\ncol 90\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 91\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 92\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 93\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 94\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 95\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 96\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 97\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 98\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 99\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\ncol 100\n"}, {"input": "100 1\r\n173\r\n164\r\n99\r\n114\r\n255\r\n223\r\n280\r\n235\r\n207\r\n190\r\n136\r\n204\r\n206\r\n282\r\n253\r\n335\r\n267\r\n184\r\n288\r\n299\r\n263\r\n243\r\n341\r\n111\r\n278\r\n111\r\n214\r\n133\r\n125\r\n245\r\n99\r\n144\r\n232\r\n203\r\n131\r\n204\r\n117\r\n315\r\n269\r\n206\r\n262\r\n125\r\n212\r\n95\r\n220\r\n243\r\n141\r\n163\r\n311\r\n171\r\n222\r\n266\r\n141\r\n314\r\n329\r\n138\r\n187\r\n342\r\n272\r\n181\r\n300\r\n261\r\n339\r\n110\r\n194\r\n187\r\n183\r\n129\r\n151\r\n187\r\n129\r\n185\r\n322\r\n167\r\n99\r\n340\r\n285\r\n99\r\n176\r\n175\r\n272\r\n126\r\n220\r\n164\r\n237\r\n214\r\n96\r\n162\r\n129\r\n141\r\n144\r\n135\r\n172\r\n191\r\n155\r\n333\r\n186\r\n324\r\n237\r\n318\r\n", "output": "11282\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 3\nrow 3\nrow 3\nrow 3\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 11\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 12\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 13\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 14\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 15\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 16\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 17\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 18\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 19\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 20\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 21\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 22\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 23\nrow 24\nrow 24\nrow 24\nrow 24\nrow 24\nrow 24\nrow 24\nrow 24\nrow 24\nrow 24\nrow 24\nrow 24\nrow 24\nrow 24\nrow 24\nrow 24\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 25\nrow 26\nrow 26\nrow 26\nrow 26\nrow 26\nrow 26\nrow 26\nrow 26\nrow 26\nrow 26\nrow 26\nrow 26\nrow 26\nrow 26\nrow 26\nrow 26\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 27\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 28\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 29\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 30\nrow 31\nrow 31\nrow 31\nrow 31\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 32\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 33\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 34\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 35\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 36\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 37\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 38\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 39\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 40\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 41\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 42\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 43\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 45\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 46\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 47\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 48\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 49\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 50\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 51\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 52\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 53\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 54\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 55\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 56\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 57\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 58\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 59\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 60\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 61\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 62\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 63\nrow 64\nrow 64\nrow 64\nrow 64\nrow 64\nrow 64\nrow 64\nrow 64\nrow 64\nrow 64\nrow 64\nrow 64\nrow 64\nrow 64\nrow 64\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 65\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 66\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 67\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 68\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 69\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 70\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 71\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 72\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 73\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 74\nrow 75\nrow 75\nrow 75\nrow 75\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 76\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 77\nrow 78\nrow 78\nrow 78\nrow 78\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 79\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 80\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 81\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 82\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 83\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 84\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 85\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 86\nrow 87\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 88\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 89\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 90\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 91\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 92\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 93\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 94\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 95\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 96\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 97\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 98\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 99\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\nrow 100\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\n"}, {"input": "1 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 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\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\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\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": "0\r\n"}, {"input": "1 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": "1\r\nrow 1\r\n"}, {"input": "100 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\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", "output": "1\r\ncol 1\r\n"}, {"input": "1 100\r\n500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500\r\n", "output": "500\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\n"}, {"input": "100 1\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n500\r\n", "output": "500\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\n"}, {"input": "2 1\r\n1\r\n1\r\n", "output": "1\r\ncol 1\r\n"}, {"input": "4 3\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "3\r\ncol 1\r\ncol 2\r\ncol 3\r\n"}, {"input": "2 1\r\n2\r\n2\r\n", "output": "2\r\ncol 1\r\ncol 1\r\n"}, {"input": "3 2\r\n1 1\r\n1 1\r\n1 1\r\n", "output": "2\r\ncol 1\r\ncol 2\r\n"}, {"input": "2 1\r\n1\r\n2\r\n", "output": "2\r\ncol 1\r\nrow 2\r\n"}, {"input": "2 3\r\n1 1 1\r\n1 1 1\r\n", "output": "2\r\nrow 1\r\nrow 2\r\n"}, {"input": "1 2\r\n1 1\r\n", "output": "1\r\nrow 1\r\n"}, {"input": "5 1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n", "output": "1\r\ncol 1\r\n"}, {"input": "10 3\r\n101 201 301\r\n102 202 302\r\n103 203 303\r\n104 204 304\r\n105 205 305\r\n106 206 306\r\n107 207 307\r\n108 208 308\r\n109 209 309\r\n111 211 311\r\n", "output": "649\nrow 2\nrow 3\nrow 3\nrow 4\nrow 4\nrow 4\nrow 5\nrow 5\nrow 5\nrow 5\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\n"}, {"input": "2 1\r\n10\r\n10\r\n", "output": "10\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\n"}, {"input": "4 3\r\n2 2 2\r\n2 2 2\r\n2 2 2\r\n2 2 2\r\n", "output": "6\r\ncol 1\r\ncol 2\r\ncol 3\r\ncol 1\r\ncol 2\r\ncol 3\r\n"}, {"input": "3 1\r\n1\r\n1\r\n1\r\n", "output": "1\r\ncol 1\r\n"}, {"input": "8 2\r\n2 2\r\n2 2\r\n2 2\r\n2 2\r\n2 2\r\n2 2\r\n2 2\r\n2 2\r\n", "output": "4\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\n"}, {"input": "1 2\r\n2 2\r\n", "output": "2\r\nrow 1\r\nrow 1\r\n"}, {"input": "3 2\r\n2 3\r\n2 3\r\n2 3\r\n", "output": "5\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\ncol 2\r\n"}, {"input": "2 1\r\n3\r\n3\r\n", "output": "3\r\ncol 1\r\ncol 1\r\ncol 1\r\n"}, {"input": "6 2\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n", "output": "2\r\ncol 1\r\ncol 2\r\n"}, {"input": "4 1\r\n1\r\n1\r\n1\r\n1\r\n", "output": "1\r\ncol 1\r\n"}, {"input": "2 5\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "2\r\nrow 1\r\nrow 2\r\n"}, {"input": "3 1\r\n500\r\n500\r\n500\r\n", "output": "500\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\n"}, {"input": "5 2\r\n1 1\r\n2 2\r\n2 2\r\n2 2\r\n2 2\r\n", "output": "6\r\ncol 1\r\ncol 2\r\nrow 2\r\nrow 3\r\nrow 4\r\nrow 5\r\n"}, {"input": "4 3\r\n3 3 3\r\n3 3 3\r\n3 3 3\r\n3 3 3\r\n", "output": "9\r\ncol 1\r\ncol 2\r\ncol 3\r\ncol 1\r\ncol 2\r\ncol 3\r\ncol 1\r\ncol 2\r\ncol 3\r\n"}, {"input": "5 2\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n", "output": "2\r\ncol 1\r\ncol 2\r\n"}, {"input": "1 4\r\n1 1 1 1\r\n", "output": "1\r\nrow 1\r\n"}, {"input": "3 1\r\n2\r\n3\r\n2\r\n", "output": "3\r\ncol 1\r\ncol 1\r\nrow 2\r\n"}, {"input": "1 5\r\n1 1 1 1 1\r\n", "output": "1\r\nrow 1\r\n"}, {"input": "2 4\r\n3 1 1 1\r\n3 1 1 1\r\n", "output": "4\r\nrow 1\r\nrow 2\r\ncol 1\r\ncol 1\r\n"}, {"input": "3 3\r\n1 1 1\r\n0 1 0\r\n0 0 0\r\n", "output": "-1\r\n"}, {"input": "3 2\r\n2 2\r\n1 1\r\n2 2\r\n", "output": "4\r\ncol 1\r\ncol 2\r\nrow 1\r\nrow 3\r\n"}, {"input": "2 1\r\n9\r\n9\r\n", "output": "9\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\n"}, {"input": "1 7\r\n3 3 3 3 3 3 3\r\n", "output": "3\r\nrow 1\r\nrow 1\r\nrow 1\r\n"}, {"input": "5 2\r\n3 3\r\n3 3\r\n3 3\r\n3 3\r\n3 3\r\n", "output": "6\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\n"}, {"input": "10 11\r\n250 198 192 182 85 239 295 91 318 216 249\r\n290 238 232 222 125 279 335 131 358 256 289\r\n409 357 351 341 244 398 454 250 477 375 408\r\n362 310 304 294 197 351 407 203 430 328 361\r\n352 300 294 284 187 341 397 193 420 318 351\r\n409 357 351 341 244 398 454 250 477 375 408\r\n209 157 151 141 44 198 254 50 277 175 208\r\n313 261 255 245 148 302 358 154 381 279 312\r\n171 119 113 103 6 160 216 12 239 137 170\r\n275 223 217 207 110 264 320 116 343 241 274\r\n", "output": "2770\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 4\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 5\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 6\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 7\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 8\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 9\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\nrow 10\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\ncol 11\n"}, {"input": "7 1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n", "output": "1\r\ncol 1\r\n"}, {"input": "5 3\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "3\r\ncol 1\r\ncol 2\r\ncol 3\r\n"}, {"input": "5 3\r\n3 3 3\r\n3 3 3\r\n3 3 3\r\n3 3 3\r\n3 3 3\r\n", "output": "9\r\ncol 1\r\ncol 2\r\ncol 3\r\ncol 1\r\ncol 2\r\ncol 3\r\ncol 1\r\ncol 2\r\ncol 3\r\n"}, {"input": "2 1\r\n4\r\n5\r\n", "output": "5\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\nrow 2\r\n"}, {"input": "4 2\r\n3 3\r\n3 3\r\n3 3\r\n3 3\r\n", "output": "6\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\n"}, {"input": "6 3\r\n2 2 2\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "4\r\ncol 1\r\ncol 2\r\ncol 3\r\nrow 1\r\n"}, {"input": "5 1\r\n1\r\n2\r\n3\r\n4\r\n5\r\n", "output": "11\r\ncol 1\r\nrow 2\r\nrow 3\r\nrow 3\r\nrow 4\r\nrow 4\r\nrow 4\r\nrow 5\r\nrow 5\r\nrow 5\r\nrow 5\r\n"}, {"input": "2 1\r\n1\r\n3\r\n", "output": "3\r\ncol 1\r\nrow 2\r\nrow 2\r\n"}, {"input": "3 2\r\n1 500\r\n1 500\r\n1 500\r\n", "output": "501\ncol 1\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\n"}, {"input": "10 1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n", "output": "1\r\ncol 1\r\n"}, {"input": "6 2\r\n2 2\r\n2 2\r\n2 2\r\n2 2\r\n2 2\r\n2 2\r\n", "output": "4\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\n"}, {"input": "3 5\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "3\r\nrow 1\r\nrow 2\r\nrow 3\r\n"}, {"input": "2 3\r\n2 1 2\r\n2 1 2\r\n", "output": "4\r\nrow 1\r\nrow 2\r\ncol 1\r\ncol 3\r\n"}, {"input": "5 2\r\n2 2\r\n2 2\r\n2 2\r\n2 2\r\n2 2\r\n", "output": "4\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\n"}, {"input": "1 2\r\n1 3\r\n", "output": "3\r\nrow 1\r\ncol 2\r\ncol 2\r\n"}, {"input": "4 3\r\n2 2 2\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "4\r\ncol 1\r\ncol 2\r\ncol 3\r\nrow 1\r\n"}, {"input": "3 2\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "5\r\ncol 1\r\ncol 2\r\nrow 2\r\nrow 3\r\nrow 3\r\n"}, {"input": "4 2\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n", "output": "2\r\ncol 1\r\ncol 2\r\n"}, {"input": "3 4\r\n1 1 1 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "3\r\nrow 1\r\nrow 2\r\nrow 3\r\n"}, {"input": "2 1\r\n2\r\n3\r\n", "output": "3\r\ncol 1\r\ncol 1\r\nrow 2\r\n"}, {"input": "5 3\r\n2 2 2\r\n2 2 2\r\n2 2 2\r\n2 2 2\r\n2 2 2\r\n", "output": "6\r\ncol 1\r\ncol 2\r\ncol 3\r\ncol 1\r\ncol 2\r\ncol 3\r\n"}, {"input": "3 2\r\n1 0\r\n2 1\r\n2 1\r\n", "output": "3\r\ncol 1\r\nrow 2\r\nrow 3\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "6\r\ncol 1\r\ncol 2\r\ncol 2\r\nrow 2\r\nrow 3\r\nrow 3\r\n"}, {"input": "3 3\r\n1 1 1\r\n1 2 1\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "4 3\r\n2 1 1\r\n2 1 1\r\n2 1 1\r\n2 1 1\r\n", "output": "4\r\ncol 1\r\ncol 2\r\ncol 3\r\ncol 1\r\n"}, {"input": "4 1\r\n3\r\n3\r\n3\r\n3\r\n", "output": "3\r\ncol 1\r\ncol 1\r\ncol 1\r\n"}, {"input": "1 3\r\n2 3 2\r\n", "output": "3\r\nrow 1\r\nrow 1\r\ncol 2\r\n"}, {"input": "1 2\r\n1 2\r\n", "output": "2\r\nrow 1\r\ncol 2\r\n"}, {"input": "3 2\r\n2 2\r\n2 2\r\n2 2\r\n", "output": "4\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\n"}, {"input": "1 3\r\n1 1 1\r\n", "output": "1\r\nrow 1\r\n"}, {"input": "6 3\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "3\r\ncol 1\r\ncol 2\r\ncol 3\r\n"}, {"input": "3 1\r\n2\r\n2\r\n2\r\n", "output": "2\r\ncol 1\r\ncol 1\r\n"}, {"input": "3 1\r\n3\r\n3\r\n3\r\n", "output": "3\r\ncol 1\r\ncol 1\r\ncol 1\r\n"}, {"input": "3 2\r\n2 2\r\n1 1\r\n1 1\r\n", "output": "3\r\ncol 1\r\ncol 2\r\nrow 1\r\n"}, {"input": "5 3\r\n1 1 2\r\n1 1 2\r\n1 1 2\r\n1 1 2\r\n1 1 2\r\n", "output": "4\r\ncol 1\r\ncol 2\r\ncol 3\r\ncol 3\r\n"}, {"input": "1 2\r\n2 3\r\n", "output": "3\r\nrow 1\r\nrow 1\r\ncol 2\r\n"}, {"input": "5 1\r\n2\r\n2\r\n2\r\n2\r\n2\r\n", "output": "2\r\ncol 1\r\ncol 1\r\n"}, {"input": "3 2\r\n1 1\r\n2 2\r\n2 2\r\n", "output": "4\r\ncol 1\r\ncol 2\r\nrow 2\r\nrow 3\r\n"}, {"input": "3 3\r\n1 1 1\r\n2 3 3\r\n4 4 4\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n5\r\n2\r\n", "output": "5\r\ncol 1\r\ncol 1\r\nrow 1\r\nrow 1\r\nrow 1\r\n"}, {"input": "4 2\r\n2 2\r\n2 2\r\n2 2\r\n2 2\r\n", "output": "4\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\n"}, {"input": "3 2\r\n5 10\r\n5 10\r\n5 10\r\n", "output": "15\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\ncol 2\r\ncol 2\r\ncol 2\r\ncol 2\r\ncol 2\r\n"}, {"input": "4 3\r\n3 4 3\r\n5 6 5\r\n3 4 3\r\n3 4 3\r\n", "output": "12\r\ncol 1\r\ncol 2\r\ncol 3\r\ncol 1\r\ncol 2\r\ncol 3\r\ncol 1\r\ncol 2\r\ncol 3\r\ncol 2\r\nrow 2\r\nrow 2\r\n"}, {"input": "4 2\r\n1 1\r\n1 1\r\n1 1\r\n2 2\r\n", "output": "3\r\ncol 1\r\ncol 2\r\nrow 4\r\n"}, {"input": "2 3\r\n1 1 1\r\n500 500 500\r\n", "output": "501\nrow 1\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\n"}, {"input": "4 1\r\n4\r\n4\r\n4\r\n4\r\n", "output": "4\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\n"}, {"input": "3 2\r\n1 1\r\n1 1\r\n2 2\r\n", "output": "3\r\ncol 1\r\ncol 2\r\nrow 3\r\n"}, {"input": "2 3\r\n2 2 2\r\n2 2 2\r\n", "output": "4\r\nrow 1\r\nrow 2\r\nrow 1\r\nrow 2\r\n"}, {"input": "3 2\r\n3 3\r\n3 3\r\n3 3\r\n", "output": "6\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\ncol 1\r\ncol 2\r\n"}, {"input": "2 3\r\n10 10 10\r\n5 5 5\r\n", "output": "15\r\nrow 1\r\nrow 2\r\nrow 1\r\nrow 2\r\nrow 1\r\nrow 2\r\nrow 1\r\nrow 2\r\nrow 1\r\nrow 2\r\nrow 1\r\nrow 1\r\nrow 1\r\nrow 1\r\nrow 1\r\n"}, {"input": "5 2\r\n1 2\r\n1 2\r\n1 2\r\n1 2\r\n1 2\r\n", "output": "3\r\ncol 1\r\ncol 2\r\ncol 2\r\n"}, {"input": "1 2\r\n500 500\r\n", "output": "500\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\n"}, {"input": "2 1\r\n5\r\n5\r\n", "output": "5\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 1\r\ncol 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, 'r') as f: n, m = map(int, f.readline().split()) grid = [list(map(int, f.readline().split())) for _ in range(n)] possible = True g1_1 = grid[0][0] if n > 0 and m > 0 else 0 for j in range(1, m): expected_delta = grid[0][j] - g1_1 for i in range(n): if grid[i][j] - grid[i][0] != expected_delta: possible = False break if not possible: break if possible: for i in range(1, n): expected_delta_row = grid[i][0] - g1_1 for j in range(m): if grid[i][j] - grid[0][j] != expected_delta_row: possible = False break if not possible: break with open(submission_path, 'r') as f: lines = [line.strip() for line in f.readlines()] if not lines: print(0) return first_line = lines[0] if first_line == '-1': print(1 if not possible else 0) return else: if not possible: print(0) return try: k_sub = int(first_line) except: print(0) return if len(lines) != k_sub + 1: print(0) return moves = lines[1:] c_min_j = max(g1_1 - grid[0][j] for j in range(m)) c_min = max(c_min_j, 0) c_max = min(row[0] for row in grid) if n > 0 else 0 if m > n: c_opt = c_min elif m < n: c_opt = c_max else: c_opt = c_min sum_gi1 = sum(row[0] for row in grid) sum_g1j = sum(grid[0]) if m > 0 else 0 minimal_sum = sum_gi1 + sum_g1j - m * g1_1 + (m - n) * c_opt if k_sub != minimal_sum: print(0) return valid_moves = True for move in moves: parts = move.split() if len(parts) != 2: valid_moves = False break typ, num = parts if typ not in ('row', 'col'): valid_moves = False break try: x = int(num) if (typ == 'row' and not (1 <= x <= n)) or (typ == 'col' and not (1 <= x <= m)): valid_moves = False break except: valid_moves = False break if not valid_moves: print(0) return sim = [[0] * m for _ in range(n)] for move in moves: typ, num = move.split() x = int(num) if typ == 'row': for j in range(m): sim[x-1][j] += 1 else: for i in range(n): sim[i][x-1] += 1 match = all(sim[i][j] == grid[i][j] for i in range(n) for j in range(m)) print(1 if match else 0) if __name__ == '__main__': main()
true
814/A
814
A
Python 3
TESTS
14
46
0
27634786
n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) vis=[0 for i in range(250)] cnt=0 num=0 for i in range(n): if a[i]==0: cnt+=1 for i in range(m): if vis[b[i]]==0: vis[b[i]]=1 num+=1 if num<cnt: print('No') elif num==1: flag=True if a[0]==0: a[0]=b[0] for i in range(1,n): if a[i]!=0 and a[i]<=a[i-1]: flag=False break elif a[i]==0 and b[0]<=a[i-1]: flag=False break if flag: print('No') else: print('Yes') else: print('Yes')
96
46
0
191280778
n, k = map(int, input().split()) a, b = list(map(int, input().split())), list(map(int, input().split())) a[a.index(0)] = b[0] print('Yes' if k > 1 or a != sorted(a) else 'No')
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An abandoned sentiment from past
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.
The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements. The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in a and b more than once in total.
Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.
null
In the first sample: - Sequence a is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in b are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
[{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}]
900
["constructive algorithms", "greedy", "implementation", "sortings"]
96
[{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\r\n80\r\n", "output": "No\r\n"}, {"input": "100 1\r\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\r\n58\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n2 1 0 4\r\n3\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n199 0\r\n200\r\n", "output": "No\r\n"}, {"input": "3 2\r\n115 0 0\r\n145 191\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n196 197 198 0 200\r\n199\r\n", "output": "No\r\n"}, {"input": "5 1\r\n92 0 97 99 100\r\n93\r\n", "output": "No\r\n"}, {"input": "3 1\r\n3 87 0\r\n81\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 92 192\r\n118\r\n", "output": "Yes\r\n"}, {"input": "10 1\r\n1 3 0 7 35 46 66 72 83 90\r\n22\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 0 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113\r\n67\r\n", "output": "No\r\n"}, {"input": "100 5\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 0 99 100\r\n98 64 55 52 29\r\n", "output": "Yes\r\n"}, {"input": "100 5\r\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\r\n121 199 62 193 27\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 0 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n11\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n1\r\n", "output": "No\r\n"}, {"input": "100 1\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 0\r\n100\r\n", "output": "No\r\n"}, {"input": "100 1\r\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\r\n65\r\n", "output": "Yes\r\n"}, {"input": "100 2\r\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 0 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\r\n48 1\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\r\n69\r\n", "output": "Yes\r\n"}, {"input": "100 1\r\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\r\n129\r\n", "output": "No\r\n"}, {"input": "5 2\r\n0 2 7 0 10\r\n1 8\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 4 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 3\r\n4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n1\r\n", "output": "No\r\n"}, {"input": "2 1\r\n0 5\r\n7\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 0 12 13\r\n1\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n0 2 3 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 0 3 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "7 2\r\n1 2 3 0 0 6 7\r\n4 5\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "2 2\r\n0 0\r\n1 2\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n1 0 0\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 4 0\r\n5 2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 1\r\n2\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 4 0 6\r\n2 5\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 4 5\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 2 3\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 5 0\r\n6\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n5 0 2\r\n7\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n4 5 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n10 11 12 0 14\r\n13\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 2 0 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 11 14\r\n12\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 3 0 4\r\n2\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 5\r\n1\r\n", "output": "No\r\n"}, {"input": "5 1\r\n1 2 0 4 7\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 5 4\r\n6\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n11 0 0 14\r\n13 12\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n1 0\r\n2\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 1\r\n1 0 3 2\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n5\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 1 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 2 3 4\r\n5\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 2 0\r\n5\r\n", "output": "No\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 0 5 7\r\n6\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 3 0\r\n4\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 0 11\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n7 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 3 0 5 0\r\n6 4\r\n", "output": "Yes\r\n"}, {"input": "3 2\r\n0 1 0\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n6 9 5 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 3\r\n6\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 2 0 0 5\r\n4 3\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n2 0 0 8\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n0 2\r\n3\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n0 4 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n1 2 3 4 0 5\r\n6\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n2 0\r\n3\r\n", "output": "No\r\n"}, {"input": "4 2\r\n11 0 0 200\r\n100 199\r\n", "output": "Yes\r\n"}, {"input": "2 1\r\n5 0\r\n4\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n1 0 5\r\n10\r\n", "output": "Yes\r\n"}, {"input": "6 2\r\n1 2 0 0 5 6\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 2\r\n1 0 3 0 5\r\n2 4\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n1 4 0 8\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n5 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 7\r\n3 2\r\n", "output": "Yes\r\n"}, {"input": "3 3\r\n0 0 0\r\n1 4 3\r\n", "output": "Yes\r\n"}, {"input": "5 5\r\n0 0 0 0 0\r\n5 4 3 2 1\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n3 9 4 0\r\n8\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 0 0 4\r\n2 3\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 4 0 8 9 10\r\n3\r\n", "output": "Yes\r\n"}, {"input": "4 1\r\n0 3 5 6\r\n9\r\n", "output": "Yes\r\n"}, {"input": "4 2\r\n1 2 0 0\r\n3 4\r\n", "output": "Yes\r\n"}, {"input": "5 1\r\n2 3 4 5 0\r\n1\r\n", "output": "Yes\r\n"}, {"input": "3 1\r\n2 0 4\r\n5\r\n", "output": "Yes\r\n"}]
false
stdio
null
true
845/A
845
A
Python 3
TESTS
6
61
0
29677284
n=int(input()) #k=[] k=input().split() i=0 k.sort() if int(k[n])>int(k[n-1]): print('YES') else: print('NO')
88
46
0
157877192
import sys input = sys.stdin.readline n = int(input()) w = sorted(map(int, input().split())) if w[n] == w[n-1]: print("NO") else: print("YES")
Educational Codeforces Round 27
ICPC
2,017
1
256
Chess Tourney
Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins. Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?
The first line contains one integer n (1 ≤ n ≤ 100). The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).
If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
null
null
[{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}]
1,100
["implementation", "sortings"]
88
[{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 3\r\n", "output": "YES\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "NO\r\n"}, {"input": "35\r\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 10 10 6 7 8 9\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 1 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n10 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3 3 3\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 4 6 7\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 5 4 5 8 3 1 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4 1 4 10 9\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 8 10 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 3 4 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 3 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7 7 8 9 10 11 12 19\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 5 6 7\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 2 2 3 3 3 3\r\n", "output": "YES\r\n"}, {"input": "51\r\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 3 3 2 3 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n5 3 3 6\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 2 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7 19 19 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n6 6 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 1 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3 3 1 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n4 5 6 4 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2 3 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n100 99 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 6 5 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 6 7 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n6 5 3 3 1 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 5 6 8 6\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 7 4 5 319 19\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4 4 3 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 3 4 5 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 4 5 3 6 7 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 3 4 4 5 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 4 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 5 4 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 4 5 6 7 8 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 4 5 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 2 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 1 1 1 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2 3 5 6 7 8 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n4 3 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2 4 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 6\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 2 4 5 5 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 3 4 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4 4 2 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 7 1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 2 2 2\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 1 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n8 6\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 7 6 7 3 1 9 4 6 10 8 2 5 7\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 9 2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 3 3\r\n", "output": "NO\r\n"}]
false
stdio
null
true
845/A
845
A
Python 3
TESTS
6
77
0
30044263
n = int(input('')) a = input('') b = sorted(a.split()) if int(b[n-1]) < int(b[n]): print('YES') else: print('NO')
88
46
0
189799761
# LUOGU_RID: 100288399 n, a = int(input()), [] t = input().split() for x in t: a.append(int(x)) a.sort() if a[n] > a[n - 1]: print("YES") else: print("NO")
Educational Codeforces Round 27
ICPC
2,017
1
256
Chess Tourney
Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins. Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?
The first line contains one integer n (1 ≤ n ≤ 100). The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).
If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
null
null
[{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}]
1,100
["implementation", "sortings"]
88
[{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 3\r\n", "output": "YES\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "NO\r\n"}, {"input": "35\r\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 10 10 6 7 8 9\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 1 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n10 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3 3 3\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 4 6 7\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 5 4 5 8 3 1 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4 1 4 10 9\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 8 10 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 3 4 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 3 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7 7 8 9 10 11 12 19\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 5 6 7\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 2 2 3 3 3 3\r\n", "output": "YES\r\n"}, {"input": "51\r\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 3 3 2 3 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n5 3 3 6\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 2 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7 19 19 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n6 6 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 1 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3 3 1 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n4 5 6 4 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2 3 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n100 99 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 6 5 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 6 7 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n6 5 3 3 1 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 5 6 8 6\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 7 4 5 319 19\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4 4 3 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 3 4 5 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 4 5 3 6 7 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 3 4 4 5 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 4 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 5 4 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 4 5 6 7 8 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 4 5 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 2 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 1 1 1 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2 3 5 6 7 8 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n4 3 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2 4 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 6\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 2 4 5 5 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 3 4 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4 4 2 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 7 1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 2 2 2\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 1 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n8 6\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 7 6 7 3 1 9 4 6 10 8 2 5 7\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 9 2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 3 3\r\n", "output": "NO\r\n"}]
false
stdio
null
true
845/A
845
A
Python 3
TESTS
6
62
0
29868692
n=int(input()) str=input() arr= str.split() arr.sort() if arr[n-1]==arr[n]: print("NO") else: print("YES")
88
46
0
213243425
# LUOGU_RID: 114908305 n=int(input()) alist=list(map(int,input().split())) alist.sort() if alist[n]>alist[n-1]: print("YES") else: print("NO")
Educational Codeforces Round 27
ICPC
2,017
1
256
Chess Tourney
Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins. Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?
The first line contains one integer n (1 ≤ n ≤ 100). The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).
If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
null
null
[{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}]
1,100
["implementation", "sortings"]
88
[{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 3\r\n", "output": "YES\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "NO\r\n"}, {"input": "35\r\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 10 10 6 7 8 9\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 1 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n10 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3 3 3\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 4 6 7\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 5 4 5 8 3 1 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4 1 4 10 9\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 8 10 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 3 4 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 3 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7 7 8 9 10 11 12 19\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 5 6 7\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 2 2 3 3 3 3\r\n", "output": "YES\r\n"}, {"input": "51\r\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 3 3 2 3 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n5 3 3 6\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 2 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7 19 19 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n6 6 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 1 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3 3 1 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n4 5 6 4 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2 3 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n100 99 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 6 5 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 6 7 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n6 5 3 3 1 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 5 6 8 6\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 7 4 5 319 19\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4 4 3 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 3 4 5 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 4 5 3 6 7 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 3 4 4 5 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 4 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 5 4 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 4 5 6 7 8 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 4 5 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 2 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 1 1 1 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2 3 5 6 7 8 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n4 3 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2 4 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 6\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 2 4 5 5 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 3 4 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4 4 2 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 7 1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 2 2 2\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 1 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n8 6\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 7 6 7 3 1 9 4 6 10 8 2 5 7\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 9 2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 3 3\r\n", "output": "NO\r\n"}]
false
stdio
null
true
845/A
845
A
Python 3
TESTS
6
62
5,632,000
34226787
a=int(input()) b=input() b=b.split(' ') b.sort() c=len(b)//2 if b[c]==b[c-1]: print('NO') else: print('YES')
88
46
0
215073561
n = int(input()) r = input() ratings =[] int_ratings =[] counter = 0 for x in r: if x == " ": ratings.append(r[0:r.index(x)]) r = r.replace(r[0:r.index(x)+1], "", 1) ratings.append(r) for x in ratings: int_ratings.append(int(x)) int_ratings.sort() for x in int_ratings[0:n]: if int_ratings[n] > x: counter += 1 if counter == n: print("YES") else: print("NO")
Educational Codeforces Round 27
ICPC
2,017
1
256
Chess Tourney
Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins. Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?
The first line contains one integer n (1 ≤ n ≤ 100). The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).
If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
null
null
[{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}]
1,100
["implementation", "sortings"]
88
[{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 3\r\n", "output": "YES\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "NO\r\n"}, {"input": "35\r\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 10 10 6 7 8 9\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 1 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n10 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3 3 3\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 4 6 7\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 5 4 5 8 3 1 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4 1 4 10 9\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 8 10 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 3 4 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 3 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7 7 8 9 10 11 12 19\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 5 6 7\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 2 2 3 3 3 3\r\n", "output": "YES\r\n"}, {"input": "51\r\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 3 3 2 3 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n5 3 3 6\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 2 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7 19 19 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n6 6 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 1 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3 3 1 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n4 5 6 4 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2 3 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n100 99 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 6 5 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 6 7 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n6 5 3 3 1 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 5 6 8 6\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 7 4 5 319 19\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4 4 3 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 3 4 5 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 4 5 3 6 7 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 3 4 4 5 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 4 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 5 4 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 4 5 6 7 8 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 4 5 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 2 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 1 1 1 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2 3 5 6 7 8 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n4 3 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2 4 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 6\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 2 4 5 5 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 3 4 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4 4 2 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 7 1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 2 2 2\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 1 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n8 6\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 7 6 7 3 1 9 4 6 10 8 2 5 7\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 9 2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 3 3\r\n", "output": "NO\r\n"}]
false
stdio
null
true
845/A
845
A
Python 3
TESTS
6
62
0
29660553
n = int(input()) a = [] s = input() t = s.split() for k in t: if k != " ": a.append(k) a = sorted(a) if a[n-1] == a[n]: print("NO") else: print("YES")
88
61
0
29648246
n = int(input()) a = input().strip().split(' ') for i in range(len(a)): a[i] = int(a[i]) a.sort() if a[n-1] >= a[n]: print("NO") else: print("YES")
Educational Codeforces Round 27
ICPC
2,017
1
256
Chess Tourney
Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins. Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?
The first line contains one integer n (1 ≤ n ≤ 100). The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).
If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
null
null
[{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}]
1,100
["implementation", "sortings"]
88
[{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 3\r\n", "output": "YES\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "NO\r\n"}, {"input": "35\r\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 10 10 6 7 8 9\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 1 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n10 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3 3 3\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 4 6 7\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 5 4 5 8 3 1 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4 1 4 10 9\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 8 10 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 3 4 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 3 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7 7 8 9 10 11 12 19\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 5 6 7\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 2 2 3 3 3 3\r\n", "output": "YES\r\n"}, {"input": "51\r\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 3 3 2 3 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n5 3 3 6\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 2 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7 19 19 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n6 6 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 1 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3 3 1 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n4 5 6 4 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2 3 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n100 99 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 6 5 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 6 7 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n6 5 3 3 1 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 5 6 8 6\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 7 4 5 319 19\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4 4 3 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 3 4 5 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 4 5 3 6 7 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 3 4 4 5 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 4 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 5 4 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 4 5 6 7 8 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 4 5 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 2 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 1 1 1 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2 3 5 6 7 8 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n4 3 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2 4 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 6\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 2 4 5 5 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 3 4 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4 4 2 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 7 1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 2 2 2\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 1 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n8 6\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 7 6 7 3 1 9 4 6 10 8 2 5 7\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 9 2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 3 3\r\n", "output": "NO\r\n"}]
false
stdio
null
true
845/A
845
A
Python 3
TESTS
6
62
0
29660327
n = int(input()) a = input().split() team_a = [] team_b = [] arr = sorted(a) #print(arr) for i in range(0, len(a)//2):team_b.append(arr[i]) for i in range(len(a)//2, len(a)):team_a.append(arr[i]) if(team_a[0] > team_b[-1]): print("YES") else: print("NO")
88
61
0
29648679
n = int(input()) arr = sorted(map(int, input().split())) arr1 = arr[:n] arr2 = arr[n:] if arr1[-1] >= arr2[0]: print("NO") else: print("YES")
Educational Codeforces Round 27
ICPC
2,017
1
256
Chess Tourney
Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins. Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?
The first line contains one integer n (1 ≤ n ≤ 100). The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).
If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
null
null
[{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}]
1,100
["implementation", "sortings"]
88
[{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 3\r\n", "output": "YES\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "NO\r\n"}, {"input": "35\r\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 10 10 6 7 8 9\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 1 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n10 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3 3 3\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 4 6 7\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 5 4 5 8 3 1 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4 1 4 10 9\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 8 10 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 3 4 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 3 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7 7 8 9 10 11 12 19\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 5 6 7\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 2 2 3 3 3 3\r\n", "output": "YES\r\n"}, {"input": "51\r\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 3 3 2 3 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n5 3 3 6\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 2 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7 19 19 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n6 6 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 1 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3 3 1 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n4 5 6 4 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2 3 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n100 99 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 6 5 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 6 7 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n6 5 3 3 1 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 5 6 8 6\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 7 4 5 319 19\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4 4 3 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 3 4 5 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 4 5 3 6 7 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 3 4 4 5 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 4 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 5 4 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 4 5 6 7 8 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 4 5 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 2 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 1 1 1 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2 3 5 6 7 8 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n4 3 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2 4 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 6\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 2 4 5 5 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 3 4 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4 4 2 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 7 1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 2 2 2\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 1 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n8 6\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 7 6 7 3 1 9 4 6 10 8 2 5 7\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 9 2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 3 3\r\n", "output": "NO\r\n"}]
false
stdio
null
true
845/A
845
A
Python 3
TESTS
6
77
0
30044378
n = int(input('')) a = input('').split() for b in a: b = int(b) a.sort() if a[n-1] < a[n]: print('YES') else: print('NO')
88
61
0
29652842
import sys def main(): n = int(sys.stdin.readline()) liste = list(map(int, sys.stdin.readline().split())) liste.sort() if liste[n-1] < liste[n]: print("YES") else: print("NO") main()
Educational Codeforces Round 27
ICPC
2,017
1
256
Chess Tourney
Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins. Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?
The first line contains one integer n (1 ≤ n ≤ 100). The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).
If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
null
null
[{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}]
1,100
["implementation", "sortings"]
88
[{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 3\r\n", "output": "YES\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "NO\r\n"}, {"input": "35\r\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 10 10 6 7 8 9\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 1 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n10 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3 3 3\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 4 6 7\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 5 4 5 8 3 1 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4 1 4 10 9\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 8 10 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 3 4 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 3 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7 7 8 9 10 11 12 19\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 5 6 7\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 2 2 3 3 3 3\r\n", "output": "YES\r\n"}, {"input": "51\r\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 3 3 2 3 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n5 3 3 6\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 2 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7 19 19 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n6 6 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 1 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3 3 1 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n4 5 6 4 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2 3 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n100 99 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 6 5 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 6 7 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n6 5 3 3 1 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 5 6 8 6\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 7 4 5 319 19\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4 4 3 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 3 4 5 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 4 5 3 6 7 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 3 4 4 5 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 4 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 5 4 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 4 5 6 7 8 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 4 5 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 2 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 1 1 1 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2 3 5 6 7 8 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n4 3 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2 4 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 6\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 2 4 5 5 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 3 4 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4 4 2 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 7 1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 2 2 2\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 1 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n8 6\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 7 6 7 3 1 9 4 6 10 8 2 5 7\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 9 2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 3 3\r\n", "output": "NO\r\n"}]
false
stdio
null
true
845/A
845
A
Python 3
TESTS
6
46
0
29663806
n = int(input()) a = [i for i in input().split()] a.sort() st = 'YES' if a[n-1] == a[n]: st='NO' print(st)
88
61
0
29937775
a = [] n = int(input()) a = input().split() for i in range(n*2): a[i] = int(a[i]) a.sort() ##print(a[n-1], a[n]) if(a[n-1] == a[n]): print("NO") else: print("YES")
Educational Codeforces Round 27
ICPC
2,017
1
256
Chess Tourney
Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins. Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?
The first line contains one integer n (1 ≤ n ≤ 100). The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).
If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
null
null
[{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}]
1,100
["implementation", "sortings"]
88
[{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 3\r\n", "output": "YES\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "NO\r\n"}, {"input": "35\r\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 10 10 6 7 8 9\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 1 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n10 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3 3 3\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 4 6 7\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 5 4 5 8 3 1 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4 1 4 10 9\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 8 10 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 3 4 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 3 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7 7 8 9 10 11 12 19\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 5 6 7\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 2 2 3 3 3 3\r\n", "output": "YES\r\n"}, {"input": "51\r\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 3 3 2 3 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n5 3 3 6\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 2 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7 19 19 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n6 6 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 1 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3 3 1 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n4 5 6 4 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2 3 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n100 99 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 6 5 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 6 7 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n6 5 3 3 1 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 5 6 8 6\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 7 4 5 319 19\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4 4 3 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 3 4 5 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 4 5 3 6 7 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 3 4 4 5 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 4 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 5 4 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 4 5 6 7 8 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 4 5 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 2 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 1 1 1 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2 3 5 6 7 8 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n4 3 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2 4 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 6\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 2 4 5 5 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 3 4 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4 4 2 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 7 1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 2 2 2\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 1 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n8 6\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 7 6 7 3 1 9 4 6 10 8 2 5 7\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 9 2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 3 3\r\n", "output": "NO\r\n"}]
false
stdio
null
true
845/A
845
A
Python 3
TESTS
6
77
0
29925938
n = int(input()) ratings = input().split(" ") ratings.sort() if ratings[n - 1] == ratings[n]: print("NO") else: print("YES")
88
61
4,300,800
133323495
n = int(input()) p = sorted(list(map(int,input().split()))) print(('NO','YES')[p[n]>p[n-1]])
Educational Codeforces Round 27
ICPC
2,017
1
256
Chess Tourney
Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins. Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?
The first line contains one integer n (1 ≤ n ≤ 100). The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).
If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
null
null
[{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}]
1,100
["implementation", "sortings"]
88
[{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 3\r\n", "output": "YES\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "NO\r\n"}, {"input": "35\r\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 10 10 6 7 8 9\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 1 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n10 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3 3 3\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 4 6 7\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 5 4 5 8 3 1 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n8 2 2 4 1 4 10 9\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 8 10 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 3 4 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 1 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 3 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7 7 8 9 10 11 12 19\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 5 6 7\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 2 2 3 3 3 3\r\n", "output": "YES\r\n"}, {"input": "51\r\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 3 3 2 3 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n5 3 3 6\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 2 2\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 3 3 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7 19 19 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 6\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 2 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n6 6 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 1 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3 3 1 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n4 5 6 4 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2 3 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n100 99 1 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 6 5 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 2 1 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 3 4 5 6 7 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n6 5 3 3 1 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 5 6 8 6\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5 3 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 7 4 5 319 19\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4 4 3 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 3 4 5 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 4 4 5 3 6 7 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 3 4 4 5 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 4 3 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 5 4 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 4 5 6 7 8 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 5 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 4 4 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 4 5 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 3 3\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1 2 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 1 1 1 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2 3 5 6 7 8 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n4 3 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2 4 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 3 3 4 6\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 2 4 5 5 5 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 3 4 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 3 2 3\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4 4 2 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 7 1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 2 2 2\r\n", "output": "NO\r\n"}, {"input": "1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 1 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n8 6\r\n", "output": "YES\r\n"}, {"input": "7\r\n6 7 6 7 3 1 9 4 6 10 8 2 5 7\r\n", "output": "NO\r\n"}, {"input": "2\r\n3 9 2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n3 3 3 3\r\n", "output": "NO\r\n"}]
false
stdio
null
true
671/A
671
A
Python 3
TESTS
40
888
5,222,400
17866913
from math import * ax, ay, bx, by, cx, cy = [int(t) for t in input().split()] n = int(input()) dist = 0 maxv = [[-99999999, -99999999], [-99999999, -99999999]] index = [[0,0], [0,0]] def update(d, idx, p): global maxv, index if d > maxv[p][0]: maxv[p][1] = maxv[p][0] index[p][1] = index[p][0] maxv[p][0] = d index[p][0] = idx else: if d > maxv[p][1]: maxv[p][1] = d index[p][1] = idx for i in range(n): x, y = [int(t) for t in input().split()] bottle_recycle = sqrt((cx - x) ** 2 + (cy - y) ** 2) dist += bottle_recycle * 2 dista = bottle_recycle - sqrt((ax - x) ** 2 + (ay - y) ** 2) distb = bottle_recycle - sqrt((bx - x) ** 2 + (by - y) ** 2) update(dista, i, 0) update(distb, i, 1) maxx, maxy = maxv[0][0], maxv[1][0] if(index[0][0] == index[1][0]): if(maxv[0][0] + maxv[1][1] > maxv[0][1] + maxv[1][0]): maxy = maxv[1][1] else: maxx = maxv[0][1] if(maxx > 0 and maxy > 0): print(dist - maxx - maxy) else: print(dist - max(maxx, maxy))
148
826
13,107,200
151388689
import math class PoV: def __init__(self,x,y): self.x = x self.y = y def __sub__(self,o): return PoV(self.x-o.x,self.y-o.y) def __abs__(self): return math.sqrt(self.x*self.x+self.y*self.y) def minDet(a,b): n = len(a)-1 pre = [0]*(n+1) suf = [0]*(n+2) pre[0] = float('inf') suf[n+1] = float('inf') for i in range(1,n+1): pre[i]=min(a[i],pre[i-1]) for i in range(n,-1,-1): suf[i]=min(a[i],suf[i+1]) ans = suf[0] #min det by a for i in range(1,n+1): ans = min(ans,b[i]+min(0,min(pre[i-1],suf[i+1]))) #b pick i! return ans ax,ay,bx,by,tx,ty=map(int,input().split()) a = PoV(ax,ay) b = PoV(bx,by) t = PoV(tx,ty) n = int(input()) pre = [0]*(n+2) #a's amount of detour if pick i first! (prefix-min) suf = [0]*(n+2) bdt = [0]*(n+1) #b's amount of detour if pick i first! tot = 0 for i in range(1,n+1): x,y = map(int,input().split()) p = PoV(x,y) pt = abs(p-t) tot+= pt*2 pre[i] = suf[i] = abs(p-a)-pt bdt[i] = abs(p-b)-pt pre[0]=suf[n+1]=float('inf') for i in range(1,n+1): pre[i]=min(pre[i-1],pre[i]) for i in range(n,0,-1): suf[i]=min(suf[i+1],suf[i]) ans = suf[1] for i in range(1,n+1): ans = min(ans,bdt[i]+min(0,min(pre[i-1],suf[i+1]))) print(tot+ans)
Codeforces Round 352 (Div. 1)
CF
2,016
2
256
Recycling Bottles
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can carry only one bottle at once each. For both Adil and Bera the process looks as follows: 1. Choose to stop or to continue to collect bottles. 2. If the choice was to continue then choose some bottle and walk towards it. 3. Pick this bottle and walk to the recycling bin. 4. Go to step 1. Adil and Bera may move independently. They are allowed to pick bottles simultaneously, all bottles may be picked by any of the two, it's allowed that one of them stays still while the other one continues to pick bottles. They want to organize the process such that the total distance they walk (the sum of distance walked by Adil and distance walked by Bera) is minimum possible. Of course, at the end all bottles should lie in the recycling bin.
First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively. The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground. Then follow n lines, each of them contains two integers xi and yi (0 ≤ xi, yi ≤ 109) — position of the i-th bottle. It's guaranteed that positions of Adil, Bera, recycling bin and all bottles are distinct.
Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if $$\frac{|a-b|}{\max(1,b)} \leq 10^{-6}$$.
null
Consider the first sample. Adil will use the following path: $$(3,1)\rightarrow(2,1)\rightarrow(0,0)\rightarrow(1,1)\rightarrow(0,0)$$. Bera will use the following path: $$(1,2)\rightarrow(2,3)\rightarrow(0,0)$$. Adil's path will be $$1 + \sqrt{5} + \sqrt{2} + \sqrt{2}$$ units long, while Bera's path will be $$\sqrt{2} + \sqrt{13}$$ units long.
[{"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "output": "11.084259940083"}, {"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "output": "33.121375178000"}]
1,800
["dp", "geometry", "greedy", "implementation"]
148
[{"input": "3 1 1 2 0 0\r\n3\r\n1 1\r\n2 1\r\n2 3\r\n", "output": "11.084259940083\r\n"}, {"input": "5 0 4 2 2 0\r\n5\r\n5 2\r\n3 0\r\n5 5\r\n3 5\r\n3 3\r\n", "output": "33.121375178000\r\n"}, {"input": "107 50 116 37 104 118\r\n12\r\n16 78\r\n95 113\r\n112 84\r\n5 88\r\n54 85\r\n112 80\r\n19 98\r\n25 14\r\n48 76\r\n95 70\r\n77 94\r\n38 32\r\n", "output": "1576.895607473206\r\n"}, {"input": "446799 395535 281981 494983 755701 57488\r\n20\r\n770380 454998\r\n147325 211816\r\n818964 223521\r\n408463 253399\r\n49120 253709\r\n478114 283776\r\n909705 631953\r\n303154 889956\r\n126532 258846\r\n597028 708070\r\n147061 192478\r\n39515 879057\r\n911737 878857\r\n26966 701951\r\n616099 715301\r\n998385 735514\r\n277633 346417\r\n642301 188888\r\n617247 256225\r\n668067 352814\r\n", "output": "22423982.398765542000\r\n"}, {"input": "0 0 214409724 980408402 975413181 157577991\r\n4\r\n390610378 473484159\r\n920351980 785918656\r\n706277914 753279807\r\n159291646 213569247\r\n", "output": "4854671149.842136400000\r\n"}, {"input": "214409724 980408402 0 0 975413181 157577991\r\n4\r\n390610378 473484159\r\n920351980 785918656\r\n706277914 753279807\r\n159291646 213569247\r\n", "output": "4854671149.842136400000\r\n"}, {"input": "383677880 965754167 658001115 941943959 0 0\r\n10\r\n9412 5230\r\n4896 7518\r\n3635 6202\r\n2365 1525\r\n241 1398\r\n7004 5166\r\n1294 9162\r\n3898 6706\r\n6135 8199\r\n4195 4410\r\n", "output": "1039303750.884648200000\r\n"}, {"input": "825153337 326797826 774256604 103765336 0 0\r\n21\r\n6537 9734\r\n3998 8433\r\n560 7638\r\n1937 2557\r\n3487 244\r\n8299 4519\r\n73 9952\r\n2858 3719\r\n9267 5675\r\n9584 7636\r\n9234 1049\r\n7415 6018\r\n7653 9345\r\n7752 9628\r\n7476 8917\r\n7207 2352\r\n2602 4612\r\n1971 3307\r\n5530 3694\r\n2393 8573\r\n7506 9810\r\n", "output": "781520533.726828810000\r\n"}, {"input": "214409724 980408402 975413181 157577991 0 0\r\n4\r\n3721 6099\r\n5225 4247\r\n940 340\r\n8612 7341\r\n", "output": "988090959.937532070000\r\n"}, {"input": "235810013 344493922 0 0 975204641 211157253\r\n18\r\n977686151 621301932\r\n408277582 166435161\r\n595105725 194278844\r\n967498841 705149530\r\n551735395 659209387\r\n492239556 317614998\r\n741520864 843275770\r\n585383143 903832112\r\n272581169 285871890\r\n339100580 134101148\r\n920610054 824829107\r\n657996186 852771589\r\n948065129 573712142\r\n615254670 698346010\r\n365251531 883011553\r\n304877602 625498272\r\n418150850 280945187\r\n731399551 643859052\r\n", "output": "20756961047.556908000000\r\n"}, {"input": "0 0 1 1 2 2\r\n1\r\n1 3\r\n", "output": "3.414213562373\r\n"}, {"input": "10000 1000 151 121 10 10\r\n2\r\n1 1\r\n2 2\r\n", "output": "227.449066182313\r\n"}, {"input": "5 5 10 10 15 15\r\n2\r\n1 1\r\n11 11\r\n", "output": "32.526911934581\r\n"}, {"input": "1000000 1000000 1 1 0 0\r\n1\r\n2 2\r\n", "output": "4.242640687119\r\n"}, {"input": "100 0 0 1 0 0\r\n2\r\n1 1\r\n1 2\r\n", "output": "6.478708664619\r\n"}, {"input": "0 0 1000000000 1000000000 1 1\r\n2\r\n0 1\r\n1 0\r\n", "output": "4.000000000000\r\n"}, {"input": "1000 1000 0 0 1 1\r\n1\r\n2 2\r\n", "output": "4.242640687119\r\n"}, {"input": "1 0 1000000 0 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "7.892922226992\r\n"}, {"input": "3 0 100 100 0 0\r\n2\r\n1 0\r\n2 0\r\n", "output": "5.000000000000\r\n"}, {"input": "0 100 0 101 0 0\r\n1\r\n0 99\r\n", "output": "100.000000000000\r\n"}, {"input": "1000 1000 3 3 0 0\r\n2\r\n1 0\r\n0 1\r\n", "output": "6.605551275464\r\n"}, {"input": "0 5 0 6 0 7\r\n1\r\n0 100\r\n", "output": "187.000000000000\r\n"}, {"input": "1 1 1000000 1000000 0 0\r\n2\r\n1 2\r\n2 1\r\n", "output": "7.708203932499\r\n"}, {"input": "1 0 10000000 1000000 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "7.892922226992\r\n"}, {"input": "2 2 10 2 6 5\r\n2\r\n6 2\r\n5 5\r\n", "output": "9.000000000000\r\n"}, {"input": "100000001 100000001 100000000 100000000 1 1\r\n1\r\n1 0\r\n", "output": "141421356.530202720000\r\n"}, {"input": "1000 1000 1001 1001 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "1417.041989497841\r\n"}, {"input": "1000000000 1000000000 999999999 999999999 1 1\r\n4\r\n1 2\r\n1 3\r\n2 2\r\n2 3\r\n", "output": "1414213568.487842800000\r\n"}, {"input": "0 100 1 1 1 0\r\n2\r\n2 1\r\n0 1\r\n", "output": "5.242640687119\r\n"}, {"input": "0 100 0 1 0 0\r\n5\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n0 6\r\n", "output": "39.000000000000\r\n"}, {"input": "100 0 0 100 0 0\r\n2\r\n0 1\r\n1 0\r\n", "output": "102.000000000000\r\n"}, {"input": "0 0 1000000 1000000 0 1\r\n2\r\n1 1\r\n2 2\r\n", "output": "6.886349517373\r\n"}, {"input": "0 0 1000 1000 1 0\r\n2\r\n1 1\r\n1 2\r\n", "output": "6.236067977500\r\n"}, {"input": "1 0 100000 100000 0 0\r\n1\r\n2 0\r\n", "output": "3.000000000000\r\n"}, {"input": "5 5 5 4 4 5\r\n2\r\n3 4\r\n3 5\r\n", "output": "5.414213562373\r\n"}, {"input": "10000 10000 9000 9000 0 0\r\n3\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "12736.407342732093\r\n"}, {"input": "1 1 1000 1000 0 0\r\n3\r\n2 2\r\n3 3\r\n4 4\r\n", "output": "24.041630560343\r\n"}, {"input": "7 0 8 0 0 0\r\n2\r\n1 0\r\n1 1\r\n", "output": "9.496976092671\r\n"}, {"input": "1 3 3 3 2 1\r\n2\r\n2 3\r\n3 1\r\n", "output": "5.000000000000\r\n"}, {"input": "1 2 3 4 5 6\r\n1\r\n1 1\r\n", "output": "7.403124237433\r\n"}, {"input": "1000000000 1000000000 0 0 1 1\r\n5\r\n2 2\r\n2 3\r\n2 4\r\n2 5\r\n2 6\r\n", "output": "33.294904485247\r\n"}, {"input": "2 1 1 2 0 0\r\n1\r\n1 1\r\n", "output": "2.414213562373\r\n"}, {"input": "1 0 100000 0 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "7.892922226992\r\n"}, {"input": "0 100 1 100 1 0\r\n2\r\n2 1\r\n0 1\r\n", "output": "103.242640687119\r\n"}, {"input": "0 0 2 0 1 5\r\n2\r\n1 0\r\n1 20\r\n", "output": "36.000000000000\r\n"}, {"input": "1000 1000 999 999 0 0\r\n2\r\n1 0\r\n0 1\r\n", "output": "1415.092419071783\r\n"}, {"input": "5 0 1000 1000 2 0\r\n2\r\n4 0\r\n6 7\r\n", "output": "19.124515496597\r\n"}, {"input": "10000 0 1000000 0 0 0\r\n2\r\n1 1\r\n2 2\r\n", "output": "10003.657054289499\r\n"}, {"input": "0 100 0 101 0 0\r\n2\r\n0 1\r\n0 2\r\n", "output": "102.000000000000\r\n"}, {"input": "0 0 10000 10000 1 0\r\n2\r\n2 0\r\n3 0\r\n", "output": "7.000000000000\r\n"}, {"input": "3 1 1 2 0 0\r\n1\r\n1 1\r\n", "output": "2.414213562373\r\n"}, {"input": "1000 0 0 1000 0 0\r\n2\r\n1 0\r\n0 1\r\n", "output": "1002.000000000000\r\n"}, {"input": "1 1 1000000 1000000 0 0\r\n2\r\n2 1\r\n1 2\r\n", "output": "7.708203932499\r\n"}, {"input": "1000 1000 2000 2000 1 1\r\n3\r\n2 2\r\n1 2\r\n3 3\r\n", "output": "1417.627775935468\r\n"}, {"input": "0 0 1000000000 1000000000 1 1\r\n4\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n", "output": "29.698484809835\r\n"}, {"input": "10000000 1 2 1 1 1\r\n3\r\n1 3\r\n1 4\r\n1 5\r\n", "output": "18.123105625618\r\n"}, {"input": "3 7 5 7 4 4\r\n2\r\n4 6\r\n4 0\r\n", "output": "11.414213562373\r\n"}, {"input": "0 0 3 0 1 5\r\n2\r\n1 0\r\n1 20\r\n", "output": "36.000000000000\r\n"}, {"input": "0 0 0 1 1000 3\r\n2\r\n1000 2\r\n1000 1\r\n", "output": "1004.000000000000\r\n"}, {"input": "1000000000 0 0 1 0 0\r\n2\r\n0 2\r\n0 3\r\n", "output": "9.000000000000\r\n"}, {"input": "0 1000000000 1000000000 0 0 0\r\n1\r\n1 1\r\n", "output": "1000000000.414213500000\r\n"}, {"input": "1000 1000 1000 1001 0 0\r\n2\r\n0 1\r\n1 1\r\n", "output": "1416.213562373095\r\n"}, {"input": "1002 0 1001 0 0 0\r\n1\r\n1000 0\r\n", "output": "1001.000000000000\r\n"}, {"input": "1002 0 1001 0 0 0\r\n2\r\n2 0\r\n1 0\r\n", "output": "1003.000000000000\r\n"}, {"input": "3 0 0 100 0 0\r\n2\r\n1 0\r\n2 0\r\n", "output": "5.000000000000\r\n"}, {"input": "10 10 0 0 0 1\r\n2\r\n1 0\r\n1 1\r\n", "output": "4.414213562373\r\n"}, {"input": "1000 1000 1001 1001 0 0\r\n2\r\n0 1\r\n1 1\r\n", "output": "1416.213562373095\r\n"}, {"input": "0 100 0 200 0 0\r\n2\r\n0 1\r\n0 2\r\n", "output": "102.000000000000\r\n"}, {"input": "100 100 0 0 1 1\r\n1\r\n2 2\r\n", "output": "4.242640687119\r\n"}, {"input": "123123 154345 123123 123123 2 2\r\n3\r\n3 3\r\n4 4\r\n5 5\r\n", "output": "174127.873294312070\r\n"}, {"input": "0 1 0 2 0 0\r\n1\r\n1 0\r\n", "output": "2.414213562373\r\n"}, {"input": "1 2 3 4 1000 1000\r\n1\r\n156 608\r\n", "output": "1553.668251715911\r\n"}, {"input": "0 0 10 0 5 0\r\n3\r\n4 1\r\n5 1\r\n6 1\r\n", "output": "10.365746312737\r\n"}, {"input": "0 0 0 1 1000000000 999999999\r\n1\r\n1000000000 1000000000\r\n", "output": "1414213562.665988200000\r\n"}, {"input": "1231231 2342342 123124 123151 12315 12312\r\n1\r\n354345 234234\r\n", "output": "664238.053973730540\r\n"}, {"input": "0 0 1000000 0 1 1\r\n2\r\n0 1\r\n3 0\r\n", "output": "6.472135955000\r\n"}, {"input": "1000 1000 2000 2000 1 1\r\n1\r\n2 2\r\n", "output": "1412.799348810722\r\n"}, {"input": "10 20 10 0 10 10\r\n2\r\n10 11\r\n10 9\r\n", "output": "12.000000000000\r\n"}, {"input": "1000000000 1 1 1000000000 0 0\r\n1\r\n2 2\r\n", "output": "1000000000.828427200000\r\n"}, {"input": "0 0 1000 1000 1 0\r\n2\r\n2 0\r\n3 0\r\n", "output": "7.000000000000\r\n"}, {"input": "1000 0 100000000 100000000 0 0\r\n2\r\n999 0\r\n1100 0\r\n", "output": "3198.000000000000\r\n"}, {"input": "2 2 1000000000 1000000000 0 0\r\n3\r\n1 1\r\n5 5\r\n100 100\r\n", "output": "296.984848098350\r\n"}, {"input": "2 0 4 0 0 0\r\n1\r\n3 0\r\n", "output": "4.000000000000\r\n"}, {"input": "2 2 1000 1000 0 0\r\n2\r\n1 1\r\n1 2\r\n", "output": "6.064495102246\r\n"}, {"input": "0 0 1000000000 1000000000 0 1\r\n3\r\n1 0\r\n2 0\r\n3 0\r\n", "output": "13.210904837709\r\n"}, {"input": "1 10000 10000 1 0 0\r\n2\r\n1 100\r\n100 1\r\n", "output": "10200.014999625020\r\n"}, {"input": "5 0 6 0 0 0\r\n2\r\n2 0\r\n0 2\r\n", "output": "9.000000000000\r\n"}, {"input": "2 4 1000000000 1000000000 0 0\r\n4\r\n2 3\r\n2 1\r\n3 2\r\n1 2\r\n", "output": "20.760925736391\r\n"}, {"input": "0 100 1 1 0 0\r\n2\r\n0 1\r\n3 1\r\n", "output": "7.162277660168\r\n"}, {"input": "0 0 10 0 8 2\r\n1\r\n6 0\r\n", "output": "6.828427124746\r\n"}, {"input": "0 9 0 8 0 1\r\n1\r\n0 0\r\n", "output": "9.000000000000\r\n"}, {"input": "100 0 0 100 0 0\r\n2\r\n40 0\r\n0 40\r\n", "output": "180.000000000000\r\n"}, {"input": "0 0 0 1 1000 3\r\n2\r\n1000 1\r\n1000 2\r\n", "output": "1004.000000000000\r\n"}, {"input": "1 1 123123 123123 2 2\r\n3\r\n3 3\r\n4 4\r\n5 5\r\n", "output": "18.384776310850\r\n"}, {"input": "999999999 999999999 1000000000 1000000000 1 1\r\n1\r\n1 0\r\n", "output": "1414213561.251774800000\r\n"}, {"input": "3 2 1 1 0 0\r\n1\r\n2 2\r\n", "output": "3.828427124746\r\n"}, {"input": "0 0 1 1 100 100\r\n2\r\n101 101\r\n102 102\r\n", "output": "148.492424049175\r\n"}, {"input": "1 15 4 10 1 1\r\n2\r\n1 10\r\n4 5\r\n", "output": "22.000000000000\r\n"}, {"input": "100 0 0 100 0 0\r\n2\r\n60 0\r\n0 40\r\n", "output": "180.000000000000\r\n"}, {"input": "0 0 0 1000 1 0\r\n4\r\n0 1\r\n0 2\r\n0 3\r\n0 4\r\n", "output": "21.457116088945\r\n"}, {"input": "0 0 100 0 3 0\r\n1\r\n2 0\r\n", "output": "3.000000000000\r\n"}, {"input": "0 0 100 0 98 2\r\n1\r\n98 0\r\n", "output": "4.000000000000\r\n"}, {"input": "1 1 2 2 3 3\r\n1\r\n0 0\r\n", "output": "5.656854249492\r\n"}, {"input": "2 2 1 1 0 0\r\n1\r\n1 2\r\n", "output": "3.236067977500\r\n"}, {"input": "10000000 1 2 1 1 1\r\n3\r\n1 40\r\n1 20\r\n1 5\r\n", "output": "124.012818406262\r\n"}, {"input": "1000 1000 1001 1000 0 0\r\n3\r\n1 1\r\n1 2\r\n1 3\r\n", "output": "1421.848684511914\r\n"}, {"input": "10000 10000 9999 9999 0 0\r\n3\r\n0 1\r\n0 2\r\n0 3\r\n", "output": "14147.600248963827\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(output_path) as f: correct = f.read().strip() with open(submission_path) as f: submission = f.read().strip() try: correct_val = float(correct) submission_val = float(submission) except: print(0) return delta = abs(correct_val - submission_val) denominator = max(1.0, abs(correct_val)) if delta <= 1e-6 * denominator: print(1) else: print(0) if __name__ == "__main__": main()
true
997/A
997
A
Python 3
TESTS
15
155
3,891,200
45398240
# 00101101001 n, x, y = map(int, input().split()) line = input() temp = line.split('1') cnt = 0 #print(temp) for i in temp: if len(i) > 0: cnt += 1 print(min(y*cnt, y+x*(cnt-1)))
115
77
2,764,800
205185457
n,x,y = map(int,input().split()) s = input() s += '1' count = 0 cnt = 0 for i in range(n + 1): if s[i] == '1': if count: cnt += 1 count = 0 else: count += 1 if cnt == 0: print(0) else: print(min((cnt - 1) * x + y,cnt * y))
Codeforces Round 493 (Div. 1)
CF
2,018
1
256
Convert to Ones
You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones. Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$. You can apply the following operations any number of times: - Choose some substring of string $$$a$$$ (for example, you can choose entire string) and reverse it, paying $$$x$$$ coins for it (for example, «0101101» $$$\to$$$ «0111001»); - Choose some substring of string $$$a$$$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $$$y$$$ coins for it (for example, «0101101» $$$\to$$$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones?
The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $$$a$$$ of length $$$n$$$, consisting of zeros and ones.
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations.
null
In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «10000» $$$\to$$$ «11111». The total cost of operations is $$$1 + 10 = 11$$$. In the second sample, at first you need to invert substring $$$[1 \dots 1]$$$, and then you need to invert substring $$$[3 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «11000» $$$\to$$$ «11111». The overall cost is $$$1 + 1 = 2$$$. In the third example, string already consists only of ones, so the answer is $$$0$$$.
[{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}]
1,500
["brute force", "greedy", "implementation", "math"]
115
[{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 261764879\r\n0\r\n", "output": "261764879\r\n"}, {"input": "1 491511050 399084767\r\n1\r\n", "output": "0\r\n"}, {"input": "2 163093925 214567542\r\n00\r\n", "output": "214567542\r\n"}, {"input": "2 340351106 646854722\r\n10\r\n", "output": "646854722\r\n"}, {"input": "2 222640995 489207317\r\n01\r\n", "output": "489207317\r\n"}, {"input": "2 399898176 552898277\r\n11\r\n", "output": "0\r\n"}, {"input": "2 690218164 577155357\r\n00\r\n", "output": "577155357\r\n"}, {"input": "2 827538051 754412538\r\n10\r\n", "output": "754412538\r\n"}, {"input": "2 636702427 259825230\r\n01\r\n", "output": "259825230\r\n"}, {"input": "2 108926899 102177825\r\n11\r\n", "output": "0\r\n"}, {"input": "3 368381052 440077270\r\n000\r\n", "output": "440077270\r\n"}, {"input": "3 505700940 617334451\r\n100\r\n", "output": "617334451\r\n"}, {"input": "3 499624340 643020827\r\n010\r\n", "output": "1142645167\r\n"}, {"input": "3 75308005 971848814\r\n110\r\n", "output": "971848814\r\n"}, {"input": "3 212627893 854138703\r\n001\r\n", "output": "854138703\r\n"}, {"input": "3 31395883 981351561\r\n101\r\n", "output": "981351561\r\n"}, {"input": "3 118671447 913685773\r\n011\r\n", "output": "913685773\r\n"}, {"input": "3 255991335 385910245\r\n111\r\n", "output": "0\r\n"}, {"input": "3 688278514 268200134\r\n000\r\n", "output": "268200134\r\n"}, {"input": "3 825598402 445457315\r\n100\r\n", "output": "445457315\r\n"}, {"input": "3 300751942 45676507\r\n010\r\n", "output": "91353014\r\n"}, {"input": "3 517900980 438071829\r\n110\r\n", "output": "438071829\r\n"}, {"input": "3 400190869 280424424\r\n001\r\n", "output": "280424424\r\n"}, {"input": "3 577448050 344115384\r\n101\r\n", "output": "344115384\r\n"}, {"input": "3 481435271 459737939\r\n011\r\n", "output": "459737939\r\n"}, {"input": "3 931962412 913722450\r\n111\r\n", "output": "0\r\n"}, {"input": "4 522194562 717060616\r\n0000\r\n", "output": "717060616\r\n"}, {"input": "4 659514449 894317797\r\n1000\r\n", "output": "894317797\r\n"}, {"input": "4 71574977 796834337\r\n0100\r\n", "output": "868409314\r\n"}, {"input": "4 248832158 934154224\r\n1100\r\n", "output": "934154224\r\n"}, {"input": "4 71474110 131122047\r\n0010\r\n", "output": "202596157\r\n"}, {"input": "4 308379228 503761290\r\n1010\r\n", "output": "812140518\r\n"}, {"input": "4 272484957 485636409\r\n0110\r\n", "output": "758121366\r\n"}, {"input": "4 662893590 704772137\r\n1110\r\n", "output": "704772137\r\n"}, {"input": "4 545183479 547124732\r\n0001\r\n", "output": "547124732\r\n"}, {"input": "4 684444619 722440661\r\n1001\r\n", "output": "722440661\r\n"}, {"input": "4 477963686 636258459\r\n0101\r\n", "output": "1114222145\r\n"}, {"input": "4 360253575 773578347\r\n1101\r\n", "output": "773578347\r\n"}, {"input": "4 832478048 910898234\r\n0011\r\n", "output": "910898234\r\n"}, {"input": "4 343185412 714767937\r\n1011\r\n", "output": "714767937\r\n"}, {"input": "4 480505300 892025118\r\n0111\r\n", "output": "892025118\r\n"}, {"input": "4 322857895 774315007\r\n1111\r\n", "output": "0\r\n"}, {"input": "4 386548854 246539479\r\n0000\r\n", "output": "246539479\r\n"}, {"input": "4 523868742 128829368\r\n1000\r\n", "output": "128829368\r\n"}, {"input": "4 956155921 11119257\r\n0100\r\n", "output": "22238514\r\n"}, {"input": "4 188376438 93475808\r\n1100\r\n", "output": "93475808\r\n"}, {"input": "4 754947032 158668188\r\n0010\r\n", "output": "317336376\r\n"}, {"input": "4 927391856 637236921\r\n1010\r\n", "output": "1274473842\r\n"}, {"input": "4 359679035 109461393\r\n0110\r\n", "output": "218922786\r\n"}, {"input": "4 991751283 202031630\r\n1110\r\n", "output": "202031630\r\n"}, {"input": "4 339351517 169008463\r\n0001\r\n", "output": "169008463\r\n"}, {"input": "4 771638697 346265644\r\n1001\r\n", "output": "346265644\r\n"}, {"input": "4 908958584 523522825\r\n0101\r\n", "output": "1047045650\r\n"}, {"input": "4 677682252 405812714\r\n1101\r\n", "output": "405812714\r\n"}, {"input": "4 815002139 288102603\r\n0011\r\n", "output": "288102603\r\n"}, {"input": "4 952322026 760327076\r\n1011\r\n", "output": "760327076\r\n"}, {"input": "4 663334158 312481698\r\n0111\r\n", "output": "312481698\r\n"}, {"input": "4 840591339 154834293\r\n1111\r\n", "output": "0\r\n"}, {"input": "14 3 11\r\n10110100011001\r\n", "output": "20\r\n"}, {"input": "19 1 1\r\n1010101010101010101\r\n", "output": "9\r\n"}, {"input": "1 10 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 100 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 1000 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 10 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "7 3 2\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 10\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 3 2\r\n1\r\n", "output": "0\r\n"}, {"input": "2 10 1\r\n11\r\n", "output": "0\r\n"}, {"input": "4 148823922 302792601\r\n1010\r\n", "output": "451616523\r\n"}, {"input": "1 2 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n00011\r\n", "output": "3\r\n"}, {"input": "1 5 0\r\n1\r\n", "output": "0\r\n"}, {"input": "7 2 3\r\n1001001\r\n", "output": "5\r\n"}, {"input": "10 1 1000000000\r\n1111010111\r\n", "output": "1000000001\r\n"}, {"input": "25 999999998 999999999\r\n1011001110101010100111001\r\n", "output": "7999999985\r\n"}, {"input": "2 0 1\r\n00\r\n", "output": "1\r\n"}, {"input": "2 1 100\r\n10\r\n", "output": "100\r\n"}, {"input": "7 20 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "0\r\n"}, {"input": "3 1 10\r\n010\r\n", "output": "11\r\n"}, {"input": "2 1 0\r\n11\r\n", "output": "0\r\n"}, {"input": "7 100 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 1000\r\n10101\r\n", "output": "1001\r\n"}, {"input": "5 2 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "1 1000 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 799543940 488239239\r\n1\r\n", "output": "0\r\n"}, {"input": "6 1 1000\r\n010101\r\n", "output": "1002\r\n"}, {"input": "5 11 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n10101\r\n", "output": "5\r\n"}, {"input": "3 10 1\r\n111\r\n", "output": "0\r\n"}, {"input": "7 9 10\r\n1001011\r\n", "output": "19\r\n"}, {"input": "5 5 6\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 1000000000 0\r\n1\r\n", "output": "0\r\n"}, {"input": "4 0 1\r\n0101\r\n", "output": "1\r\n"}, {"input": "8 2 3\r\n10101010\r\n", "output": "9\r\n"}, {"input": "6 3 100\r\n010101\r\n", "output": "106\r\n"}, {"input": "3 3 2\r\n111\r\n", "output": "0\r\n"}, {"input": "1 20 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n01\r\n", "output": "2\r\n"}]
false
stdio
null
true
789/B
789
B
Python 3
PRETESTS
13
93
12,902,400
25903791
from sys import stdin, stdout b, q, l, m = map(int, stdin.readline().rstrip().split()) badInts = set([int(a) for a in stdin.readline().rstrip().split()]) totalInts = 0 if q==0: if 0 not in badInts: totalInts = -1 elif b in badInts: totalInts = 0 else: totalInts = 1 elif b==0: if 0 not in badInts: totalInts = -1 else: totalInts = 0 elif q==1: if b in badInts: totalInts=0 else: totalInts=-1 elif q==-1: if b in badInts and -b in badInts: totalInts=0 else: totalInts = -1 else: while b<=l and -b<=l: if b not in badInts: totalInts+=1 b*=q if totalInts<0: print("inf") else: print(totalInts)
116
93
15,667,200
25931548
B1, Q, L, M = map(int, input().split()) As = set(map(int, input().split())) Bs = [] tmp = B1 cnt = 0 while abs(tmp) <= L and cnt < 100: if tmp not in As: Bs.append(tmp) tmp *= Q cnt += 1 if 32 < len(Bs): print('inf') else: print(len(Bs))
Codeforces Round 407 (Div. 2)
CF
2,017
1
256
Masha and geometric depression
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board.
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
null
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123.
[{"input": "3 2 30 4\n6 14 25 48", "output": "3"}, {"input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0"}, {"input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf"}]
1,700
["brute force", "implementation", "math"]
116
[{"input": "3 2 30 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "123 1 2143435 4\r\n123 11 -5453 141245\r\n", "output": "0"}, {"input": "123 1 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "3 2 25 2\r\n379195692 -69874783\r\n", "output": "4"}, {"input": "3 2 30 3\r\n-691070108 -934106649 -220744807\r\n", "output": "4"}, {"input": "3 3 104 17\r\n9 -73896485 -290898562 5254410 409659728 -916522518 -435516126 94354167 262981034 -375897180 -80186684 -173062070 -288705544 -699097793 -11447747 320434295 503414250\r\n", "output": "3"}, {"input": "-1000000000 -1000000000 1 1\r\n232512888\r\n", "output": "0"}, {"input": "11 0 228 5\r\n-1 0 1 5 -11245\r\n", "output": "1"}, {"input": "11 0 228 5\r\n-1 -17 1 5 -11245\r\n", "output": "inf"}, {"input": "0 0 2143435 5\r\n-1 -153 1 5 -11245\r\n", "output": "inf"}, {"input": "123 0 2143435 4\r\n5433 0 123 -645\r\n", "output": "0"}, {"input": "123 -1 2143435 5\r\n-123 0 12 5 -11245\r\n", "output": "inf"}, {"input": "123 0 21 4\r\n543453 -123 6 1424\r\n", "output": "0"}, {"input": "3 2 115 16\r\n24 48 12 96 3 720031148 -367712651 -838596957 558177735 -963046495 -313322487 -465018432 -618984128 -607173835 144854086 178041956\r\n", "output": "1"}, {"input": "-3 0 92055 36\r\n-92974174 -486557474 -663622151 695596393 177960746 -563227474 -364263320 -676254242 -614140218 71456762 -764104225 705056581 -106398436 332755134 -199942822 -732751692 658942664 677739866 886535704 183687802 -784248291 -22550621 -938674499 637055091 -704750213 780395802 778342470 -999059668 -794361783 796469192 215667969 354336794 -60195289 -885080928 -290279020 201221317\r\n", "output": "inf"}, {"input": "0 -3 2143435 5\r\n-1 0 1 5 -11245\r\n", "output": "0"}, {"input": "123 -1 2143435 5\r\n-123 0 123 -5453 141245\r\n", "output": "0"}, {"input": "123 0 2143435 4\r\n5433 0 -123 -645\r\n", "output": "1"}, {"input": "11 0 2 5\r\n-1 0 1 5 -11245\r\n", "output": "0"}, {"input": "2 2 4 1\r\n2\r\n", "output": "1"}, {"input": "1 -2 1000000000 1\r\n0\r\n", "output": "30"}, {"input": "0 8 10 1\r\n5\r\n", "output": "inf"}, {"input": "-1000 0 10 1\r\n5\r\n", "output": "0"}, {"input": "0 2 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "0 8 5 1\r\n9\r\n", "output": "inf"}, {"input": "-10 1 5 1\r\n100\r\n", "output": "0"}, {"input": "123 -1 2143435 4\r\n54343 -13 6 123\r\n", "output": "inf"}, {"input": "-5 -1 10 1\r\n-5\r\n", "output": "inf"}, {"input": "2 0 1 1\r\n2\r\n", "output": "0"}, {"input": "0 5 8 1\r\n10\r\n", "output": "inf"}, {"input": "0 5 100 2\r\n34 56\r\n", "output": "inf"}, {"input": "15 -1 15 4\r\n15 -15 1 2\r\n", "output": "0"}, {"input": "10 -1 2 1\r\n1\r\n", "output": "0"}, {"input": "2 0 2 1\r\n2\r\n", "output": "inf"}, {"input": "4 0 4 1\r\n0\r\n", "output": "1"}, {"input": "10 10 10 1\r\n123\r\n", "output": "1"}, {"input": "2 2 4 1\r\n3\r\n", "output": "2"}, {"input": "0 1 1 1\r\n0\r\n", "output": "0"}, {"input": "3 2 30 1\r\n3\r\n", "output": "3"}, {"input": "1000000000 100000 1000000000 4\r\n5433 13 6 0\r\n", "output": "1"}, {"input": "-2 0 1 1\r\n1\r\n", "output": "0"}, {"input": "2 -1 10 1\r\n2\r\n", "output": "inf"}, {"input": "1 -1 2 1\r\n1\r\n", "output": "inf"}, {"input": "0 10 10 1\r\n2\r\n", "output": "inf"}, {"input": "0 35 2 1\r\n3\r\n", "output": "inf"}, {"input": "3 1 3 1\r\n5\r\n", "output": "inf"}, {"input": "3 2 3 4\r\n6 14 25 48\r\n", "output": "1"}, {"input": "0 69 12 1\r\n1\r\n", "output": "inf"}, {"input": "100 0 100000 1\r\n100\r\n", "output": "inf"}, {"input": "0 4 1000 3\r\n5 6 7\r\n", "output": "inf"}, {"input": "0 2 100 1\r\n5\r\n", "output": "inf"}, {"input": "3 2 24 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "0 4 1 1\r\n2\r\n", "output": "inf"}, {"input": "1 5 10000 1\r\n125\r\n", "output": "5"}, {"input": "2 -1 1 1\r\n1\r\n", "output": "0"}, {"input": "0 3 100 1\r\n5\r\n", "output": "inf"}, {"input": "0 3 3 1\r\n1\r\n", "output": "inf"}, {"input": "0 2 5 1\r\n1\r\n", "output": "inf"}, {"input": "5 -1 100 1\r\n5\r\n", "output": "inf"}, {"input": "-20 0 10 1\r\n0\r\n", "output": "0"}, {"input": "3 0 1 1\r\n3\r\n", "output": "0"}, {"input": "2 -1 3 1\r\n2\r\n", "output": "inf"}, {"input": "1 1 1000000000 1\r\n100\r\n", "output": "inf"}, {"input": "5 -1 3 1\r\n0\r\n", "output": "0"}, {"input": "0 5 10 1\r\n2\r\n", "output": "inf"}, {"input": "123 0 125 1\r\n123\r\n", "output": "inf"}, {"input": "2 -1 100 1\r\n2\r\n", "output": "inf"}, {"input": "5 2 100 1\r\n5\r\n", "output": "4"}, {"input": "-5 0 1 1\r\n1\r\n", "output": "0"}, {"input": "-3 0 1 1\r\n-3\r\n", "output": "0"}, {"input": "2 -2 10 1\r\n1\r\n", "output": "3"}, {"input": "0 2 30 4\r\n6 14 25 48\r\n", "output": "inf"}, {"input": "1 -1 1 1\r\n1\r\n", "output": "inf"}, {"input": "2 -1 6 1\r\n2\r\n", "output": "inf"}, {"input": "-3 1 100 1\r\n-3\r\n", "output": "0"}, {"input": "1 0 2 1\r\n1\r\n", "output": "inf"}, {"input": "1000000000 999999998 1000000000 1\r\n0\r\n", "output": "1"}, {"input": "1 0 2143435 4\r\n1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "-1000 0 100 1\r\n-1000\r\n", "output": "0"}, {"input": "100 10 2 1\r\n100\r\n", "output": "0"}, {"input": "-3 1 100 1\r\n3\r\n", "output": "inf"}, {"input": "123 -1 10000 1\r\n123\r\n", "output": "inf"}, {"input": "1 -1 2143435 4\r\n1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "5 1 5 5\r\n1 2 3 4 0\r\n", "output": "inf"}, {"input": "-100 -1 1 1\r\n1\r\n", "output": "0"}, {"input": "10 -1 3 2\r\n10 8\r\n", "output": "0"}, {"input": "-10 0 5 1\r\n0\r\n", "output": "0"}, {"input": "3 0 3 1\r\n0\r\n", "output": "1"}, {"input": "2 0 2 1\r\n-1\r\n", "output": "inf"}, {"input": "5 0 20 1\r\n5\r\n", "output": "inf"}, {"input": "-4 1 1 1\r\n0\r\n", "output": "0"}, {"input": "11 0 1111 1\r\n11\r\n", "output": "inf"}, {"input": "2 0 3 1\r\n2\r\n", "output": "inf"}, {"input": "-1 -1 2143435 4\r\n-1 -123 -5453 141245\r\n", "output": "inf"}, {"input": "-100 0 50 1\r\n0\r\n", "output": "0"}, {"input": "5 1 2 1\r\n2\r\n", "output": "0"}, {"input": "3 0 3 1\r\n4\r\n", "output": "inf"}, {"input": "0 23 3 1\r\n3\r\n", "output": "inf"}, {"input": "-1000 0 100 1\r\n2\r\n", "output": "0"}, {"input": "1 -1 10 1\r\n1\r\n", "output": "inf"}]
false
stdio
null
true
997/A
997
A
Python 3
TESTS
15
93
1,024,000
230901965
n, x, y = map(int, input().split()) s = input() zero = 0 for i, c in enumerate(s): if c == '0' and (i == 0 or s[i-1] == '1'): zero += 1 print(min(y*zero, x*(zero-1)+y))
115
77
2,969,600
168498916
def rev(): ret=0 i=0 while i<n and s[i]=='1':i+=1 while i<n: if s[i]=='1': while i<n and s[i]=='1':i+=1 if i<n:ret+=x else:i+=1 return ret+y def change(): ret1,ret2=0,0 cnt=0 for i in s: if i=='1':cnt+=1 ret1=(cnt*y)+(n*y) i=0 while i<n: if s[i]=='0': while i<n and s[i]=='0':i+=1 ret2+=y else:i+=1 return min(ret1,ret2) n,x,y=[int(a) for a in input().split()] s=input() print(min(rev(),change()))
Codeforces Round 493 (Div. 1)
CF
2,018
1
256
Convert to Ones
You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones. Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$. You can apply the following operations any number of times: - Choose some substring of string $$$a$$$ (for example, you can choose entire string) and reverse it, paying $$$x$$$ coins for it (for example, «0101101» $$$\to$$$ «0111001»); - Choose some substring of string $$$a$$$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $$$y$$$ coins for it (for example, «0101101» $$$\to$$$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones?
The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $$$a$$$ of length $$$n$$$, consisting of zeros and ones.
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations.
null
In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «10000» $$$\to$$$ «11111». The total cost of operations is $$$1 + 10 = 11$$$. In the second sample, at first you need to invert substring $$$[1 \dots 1]$$$, and then you need to invert substring $$$[3 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «11000» $$$\to$$$ «11111». The overall cost is $$$1 + 1 = 2$$$. In the third example, string already consists only of ones, so the answer is $$$0$$$.
[{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}]
1,500
["brute force", "greedy", "implementation", "math"]
115
[{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 261764879\r\n0\r\n", "output": "261764879\r\n"}, {"input": "1 491511050 399084767\r\n1\r\n", "output": "0\r\n"}, {"input": "2 163093925 214567542\r\n00\r\n", "output": "214567542\r\n"}, {"input": "2 340351106 646854722\r\n10\r\n", "output": "646854722\r\n"}, {"input": "2 222640995 489207317\r\n01\r\n", "output": "489207317\r\n"}, {"input": "2 399898176 552898277\r\n11\r\n", "output": "0\r\n"}, {"input": "2 690218164 577155357\r\n00\r\n", "output": "577155357\r\n"}, {"input": "2 827538051 754412538\r\n10\r\n", "output": "754412538\r\n"}, {"input": "2 636702427 259825230\r\n01\r\n", "output": "259825230\r\n"}, {"input": "2 108926899 102177825\r\n11\r\n", "output": "0\r\n"}, {"input": "3 368381052 440077270\r\n000\r\n", "output": "440077270\r\n"}, {"input": "3 505700940 617334451\r\n100\r\n", "output": "617334451\r\n"}, {"input": "3 499624340 643020827\r\n010\r\n", "output": "1142645167\r\n"}, {"input": "3 75308005 971848814\r\n110\r\n", "output": "971848814\r\n"}, {"input": "3 212627893 854138703\r\n001\r\n", "output": "854138703\r\n"}, {"input": "3 31395883 981351561\r\n101\r\n", "output": "981351561\r\n"}, {"input": "3 118671447 913685773\r\n011\r\n", "output": "913685773\r\n"}, {"input": "3 255991335 385910245\r\n111\r\n", "output": "0\r\n"}, {"input": "3 688278514 268200134\r\n000\r\n", "output": "268200134\r\n"}, {"input": "3 825598402 445457315\r\n100\r\n", "output": "445457315\r\n"}, {"input": "3 300751942 45676507\r\n010\r\n", "output": "91353014\r\n"}, {"input": "3 517900980 438071829\r\n110\r\n", "output": "438071829\r\n"}, {"input": "3 400190869 280424424\r\n001\r\n", "output": "280424424\r\n"}, {"input": "3 577448050 344115384\r\n101\r\n", "output": "344115384\r\n"}, {"input": "3 481435271 459737939\r\n011\r\n", "output": "459737939\r\n"}, {"input": "3 931962412 913722450\r\n111\r\n", "output": "0\r\n"}, {"input": "4 522194562 717060616\r\n0000\r\n", "output": "717060616\r\n"}, {"input": "4 659514449 894317797\r\n1000\r\n", "output": "894317797\r\n"}, {"input": "4 71574977 796834337\r\n0100\r\n", "output": "868409314\r\n"}, {"input": "4 248832158 934154224\r\n1100\r\n", "output": "934154224\r\n"}, {"input": "4 71474110 131122047\r\n0010\r\n", "output": "202596157\r\n"}, {"input": "4 308379228 503761290\r\n1010\r\n", "output": "812140518\r\n"}, {"input": "4 272484957 485636409\r\n0110\r\n", "output": "758121366\r\n"}, {"input": "4 662893590 704772137\r\n1110\r\n", "output": "704772137\r\n"}, {"input": "4 545183479 547124732\r\n0001\r\n", "output": "547124732\r\n"}, {"input": "4 684444619 722440661\r\n1001\r\n", "output": "722440661\r\n"}, {"input": "4 477963686 636258459\r\n0101\r\n", "output": "1114222145\r\n"}, {"input": "4 360253575 773578347\r\n1101\r\n", "output": "773578347\r\n"}, {"input": "4 832478048 910898234\r\n0011\r\n", "output": "910898234\r\n"}, {"input": "4 343185412 714767937\r\n1011\r\n", "output": "714767937\r\n"}, {"input": "4 480505300 892025118\r\n0111\r\n", "output": "892025118\r\n"}, {"input": "4 322857895 774315007\r\n1111\r\n", "output": "0\r\n"}, {"input": "4 386548854 246539479\r\n0000\r\n", "output": "246539479\r\n"}, {"input": "4 523868742 128829368\r\n1000\r\n", "output": "128829368\r\n"}, {"input": "4 956155921 11119257\r\n0100\r\n", "output": "22238514\r\n"}, {"input": "4 188376438 93475808\r\n1100\r\n", "output": "93475808\r\n"}, {"input": "4 754947032 158668188\r\n0010\r\n", "output": "317336376\r\n"}, {"input": "4 927391856 637236921\r\n1010\r\n", "output": "1274473842\r\n"}, {"input": "4 359679035 109461393\r\n0110\r\n", "output": "218922786\r\n"}, {"input": "4 991751283 202031630\r\n1110\r\n", "output": "202031630\r\n"}, {"input": "4 339351517 169008463\r\n0001\r\n", "output": "169008463\r\n"}, {"input": "4 771638697 346265644\r\n1001\r\n", "output": "346265644\r\n"}, {"input": "4 908958584 523522825\r\n0101\r\n", "output": "1047045650\r\n"}, {"input": "4 677682252 405812714\r\n1101\r\n", "output": "405812714\r\n"}, {"input": "4 815002139 288102603\r\n0011\r\n", "output": "288102603\r\n"}, {"input": "4 952322026 760327076\r\n1011\r\n", "output": "760327076\r\n"}, {"input": "4 663334158 312481698\r\n0111\r\n", "output": "312481698\r\n"}, {"input": "4 840591339 154834293\r\n1111\r\n", "output": "0\r\n"}, {"input": "14 3 11\r\n10110100011001\r\n", "output": "20\r\n"}, {"input": "19 1 1\r\n1010101010101010101\r\n", "output": "9\r\n"}, {"input": "1 10 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 100 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 1000 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 10 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "7 3 2\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 10\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 3 2\r\n1\r\n", "output": "0\r\n"}, {"input": "2 10 1\r\n11\r\n", "output": "0\r\n"}, {"input": "4 148823922 302792601\r\n1010\r\n", "output": "451616523\r\n"}, {"input": "1 2 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n00011\r\n", "output": "3\r\n"}, {"input": "1 5 0\r\n1\r\n", "output": "0\r\n"}, {"input": "7 2 3\r\n1001001\r\n", "output": "5\r\n"}, {"input": "10 1 1000000000\r\n1111010111\r\n", "output": "1000000001\r\n"}, {"input": "25 999999998 999999999\r\n1011001110101010100111001\r\n", "output": "7999999985\r\n"}, {"input": "2 0 1\r\n00\r\n", "output": "1\r\n"}, {"input": "2 1 100\r\n10\r\n", "output": "100\r\n"}, {"input": "7 20 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "0\r\n"}, {"input": "3 1 10\r\n010\r\n", "output": "11\r\n"}, {"input": "2 1 0\r\n11\r\n", "output": "0\r\n"}, {"input": "7 100 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 1000\r\n10101\r\n", "output": "1001\r\n"}, {"input": "5 2 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "1 1000 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 799543940 488239239\r\n1\r\n", "output": "0\r\n"}, {"input": "6 1 1000\r\n010101\r\n", "output": "1002\r\n"}, {"input": "5 11 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n10101\r\n", "output": "5\r\n"}, {"input": "3 10 1\r\n111\r\n", "output": "0\r\n"}, {"input": "7 9 10\r\n1001011\r\n", "output": "19\r\n"}, {"input": "5 5 6\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 1000000000 0\r\n1\r\n", "output": "0\r\n"}, {"input": "4 0 1\r\n0101\r\n", "output": "1\r\n"}, {"input": "8 2 3\r\n10101010\r\n", "output": "9\r\n"}, {"input": "6 3 100\r\n010101\r\n", "output": "106\r\n"}, {"input": "3 3 2\r\n111\r\n", "output": "0\r\n"}, {"input": "1 20 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n01\r\n", "output": "2\r\n"}]
false
stdio
null
true
997/A
997
A
PyPy 3-64
TESTS
15
139
39,731,200
157202162
import sys def II(): return int(sys.stdin.readline()) def LI(): return [int(num) for num in sys.stdin.readline().split()] def SI(): return sys.stdin.readline().rstrip() n, x, y = LI() old_s = SI() s = [old_s[0]] prev = old_s[0] for si in old_s: if si != prev: prev = si s.append(si) s = "".join(s) # print(s) s = [seq for seq in s.split('1') if seq != ''] # print(s) print(min(y * len(s), x * (len(s) - 1) + y))
115
77
20,889,600
201858445
import sys input = lambda: sys.stdin.readline().rstrip() n,x,y = map(int, input().split()) S = input() A = [S[0]] for c in S[1:]: if c==A[-1]: continue else: A.append(c) cnt = A.count('0') if cnt==0: print(0) else: print(y+min((cnt-1)*x, (cnt-1)*y))
Codeforces Round 493 (Div. 1)
CF
2,018
1
256
Convert to Ones
You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones. Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$. You can apply the following operations any number of times: - Choose some substring of string $$$a$$$ (for example, you can choose entire string) and reverse it, paying $$$x$$$ coins for it (for example, «0101101» $$$\to$$$ «0111001»); - Choose some substring of string $$$a$$$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $$$y$$$ coins for it (for example, «0101101» $$$\to$$$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones?
The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $$$a$$$ of length $$$n$$$, consisting of zeros and ones.
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations.
null
In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «10000» $$$\to$$$ «11111». The total cost of operations is $$$1 + 10 = 11$$$. In the second sample, at first you need to invert substring $$$[1 \dots 1]$$$, and then you need to invert substring $$$[3 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «11000» $$$\to$$$ «11111». The overall cost is $$$1 + 1 = 2$$$. In the third example, string already consists only of ones, so the answer is $$$0$$$.
[{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}]
1,500
["brute force", "greedy", "implementation", "math"]
115
[{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 261764879\r\n0\r\n", "output": "261764879\r\n"}, {"input": "1 491511050 399084767\r\n1\r\n", "output": "0\r\n"}, {"input": "2 163093925 214567542\r\n00\r\n", "output": "214567542\r\n"}, {"input": "2 340351106 646854722\r\n10\r\n", "output": "646854722\r\n"}, {"input": "2 222640995 489207317\r\n01\r\n", "output": "489207317\r\n"}, {"input": "2 399898176 552898277\r\n11\r\n", "output": "0\r\n"}, {"input": "2 690218164 577155357\r\n00\r\n", "output": "577155357\r\n"}, {"input": "2 827538051 754412538\r\n10\r\n", "output": "754412538\r\n"}, {"input": "2 636702427 259825230\r\n01\r\n", "output": "259825230\r\n"}, {"input": "2 108926899 102177825\r\n11\r\n", "output": "0\r\n"}, {"input": "3 368381052 440077270\r\n000\r\n", "output": "440077270\r\n"}, {"input": "3 505700940 617334451\r\n100\r\n", "output": "617334451\r\n"}, {"input": "3 499624340 643020827\r\n010\r\n", "output": "1142645167\r\n"}, {"input": "3 75308005 971848814\r\n110\r\n", "output": "971848814\r\n"}, {"input": "3 212627893 854138703\r\n001\r\n", "output": "854138703\r\n"}, {"input": "3 31395883 981351561\r\n101\r\n", "output": "981351561\r\n"}, {"input": "3 118671447 913685773\r\n011\r\n", "output": "913685773\r\n"}, {"input": "3 255991335 385910245\r\n111\r\n", "output": "0\r\n"}, {"input": "3 688278514 268200134\r\n000\r\n", "output": "268200134\r\n"}, {"input": "3 825598402 445457315\r\n100\r\n", "output": "445457315\r\n"}, {"input": "3 300751942 45676507\r\n010\r\n", "output": "91353014\r\n"}, {"input": "3 517900980 438071829\r\n110\r\n", "output": "438071829\r\n"}, {"input": "3 400190869 280424424\r\n001\r\n", "output": "280424424\r\n"}, {"input": "3 577448050 344115384\r\n101\r\n", "output": "344115384\r\n"}, {"input": "3 481435271 459737939\r\n011\r\n", "output": "459737939\r\n"}, {"input": "3 931962412 913722450\r\n111\r\n", "output": "0\r\n"}, {"input": "4 522194562 717060616\r\n0000\r\n", "output": "717060616\r\n"}, {"input": "4 659514449 894317797\r\n1000\r\n", "output": "894317797\r\n"}, {"input": "4 71574977 796834337\r\n0100\r\n", "output": "868409314\r\n"}, {"input": "4 248832158 934154224\r\n1100\r\n", "output": "934154224\r\n"}, {"input": "4 71474110 131122047\r\n0010\r\n", "output": "202596157\r\n"}, {"input": "4 308379228 503761290\r\n1010\r\n", "output": "812140518\r\n"}, {"input": "4 272484957 485636409\r\n0110\r\n", "output": "758121366\r\n"}, {"input": "4 662893590 704772137\r\n1110\r\n", "output": "704772137\r\n"}, {"input": "4 545183479 547124732\r\n0001\r\n", "output": "547124732\r\n"}, {"input": "4 684444619 722440661\r\n1001\r\n", "output": "722440661\r\n"}, {"input": "4 477963686 636258459\r\n0101\r\n", "output": "1114222145\r\n"}, {"input": "4 360253575 773578347\r\n1101\r\n", "output": "773578347\r\n"}, {"input": "4 832478048 910898234\r\n0011\r\n", "output": "910898234\r\n"}, {"input": "4 343185412 714767937\r\n1011\r\n", "output": "714767937\r\n"}, {"input": "4 480505300 892025118\r\n0111\r\n", "output": "892025118\r\n"}, {"input": "4 322857895 774315007\r\n1111\r\n", "output": "0\r\n"}, {"input": "4 386548854 246539479\r\n0000\r\n", "output": "246539479\r\n"}, {"input": "4 523868742 128829368\r\n1000\r\n", "output": "128829368\r\n"}, {"input": "4 956155921 11119257\r\n0100\r\n", "output": "22238514\r\n"}, {"input": "4 188376438 93475808\r\n1100\r\n", "output": "93475808\r\n"}, {"input": "4 754947032 158668188\r\n0010\r\n", "output": "317336376\r\n"}, {"input": "4 927391856 637236921\r\n1010\r\n", "output": "1274473842\r\n"}, {"input": "4 359679035 109461393\r\n0110\r\n", "output": "218922786\r\n"}, {"input": "4 991751283 202031630\r\n1110\r\n", "output": "202031630\r\n"}, {"input": "4 339351517 169008463\r\n0001\r\n", "output": "169008463\r\n"}, {"input": "4 771638697 346265644\r\n1001\r\n", "output": "346265644\r\n"}, {"input": "4 908958584 523522825\r\n0101\r\n", "output": "1047045650\r\n"}, {"input": "4 677682252 405812714\r\n1101\r\n", "output": "405812714\r\n"}, {"input": "4 815002139 288102603\r\n0011\r\n", "output": "288102603\r\n"}, {"input": "4 952322026 760327076\r\n1011\r\n", "output": "760327076\r\n"}, {"input": "4 663334158 312481698\r\n0111\r\n", "output": "312481698\r\n"}, {"input": "4 840591339 154834293\r\n1111\r\n", "output": "0\r\n"}, {"input": "14 3 11\r\n10110100011001\r\n", "output": "20\r\n"}, {"input": "19 1 1\r\n1010101010101010101\r\n", "output": "9\r\n"}, {"input": "1 10 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 100 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 1000 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 10 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "7 3 2\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 10\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 3 2\r\n1\r\n", "output": "0\r\n"}, {"input": "2 10 1\r\n11\r\n", "output": "0\r\n"}, {"input": "4 148823922 302792601\r\n1010\r\n", "output": "451616523\r\n"}, {"input": "1 2 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n00011\r\n", "output": "3\r\n"}, {"input": "1 5 0\r\n1\r\n", "output": "0\r\n"}, {"input": "7 2 3\r\n1001001\r\n", "output": "5\r\n"}, {"input": "10 1 1000000000\r\n1111010111\r\n", "output": "1000000001\r\n"}, {"input": "25 999999998 999999999\r\n1011001110101010100111001\r\n", "output": "7999999985\r\n"}, {"input": "2 0 1\r\n00\r\n", "output": "1\r\n"}, {"input": "2 1 100\r\n10\r\n", "output": "100\r\n"}, {"input": "7 20 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "0\r\n"}, {"input": "3 1 10\r\n010\r\n", "output": "11\r\n"}, {"input": "2 1 0\r\n11\r\n", "output": "0\r\n"}, {"input": "7 100 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 1000\r\n10101\r\n", "output": "1001\r\n"}, {"input": "5 2 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "1 1000 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 799543940 488239239\r\n1\r\n", "output": "0\r\n"}, {"input": "6 1 1000\r\n010101\r\n", "output": "1002\r\n"}, {"input": "5 11 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n10101\r\n", "output": "5\r\n"}, {"input": "3 10 1\r\n111\r\n", "output": "0\r\n"}, {"input": "7 9 10\r\n1001011\r\n", "output": "19\r\n"}, {"input": "5 5 6\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 1000000000 0\r\n1\r\n", "output": "0\r\n"}, {"input": "4 0 1\r\n0101\r\n", "output": "1\r\n"}, {"input": "8 2 3\r\n10101010\r\n", "output": "9\r\n"}, {"input": "6 3 100\r\n010101\r\n", "output": "106\r\n"}, {"input": "3 3 2\r\n111\r\n", "output": "0\r\n"}, {"input": "1 20 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n01\r\n", "output": "2\r\n"}]
false
stdio
null
true
997/A
997
A
Python 3
TESTS
10
343
1,024,000
188358820
def flip(s, startIndex): flag = False i1 = i2 = 0 for i in range(startIndex, len(s)): if s[i] == "1": flag = True i1 = i break if flag: i2 = i1 for i in range(i1, len(s)): if s[i] == "0": i2 = i - 1 break return flag, i2 def numZero(s, startIndex): for i in range(startIndex, len(s)): if s[i] == "1": return i - 1 return len(s)-1 n, x, y = tuple(map(int, input().split())) a = input() if len(set(a)) == 1: if a[0] == "1": print(0) else: print(y) else: cost = 0 i = -1 while i < n - 1: i += 1 if a[i] == "1": continue else: if x <= y: t = flip(a, i) if t[0]: cost += x i = t[1] else: cost += y break else: i = numZero(a, i) cost += y print(cost)
115
78
921,600
205314625
n,x,y=map(int,input().split(' ')) w=str(input()) cnt=int(w[0]=='0') for i in range(1,n): if w[i]=='0' and w[i-1]=='1': cnt+=1 if cnt==0: print(0) else: res=y+min(x,y)*(cnt-1) print(res)
Codeforces Round 493 (Div. 1)
CF
2,018
1
256
Convert to Ones
You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones. Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$. You can apply the following operations any number of times: - Choose some substring of string $$$a$$$ (for example, you can choose entire string) and reverse it, paying $$$x$$$ coins for it (for example, «0101101» $$$\to$$$ «0111001»); - Choose some substring of string $$$a$$$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $$$y$$$ coins for it (for example, «0101101» $$$\to$$$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones?
The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $$$a$$$ of length $$$n$$$, consisting of zeros and ones.
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations.
null
In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «10000» $$$\to$$$ «11111». The total cost of operations is $$$1 + 10 = 11$$$. In the second sample, at first you need to invert substring $$$[1 \dots 1]$$$, and then you need to invert substring $$$[3 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «11000» $$$\to$$$ «11111». The overall cost is $$$1 + 1 = 2$$$. In the third example, string already consists only of ones, so the answer is $$$0$$$.
[{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}]
1,500
["brute force", "greedy", "implementation", "math"]
115
[{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 261764879\r\n0\r\n", "output": "261764879\r\n"}, {"input": "1 491511050 399084767\r\n1\r\n", "output": "0\r\n"}, {"input": "2 163093925 214567542\r\n00\r\n", "output": "214567542\r\n"}, {"input": "2 340351106 646854722\r\n10\r\n", "output": "646854722\r\n"}, {"input": "2 222640995 489207317\r\n01\r\n", "output": "489207317\r\n"}, {"input": "2 399898176 552898277\r\n11\r\n", "output": "0\r\n"}, {"input": "2 690218164 577155357\r\n00\r\n", "output": "577155357\r\n"}, {"input": "2 827538051 754412538\r\n10\r\n", "output": "754412538\r\n"}, {"input": "2 636702427 259825230\r\n01\r\n", "output": "259825230\r\n"}, {"input": "2 108926899 102177825\r\n11\r\n", "output": "0\r\n"}, {"input": "3 368381052 440077270\r\n000\r\n", "output": "440077270\r\n"}, {"input": "3 505700940 617334451\r\n100\r\n", "output": "617334451\r\n"}, {"input": "3 499624340 643020827\r\n010\r\n", "output": "1142645167\r\n"}, {"input": "3 75308005 971848814\r\n110\r\n", "output": "971848814\r\n"}, {"input": "3 212627893 854138703\r\n001\r\n", "output": "854138703\r\n"}, {"input": "3 31395883 981351561\r\n101\r\n", "output": "981351561\r\n"}, {"input": "3 118671447 913685773\r\n011\r\n", "output": "913685773\r\n"}, {"input": "3 255991335 385910245\r\n111\r\n", "output": "0\r\n"}, {"input": "3 688278514 268200134\r\n000\r\n", "output": "268200134\r\n"}, {"input": "3 825598402 445457315\r\n100\r\n", "output": "445457315\r\n"}, {"input": "3 300751942 45676507\r\n010\r\n", "output": "91353014\r\n"}, {"input": "3 517900980 438071829\r\n110\r\n", "output": "438071829\r\n"}, {"input": "3 400190869 280424424\r\n001\r\n", "output": "280424424\r\n"}, {"input": "3 577448050 344115384\r\n101\r\n", "output": "344115384\r\n"}, {"input": "3 481435271 459737939\r\n011\r\n", "output": "459737939\r\n"}, {"input": "3 931962412 913722450\r\n111\r\n", "output": "0\r\n"}, {"input": "4 522194562 717060616\r\n0000\r\n", "output": "717060616\r\n"}, {"input": "4 659514449 894317797\r\n1000\r\n", "output": "894317797\r\n"}, {"input": "4 71574977 796834337\r\n0100\r\n", "output": "868409314\r\n"}, {"input": "4 248832158 934154224\r\n1100\r\n", "output": "934154224\r\n"}, {"input": "4 71474110 131122047\r\n0010\r\n", "output": "202596157\r\n"}, {"input": "4 308379228 503761290\r\n1010\r\n", "output": "812140518\r\n"}, {"input": "4 272484957 485636409\r\n0110\r\n", "output": "758121366\r\n"}, {"input": "4 662893590 704772137\r\n1110\r\n", "output": "704772137\r\n"}, {"input": "4 545183479 547124732\r\n0001\r\n", "output": "547124732\r\n"}, {"input": "4 684444619 722440661\r\n1001\r\n", "output": "722440661\r\n"}, {"input": "4 477963686 636258459\r\n0101\r\n", "output": "1114222145\r\n"}, {"input": "4 360253575 773578347\r\n1101\r\n", "output": "773578347\r\n"}, {"input": "4 832478048 910898234\r\n0011\r\n", "output": "910898234\r\n"}, {"input": "4 343185412 714767937\r\n1011\r\n", "output": "714767937\r\n"}, {"input": "4 480505300 892025118\r\n0111\r\n", "output": "892025118\r\n"}, {"input": "4 322857895 774315007\r\n1111\r\n", "output": "0\r\n"}, {"input": "4 386548854 246539479\r\n0000\r\n", "output": "246539479\r\n"}, {"input": "4 523868742 128829368\r\n1000\r\n", "output": "128829368\r\n"}, {"input": "4 956155921 11119257\r\n0100\r\n", "output": "22238514\r\n"}, {"input": "4 188376438 93475808\r\n1100\r\n", "output": "93475808\r\n"}, {"input": "4 754947032 158668188\r\n0010\r\n", "output": "317336376\r\n"}, {"input": "4 927391856 637236921\r\n1010\r\n", "output": "1274473842\r\n"}, {"input": "4 359679035 109461393\r\n0110\r\n", "output": "218922786\r\n"}, {"input": "4 991751283 202031630\r\n1110\r\n", "output": "202031630\r\n"}, {"input": "4 339351517 169008463\r\n0001\r\n", "output": "169008463\r\n"}, {"input": "4 771638697 346265644\r\n1001\r\n", "output": "346265644\r\n"}, {"input": "4 908958584 523522825\r\n0101\r\n", "output": "1047045650\r\n"}, {"input": "4 677682252 405812714\r\n1101\r\n", "output": "405812714\r\n"}, {"input": "4 815002139 288102603\r\n0011\r\n", "output": "288102603\r\n"}, {"input": "4 952322026 760327076\r\n1011\r\n", "output": "760327076\r\n"}, {"input": "4 663334158 312481698\r\n0111\r\n", "output": "312481698\r\n"}, {"input": "4 840591339 154834293\r\n1111\r\n", "output": "0\r\n"}, {"input": "14 3 11\r\n10110100011001\r\n", "output": "20\r\n"}, {"input": "19 1 1\r\n1010101010101010101\r\n", "output": "9\r\n"}, {"input": "1 10 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 100 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 1000 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 10 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "7 3 2\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 10\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 3 2\r\n1\r\n", "output": "0\r\n"}, {"input": "2 10 1\r\n11\r\n", "output": "0\r\n"}, {"input": "4 148823922 302792601\r\n1010\r\n", "output": "451616523\r\n"}, {"input": "1 2 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n00011\r\n", "output": "3\r\n"}, {"input": "1 5 0\r\n1\r\n", "output": "0\r\n"}, {"input": "7 2 3\r\n1001001\r\n", "output": "5\r\n"}, {"input": "10 1 1000000000\r\n1111010111\r\n", "output": "1000000001\r\n"}, {"input": "25 999999998 999999999\r\n1011001110101010100111001\r\n", "output": "7999999985\r\n"}, {"input": "2 0 1\r\n00\r\n", "output": "1\r\n"}, {"input": "2 1 100\r\n10\r\n", "output": "100\r\n"}, {"input": "7 20 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "0\r\n"}, {"input": "3 1 10\r\n010\r\n", "output": "11\r\n"}, {"input": "2 1 0\r\n11\r\n", "output": "0\r\n"}, {"input": "7 100 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 1000\r\n10101\r\n", "output": "1001\r\n"}, {"input": "5 2 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "1 1000 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 799543940 488239239\r\n1\r\n", "output": "0\r\n"}, {"input": "6 1 1000\r\n010101\r\n", "output": "1002\r\n"}, {"input": "5 11 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n10101\r\n", "output": "5\r\n"}, {"input": "3 10 1\r\n111\r\n", "output": "0\r\n"}, {"input": "7 9 10\r\n1001011\r\n", "output": "19\r\n"}, {"input": "5 5 6\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 1000000000 0\r\n1\r\n", "output": "0\r\n"}, {"input": "4 0 1\r\n0101\r\n", "output": "1\r\n"}, {"input": "8 2 3\r\n10101010\r\n", "output": "9\r\n"}, {"input": "6 3 100\r\n010101\r\n", "output": "106\r\n"}, {"input": "3 3 2\r\n111\r\n", "output": "0\r\n"}, {"input": "1 20 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n01\r\n", "output": "2\r\n"}]
false
stdio
null
true
997/A
997
A
Python 3
TESTS
15
233
1,126,400
47706443
l = [()] n = input().split(' ') s = input() x = int(n[1]) y = int(n[2]) com = "" nn = 0 for i in s: if len(com) ==0 or com[-1] != i: com+=i if(i == '0'): nn+=1 print(min(nn*y, (nn-1)*x+y))
115
92
4,300,800
132037205
def main(): n,x,y = map(int,input().split()) s = input() curr = '' zero = 0 for i in s: if i != curr: if curr == '0': zero += 1 curr = i if curr == '0': zero += 1 min_val = float('inf') for i in range(zero,0,-1): min_val = min(min_val, y*i + (zero-i)*x) if min_val == float('inf'): min_val = 0 print(min_val) main()
Codeforces Round 493 (Div. 1)
CF
2,018
1
256
Convert to Ones
You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones. Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$. You can apply the following operations any number of times: - Choose some substring of string $$$a$$$ (for example, you can choose entire string) and reverse it, paying $$$x$$$ coins for it (for example, «0101101» $$$\to$$$ «0111001»); - Choose some substring of string $$$a$$$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $$$y$$$ coins for it (for example, «0101101» $$$\to$$$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones?
The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $$$a$$$ of length $$$n$$$, consisting of zeros and ones.
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations.
null
In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «10000» $$$\to$$$ «11111». The total cost of operations is $$$1 + 10 = 11$$$. In the second sample, at first you need to invert substring $$$[1 \dots 1]$$$, and then you need to invert substring $$$[3 \dots 5]$$$. Then the string was changed as follows: «01000» $$$\to$$$ «11000» $$$\to$$$ «11111». The overall cost is $$$1 + 1 = 2$$$. In the third example, string already consists only of ones, so the answer is $$$0$$$.
[{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}]
1,500
["brute force", "greedy", "implementation", "math"]
115
[{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 261764879\r\n0\r\n", "output": "261764879\r\n"}, {"input": "1 491511050 399084767\r\n1\r\n", "output": "0\r\n"}, {"input": "2 163093925 214567542\r\n00\r\n", "output": "214567542\r\n"}, {"input": "2 340351106 646854722\r\n10\r\n", "output": "646854722\r\n"}, {"input": "2 222640995 489207317\r\n01\r\n", "output": "489207317\r\n"}, {"input": "2 399898176 552898277\r\n11\r\n", "output": "0\r\n"}, {"input": "2 690218164 577155357\r\n00\r\n", "output": "577155357\r\n"}, {"input": "2 827538051 754412538\r\n10\r\n", "output": "754412538\r\n"}, {"input": "2 636702427 259825230\r\n01\r\n", "output": "259825230\r\n"}, {"input": "2 108926899 102177825\r\n11\r\n", "output": "0\r\n"}, {"input": "3 368381052 440077270\r\n000\r\n", "output": "440077270\r\n"}, {"input": "3 505700940 617334451\r\n100\r\n", "output": "617334451\r\n"}, {"input": "3 499624340 643020827\r\n010\r\n", "output": "1142645167\r\n"}, {"input": "3 75308005 971848814\r\n110\r\n", "output": "971848814\r\n"}, {"input": "3 212627893 854138703\r\n001\r\n", "output": "854138703\r\n"}, {"input": "3 31395883 981351561\r\n101\r\n", "output": "981351561\r\n"}, {"input": "3 118671447 913685773\r\n011\r\n", "output": "913685773\r\n"}, {"input": "3 255991335 385910245\r\n111\r\n", "output": "0\r\n"}, {"input": "3 688278514 268200134\r\n000\r\n", "output": "268200134\r\n"}, {"input": "3 825598402 445457315\r\n100\r\n", "output": "445457315\r\n"}, {"input": "3 300751942 45676507\r\n010\r\n", "output": "91353014\r\n"}, {"input": "3 517900980 438071829\r\n110\r\n", "output": "438071829\r\n"}, {"input": "3 400190869 280424424\r\n001\r\n", "output": "280424424\r\n"}, {"input": "3 577448050 344115384\r\n101\r\n", "output": "344115384\r\n"}, {"input": "3 481435271 459737939\r\n011\r\n", "output": "459737939\r\n"}, {"input": "3 931962412 913722450\r\n111\r\n", "output": "0\r\n"}, {"input": "4 522194562 717060616\r\n0000\r\n", "output": "717060616\r\n"}, {"input": "4 659514449 894317797\r\n1000\r\n", "output": "894317797\r\n"}, {"input": "4 71574977 796834337\r\n0100\r\n", "output": "868409314\r\n"}, {"input": "4 248832158 934154224\r\n1100\r\n", "output": "934154224\r\n"}, {"input": "4 71474110 131122047\r\n0010\r\n", "output": "202596157\r\n"}, {"input": "4 308379228 503761290\r\n1010\r\n", "output": "812140518\r\n"}, {"input": "4 272484957 485636409\r\n0110\r\n", "output": "758121366\r\n"}, {"input": "4 662893590 704772137\r\n1110\r\n", "output": "704772137\r\n"}, {"input": "4 545183479 547124732\r\n0001\r\n", "output": "547124732\r\n"}, {"input": "4 684444619 722440661\r\n1001\r\n", "output": "722440661\r\n"}, {"input": "4 477963686 636258459\r\n0101\r\n", "output": "1114222145\r\n"}, {"input": "4 360253575 773578347\r\n1101\r\n", "output": "773578347\r\n"}, {"input": "4 832478048 910898234\r\n0011\r\n", "output": "910898234\r\n"}, {"input": "4 343185412 714767937\r\n1011\r\n", "output": "714767937\r\n"}, {"input": "4 480505300 892025118\r\n0111\r\n", "output": "892025118\r\n"}, {"input": "4 322857895 774315007\r\n1111\r\n", "output": "0\r\n"}, {"input": "4 386548854 246539479\r\n0000\r\n", "output": "246539479\r\n"}, {"input": "4 523868742 128829368\r\n1000\r\n", "output": "128829368\r\n"}, {"input": "4 956155921 11119257\r\n0100\r\n", "output": "22238514\r\n"}, {"input": "4 188376438 93475808\r\n1100\r\n", "output": "93475808\r\n"}, {"input": "4 754947032 158668188\r\n0010\r\n", "output": "317336376\r\n"}, {"input": "4 927391856 637236921\r\n1010\r\n", "output": "1274473842\r\n"}, {"input": "4 359679035 109461393\r\n0110\r\n", "output": "218922786\r\n"}, {"input": "4 991751283 202031630\r\n1110\r\n", "output": "202031630\r\n"}, {"input": "4 339351517 169008463\r\n0001\r\n", "output": "169008463\r\n"}, {"input": "4 771638697 346265644\r\n1001\r\n", "output": "346265644\r\n"}, {"input": "4 908958584 523522825\r\n0101\r\n", "output": "1047045650\r\n"}, {"input": "4 677682252 405812714\r\n1101\r\n", "output": "405812714\r\n"}, {"input": "4 815002139 288102603\r\n0011\r\n", "output": "288102603\r\n"}, {"input": "4 952322026 760327076\r\n1011\r\n", "output": "760327076\r\n"}, {"input": "4 663334158 312481698\r\n0111\r\n", "output": "312481698\r\n"}, {"input": "4 840591339 154834293\r\n1111\r\n", "output": "0\r\n"}, {"input": "14 3 11\r\n10110100011001\r\n", "output": "20\r\n"}, {"input": "19 1 1\r\n1010101010101010101\r\n", "output": "9\r\n"}, {"input": "1 10 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 100 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 1000 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 10 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "7 3 2\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 10\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 3 2\r\n1\r\n", "output": "0\r\n"}, {"input": "2 10 1\r\n11\r\n", "output": "0\r\n"}, {"input": "4 148823922 302792601\r\n1010\r\n", "output": "451616523\r\n"}, {"input": "1 2 1\r\n1\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n00011\r\n", "output": "3\r\n"}, {"input": "1 5 0\r\n1\r\n", "output": "0\r\n"}, {"input": "7 2 3\r\n1001001\r\n", "output": "5\r\n"}, {"input": "10 1 1000000000\r\n1111010111\r\n", "output": "1000000001\r\n"}, {"input": "25 999999998 999999999\r\n1011001110101010100111001\r\n", "output": "7999999985\r\n"}, {"input": "2 0 1\r\n00\r\n", "output": "1\r\n"}, {"input": "2 1 100\r\n10\r\n", "output": "100\r\n"}, {"input": "7 20 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "0\r\n"}, {"input": "3 1 10\r\n010\r\n", "output": "11\r\n"}, {"input": "2 1 0\r\n11\r\n", "output": "0\r\n"}, {"input": "7 100 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "5 1 1000\r\n10101\r\n", "output": "1001\r\n"}, {"input": "5 2 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "1 1000 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 799543940 488239239\r\n1\r\n", "output": "0\r\n"}, {"input": "6 1 1000\r\n010101\r\n", "output": "1002\r\n"}, {"input": "5 11 1\r\n11111\r\n", "output": "0\r\n"}, {"input": "5 2 3\r\n10101\r\n", "output": "5\r\n"}, {"input": "3 10 1\r\n111\r\n", "output": "0\r\n"}, {"input": "7 9 10\r\n1001011\r\n", "output": "19\r\n"}, {"input": "5 5 6\r\n10101\r\n", "output": "11\r\n"}, {"input": "1 1000000000 0\r\n1\r\n", "output": "0\r\n"}, {"input": "4 0 1\r\n0101\r\n", "output": "1\r\n"}, {"input": "8 2 3\r\n10101010\r\n", "output": "9\r\n"}, {"input": "6 3 100\r\n010101\r\n", "output": "106\r\n"}, {"input": "3 3 2\r\n111\r\n", "output": "0\r\n"}, {"input": "1 20 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n01\r\n", "output": "2\r\n"}]
false
stdio
null
true
979/B
979
B
Python 3
TESTS
94
62
716,800
194127133
from sys import stdin ,stdout input=stdin.readline from collections import Counter , defaultdict def print(*args, end='\n', sep=' ') -> None: stdout.write(sep.join(map(str, args)) + end) n= int(input()) ; a=input().strip() ; lenth=len(a) ; ku=sh=ka=min(n,lenth) ; c1=Counter(a) ; c2=Counter(input().strip()) ; c3=Counter(input().strip()) for i in c1 : if c1[i]+n>lenth: if c1[i]+n-lenth>=3: ku=lenth else :ku=max(lenth-1,ku) else :ku=max(c1[i]+n,ku) for i in c2 : if c2[i]+n>lenth: if c2[i]+n-lenth>=3: sh=lenth else :sh=max(lenth-1,sh) else :sh=max(c2[i]+n,sh) for i in c3 : if c3[i]+n>lenth: if c3[i]+n-lenth>=3: ka=lenth else :ka=max(lenth-1,ka) else: ka=max(c3[i]+n,ka) dic={"Kuro":ku , "Shiro" : sh , "Katie":ka} ; val=list(dic.values()) ; dic2=defaultdict(list) ; key=list(dic.keys()) for i in range(3): dic2[val[i]].append(key[i]) val.sort(reverse=True) if len(dic2[val[0]])>1 : print("Draw") else : print((dic2[val[0]][0]))
184
93
7,782,400
125617453
from collections import Counter def f(x): return max(list(Counter(x).values())) n=int(input()) z=input() l=len(z) a=f(z) b=f(input()) c=f(input()) def v(x): if x==l: return x-1 else: return x+1 if n==1: a, b, c=v(a), v(b), v(c) if a>b and a>c: print("Kuro") elif b>a and b>c: print("Shiro") elif c>a and c>b: print("Katie") else: print("Draw") elif (l-a<=n)+(l-b<=n)+(l-c<=n)>=2: print("Draw") elif a>b and a>c: print("Kuro") elif b>a and b>c: print("Shiro") elif c>a and c>b: print("Katie") else: print("Draw") #print((l-a<=n)+(l-b<=n)+(l-c<=n)) #print(a, b, c)
Codeforces Round 482 (Div. 2)
CF
2,018
1
256
Treasure Hunt
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her. The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons. A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $$$7$$$ because its subribbon a appears $$$7$$$ times, and the ribbon abcdabc has the beauty of $$$2$$$ because its subribbon abc appears twice. The rules are simple. The game will have $$$n$$$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $$$n$$$ turns wins the treasure. Could you find out who is going to be the winner if they all play optimally?
The first line contains an integer $$$n$$$ ($$$0 \leq n \leq 10^{9}$$$) — the number of turns. Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $$$10^{5}$$$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.
Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".
null
In the first example, after $$$3$$$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $$$5$$$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $$$4$$$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro. In the fourth example, since the length of each of the string is $$$9$$$ and the number of turn is $$$15$$$, everyone can change their ribbons in some way to reach the maximal beauty of $$$9$$$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.
[{"input": "3\nKuroo\nShiro\nKatie", "output": "Kuro"}, {"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces", "output": "Shiro"}, {"input": "1\nabcabc\ncbabac\nababca", "output": "Katie"}, {"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE", "output": "Draw"}]
1,800
["greedy"]
184
[{"input": "3\r\nKuroo\r\nShiro\r\nKatie\r\n", "output": "Kuro\r\n"}, {"input": "7\r\ntreasurehunt\r\nthreefriends\r\nhiCodeforces\r\n", "output": "Shiro\r\n"}, {"input": "1\r\nabcabc\r\ncbabac\r\nababca\r\n", "output": "Katie\r\n"}, {"input": "15\r\nfoPaErcvJ\r\nmZaxowpbt\r\nmkuOlaHRE\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaaaaaaaa\r\nAAAAAAcAAA\r\nbbbbbbzzbb\r\n", "output": "Shiro\r\n"}, {"input": "60\r\nddcZYXYbZbcXYcZdYbddaddYaZYZdaZdZZdXaaYdaZZZaXZXXaaZbb\r\ndcdXcYbcaXYaXYcacYabYcbZYdacaYbYdXaccYXZZZdYbbYdcZZZbY\r\nXaZXbbdcXaadcYdYYcbZdcaXaYZabbXZZYbYbcXbaXabcXbXadbZYZ\r\n", "output": "Draw\r\n"}, {"input": "9174\r\nbzbbbzzzbbzzccczzccczzbzbzcbzbbzccbzcccbccczzbbcbbzbzzzcbczbzbzzbbbczbbcbzzzbcbzczbcczb\r\ndbzzzccdcdczzzzzcdczbbzcdzbcdbzzdczbzddcddbdbzzzczcczzbdcbbzccbzzzdzbzddcbzbdzdcczccbdb\r\nzdczddzcdddddczdczdczdcdzczddzczdzddczdcdcdzczczzdzccdccczczdzczczdzcdddzddzccddcczczzd\r\n", "output": "Draw\r\n"}, {"input": "727\r\nbaabbabbbababbbbaaaabaabbaabababaaababaaababbbbababbbbbbbbbbaaabaabbbbbbbbaaaabaabbaaabaabbabaa\r\nddcdcccccccdccdcdccdddcddcddcddddcdddcdcdccddcdddddccddcccdcdddcdcccdccccccdcdcdccccccdccccccdc\r\nfffeefeffeefeeeeffefffeeefffeefffefeefefeeeffefefefefefefffffffeeeeeffffeefeeeeffffeeeeeefeffef\r\n", "output": "Draw\r\n"}, {"input": "61\r\nbzqiqprzfwddqwctcrhnkqcsnbmcmfmrgaljwieajfouvuiunmfbrehxchupmsdpwilwu\r\njyxxujvxkwilikqeegzxlyiugflxqqbwbujzedqnlzucdnuipacatdhcozuvgktwvirhs\r\ntqiahohijwfcetyyjlkfhfvkhdgllxmhyyhhtlhltcdspusyhwpwqzyagtsbaswaobwub\r\n", "output": "Katie\r\n"}, {"input": "30\r\njAjcdwkvcTYSYBBLniJIIIiubKWnqeDtUiaXSIPfhDTOrCWBQetm\r\nPQPOTgqfBWzQvPNeEaUaPQGdUgldmOZsBtsIqZGGyXozntMpOsyY\r\nNPfvGxMqIULNWOmUrHJfsqORUHkzKQfecXsTzgFCmUtFmIBudCJr\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcabcabcabcdddabc\r\nzxytzytxxtytxyzxyt\r\nfgffghfghffgghghhh\r\n", "output": "Katie\r\n"}, {"input": "3\r\naaaaa\r\naaaaa\r\naaaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaa\r\naaaabcd\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaa\r\naaabcde\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaaaa\r\naaaabbb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaa\r\nbbb\r\nabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\nqwert\r\nlkjhg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\nbbbbb\r\naabcd\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcde\r\nfghij\r\nkkkkk\r\n", "output": "Katie\r\n"}, {"input": "4\r\naaaabcd\r\naaaabcd\r\naaaaaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naabcde\r\nabcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaab\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaaaaa\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "1\r\nAAAAA\r\nBBBBB\r\nABCDE\r\n", "output": "Draw\r\n"}, {"input": "1\r\nabcde\r\naaaaa\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaabbb\r\nabfcde\r\nabfcde\r\n", "output": "Kuro\r\n"}, {"input": "0\r\naaa\r\naab\r\nccd\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\naaaaa\r\naabbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\nxxxxxx\r\nxxxooo\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "2\r\noooo\r\naaac\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaaaaa\r\naaabcde\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nooooo\r\naaabb\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nqwert\r\nqwery\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaaa\r\nbbbbbb\r\naaaaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naabb\r\naabb\r\naabc\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaa\r\naab\r\naab\r\n", "output": "Draw\r\n"}, {"input": "3\r\nbbbbcc\r\nbbbbbb\r\nsadfgh\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaacc\r\nxxxxkkkk\r\nxxxxkkkk\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaac\r\nbbbbc\r\nccccc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaa\r\naaabbbbbb\r\nabcdewert\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaabc\r\naaaab\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaa\r\naaaaaaab\r\naaaabbbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\nabcdefg\r\nabccccc\r\nacccccc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\naabcd\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaabbb\r\nabcdef\r\nabcdef\r\n", "output": "Kuro\r\n"}, {"input": "4\r\naaabbb\r\naabdef\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabba\r\nbbbb\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nbbaaa\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaa\r\naaa\r\nabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcda\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcde\r\nbcdef\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naabbc\r\nqwert\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naabbcc\r\naabbcc\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nAAAAAA\r\nAAAAAB\r\nABCDEF\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabc\r\naac\r\nbbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaab\r\naabbc\r\naabbc\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaaab\r\naaaaabb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaaaa\r\nbbbbbbbbaaa\r\nqwertyuiasd\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\nbbbb\r\naabb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaabcd\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaa\r\nabc\r\nbbb\r\n", "output": "Draw\r\n"}, {"input": "1\r\naa\r\nab\r\nbb\r\n", "output": "Shiro\r\n"}, {"input": "1\r\naacb\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaabbb\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\naaaa\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "2\r\nabcd\r\nabcd\r\naaad\r\n", "output": "Katie\r\n"}, {"input": "3\r\naaa\r\nbbb\r\naab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaaaab\r\naaaaaa\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaab\r\nabcd\r\nabcd\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nooooo\r\nShiro\r\nKatie\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naabcd\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "4\r\nabcd\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaa\r\nbbb\r\naab\r\n", "output": "Draw\r\n"}, {"input": "2\r\nxxxx\r\nyyyx\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "3\r\nAAAAA\r\nAAAAB\r\nABCDE\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaacdc\r\naaaaabc\r\naaaaabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naabcde\r\naabcde\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naaabb\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "5\r\nabbbbb\r\ncbbbbb\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaa\r\naaaaabbbb\r\naaaaabbbb\r\n", "output": "Kuro\r\n"}, {"input": "4\r\naaaaaab\r\naaabbbb\r\naaabbbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaaabb\r\naaabbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaabb\r\naaaaab\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaaa\r\naaaae\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\nbbbcde\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaaabbb\r\naabcdef\r\naabcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaa\r\naaaab\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naabbbbb\r\naaabbbb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcde\r\naabcd\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "5\r\naaabbcc\r\nabcdefg\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naabbb\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "0\r\nbbb\r\nabb\r\nqer\r\n", "output": "Kuro\r\n"}, {"input": "5\r\naabbbbb\r\naaaaaaa\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaab\r\naaaab\r\naaabb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaaaab\r\naaaabbb\r\naaaaccc\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaaaaaaaaa\r\naaaaaaaaaaab\r\naaaaaabbbbbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaabb\r\nabcde\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaac\r\naaaaebc\r\naaaaaac\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaabbb\r\nqwerty\r\n", "output": "Draw\r\n"}, {"input": "3\r\ncccca\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "100005\r\nAA\r\nBC\r\nCC\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\nbbbb\r\nccca\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nbcdef\r\nbcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaab\r\naabb\r\nqwer\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcddd\r\nabcdef\r\nbbaaaa\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaa\r\naaaa\r\naabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\naaaa\r\naaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcddd\r\nabcdef\r\naaaaaa\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaa\r\nabcd\r\naaab\r\n", "output": "Katie\r\n"}]
false
stdio
null
true
603/A
603
A
Python 3
TESTS
7
77
4,812,800
26640717
n = int(input()) s = input().strip() ret = 1 nb2 = 0 for i in range(1,n): if s[i-1] != s[i]: ret += 1 else: nb2 += 1 if nb2 >= 2: ret += 2 elif n >= 2: if s[0] == s[1] or s[-1] == s[-2]: ret += 1 print(ret)
116
61
102,400
228864100
# brownfox2k6 n = int(input()) s = input() alt = 1 for i in range(1, n): alt += s[i] != s[i-1] # at most we can get +2 ans = min(n, alt + 2) print(ans)
Codeforces Round 334 (Div. 1)
CF
2,015
2
256
Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not. Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.
The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000). The following line contains a binary string of length n representing Kevin's results on the USAICO.
Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.
null
In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'. In the second sample, Kevin can flip the entire string and still have the same score.
[{"input": "8\n10000011", "output": "5"}, {"input": "2\n01", "output": "2"}]
1,600
["dp", "greedy", "math"]
116
[{"input": "8\r\n10000011\r\n", "output": "5\r\n"}, {"input": "2\r\n01\r\n", "output": "2\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "75\r\n010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "75\r\n"}, {"input": "11\r\n00000000000\r\n", "output": "3\r\n"}, {"input": "56\r\n10101011010101010101010101010101010101011010101010101010\r\n", "output": "56\r\n"}, {"input": "50\r\n01011010110101010101010101010101010101010101010100\r\n", "output": "49\r\n"}, {"input": "7\r\n0110100\r\n", "output": "7\r\n"}, {"input": "8\r\n11011111\r\n", "output": "5\r\n"}, {"input": "6\r\n000000\r\n", "output": "3\r\n"}, {"input": "5\r\n01000\r\n", "output": "5\r\n"}, {"input": "59\r\n10101010101010101010101010101010101010101010101010101010101\r\n", "output": "59\r\n"}, {"input": "88\r\n1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "88\r\n"}, {"input": "93\r\n010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "93\r\n"}, {"input": "70\r\n0101010101010101010101010101010101010101010101010101010101010101010101\r\n", "output": "70\r\n"}, {"input": "78\r\n010101010101010101010101010101101010101010101010101010101010101010101010101010\r\n", "output": "78\r\n"}, {"input": "83\r\n10101010101010101010101010101010101010101010101010110101010101010101010101010101010\r\n", "output": "83\r\n"}, {"input": "87\r\n101010101010101010101010101010101010101010101010101010101010101010101010101010010101010\r\n", "output": "87\r\n"}, {"input": "65\r\n01010101101010101010101010101010101010101010101010101010101010101\r\n", "output": "65\r\n"}, {"input": "69\r\n010101010101010101101010101010101010101010101010101010101010101010101\r\n", "output": "69\r\n"}, {"input": "74\r\n01010101010101010101010101010101010101010101010101010101010101000101010101\r\n", "output": "74\r\n"}, {"input": "77\r\n01010101010101001010101010101010100101010101010101010101010101010101010101010\r\n", "output": "77\r\n"}, {"input": "60\r\n101010110101010101010101010110101010101010101010101010101010\r\n", "output": "60\r\n"}, {"input": "89\r\n01010101010101010101010101010101010101010101010101010101101010101010101010100101010101010\r\n", "output": "89\r\n"}, {"input": "68\r\n01010101010101010101010101010101010100101010100101010101010100101010\r\n", "output": "67\r\n"}, {"input": "73\r\n0101010101010101010101010101010101010101010111011010101010101010101010101\r\n", "output": "72\r\n"}, {"input": "55\r\n1010101010101010010101010101101010101010101010100101010\r\n", "output": "54\r\n"}, {"input": "85\r\n1010101010101010101010101010010101010101010101101010101010101010101011010101010101010\r\n", "output": "84\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n1111111111\r\n", "output": "3\r\n"}, {"input": "2\r\n10\r\n", "output": "2\r\n"}, {"input": "2\r\n11\r\n", "output": "2\r\n"}, {"input": "2\r\n00\r\n", "output": "2\r\n"}, {"input": "3\r\n000\r\n", "output": "3\r\n"}, {"input": "3\r\n001\r\n", "output": "3\r\n"}, {"input": "3\r\n010\r\n", "output": "3\r\n"}, {"input": "3\r\n011\r\n", "output": "3\r\n"}, {"input": "3\r\n100\r\n", "output": "3\r\n"}, {"input": "3\r\n101\r\n", "output": "3\r\n"}, {"input": "3\r\n110\r\n", "output": "3\r\n"}, {"input": "3\r\n111\r\n", "output": "3\r\n"}, {"input": "4\r\n0000\r\n", "output": "3\r\n"}, {"input": "4\r\n0001\r\n", "output": "4\r\n"}, {"input": "4\r\n0010\r\n", "output": "4\r\n"}, {"input": "4\r\n0011\r\n", "output": "4\r\n"}, {"input": "4\r\n0100\r\n", "output": "4\r\n"}, {"input": "4\r\n0101\r\n", "output": "4\r\n"}, {"input": "4\r\n0110\r\n", "output": "4\r\n"}, {"input": "4\r\n0111\r\n", "output": "4\r\n"}, {"input": "4\r\n1000\r\n", "output": "4\r\n"}, {"input": "4\r\n1001\r\n", "output": "4\r\n"}, {"input": "4\r\n1010\r\n", "output": "4\r\n"}, {"input": "4\r\n1011\r\n", "output": "4\r\n"}, {"input": "4\r\n1100\r\n", "output": "4\r\n"}, {"input": "4\r\n1101\r\n", "output": "4\r\n"}, {"input": "4\r\n1110\r\n", "output": "4\r\n"}, {"input": "4\r\n1111\r\n", "output": "3\r\n"}, {"input": "5\r\n00000\r\n", "output": "3\r\n"}, {"input": "5\r\n00001\r\n", "output": "4\r\n"}, {"input": "5\r\n00010\r\n", "output": "5\r\n"}, {"input": "5\r\n00011\r\n", "output": "4\r\n"}, {"input": "5\r\n00100\r\n", "output": "5\r\n"}, {"input": "5\r\n00101\r\n", "output": "5\r\n"}, {"input": "5\r\n00110\r\n", "output": "5\r\n"}, {"input": "5\r\n00111\r\n", "output": "4\r\n"}, {"input": "5\r\n01000\r\n", "output": "5\r\n"}, {"input": "5\r\n01001\r\n", "output": "5\r\n"}, {"input": "5\r\n01010\r\n", "output": "5\r\n"}, {"input": "5\r\n01011\r\n", "output": "5\r\n"}, {"input": "5\r\n01100\r\n", "output": "5\r\n"}, {"input": "5\r\n01101\r\n", "output": "5\r\n"}, {"input": "5\r\n01110\r\n", "output": "5\r\n"}, {"input": "5\r\n01111\r\n", "output": "4\r\n"}, {"input": "5\r\n10000\r\n", "output": "4\r\n"}, {"input": "5\r\n10001\r\n", "output": "5\r\n"}, {"input": "5\r\n10010\r\n", "output": "5\r\n"}, {"input": "5\r\n10100\r\n", "output": "5\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "5\r\n10110\r\n", "output": "5\r\n"}, {"input": "5\r\n10111\r\n", "output": "5\r\n"}, {"input": "5\r\n11000\r\n", "output": "4\r\n"}, {"input": "5\r\n11001\r\n", "output": "5\r\n"}, {"input": "5\r\n11010\r\n", "output": "5\r\n"}, {"input": "5\r\n11011\r\n", "output": "5\r\n"}, {"input": "5\r\n11100\r\n", "output": "4\r\n"}, {"input": "5\r\n11101\r\n", "output": "5\r\n"}, {"input": "5\r\n11110\r\n", "output": "4\r\n"}, {"input": "5\r\n11111\r\n", "output": "3\r\n"}]
false
stdio
null
true
603/A
603
A
Python 3
TESTS
7
109
6,758,400
14930988
input() a = input() s = [] for c in a: if not s or s[-1][0] != c: s.append([c, 1]) else: s[-1][1] += 1 s2 = sorted(s, key=lambda x: x[1]) delta = 0 if s2[-1][1] >= 3 or len(s2) > 1 and s2[-2][1] >= 2: delta = 2 elif s[0][1] >= 2 or s[-1][1] >= 2: delta = 1 print(len(s) + delta)
116
62
0
170713558
n,s,c=int(input()),input(),3 for i in range(n-1):c+=s[i]!=s[i+1] print(min(n,c))
Codeforces Round 334 (Div. 1)
CF
2,015
2
256
Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not. Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.
The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000). The following line contains a binary string of length n representing Kevin's results on the USAICO.
Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.
null
In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'. In the second sample, Kevin can flip the entire string and still have the same score.
[{"input": "8\n10000011", "output": "5"}, {"input": "2\n01", "output": "2"}]
1,600
["dp", "greedy", "math"]
116
[{"input": "8\r\n10000011\r\n", "output": "5\r\n"}, {"input": "2\r\n01\r\n", "output": "2\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "75\r\n010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "75\r\n"}, {"input": "11\r\n00000000000\r\n", "output": "3\r\n"}, {"input": "56\r\n10101011010101010101010101010101010101011010101010101010\r\n", "output": "56\r\n"}, {"input": "50\r\n01011010110101010101010101010101010101010101010100\r\n", "output": "49\r\n"}, {"input": "7\r\n0110100\r\n", "output": "7\r\n"}, {"input": "8\r\n11011111\r\n", "output": "5\r\n"}, {"input": "6\r\n000000\r\n", "output": "3\r\n"}, {"input": "5\r\n01000\r\n", "output": "5\r\n"}, {"input": "59\r\n10101010101010101010101010101010101010101010101010101010101\r\n", "output": "59\r\n"}, {"input": "88\r\n1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "88\r\n"}, {"input": "93\r\n010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "93\r\n"}, {"input": "70\r\n0101010101010101010101010101010101010101010101010101010101010101010101\r\n", "output": "70\r\n"}, {"input": "78\r\n010101010101010101010101010101101010101010101010101010101010101010101010101010\r\n", "output": "78\r\n"}, {"input": "83\r\n10101010101010101010101010101010101010101010101010110101010101010101010101010101010\r\n", "output": "83\r\n"}, {"input": "87\r\n101010101010101010101010101010101010101010101010101010101010101010101010101010010101010\r\n", "output": "87\r\n"}, {"input": "65\r\n01010101101010101010101010101010101010101010101010101010101010101\r\n", "output": "65\r\n"}, {"input": "69\r\n010101010101010101101010101010101010101010101010101010101010101010101\r\n", "output": "69\r\n"}, {"input": "74\r\n01010101010101010101010101010101010101010101010101010101010101000101010101\r\n", "output": "74\r\n"}, {"input": "77\r\n01010101010101001010101010101010100101010101010101010101010101010101010101010\r\n", "output": "77\r\n"}, {"input": "60\r\n101010110101010101010101010110101010101010101010101010101010\r\n", "output": "60\r\n"}, {"input": "89\r\n01010101010101010101010101010101010101010101010101010101101010101010101010100101010101010\r\n", "output": "89\r\n"}, {"input": "68\r\n01010101010101010101010101010101010100101010100101010101010100101010\r\n", "output": "67\r\n"}, {"input": "73\r\n0101010101010101010101010101010101010101010111011010101010101010101010101\r\n", "output": "72\r\n"}, {"input": "55\r\n1010101010101010010101010101101010101010101010100101010\r\n", "output": "54\r\n"}, {"input": "85\r\n1010101010101010101010101010010101010101010101101010101010101010101011010101010101010\r\n", "output": "84\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n1111111111\r\n", "output": "3\r\n"}, {"input": "2\r\n10\r\n", "output": "2\r\n"}, {"input": "2\r\n11\r\n", "output": "2\r\n"}, {"input": "2\r\n00\r\n", "output": "2\r\n"}, {"input": "3\r\n000\r\n", "output": "3\r\n"}, {"input": "3\r\n001\r\n", "output": "3\r\n"}, {"input": "3\r\n010\r\n", "output": "3\r\n"}, {"input": "3\r\n011\r\n", "output": "3\r\n"}, {"input": "3\r\n100\r\n", "output": "3\r\n"}, {"input": "3\r\n101\r\n", "output": "3\r\n"}, {"input": "3\r\n110\r\n", "output": "3\r\n"}, {"input": "3\r\n111\r\n", "output": "3\r\n"}, {"input": "4\r\n0000\r\n", "output": "3\r\n"}, {"input": "4\r\n0001\r\n", "output": "4\r\n"}, {"input": "4\r\n0010\r\n", "output": "4\r\n"}, {"input": "4\r\n0011\r\n", "output": "4\r\n"}, {"input": "4\r\n0100\r\n", "output": "4\r\n"}, {"input": "4\r\n0101\r\n", "output": "4\r\n"}, {"input": "4\r\n0110\r\n", "output": "4\r\n"}, {"input": "4\r\n0111\r\n", "output": "4\r\n"}, {"input": "4\r\n1000\r\n", "output": "4\r\n"}, {"input": "4\r\n1001\r\n", "output": "4\r\n"}, {"input": "4\r\n1010\r\n", "output": "4\r\n"}, {"input": "4\r\n1011\r\n", "output": "4\r\n"}, {"input": "4\r\n1100\r\n", "output": "4\r\n"}, {"input": "4\r\n1101\r\n", "output": "4\r\n"}, {"input": "4\r\n1110\r\n", "output": "4\r\n"}, {"input": "4\r\n1111\r\n", "output": "3\r\n"}, {"input": "5\r\n00000\r\n", "output": "3\r\n"}, {"input": "5\r\n00001\r\n", "output": "4\r\n"}, {"input": "5\r\n00010\r\n", "output": "5\r\n"}, {"input": "5\r\n00011\r\n", "output": "4\r\n"}, {"input": "5\r\n00100\r\n", "output": "5\r\n"}, {"input": "5\r\n00101\r\n", "output": "5\r\n"}, {"input": "5\r\n00110\r\n", "output": "5\r\n"}, {"input": "5\r\n00111\r\n", "output": "4\r\n"}, {"input": "5\r\n01000\r\n", "output": "5\r\n"}, {"input": "5\r\n01001\r\n", "output": "5\r\n"}, {"input": "5\r\n01010\r\n", "output": "5\r\n"}, {"input": "5\r\n01011\r\n", "output": "5\r\n"}, {"input": "5\r\n01100\r\n", "output": "5\r\n"}, {"input": "5\r\n01101\r\n", "output": "5\r\n"}, {"input": "5\r\n01110\r\n", "output": "5\r\n"}, {"input": "5\r\n01111\r\n", "output": "4\r\n"}, {"input": "5\r\n10000\r\n", "output": "4\r\n"}, {"input": "5\r\n10001\r\n", "output": "5\r\n"}, {"input": "5\r\n10010\r\n", "output": "5\r\n"}, {"input": "5\r\n10100\r\n", "output": "5\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "5\r\n10110\r\n", "output": "5\r\n"}, {"input": "5\r\n10111\r\n", "output": "5\r\n"}, {"input": "5\r\n11000\r\n", "output": "4\r\n"}, {"input": "5\r\n11001\r\n", "output": "5\r\n"}, {"input": "5\r\n11010\r\n", "output": "5\r\n"}, {"input": "5\r\n11011\r\n", "output": "5\r\n"}, {"input": "5\r\n11100\r\n", "output": "4\r\n"}, {"input": "5\r\n11101\r\n", "output": "5\r\n"}, {"input": "5\r\n11110\r\n", "output": "4\r\n"}, {"input": "5\r\n11111\r\n", "output": "3\r\n"}]
false
stdio
null
true
127/B
127
B
PyPy 3-64
TESTS
49
62
0
180987651
import sys from itertools import combinations def qinput(): return sys.stdin.readline().strip() def qprint(string): sys.stdout.write(str(string)) def solve(n, a): counts = {} frames = 0 for stick in a: if stick in counts: counts[stick] += 1 else: counts[stick] = 1 for width in counts: for height in counts: if counts[width] >= 2 and counts[height] >= 2: if counts[width] >= 2: counts[width] -= 2 if counts[height] >= 2: counts[height] -= 2 frames += 1 ## print(f"Width: {width}, height: {height}") else: counts[width] += 2 return frames if __name__ == "__main__": n = int(qinput()) a = [*map(int, qinput().split())] result = solve(n, a) print(result)
93
46
0
166756707
n = int(input()) a = list(map(int, input().split())) a.sort() prev = None counter = 0 pairs = 0 for stick in a: counter += 1 if stick != prev: counter = 1 elif counter == 2: pairs += 1 counter = 0 prev = stick print(pairs // 2)
Codeforces Beta Round 93 (Div. 2 Only)
CF
2,011
1
256
Canvas Frames
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the sticks or glue them together. To make a h × w-sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w. Specifically, to make a square frame (when h = w), he needs four sticks of the same length. Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.
The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100).
Print the single number — the maximum number of frames Nicholas can make for his future canvases.
null
null
[{"input": "5\n2 4 3 2 3", "output": "1"}, {"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3"}, {"input": "4\n3 3 3 5", "output": "0"}]
1,000
["implementation"]
93
[{"input": "5\r\n2 4 3 2 3\r\n", "output": "1"}, {"input": "13\r\n2 2 4 4 4 4 6 6 6 7 7 9 9\r\n", "output": "3"}, {"input": "4\r\n3 3 3 5\r\n", "output": "0"}, {"input": "2\r\n3 5\r\n", "output": "0"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0"}, {"input": "14\r\n2 4 2 6 2 3 4 1 4 5 4 3 4 1\r\n", "output": "2"}, {"input": "33\r\n1 2 2 6 10 10 33 11 17 32 25 6 7 29 11 32 33 8 13 17 17 6 11 11 11 8 10 26 29 26 32 33 36\r\n", "output": "5"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n10\r\n", "output": "0"}, {"input": "2\r\n1 1\r\n", "output": "0"}, {"input": "3\r\n1 1 1\r\n", "output": "0"}, {"input": "3\r\n1 2 2\r\n", "output": "0"}, {"input": "3\r\n3 2 1\r\n", "output": "0"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1"}, {"input": "4\r\n1 2 1 2\r\n", "output": "1"}, {"input": "4\r\n1 100 1 100\r\n", "output": "1"}, {"input": "4\r\n10 100 100 10\r\n", "output": "1"}, {"input": "4\r\n1 2 3 3\r\n", "output": "0"}, {"input": "4\r\n8 5 9 13\r\n", "output": "0"}, {"input": "4\r\n100 100 100 100\r\n", "output": "1"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1"}, {"input": "5\r\n1 4 4 1 1\r\n", "output": "1"}, {"input": "5\r\n1 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 1 100 100 100\r\n", "output": "1"}, {"input": "5\r\n100 100 100 100 100\r\n", "output": "1"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "1"}, {"input": "6\r\n1 1 5 1 1 5\r\n", "output": "1"}, {"input": "6\r\n1 100 100 1 1 1\r\n", "output": "1"}, {"input": "6\r\n100 1 1 100 1 100\r\n", "output": "1"}, {"input": "6\r\n1 2 3 2 3 1\r\n", "output": "1"}, {"input": "6\r\n1 50 1 100 50 100\r\n", "output": "1"}, {"input": "6\r\n10 10 10 12 13 14\r\n", "output": "0"}, {"input": "7\r\n1 1 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 2 1 2 1 2\r\n", "output": "1"}, {"input": "7\r\n1 1 2 2 1 2 3\r\n", "output": "1"}, {"input": "7\r\n1 3 2 2 3 1 4\r\n", "output": "1"}, {"input": "7\r\n1 3 4 3 5 4 6\r\n", "output": "1"}, {"input": "7\r\n7 6 5 4 3 2 1\r\n", "output": "0"}, {"input": "8\r\n1 2 1 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 2 1 1 2 2 2\r\n", "output": "1"}, {"input": "8\r\n1 2 2 2 3 1 1 3\r\n", "output": "1"}, {"input": "8\r\n1 2 3 4 1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n1 1 1 1 2 3 2 3\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 5 5 5\r\n", "output": "1"}, {"input": "8\r\n1 2 1 3 4 1 5 6\r\n", "output": "0"}, {"input": "8\r\n1 2 3 4 5 6 1 7\r\n", "output": "0"}, {"input": "8\r\n8 6 3 4 5 2 1 7\r\n", "output": "0"}, {"input": "8\r\n100 100 100 100 100 100 100 100\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "10\r\n19 9 14 14 19 5 5 18 10 17\r\n", "output": "1"}, {"input": "10\r\n72 86 73 25 84 29 33 34 20 29\r\n", "output": "0"}, {"input": "10\r\n93 93 99 98 91 96 92 98 94 98\r\n", "output": "1"}, {"input": "13\r\n35 6 21 30 67 55 70 39 75 72 11 13 69\r\n", "output": "0"}, {"input": "17\r\n90 97 12 56 94 11 49 96 22 7 15 48 71 71 94 72 100\r\n", "output": "1"}, {"input": "18\r\n39 72 67 28 69 41 43 51 66 99 4 57 68 93 28 27 37 27\r\n", "output": "1"}, {"input": "23\r\n88 82 2 67 4 6 67 83 77 58 48 64 86 37 96 83 35 46 13 79 72 18 35\r\n", "output": "1"}, {"input": "30\r\n43 34 38 50 47 24 26 20 7 5 26 29 98 87 90 46 10 53 88 61 90 39 78 81 65 13 72 95 53 27\r\n", "output": "1"}, {"input": "33\r\n1 3 34 55 38 58 64 26 66 44 50 63 46 62 62 99 73 87 35 20 30 38 39 85 49 24 93 68 8 25 86 30 51\r\n", "output": "1"}, {"input": "38\r\n65 69 80 93 28 36 40 81 53 75 55 50 82 95 8 51 66 65 50 4 40 92 18 70 38 68 42 100 34 57 98 79 95 84 82 35 100 89\r\n", "output": "3"}, {"input": "40\r\n4 2 62 38 76 68 19 71 44 91 76 31 3 63 56 62 93 98 10 61 52 59 81 46 23 27 36 26 24 38 37 66 15 16 78 41 95 82 73 90\r\n", "output": "1"}, {"input": "43\r\n62 31 14 43 67 2 60 77 64 70 91 9 3 43 76 7 56 84 5 20 88 50 47 42 7 39 8 56 71 24 49 59 70 61 81 17 76 44 80 61 77 5 96\r\n", "output": "4"}, {"input": "49\r\n75 64 7 2 1 66 31 84 78 53 34 5 40 90 7 62 86 54 99 77 8 92 30 3 18 18 61 38 38 11 79 88 84 89 50 94 72 8 54 85 100 1 19 4 97 91 13 39 91\r\n", "output": "4"}, {"input": "57\r\n83 94 42 57 19 9 40 25 56 92 9 38 58 66 43 19 50 10 100 3 49 96 77 36 20 3 48 15 38 19 99 100 66 14 52 13 16 73 65 99 29 85 75 18 97 64 57 82 70 19 16 25 40 11 9 22 89\r\n", "output": "6"}, {"input": "67\r\n36 22 22 86 52 53 36 68 46 82 99 37 15 43 57 35 33 99 22 96 7 8 80 93 70 70 55 51 61 74 6 28 85 72 84 42 29 1 4 71 7 40 61 95 93 36 42 61 16 40 10 85 31 86 93 19 44 20 52 66 10 22 40 53 25 29 23\r\n", "output": "8"}, {"input": "74\r\n90 26 58 69 87 23 44 9 32 25 33 13 79 84 52 90 4 7 93 77 29 85 22 1 96 69 98 16 76 87 57 16 44 41 57 28 18 70 77 83 37 17 59 87 27 19 89 63 14 84 77 40 46 77 82 73 86 73 30 58 6 30 70 36 31 12 43 50 93 3 3 57 38 91\r\n", "output": "7"}, {"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": "25"}, {"input": "100\r\n1 9 3 5 10 10 9 8 10 1 7 6 5 6 7 9 1 5 8 3 2 3 3 10 2 3 10 7 10 3 6 3 2 10 1 10 2 3 4 3 3 1 7 5 10 2 3 8 9 2 5 4 7 2 5 9 2 1 7 9 9 8 4 4 6 1 6 6 4 7 2 3 1 1 1 6 9 1 2 9 3 7 6 10 3 6 2 5 2 5 3 9 10 6 4 2 9 9 4 5\r\n", "output": "23"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "7\r\n13 13 13 13 6 2 3\r\n", "output": "1"}, {"input": "8\r\n1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n100 100 99 99 5\r\n", "output": "1"}, {"input": "8\r\n2 2 2 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 6 7 7\r\n", "output": "0"}, {"input": "8\r\n4 4 4 4 4 4 4 4\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 2 2\r\n", "output": "2"}, {"input": "4\r\n100 100 100 99\r\n", "output": "0"}, {"input": "4\r\n2 2 2 2\r\n", "output": "1"}, {"input": "5\r\n100 100 99 99 2\r\n", "output": "1"}, {"input": "9\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n2 2 3 4 4\r\n", "output": "1"}, {"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": "25"}, {"input": "13\r\n1 2 3 4 5 6 7 8 9 10 11 12 13\r\n", "output": "0"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "4\r\n4 4 4 4\r\n", "output": "1"}, {"input": "5\r\n1 1 2 3 3\r\n", "output": "1"}, {"input": "5\r\n30 30 30 1 1\r\n", "output": "1"}]
false
stdio
null
true