QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#217602#5108. Prehistoric ProgramsdrldrlsWA 430ms72120kbC++174.3kb2023-10-17 02:17:092023-10-17 02:17:09

Judging History

你现在查看的是最新测评结果

  • [2023-10-17 02:17:09]
  • 评测
  • 测评结果:WA
  • 用时:430ms
  • 内存:72120kb
  • [2023-10-17 02:17:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

bool compare_neg_score(const vector<int>& a, const vector<int>& b){
    return a[2] > b[2];
}

int main(){
    // To get input n
    int count{0};
    cin >> count;

    // Process of solving this problem:
    // 1. First, in order to make a properly nested structure, the counts of '(' and ')' has to be the same.
    // Let the total '(' - ')' be total_score, and each string also has its score.

    // 2. In the final sequence, we will always have all strings with positive scores in the front,
    // and those with negative scores in the back, so there wont be strings like "))((" happens.

    // 3. But in positive strings, there could be a substring of negative scores. E.g. ")))((((((". 
    // Despite it has positive score, it cannot be paired with some positive strings like "(" in the front.
    // Thus, we need to calculate another score "neg_score" to indicate the substring (from the start of the string) with smallest negative score.

    // 4. If all positive strings has neg_score < 0, then it's "impossible", since it must starts with ')'.

    // 5. Sort all positive strings by their neg_score (decreasing).
    // This can guaruntee we find the possible answer without choose something like "))((" as the first string and return "impossible".
    // Check each time if the total_score - new neg_score is >= 0. If not, return "impossible".
    
    // 6. After checking all the positive strings, check the negative strings for the sequence. 
    // Reverse all negative string and check like positive strings. It's like checking the string from behind.
    // Reverse means flip all ( & ) and reverse the order.
    // When they meet in the middle, we can check if total_score = 0.
    
    // 7. If it's a valid nested structure (total_score = 0), print out the sequence. Else print "impossible".
    
    // *strings with score = 0 are stored to positive strings.

    vector<vector<int>> pos_strings(0); // save strings with positive score 
    vector<vector<int>> neg_strings(0); // save strings with negative score
    bool wrong = false; // save whether it's impossible 

    // Getting input strings
    for(int i = 0; i < count; i++){
        string s;
        int score{0}, neg_score{0}, temp_neg{0}, pos_score{0}, temp_pos{0};
        cin >> s;

        // calculate score & neg_score. Fkip the negative strings
        score = 2 * std::count(s.begin(), s.end(), '(') - s.length();

        if(score < 0){
            for(char c: s){
                if(c == '(') c = ')';
                else c = '(';
            }
            reverse(s.begin(), s.end());
        }

        for(char c: s){
            if(c == '('){
                temp_neg++;
                score++;
            }else{
                temp_neg--;
                score--;
            }
            neg_score = temp_neg < neg_score ? temp_neg : neg_score;
        }

        // save the strings to corresponding vectors
        vector<int> v = {i + 1, score, neg_score};
        if(score >= 0) pos_strings.emplace_back(v);
        else neg_strings.emplace_back(v);
    }

    // sort positive strings by neg_score (function defined above)
    sort(pos_strings.begin(), pos_strings.end(), compare_neg_score);
    sort(neg_strings.begin(), neg_strings.end(), compare_neg_score);
 
    // check each round that if the score went below 0. If so, print "impossible" and return
    int total_pos_score{0}; // save the current score 
    for(auto s: pos_strings){
        total_pos_score += s[1];
        if(total_pos_score + s[2] < 0){
            cout << "impossible";
            return 0;
        }
    }

    // check negatve strings
    int total_neg_score{0}; // save the current score 
    for(auto s: neg_strings){
        total_neg_score -= s[1];
        if(total_neg_score + s[2] < 0){
            cout << "impossible";
            return 0;
        }
    }

    if(total_pos_score != total_neg_score) cout << "impossible";
    else{
        // print results after passing all the checks, print neg strings in reverse order
        for(auto s: pos_strings) cout << s[0] << " ";
        for(auto it = neg_strings.rbegin(); it != neg_strings.rend(); it++) cout << (*it)[0] << " ";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 16ms
memory: 5972kb

input:

50000
(
(
))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()(
)
(
)
(((
(
(
(
(
(
()
(
)
(
)((())()((
)))))(
(
)
))
)()
(
)
)
)()(
(
(
()
(
)
(
)()((((())()))())(
(
(
)(
(
(
(()())())
)
)
(
(
(
)((())))((())))))))))((((()()))()))))))))((()())()))
)
)()
)
)
)
)
)
())(())))))()(()((()(())...

output:

31744 31767 31765 31764 31763 31759 31757 31755 31754 31753 31750 31747 31768 31743 31740 31738 31736 31734 31727 31726 31722 31721 31711 31710 31796 31818 31817 31815 31814 31812 31809 31806 31803 31801 31799 31798 31705 31795 31794 31793 31789 31787 31785 31784 31782 31777 31775 31634 31658 31656 ...

result:

ok good plan

Test #2:

score: 0
Accepted
time: 2ms
memory: 3840kb

input:

1000
(
))(()))
((((())())))((())(()))(
)(
)
)))
))((()(((((((())()(())()())))(()(())()())))))))((()((()())()())(())))()((()())
)((()()()(())(()))()(())()))(()))))())))))))))))))()))(()()(())(()))())()()))))(())()()()((())(()))(())))))))(()()())()))()())))()()))))))(
)))(((
(
)))()()())))
(
(((())(((...

output:

554 576 575 573 570 566 564 563 562 561 560 557 577 553 544 535 534 524 522 517 516 514 511 502 619 655 653 652 650 646 640 638 636 632 628 626 498 617 615 611 604 598 596 595 590 585 584 387 422 420 414 410 408 406 399 398 397 396 390 426 386 384 382 381 379 377 372 371 356 347 345 460 496 489 481 ...

result:

ok good plan

Test #3:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

2
()
()

output:

1 2 

result:

ok good plan

Test #4:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

2
((
))

output:

1 2 

result:

ok good plan

Test #5:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

2
)(
()

output:

impossible

result:

ok impossible

Test #6:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

3
()
(
)

output:

1 2 3 

result:

ok good plan

Test #7:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

3
)(
(
)

output:

2 1 3 

result:

ok good plan

Test #8:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

5
))(
(()
)(
(
)

output:

2 4 3 5 1 

result:

ok good plan

Test #9:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

3
((
))())
(

output:

1 3 2 

result:

ok good plan

Test #10:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

6
)
()
()()()
((
)
)

output:

impossible

result:

ok impossible

Test #11:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

500
(
)
)
(
)(
(
(
)
))(
(
(
(
(
)
)
(
(
)
(
(
)
(
()(()
(
)())
(
(
)
(
)()((
(
)
(
)
)
(
(
(
)
(
(
)
)
)(
(
(
)
)
(
)
(
(
(
)
(
(
())))
(
(
(
)
(
)
)
(
(
)
)
(
(
(
(
(
()
(
(
(
(
(
((
)
(
(
)
(
(
(
)
())
(
(
(
)
(
(
(
)
)
(
)
)
(
)
(
(
(
(
)
(
)
)
)
)
(
)
)))()(
(
)
)
(
)
)(
)
(
)
)
))
(
(
(
(
(
(
...

output:

334 290 296 297 304 308 309 311 315 318 320 321 325 327 329 330 288 338 339 340 343 344 345 348 349 350 351 353 356 357 360 362 262 232 234 239 1 241 242 243 247 248 249 251 253 254 256 258 366 264 265 268 269 271 274 275 277 282 283 284 285 286 287 467 434 435 436 437 438 439 440 442 443 445 449 45...

result:

ok good plan

Test #12:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

50
)
)
((((()())())))(())(())
()(((()))
(((()))(()
()(((
))
)
)()))(()(()())(((((()
(
)
)
)((
)()((
())()))
(())))()
(((
))))(()
()(())(()))())()
)
)
(
(
(
(
((())()())())))(((())
()(
(()(())()((()
()(((()())))())()(
)
)((()
(
)
((
)
()(
(
(
)
)))((())
)
()))()(((()(()
((
((()))(())(()())(()())())()...

output:

4 43 38 37 36 34 32 28 27 25 24 23 22 17 10 6 5 3 14 29 31 13 46 42 9 45 44 50 49 15 16 19 26 18 40 7 48 8 11 12 47 41 20 21 1 30 33 35 39 2 

result:

ok good plan

Test #13:

score: 0
Accepted
time: 0ms
memory: 3496kb

input:

50
)
(
)()(
())(
()()(((((())(
)(())(()((())(()(()))(())())))))(())()))()())))))()(()()))(())))(()(((())(())()((())())()())(())())))()((()(()(())((()()))))()((((())()())((()))))((()()(())))))(()(())(()(()((())(()(())((()())))())(()))()())))()()((((()()((()()))((())())))()(())((()()((()((())())(()(()...

output:

15 33 40 28 26 41 2 18 16 13 11 8 5 46 47 19 42 44 37 10 4 3 29 21 6 31 36 12 17 39 43 32 7 9 14 20 22 23 24 25 27 1 34 35 38 45 48 49 50 30 

result:

ok good plan

Test #14:

score: 0
Accepted
time: 1ms
memory: 3616kb

input:

150
))(()))(())(())))()))())()()()(())(((())))()))))()
)))()(()()(()((())())))(()(()(())((())))(((()(((())()()())))()())(((((((()))((())((())(())())(()))()(()()()()((((()))(()())))()(()((()(()(((((()((()())()))((((()))()))(()(((()()(((()(((()(((())(())())(()((()))))))()())((()(())())))((()()(()(((()...

output:

79 38 40 140 136 48 49 52 53 130 60 69 73 149 84 87 92 94 98 100 103 104 105 106 111 120 148 15 17 14 143 12 20 11 24 142 7 6 28 4 37 141 32 35 117 10 5 96 93 91 89 23 137 135 27 51 133 129 61 62 70 16 102 147 77 29 122 3 125 2 9 25 86 18 41 43 47 56 115 134 150 59 45 30 85 19 55 72 50 81 31 71 63 1...

result:

ok good plan

Test #15:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

150
)))(
(()
(())((())))(()))()(()
((((()(((()))()(((((())()(()()((((()))((((()(())()(()))(()(())())(())(())))(((()))(())()))()((())((()(()(())())))))()(((()(()()())()))))()))(()(()()()(()(())()))))()))(((((())(()())((()()((((()))))(())())(())(())((()()(())))((((())((((()))()))()))))))))()())))))
(
...

output:

98 51 52 56 58 61 64 2 70 86 87 89 94 66 100 104 118 121 127 128 129 141 142 148 149 150 37 26 32 19 36 15 14 10 42 49 46 4 5 44 8 50 16 18 117 113 112 107 145 102 23 29 55 84 80 75 74 53 136 63 39 76 114 82 34 90 88 85 144 21 13 140 41 7 62 45 122 81 96 79 139 12 125 40 111 123 22 108 115 33 116 78...

result:

ok good plan

Test #16:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

150
)()((
)
)))())))
)()())((()(()())((())()))(()))(())((((((((()()(())())(()(((()))())()((()((())())))))))()((()))))((()(((()(((((()))()))((()((()()))(())))))()))))()())()()())(())(())(()))())((((((()()()))()((((()))))))((())()))()(()((()(())(())(())()())(())
()()
)
(())()))(())(()((())()()())())((...

output:

106 60 65 67 68 74 75 81 84 89 92 93 97 98 99 5 108 110 111 115 117 118 122 123 129 130 131 136 140 149 48 36 30 27 45 50 52 55 8 58 127 11 57 124 19 24 9 26 1 31 100 42 63 56 70 46 88 119 146 128 14 15 120 82 114 35 91 101 37 107 133 43 32 90 78 12 44 61 112 7 64 109 125 85 134 72 77 71 132 116 20 ...

result:

ok good plan

Test #17:

score: 0
Accepted
time: 2ms
memory: 3608kb

input:

750
(()()((()((((())()((()))()()))()))(()()(()))(()(())()))((((((
)))))))
)
((()()()(())((()(()())(())(((()((((()))(()(())((())(()())(())())))())))()(())()))((()(()((((()(()))(()())()((()()()))))(())())(())())())()((()(
)
)
(
)()(((()(())))()))))(((((((()))()()()(()())))(()())(()((
(
)
)(()))
((())(...

output:

437 470 469 468 461 455 450 446 442 441 440 473 434 432 429 427 426 425 419 418 417 495 530 526 522 518 516 512 504 502 500 414 494 492 491 490 489 485 481 477 475 348 378 374 371 369 368 362 361 360 358 357 379 345 343 341 338 335 333 332 331 330 395 409 408 407 406 405 401 400 397 396 541 394 392 ...

result:

ok good plan

Test #18:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

100
)
)
)
(
)
(
))))()
)
(
(
(
(
)
)
)
)
(
(
(
(
())
(
)
)
)((
)
(
(
(
)
(
(
)
)
)
)
()((
(
)
)
)
)(((
((((
(
)
(
)
((
)
(
(
)
(
())(()))
)
)
(
)
(
(
(
(
)))()()
)
(
(
(
(
)
(
)
)
)
(
)
)
)
)
(
)
(
(
)
(
)
(
(
(
)
)
(
)
)
(
)((((
)
)
()((()()(()))))
)
(

output:

70 51 53 57 59 60 61 62 65 66 67 68 50 74 79 81 82 84 86 87 88 91 94 100 27 6 9 10 11 12 17 18 19 20 22 4 28 29 31 32 37 38 43 44 46 48 25 42 95 98 7 54 63 21 47 45 41 40 39 36 35 34 33 30 49 24 23 16 15 14 13 8 5 3 2 26 99 97 96 93 92 90 89 85 83 80 78 52 76 75 73 72 71 69 64 58 56 55 1 77 

result:

ok good plan

Test #19:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

100
)
()(
(
)
(
)
(
(
)
)
)(()
)
)))
)
)
(
(
(
)
(
(
)
(
)
(
(
(
))(
(
(
))((
(
)
(
))())
)
(()
)
)
(
)
(
(
)
)
(
)
(
))
(
(
)
)
(
)
)
)
)
(
())
)
(
(
)
)
(
)
(
))
(
)
)
(
(
(((
(
(
(()
)
)()())(()((()((())
(
)
)
(
(
)
)
(
)
(
)
(
))(
)
(
(
(
)
(
(((())

output:

impossible

result:

ok impossible

Test #20:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

100
)
)
()))((((
))()
(
(
(
)
(
)
(
(
)
()
(
(
)
)
(
)
(
(
)
)
)
(
)
)
(
(
)
)
(
)
)
)
)
(
(
)
((
(
(
)
)
(
(
)
(
)
(()((
)
(
)
)
(()))()()())))()()((
(
)
)
(
(
(
)
)
(
(
)
(
(
(
)
(
(
)
)(
(
)
)
)
(
(())())(()
)
)
(
()
((
(
)
)
)
)
(
)
(
(
)
)
(
())
)(

output:

72 51 53 57 60 61 62 65 66 68 69 70 5 73 76 80 84 85 86 87 92 94 95 98 47 6 7 9 11 12 14 15 16 19 21 22 26 29 30 33 38 39 41 42 43 46 49 75 81 100 3 56 99 4 48 44 40 37 36 35 34 32 31 28 27 25 24 23 20 18 17 13 10 8 1 45 97 96 93 91 90 89 88 83 82 79 78 2 74 71 67 64 63 59 58 55 54 52 50 77 

result:

ok good plan

Test #21:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

100
(
(
)
(
)
(
(
(
(
)
)
)
)
()
)(
)
)
(
(
)
(
(
)
)
)
(
)
(
(
))))
(
)
(
)
(
(
(
()()(
)
())
(
(
)
)
(
(
)
(
(
)
)
(
(
(
(
(
)
(
(
(((
)
)
)
))))
(
))(
)
)
()
())()
)
)
(
)))
(
)((()))(
(
(((
((
(
)
(
(
)
(
)
)
()
)()
)
)
()))()(
)(())(
)
(
(
(
(
)(
)

output:

75 49 52 53 54 55 56 58 59 60 65 69 73 2 77 78 79 80 82 83 85 88 95 96 97 98 26 6 7 4 8 9 14 1 18 19 21 22 48 28 29 31 33 35 36 37 38 41 42 45 46 99 93 15 76 64 30 74 92 40 70 44 43 39 34 32 27 25 47 23 20 17 16 13 12 11 10 5 24 100 94 91 90 89 87 86 84 81 51 71 68 67 66 63 62 61 57 3 50 72 

result:

ok good plan

Test #22:

score: 0
Accepted
time: 1ms
memory: 3684kb

input:

1000
(())())()(((())()())(((()(()))((()((((()())))())))))(()(()((())(((()))()(()
)
(
)
()
)
)((()))))
)
((((((()))()())))))((()(
((
()(()())))(()
)()
(
((
(
)
)
)(()
)))(
)
))
(
(()))))
)(())(((())((((
)
)
(
(
())))(())
(((
(
(((
())()(
()())
)
)
)
(
))))())(
)
))(
)
())(()(()))))()(()((())((((()())...

output:

impossible

result:

ok impossible

Test #23:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

1000
))(()))
(
)))(
)
((
()))()))))()()(
))))((((((((()()(())((()()
(
)
)()(()
(
()))))()
(
(()(()(((()())(((((((())()()())())(())()))))((()((())((((((()(()()
)(()())((()))
(((
)
)
(
)((
(
(
)
(
)
()(())(((
(
)
(
(
)
()(()(()()(()()((()))())((()())))))((())(((()()(())(()()())(()()(((())()(()((((((((...

output:

impossible

result:

ok impossible

Test #24:

score: 0
Accepted
time: 2ms
memory: 4032kb

input:

4000
(
)
))
)()))))(
(
)
(
)
)
)
)((()((
(
)
)()(
)
)
)
)
(
)
(
)
)
(
()))((()))))()((()(
(
)))
(
)
(
(
(
(
)
)()(()()(()()))))())
)
)
)(((
)
)
)
)
(
(
)
))()()))((())
(
(
)
(
))(
(
)
)
(
)
)
())(
)
(
(
(
)
())))(())((()(()()((()((
(
)
)
(
)
)
)
)
)
)
)
)
(
)
(()))))(
)
)
(
())))(((())()(
(
(
()(
(
...

output:

impossible

result:

ok impossible

Test #25:

score: 0
Accepted
time: 349ms
memory: 72120kb

input:

1000000
)
(
)()(((()))(
(
(
(
)
(
(
)
)
(((())((()(()((())
(
)
)(
)
)
))))(()))()())(()((()))(()()()))()()()))))))))(())))((((()(()()))((((((()((((()()(
)
((
)
)
(
)
())()()((
)
)))(())((()))((()()))(()(())())))())))())))(()()(
(
()(
(
(
()()
)
))
)
(
(
(
)
)
)
(
)
(
)
)
)
)(()))()))
(
)
)))
(
)
(
(...

output:

641462 641493 641489 641488 641485 641484 641480 641479 641476 641474 641473 641471 641469 641465 641464 641494 641461 641460 641459 641456 641454 641453 641451 641448 641446 641445 641443 641441 641437 641436 641523 641555 641548 641547 641546 641545 641544 641542 641541 641536 641533 641532 641530...

result:

ok good plan

Test #26:

score: 0
Accepted
time: 116ms
memory: 19252kb

input:

1
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

impossible

result:

ok impossible

Test #27:

score: 0
Accepted
time: 103ms
memory: 19572kb

input:

1
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))...

output:

impossible

result:

ok impossible

Test #28:

score: 0
Accepted
time: 105ms
memory: 18892kb

input:

1
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

1 

result:

ok good plan

Test #29:

score: 0
Accepted
time: 109ms
memory: 19492kb

input:

1
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

impossible

result:

ok impossible

Test #30:

score: 0
Accepted
time: 100ms
memory: 20576kb

input:

1
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

impossible

result:

ok impossible

Test #31:

score: 0
Accepted
time: 103ms
memory: 17392kb

input:

2
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))...

output:

2 1 

result:

ok good plan

Test #32:

score: 0
Accepted
time: 107ms
memory: 17736kb

input:

2
)()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()(...

output:

impossible

result:

ok impossible

Test #33:

score: 0
Accepted
time: 98ms
memory: 19440kb

input:

3
)()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()(...

output:

3 1 2 

result:

ok good plan

Test #34:

score: 0
Accepted
time: 260ms
memory: 59108kb

input:

1000000
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((...

output:

impossible

result:

ok impossible

Test #35:

score: 0
Accepted
time: 271ms
memory: 58056kb

input:

1000000
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))...

output:

impossible

result:

ok impossible

Test #36:

score: 0
Accepted
time: 337ms
memory: 57796kb

input:

1000000
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))...

output:

666658 666688 666686 666684 666682 666680 666678 666676 666674 666672 666670 666668 666666 666664 666662 666660 666690 666656 666654 666652 666650 666648 666646 666644 666642 666640 666638 666636 666634 666632 666630 666720 666750 666748 666746 666744 666742 666740 666738 666736 666734 666732 666730...

result:

ok good plan

Test #37:

score: 0
Accepted
time: 298ms
memory: 58012kb

input:

999999
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)...

output:

833328 833343 833342 833341 833340 833339 833338 833337 833336 833335 833334 833333 833332 833331 833330 833329 833344 833327 833326 833325 833324 833323 833322 833321 833320 833319 833318 833317 833316 833315 833314 833359 833374 833373 833372 833371 833370 833369 833368 833367 833366 833365 833364...

result:

ok good plan

Test #38:

score: 0
Accepted
time: 430ms
memory: 67052kb

input:

1000000
)(
()(()))()((
)())
)()((((((
((((
))))))))()())((()(
)((
)())
))()((()
()
(
)(
()(
(((()((()())(()))(((())(((
)()()
)))(
(((
(()(()(())))(())))(((((
())())((()))(
(())
(()
()))(()(())()())(
())((
)))))))))
())()((())))(
()())((((()())()
((
()())
()((())
)()))))))))()())()))())
()())
)()())
...

output:

792159 360775 792142 360773 792148 792149 792150 792153 792154 575472 360779 360759 360756 360755 360754 360752 360751 575473 360746 360791 360812 360810 669464 360806 360805 360802 792137 360795 360793 575474 360789 669463 360787 792140 360785 792141 360783 360782 792196 360713 792181 792182 792184...

result:

ok good plan

Test #39:

score: 0
Accepted
time: 427ms
memory: 66580kb

input:

1000000
)()))))(()(((()
()((((()))
)())
)
()()(
()
())()((())))))())()(())(())
())))()())((
)()()((()((())
)
)()(
()()(
((())((
)(
(
)((()((()((()(())(()())
))()
())
()()()
(())
))()(()(()()()()((
(())))()((((()()(
(())
)())((()))
))(()
()()()(()(()()((((())))((())))(()()(()))))
(()()))()(())))()))(...

output:

564089 564128 564127 564119 564115 564114 564113 564111 564109 564106 564103 564102 564096 564135 564086 564082 564078 564077 564076 564071 564070 564069 564066 564061 564060 564163 564190 564187 564182 564181 564180 564179 564175 564174 564173 564172 564168 564059 564161 564160 564159 564156 564155...

result:

ok good plan

Test #40:

score: -100
Wrong Answer
time: 138ms
memory: 3840kb

input:

564
)())((())((()))))(()())((((()()(()(()))(()((((()()))(((()))(()()()(()((()()()()((()))))((())))()(()((())(()())))))))())))(((())()()()))))()((((()()))()(()()())))(()()(())((())((()())(()()())()(((()))()())())))(((()(((((()())()())))()()((())))()()()(()()))()(()()()(((())())))(()(()(()((())()((()(...

output:

impossible

result:

wrong answer you didn't find a solution but jury did