#include <bits/stdc++.h>

using namespace std;

int main() {

    ios::sync_with_stdio(false); cin.tie(0);
    int n,m,k,x,y,u,v, type, type2;
    long long w,w2;

    scanf("%d %d %d", &n, &m, &k);

    vector<set<tuple<int,int,int> > > G(n);
    map<pair<int,int>, int> mp;
    vector<long long> dis(n, LLONG_MAX);
    vector<int> st(n, INT_MAX);

    auto get = [] (int a, int b) -> pair<int,int> {
        return {min(a,b), max(a,b)};
    };
    for (int i = 0; i < m; ++i) {
        scanf("%d %d %lld", &x, &y, &w);
        x--,y--;
        if(mp.count(get(x,y))) {
            if(mp[get(x,y)] > w) {
                G[x].erase({y, mp[get(x,y)], 0});
                G[y].erase({x, mp[get(x,y)], 0});
                G[x].insert({y, w, 0});
                G[y].insert({x, w, 0});
            }
        } else {
            G[x].insert({y, w, 0});
            G[y].insert({x, w, 0});
            mp[get(x,y)] = w;
        }
    }

    for (int i = 0; i < k; ++i) {
        scanf("%d %d", &x, &y);
        x--;
        if(mp.count(get(1,x))) {
            if(mp[get(x,y)] > w) {
                G[x].erase({y, mp[get(x,y)], 0});
                G[y].erase({x, mp[get(x,y)], 0});
                G[0].insert({x, y, i + 1});
                G[x].insert({0, y, i + 1});
            }
        } else {
            mp[get(x,y)] = y;
            G[0].insert({x, y, i + 1});
            G[x].insert({0, y, i + 1});
        }
    }

    priority_queue<tuple<long long, int, int> > q;
    q.push({0,0,0});
    dis[0] = 0;
    st[0] = 0;

    while(!q.empty()) {
        tie(w, u, type) = q.top();
        q.pop();
        for (auto p: G[u]) {
            tie(v, w2, type2) = p;
            if(dis[u] + w2 < dis[v]) {
                dis[v] = dis[u] + w2;
                st[v] = max(type, type2);
                q.push({-dis[v], v, st[v]});
            } else if(dis[u] + w2 == dis[v] and max(type2, type) == 0) {
                st[v] = max(type2, type);
                q.push({-dis[v], v, st[v]});
            }
        }
    }

    set<int> s;
    for (int i = 0; i < n; ++i)  {
        if(st[i]) s.insert(st[i]);
    }
    cout << k - s.size() << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

    ios::sync_with_stdio(false); cin.tie(0);
    int n,m,k,x,y,u,v, type2;
    long long w,w2;

    scanf("%d %d %d", &n, &m, &k);

    vector<vector<tuple<int,int,int> > > G(n);
    vector<long long> dis(n, LLONG_MAX);
    vector<int> st(n, INT_MAX);
    map<pair<int,int>, pair<int,int> > mp;

    auto get = [] (int a,int b) -> pair<int,int> {
        return {min(a,b), max(a,b)};
    };

    for (int i = 0; i < m; ++i) {
        scanf("%d %d %lld", &x, &y, &w);
        x--,y--;
        if(!mp.count(get(x,y)))
            mp[get(x,y)] = {w,0};
        else mp[get(x,y)] = min({w,0}, mp[get(x,y)]);
    }

    for (int i = 0; i < k; ++i) {
        scanf("%d %d", &x, &y);
        x--;
        if(!mp.count(get(0,x)))
            mp[get(0,x)] = {y,i + 1};
        else mp[get(x,0)] = min(make_pair(y, i + 1), mp[get(x,0)]);
    }

    for (auto p: mp) {
        int x = p.first.first;
        int y = p.first.second;
        int w = p.second.first;
        int id = p.second.second;
        G[x].push_back({y,w,id});
        G[y].push_back({x,w,id});
    }

    priority_queue<pair<long long, int> > q;
    q.push({0,0});
    dis[0] = 0;
    st[0] = 0;
    while(!q.empty()) {
        w = -q.top().first;
        u = q.top().second;
        q.pop();
        if(dis[u] != -w) continue;
        for (auto p: G[u]) {
            tie(v, w2, type2) = p;
            if(dis[u] + w2 < dis[v]) {
                dis[v] = dis[u] + w2;
                st[v] = max(st[u], type2);
                q.push({-dis[v], v});
            } else if(dis[u] + w2 == dis[v] and max(type2, st[u]) == 0) {
                st[v] = max(type2, st[u]);
                q.push({-dis[v], v});
            }
        }
    }

    set<int> s;
    for (int i = 0; i < n; ++i)  {
        if(st[i]) s.insert(st[i]);
    }
    cout << k - s.size() << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

    ios::sync_with_stdio(false); cin.tie(0);
    int n,m,k,x,y,u,v, type, type2;
    long long w,w2;

    scanf("%d %d %d", &n, &m, &k);

    vector<vector<tuple<int,int,int> > > G(n);
    vector<long long> dis(n, LLONG_MAX);
    vector<int> st(n, INT_MAX);

    for (int i = 0; i < m; ++i) {
        scanf("%d %d %lld", &x, &y, &w);
        x--,y--;
        G[x].push_back({y, w, 0});
        G[y].push_back({x, w, 0});
    }

    for (int i = 0; i < k; ++i) {
        scanf("%d %d", &x, &y);
        x--;
        G[0].push_back({x, y, i + 1});
        G[x].push_back({0, y, i + 1});
    }

    priority_queue<tuple<long long, int, int> > q;
    q.push({0,0,0});
    dis[0] = 0;
    st[0] = 0;
    while(!q.empty()) {
        tie(w, u, type) = q.top();
        q.pop();

        for (auto p: G[u]) {
            tie(v, w2, type2) = p;
            if(dis[u] + w2 < dis[v]) {
                dis[v] = dis[u] + w2;
                st[v] = 1;
                q.push({-dis[v], v, st[v]});
            } else if(dis[u] + w2 == dis[v] and type == 0) {
                st[v] = 2;
                q.push({-dis[v], v, st[v]});
            }
        }
    }

    set<int> s;
    for (int i = 0; i < n; ++i)  {
        if(st[i] == 2) s.insert(st[i]);
    }
    cout << k - s.size() << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

    ios::sync_with_stdio(false); cin.tie(0);
    int n,m,k,x,y,u,v, type, type2;
    long long w,w2;

    scanf("%d %d %d", &n, &m, &k);

    vector<set<tuple<int,int,int> > > G(n);
    vector<long long> dis(n, LLONG_MAX);
    vector<int> st(n, INT_MAX);

    for (int i = 0; i < m; ++i) {
        scanf("%d %d %lld", &x, &y, &w);
        x--,y--;
        G[x].insert({y, w, 0});
        G[y].insert({x, w, 0});
    }

    for (int i = 0; i < k; ++i) {
        scanf("%d %d", &x, &y);
        x--;
        G[0].insert({x, y, i + 1});
        G[x].insert({0, y, i + 1});
    }

    priority_queue<tuple<long long, int, int> > q;
    q.push({0,0,0});
    dis[0] = 0;
    st[0] = 0;

    while(!q.empty()) {
        tie(w, u, type) = q.top();
        q.pop();
        for (auto p: G[u]) {
            tie(v, w2, type2) = p;
            if(dis[u] + w2 < dis[v]) {
                dis[v] = dis[u] + w2;
                st[v] = max(type, type2);
                q.push({-dis[v], v, st[v]});
            } else if(dis[u] + w2 == dis[v] and max(type2, type) == 0) {
                st[v] = max(type2, type);
                q.push({-dis[v], v, st[v]});
            }
        }
    }

    set<int> s;
    for (int i = 0; i < n; ++i)  {
        if(st[i]) s.insert(st[i]);
    }
    cout << k - s.size() << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

    ios::sync_with_stdio(false); cin.tie(0);
    int n,m,k,x,y,u,v, type, type2;
    long long w,w2;

    scanf("%d %d %d", &n, &m, &k);

    vector<set<tuple<int,int,int> > > G(n);
    map<pair<int,int>, pair<int,int> > mp;
    vector<long long> dis(n, LLONG_MAX);
    vector<int> st(n, INT_MAX);

    auto get = [] (int a, int b) -> pair<int,int> {
        return {min(a,b), max(a,b)};
    };
    for (int i = 0; i < m; ++i) {
        scanf("%d %d %lld", &x, &y, &w);
        x--,y--;
        if(mp.count(get(x,y))) {
            if(mp[get(x,y)].first > w) {
                G[x].erase({y, mp[get(x,y)].first, 0});
                G[y].erase({x, mp[get(x,y)].first, 0});
                G[x].insert({y, w, 0});
                G[y].insert({x, w, 0});
                mp[get(x,y)] = {w, 0};
            }
        } else {
            G[x].insert({y, w, 0});
            G[y].insert({x, w, 0});
            mp[get(x,y)] = {w, 0};
        }
    }

    for (int i = 0; i < k; ++i) {
        scanf("%d %d", &x, &y);
        x--;
        if(mp.count(get(1,x))) {
            if(mp[get(0,x)].first > y) {
                G[0].erase({x, mp[get(x,y)].first, mp[get(x,y)].second});
                G[x].erase({0, mp[get(x,y)].first, mp[get(x,y)].second});
                G[0].insert({x, y, i + 1});
                G[x].insert({0, y, i + 1});
                mp[get(0,x)] = {y, i + 1};
            }
        } else {
            mp[get(0,x)] = {y, i + 1};
            G[0].insert({x, y, i + 1});
            G[x].insert({0, y, i + 1});
        }
    }

    priority_queue<tuple<long long, int, int> > q;
    q.push({0,0,0});
    dis[0] = 0;
    st[0] = 0;

    while(!q.empty()) {
        tie(w, u, type) = q.top();
        q.pop();
        for (auto p: G[u]) {
            tie(v, w2, type2) = p;
            if(dis[u] + w2 < dis[v]) {
                dis[v] = dis[u] + w2;
                st[v] = max(type, type2);
                q.push({-dis[v], v, st[v]});
            } else if(dis[u] + w2 == dis[v] and max(type2, type) == 0) {
                st[v] = max(type2, type);
                q.push({-dis[v], v, st[v]});
            }
        }
    }

    set<int> s;
    for (int i = 0; i < n; ++i)  {
        if(st[i]) s.insert(st[i]);
    }
    cout << k - s.size() << "\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
struct ke{
    int v,w;
};
vector <ke> a[100001];
long long d[100001];
typedef pair <int,int>  ii;
map <int,bool> f;
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    priority_queue <ii,vector <ii>, greater<ii> > h;
    d[1]=0;
    h.push({d[1],1});
    while(!h.empty())
    {
        ii x=h.top();
        h.pop();
        int du=x.first;
        int u=x.second;
        for(auto i:a[u])
        {
            if(d[i.v]>=du+i.w)
            {
                d[i.v]=du+i.w;
                f[i.v]=false;
                h.push({d[i.v],i.v});
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=1;i<=n;i++)
        d[i]=1e9;
    for(int i=1;i<=k;i++)
    {
        int y,w;
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            f[y]=true;
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=f[i];
    }
    cout<<k-dem;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
struct ke{
    int v,w;
};
vector <ke> a[100001];
int vis[100001];
long long d[100001];
typedef pair <int,int>  ii;
map <int,bool> f;
queue <int> q;
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=0;
        for(auto i:a[u])
        {
            int v=i.v;
            int w=i.w;
            if(d[v]>d[u]+w)
            {
                d[v]=d[u]+w;
                f[v]=0;
                vis[v]=1;
                q.push(v);
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=1;i<=n;i++)
        d[i]=1e9;
    q.push(1);
    for(int i=1;i<=k;i++)
    {
        int y,w;
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            f[y]=true;
            q.push(y);
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=f[i];
    }
    cout<<k-dem;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
struct ke{
    int v,w;
};
vector <ke> a[100001];
int vis[100001];
long long d[100001];
typedef pair <int,int>  ii;
map <int,bool> f;
queue <int> q;
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=0;
        for(auto i:a[u])
        {
            int v=i.v;
            int w=i.w;
            if(d[v]>=d[u]+w)
            {
                d[v]=d[u]+w;
                f[v]=0;
                vis[v]=1;
                q.push(v);
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=1;i<=n;i++)
        d[i]=1e9;
    q.push(1);
    d[1]=0;
    vis[1]=1;
    for(int i=1;i<=k;i++)
    {
        int y,w;
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            f[y]=1;
            vis[y]=1;
            q.push(y);
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=f[i];
    }
    cout<<k-dem;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
struct ke{
    int v,w;
};
vector <ke> a[100001];
int d[100001];
typedef pair <int,int>  ii;
bool f[100001];
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    priority_queue <ii,vector <ii>, greater<ii> > h;
    d[1]=0;
    h.push({d[1],1});
    while(!h.empty())
    {
        ii x=h.top();
        h.pop();
        int du=x.first;
        int u=x.second;
        for(auto i:a[u])
        {
            if(d[i.v]==du+i.w)
            {
                f[i.v]=false;
            }
            if(d[i.v]>du+i.w)
            {
                d[i.v]=du+i.w;
                f[i.v]=false;
                h.push({d[i.v],i.v});
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=1;i<=n;i++)
        d[i]=1e9;
    for(int i=1;i<=k;i++)
    {
        int y,w;
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            f[y]=true;
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=f[i];
    }
    cout<<k-dem;
    return


#include <bits/stdc++.h>
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
struct ke{
    int v,w;
};
vector <ke> a[100001];
int d[100001];
typedef pair <int,int>  ii;
bool f[100001];
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    priority_queue <ii,vector <ii>, greater<ii> > h;
    d[1]=0;
    h.push({d[1],1});
    while(!h.empty())
    {
        ii x=h.top();
        h.pop();
        int du=x.first;
        int u=x.second;
        for(auto i:a[u])
        {
            if(d[i.v]==du+i.w)
            {
                f[i.v]=false;
            }
            if(d[i.v]>du+i.w)
            {
                d[i.v]=du+i.w;
                f[i.v]=false;
                h.push({d[i.v],i.v});
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=1;i<=n;i++)
        d[i]=1e9;
    for(int i=1;i<=k;i++)
    {
        int y,w;
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            f[y]=true;
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=f[i];
    }
    cout<<k-dem;
    return 0;


#include <bits/stdc++.h>
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
struct ke{
    int v,w;
};
vector <ke> a[100001];
int d[100001];
typedef pair <int,int>  ii;
bool f[100001];
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    priority_queue <ii,vector <ii>, greater<ii> > h;
    d[1]=0;
    h.push({d[1],1});
    while(!h.empty())
    {
        ii x=h.top();
        h.pop();
        int du=x.first;
        int u=x.second;
        for(auto i:a[u])
        {
            if(d[i.v]>=du+i.w)
            {
                d[i.v]=du+i.w;
                if(d[i.v]!=du+i.w)
                    h.push({d[i.v],i.v});
                f[i.v]=false;
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=1;i<=n;i++)
        d[i]=1e9;
    for(int i=1;i<=k;i++)
    {
        int y,w;
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            f[y]=true;
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=f[i];
    }
    cout<<k-dem;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define MAX 100001
#define inf 0x3f3f3f3f3f3
using namespace std;typedef pair <int,int>  ii;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
vector <ii> a[100001];
long long d[100001];

int vis[MAX],map[MAX];
queue <int> q;
void nhap()
{
    int u,v,w;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=0;
        for(auto i:a[u])
        {
            int v=i.first;
            int w=i.second;
            if(d[v]>=d[u]+w)
            {
                d[v]=d[u]+w;
                map[v]=0;
                vis[v]=1;
                q.push(v);
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=0;i<=n;i++)
        d[i]=inf;
    q.push(1);
    d[1]=0;
    vis[1]=1;
    for(int i=1;i<=k;i++)
    {
        int y,w;
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            map[y]=1;
            vis[y]=1;
            q.push(y);
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=map[i];
    }
    cout<<k-dem;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
struct ke{
    int v,w;
};
vector <ke> a[100001];
int d[100001];
typedef pair <int,int>  ii;
bool f[100001];
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    priority_queue <ii,vector <ii>, greater<ii> > h;
    d[1]=0;
    h.push({d[1],1});
    while(!h.empty())
    {
        ii x=h.top();
        h.pop();
        int du=x.first;
        int u=x.second;
        for(auto i:a[u])
        {
            if(d[i.v]>=du+i.w)
            {
                d[i.v]=du+i.w;
                if(d[i.v]!=du+i.w)
                    h.push({d[i.v],i.v});
                f[i.v]=false;
                h.push({d[i.v],i.v});
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=1;i<=n;i++)
        d[i]=1e9;
    for(int i=1;i<=k;i++)
    {
        int y,w;
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            f[y]=true;
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=f[i];
    }
    cout<<k-dem;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
struct ke{
    int v,w;
};
vector <ke> a[100001];
int d[100001];
typedef pair <int,int>  ii;
bool f[100001];
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    priority_queue <ii,vector <ii>, greater<ii> > h;
    d[1]=0;
    h.push({d[1],1});
    while(!h.empty())
    {
        ii x=h.top();
        h.pop();
        int du=x.first;
        int u=x.second;
        for(auto i:a[u])
        {
            if(d[i.v]>=du+i.w)
            {
                d[i.v]=du+i.w;
                f[i.v]=false;
                h.push({d[i.v],i.v});
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=1;i<=n;i++)
        d[i]=1e9;
    for(int i=1;i<=k;i++)
    {
        int y,w;
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            f[y]=true;
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=f[i];
    }
    cout<<k-dem;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
struct ke{
    int v,w;
};
vector <ke> a[100001];
int d[100001];
typedef pair <int,int>  ii;
bool f[100001];
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    priority_queue <ii,vector <ii>, greater<ii> > h;
    d[1]=0;
    h.push({d[1],1});
    while(!h.empty())
    {
        ii x=h.top();
        h.pop();
        int du=x.first;
        int u=x.second;
        for(auto i:a[u])
        {
            if(d[i.v]>=du+i.w)
            {
                d[i.v]=du+i.w;
                f[i.v]=false;
                h.push({d[i.v],i.v});
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=1;i<=n;i++)
        d[i]=1e9;
    for(int i=1;i<=k;i++)
    {
        int y,w;
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            f[y]=true;
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=f[i];
    }
    cout<<k-dem;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define MAX 100001
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
struct ke{
    int v,w;
};
vector <ke> a[100001];
long long d[100001];
typedef pair <int,int>  ii;
int vis[MAX],map[MAX];
queue <int> q;
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=0;
        for(auto i:a[u])
        {
            int v=i.v;
            int w=i.w;
            if(d[v]>=d[u]+w)
            {
                d[v]=d[u]+w;
                map[v]=0;
                vis[v]=1;
                q.push(v);
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=1;i<=n;i++)
        d[i]=1e9;
    q.push(1);
    d[1]=0;
    vis[1]=1;
    for(int i=1;i<=k;i++)
    {
        int y,w;
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            map[y]=1;
            vis[y]=1;
            q.push(y);
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=map[i];
    }
    cout<<k-dem;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
struct ke{
    int v,w;
};
vector <ke> a[100001];
long long d[100001];
typedef pair <int,int>  ii;
map <int,bool> f[100001];
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    priority_queue <ii,vector <ii>, greater<ii> > h;
    d[1]=0;
    h.push({d[1],1});
    while(!h.empty())
    {
        ii x=h.top();
        h.pop();
        int du=x.first;
        int u=x.second;
        for(auto i:a[u])
        {
            if(d[i.v]>=du+i.w)
            {
                d[i.v]=du+i.w;
                f[i.v]=false;
                h.push({d[i.v],i.v});
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=1;i<=n;i++)
        d[i]=1e9;
    for(int i=1;i<=k;i++)
    {
        int y,w;
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            f[y]=true;
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=f[i];
    }
    cout<<k-dem;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define MAX 100001
#define inf 0x3f3f3f3f3f3
using namespace std;typedef pair <int,int>  ii;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
vector <ii> a[100001];
long long d[100001];

int vis[MAX],map[MAX];
queue <int> q;
int x,y,w;
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=0;
        for(auto i:a[u])
        {
            int v=i.first;
            int w=i.second;
            if(d[v]>=d[u]+w)
            {
                d[v]=d[u]+w;
                map[v]=0;
                if(!vis[v])
                {
                    vis[v]=1;
                    q.push(v);
                }
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=0;i<=n;i++)
        d[i]=inf;
    q.push(1);
    d[1]=0;
    vis[1]=1;
    for(int i=1;i<=k;i++)
    {
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            map[y]=1;
            vis[y]=1;
            q.push(y);
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=map[i];
    }
    cout<<k-dem;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
struct ke{
    int v,w;
};
vector <ke> a[100001];
int d[100001];
typedef pair <int,int>  ii;
bool f[100001];
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    priority_queue <ii,vector <ii>, greater<ii> > h;
    d[1]=0;
    h.push({d[1],1});
    while(!h.empty())
    {
        ii x=h.top();
        h.pop();
        int du=x.first;
        int u=x.second;
        for(auto i:a[u])
        {
            if(d[i.v]==du+i.w)
            {
                f[i.v]=false;
            }
            if(d[i.v]>du+i.w)
            {
                d[i.v]=du+i.w;
                f[i.v]=false;
                h.push({d[i.v],i.v});
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=1;i<=n;i++)
        d[i]=1e9;
    for(int i=1;i<=k;i++)
    {
        int y,w;
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            f[y]=true;
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=f[i];
    }
    cout<<k-dem;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define MAX 100001
#define inf 0x3f3f3f3f3f3
using namespace std;typedef pair <int,int>  ii;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
vector <ii> a[100001];
long long d[100001];

int vis[MAX],map[MAX];
queue <int> q;
int x,y,w,u,v;
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=0;
        for(auto i:a[u])
        {
            int v=i.first;
            int w=i.second;
            if(d[v]>=d[u]+w)
            {
                d[v]=d[u]+w;
                map[v]=0;
                if(!vis[v])
                {
                    vis[v]=1;
                    q.push(v);
                }
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=0;i<=n;i++)
        d[i]=inf;
    q.push(1);
    d[1]=0;
    vis[1]=1;
    for(int i=1;i<=k;i++)
    {
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            map[y]=1;
            vis[y]=1;
            q.push(y);
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=map[i];
    }
    cout<<k-dem;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
struct ke{
    int v,w;
};
vector <ke> a[100001];
int vis[100001];
long long d[100001];
typedef pair <int,int>  ii;
map <int,bool> f;
queue <int> q;
void nhap()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
}
void dit_tra()
{
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=0;
        for(auto i:a[u])
        {
            int v=i.v;
            int w=i.w;
            if(d[v]>d[u]+w)
            {
                d[v]=d[u]+w;
                f[v]=0;
                vis[v]=1;
                q.push(v);
            }
        }
    }
}
int main()
{
    nhap();
    for(int i=1;i<=n;i++)
        d[i]=1e9;
    q.push(1);
    d[1]=0;
    vis[1]=1;
    for(int i=1;i<=k;i++)
    {
        int y,w;
        scanf("%d%d",&y,&w);
        if(d[y]>w)
        {
            d[y]=w;
            f[y]=1;
            q.push(y);
        }
    }
    dit_tra();
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        dem+=f[i];
    }
    cout<<k-dem;
    return 0;
}


#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0)
using namespace std;
#ifdef _WIN32
#include <windows.h>
#define print(x) PRINT(x, #x)
template<typename T> inline const void PRINT(T VARIABLE, string NAME)
{
#ifndef ONLINE_JUDGE /// ONLINE_JUDGE IS DEFINED ON CODEFORCES
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, 10);
    cerr << NAME << " = " << VARIABLE << '\n';
    SetConsoleTextAttribute(hConsole, 7);
#endif
}
#else
#define print(x) 0
#endif
struct pair_hash
{
    template<typename T1, typename T2>
    size_t operator () (const pair<T1, T2> &p) const
    {
        auto h1 = hash<T1>{}(p.first);
        auto h2 = hash<T2>{}(p.second);
        return h1 ^ h2;
    }
};
typedef long long ll;
typedef unsigned long long ull;
const ll INFLL = 2 * (ll)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
//ifstream fin(".in");
//ofstream fout(".out");
void die()
{
    cout << "-1";
    exit(0);
}
const int NMAX = 1e5 + 100;
const int MOD = 1e9 + 7; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;

int n, m, k;
VP graf[NMAX];
map<pair<int, int>, int> weight;
map<pair<int, int>, bool> is_train;
VP edges;
V trains;
int sol;
ll dist[NMAX];

priority_queue<pair<int, int>, VP, greater<pair<int, int> > > heap;
void dijkstra()
{
    heap.push({0, 1});
    for(int i = 1; i <= n; i++) dist[i] = INFLL;
    while(!heap.empty())
    {
        int nod = heap.top().second;
        int cost = heap.top().first;
        heap.pop();

        if(dist[nod] > cost)
        {
            print("here");
            dist[nod] = cost;
            for(auto i: graf[nod])
                if(dist[nod] + i.second < dist[i.first])
                    heap.push({dist[nod] + i.second, i.first});

        }
    }
}

int parent[NMAX];
void solve()
{
    for(auto i: edges)
    {
        if(dist[i.first] == dist[i.second] + weight[{i.first, i.second}])
            parent[i.first] = i.second;

        if(dist[i.second] == dist[i.first] + weight[{i.first, i.second}])
            parent[i.second] = i.first;
    }

    for(auto i: trains)
    {
        if((parent[i] != 1 && parent[i])) sol++;
    }

}

int main()
{
    FASTIO;
    cin >> n >> m >> k;
    for1(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        if(weight[{a, b}] == 0)
        {
            weight[{a, b}] = c;

            edges.pb({a, b});
        }
        else weight[{a, b}] = min(weight[{a, b}], c);
        weight[{b, a}] = weight[{a, b}];
        graf[a].pb({b, c});
        graf[b].pb({a, c});
    }
    for1(i, k)
    {
        int a, c;
        cin >> a >> c;
        if(weight[{a, 1}] == 0)
        {
            weight[{a, 1}] = c;
            trains.pb(a);
        }
        else if(weight[{a, 1}] <= c) sol++;
        else weight[{a, 1}] = c;
        weight[{1, a}] = weight[{a, 1}];
        graf[a].pb({1, c});
        graf[1].pb({a, c});
    }
    dijkstra();
    solve();
    cout << sol << endl;

    print(dist[2]); print(dist[3]);

    return 0;
}
/*
3 2 2
1 2 4
2 3 4
2 2
3 6
*/


#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define clr(A, x) memset(A, x, sizeof(A))
#define cpy(A, B) memcpy(A, B, sizeof(B))
#define g(s) getline(cin, s) ///ai grija la fin/cin ///
#define FASTIO ios_base::sync_with_stdio(0)
const long long INFLL = 2 * 1e18 + 100;
const int INFINT = 2 * 1e9 + 100;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
//ifstream fin("input.txt");
//ofstream fout("output.txt");
void die()
{
    cout << "-1";
    exit(0);
}
const int NMAX = 1e5 + 5;
const int MOD = 1e8; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;

int n, m, k;
VP graf[NMAX];
ll dist[NMAX];
ll trains[NMAX];
bool train[NMAX], trece_trenu[NMAX];
int sol;

void bfs()
{
    queue<int> coada;
    coada.push(1);

    while(!coada.empty())
    {
        int nod = coada.front();
     //   cout << nod << endl;
        coada.pop();
        for(auto i: graf[nod])
        {
            if(dist[i.first] == dist[nod] + i.second)
            {
                if(train[i.first])
                {
                    train[i.first] = 0;
                    sol++;
                    coada.push(i.first);
                }
                continue;
            }
            if(dist[i.first] > dist[nod] + i.second)
            {
                if(train[i.first])
                {
                    train[i.first] = 0;
                    sol++;
                }
                dist[i.first] = dist[nod] + i.second;
                coada.push(i.first);
                continue;
            }
            if(trece_trenu[i.first] == 1)
            {
                trece_trenu[i.first] = 0;
                coada.push(i.first);
            }
        }

    }
}

int main()
{
    FASTIO;
    cin >> n >> m >> k;
    for1(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        graf[a].pb({b, c});
        graf[b].pb({a, c});
    }
    for1(i, n)
        dist[i] = INFLL, trains[i] = INFLL;
    for1(i, k)
    {
        int a, b;
        cin >> a >> b;
        if(trains[a] != INFLL)
            sol++;
        trains[a] = min(trains[a], (ll)b);
    }
    dist[1] = 0;
    for(int i = 2; i <= n; i++)
    {
        dist[i] = trains[i];
        if(trains[i] != INFLL)
            train[i] = trece_trenu[i] = 1;
    }

    bfs();
    cout << sol;
    return 0;
}


#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0)
using namespace std;
#ifdef _WIN32
#include <windows.h>
#define print(x) PRINT(x, #x)
template<typename T> inline const void PRINT(T VARIABLE, string NAME)
{
#ifndef ONLINE_JUDGE /// ONLINE_JUDGE IS DEFINED ON CODEFORCES
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, 10);
    cerr << NAME << " = " << VARIABLE << '\n';
    SetConsoleTextAttribute(hConsole, 7);
#endif
}
#else
#define print(x) 0
#endif
struct pair_hash
{
    template<typename T1, typename T2>
    size_t operator () (const pair<T1, T2> &p) const
    {
        auto h1 = hash<T1>{}(p.first);
        auto h2 = hash<T2>{}(p.second);
        return h1 ^ h2;
    }
};
typedef long long ll;
typedef unsigned long long ull;
const ll INFLL = 2 * (ll)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
//ifstream fin(".in");
//ofstream fout(".out");
void die()
{
    cout << "-1";
    exit(0);
}
const int NMAX = 1e5 + 100;
const int MOD = 1e9 + 7; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;

int n, m, k;
VP graf[NMAX];
unordered_map<pair<int, int>, int, pair_hash> weight;
unordered_map<pair<int, int>, bool, pair_hash> is_train;
VP edges;
V trains;
int sol;
ll dist[NMAX];

priority_queue<pair<int, int>, VP, greater<pair<int, int> > > heap;
void dijkstra()
{
    heap.push({0, 1});
    for(int i = 1; i <= n; i++) dist[i] = INFLL;
    while(!heap.empty())
    {
        int nod = heap.top().second;
        int cost = heap.top().first;
        heap.pop();

        if(dist[nod] > cost)
        {
            print("here");
            dist[nod] = cost;
            for(auto i: graf[nod])
                if(dist[nod] + i.second < dist[i.first])
                    heap.push({dist[nod] + i.second, i.first});

        }
    }
}

int parent[NMAX];
void solve()
{
    for(auto i: edges)
    {
        if(dist[i.first] == dist[i.second] + weight[{i.first, i.second}])
            parent[i.first] = i.second;

        if(dist[i.second] == dist[i.first] + weight[{i.first, i.second}])
            parent[i.second] = i.first;
    }

    for(auto i: trains)
    {
        if((parent[i] != 1 && parent[i])) sol++;
    }

}

int main()
{
    FASTIO;
    cin >> n >> m >> k;
    for1(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        if(weight[{a, b}] == 0)
        {
            weight[{a, b}] = c;

            edges.pb({a, b});
        }
        else weight[{a, b}] = min(weight[{a, b}], c);
        weight[{b, a}] = weight[{a, b}];
        graf[a].pb({b, c});
        graf[b].pb({a, c});
    }
    for1(i, k)
    {
        int a, c;
        cin >> a >> c;
        if(weight[{a, 1}] == 0)
        {
            weight[{a, 1}] = c;
            trains.pb(a);
        }
        else if(weight[{a, 1}] <= c) sol++;
        else weight[{a, 1}] = c;
        weight[{1, a}] = weight[{a, 1}];
        graf[a].pb({1, c});
        graf[1].pb({a, c});
    }
    dijkstra();
    solve();
    cout << sol << endl;

    print(dist[2]); print(dist[3]);

    return 0;
}
/*
3 2 2
1 2 4
2 3 4
2 2
3 6
*/


#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0)
using namespace std;
#ifdef _WIN32
#include <windows.h>
#define print(x) PRINT(x, #x)
template<typename T> inline const void PRINT(T VARIABLE, string NAME)
{
#ifndef ONLINE_JUDGE /// ONLINE_JUDGE IS DEFINED ON CODEFORCES
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, 10);
    cerr << NAME << " = " << VARIABLE << '\n';
    SetConsoleTextAttribute(hConsole, 7);
#endif
}
#else
#define print(x) 0
#endif
struct pair_hash
{
    template<typename T1, typename T2>
    size_t operator () (const pair<T1, T2> &p) const
    {
        auto h1 = hash<T1>{}(p.first);
        auto h2 = hash<T2>{}(p.second);
        return h1 ^ h2;
    }
};
typedef long long ll;
typedef unsigned long long ull;
const ll INFLL = 2 * (ll)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
//ifstream fin(".in");
//ofstream fout(".out");
void die()
{
    cout << "-1";
    exit(0);
}
const int NMAX = 1e5 + 5;
const int MOD = 1e9 + 7; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;

int n, m, k;
vector<pair<pair<int, int>, int > > graf[NMAX];

ll dist[NMAX];
bool used_train[NMAX];
void dij()
{
    priority_queue<pair<pair<int, int>, int >, vector<pair<pair<int, int>, int > >, greater<pair<pair<int, int>, int > > > heap;
    heap.push(mp(mp(0, 0), 1));
    for1(i, n) dist[i] = INFLL;
    while(!heap.empty())
    {
        int nod = heap.top().second;
        int cost = heap.top().first.first;
        bool train = heap.top().first.second;
        heap.pop();

        if(dist[nod] > cost)
        {
            print(nod);
            dist[nod] = cost;
            used_train[nod] = train;

            for(auto i: graf[nod])
                if(dist[nod] + i.first.second < dist[i.first.first])
                    heap.push(mp(mp(dist[nod] + i.first.second, i.second), i.first.first));
        }
    }
}

int main()
{
    FASTIO;
    cin >> n >> m >> k;
    for1(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        graf[a].pb(mp(mp(b, c), 0));
        graf[b].pb(mp(mp(a, c), 0));
    }
    for1(i, k)
    {
        int a, c;
        cin >> a >> c;
        graf[1].pb(mp(mp(a, c), 1));
        graf[a].pb(mp(mp(1, c), 1));
    }
    dij();
    int ans = 0;
    for1(i, n) if(used_train[i]) ans++;
    cout << k - ans;
    return 0;
}


#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define clr(A, x) memset(A, x, sizeof(A))
#define cpy(A, B) memcpy(A, B, sizeof(B))
#define g(s) getline(cin, s) ///ai grija la fin/cin ///
#define FASTIO ios_base::sync_with_stdio(0)
const long long INFLL = 2 * 1e18 + 100;
const int INFINT = 2 * 1e9 + 100;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
//ifstream fin("input.txt");
//ofstream fout("output.txt");
void die()
{
    cout << "-1";
    exit(0);
}
const int NMAX = 1e5 + 5;
const int MOD = 1e8; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;

int n, m, k;
VP graf[NMAX];
ll dist[NMAX];
set<int> trains[NMAX];
int sol;

void bfs()
{
    queue<int> coada;
    coada.push(1);

    while(!coada.empty())
    {
        int nod = coada.front();
        coada.pop();
        for(auto i: graf[nod])
            if(dist[i.first] > dist[nod] + i.second)
            {
                dist[i.first] = dist[nod] + i.second;
                coada.push(i.first);
            }
    }
}

int main()
{
    FASTIO;
    cin >> n >> m >> k;
    for1(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        graf[a].pb({b, c});
        graf[b].pb({a, c});
    }
    for1(i, n)
        dist[i] = INFLL;
    dist[1] = dist[0] = 0;
    bfs();

    for1(i, k)
    {
        int a, b;
        cin >> a >> b;
        trains[a].insert(b);
    }

    for1(i, n)
    {
        if(trains[i].empty())
            continue;
        if(dist[i] <= *trains[i].begin())
            sol += trains[i].size();
        else sol += trains[i].size() - 1;
    }
    cout << sol;
    return 0;
}


#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define clr(A, x) memset(A, x, sizeof(A))
#define cpy(A, B) memcpy(A, B, sizeof(B))
#define g(s) getline(cin, s) ///ai grija la fin/cin ///
#define FASTIO ios_base::sync_with_stdio(0)
const long long INFLL = 2 * 1e18 + 100;
const int INFINT = 2 * 1e9 + 100;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
//ifstream fin("input.txt");
//ofstream fout("output.txt");
void die()
{
    cout << "-1";
    exit(0);
}
const int NMAX = 1e5 + 5;
const int MOD = 1e8; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;

int n, m, k;
VP graf[NMAX];
ll dist[NMAX];
int trains[NMAX];
bool train[NMAX], trece_trenu[NMAX];
int sol;

void bfs()
{
    queue<int> coada;
    coada.push(1);

    while(!coada.empty())
    {
        int nod = coada.front();
     //   cout << nod << endl;
        coada.pop();
        for(auto i: graf[nod])
        {
            if(dist[i.first] == dist[nod] + i.second)
            {
                if(train[i.first])
                {
                    train[i.first] = 0;
                    sol++;
                    coada.push(i.first);
                }
                continue;
            }
            if(dist[i.first] > dist[nod] + i.second)
            {
                if(train[i.first])
                {
                    train[i.first] = 0;
                    sol++;
                }
                dist[i.first] = dist[nod] + i.second;
                coada.push(i.first);
                continue;
            }
            if(trece_trenu[i.first] == 1)
            {
                trece_trenu[i.first] = 0;
                coada.push(i.first);
            }
        }

    }
}

int main()
{
    FASTIO;
    cin >> n >> m >> k;
    for1(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        graf[a].pb({b, c});
        graf[b].pb({a, c});
    }
    for1(i, n)
        dist[i] = INFLL, trains[i] = INFINT;
    for1(i, k)
    {
        int a, b;
        cin >> a >> b;
        if(trains[a] != INFINT)
            sol++;
        trains[a] = min(trains[a], b);
    }
    dist[1] = 0;
    for(int i = 2; i <= n; i++)
    {
        dist[i] = trains[i];
        if(trains[i] != INFINT)
            train[i] = trece_trenu[i] = 1;
    }

    bfs();
    cout << sol;
    return 0;
}


import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scan in = new Scan ();
        Print out = new Print ();

        String s = in.scanString();

        int sum = 0,
        	multiplier = 1;

        if(s.charAt(0) == 'a')
        	sum = 1;

        for(int i = 1; i < s.length(); i++) {
        	if(s.charAt(i) == 'a') {
        		sum += multiplier;
        	}
        	else if(s.charAt(i) == 'b') {
        		if(s.charAt(i - 1) == 'a')
        			multiplier++;
        	}
        	else {
        		multiplier = 1;
        	}
        }

        out.println(Integer.valueOf(sum).toString());

        out.close();
    }

    static class Scan {
		private byte[] buf=new byte[1024];
		private int index;
		private InputStream in;
		private int total;
		public Scan()
		{
			in=System.in;
		}
		public int scan()throws IOException
		{
			if(total<0)
			throw new InputMismatchException();
			if(index>=total)
			{
				index=0;
				total=in.read(buf);
				if(total<=0)
				return -1;
			}
			return buf[index++];
		}
		public int scanInt()throws IOException
		{
			int integer=0;
			int n=scan();
			while(isWhiteSpace(n))
			n=scan();
			int neg=1;
			if(n=='-')
			{
				neg=-1;
				n=scan();
			}
			while(!isWhiteSpace(n))
			{
				if(n>='0'&&n<='9')
				{
					integer*=10;
					integer+=n-'0';
					n=scan();
				}
				else throw new InputMismatchException();
			}
			return neg*integer;
		}
		public long scanLong()throws IOException
		{
			long integer=0;
			int n=scan();
			while(isWhiteSpace(n))
			n=scan();
			int neg=1;
			if(n=='-')
			{
				neg=-1;
				n=scan();
			}
			while(!isWhiteSpace(n))
			{
				if(n>='0'&&n<='9')
				{
					integer*=10;
					integer+=n-'0';
					n=scan();
				}
				else throw new InputMismatchException();
			}
			return neg*integer;
		}
		public double scanDouble()throws IOException
		{
			double doub=0;
			int n=scan();
			while(isWhiteSpace(n))
			n=scan();
			int neg=1;
			if(n=='-')
			{
				neg=-1;
				n=scan();
			}
			while(!isWhiteSpace(n)&&n!='.')
			{
				if(n>='0'&&n<='9')
				{
					doub*=10;
					doub+=n-'0';
					n=scan();
				}
				else throw new InputMismatchException();
			}
			if(n=='.')
			{
				n=scan();
				double temp=1;
				while(!isWhiteSpace(n))
				{
					if(n>='0'&&n<='9')
					{
						temp/=10;
						doub+=(n-'0')*temp;
						n=scan();
					}
					else throw new InputMismatchException();
				}
			}
			return doub*neg;
		}
		public String scanString()throws IOException
		{
			StringBuilder sb=new StringBuilder();
			int n=scan();
			while(isWhiteSpace(n))
			n=scan();
			while(!isWhiteSpace(n))
			{
				sb.append((char)n);
				n=scan();
			}
			return sb.toString();
		}
		private boolean isWhiteSpace(int n)
		{
			if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
			return true;
			return false;
		}
	}

	static class Print {
		private final BufferedWriter bw;
		public Print()
		{
			bw=new BufferedWriter(new OutputStreamWriter(System.out));
		}
		public void print(String str)throws IOException
		{
			bw.append(str);
		}
		public void println(String str)throws IOException
		{
			print(str);
			bw.append("\n");
		}
		public void flushedPrintln(String str)throws IOException {
			println(str);
			bw.flush();
		}
		public void close()throws IOException
		{
			bw.close();
		}
		public void flush() throws IOException {
			bw.flush();
		}
	}
}


import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scan in = new Scan ();
        Print out = new Print ();

        String s = in.scanString();
        StringBuilder sb = new StringBuilder(s.length());

        for(int i = 0; i < s.length(); i++)
        	if(s.charAt(i) == 'a' || s.charAt(i) == 'b')
        		sb.append(s.charAt(i));

        s = sb.toString();

        long sum = 0,
        	 M = 1000000007l;

        if(s.length() > 0) {
			long multiplier = 0;

	        for(int i = 0; i < s.length(); i++) {
	        	if(s.charAt(i) == 'a') {
	        		sum = (sum + multiplier + 1) % M;
	        	}
	        	else if(s.charAt(i) == 'b') {
	        		if(i > 0 && s.charAt(i - 1) == 'a'){
	        			multiplier = sum;
	        		}
	        	}
	        }
	    }

        out.println(Long.valueOf(sum % M).toString());

        out.close();
    }

    static class Scan {
		private byte[] buf=new byte[1024];
		private int index;
		private InputStream in;
		private int total;
		public Scan()
		{
			in=System.in;
		}
		public int scan()throws IOException
		{
			if(total<0)
			throw new InputMismatchException();
			if(index>=total)
			{
				index=0;
				total=in.read(buf);
				if(total<=0)
				return -1;
			}
			return buf[index++];
		}
		public int scanInt()throws IOException
		{
			int integer=0;
			int n=scan();
			while(isWhiteSpace(n))
			n=scan();
			int neg=1;
			if(n=='-')
			{
				neg=-1;
				n=scan();
			}
			while(!isWhiteSpace(n))
			{
				if(n>='0'&&n<='9')
				{
					integer*=10;
					integer+=n-'0';
					n=scan();
				}
				else throw new InputMismatchException();
			}
			return neg*integer;
		}
		public long scanLong()throws IOException
		{
			long integer=0;
			int n=scan();
			while(isWhiteSpace(n))
			n=scan();
			int neg=1;
			if(n=='-')
			{
				neg=-1;
				n=scan();
			}
			while(!isWhiteSpace(n))
			{
				if(n>='0'&&n<='9')
				{
					integer*=10;
					integer+=n-'0';
					n=scan();
				}
				else throw new InputMismatchException();
			}
			return neg*integer;
		}
		public double scanDouble()throws IOException
		{
			double doub=0;
			int n=scan();
			while(isWhiteSpace(n))
			n=scan();
			int neg=1;
			if(n=='-')
			{
				neg=-1;
				n=scan();
			}
			while(!isWhiteSpace(n)&&n!='.')
			{
				if(n>='0'&&n<='9')
				{
					doub*=10;
					doub+=n-'0';
					n=scan();
				}
				else throw new InputMismatchException();
			}
			if(n=='.')
			{
				n=scan();
				double temp=1;
				while(!isWhiteSpace(n))
				{
					if(n>='0'&&n<='9')
					{
						temp/=10;
						doub+=(n-'0')*temp;
						n=scan();
					}
					else throw new InputMismatchException();
				}
			}
			return doub*neg;
		}
		public String scanString()throws IOException
		{
			StringBuilder sb=new StringBuilder();
			int n=scan();
			while(isWhiteSpace(n))
			n=scan();
			while(!isWhiteSpace(n))
			{
				sb.append((char)n);
				n=scan();
			}
			return sb.toString();
		}
		private boolean isWhiteSpace(int n)
		{
			if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
			return true;
			return false;
		}
	}

	static class Print {
		private final BufferedWriter bw;
		public Print()
		{
			bw=new BufferedWriter(new OutputStreamWriter(System.out));
		}
		public void print(String str)throws IOException
		{
			bw.append(str);
		}
		public void println(String str)throws IOException
		{
			print(str);
			bw.append("\n");
		}
		public void flushedPrintln(String str)throws IOException {
			println(str);
			bw.flush();
		}
		public void close()throws IOException
		{
			bw.close();
		}
		public void flush() throws IOException {
			bw.flush();
		}
	}
}


import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scan in = new Scan ();
        Print out = new Print ();

        String s = in.scanString();
        StringBuilder sb = new StringBuilder(s.length());

        for(int i = 0; i < s.length(); i++)
        	if(s.charAt(i) == 'a' || s.charAt(i) == 'b')
        		sb.append(s.charAt(i));

        s = sb.toString();

        long sum = 0,
        	 M = 1000000007l;

        if(s.length() > 0) {
			int multiplier = 1,
				aNum = 0;

	        if(s.charAt(0) == 'a') {
	        	sum = aNum = 1;
	        }

	        for(int i = 1; i < s.length(); i++) {
	        	if(s.charAt(i) == 'a') {
	        		if(aNum > 0 && s.charAt(i - 1) == 'b') {
	        			multiplier += aNum - 1;
	        			aNum = 0;
	        		}
	        		sum += multiplier;
	        		aNum++;
	        	}
	        	else if(s.charAt(i) == 'b') {
	        		if(s.charAt(i - 1) == 'a')
	        			multiplier++;
	        	}
	        	/*else {
	        		multiplier = 1;
	        		aNum = 0;
	        	}*/
	        }
	    }

        out.println(Long.valueOf(sum % M).toString());

        out.close();
    }

    static class Scan {
		private byte[] buf=new byte[1024];
		private int index;
		private InputStream in;
		private int total;
		public Scan()
		{
			in=System.in;
		}
		public int scan()throws IOException
		{
			if(total<0)
			throw new InputMismatchException();
			if(index>=total)
			{
				index=0;
				total=in.read(buf);
				if(total<=0)
				return -1;
			}
			return buf[index++];
		}
		public int scanInt()throws IOException
		{
			int integer=0;
			int n=scan();
			while(isWhiteSpace(n))
			n=scan();
			int neg=1;
			if(n=='-')
			{
				neg=-1;
				n=scan();
			}
			while(!isWhiteSpace(n))
			{
				if(n>='0'&&n<='9')
				{
					integer*=10;
					integer+=n-'0';
					n=scan();
				}
				else throw new InputMismatchException();
			}
			return neg*integer;
		}
		public long scanLong()throws IOException
		{
			long integer=0;
			int n=scan();
			while(isWhiteSpace(n))
			n=scan();
			int neg=1;
			if(n=='-')
			{
				neg=-1;
				n=scan();
			}
			while(!isWhiteSpace(n))
			{
				if(n>='0'&&n<='9')
				{
					integer*=10;
					integer+=n-'0';
					n=scan();
				}
				else throw new InputMismatchException();
			}
			return neg*integer;
		}
		public double scanDouble()throws IOException
		{
			double doub=0;
			int n=scan();
			while(isWhiteSpace(n))
			n=scan();
			int neg=1;
			if(n=='-')
			{
				neg=-1;
				n=scan();
			}
			while(!isWhiteSpace(n)&&n!='.')
			{
				if(n>='0'&&n<='9')
				{
					doub*=10;
					doub+=n-'0';
					n=scan();
				}
				else throw new InputMismatchException();
			}
			if(n=='.')
			{
				n=scan();
				double temp=1;
				while(!isWhiteSpace(n))
				{
					if(n>='0'&&n<='9')
					{
						temp/=10;
						doub+=(n-'0')*temp;
						n=scan();
					}
					else throw new InputMismatchException();
				}
			}
			return doub*neg;
		}
		public String scanString()throws IOException
		{
			StringBuilder sb=new StringBuilder();
			int n=scan();
			while(isWhiteSpace(n))
			n=scan();
			while(!isWhiteSpace(n))
			{
				sb.append((char)n);
				n=scan();
			}
			return sb.toString();
		}
		private boolean isWhiteSpace(int n)
		{
			if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
			return true;
			return false;
		}
	}

	static class Print {
		private final BufferedWriter bw;
		public Print()
		{
			bw=new BufferedWriter(new OutputStreamWriter(System.out));
		}
		public void print(String str)throws IOException
		{
			bw.append(str);
		}
		public void println(String str)throws IOException
		{
			print(str);
			bw.append("\n");
		}
		public void flushedPrintln(String str)throws IOException {
			println(str);
			bw.flush();
		}
		public void close()throws IOException
		{
			bw.close();
		}
		public void flush() throws IOException {
			bw.flush();
		}
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class TheFairNutAndString
{
    static final int MOD = 1000000007;
    static String str;

    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        str = in.next();
        System.out.println(solve(0));
    }

    static int solve(int k)
    {

        int[] dp = new int[str.length()];
        Arrays.fill(dp, 0);
        dp[0] = str.charAt(0) == 'a' ? 1 : 0;
        int aCnt = dp[0];
        int sec = 0;

        for(int i = 1; i < str.length(); i++)
        {
//            System.out.println("********* i: " + i + " *********");
//            System.out.println(str.charAt(i));
            dp[i] = dp[i-1];
            if(str.charAt(i) == 'a')
            {
                aCnt++;
                dp[i] += 1 + sec;
            }
            else if(str.charAt(i) == 'b')
            {
                sec = aCnt;
            }
            dp[i] %= MOD;
//            System.out.println("aCnt: " + aCnt + "\tsec: " + sec);
        }
//        System.out.println(Arrays.toString(dp));
        return dp[str.length() - 1];
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class TheFairNutAndString
{
    static final int MOD = 1000000007;
    static String str;

    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        str = in.next();
        System.out.println(solve(0));
    }

    static int solve(int k)
    {

        int[] dp = new int[str.length()];
        Arrays.fill(dp, 0);
        dp[0] = str.charAt(0) == 'a' ? 1 : 0;
        int aCnt = dp[0];
        int sec = 0;

        for(int i = 1; i < str.length(); i++)
        {
//            System.out.println("********* i: " + i + " *********");
//            System.out.println(str.charAt(i));
            dp[i] = dp[i-1];
            if(str.charAt(i) == 'a')
            {
                aCnt++;
                dp[i] += 1 + sec;
            }
            else if(str.charAt(i) == 'b')
            {
                sec = aCnt;
            }
//            System.out.println("aCnt: " + aCnt + "\tsec: " + sec);
        }
//        System.out.println(Arrays.toString(dp));
        return dp[str.length() - 1];
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class TheFairNutAndString2
{

    static final int MOD = (int) (1e9 + 7);
    static String str;

    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        str = in.next() + 'b';
        System.out.println(solve());
    }

    static long solve()
    {
        long res = 1;
        long tmp = 0;
        int cnt = 0;
        ArrayList<Long> al = new ArrayList<>();

        for(int i = 0; i < str.length(); i++)
        {
            if(str.charAt(i) == 'a')
                tmp++;
            else if(str.charAt(i) == 'b')
            {
                al.add(tmp);
                tmp = 0;
            }
        }

        for(int i = 0; i < al.size(); i++)
        {
            res = (res * (al.get(i) + 1)) % MOD;
        }

        return res - 1;
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class TheFairNutAndString2
{

    static final int MOD = (int) (1e9 + 7);
    static String str;

    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        str = in.next() + 'b';
        System.out.println(solve());
    }

    static int solve()
    {
        int res = 1;
        int tmp = 0;
        int cnt = 0;
        ArrayList<Integer> al = new ArrayList<>();

        for(int i = 0; i < str.length(); i++)
        {
            if(str.charAt(i) == 'a')
                tmp++;
            else if(str.charAt(i) == 'b')
            {
                al.add(tmp);
                tmp = 0;
            }
        }

        for(int i = 0; i < al.size(); i++)
        {
            res = (res * (al.get(i) + 1)) % MOD;
        }

        return res - 1;
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTheFairNutAndString solver = new CTheFairNutAndString();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTheFairNutAndString {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            long ans = 1;
            int index = 0;
            while (index < s.length() && s.charAt(index) != 'a') {
                index++;
            }
            if (index > s.length()) {
                out.println(0);
            } else {
                int[] count = new int[s.length()];
                for (int i = 0; i < s.length(); i++) count[i] = 0;
                int j = 0;
                for (int i = index; i < s.length(); i++) {
                    if (s.charAt(i) == 'a') {
                        count[j]++;
                    } else if (s.charAt(i) == 'b') {
                        j++;
                    }
                }
                long sum = 0;
                for (int i = 0; i < s.length(); i++) {
                    //out.print(count[i]+" ");
                    sum += count[i];
                }
                for (int i = 0; i < s.length(); i++) {
                    if (count[i] != 0) {
                        ans = ans * (count[i] + 1);
                    }
                }
                out.println(ans - 1);
            }
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTheFairNutAndString solver = new CTheFairNutAndString();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTheFairNutAndString {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            long ans = 0;
            int index = 0;
            while (index < s.length() && s.charAt(index) != 'a') {
                index++;
            }
            if (index > s.length()) {
                out.println(0);
            } else {

                for (int i = 0; i < s.length(); i++) {
                    if (s.charAt(i) == 'a') {
                        ans++;
                    }
                }

                ans %= 1000000007;
                int[] count = new int[s.length()];
                for (int i = 0; i < s.length(); i++) count[i] = 0;
                int j = 0;
                for (int i = index; i < s.length(); i++) {
                    if (s.charAt(i) == 'a') {
                        count[j]++;
                    } else if (s.charAt(i) == 'b') {
                        j++;
                    }
                }
                long sum = 0;
                for (int i = 0; i < s.length(); i++) {
                    //out.print(count[i]+" ");
                    sum += count[i];
                }
                for (int i = 0; i < s.length(); i++) {
                    sum -= count[i];
                    long temp = sum * count[i];
                    temp %= 1000000007;
                    ans += temp;
                }
                out.println(ans);
            }
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTheFairNutAndString solver = new CTheFairNutAndString();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTheFairNutAndString {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            long ans = 1;
            int index = 0;
            while (index < s.length() && s.charAt(index) != 'a') {
                index++;
            }
            if (index > s.length()) {
                out.println(0);
            } else {
                int[] count = new int[s.length()];
                for (int i = 0; i < s.length(); i++) count[i] = 0;
                int j = 0;
                for (int i = index; i < s.length(); i++) {
                    if (s.charAt(i) == 'a') {
                        count[j]++;
                    } else if (s.charAt(i) == 'b') {
                        j++;
                    }
                }
                for (int i = 0; i < s.length(); i++) {
                    if (count[i] != 0) {
                        ans = ans * (count[i] + 1);
                        ans %= 1000000007;
                    }
                }
                out.println(ans - 1);
            }
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTheFairNutAndString solver = new CTheFairNutAndString();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTheFairNutAndString {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            long ans = 0;
            int index = 0;
            while (s.charAt(index) != 'a') {
                index++;
            }
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == 'a') {
                    ans++;
                }
            }

            ans %= 1000000007;
            int[] count = new int[s.length()];
            for (int i = 0; i < s.length(); i++) count[i] = 0;
            int j = 0;
            for (int i = index; i < s.length(); i++) {
                if (s.charAt(i) == 'a') {
                    count[j]++;
                } else if (s.charAt(i) == 'b') {
                    j++;
                }
            }
            long sum = 0;
            for (int i = 0; i < s.length(); i++) {
                //out.print(count[i]+" ");
                sum += count[i];
            }
            for (int i = 0; i < s.length(); i++) {
                sum -= count[i];
                long temp = sum * count[i];
                temp %= 1000000007;
                ans += temp;
            }
            out.println(ans);
        }

    }
}


//Where there is a will, there is a way !
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
	// write your code here
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        PrintWriter pw=new PrintWriter(System.out);
        /*
        inputCopy
inputCopy
abbaa
outputCopy
5
inputCopy
baaaa
outputCopy
4
inputCopy
agaa
outputCopy
3

        */
        char [] str=st.nextToken().toCharArray();
        int n=str.length;
        int [] totala=new int[n];
        long ans=0;
        long mod=(long)(1e9+7);
        //System.out.println(mod);
        if(str[0]=='a') {
            totala[0] = 1;
            ++ans;
        }
        for(int i=1;i<str.length;++i)
        {
            totala[i]=totala[i-1];
            if(str[i]=='a') {
                ++totala[i];
                ++ans;
            }
        }
        int preva=0;
        for(int i=0;i<str.length;++i)
        {
            char i2=str[i];
            for(int j=i+1;j<str.length;++j)
            {
                if(str[j]=='b')
                {
                    while(j+1<str.length)
                    {
                        ++j;
                        if(str[j]=='b')
                            continue;
                        if(i2<=str[j]) {
                            ++ans;
                            ans = ans % mod;
                        }
                    }
                }
            }
        }
        pw.println(ans);
        pw.flush();
        pw.close();
    }

}


//Where there is a will, there is a way !
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
	// write your code here
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        PrintWriter pw=new PrintWriter(System.out);
        /*
        inputCopy
inputCopy
abbaa
outputCopy
5
inputCopy
baaaa
outputCopy
4
inputCopy
agaa
outputCopy
3

        */
        char [] str=st.nextToken().toCharArray();
        int n=str.length;
        int [] totala=new int[n];
        long ans=0;
        long mod=(long)(1e9+7);
        if(str[0]=='a') {
            totala[0] = 1;
            ++ans;
        }
        for(int i=1;i<str.length;++i)
        {
            totala[i]=totala[i-1];
            if(str[i]=='a') {
                ++totala[i];
                ++ans;
            }
        }
        int preva=0;
        for(int i=0;i<str.length;++i)
        {
            if(str[i]=='b')
            {
                ans+=(totala[i]-preva)*(totala[n-1]-totala[i]);
                ans%=mod;
                preva=totala[i];
                while(i+1<str.length && str[i+1]=='b')
                {
                    ++i;
                }
            }
        }
        pw.println(ans);
        pw.flush();
        pw.close();
    }

}


//Where there is a will, there is a way !
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
	// write your code here
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        PrintWriter pw=new PrintWriter(System.out);
        /*
        inputCopy
inputCopy
abbaa
outputCopy
5
inputCopy
baaaa
outputCopy
4
inputCopy
agaa
outputCopy
3

        */
        char [] str=st.nextToken().toCharArray();
        int n=str.length;
        int [] totala=new int[n];
        long ans=0;
        long mod=(long)(1e9+7);
        if(str[0]=='a') {
            totala[0] = 1;
            ++ans;
        }
        for(int i=1;i<str.length;++i)
        {
            totala[i]=totala[i-1];
            if(str[i]=='a') {
                ++totala[i];
                ++ans;
            }
        }
        int preva=0;
        for(int i=0;i<str.length;++i)
        {
            if(str[i]=='b')
            {
                ans+=(totala[i]-preva)*(totala[n-1]-totala[i]);
                ans%=mod;
                preva+=totala[i];
            }
        }
        pw.println(ans);
        pw.flush();
        pw.close();
    }

}


//Where there is a will, there is a way !
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
	// write your code here
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        PrintWriter pw=new PrintWriter(System.out);
        /*
        inputCopy
inputCopy
abbaa
outputCopy
5
inputCopy
baaaa
outputCopy
4
inputCopy
agaa
outputCopy
3

        */
        char [] str=st.nextToken().toCharArray();
        int n=str.length;
        int [] totala=new int[n];
        long ans=0;
        long mod=(long)(1e9+7);
        if(str[0]=='a') {
            totala[0] = 1;
            ++ans;
        }
        for(int i=1;i<str.length;++i)
        {
            totala[i]=totala[i-1];
            if(str[i]=='a') {
                ++totala[i];
                ++ans;
            }
        }
        int preva=0;
        for(int i=0;i<str.length;++i)
        {
            if(str[i]=='b')
            {
                ans+=(long)(totala[i]-preva)*(long)(totala[n-1]-totala[i]);
                ans%=mod;
                preva=totala[i];
                while(i+1<str.length && str[i+1]=='b')
                {
                    ++i;
                }
            }
        }
        pw.println(ans);
        pw.flush();
        pw.close();
    }

}


// Magic. Do not touch.
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    static int mod=(int)(1e9+7);
    static class FastReader
    {
        PrintWriter pw = new PrintWriter(System.out);
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(next()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
        public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li)arr[li]=i();}
        public void printIntArr(int [] arr){ for(int li=0;li<arr.length;++li)pw.print(arr[li]+" ");pw.println();}
        public void printLongArr(long [] arr){ for(int li=0;li<arr.length;++li)pw.print(arr[li]+" ");pw.println();}
        public void scanIntIndexArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i()-1;}}
        public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}}
        public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }
        public void shuffle(long [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); long temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }
        public int swapIntegers(int a,int b){return a;} //Call it like this: a=swapIntegers(b,b=a)
    }
    public static boolean possible=true;
    public static String [] ans;
    public static void main(String[] args) throws IOException {

        FastReader fr = new FastReader();
        PrintWriter pw = new PrintWriter(System.out);

     /*
inputCopy
abbaa
outputCopy
5
inputCopy
baaaa
outputCopy
4
inputCopy
agaa
outputCopy
3
  */
        //Press Ctrl+Win+Alt+L for reformatting indentation

        int t = 1;

        for (int ti = 0; ti < t; ++ti) {
            char [] str=fr.nextLine().toCharArray();
            long ans=0;
            long prev=0;
            for (char c : str) {
                if (c != 'a' && c != 'b')
                    continue;
                if (c == 'a')
                    ans += 1+prev;
                else
                    prev = ans;
                ans %= mod;
            }
            pw.println(ans);
        }
        pw.flush();
        pw.close();
    }
}


import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {

    void solve(){
        char s[]=ns().toCharArray();
        long  ans=1;
        boolean a=false;
        int cc=0;

        for(char ch : s){
            if(ch=='a'){
                cc++;
                a=true;
            }else if(ch=='b'){
                ans*=(1+cc);
                if(ans>=M) ans%=M;
                cc=0;
            }

        }
        ans*=(1+cc);
        if(ans>=M) ans%=M;
        ans--;
        if(ans<0) ans+=M;
        if(!a) ans=0;

        pw.println(ans);
    }

    long M= (long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");

    }
    public static void main(String[] args) throws Exception { new Main().run(); }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }

}


import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {

    void solve(){
        char s[]=ns().toCharArray();
        long  ans=1;
        boolean a=false;
        int cc=0;

        for(char ch : s){
            if(ch=='a'){
                cc++;
                a=true;
            }else if(ch=='b'){
                ans*=(1+cc);
                cc=0;
            }

        }
        ans*=(1+cc);
        ans--;
        if(!a) ans=0;

        pw.println(ans);
    }

    long M= (long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");

    }
    public static void main(String[] args) throws Exception { new Main().run(); }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }

}


import java.util.Scanner;

public class CString {

    public static final long MOD = (long)Math.pow(10,9) + 7l;

    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        String s = scn.next();
        System.out.println(subs(s));

    }

    public static long subs(String s) {
        long sums = 1;

        long t = 1;

        for (char c : s.toCharArray()) {
            if (c == 'a') {
                t += 1;
            }

            if ( c == 'b') {
                if (t > 0) {
                    sums *= t % MOD;
                    t = 1;
                }
            }
        }

        if (t > 0)
            sums *= t;

        return (sums - 1) % MOD;
    }

}


import java.util.Scanner;

public class CString {

    public static final long MOD = (long)Math.pow(10,9) + 7l;

    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        String s = scn.next();
        System.out.println(subs(s));

    }

    public static long subs(String s) {
        long sums = 1;

        long t = 1;

        for (char c : s.toCharArray()) {
            if (c == 'a') {
                t += 1;
                t %= MOD;
            }

            if ( c == 'b') {
                if (t > 0) {
                    sums *= (t % MOD);
                    sums %= MOD;
                    t = 1;
                }
            }
        }

        if (t > 0)
            sums *= t % MOD;

        return (sums - 1) % MOD;
    }

}


import java.util.Scanner;

public class CString {

    public static final long MOD = (long)Math.pow(10,9) + 7l;

    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        String s = scn.next();
        System.out.println(subs(s));
    }

    public static long subs(String s) {
        long sums = 1;

        long t = 1;

        for (char c : s.toCharArray()) {
            if (c == 'a') {
                t += 1;
                t %= MOD;
            }

            if ( c == 'b') {
                if (t > 0) {
                    sums *= t;
                    sums %= MOD;
                    t = 1;
                }
            }
        }

        if (t > 0)
            sums *= t;

        return (sums - 1) % MOD;
    }

}


import java.util.Scanner;

public class CString {

    public static final long MOD = (long)Math.pow(10,9) + 7l;

    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        String s = scn.next();
        System.out.println(subs(s));

    }

    public static long subs(String s) {
        long sums = 1;

        long t = 1;

        for (char c : s.toCharArray()) {
            if (c == 'a') {
                t += 1;
                t %= MOD;
            }

            if ( c == 'b') {
                if (t > 0) {
                    sums *= t % MOD;
                    t = 1;
                }
            }
        }

        if (t > 0)
            sums *= t % MOD;

        return (sums - 1) % MOD;
    }

}


import java.util.Scanner;

public class CString {

    public static final long MOD = (long)Math.pow(10,9) + 7l;
    private static Long[] cache;

    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        String s = scn.next();
        cache = new Long[s.length()+1];
        System.out.println(subs(0,s));

    }

    public static long subs(int i, String s) {
        if (cache[i] != null)
            return cache[i];

        if (i >= s.length())
            return 0;

        if (s.charAt(i) == 'a') {
            for (int x = i+1; x < s.length(); x++) {
                if (s.charAt(x) == 'b') {
                    cache[i] = ((1l + 2*subs(x+1, s))%MOD);
                    return cache[i];
                }
            }

            cache[i] = ((1l+subs(i+1,s))% MOD);
            return cache[i];
        }

        cache[i] = (subs(i+1, s)%MOD);
        return cache[i];
    }

}


import java.util.Scanner;

public class CString {

    public static final long MOD = (long)Math.pow(10,9) + 7l;
    private static Long[] cache;

    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        String s = scn.next();
        cache = new Long[s.length()+1];
        System.out.println(subs(s));

    }

    public static long subs(String s) {
        long sums = 1;

        long t = 1;

        for (char c : s.toCharArray()) {
            if (c == 'a') {
                t += 1;
            }

            if ( c == 'b') {
                if (t > 0) {
                    sums *= t;
                    t = 1;
                }
            }
        }

        if (t > 0)
            sums *= t;

        return sums - 1;
    }

}


import java.util.Scanner;

public class Task1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s=in.next();
        int a[]=new int[s.length()];
        int t=0;
        for (int i = 0; i <s.length() ; i++) {
            if(s.charAt(i)=='a'){a[t]++;}
            if(s.charAt(i)=='b') {t++;}
        }
        long k=1;
        for (int i = 0; i <s.length() ; i++) {
             k*=(a[i]+1);
        }
        k--;
        System.out.print(k%1000000007);
    }
}


import java.util.Scanner;

public class Task1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long s=in.nextLong();
        int minkol=1000000000;
        long v=-s;
        for (int i = 0; i <n ; i++) {
            int a=in.nextInt();
            if(a<minkol){
                minkol=a;
            }
            v+=a;
        }
        if(0>v){
            System.out.print(-1);
        }else{
            System.out.print(Math.min((v)/n,minkol));
        }
    }
}


import java.util.Scanner;

public class Task1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s=in.next();
        int a[]=new int[s.length()];
        int t=0;
        for (int i = 0; i <s.length() ; i++) {
            if(s.charAt(i)=='a'){a[t]++;}
            if(s.charAt(i)=='b') {t++;}
        }
        long k=1;
        for (int i = 0; i <s.length() ; i++) {
             k*=(a[i]+1);
            k%=1000000007;
        }
        k--;
        if(k<0){ k+=1000000007;}
        System.out.print(k);
    }
}


import java.util.Scanner;

public class Task1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s=in.next();
        int a[]=new int[s.length()];
        int t=0;
        for (int i = 0; i <s.length() ; i++) {
            if(s.charAt(i)=='a'){a[t]++;}
            if(s.charAt(i)=='b') {t++;}
        }
        long k=1;
        for (int i = 0; i <s.length() ; i++) {
            if(a[i]!=0){ k*=(a[i]+1);}
        }
        System.out.print((k-1)%(1000000007));
    }
}


import java.util.Scanner;

public class Task1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s=in.next();
        int a[]=new int[s.length()];
        int t=0;
        for (int i = 0; i <s.length() ; i++) {
            if(s.charAt(i)=='a'){a[t]++;}
            if(s.charAt(i)=='b') {t++;}
        }
        int k=1;
        for (int i = 0; i <s.length() ; i++) {
            if(a[i]!=0){ k*=(a[i]+1);}
        }
        System.out.print(k-1);
    }
}


import java.util.Scanner;

public class Task1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s=in.next();
        int a[]=new int[s.length()];
        int t=0;
        for (int i = 0; i <s.length() ; i++) {
            if(s.charAt(i)=='a'){a[t]++;}
            if(s.charAt(i)=='b') {t++;}
        }
        int k=1;
        for (int i = 0; i <s.length() ; i++) {
            if(a[i]!=0){ k*=(a[i]+1);}
        }
        System.out.print((k-1)%(1000000007));
    }
}


#include <string>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    string s;
    cin >> s;

    int n = s.length();
    long long res = 0;
    int pos;
    vector<int> numa;
    int *presum = new int[n];

    for (pos = 0; pos < n; pos++)
        if (s[pos] == 'a')
            break;
    int numOfa = 0;
    int blocka = 0;

    while (pos < n)
    {
        if (s[pos] == 'a')
        {
            blocka++;
            pos++;
            numOfa++;
        }
        else if (s[pos] == 'b')
        {
            while (s[pos] == 'b' && pos < n)
                pos++;
            numa.push_back(blocka);
            blocka = 0;
        }
        else
            pos++;
    }

    if (blocka != 0)
        numa.push_back(blocka);
    res += numOfa;

    if (numa.size() > 1)
    {
        presum[0] = numa[0];
        for (int i = 1; i < numa.size(); i++) presum[i] = presum[i - 1] + numa[i];
        for (int i = 0; i < numa.size() - 1; i++)
        {
            res += numa[i] * (presum[numa.size() - 1] - presum[i]);
            res %= 1000000000 + 7;
        }
    }

    printf("%lld", res);
}


#include <string>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    string s;
    cin >> s;

    int mod = 1e9 + 7;
    int n = s.length();
    long long res = 1;
    int pos;
    bool bflag = false;
    bool aflag = false;
    int numOfa = 0;

    for (pos = 0; pos < n; pos++)
        if (s[pos] == 'a')
            break;
        else if (s[pos] == 'b')
            bflag = true;
    int blocka = 0;

    while (pos < n)
    {
        if (s[pos] == 'a')
        {
            blocka++;
            numOfa++;
            pos++;
            if (!aflag)
                aflag = true;
        }
        else if (s[pos] == 'b')
        {
            while (s[pos] == 'b' && pos < n)
                pos++;
            res = res * (blocka + 1) % mod;
            blocka = 0;
            if (!bflag)
                bflag = true;
        }
        else
            pos++;
    }

    if (!bflag)
        res = numOfa;
    else if (!aflag)
        res = 0;
    else if (blocka != 0)
        res = (res * (blocka + 1) % mod) - 1;
    else res--;
    printf("%lld", res);
}


#include <string>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    string s;
    cin >> s;

    int mod = 1e9 + 7;
    int n = s.length();
    long long res = 1;
    int pos;
    bool bflag = false;
    bool aflag = false;
    int numOfa = 0;

    for (pos = 0; pos < n; pos++)
        if (s[pos] == 'a')
            break;
        else if (s[pos] == 'b')
            bflag = true;
    int blocka = 0;

    while (pos < n)
    {
        if (s[pos] == 'a')
        {
            blocka++;
            numOfa++;
            pos++;
            if (!aflag)
                aflag = true;
        }
        else if (s[pos] == 'b')
        {
            while (s[pos] == 'b' && pos < n)
                pos++;
            res = res * (blocka + 1) % mod;
            blocka = 0;
            if (!bflag)
                bflag = true;
        }
        else
            pos++;
    }

    if (!bflag)
        res = numOfa;
    else if (!aflag)
        res = 0;
    else if (blocka != 0)
        res = res * (blocka + 1) % mod - 1;
    printf("%lld", res);
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
int main() {
	string s;
	cin>>s;
	ll c=0,ans=1;
	for(int i=0;i<s.size();i++){
	    if(s[i]=='a'){
	        c++;
	    }
	    else{
	        if(s[i]=='b'){
	        ans=(ans*(1+c))%mod;
	        c=0;
	        }
	    }
	}
	ans=(ans*(1+c))%mod;
	cout<<ans-1;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
int main() {
	string s;
	cin>>s;
	ll c=0,ans=1;
	for(int i=0;i<s.size();i++){
	    if(s[i]=='a'){
	        c++;
	    }
	    else{
	        if(s[i]=='b'){
    	        ans=(ans*(1+c))%mod;
    	        c=0;
	        }
	    }
	}
	cout<<(ans*(1+c))%mod-1;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
int main() {
	string s;
	cin>>s;
	ll c=0,ans=1;
	for(int i=0;i<s.size();i++){
	    if(s[i]=='a'){
	        c++;
	    }
	    else{
	        ans=(ans*(1+c))%mod;
	        c=0;
	    }
	}
	ans=(ans*(1+c))%mod;
	cout<<ans-1;

	return 0;
}


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

long long mod = 1000000007;

int main(){
    ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);

    string input, other;
    cin >> input;

    int n = input.length();

    bool previous_b;
    int ca = 0;
    long long ans = 1;

    for (int i = 0; i < n; i++){
        if (i == n - 1 && input[i] == 'a'){
            ca++;
            ans = (ans * (++ca)) % mod;
            //cout << ans << " ";
        } else if (i == n - 1) {
            ans = (ans * (++ca)) % mod;
        } else if(input[i] != 'a' && input[i] != 'b'){
            continue;
        } else if (input[i] == 'a'){
            ca++;
            previous_b = false;
        } else if (input[i] == 'b' && previous_b){
            continue;
        } else{
            ans = (ans * (++ca)) % mod;
            //cout << ans << " ";
            ca = 0;
            previous_b = true;
        }
    }
    cout << ans - 1 << endl;
    return 0;
}


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

long long mod = 1000000007;

int main(){
    ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);

    string input, other;
    cin >> input;

    int n = input.length();

    bool previous_b;
    int ca = 0;
    long long ans = 1;

    for (int i = 0; i < n; i++){
        if (i == n - 1 && input[i] == 'a'){
            ca++;
            ans = (ans * (++ca)) % mod;
            //cout << ans << " ";
        } else if(input[i] != 'a' && input[i] != 'b'){
            continue;
        } else if (input[i] == 'a'){
            ca++;
            previous_b = false;
        } else if (input[i] == 'b' && previous_b){
            continue;
        } else{
            ans = (ans * (++ca)) % mod;
            //cout << ans << " ";
            ca = 0;
            previous_b = true;
        }
    }
    cout << ans - 1 << endl;
    return 0;
}