Language: C++

#include<bits/stdc++.h>
#define U [1<<17]={}
#define G(a)((c=A[a]+A[P[a]]+C[a])%k?c:0)
typedef long long L;using namespace std;ap<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U; D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;} M(L i){return i?B[i]+M(i^i&-i):0;} S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;} K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f])-M(O[a])+G(a)+K(P[a]):abs(M(O[f])-M(O[b]));}ain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(b=0);n<*Z;n++)if(!n|H[P[a=n]]-n)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}

Compiler output:
a.cc:4:41: error: 'ap' does not name a type
    4 | typedef long long L;using namespace std;ap<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U; D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;} M(L i){return i?B[i]+M(i^i&-i):0;} S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;} K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f])-M(O[a])+G(a)+K(P[a]):abs(M(O[f])-M(O[b]));}ain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(b=0);n<*Z;n++)if(!n|H[P[a=n]]-n)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}
      |                                         ^~
a.cc:4:110: error: ISO C++ forbids declaration of 'D' with no type [-fpermissive]
    4 | typedef long long L;using namespace std;ap<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U; D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;} M(L i){return i?B[i]+M(i^i&-i):0;} S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;} K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f])-M(O[a])+G(a)+K(P[a]):abs(M(O[f])-M(O[b]));}ain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(b=0);n<*Z;n++)if(!n|H[P[a=n]]-n)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}
      |                                                                                                              ^
a.cc: In function 'int D(L)':
a.cc:4:153: error: 'T' was not declared in this scope
    4 | typedef long long L;using namespace std;ap<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U; D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;} M(L i){return i?B[i]+M(i^i&-i):0;} S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;} K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f])-M(O[a])+G(a)+K(P[a]):abs(M(O[f])-M(O[b]));}ain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(b=0);n<*Z;n++)if(!n|H[P[a=n]]-n)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}
      |                                                                                                                                                         ^
a.cc:4:282: warning: no return statement in function returning non-void [-Wreturn-type]
    4 | typedef long long L;using namespace std;ap<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U; D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;} M(L i){return i?B[i]+M(i^i&-i):0;} S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;} K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f])-M(O[a])+G(a)+K(P[a]):abs(M(O[f])-M(O[b]));}ain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(b=0);n<*Z;n++)if(!n|H[P[a=n]]-n)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}
      |                                                                                                                                                                                                                                                                                          ^
a.cc: At global scope:
a.cc:4:284: error: ISO C++ forbids declaration of 'M' with no type [-fpermissive]
    4 | typedef long long L;using namespace std;ap<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U; D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;} M(L i){return i?B[i]+M(i^i&-i):0;} S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;} K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f])-M(O[a])+G(a)+K(P[a]):abs(M(O[f])-M(O[b]));}ain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(b=0);n<*Z;n++)if(!n|H[P[a=n]]-n)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}
      |                                                                                                                                                                                                                                                                                            ^
a.cc:4:319: error: ISO C++ forbids declaration of 'S' with no type [-fpermissive]
    4 | typedef long long L;using namespace std;ap<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U; D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;} M(L i){return i?B[i]+M(i^i&-i):0;} S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;} K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f])-M(O[a])+G(a)+K(P[a]):abs(M(O[f])-M(O[b]));}ain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(b=0);n<*Z;n++)if(!n|H[P[a=n]]-n)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}
      |                                                                                                                                                                                                                                                                                                                               ^
a.cc: In function 'int S(L, L)':
a.cc:4:375: warning: no return statement in function returning non-void [-Wreturn-type]
    4 | typedef long long L;using namespace std;ap<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U; D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;} M(L i){return i?B[i]+M(i^i&-i):0;} S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;} K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f])-M(O[a])+G(a)+K(P[a]):abs(M(O[f])-M(O[b]));}ain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(b=0);n<*Z;n++)if(!n|H[P[a=n]]-n)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}
      |                                                                                                                                                                                                                                                                                                                                                                                       ^
a.cc: At global scope:
a.cc:4:377: error: ISO C++ forbids declaration of 'K' with no type [-fpermissive]
    4 | typedef long long L;using namespace std;ap<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U; D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;} M(L i){return i?B[i]+M(i^i&-i):0;} S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;} K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f])-M(O[a])+G(a)+K(P[a]):abs(M(O[f])-M(O[b]));}ain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(b=0);n<*Z;n++)if(!n|H[P[a=n]]-n)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}
      |                                                                                                                                                                                                                                                                                                                                                                                         ^
a.cc:4:484: error: ISO C++ forbids declaration of 'ain' with no type [-fpermissive]
    4 | typedef long long L;using namespace std;ap<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U; D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;} M(L i){return i?B[i]+M(i^i&-i):0;} S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;} K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f])-M(O[a])+G(a)+K(P[a]):abs(M(O[f])-M(O[b]));}ain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(b=0);n<*Z;n++)if(!n|H[P[a=n]]-n)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ^~~
a.cc: In function 'int ain()':
a.cc:4:508: error: 'T' was not declared in this scope
    4 | typedef long long L;using namespace std;ap<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U; D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;} M(L i){return i?B[i]+M(i^i&-i):0;} S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;} K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f])-M(O[a])+G(a)+K(P[a]):abs(M(O[f])-M(O[b]))