Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define fi first
#define se second
#define gc getchar
#define pc putchar
inline ll read(){
    ll x=0,f=1;char c=gc();
    for(;!isdigit(c);c=gc())if(c=='-')f=-1;
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return x*f;
}
inline void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
inline void wri(ll x){write(x);pc(' ');}
inline void writeln(ll x){write(x);pc('\n');}
#define int ll
const int maxn = 2005;
struct Edge{
	int to,nxt,cap;
	ll v;
	Edge(){}
	Edge(int to,int nxt,int cap,ll v):
		to(to),nxt(nxt),cap(cap),v(v){}
}edge[maxn*maxn];
int first[maxn],nume;
int tot,S,T,idx[maxn],idy[maxn];
void Addedge(int a,int b,int c,ll v){
//	printf("_%d -> %d{%d %d}\n",a,b,c,v);
	edge[nume] = Edge(b,first[a],c,v);first[a] = nume++;
	edge[nume] = Edge(a,first[b],0,-v);first[b] = nume++;
}
ll dis[maxn];
int q[maxn*maxn],vis[maxn],from[maxn];
bool spfa(){
	Rep(i,1,tot) dis[i] = -(1ll<<62),vis[i] = 0,from[i] = 0;
	int front=0,rear=0;
	q[rear++] = S;dis[S] = 0;vis[S] = true;
	while(front < rear){
		int u = q[front++];vis[u] = false;
		for(int e=first[u];~e;e=edge[e].nxt){
			if(dis[edge[e].to] < dis[u] + edge[e].v && edge[e].cap){
				dis[edge[e].to] = dis[u] + edge[e].v;
				from[edge[e].to] = e;
				if(!vis[edge[e].to]){
					vis[edge[e].to] = true;
					q[rear++] = edge[e].to;
				}
			}
		}
	}
	return dis[T] != -(1ll<<62);
}
void del(){
	for(int e=from[T];e;e=from[edge[e^1].to]){
		edge[e].cap--,edge[e^1].cap++;
	}
}
struct que{
	char s[10];
	int x,cnt;
}qq[maxn];
int n,Q,x[maxn],y[maxn],mn[maxn],mx[maxn];
ll v[maxn];
const int MX = 100;
ll work(int cnt){
	memset(first,-1,sizeof(first));nume = 0;
	tot = 0;S = ++tot;T = ++tot;
	Rep(i,1,MX) idx[i] = ++tot,idy[i] = ++tot;
	Rep(i,1,n) Addedge(idx[x[i]],idy[y[i]],1,v[i]);
	
		Rep(i,0,cnt+1) mx[i]=MX,mn[i]=1;
		Rep(i,1,Q){
			if (qq[i].s[0]=='L'&&cnt>=qq[i].cnt+1){
				mn[qq[i].cnt+1]=max(mn[qq[i].cnt+1],qq[i].x+1);
//				printf("Mn(%d) [%d]\n",qq[i].cnt+1,qq[i].x+1);
			}
			if (qq[i].s[0]=='R'&&cnt>=qq[i].cnt+1)
				mx[cnt-qq[i].cnt]=min(mx[cnt-qq[i].cnt],qq[i].x-1);
		}
		Rep(i,1,cnt) mn[i]=max(mn[i],mn[i-1]);
		Dep(i,cnt,1) mx[i]=min(mx[i],mx[i+1]);
//		Rep(i,1,cnt){
//			printf("{%d %d}\n",mn[i],mx[i]);
//		}
		Rep(i,1,cnt){
			int tmp=++tot;
			if (mn[i]>mx[i]) return 0;
			Addedge(S,tmp,1,0);
			Rep(j,mn[i],mx[i])
				Addedge(tmp,idx[j],1,0);
		}

		Rep(i,0,cnt+1) mx[i]=MX,mn[i]=1;
		Rep(i,1,Q){
			if (qq[i].s[0]=='D'&&cnt>=qq[i].cnt+1)
				mn[qq[i].cnt+1]=max(mn[qq[i].cnt+1],qq[i].x+1);
			if (qq[i].s[0]=='U'&&cnt>=qq[i].cnt+1)
				mx[cnt-qq[i].cnt]=min(mx[cnt-qq[i].cnt],qq[i].x-1);
		}
		Rep(i,1,cnt) mn[i]=max(mn[i],mn[i-1]);
		Dep(i,cnt,1) mx[i]=min(mx[i],mx[i+1]);
		Rep(i,1,cnt){
			int tmp=++tot;
			if (mn[i]>mx[i]) return 0;
			Addedge(tmp,T,1,0);
			Rep(j,mn[i],mx[i])
				Addedge(idy[j],tmp,1,0);
		}
	ll ans = 0;
	Rep(i,1,cnt){
		if(!spfa()) return 0;
		ans += dis[T];
		del();
	}
//	printf("%lld %lld\n",cnt,ans);
	return ans;
}
signed main(){
	n = read();
	Rep(i,1,n){
		x[i] = read(),y[i] = read(),v[i] = read();
	}
	Q = read();
	Rep(i,1,Q) scanf("%s",qq[i].s);qq[i] . x = read(),qq[i] . cnt = read();
	ll ans = 0;
	Rep(i,1,n) ans=max(ans,work(i));
	writeln(ans);
	return 0;
}

Compiler output:
a.cc: In function 'bool spfa()':
a.cc:42:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   42 |         Rep(i,1,tot) dis[i] = -(1ll<<62),vis[i] = 0,from[i] = 0;
      |             ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc: In function 'll work(ll)':
a.cc:75:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   75 |         Rep(i,1,MX) idx[i] = ++tot,idy[i] = ++tot;
      |             ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc:76:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   76 |         Rep(i,1,n) Addedge(idx[x[i]],idy[y[i]],1,v[i]);
      |             ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc:78:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   78 |                 Rep(i,0,cnt+1) mx[i]=MX,mn[i]=1;
      |                     ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc:79:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   79 |                 Rep(i,1,Q){
      |                     ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc:87:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   87 |                 Rep(i,1,cnt) mn[i]=max(mn[i],mn[i-1]);
      |                     ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc:88:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   88 |                 Dep(i,cnt,1) mx[i]=min(mx[i],mx[i+1]);
      |                     ^
a.cc:7:37: note: in definition of macro 'Dep'
    7 | #define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
      |                                     ^
a.cc:92:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   92 |                 Rep(i,1,cnt){
      |                     ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc:96:29: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   96 |                         Rep(j,mn[i],mx[i])
      |                             ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc:100:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  100 |                 Rep(i,0,cnt+1) mx[i]=MX,mn[i]=1;
      |                     ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc:101:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  101 |                 Rep(i,1,Q){
      |                     ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc:107:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  107 |                 Rep(i,1,cnt) mn[i]=max(mn[i],mn[i-1]);
      |                     ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc:108:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  108 |                 Dep(i,cnt,1) mx[i]=min(mx[i],mx[i+1]);
      |                     ^
a.cc:7:37: note: in definition of macro 'Dep'
    7 | #define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
      |                                     ^
a.cc:109:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  109 |                 Rep(i,1,cnt){
      |                     ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc:113:29: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  113 |                         Rep(j,mn[i],mx[i])
      |                             ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc:117:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  117 |         Rep(i,1,cnt){
      |             ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc: In function 'int main()':
a.cc:127:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  127 |         Rep(i,1,n){
      |             ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc:131:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  131 |         Rep(i,1,Q) scanf("%s",qq[i].s);qq[i] . x = read(),qq[i] . cnt = read();
      |             ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^
a.cc:131:43: error: 'i' was not declared in this scope
  131 |         Rep(i,1,Q) scanf("%s",qq[i].s);qq[i] . x = read(),qq[i] . cnt = read();
      |                                           ^
a.cc:133:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  133 |         Rep(i,1,n) ans=max(ans,work(i));
      |             ^
a.cc:6:37: note: in definition of macro 'Rep'
    6 | #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
      |                                     ^