QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#605119#8759. 小班课UESTC_DECAYALIAC ✓27ms7016kbC++202.2kb2024-10-02 15:35:382024-10-02 15:35:39

Judging History

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

  • [2024-10-02 15:35:39]
  • 评测
  • 测评结果:AC
  • 用时:27ms
  • 内存:7016kb
  • [2024-10-02 15:35:38]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cassert>
#define RI register int
#define CI const int&
using namespace std;
const int N=505,INF=1e9;
int T,n,m,b[N],valid[N],mat[N],val[N*N],pre[N*N],rb[N],L[N],R[N],vis[N*N]; vector <int> v[N],a[N];
inline bool find(CI now,CI idx)
{
    for (auto to:v[now]) if (vis[to]!=idx)
    {
        vis[to]=idx;
        if (!pre[to]||find(pre[to],idx))
        return pre[to]=now,1;
    }
    return 0;
}
int main()
{
   	//freopen("1.in","r",stdin);
    for (scanf("%d",&T);T;--T)
    {
        scanf("%d%d",&n,&m);
        for (RI i=1;i<=n;++i) valid[i]=1,v[i].clear(),mat[i]=0;
        int idx=0;
        for (RI i=1;i<=m;++i)
        {
            scanf("%d",&b[i]);
            L[i]=idx+1;
            for (RI j=1;j<=b[i];++j) val[++idx]=i;
            R[i]=idx;
        }
        for (RI i=1;i<=n;++i)
        {
            int x; scanf("%d",&x); a[i].resize(x);
            for (RI j=0;j<a[i].size();++j)
            {
                scanf("%d",&a[i][j]);
                for (RI k=L[a[i][j]];k<=R[a[i][j]];++k)
                v[i].push_back(k);
            }
        }
        for (RI i=1;i<=idx;++i) pre[i]=vis[i]=0;
        int flow=0;
        for (RI i=1;i<=n;++i) flow+=find(i,i);
        printf("%d\n",flow);
        for (RI i=1;i<=idx;++i)
        if (pre[i]) ++rb[mat[pre[i]]=val[i]];
        //for (RI i=1;i<=n;++i) printf("%d%c",mat[i]," \n"[i==n]);
        vector <int> ans;
        for (RI k=1;k<=n;++k)
        {
            bool find=0;
            for (RI i=1;i<=n;++i)
            {
                if (!valid[i]) continue;
                bool flag=1;
                for (auto x:a[i])
                {
                    if (x==mat[i]) break;
                    if (rb[x]>0) { flag=0; break; }                                                     
                }
                if (flag)
                {
                    ans.push_back(i); valid[i]=0;
                    --rb[mat[i]]; find=1; break;
                }
            }
            assert(find==1);
        }
        for (auto x:ans) printf("%d ",x); putchar('\n');
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 4136kb

input:

3
5 5
1 1 1 1 1
4 1 3 2 4
1 5
4 3 4 2 1
2 3 5
1 1
5 3
1 2 2
2 1 2
2 1 2
2 1 3
2 1 3
2 1 3
5 5
1 1 1 1 1
2 1 2
2 5 4
2 3 2
2 4 3
2 5 1

output:

5
2 4 3 5 1 
5
5 1 2 3 4 
5
1 5 2 4 3 

result:

ok Correct!

Test #2:

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

input:

250
2 1
2
1 1
1 1
1 1
1
0
2 2
1 1
1 1
2 2 1
2 2
0 2
2 1 2
1 2
1 1
1
1 1
1 2
1 0
0
1 2
1 0
0
2 1
2
1 1
0
1 2
1 0
0
2 1
2
1 1
1 1
1 1
1
1 1
1 2
1 0
1 2
2 2
2 0
1 1
1 2
1 1
1
0
1 1
1
0
1 2
0 1
1 1
2 2
1 1
1 1
2 1 2
2 2
1 1
2 2 1
2 2 1
1 2
0 1
1 2
2 1
2
1 1
0
2 2
2 0
1 1
1 2
1 1
1
1 1
2 1
2
0
1 1
1 1
1
...

output:

2
1 2 
0
1 
2
1 2 
2
1 2 
1
1 
0
1 
0
1 
1
1 2 
0
1 
2
1 2 
1
1 
0
1 
1
1 2 
0
1 
0
1 
0
1 
2
1 2 
2
2 1 
1
1 
1
1 2 
1
1 2 
1
1 
1
1 2 
1
1 
1
1 2 
0
1 2 
1
1 
1
1 
0
1 
1
1 
2
1 2 
0
1 
0
1 
1
1 2 
2
1 2 
0
1 
0
1 
0
1 
0
1 2 
2
1 2 
1
1 
1
1 
0
1 
0
1 
0
1 
1
1 
1
1 
0
1 
2
1 2 
2
1 2 
1
1 2 
1
1...

result:

ok Correct!

Test #3:

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

input:

166
3 3
1 1 1
0
2 2 3
0
3 3
0 3 0
0
2 1 3
0
3 3
0 0 3
0
2 2 3
0
3 3
2 0 1
2 2 3
0
2 3 2
3 3
0 2 1
2 3 1
0
2 2 1
3 3
1 1 1
2 3 1
2 1 2
1 3
3 3
2 1 0
1 3
0
0
3 3
1 1 1
1 2
0
2 2 3
3 3
1 1 1
0
1 2
2 2 1
3 3
0 0 3
1 1
2 1 3
1 3
3 3
0 1 2
2 2 3
2 2 3
0
3 3
2 0 1
0
1 1
0
3 3
1 2 0
2 2 1
1 1
0
3 3
1 0 2
0
...

output:

1
1 2 3 
0
1 2 3 
1
1 2 3 
1
1 2 3 
2
1 2 3 
3
3 1 2 
0
1 2 3 
2
1 2 3 
2
1 2 3 
2
1 2 3 
2
2 1 3 
1
1 2 3 
2
1 2 3 
1
1 2 3 
1
1 2 3 
2
1 2 3 
2
1 2 3 
0
1 2 3 
2
1 2 3 
0
1 2 3 
1
1 2 3 
2
1 2 3 
1
1 2 3 
3
1 2 3 
3
1 2 3 
0
1 2 3 
1
1 2 3 
2
1 2 3 
2
1 2 3 
2
2 1 3 
2
1 2 3 
1
1 2 3 
2
1 2 3 
1
1...

result:

ok Correct!

Test #4:

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

input:

125
4 4
3 1 0 0
1 2
0
2 1 3
3 2 3 1
4 4
2 0 1 1
2 1 3
2 1 2
2 4 1
0
4 4
2 0 1 1
2 2 3
3 3 2 4
1 2
0
4 4
0 1 1 2
2 3 1
1 4
3 1 2 4
0
4 4
1 1 1 1
2 3 2
2 4 2
0
2 4 2
4 4
2 2 0 0
3 2 1 4
2 3 4
1 2
1 3
4 4
2 0 0 2
1 2
3 3 2 1
2 3 2
2 2 1
4 4
1 2 0 1
1 4
0
0
0
4 4
3 0 0 1
3 2 1 3
0
2 1 4
2 4 3
4 4
1 2 1 ...

output:

3
1 2 3 4 
3
1 2 3 4 
2
1 2 3 4 
3
1 2 3 4 
3
1 3 4 2 
2
1 2 3 4 
2
1 2 3 4 
1
1 2 3 4 
3
1 2 3 4 
3
2 3 1 4 
0
1 2 3 4 
2
1 2 3 4 
2
1 2 3 4 
2
1 2 3 4 
4
2 3 4 1 
2
1 2 3 4 
2
1 2 3 4 
2
1 2 3 4 
3
1 2 3 4 
4
1 2 3 4 
3
1 2 3 4 
1
1 2 3 4 
2
1 2 3 4 
3
1 2 3 4 
2
1 2 3 4 
4
1 2 3 4 
2
1 2 3 4 
3
1...

result:

ok Correct!

Test #5:

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

input:

100
5 5
2 1 2 0 0
0
2 3 2
3 5 4 3
2 1 2
0
5 5
0 2 0 0 3
1 5
0
1 1
0
0
5 5
0 1 3 0 1
2 5 4
2 1 5
0
0
3 3 1 4
5 5
1 1 0 2 1
1 2
0
2 4 5
0
1 4
5 5
0 1 1 2 1
2 4 2
0
2 1 3
0
1 1
5 5
0 0 2 2 1
2 4 3
1 4
0
3 5 4 1
3 5 1 2
5 5
1 2 1 0 1
2 1 2
0
3 3 5 2
2 4 3
0
5 5
1 0 1 1 2
0
1 4
1 3
1 3
0
5 5
1 2 1 1 0
1 ...

output:

3
1 2 3 4 5 
1
1 2 3 4 5 
2
1 2 3 4 5 
3
1 2 3 4 5 
2
1 2 3 4 5 
4
2 3 5 4 1 
3
1 2 4 3 5 
2
1 2 3 4 5 
1
1 2 3 4 5 
4
1 2 3 4 5 
2
1 2 3 4 5 
2
1 2 3 4 5 
3
1 2 3 4 5 
3
2 3 4 1 5 
3
1 2 3 4 5 
3
1 3 2 4 5 
2
1 2 3 4 5 
3
1 2 3 4 5 
1
1 2 3 4 5 
3
1 2 3 4 5 
1
1 2 3 4 5 
2
1 2 3 4 5 
2
1 2 3 4 5 
2...

result:

ok Correct!

Test #6:

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

input:

10
45 47
3 0 2 0 1 1 1 0 2 0 1 0 0 3 0 0 0 4 0 1 0 0 1 2 1 1 1 0 1 1 1 0 0 0 0 1 0 0 0 1 2 4 1 2 1 2 3
7 1 37 21 3 13 43 22
0
10 23 46 22 40 12 19 47 27 16 42
4 29 19 45 35
10 6 26 2 43 41 7 9 16 42 44
5 39 40 34 46 14
3 34 3 38
8 10 5 38 23 19 37 9 34
0
5 31 29 15 13 35
3 40 4 28
1 7
6 29 12 9 35 2...

output:

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

result:

ok Correct!

Test #7:

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

input:

1
499 497
1 2 0 2 0 1 0 0 0 2 1 2 0 3 1 2 0 0 0 1 0 1 0 2 1 0 1 0 1 1 1 2 0 1 0 1 0 2 2 3 1 1 2 1 0 0 1 0 2 3 0 1 0 0 2 0 1 2 1 0 0 1 2 0 0 2 0 2 0 1 0 1 0 0 1 0 0 1 1 1 1 1 0 0 0 1 2 3 0 0 0 4 2 2 1 2 2 0 1 0 1 0 2 0 1 0 2 0 0 1 1 1 3 2 0 2 2 2 0 1 1 1 1 1 0 1 0 1 1 1 1 1 2 0 0 1 0 2 1 2 1 2 1 0 1 ...

output:

482
4 5 8 10 11 15 17 18 19 21 23 28 30 31 35 14 40 41 42 52 53 56 57 59 61 63 66 67 68 69 50 70 71 73 74 75 76 81 82 84 85 87 89 91 92 94 95 96 102 103 104 106 108 110 112 115 120 122 124 126 130 131 132 135 136 137 139 141 142 143 148 150 151 153 79 146 165 167 169 170 171 20 99 116 172 175 34 176...

result:

ok Correct!

Test #8:

score: 0
Accepted
time: 12ms
memory: 5824kb

input:

1
498 499
0 1 1 0 1 0 1 0 0 0 0 2 0 3 1 2 4 0 1 0 1 1 0 0 0 1 1 0 0 2 2 0 1 1 1 0 4 1 1 2 1 0 0 1 2 0 1 2 1 0 1 2 0 2 1 2 2 0 2 2 0 1 0 2 0 0 3 0 1 1 1 1 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 2 1 1 0 1 0 1 0 0 0 1 1 2 0 1 0 2 1 1 2 2 0 0 0 0 2 0 2 1 0 1 0 2 0 1 3 1 1 1 0 1 3 0 1 0 1 0 0 1 3 2 3 2 1 1 0 2 ...

output:

498
1 2 3 4 7 8 9 10 11 14 20 22 23 24 26 27 25 28 29 32 33 34 35 36 39 40 41 42 44 45 47 52 53 58 61 66 63 70 72 15 73 74 76 77 83 85 86 88 91 92 96 100 101 46 103 104 106 109 111 114 116 117 118 120 126 129 132 133 135 136 141 142 84 147 148 150 152 156 62 157 158 160 161 162 167 168 171 172 176 1...

result:

ok Correct!

Test #9:

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

input:

5
99 96
2 0 0 1 1 2 1 0 1 1 1 0 0 0 1 0 1 1 2 1 1 1 1 1 0 1 2 4 0 0 0 2 2 1 1 1 1 1 0 2 0 0 0 1 1 3 0 1 0 0 1 2 1 4 1 2 1 0 1 0 0 2 0 0 0 2 3 2 1 0 1 2 2 0 1 1 0 0 1 0 0 1 2 1 3 1 3 1 3 0 3 0 0 2 2 2
2 14 58
1 55
2 53 69
0
0
1 76
2 23 38
1 41
2 74 54
0
0
2 83 91
0
0
0
1 48
0
0
1 96
2 76 52
1 17
2 51...

output:

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

result:

ok Correct!

Test #10:

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

input:

5
99 97
0 2 4 0 0 2 0 1 1 1 0 1 0 3 0 1 1 1 1 0 0 1 0 0 1 2 0 0 1 3 1 2 0 2 1 1 1 3 3 1 2 1 0 1 0 1 0 2 0 0 0 0 1 2 3 1 1 1 0 1 0 1 0 0 1 2 1 2 1 1 1 2 2 3 1 1 0 0 1 1 0 0 1 1 2 1 2 2 0 1 1 1 2 0 1 3 1
2 56 63
2 52 45
4 26 56 80 10
2 27 19
1 81
2 38 64
1 83
1 8
3 14 81 60
3 63 28 15
5 59 33 80 88 56...

output:

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

result:

ok Correct!

Test #11:

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

input:

5
99 98
4 0 1 1 3 2 0 1 4 0 1 1 2 2 1 2 0 0 1 2 1 2 0 1 1 1 2 0 2 0 0 3 0 2 0 0 1 1 1 0 1 1 1 2 0 1 1 0 1 1 1 0 0 1 0 0 2 1 2 3 3 0 0 0 0 0 1 2 1 1 0 3 0 0 0 1 2 0 0 0 0 1 0 2 2 1 2 1 0 1 0 0 1 1 2 3 3 0
5 72 78 90 7 60
6 69 37 10 41 4 59
10 61 85 79 5 7 58 3 55 1 50
6 59 24 30 26 77 21
2 29 21
10 7...

output:

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

result:

ok Correct!

Test #12:

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

input:

5
97 100
1 1 1 0 0 1 0 1 1 2 0 1 2 0 1 0 2 3 0 1 0 1 0 1 0 0 1 0 1 2 0 3 2 2 1 0 1 1 2 3 3 1 0 2 1 1 1 2 2 2 0 2 0 3 1 2 2 2 0 1 0 1 1 0 2 0 0 0 0 3 1 0 0 1 0 1 1 0 0 1 1 2 1 2 0 0 1 2 0 1 1 0 2 0 0 1 0 0 2 2
48 80 1 66 89 71 73 40 2 50 99 68 91 31 76 25 67 94 37 6 88 86 28 22 43 62 21 16 17 39 70 1...

output:

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

result:

ok Correct!

Test #13:

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

input:

5
96 96
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 72 44
0
0
1 75
0
2 48 35
1 29
1 55
2 75 32
1 95
0
2 87 85
1 69
1 6
2 48 6
1 77
1 67
0
0
1 75
2 59 ...

output:

59
2 3 4 5 7 8 9 10 11 12 13 14 15 6 16 17 18 19 20 21 22 23 24 25 26 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 47 48 27 49 50 51 52 53 54 44 55 56 57 58 59 46 60 61 63 64 65 66 67 68 69 70 71 62 1 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 
54
1 2 3 4 6 7 8 ...

result:

ok Correct!

Test #14:

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

input:

1
499 497
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

287
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 25 26 27 28 29 30 31 32 33 34 24 36 37 38 39 40 41 42 43 44 45 47 48 49 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 81 82 84 85 86 87 88 89 90 91 92 94 95 96 97 98 99 102 103 104 105 106 107 108 110 111...

result:

ok Correct!

Test #15:

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

input:

10
50 49
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 43
0
0
2 25 28
0
0
2 28 14
0
2 8 38
1 1
0
1 6
1 41
0
2 40 47
2 8 34
2 26 41
2 31 28
1 5
0
2 33 45
0
2 14 43
0
2 39 34
1 32
1 6
1 15
1 17
0
0
2 9 6
2 37 1
0
2 13 20
0
2 4 41
2 31 5
0
2 44 14
1...

output:

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

result:

ok Correct!

Test #16:

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

input:

10
50 49
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 32
0
0
2 47 41
1 10
3 33 18 13
1 43
1 49
1 39
0
0
3 16 27 31
0
0
2 30 25
3 23 16 37
3 18 1 46
2 8 9
3 32 33 10
3 24 14 31
3 31 11 2
2 8 36
1 44
1 9
0
2 39 27
1 14
1 6
3 47 12 10
1 14
1 10
0
1...

output:

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

result:

ok Correct!

Test #17:

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

input:

1
495 495
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

344
1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20 21 23 24 25 26 27 28 30 31 33 34 35 36 41 42 43 45 46 47 48 50 51 53 54 55 56 57 58 59 63 65 12 66 67 68 69 70 71 72 73 74 75 76 77 78 79 82 83 85 86 88 89 90 91 44 92 93 94 95 96 97 98 99 100 101 102 103 104 105 107 108 109 60 110 111 112 113 114 ...

result:

ok Correct!

Test #18:

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

input:

250
1 2
1 0
2 1 2
2 2
0 2
1 1
1 1
2 2
1 1
2 1 2
2 1 2
1 1
1
0
2 2
0 2
2 1 2
0
2 1
2
1 1
0
2 2
0 2
1 1
2 1 2
2 1
2
0
0
1 2
0 1
2 1 2
1 1
1
1 1
2 1
2
0
1 1
2 2
1 1
2 1 2
1 1
1 1
1
1 1
2 1
2
0
1 1
1 2
0 1
2 1 2
1 2
0 1
0
1 2
0 1
1 1
2 2
1 1
1 1
2 1 2
2 1
2
1 1
1 1
1 2
1 0
2 1 2
1 2
0 1
2 1 2
1 2
1 0
2 ...

output:

1
1 
0
1 2 
2
2 1 
0
1 
1
1 2 
1
1 2 
1
1 2 
0
1 2 
1
1 
1
1 
1
1 2 
2
2 1 
1
1 
1
1 2 
1
1 
0
1 
0
1 
2
1 2 
2
1 2 
1
1 
1
1 
1
1 
2
1 2 
0
1 2 
2
1 2 
1
1 
1
1 2 
0
1 
1
1 
1
1 
1
1 2 
2
1 2 
1
1 2 
1
1 
1
1 2 
0
1 
1
1 
2
1 2 
1
1 
1
1 2 
1
1 2 
0
1 2 
0
1 
0
1 2 
1
1 
1
1 2 
0
1 2 
1
1 2 
1
1 
0...

result:

ok Correct!

Test #19:

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

input:

166
3 3
1 1 1
1 1
0
1 1
3 3
1 1 1
1 1
2 1 2
0
3 3
1 2 0
1 1
1 1
0
3 3
1 0 2
0
2 1 2
0
3 3
0 2 1
1 1
2 1 2
2 1 2
3 3
1 0 2
0
0
1 1
3 3
1 0 2
0
1 1
1 1
3 3
1 0 2
0
0
1 1
3 3
0 2 1
2 1 2
0
2 1 2
3 3
0 1 2
0
0
2 1 2
3 3
0 1 2
2 1 2
2 1 2
2 1 2
3 3
1 0 2
2 1 2
0
0
3 3
0 1 2
0
2 1 2
2 1 2
3 3
0 3 0
0
1 1
...

output:

1
1 2 3 
2
1 2 3 
1
1 2 3 
1
1 2 3 
2
1 2 3 
1
1 2 3 
1
1 2 3 
1
1 2 3 
2
1 2 3 
1
1 2 3 
1
1 2 3 
1
1 2 3 
1
1 2 3 
1
1 2 3 
1
1 2 3 
0
1 2 3 
0
1 2 3 
1
1 2 3 
1
1 2 3 
0
1 2 3 
1
1 2 3 
2
1 2 3 
0
1 2 3 
1
1 2 3 
1
1 2 3 
2
1 2 3 
0
1 2 3 
0
1 2 3 
0
1 2 3 
1
1 2 3 
0
1 2 3 
1
1 2 3 
1
1 2 3 
2
1...

result:

ok Correct!

Test #20:

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

input:

125
4 4
0 1 1 2
1 1
3 1 2 3
2 1 2
2 1 2
4 4
1 2 1 0
2 1 2
3 1 2 3
0
1 1
4 4
1 1 1 1
2 1 2
2 1 2
3 1 2 3
1 1
4 4
0 1 1 2
0
3 1 2 3
2 1 2
3 1 2 3
4 4
0 2 0 2
3 1 2 3
0
3 1 2 3
3 1 2 3
4 4
0 2 1 1
0
1 1
3 1 2 3
2 1 2
4 4
0 2 2 0
0
3 1 2 3
2 1 2
2 1 2
4 4
0 0 1 3
2 1 2
0
1 1
2 1 2
4 4
0 1 0 3
1 2
0
1 1
...

output:

2
1 3 2 4 
3
3 4 1 2 
3
2 1 3 4 
2
1 3 2 4 
2
1 2 3 4 
2
1 2 3 4 
3
1 3 4 2 
0
1 2 3 4 
1
1 2 3 4 
0
1 2 3 4 
1
1 2 3 4 
2
1 3 4 2 
1
1 2 3 4 
3
2 3 1 4 
1
1 2 3 4 
1
1 2 3 4 
1
1 2 3 4 
0
1 2 3 4 
3
2 3 4 1 
2
1 2 3 4 
2
2 3 4 1 
2
1 3 2 4 
0
1 2 3 4 
2
1 3 2 4 
2
1 2 3 4 
2
1 2 3 4 
2
1 2 3 4 
2
1...

result:

ok Correct!

Test #21:

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

input:

100
5 5
0 0 1 1 3
3 1 2 3
3 1 2 3
2 1 2
3 1 2 3
1 1
5 5
1 2 1 0 1
0
2 1 2
0
3 1 2 3
0
5 5
0 0 1 2 2
3 1 2 3
3 1 2 3
3 1 2 3
0
3 2 3 4
5 5
0 2 1 2 0
1 1
2 1 2
3 1 2 3
1 1
2 1 2
5 5
0 0 0 0 5
0
0
0
0
3 1 2 3
5 5
1 0 0 2 2
1 1
3 1 2 3
2 1 2
3 1 2 3
3 1 2 3
5 5
0 0 1 2 2
3 1 2 3
0
0
2 1 2
1 1
5 5
0 2 0 ...

output:

1
1 2 3 4 5 
2
1 3 4 2 5 
2
1 2 3 4 5 
3
1 2 4 5 3 
0
1 2 3 4 5 
1
1 2 3 4 5 
1
1 2 3 4 5 
2
1 2 3 4 5 
0
1 2 3 4 5 
4
1 3 4 2 5 
2
1 2 3 4 5 
0
1 2 3 4 5 
3
2 4 5 1 3 
2
2 3 1 4 5 
3
2 3 4 1 5 
1
1 2 3 4 5 
2
1 3 2 4 5 
1
1 2 3 4 5 
2
1 2 3 4 5 
3
1 3 4 2 5 
3
1 4 3 2 5 
0
1 2 3 4 5 
1
1 2 3 4 5 
0...

result:

ok Correct!

Test #22:

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

input:

10
49 49
0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 0 0 1 2 0 2 2 1 1 0 0 2 3 1 2 1 1 1 2 2 0 1 0 1 0 2 2 0 0 4 1 3 3 3
5 3 10 12 16 18
5 2 16 36 21 39
9 19 23 5 31 32 12 15 34 40
0
5 5 19 21 24 30
3 6 8 16
6 15 17 26 2 14 7
1 3
2 14 15
3 16 21 23
6 3 4 17 19 21 22
1 7
7 2 11 28 10 13 31 6
0
6 13 33 43 47 14 1
4...

output:

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

result:

ok Correct!

Test #23:

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

input:

1
498 500
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 2 1 0 1 0 0 2 0 1 0 0 1 1 0 0 0 0 0 2 0 0 1 0 1 0 0 0 0 0 2 1 2 0 1 0 0 1 1 0 1 ...

output:

464
3 4 8 10 17 21 23 24 26 27 29 33 36 40 42 43 45 46 50 51 52 55 56 59 60 64 66 70 76 78 69 79 80 81 85 87 88 91 93 57 94 99 100 104 109 115 118 126 129 134 135 136 61 138 112 140 142 143 149 155 162 97 166 168 170 172 174 178 179 181 182 184 189 133 190 197 199 202 130 175 207 208 210 212 216 218...

result:

ok Correct!

Test #24:

score: 0
Accepted
time: 9ms
memory: 7016kb

input:

1
497 496
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 1 0 1 0 1 0 2 1 0 0 0 0 0 0 0 1 1 0 1 0 1 2 1 2 0 1 0 0 1 2 0 1 1 1 0 0 0 0 2 1 1 1 0 0 1 ...

output:

496
6 7 9 18 21 24 33 35 45 46 55 60 62 5 66 77 79 82 73 87 94 102 105 108 110 112 123 139 142 143 149 168 85 174 175 179 177 183 190 194 196 198 199 206 208 209 213 231 235 238 240 246 248 251 260 145 261 262 268 273 243 277 254 280 39 203 284 70 164 245 290 298 299 313 318 91 319 328 227 332 334 3...

result:

ok Correct!

Test #25:

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

input:

5
100 100
0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1 0 0 0 1 0 1 0 1 0 1 0 1 0 1 1 2 0 1 0 0 1 1 1 1 0 2 1 0 0 1 2 1 0 1 1 1 1 0 1 1 2 5 1 0 1 2 0 2 0 3 1 1 1 2 3 2 1 1 1 2 4 2 1 4 1 2 1 0 3 3 1 3 0 0 3 1 0 0 0 3 4 2
1 35
0
1 8
1 35
0
0
1 10
2 15 19
2 1 3
2 6 61
0
0
0
0
2 14 20
2 4 80
0
0
0
1 6
0
1 13
1 4
...

output:

19
1 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 
26
1...

result:

ok Correct!

Test #26:

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

input:

5
95 99
0 0 1 0 0 0 0 0 1 1 0 0 0 2 1 0 0 0 1 0 1 0 0 0 1 2 0 0 1 1 2 0 0 0 1 0 0 1 1 1 0 1 0 1 1 0 1 1 1 2 2 0 0 0 1 0 1 1 1 4 3 0 3 1 2 1 0 1 0 1 5 0 1 1 0 3 0 3 1 2 2 4 0 0 0 1 1 1 2 3 1 0 2 4 0 1 1 4 3
0
1 5
3 31 50 70
1 21
5 14 26 31 2 6
5 7 41 19 45 30
3 1 6 40
0
2 16 19
4 5 6 9 25
0
0
5 17 47...

output:

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

result:

ok Correct!

Test #27:

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

input:

5
97 97
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 1 0 0 1 1 2 0 0 1 2 1 0 0 1 2 2 1 0 2 0 1 0 0 3 0 2 3 0 2 1 1 1 1 0 1 1 2 4 1 0 2 1 0 1 2 1 2 2 2 1 2 5 2 0 1 0 3 1 3 1 0 1 2 0 0 2 4 2 2 1 2 1 3 0
0
5 14 16 33 41 9
7 12 28 16 32 45 46 71
10 15 63 65 17 66 18 81 45 8 68
6 8 35 12 54 21 63
0
0
0
...

output:

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

result:

ok Correct!

Test #28:

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

input:

5
95 95
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 1 0 1 0 0 0 1 1 0 1 0 1 1 1 0 0 2 1 0 0 1 1 0 0 1 0 1 0 0 3 0 2 1 1 5 0 0 0 4 3 0 2 1 0 3 2 2 1 2 1 6 1 3 4 2 1 2 2 3 0 2 0 2 1 1 2 2 1 0 2 1 0 0 1 2 3
16 2 9 23 36 52 58 31 65 66 71 72 17 75 24 44 27
28 4 2 32 38 45 21 52 61 94 55 46 79 92 1 11 65 73 95...

output:

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

result:

ok Correct!

Test #29:

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

input:

1
498 500
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 2 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 1 1 2 0 0 1 0 0 0 0 0 1 0 0 2 0 1 1 1 0 0 1 0 2 0 0 1 1 0 0 2 0 0 0 0 0 3 1 0 2 0 1 3 0 0 0 ...

output:

108
1 2 3 4 5 6 7 8 9 10 11 12 13 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 101 102...

result:

ok Correct!

Test #30:

score: 0
Accepted
time: 6ms
memory: 5748kb

input:

1
500 498
2 0 0 1 1 1 0 0 0 0 1 1 2 2 2 0 1 0 0 0 1 1 1 0 1 1 2 2 2 1 1 0 4 3 1 1 1 1 0 3 0 3 3 1 2 1 0 2 3 2 0 2 0 0 0 1 1 1 0 2 4 1 0 1 1 1 1 3 1 0 0 1 1 2 2 4 1 1 1 0 0 2 2 1 2 1 1 1 0 0 2 0 0 1 0 0 1 1 1 1 0 1 0 0 1 2 1 1 1 2 2 4 2 0 0 0 0 1 1 0 1 4 1 3 0 2 0 3 0 1 1 1 0 4 0 1 1 3 2 0 0 1 0 1 1 ...

output:

258
3 7 11 12 15 17 21 28 29 30 35 36 43 46 47 50 51 56 58 59 19 61 67 70 72 75 76 80 82 83 84 86 88 89 90 91 92 99 104 20 106 107 108 109 110 111 14 112 77 114 118 119 10 120 121 125 130 131 135 136 137 138 142 143 145 146 147 150 154 157 158 161 57 69 53 9 163 164 166 167 172 173 174 74 176 177 17...

result:

ok Correct!

Test #31:

score: 0
Accepted
time: 27ms
memory: 6604kb

input:

1
496 498
0 0 0 0 2 0 0 1 0 1 1 0 2 3 1 1 2 0 3 2 2 0 2 1 2 0 1 1 1 0 1 2 0 0 0 0 5 1 1 0 2 1 0 0 1 0 0 2 0 3 0 0 3 1 0 3 0 1 1 2 1 2 0 2 0 2 1 0 3 0 1 0 1 1 2 0 1 0 0 1 2 1 2 0 1 0 1 1 1 0 3 3 3 2 0 1 2 1 1 3 1 1 0 0 3 0 1 0 0 0 0 1 3 1 0 1 1 2 1 0 1 2 0 2 0 1 1 1 2 2 0 0 1 2 1 1 1 2 1 3 1 1 1 0 0 ...

output:

248
2 3 5 8 9 10 11 12 14 15 17 18 22 23 25 27 31 33 37 38 39 40 43 44 45 46 47 49 50 55 60 62 63 66 69 71 72 75 77 78 82 85 91 35 52 81 92 97 99 100 67 101 102 103 104 87 110 111 112 113 74 119 120 24 121 123 125 98 126 127 128 4 129 130 133 115 134 135 136 138 141 147 148 150 151 153 155 157 160 1...

result:

ok Correct!

Test #32:

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

input:

10
49 50
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
0
0
1 4
0
1 7
2 8 7
2 9 8
0
1 10
1 12
2 13 12
0
0
1 16
2 16 17
0
1 19
0
1 20
1 21
1 23
2 24 23
2 25 24
1 26
1 27
1 27
1 28
0
2 31 30
1 32
0
1 33
1 34
2 35 36
1 37
2 38 37
1 38
1 40
2 41 4...

output:

35
1 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 
31
1 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 
30
1 2 3 4 5 6 7...

result:

ok Correct!

Test #33:

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

input:

5
99 99
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 2
0
0
2 5 4
1 5
1 7
0
1 9
1 10
0
2 12 11
1 12
1 14
1 14
2 15 16
1 17
0
1 19
1 19
1 21
2 21 2...

output:

60
1 2 3 5 4 6 7 8 9 10 12 11 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 33 32 31 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 67 66 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 
63
1 2 3...

result:

ok Correct!

Test #34:

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

input:

1
496 500
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

325
1 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 75 74 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 97 96 98 99 100 101 ...

result:

ok Correct!

Test #35:

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

input:

10
46 47
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
2 3 4
1 5
2 5 6
2 6 5
3 8 6 7
0
1 8
1 10
0
2 11 13
2 14 13
2 14 13
3 15 14 16
2 16 15
1 18
1 18
0
1 20
1 21
1 21
0
2 23 24
1 26
2 27 26
1 27
1 29
1 29
1 31
1 30
1 32
1 32
1 33
2 35 36
2 35 37
1...

output:

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

result:

ok Correct!

Test #36:

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

input:

5
99 99
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3 1 3 2
2 4 3
2 4 3
0
2 6 7
1 6
3 8 7 9
2 10 9
1 11
3 12 11 10
3 13 12 11
1 12
2 13 14
0
1 15
...

output:

75
3 2 4 6 5 7 9 11 12 10 8 13 14 15 16 17 18 20 19 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 37 36 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 77 76 78 79 80 81 82 84 83 86 85 87 88 91 89 90 93 92 94 96 97 95 98 99 1 
75
1 2 3...

result:

ok Correct!

Test #37:

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

input:

1
495 497
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

383
1 2 4 3 5 6 7 8 10 9 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 34 33 32 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 78 77 81 80 79 83 84 82 85 86 87 88 89 90 92 91 94 93 95 96 97 98 99 102 103 ...

result:

ok Correct!

Test #38:

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

input:

10
45 49
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3 3 5 2
0
2 6 5
3 4 5 8
3 9 6 8
3 7 8 10
1 8
3 8 11 10
2 12 10
3 13 12 10
3 14 15 12
3 14 13 12
3 15 17 13
2 15 18
3 19 17 18
4 16 17 19 20
3 18 21 20
1 18
2 19 21
3 21 20 23
3 23 21 25
1 22
3 ...

output:

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

result:

ok Correct!

Test #39:

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

input:

5
95 98
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3 5 1 3
1 6
3 5 4 7
2 7 8
1 7
3 7 10 6
3 9 11 8
4 10 8 9 11
3 9 10 12
1 12
3 12 14 15
1 16
4 14 ...

output:

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

result:

ok Correct!

Test #40:

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

input:

1
498 496
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

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

result:

ok Correct!

Test #41:

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

input:

10
49 47
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
7 3 1 7 4 9 8 10
6 11 2 6 3 4 5
3 3 12 10
5 5 9 6 12 7
5 13 7 10 9 11
3 10 6 12
6 12 16 7 8 10 9
7 11 9 16 12 17 10 15
5 15 14 11 13 9
3 12 18 16
5 13 20 17 15 19
4 15 19 17 12
7 13 15 22 18 19 17 ...

output:

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

result:

ok Correct!

Test #42:

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

input:

5
99 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 9 7
5 2 9 8 11 7
6 5 8 4 9 3 11
6 9 8 13 10 12 4
6 5 6 12 14 9 11
2 10 14
8 12 15 8 9 14 ...

output:

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

result:

ok Correct!

Test #43:

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

input:

1
498 499
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

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

result:

ok Correct!