JerryL/AlgoSimBench huggingface dataset:
580_D. Kefa and Dishes

When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly m dishes. But at that, he doesn't want to order the same dish twice to taste as many dishes as possible. 

Kefa knows that the i-th dish gives him ai units of satisfaction. But some dishes do not go well together and some dishes go very well together. Kefa set to himself k rules of eating food of the following type — if he eats dish x exactly before dish y (there should be no other dishes between x and y), then his satisfaction level raises by c. 

Of course, our parrot wants to get some maximal possible satisfaction from going to the restaurant. Help him in this hard task!

Input

The first line of the input contains three space-separated numbers, n, m and k (1 ≤ m ≤ n ≤ 18, 0 ≤ k ≤ n * (n - 1)) — the number of dishes on the menu, the number of portions Kefa needs to eat to get full and the number of eating rules.

The second line contains n space-separated numbers ai, (0 ≤ ai ≤ 109) — the satisfaction he gets from the i-th dish.

Next k lines contain the rules. The i-th rule is described by the three numbers xi, yi and ci (1 ≤ xi, yi ≤ n, 0 ≤ ci ≤ 109). That means that if you eat dish xi right before dish yi, then the Kefa's satisfaction increases by ci. It is guaranteed that there are no such pairs of indexes i and j (1 ≤ i < j ≤ k), that xi = xj and yi = yj.

Output

In the single line of the output print the maximum satisfaction that Kefa can get from going to the restaurant.

Examples

Input

2 2 1
1 1
2 1 1


Output

3


Input

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


Output

12

Note

In the first sample it is best to first eat the second dish, then the first one. Then we get one unit of satisfaction for each dish and plus one more for the rule.

In the second test the fitting sequences of choice are 4 2 1 or 2 1 4. In both cases we get satisfaction 7 for dishes and also, if we fulfill rule 1, we get an additional satisfaction 5.

Example input:
2 2 1
1 1
2 1 1

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


Example output:
3
12

Tags: bitmasks
dp
Difficulty rating: 1800

Solution:
#include <bits/stdc++.h>
using namespace std;
int a, b, A[19], B[19][19];
long long dp[19][600000];
long long dfs(int x, int y, int z) {
  if (x == b) return 0;
  if (dp[y][z] != -1) return dp[y][z];
  long long w = 0;
  for (int i = 1; i <= a; i++)
    if (!(z & (1 << i))) w = max(w, A[i] + B[y][i] + dfs(x + 1, i, z | 1 << i));
  return dp[y][z] = w;
}
int main() {
  int c, i, x, y, z;
  cin >> a >> b >> c, memset(dp, -1, sizeof dp);
  for (i = 1; i <= a; i++) cin >> A[i];
  for (i = 1; i <= c; i++) scanf("%d%d%d", &x, &y, &z), B[x][y] = z;
  cout << dfs(0, 0, 0);
}
16_E. Fish

n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability aij, and the second will eat up the first with the probability aji = 1 - aij. The described process goes on until there are at least two fish in the lake. For each fish find out the probability that it will survive to be the last in the lake.

Input

The first line contains integer n (1 ≤ n ≤ 18) — the amount of fish in the lake. Then there follow n lines with n real numbers each — matrix a. aij (0 ≤ aij ≤ 1) — the probability that fish with index i eats up fish with index j. It's guaranteed that the main diagonal contains zeros only, and for other elements the following is true: aij = 1 - aji. All real numbers are given with not more than 6 characters after the decimal point.

Output

Output n space-separated real numbers accurate to not less than 6 decimal places. Number with index i should be equal to the probability that fish with index i will survive to be the last in the lake.

Examples

Input

2
0 0.5
0.5 0


Output

0.500000 0.500000 

Input

5
0 1 1 1 1
0 0 0.5 0.5 0.5
0 0.5 0 0.5 0.5
0 0.5 0.5 0 0.5
0 0.5 0.5 0.5 0


Output

1.000000 0.000000 0.000000 0.000000 0.000000 

Example input:
2
0 0.5
0.5 0

5
0 1 1 1 1
0 0 0.5 0.5 0.5
0 0.5 0 0.5 0.5
0 0.5 0.5 0 0.5
0 0.5 0.5 0.5 0


Example output:
0.500000 0.500000 
1.000000 0.000000 0.000000 0.000000 0.000000 

Tags: bitmasks
dp
probabilities
Difficulty rating: 1900

Solution:
n=int(input())
b=[]
for i in range(n):
    b.append(list(map(float,input().split())))

ma=1<<n
dp=[0 for j in range(ma)]
dp[0]=1
for mask in range(1,ma):
    l=n-bin(mask).count("1")+1
    res=l*(l-1)//2
    for i in range(n):
        if mask&(1<<i):
            for j in range(n):
                if not mask&(1<<j):

                    dp[mask]+=((dp[mask^(1<<i)]*b[j][i])/res)


ans=[]
for i in range(n):
    ans.append(dp[ma-1-(1<<i)])
print(*ans)
8_C. Looking for Order

Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag — her inherent sense of order does not let her do so.

You are given the coordinates of the handbag and the coordinates of the objects in some Сartesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.

Input

The first line of the input file contains the handbag's coordinates xs, ys. The second line contains number n (1 ≤ n ≤ 24) — the amount of objects the girl has. The following n lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.

Output

In the first line output the only number — the minimum time the girl needs to put the objects into her handbag. 

In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to n), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them. 

Examples

Input

0 0
2
1 1
-1 1


Output

8
0 1 2 0 


Input

1 1
3
4 3
3 4
0 0


Output

32
0 1 2 0 3 0 

Example input:
0 0
2
1 1
-1 1

1 1
3
4 3
3 4
0 0


Example output:
8
0 1 2 0

32
0 1 2 0 3 0


Tags: bitmasks
dp
Difficulty rating: 2000

Solution:
#include <bits/stdc++.h>
int f[1 << 24], a[25][25], r[1 << 24], n, x[25], y[25];
int main() {
  scanf("%d%d%d", x, y, &n), x[n] = x[0], y[n] = y[0];
  for (int i = 0; i < n; i++) scanf("%d%d", x + i, y + i);
  for (int i = 0; i < n + 1; i++)
    for (int j = 0; j < n + 1; j++)
      a[i][j] =
          ((x[i] - x[j]) * (x[i] - x[j])) + ((y[i] - y[j]) * (y[i] - y[j]));
  for (int i = 0; i < 1 << n; i++) f[i] = i ? 0x3f3f3f3f : 0;
  for (int i = 0; i < 1 << n; i++)
    if (f[i] < 0x3f3f3f3f)
      for (int j = 0; j < n; j++)
        if (!(i >> j & 1)) {
          for (int k = j; k < n; k++)
            if (!(i >> k & 1)) {
              int p = i | 1 << j | 1 << k,
                  q = f[i] + a[n][j] + a[k][j] + a[k][n];
              if (f[p] > q) f[p] = q, r[p] = i;
            }
          break;
        }
  printf("%d\n0", f[(1 << n) - 1]);
  for (int i = (1 << n) - 1; i; i = r[i]) {
    for (int t = i ^ r[i]; t; t -= t & -t)
      printf(" %d", int(log(t & -t) / log(2) + 1e-8 + 1));
    printf(" 0");
  }
}
678_E. Another Sith Tournament

The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each battle in the Sith Tournament ends with a death of one of opponents? The Tournament ends when the only Sith remains alive.

Jedi Ivan accidentally appeared in the list of the participants in the Sith Tournament. However, his skills in the Light Side of the Force are so strong so he can influence the choice of participants either who start the Tournament or who take the loser's place after each battle. Of course, he won't miss his chance to take advantage of it. Help him to calculate the probability of his victory.

Input

The first line contains a single integer n (1 ≤ n ≤ 18) — the number of participants of the Sith Tournament.

Each of the next n lines contains n real numbers, which form a matrix pij (0 ≤ pij ≤ 1). Each its element pij is the probability that the i-th participant defeats the j-th in a duel.

The elements on the main diagonal pii are equal to zero. For all different i, j the equality pij + pji = 1 holds. All probabilities are given with no more than six decimal places.

Jedi Ivan is the number 1 in the list of the participants.

Output

Output a real number — the probability that Jedi Ivan will stay alive after the Tournament. Absolute or relative error of the answer must not exceed 10 - 6.

Examples

Input

3
0.0 0.5 0.8
0.5 0.0 0.4
0.2 0.6 0.0


Output

0.680000000000000

Example input:
3
0.0 0.5 0.8
0.5 0.0 0.4
0.2 0.6 0.0


Example output:
0.68


Tags: bitmasks
dp
math
probabilities
Difficulty rating: 2200

Solution:
#include <bits/stdc++.h>
using namespace std;
int n;
double p[18][18], f[1 << 18];
int main() {
  f[1] = 1;
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> p[i][j];
  for (int S = 2; S < (1 << n); S++)
    for (int i = 0; i < n - 1; i++)
      if (S >> i & 1)
        for (int j = i + 1; j < n; j++)
          if (S >> j & 1)
            f[S] = max(f[S],
                       f[S ^ (1 << i)] * p[j][i] + f[S ^ (1 << j)] * p[i][j]);
  cout << f[(1 << n) - 1];
}
662_C. Binary Table

You are given a table consisting of n rows and m columns. Each cell of the table contains either 0 or 1. In one move, you are allowed to pick any row or any column and invert all values, that is, replace 0 by 1 and vice versa.

What is the minimum number of cells with value 1 you can get after applying some number of operations?

Input

The first line of the input contains two integers n and m (1 ≤ n ≤ 20, 1 ≤ m ≤ 100 000) — the number of rows and the number of columns, respectively.

Then n lines follows with the descriptions of the rows. Each line has length m and contains only digits '0' and '1'.

Output

Output a single integer — the minimum possible number of ones you can get after applying some sequence of operations.

Example

Input

3 4
0110
1010
0111


Output

2

Example input:
3 4
0110
1010
0111


Example output:
2


Tags: bitmasks
brute force
divide and conquer
dp
fft
math
Difficulty rating: 2600

Solution:
#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[21][100100];
int dp[21][1 << 20];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int j = 0; j < m; j++) {
    int x = 0;
    for (int i = 0; i < n; i++)
      if (s[i][j] == '1') x += 1 << i;
    dp[0][x]++;
  }
  for (int i = 0; i < n; i++)
    for (int j = n; j > 0; j--)
      for (int k = 0; k < 1 << n; k++) dp[j][k ^ 1 << i] += dp[j - 1][k];
  int ans = 1e9;
  for (int i = 0; i < 1 << n; i++) {
    int x = 0;
    for (int j = 0; j <= n; j++) x += min(j, n - j) * dp[j][i];
    ans = min(ans, x);
  }
  cout << ans << '\n';
}
p04041 AtCoder Regular Contest 058 - Iroha and Haiku

Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.

Iroha is looking for X,Y,Z-Haiku (defined below) in integer sequences.

Consider all integer sequences of length N whose elements are between 1 and 10, inclusive. Out of those 10^N sequences, how many contain an X,Y,Z-Haiku?

Here, an integer sequence a_0, a_1, ..., a_{N-1} is said to contain an X,Y,Z-Haiku if and only if there exist four indices x, y, z, w (0 ≦ x < y < z < w ≦ N) such that all of the following are satisfied:

* a_x + a_{x+1} + ... + a_{y-1} = X
* a_y + a_{y+1} + ... + a_{z-1} = Y
* a_z + a_{z+1} + ... + a_{w-1} = Z



Since the answer can be extremely large, print the number modulo 10^9+7.

Constraints

* 3 ≦ N ≦ 40
* 1 ≦ X ≦ 5
* 1 ≦ Y ≦ 7
* 1 ≦ Z ≦ 5

Input

The input is given from Standard Input in the following format:


N X Y Z


Output

Print the number of the sequences that contain an X,Y,Z-Haiku, modulo 10^9+7.

Examples

Input

3 5 7 5


Output

1


Input

4 5 7 5


Output

34


Input

37 4 2 3


Output

863912418


Input

40 5 7 5


Output

562805100

Example input:
40 5 7 5
4 5 7 5
3 5 7 5
37 4 2 3

Example output:
562805100
34
1
863912418

Difficulty rating: 0

Solution:
mod = 10**9+7
n, x, y, z = map(int,input().split())
xyz = 2**(x+y+z-1) + 2**(y+z-1) + 2**(z-1)
w = 2**(x+y+z-1)
dp = [[0]*w for _ in range(n+1)]
dp[0][0] = 1

for i in range(n):
    for j in range(w):
        for k in range(1,11):
            nj = ((j+j+1)<<(k-1))
            if nj&xyz != xyz:
                dp[i+1][nj%w] = (dp[i+1][nj%w]+dp[i][j])%mod

print((pow(10,n,mod)-sum(dp[-1])%mod)%mod)
p03664 AtCoder Regular Contest 078 - Mole and Abandoned Mine

Mole decided to live in an abandoned mine. The structure of the mine is represented by a simple connected undirected graph which consists of N vertices numbered 1 through N and M edges. The i-th edge connects Vertices a_i and b_i, and it costs c_i yen (the currency of Japan) to remove it.

Mole would like to remove some of the edges so that there is exactly one path from Vertex 1 to Vertex N that does not visit the same vertex more than once. Find the minimum budget needed to achieve this.

Constraints

* 2 \leq N \leq 15
* N-1 \leq M \leq N(N-1)/2
* 1 \leq a_i, b_i \leq N
* 1 \leq c_i \leq 10^{6}
* There are neither multiple edges nor self-loops in the given graph.
* The given graph is connected.

Input

Input is given from Standard Input in the following format:


N M
a_1 b_1 c_1
:
a_M b_M c_M


Output

Print the answer.

Examples

Input

4 6
1 2 100
3 1 100
2 4 100
4 3 100
1 4 100
3 2 100


Output

200


Input

2 1
1 2 1


Output

0


Input

15 22
8 13 33418
14 15 55849
7 10 15207
4 6 64328
6 9 86902
15 7 46978
8 14 53526
1 2 8720
14 12 37748
8 3 61543
6 5 32425
4 11 20932
3 12 55123
8 2 45333
9 12 77796
3 9 71922
12 15 70793
2 4 25485
11 6 1436
2 7 81563
7 11 97843
3 1 40491


Output

133677

Example input:
15 22
8 13 33418
14 15 55849
7 10 15207
4 6 64328
6 9 86902
15 7 46978
8 14 53526
1 2 8720
14 12 37748
8 3 61543
6 5 32425
4 11 20932
3 12 55123
8 2 45333
9 12 77796
3 9 71922
12 15 70793
2 4 25485
11 6 1436
2 7 81563
7 11 97843
3 1 40491
2 1
1 2 1
4 6
1 2 100
3 1 100
2 4 100
4 3 100
1 4 100
3 2 100

Example output:
133677
0
200

Difficulty rating: 0

Solution:
#include<bits/stdc++.h>
using namespace std;
const int N=17;

int n,m,G[N][N],g[1<<N],f[1<<N][N],sum=0;

int main() {
	cin>>n>>m;
	for(int i=1,a,b,c;i<=m;i++) {
		cin>>a>>b>>c;--a,--b;sum+=c;
		G[a][b]=G[b][a]=c;
		for(int j=0;j<(1<<n);j++)
			if((j>>a&1)&&(j>>b&1)) g[j]+=c;
	}
	memset(f,-1,sizeof(f));
	f[1][0]=0;
	for(int i=1;i<(1<<n);i++)
		for(int j=0;j<n;j++)
			if(~f[i][j]) {
				for(int k=0;k<n;k++)
					if(!(i>>k&1)&&G[j][k]) f[i|(1<<k)][k]=max(f[i|(1<<k)][k],f[i][j]+G[j][k]);
				for(int all=((1<<n)-1)^i,k=all;k;k=(k-1)&all)
					f[i|k][j]=max(f[i|k][j],f[i][j]+g[k|(1<<j)]);
			}
	cout<<sum-f[(1<<n)-1][n-1];
	return 0;
}
864_E. Fire

Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take ti seconds to save i-th item. In addition, for each item, he estimated the value of di — the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if ti ≥ di, then i-th item cannot be saved.

Given the values pi for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in ta seconds, and the item b — in ta + tb seconds after fire started.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of items in Polycarp's house.

Each of the following n lines contains three integers ti, di, pi (1 ≤ ti ≤ 20, 1 ≤ di ≤ 2 000, 1 ≤ pi ≤ 20) — the time needed to save the item i, the time after which the item i will burn completely and the value of item i.

Output

In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m — the number of items in the desired set. In the third line print m distinct integers — numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them.

Examples

Input

3
3 7 4
2 6 5
3 7 6


Output

11
2
2 3 


Input

2
5 6 1
3 3 5


Output

1
1
1 

Note

In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11.

In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.

Example input:
3
3 7 4
2 6 5
3 7 6

2
5 6 1
3 3 5


Example output:
11
2
2 3 
1
1
1 

Tags: dp
sortings
Difficulty rating: 2000

Solution:
P = [0] * 2001
S = [[] for i in range(2001)]
q = [list(map(int,raw_input().split())) + [str(i + 1)] for i in range(input())]
q.sort(key=lambda q: q[1])
for t, d, p, i in q:
    for x in range(t, d)[::-1]:
        if P[x] < P[x - t] + p:
            P[x] = P[x - t] + p
            S[x] = S[x - t] + [i]
k = P.index(max(P))
print('\n'.join([str(P[k]), str(len(S[k])), ' '.join(S[k])]))
p02863 AtCoder Beginner Contest 145 - All-you-can-eat

Takahashi is at an all-you-can-eat restaurant.

The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.

The restaurant has the following rules:

* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.



Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.

What is the maximum possible happiness achieved by making optimal choices?

Constraints

* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N T
A_1 B_1
:
A_N B_N


Output

Print the maximum possible happiness Takahashi can achieve.

Examples

Input

2 60
10 10
100 100


Output

110


Input

3 60
10 10
10 20
10 30


Output

60


Input

3 60
30 10
30 20
30 30


Output

50


Input

10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25


Output

145

Example input:
3 60
10 10
10 20
10 30
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
3 60
30 10
30 20
30 30
2 60
10 10
100 100

Example output:
60
145
50
110

Difficulty rating: 0

Solution:
N,T=map(int,input().split())
G=[list(map(int,input().split())) for _ in range(N)]

G.sort()
dp=[0]*(60000)
for g in G:
    for i in range(T-1,-1,-1):
        dp[i+g[0]]=max(dp[i+g[0]],dp[i]+g[1])
print(max(dp))
369_E. Valera and Queries

Valera loves segments. He has recently come up with one interesting problem.

The Ox axis of coordinates has n segments, the i-th segment starts in position li and ends in position ri (we will mark it as [li, ri]). Your task is to process m queries, each consists of number cnti and a set of cnti coordinates of points located on the Ox axis. The answer to the query is the number of segments, such that each of them contains at least one point from the query. Segment [l, r] contains point q, if l ≤ q ≤ r.

Valera found the solution of this problem too difficult. So he asked you to help him. Help Valera. 

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 3·105) — the number of segments on the axis of coordinates and the number of queries. 

Next n lines contain the descriptions of the segments. The i-th line contains two positive integers li, ri (1 ≤ li ≤ ri ≤ 106) — the borders of the i-th segment.

Next m lines contain the description of the queries, one per line. Each line starts from integer cnti (1 ≤ cnti ≤ 3·105) — the number of points in the i-th query. Then the line contains cnti distinct positive integers p1, p2, ..., pcnti (1 ≤ p1 < p2 < ... < pcnti ≤ 106) — the coordinates of points in the i-th query.

It is guaranteed that the total number of points in all queries doesn't exceed 3·105. 

Output

Print m non-negative integers, where the i-th number is the response to the i-th query.

Examples

Input

3 3
1 3
4 5
6 7
3 1 4 7
2 4 5
1 8


Output

3
1
0

Example input:
3 3
1 3
4 5
6 7
3 1 4 7
2 4 5
1 8


Example output:
3
1
0


Tags: binary search
data structures
Difficulty rating: 2200

Solution:
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1 << 20;
int s[mxn], ans[mxn], bit[mxn], n, m;
vector<int> ed[mxn];
vector<pair<int, int>> query[mxn];
void add(int idx, int v) {
  for (; idx < mxn; idx += idx & -idx) bit[idx] += v;
}
int ask(int idx) {
  int ret = 0;
  for (; idx > 0; idx -= idx & -idx) ret += bit[idx];
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, x1, x2; i <= n; ++i)
    scanf("%d%d", &x1, &x2), s[x1]++, ed[x2].push_back(x1);
  for (int i = 1, cnti, j, x, y; i <= m; ++i)
    for (scanf("%d", &cnti), j = 1, x = 0; j <= cnti; ++j)
      scanf("%d", &y), query[y].push_back({x, i}), x = y;
  for (int i = 1; i < mxn; ++i) {
    if (s[i]) add(i, s[i]);
    for (auto it : query[i]) ans[it.second] += ask(i) - ask(it.first);
    for (int j : ed[i]) add(j, -1);
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
}