#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,s,k[N],v[N][N],t[N][N];
int main(){
scanf("%d%d",&n,&s);
for(int i=1;i<=n;i++){
scanf("%d",&k[i]);
for(int j=1;j<=k[i];j++) scanf("%d%d",&v[i][j],&t[i][j]);
for(int j=1;j<=k[i];j++) t[i][j]+=t[i][j-1];
t[i][k[i]+1]=1e9;
}
int ans=0;
for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++){
int ti=0,o=2,p1=0,p2=0,s1=0,s2=0;
while(p1!=k[i]||p2!=k[j]){
int nt=min(t[i][p1+1],t[j][p2+1]);
s1+=v[i][p1+1]*(nt-ti),s2+=v[j][p2+1]*(nt-ti);
if(o!=2&&s1!=s2&&o!=(s1<s2)) ans++;
if(s1!=s2) o=s1<s2;
if(t[i][p1+1]<=nt) p1++;
if(t[j][p2+1]<=nt) p2++;
ti=nt;
}
}
printf("%d\n",ans);
}
1582C - Grandma Capa Knits a Scarf | 492A - Vanya and Cubes |
217A - Ice Skating | 270A - Fancy Fence |
181A - Series of Crimes | 1638A - Reverse |
1654C - Alice and the Cake | 369A - Valera and Plates |
1626A - Equidistant Letters | 977D - Divide by three multiply by two |
1654B - Prefix Removals | 1654A - Maximum Cake Tastiness |
1649A - Game | 139A - Petr and Book |
1612A - Distance | 520A - Pangram |
124A - The number of positions | 1041A - Heist |
901A - Hashing Trees | 1283A - Minutes Before the New Year |
1654D - Potion Brewing Class | 1107B - Digital root |
25A - IQ test | 785A - Anton and Polyhedrons |
1542B - Plus and Multiply | 306A - Candies |
1651C - Fault-tolerant Network | 870A - Search for Pretty Integers |
1174A - Ehab Fails to Be Thanos | 1169A - Circle Metro |