Language: C++

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

Compiler output:
a.cc:4:113: error: expected ')' before '{' token
    4 | typedef long long L;using namespace std;map<L,L>T U;L P U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;L M(L f{return f?B[f]+M(f^f&-f):0;}L S(L i){for(c=G i++)-M(i);i<2e5;i+=i&-i)B[i]+=c;}L D(L f){L d;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,d-P[f]?P[d]=f,C[d]=I->second,D(d),n=Z[f]+=++Z[d],Z[H[f]]<Z[d]?H[f]=d:0:0;}L K(L f){return Z[a=X[f]]>Z[n=X[b]]?n=b,b=f,K(n):abs(M(O[f])-(a-n?-G O[a])-K(P[a]):M(O[b])));}main(){for(cin>>n>>k;--*Z+n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(0);Z[a=H[P[++n]]-n?n:0];)for(;!O[a];c=a,a=H[a],S(*Z=O[c]=++b))X[a]=n;)for(cin>>a;cin>>s>>a>>b;S(b=O[a]-1),a=H[a],S(b+1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}
      |                                                                                                             ~   ^
      |                                                                                                                 )
a.cc: In function 'L S(L)':
a.cc:4:190: warning: no return statement in function returning non-void [-Wreturn-type]
    4 | typedef long long L;using namespace std;map<L,L>T U;L P U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;L M(L f{return f?B[f]+M(f^f&-f):0;}L S(L i){for(c=G i++)-M(i);i<2e5;i+=i&-i)B[i]+=c;}L D(L f){L d;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,d-P[f]?P[d]=f,C[d]=I->second,D(d),n=Z[f]+=++Z[d],Z[H[f]]<Z[d]?H[f]=d:0:0;}L K(L f){return Z[a=X[f]]>Z[n=X[b]]?n=b,b=f,K(n):abs(M(O[f])-(a-n?-G O[a])-K(P[a]):M(O[b])));}main(){for(cin>>n>>k;--*Z+n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(0);Z[a=H[P[++n]]-n?n:0];)for(;!O[a];c=a,a=H[a],S(*Z=O[c]=++b))X[a]=n;)for(cin>>a;cin>>s>>a>>b;S(b=O[a]-1),a=H[a],S(b+1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}
      |                                                                                                                                                                                              ^
a.cc: In function 'L D(L)':
a.cc:4:344: warning: no return statement in function returning non-void [-Wreturn-type]
    4 | typedef long long L;using namespace std;map<L,L>T U;L P U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;L M(L f{return f?B[f]+M(f^f&-f):0;}L S(L i){for(c=G i++)-M(i);i<2e5;i+=i&-i)B[i]+=c;}L D(L f){L d;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,d-P[f]?P[d]=f,C[d]=I->second,D(d),n=Z[f]+=++Z[d],Z[H[f]]<Z[d]?H[f]=d:0:0;}L K(L f){return Z[a=X[f]]>Z[n=X[b]]?n=b,b=f,K(n):abs(M(O[f])-(a-n?-G O[a])-K(P[a]):M(O[b])));}main(){for(cin>>n>>k;--*Z+n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(0);Z[a=H[P[++n]]-n?n:0];)for(;!O[a];c=a,a=H[a],S(*Z=O[c]=++b))X[a]=n;)for(cin>>a;cin>>s>>a>>b;S(b=O[a]-1),a=H[a],S(b+1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}
      |                                                                                                                                                                                                                                                                                                                                                        ^
a.cc: At global scope:
a.cc:4:439: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | typedef long long L;using namespace std;map<L,L>T U;L P U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;L M(L f{return f?B[f]+M(f^f&-f):0;}L S(L i){for(c=G i++)-M(i);i<2e5;i+=i&-i)B[i]+=c;}L D(L f){L d;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,d-P[f]?P[d]=f,C[d]=I->second,D(d),n=Z[f]+=++Z[d],Z[H[f]]<Z[d]?H[f]=d:0:0;}L K(L f){return Z[a=X[f]]>Z[n=X[b]]?n=b,b=f,K(n):abs(M(O[f])-(a-n?-G O[a])-K(P[a]):M(O[b])));}main(){for(cin>>n>>k;--*Z+n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(0);Z[a=H[P[++n]]-n?n:0];)for(;!O[a];c=a,a=H[a],S(*Z=O[c]=++b))X[a]=n;)for(cin>>a;cin>>s>>a>>b;S(b=O[a]-1),a=H[a],S(b+1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                       ^~~~
a.cc: In function 'int main()':
a.cc:4:573: error: expected primary-expression before ')' token
    4 | typedef long long L;using namespace std;map<L,L>T U;L P U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;L M(L f{return f?B[f]+M(f^f&-f):0;}L S(L i){for(c=G i++)-M(i);i<2e5;i+=i&-i)B[i]+=c;}L D(L f){L d;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,d-P[f]?P[d]=f,C[d]=I->second,D(d),n=Z[f]+=++Z[d],Z[H[f]]<Z[d]?H[f]=d:0:0;}L K(L f){return Z[a=X[f]]>Z[n=X[b]]?n=b,b=f,K(n):abs(M(O[f])-(a-n?-G O[a])-K(P[a]):M(O[b])));}main(){for(cin>>n>>k;--*Z+n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(0);Z[a=H[P[++n]]-n?n:0];)for(;!O[a];c=a,a=H[a],S(*Z=O[c]=++b))X[a]=n;)for(cin>>a;cin>>s>>a>>b;S(b=O[a]-1),a=H[a],S(b+1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ^
a.cc:4:623: error: expected ';' before ')' token
    4 | typedef long long L;using namespace std;map<L,L>T U;L P U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;L M(L f{return f?B[f]+M(f^f&-f):0;}L S(L i){for(c=G i++)-M(i);i<2e5;i+=i&-i)B[i]+=c;}L D(L f){L d;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,d-P[f]?P[d]=f,C[d]=I->second,D(d),n=Z[f]+=++Z[d],Z[H[f]]<Z[d]?H[f]=d:0:0;}L K(L f){return Z[a=X[f]]>Z[n=X[b]]?n=b,b=f,K(n):abs(M(O[f])-(a-n?-G O[a])-K(P[a]):M(O[b])));}main(){for(cin>>n>>k;--*Z+n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(0);Z[a=H[P[++n]]-n?n:0];)for(;!O[a];c=a,a=H[a],S(*Z=O[c]=++b))X[a]=n;)for(cin>>a;cin>>s>>a>>b;S(b=O[a]-1),a=H[a],S(b+1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ^
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ;