Place Your Ad Here

Ivan Anatolyevich’s agency is starting to become famous in the town.

They have already ordered and made n TV commercial videos. Each video is made in a special way: the colors and the soundtrack are adjusted to the time of the day and the viewers’ mood. That’s why the i-th video can only be shown within the time range of [l i, r i] (it is not necessary to use the whole segment but the broadcast time should be within this segment).

Now it’s time to choose a TV channel to broadcast the commercial. Overall, there are m TV channels broadcasting in the city, the j-th one has c j viewers, and is ready to sell time [a j, b j] to broadcast the commercial.

Ivan Anatolyevich is facing a hard choice: he has to choose exactly one video i and exactly one TV channel j to broadcast this video and also a time range to broadcast [x, y]. At that the time range should be chosen so that it is both within range [l i, r i] and within range [a j, b j].

Let’s define the efficiency of the broadcast as value (y - xc j — the total sum of time that all the viewers of the TV channel are going to spend watching the commercial. Help Ivan Anatolyevich choose the broadcast with the maximum efficiency!

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of commercial videos and channels, respectively.

Each of the following n lines contains two integers l ir i (0 ≤ l i ≤ r i ≤ 109) — the segment of time when it is possible to show the corresponding video.

Each of the following m lines contains three integers a jb jc j (0 ≤ a j ≤ b j ≤ 109, 1 ≤ c j ≤ 109), characterizing the TV channel.

Output

In the first line print an integer — the maximum possible efficiency of the broadcast. If there is no correct way to get a strictly positive efficiency, print a zero.

If the maximum efficiency is strictly positive, in the second line also print the number of the video i (1 ≤ i ≤ n) and the number of the TV channel j (1 ≤ j ≤ m) in the most effective broadcast.

If there are multiple optimal answers, you can print any of them.

Examples

input

2 3
7 9
1 4
2 8 2
0 4 1
8 9 3

output

4
2 1

input

1 1
0 0
1 1 10

output

0

Note

In the first sample test the most optimal solution is to show the second commercial using the first TV channel at time [2, 4]. The efficiency of such solution is equal to (4 - 2)·2 = 4.

In the second sample test Ivan Anatolievich’s wish does not meet the options of the TV channel, the segments do not intersect, so the answer is zero.

Solution:

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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1000010;
 
int mx[N], mid[N];
int t;
 
void modify(int x, int v, int id) {
while (x <= t) {
    if (v > mx[x]) {
mx[x] = v;
mid[x] = id;
}
x = (x | (x - 1)) + 1;
}
}
 
int find_max(int x, int &id) {
int v = -2;
while (x > 0) {
if (mx[x] > v) {
v = mx[x];
id = mid[x];
}
x &= x - 1;
}
return v;
}
 
int sa[N], fa[N];
int sb[N], fb[N], cb[N];
int pred_a[N], last_a[N];
int pred_b[N], last_b[N];
int real_x[N];
 
int main() {
int na, nb;
scanf("%d %d", &na, &nb);
for (int i = 0; i < na; i++) {
    scanf("%d %d", sa + i, fa + i);
  }
  for (int i = 0; i < nb; i++) {
    scanf("%d %d %d", sb + i, fb + i, cb + i);
  }
  vector < pair <int, int> > e;
for (int i = 0; i < na; i++) {
    e.push_back(make_pair(sa[i], i));
    e.push_back(make_pair(fa[i], ~i));
  }
  for (int i = 0; i < nb; i++) {
    e.push_back(make_pair(sb[i], i + na));
    e.push_back(make_pair(fb[i], ~(i + na)));
  }
  sort(e.begin(), e.end());
  int esz = e.size();
  t = 0;
  for (int i = 0; i < esz; i++) {
    if (i == 0 || e[i].first != e[i - 1].first) {
      t++;
      real_x[t] = e[i].first;
    }
    int id = e[i].second;
    if (id >= 0) {
if (id < na) {
        sa[id] = t;
      } else {
        sb[id - na] = t;
      }
    } else {
      id = ~id;
      if (id < na) {
        fa[id] = t;
      } else {
        fb[id - na] = t;
      }
    }
  }
//  for (int i = 0; i < na; i++)  cerr << i << " -> " << sa[i] << " " << fa[i] << endl;
//  for (int i = 0; i < nb; i++)  cerr << i << " -> " << sb[i] << " " << fb[i] << " " << cb[i] << endl;
  long long ans = 0;
  int ax = -1, ay = -1;
  for (int rot = 0; rot < 2; rot++) {
    for (int i = 1; i <= t; i++) {
      last_a[i] = -1;
      last_b[i] = -1;
    }
    for (int i = 0; i < na; i++) {
      pred_a[i] = last_a[sa[i]];
      last_a[sa[i]] = i;
    }
    for (int i = 0; i < nb; i++) {
      pred_b[i] = last_b[sb[i]];
      last_b[sb[i]] = i;
    }
    int rg = -1, rid = -1;
    for (int i = 1; i <= t; i++) {
      int j = last_a[i];
      while (j >= 0) {
if (fa[j] > rg) {
rg = fa[j];
rid = j;
}
j = pred_a[j];
}
j = last_b[i];
while (j >= 0) {
int to = min(rg, fb[j]);
if (to > sb[j]) {
long long cur = (real_x[to] - real_x[sb[j]]) * 1LL * cb[j];
if (rot == 1) {
cur = (real_x[t - sb[j] + 1] - real_x[t - to + 1]) * 1LL * cb[j];
}
if (cur > ans) {
ans = cur;
ax = rid;
ay = j;
}
}
j = pred_b[j];
}
}
for (int i = 0; i < na; i++) {
      sa[i] = t - sa[i] + 1;
      fa[i] = t - fa[i] + 1;
      swap(sa[i], fa[i]);
    }
    for (int i = 0; i < nb; i++) {
      sb[i] = t - sb[i] + 1;
      fb[i] = t - fb[i] + 1;
      swap(sb[i], fb[i]);
    }
  }
  {
    for (int i = 1; i <= t; i++) {
      last_a[i] = -1;
      last_b[i] = -1;
    }
    for (int i = 0; i < na; i++) {
      pred_a[i] = last_a[sa[i]];
      last_a[sa[i]] = i;
    }
    for (int i = 0; i < nb; i++) {
      pred_b[i] = last_b[sb[i]];
      last_b[sb[i]] = i;
    }
    for (int i = 1; i <= t; i++) {
      mx[i] = -1;
      mid[i] = -1;
    }
    for (int i = t; i >= 1; i--) {
int j = last_a[i];
while (j >= 0) {
modify(fa[j], real_x[fa[j]] - real_x[sa[j]], j);
j = pred_a[j];
}
j = last_b[i];
while (j >= 0) {
int id = -1;
int u = find_max(fb[j], id);
if (u > 0) {
long long cur = u * 1LL * cb[j];
if (cur > ans) {
ans = cur;
ax = id;
ay = j;
}
}
j = pred_b[j];
}
}
}
cout << ans << endl;
  if (ans > 0) {
cout << (ax + 1) << " " << (ay + 1) << endl;
  }
  return 0;
}