// SRM 683, d2-hard, by Errichto
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nax = 1e6 + 5 ;
int a[ nax] ;
vector< int > w[ nax] ;
const int mod = 1e9 + 7 ;
int answer;
int mul( int a, int b) { return ( ll) a * b % mod; }
pair< int ,int > dfs( int a, int par) {
int pref = 1 , ways = 1 ;
for ( int b : w[ a] ) if ( b ! = par) {
pair< int ,int > tmp = dfs( b, a) ;
pref = add( mul( pref, tmp.second ) , mul( ways, tmp.first ) ) ;
ways = mul( ways, tmp.second ) ;
}
answer = add( answer, pref) ;
return make_pair( pref, ways + 1 ) ;
}
class SubtreesCounting {
public : int sumOfSizes( int n, int a0, int b, int c, int m) {
a[ 0 ] = a0;
for ( int i = 1 ; i <= n - 2 ; ++ i)
a[ i] = ( ( ll) b * a[ i- 1 ] + c) % m;
for ( int i = 1 ; i <= n - 1 ; ++ i) {
int j = a[ i- 1 ] % i;
// edge between i and j
w[ i] .push_back ( j) ;
w[ j] .push_back ( i) ;
}
dfs( 0 , - 1 ) ;
return answer;
}
} ;
Ly8gU1JNIDY4MywgZDItaGFyZCwgYnkgRXJyaWNodG8KI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBsb25nIGxvbmcgbGw7CmNvbnN0IGludCBuYXggPSAxZTYgKyA1OwppbnQgYVtuYXhdOwp2ZWN0b3I8aW50PiB3W25heF07CmNvbnN0IGludCBtb2QgPSAxZTkgKyA3OwppbnQgYW5zd2VyOwoKaW50IG11bChpbnQgYSwgaW50IGIpIHsgcmV0dXJuIChsbCkgYSAqIGIgJSBtb2Q7IH0KCnBhaXI8aW50LGludD4gZGZzKGludCBhLCBpbnQgcGFyKSB7CglpbnQgcHJlZiA9IDEsIHdheXMgPSAxOwoJZm9yKGludCBiIDogd1thXSkgaWYoYiAhPSBwYXIpIHsKCQlwYWlyPGludCxpbnQ+IHRtcCA9IGRmcyhiLCBhKTsKCQlwcmVmID0gYWRkKG11bChwcmVmLCB0bXAuc2Vjb25kKSwgbXVsKHdheXMsIHRtcC5maXJzdCkpOwoJCXdheXMgPSBtdWwod2F5cywgdG1wLnNlY29uZCk7Cgl9CglhbnN3ZXIgPSBhZGQoYW5zd2VyLCBwcmVmKTsKCXJldHVybiBtYWtlX3BhaXIocHJlZiwgd2F5cyArIDEpOwp9CgpjbGFzcyBTdWJ0cmVlc0NvdW50aW5nIHsKCXB1YmxpYyA6IGludCBzdW1PZlNpemVzKGludCBuLCBpbnQgYTAsIGludCBiLCBpbnQgYywgaW50IG0pIHsKCQlhWzBdID0gYTA7CgkJZm9yKGludCBpID0gMTsgaSA8PSBuIC0gMjsgKytpKQoJCQlhW2ldID0gKChsbCkgYiAqIGFbaS0xXSArIGMpICUgbTsKCQlmb3IoaW50IGkgPSAxOyBpIDw9IG4gLSAxOyArK2kpIHsKCQkJaW50IGogPSBhW2ktMV0gJSBpOwoJCQkvLyBlZGdlIGJldHdlZW4gaSBhbmQgagoJCQl3W2ldLnB1c2hfYmFjayhqKTsKCQkJd1tqXS5wdXNoX2JhY2soaSk7CgkJfQoJCWRmcygwLCAtMSk7CgkJcmV0dXJuIGFuc3dlcjsKCX0gCn07
compilation info
prog.cpp: In function 'std::pair<int, int> dfs(int, int)':
prog.cpp:17:57: error: 'add' was not declared in this scope
pref = add(mul(pref, tmp.second), mul(ways, tmp.first));
^
prog.cpp:20:27: error: 'add' was not declared in this scope
answer = add(answer, pref);
^
stdout