#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <list>
#include <fstream>
#define ull unsigned long long
#define ll long long
#define ld long double
#define pi 3.1415926536
#define lp(i,n,a) for(ll i=a;i<=n;i++)
#define pl(i,n) for(ll i=n-1;i>=0;i--)
#define w while
#define re return
using namespace std;
int n,num,mint,arr[101][2];
string s,k;
char a,b;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
    cin >> s >> k >> n;
    while(n--){
        cin >> mint >> a >> num >> b;
        if(arr[num][a=='a']<2){
            if(b=='r'){
                if(a=='a')
                cout << k;
                else
                cout << s;
                cout << " " << num << " " << mint << endl;
            }
            else{
                arr[num][a=='a']++;
                if(arr[num][a=='a']==2){
                    if(a=='a')
                    cout << k;
                    else
                    cout << s;
                    cout << " " << num << " " << mint<<endl;
                }
            }
        }
    }
	re 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <list>
#include <fstream>
#define ull unsigned long long
#define ll long long
#define ld long double
#define pi 3.1415926536
#define lp(i,n,a) for(ll i=a;i<=n;i++)
#define pl(i,n) for(ll i=n-1;i>=0;i--)
#define w while
#define re return
using namespace std;
int n,num,mint,arr[101][2];
string s,k;
char a,b;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
    cin >> s >> k >> n;
    while(n--){
        cin >> mint >> a >> num >> b;
        if(b=='r'){
            if(a=='a')
            cout << k;
            else
            cout << s;
            cout << " " << num << " " << mint << endl;
        }
        else{
            arr[num][a=='a']++;
            if(arr[num][a=='a']==2){
                if(a=='a')
                cout << k;
                else
                cout << s;
                cout << " " << num << " " << mint<<endl;
            }
        }
    }
	re 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <list>
#include <fstream>
#define ull unsigned long long
#define ll long long
#define ld long double
#define pi 3.1415926536
#define lp(i,n,a) for(ll i=a;i<=n;i++)
#define pl(i,n) for(ll i=n-1;i>=0;i--)
#define w while
#define re return
using namespace std;
int n,num,mint,arr[101][2];
string s,k;
char a,b;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
    cin >> s >> k >> n;
    while(n--){
        cin >> mint >> a >> num >> b;
        if(arr[num][a=='a']<2){
            if(b=='r'){
                arr[num][a=='a']=2;
                if(a=='a')
                cout << k;
                else
                cout << s;
                cout << " " << num << " " << mint << endl;
            }
            else{
                arr[num][a=='a']++;
                if(arr[num][a=='a']==2){
                    if(a=='a')
                    cout << k;
                    else
                    cout << s;
                    cout << " " << num << " " << mint<<endl;
                }
            }
        }
    }
	re 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <list>
#include <fstream>
#define ull unsigned long long
#define ll long long
#define ld long double
#define pi 3.1415926536
#define lp(i,n,a) for(ll i=a;i<=n;i++)
#define pl(i,n) for(ll i=n-1;i>=0;i--)
#define w while
#define re return
using namespace std;
int n,num,mint,arr[101];
string s,k;
char a,b;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
    cin >> s >> k >> n;
    while(n--){
        cin >> mint >> a >> num >> b;
        if(b=='r'){
            if(a=='a')
            cout << k;
            else
            cout << s;
            cout << " " << num << " " << mint << endl;
        }
        else{
            arr[num]++;
            if(arr[num]==2){
                if(a=='a')
                cout << k;
                else
                cout << s;
                cout << " " << num << " " << mint<<endl;
            }
        }
    }
	re 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <list>
#include <fstream>
#define ull unsigned long long
#define ll long long
#define ld long double
#define pi 3.1415926536
#define lp(i,n,a) for(ll i=a;i<=n;i++)
#define pl(i,n) for(ll i=n-1;i>=0;i--)
#define w while
#define re return
using namespace std;
int n,num,mint,arr[101];
string s,k;
char a,b;
vector<pair<int,pair<int,string> > > v;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
    cin >> s >> k >> n;
    while(n--){
        cin >> mint >> a >> num >> b;
        if(b=='r'){
            if(a=='a')
                v.push_back(make_pair(mint,make_pair(num,k)));
            else
                v.push_back(make_pair(mint,make_pair(num,s)));
        }
        else{
            arr[num]++;
            if(arr[num]==2){
                if(a=='a')
                v.push_back(make_pair(mint,make_pair(num,k)));
            else
                v.push_back(make_pair(mint,make_pair(num,s)));
            }
        }
    }
    sort(v.begin(),v.end());
    n=v.size();
    for(int i=0;i<n;i++){
        cout << v[i].second.second << " " << v[i].second.first << " " << v[i].first << endl;
    }
	re 0;
}


/*
 * URL 		: https://codeforces.com/problemset/problem/466/A
 * DATE		: 18th Jan, 2019
 */

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

#define rep(i,a,b)  for(int i=a; i<b; i++)
#define req(i,a,b)  for(int i=b-1; i>=a; i--)
#define trv(it,s)   for(auto it=s.begin(); it!=s.end(); it++)
#define trs(it,s)   for(auto &it : s)

#define endl        '\n'
#define pb          push_back
#define F           first
#define S           second
#define ll          long long
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<vi>
#define mi          map<int,int>
#define umap        unordered_map
#define uset        unordered_set
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define fill(a,x)   memset(a,x,sizeof(a))
#define num1(x)     __builtin_popcount(x)

#define db(a)       cout<<"---DEBUG : "<<a<<"\n"
#define wa(x)       cout << (#x) << " -------- " << (x) << endl
#define line1	    printf("---------------------------------------\n")
#define line2	    printf("_______________________________________\n")

#define mod(x, m)   ((((x)%(m)) + (m)) % (m))

#define MOD         1000000007
#define PI          2 * acos(0.0)

//#define int 		long long
//#define printf      //

void pmap(auto l){
	trv(itt,l) printf("%d %d\n", itt->fi, itt->se);
	line1;
}

void pvi(vector<int> pvec, string name="") {
	if(name != "") cout<<"Output of "<<name<<" : ";
	for(int i=0;i<pvec.size();i++) cout<<pvec[i]<<" ";
	cout<<endl;
}

int gcd(int n,int m){
	return m==0?n:gcd(m,n%m);
}

ll mpow(ll base, ll power){
	if(power==0) return 1;
	if(power==1) return base;
	ll exp = mpow(base,power/2);
	exp = exp*exp;
	if(power%2==1) exp = exp * base;
	return exp;
}

//___________________________________________________________________________________________________________

void solve() {

	string h,a;
	cin>>h>>a;

	int n;
	cin>>n;

	vi hc(100,0);
	vi ac(100,0);

	rep(i,0,n){
		int t,p;
		char s,c;
		cin>>t>>s>>p>>c;

		if(hc[p] == -1) continue;

		if(s=='h'){
			if(c=='r'){
				cout << h << " " << p << " " << t << endl;
				hc[p] = -1;
			}
			else{
				if (hc[p] == 1){
					cout << h << " " << p << " " << t << endl;
					hc[p] = -1;
				}
				else hc[p]++;
			}
		}

		if(s=='a'){
			if(c=='r'){
				cout << a << " " << p << " " << t << endl;
				hc[p] = -1;
			}
			else{
				if (ac[p] == 1){
					cout << a << " " << p << " " << t << endl;
					hc[p] = -1;
				}
				else ac[p]++;
			}
		}
	}

}

//___________________________________________________________________________________________________________
int32_t main() {

//	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int notc = 1;
//	cin>>notc;

	while(notc--) {
		solve();
		//printf("========================================================\n");
	}
}


/*
 * URL 		: https://codeforces.com/problemset/problem/466/A
 * DATE		: 18th Jan, 2019
 */

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

#define rep(i,a,b)  for(int i=a; i<b; i++)
#define req(i,a,b)  for(int i=b-1; i>=a; i--)
#define trv(it,s)   for(auto it=s.begin(); it!=s.end(); it++)
#define trs(it,s)   for(auto &it : s)

#define endl        '\n'
#define pb          push_back
#define F           first
#define S           second
#define ll          long long
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<vi>
#define mi          map<int,int>
#define umap        unordered_map
#define uset        unordered_set
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define fill(a,x)   memset(a,x,sizeof(a))
#define num1(x)     __builtin_popcount(x)

#define db(a)       cout<<"---DEBUG : "<<a<<"\n"
#define wa(x)       cout << (#x) << " -------- " << (x) << endl
#define line1	    printf("---------------------------------------\n")
#define line2	    printf("_______________________________________\n")

#define mod(x, m)   ((((x)%(m)) + (m)) % (m))

#define MOD         1000000007
#define PI          2 * acos(0.0)

//#define int 		long long
//#define printf      //

void pmap(auto l){
	trv(itt,l) printf("%d %d\n", itt->fi, itt->se);
	line1;
}

void pvi(vector<int> pvec, string name="") {
	if(name != "") cout<<"Output of "<<name<<" : ";
	for(int i=0;i<pvec.size();i++) cout<<pvec[i]<<" ";
	cout<<endl;
}

int gcd(int n,int m){
	return m==0?n:gcd(m,n%m);
}

ll mpow(ll base, ll power){
	if(power==0) return 1;
	if(power==1) return base;
	ll exp = mpow(base,power/2);
	exp = exp*exp;
	if(power%2==1) exp = exp * base;
	return exp;
}

//___________________________________________________________________________________________________________

void solve() {

	string h,a;
	cin>>h>>a;

	int n;
	cin>>n;

	vi hc(100,0);
	vi ac(100,0);

	rep(i,0,n){
		int t,p;
		char s,c;
		cin>>t>>s>>p>>c;

		if(s=='h'){
			if(hc[p] == -1) continue;

			if(c=='r'){
				cout << h << " " << p << " " << t << endl;
				hc[p] = -1;
			}
			else{
				if (hc[p] == 1){
					cout << h << " " << p << " " << t << endl;
					hc[p] = -1;
				}
				else hc[p]++;
			}
		}

		if(s=='a'){
			if(ac[p] == -1) continue;

			if(c=='r'){
				cout << a << " " << p << " " << t << endl;
				ac[p] = -1;
			}
			else{
				if (ac[p] == 1){
					cout << a << " " << p << " " << t << endl;
					ac[p] = -1;
				}
				else ac[p]++;
			}
		}
	}

}

//___________________________________________________________________________________________________________
int32_t main() {

//	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int notc = 1;
//	cin>>notc;

	while(notc--) {
		solve();
		//printf("========================================================\n");
	}
}


/*
 * URL 		: https://codeforces.com/problemset/problem/466/A
 * DATE		: 18th Jan, 2019
 */

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

#define rep(i,a,b)  for(int i=a; i<b; i++)
#define req(i,a,b)  for(int i=b-1; i>=a; i--)
#define trv(it,s)   for(auto it=s.begin(); it!=s.end(); it++)
#define trs(it,s)   for(auto &it : s)

#define endl        '\n'
#define pb          push_back
#define F           first
#define S           second
#define ll          long long
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<vi>
#define mi          map<int,int>
#define umap        unordered_map
#define uset        unordered_set
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define fill(a,x)   memset(a,x,sizeof(a))
#define num1(x)     __builtin_popcount(x)

#define db(a)       cout<<"---DEBUG : "<<a<<"\n"
#define wa(x)       cout << (#x) << " -------- " << (x) << endl
#define line1	    printf("---------------------------------------\n")
#define line2	    printf("_______________________________________\n")

#define mod(x, m)   ((((x)%(m)) + (m)) % (m))

#define MOD         1000000007
#define PI          2 * acos(0.0)

//#define int 		long long
//#define printf      //

void pmap(auto l){
	trv(itt,l) printf("%d %d\n", itt->fi, itt->se);
	line1;
}

void pvi(vector<int> pvec, string name="") {
	if(name != "") cout<<"Output of "<<name<<" : ";
	for(int i=0;i<pvec.size();i++) cout<<pvec[i]<<" ";
	cout<<endl;
}

int gcd(int n,int m){
	return m==0?n:gcd(m,n%m);
}

ll mpow(ll base, ll power){
	if(power==0) return 1;
	if(power==1) return base;
	ll exp = mpow(base,power/2);
	exp = exp*exp;
	if(power%2==1) exp = exp * base;
	return exp;
}

//___________________________________________________________________________________________________________

void solve() {

	string h,a;
	cin>>h>>a;

	int n;
	cin>>n;

	vi hc(100,0);
	vi ac(100,0);

	rep(i,0,n){
		int t,p;
		char s,c;
		cin>>t>>s>>p>>c;

		if(hc[p] == -1) continue;

		if(s=='h'){
			if(c=='r'){
				cout << h << " " << p << " " << t << endl;
				hc[p] = -1;
			}
			else{
				if (hc[p] == 1){
					cout << h << " " << p << " " << t << endl;
					hc[p] = -1;
				}
				else hc[p]++;
			}
		}

		if(s=='a'){
			if(c=='r'){
				cout << a << " " << p << " " << t << endl;
				ac[p] = -1;
			}
			else{
				if (ac[p] == 1){
					cout << a << " " << p << " " << t << endl;
					ac[p] = -1;
				}
				else ac[p]++;
			}
		}
	}

}

//___________________________________________________________________________________________________________
int32_t main() {

//	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int notc = 1;
//	cin>>notc;

	while(notc--) {
		solve();
		//printf("========================================================\n");
	}
}


/*
 * URL 		: https://codeforces.com/problemset/problem/466/A
 * DATE		: 18th Jan, 2019
 */

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

#define rep(i,a,b)  for(int i=a; i<b; i++)
#define req(i,a,b)  for(int i=b-1; i>=a; i--)
#define trv(it,s)   for(auto it=s.begin(); it!=s.end(); it++)
#define trs(it,s)   for(auto &it : s)

#define endl        '\n'
#define pb          push_back
#define F           first
#define S           second
#define ll          long long
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<vi>
#define mi          map<int,int>
#define umap        unordered_map
#define uset        unordered_set
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define fill(a,x)   memset(a,x,sizeof(a))
#define num1(x)     __builtin_popcount(x)

#define db(a)       cout<<"---DEBUG : "<<a<<"\n"
#define wa(x)       cout << (#x) << " -------- " << (x) << endl
#define line1	    printf("---------------------------------------\n")
#define line2	    printf("_______________________________________\n")

#define mod(x, m)   ((((x)%(m)) + (m)) % (m))

#define MOD         1000000007
#define PI          2 * acos(0.0)

//#define int 		long long
//#define printf      //

void pmap(auto l){
	trv(itt,l) printf("%d %d\n", itt->fi, itt->se);
	line1;
}

void pvi(vector<int> pvec, string name="") {
	if(name != "") cout<<"Output of "<<name<<" : ";
	for(int i=0;i<pvec.size();i++) cout<<pvec[i]<<" ";
	cout<<endl;
}

int gcd(int n,int m){
	return m==0?n:gcd(m,n%m);
}

ll mpow(ll base, ll power){
	if(power==0) return 1;
	if(power==1) return base;
	ll exp = mpow(base,power/2);
	exp = exp*exp;
	if(power%2==1) exp = exp * base;
	return exp;
}

//___________________________________________________________________________________________________________

void solve() {

	string h,a;
	cin>>h>>a;

	int n;
	cin>>n;

	vi hc(100,0);
	vi ac(100,0);

	rep(i,0,n){
		int t,p;
		char s,c;
		cin>>t>>s>>p>>c;

		if(s=='h'){
			if(c=='r') cout << h << " " << p << " " << t << endl;
			else{
				if (hc[p] == 1) cout << h << " " << p << " " << t << endl;
				else hc[p]++;
			}
		}

		if(s=='a'){
			if(c=='r') cout << a << " " << p << " " << t << endl;
			else{
				if (ac[p] == 1) cout << a << " " << p << " " << t << endl;
				else ac[p]++;
			}
		}

	}

}

//___________________________________________________________________________________________________________
int32_t main() {

//	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int notc = 1;
//	cin>>notc;

	while(notc--) {
		solve();
		//printf("========================================================\n");
	}
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1,s2; cin >> s1 >> s2;
  int n; cin >> n;
  vector <pair<char,pair<int,int>>> home(n);
  vector <pair<char,pair<int,int>>> away(n);
  map<int,int> homemp;
  map<int,int> awaymp;
  vector<pair<int,int>> anshome;
  vector <pair<int,int>> ansaway;
  int m;
  char d;
  for (int i = 0; i < n; i++) {
    cin >> m;
    cin >> d;
    if (d == 'h') {
      home[i].second.first = m;
      cin >> home[i].second.second;
      cin >> home[i].first;
    }
    else {
      away[i].second.first = m;
      cin >> away[i].second.second;
      cin >> away[i].first;
    }
  }
  for (int i = 0; i < n; i++) {
    if (home[i].first == 'y') {homemp[home[i].second.second]++;}
    else if (home[i].first == 'r') {homemp[home[i].second.second] += 2;}
    else {
      break;
    }
    if (homemp[home[i].second.second] >= 2) {
      anshome.push_back({home[i].second.second,home[i].second.first});
    }
  }
  for (int i = 0; i < n; i++) {
    if (away[i].first == 'y') {awaymp[away[i].second.second]++;}
    else if (away[i].first == 'r') {awaymp[away[i].second.second = 2];}
    else {
      break;
    }
    if (awaymp[away[i].second.second] >= 2) {
      ansaway.push_back({away[i].second.second, away[i].second.first});
    }
    for (auto it : anshome) {
      cout << s1 << " " << it.first << " " << it.second << endl;
    }
    for (auto it : ansaway) {
      cout << s2 << " " << it.first << " " << it.second << endl;
    }
  }

}


#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1,s2; cin >> s1 >> s2;
  map<int,int> home;
  map<int,int> away;
  int n; cin >> n;
  int t,m;
  char a,b;
  for (int i = 0; i < n; i++) {
    cin >> t >> a >> m >> b;
    if (a == 'h') {
      if (b == 'y') home[m]++;
      else home[m] += 2;
      if (home[m] >= 2) {cout << s1 << " " << m << " " << t << endl;
      home[m] = -1e9;}
    }
    else {
      if (b == 'y') away[m]++;
      else away[m] += 2;
      if (away[m] >= 2) {cout << s2 << " " << m << " " << t << endl;
        away[m] = -1e9;
      }
    }

  }
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1,s2; cin >> s1 >> s2;
  map<int,int> home;
  map<int,int> away;
  int n; cin >> n;
  int t,m;
  char a,b;
  for (int i = 0; i < n; i++) {
    cin >> t >> a >> m >> b;
    if (a == 'h') {
      if (b == 'y') home[m]++;
      else home[m] += 2;
      if (home[m] >= 2) cout << s1 << " " << m << " " << t << endl;
    }
    else {
      if (b == 'y') away[m]++;
      else away[m] += 2;
      if (away[m] >= 2) cout << s2 << " " << m << " " << t << endl;
    }

  }
}


#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(){
	map <long, char> home;
	map <long, char> away;

	string Home, Away;
	cin>>Home>>Away;
	long n;
	cin>>n;

	long time, player; char team, card;

	for (long i = 0; i<n; i++){
		cin>>time>>team>>player>>card;
		//player from away team
		if (team == 'a'){
			if (away.find(player) != away.end() && away[player] != 'r'){
				//player already took a YELLOW card before
				away[player] = 'r';
				cout<<Away<<" "<<player<<" "<<time<<endl;
			}
			else {
				//player didn't take a card before
				//if card is red
				if (card == 'r'){
					Away[player] = 'r';
					cout<<Away<<" "<<player<<" "<<time<<endl;
				}
				//if card is yellow
				else
					away[player] = 'y';
			}
		}
		//player from home team
		else {
			if (home.find(player) != home.end() && home[player] != 'r'){
				//player already took a YELLOW card before
				home[player] = 'r';
				cout<<Home<<" "<<player<<" "<<time<<endl;
			}
			else {
				//player didn't take a card before
				//if card is red
				if (card == 'r'){
					home[player] = 'r';
					cout<<Home<<" "<<player<<" "<<time<<endl;
				}
				//if card is yellow
				else
					home[player] = 'y';
			}
		}
	}

}


#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(){
	map <long long, char> home;
	map <long long, char> away;

	string Home, Away;
	cin>>Home>>Away;
	long long n;
	cin>>n;

	long long time, player; char team, card;

	for (long long i = 0; i<n; i++){
		cin>>time>>team>>player>>card;
		//player from away team
		if (team == 'a'){
			if (away.find(player) != away.end()){
				if (away[player] != 'r'){
					//player already took a YELLOW card before
					away[player] = 'r';
					cout<<Away<<" "<<player<<" "<<time<<endl;
				}
			}
			else {
				//player didn't take a card before
				//if card is red
				if (card == 'r'){
					Away[player] = 'r';
					cout<<Away<<" "<<player<<" "<<time<<endl;
				}
				//if card is yellow
				else
					away[player] = 'y';
			}
		}
		//player from home team
		else {
			if (home.find(player) != home.end()){
				if (home[player] != 'r'){
					//player already took a YELLOW card before
					home[player] = 'r';
					cout<<Home<<" "<<player<<" "<<time<<endl;
				}
			}
			else {
				//player didn't take a card before
				//if card is red
				if (card == 'r'){
					home[player] = 'r';
					cout<<Home<<" "<<player<<" "<<time<<endl;
				}
				//if card is yellow
				else
					home[player] = 'y';
			}
		}
	}
}


#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(){
	map <long, char> home;
	map <long, char> away;

	string Home, Away;
	cin>>Home>>Away;
	long n;
	cin>>n;

	long time, player; char team, card;

	for (long i = 0; i<n; i++){
		cin>>time>>team>>player>>card;
		//player from away team
		if (team == 'a'){
			if (away.find(player) != away.end()){
				if (away[player] != 'r'){
					//player already took a YELLOW card before
					away[player] = 'r';
					cout<<Away<<" "<<player<<" "<<time<<endl;
				}
			}
			else {
				//player didn't take a card before
				//if card is red
				if (card == 'r'){
					Away[player] = 'r';
					cout<<Away<<" "<<player<<" "<<time<<endl;
				}
				//if card is yellow
				else
					away[player] = 'y';
			}
		}
		//player from home team
		else {
			if (home.find(player) != home.end()){
				if (home[player] != 'r'){
					//player already took a YELLOW card before
					home[player] = 'r';
					cout<<Home<<" "<<player<<" "<<time<<endl;
				}
			}
			else {
				//player didn't take a card before
				//if card is red
				if (card == 'r'){
					home[player] = 'r';
					cout<<Home<<" "<<player<<" "<<time<<endl;
				}
				//if card is yellow
				else
					home[player] = 'y';
			}
		}
	}

}


#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(){
	map <long, char> home;
	map <long, char> away;

	string Home, Away;
	cin>>Home>>Away;
	long n;
	cin>>n;

	long time, player; char team, card;

	for (long i = 0; i<n; i++){
		cin>>time>>team>>player>>card;
		//player from away team
		if (team == 'a'){
			if (away.find(player) != away.end()){
				//player already took a card before
				cout<<Away<<" "<<player<<" "<<time<<endl;
			}
			else {
				//player didn't take a card before
				//if card is red
				if (card == 'r')
					cout<<Away<<" "<<player<<" "<<time<<endl;
				//if card is yellow
				else
					away[player] = 'y';
			}
		}
		//player from home team
		else {
			if (home.find(player) != home.end()){
				//player already took a card before
				cout<<Home<<" "<<player<<" "<<time<<endl;
			}
			else {
				//player didn't take a card before
				//if card is red
				if (card == 'r')
					cout<<Home<<" "<<player<<" "<<time<<endl;
				//if card is yellow
				else
					home[player] = 'y';
			}
		}
	}

}


#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(){
	map <long long, char> home;
	map <long long, char> away;

	string Home, Away;
	cin>>Home>>Away;
	long long n;
	cin>>n;

	long long time, player; char team, card;

	for (long long i = 0; i<n; i++){
		cin>>time>>team>>player>>card;
		//player from away team
		if (team == 'a'){
			if (away[player] == 'r') continue;
			if (away[player] == 'y'){
				away[player] = 'r';
				cout<<Away<<" "<<player<<" "<<time<<endl;
			}
			else {
				//didn't take a card before
				if (card == 'y')
					away[player] = 'y';
				else {
					away[player] = 'r';
					cout<<Away<<" "<<player<<" "<<time<<endl;
				}
			}

			//if (away.find(player) != away.end()){
			//	if (away[player] != 'r'){
			//		//player already took a YELLOW card before
			//		away[player] = 'r';
			//		cout<<Away<<" "<<player<<" "<<time<<endl;
			//	}
			//}
			//else {
			//	//player didn't take a card before
			//	//if card is red
			//	if (card == 'r'){
			//		Away[player] = 'r';
			//		cout<<Away<<" "<<player<<" "<<time<<endl;
			//	}
			//	//if card is yellow
			//	else
			//		away[player] = 'y';
			//}
		}
		//player from home team
		else {
			if (home[player] == 'r') continue;
			if (home[player] == 'y'){
				home[player] = 'r';
				cout<<Home<<" "<<player<<" "<<time<<endl;
			}
			else {
				//didn't take a card before
				if (card == 'y')
					home[player] = 'y';
				else {
					home[player] = 'r';
					cout<<Home<<" "<<player<<" "<<time<<endl;
				}
			}

			//if (home.find(player) != home.end()){
			//	if (home[player] != 'r'){
			//		//player already took a YELLOW card before
			//		home[player] = 'r';
			//		cout<<Home<<" "<<player<<" "<<time<<endl;
			//	}
			//}
			//else {
			//	//player didn't take a card before
			//	//if card is red
			//	if (card == 'r'){
			//		home[player] = 'r';
			//		cout<<Home<<" "<<player<<" "<<time<<endl;
			//	}
			//	//if card is yellow
			//	else
			//		home[player] = 'y';
			//}
		}
	}
}


#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(){
	map <long, char> home;
	map <long, char> away;

	string Home, Away;
	cin>>Home>>Away;
	long n;
	cin>>n;

	long time, player; char team, card;

	for (long i = 0; i<n; i++){
		cin>>time>>team>>player>>card;
		//player from away team
		if (team == 'a'){
			if (away.find(player) != away.end() && away[player] != 'r'){
				//player already took a YELLOW card before
				away[player] = 'r';
				cout<<Away<<" "<<player<<" "<<time<<endl;
			}
			else {
				//player didn't take a card before
				//if card is red
				if (card == 'r'){
					Away[player] = 'r';
					cout<<Away<<" "<<player<<" "<<time<<endl;
				}
				//if card is yellow
				else
					away[player] = 'y';
			}
		}
		//player from home team
		else {
			if (home.find(player) != home.end() && home[player] != 'r'){
				//player already took a YELLOW card before
				home[player= = 'r';
				cout<<Home<<" "<<player<<" "<<time<<endl;
			}
			else {
				//player didn't take a card before
				//if card is red
				if (card == 'r'){
					home[player] = 'r';
					cout<<Home<<" "<<player<<" "<<time<<endl;
				}
				//if card is yellow
				else
					home[player] = 'y';
			}
		}
	}

}


#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(){
	map <long, char> home;
	map <long, char> away;

	string Home, Away;
	cin>>Home>>Away;
	long n;
	cin>>n;

	long time, player; char team, card;

	for (long i = 0; i<n; i++){
		cin>>time>>team>>player>>card;
		//player from away team
		if (team == 'a'){
			if (away.find(player) != away.end() && away[player] != 'r'){
				//player already took a YELLOW card before
				away[player] = 'r';
				cout<<Away<<" "<<player<<" "<<time<<endl;
			}
			else {
				//player didn't take a card before
				//if card is red
				if (card == 'r'){
					Away[player] = 'r';
					cout<<Away<<" "<<player<<" "<<time<<endl;
				}
				//if card is yellow
				else
					away[player] = 'y';
			}
		}
		//player from home team
		else {
			if (home.find(player) != home.end() && home[player] != 'r'){
				//player already took a YELLOW card before
				home[player] = 'r';
				cout<<Home<<" "<<player<<" "<<time<<endl;
			}
			else {
				//player didn't take a card before
				//if card is red
				if (card == 'r'){
					home[player] = 'r';
					cout<<Home<<" "<<player<<" "<<time<<endl;
				}
				//if card is yellow
				else
					home[player] = 'y';
			}
		}
	}
//lol
}


#include <iostream>

using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    int n,arr[100]={0},brr[100]={0};
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        int x,y;
        char a,b;
        cin>>x>>a>>y>>b;
        if (b=='y' && a=='h')
            arr[y]++;
        else if (b=='r' && a=='h')
            arr[y]+=2;
        else if (b=='y' && a=='a')
            brr[y]++;
        else if (b=='r' && a=='a')
            brr[y]+=2;
        if (arr[y]==2)
            cout<<s<<" "<<y<<" "<<x<<endl;
        else if (brr[y]==2)
            cout<<t<<" "<<y<<" "<<x<<endl;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <ctime>
#include <bitset>

#define ll long long
#define pb push_back
#define f first
#define s second

const int sz = 100005;
//const int p = 53;
//const int Q = 1e9 + 7;
//const ll mod = 998244353;
//const int SZ = 'z' - 'a' + 1, con = 1e6;

using namespace std;

int main() {
    string th, ta;
    cin >> th >> ta;

    map <int, int> t1 = {};
    map <int, int> t2 = {};

    int n;
    cin >> n;

    int t, m;
    char team, card;

    while (n--) {

        cin >> t >> team >> m >> card;

        if (team == 'h') {
            if (card == 'y') {
                if (t1[m] == 0)
                    t1[m] = t;
                else
                    cout << th << " " << m << " " << t << endl;
            }

            else if (card == 'r' && t1[m] != -1) {
                cout << th << " " << m << " " << t << endl;
                t1[m] = -1;
            }
        }

        else if (team == 'a') {
            if (card == 'y') {
                if (t2[m] == 0)
                    t2[m] = t;
                 else
                    cout << ta << " " << m << " " << t << endl;
            }

            else if (card == 'r' && t2[m] == 0) {
                cout << ta << " " << m << " " << t << endl;
                t2[m] = -1;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <ctime>
#include <bitset>

#define ll long long
#define pb push_back
#define f first
#define s second

const int sz = 100005;
//const int p = 53;
//const int Q = 1e9 + 7;
//const ll mod = 998244353;
//const int SZ = 'z' - 'a' + 1, con = 1e6;

using namespace std;

int main() {
    string th, ta;
    cin >> th >> ta;

    map <int, int> t1 = {};
    map <int, int> t2 = {};

    int n;
    cin >> n;

    int t, m;
    char team, card;

    while (n--) {

        cin >> t >> team >> m >> card;

        if (team == 'h') {
            if (card == 'y' && t1[m] != -1) {
                if (t1[m] == 0)
                    t1[m] = t;
                else if (t1[m] != -1) {
                    cout << th << " " << m << " " << t << endl;
                    t1[m] = -1;
                }
            }

            else if (card == 'r' && t1[m] != -1) {
                cout << th << " " << m << " " << t << endl;
                t1[m] = -1;
            }
        }

        else if (team == 'a') {
            if (card == 'y' && t2[m] != -1) {
                if (t2[m] == 0)
                    t2[m] = t;
                else if(t2[m] != -1) {
                    cout << ta << " " << m << " " << t << endl;
                    t2[m] = -1;
                }
            }

            else if (card == 'r' && t2[m] != -1) {
                cout << ta << " " << m << " " << t << endl;
                t2[m] = -1;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <ctime>
#include <bitset>

#define ll long long
#define pb push_back
#define f first
#define s second

const int sz = 100005;
//const int p = 53;
//const int Q = 1e9 + 7;
//const ll mod = 998244353;
//const int SZ = 'z' - 'a' + 1, con = 1e6;

using namespace std;

int main() {
    string th, ta;
    cin >> th >> ta;

    map <int, int> t1 = {};
    map <int, int> t2 = {};

    int n;
    cin >> n;

    int t, m;
    char team, card;

    while (n--) {

        cin >> t >> team >> m >> card;

        if (team == 'h') {
            if (card == 'y') {
                if (t1[m] == 0)
                    t1[m] = t;
                else
                    cout << th << " " << m << " " << t << endl;
            }

            else if (card == 'r' && t1[m] == 0) {
                cout << th << " " << m << " " << t << endl;
                t1[m] = t;
            }
        }

        else if (team == 'a') {
            if (card == 'y') {
                if (t2[m] == 0)
                    t2[m] = t;
                 else
                    cout << ta << " " << m << " " << t << endl;
            }

            else if (card == 'r' && t2[m] == 0) {
                cout << ta << " " << m << " " << t << endl;
                t2[m] = t;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <ctime>
#include <bitset>

#define ll long long
#define pb push_back
#define f first
#define s second

const int sz = 100005;
//const int p = 53;
//const int Q = 1e9 + 7;
//const ll mod = 998244353;
//const int SZ = 'z' - 'a' + 1, con = 1e6;

using namespace std;

int main() {
    string th, ta;
    cin >> th >> ta;

    map <int, int> t1 = {};
    map <int, int> t2 = {};

    int n;
    cin >> n;

    int t, m;
    char team, card;

    while (n--) {

        cin >> t >> team >> m >> card;

        if (team == 'h') {
            if (card == 'y' && t1[m] != -1) {
                if (t1[m] == 0)
                    t1[m] = t;
                else
                    cout << th << " " << m << " " << t << endl;
            }

            else if (card == 'r' && t1[m] != -1) {
                cout << th << " " << m << " " << t << endl;
                t1[m] = -1;
            }
        }

        else if (team == 'a') {
            if (card == 'y' && t2[m] != -1) {
                if (t2[m] == 0)
                    t2[m] = t;
                else
                    cout << ta << " " << m << " " << t << endl;
            }

            else if (card == 'r' && t2[m] != -1) {
                cout << ta << " " << m << " " << t << endl;
                t2[m] = -1;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <ctime>
#include <bitset>

#define ll long long
#define pb push_back
#define f first
#define s second

const int sz = 100005;
//const int p = 53;
//const int Q = 1e9 + 7;
//const ll mod = 998244353;
//const int SZ = 'z' - 'a' + 1, con = 1e6;

using namespace std;

int main() {
    string th, ta;
    cin >> th >> ta;

    map <int, int> t1 = {};
    map <int, int> t2 = {};

    int n;
    cin >> n;

    int t, m;
    char team, card;

    while (n--) {

        cin >> t >> team >> m >> card;

        if (team == 'h') {
            if (card == 'y') {
                if (t1[m] == 0)
                    t1[m] = t;
                else
                    cout << th << " " << m << " " << t << endl;
            }

            else if ( card == 'r')
                cout << th << " " << m << " " << t << endl;
        }

        else if (team == 'a') {
            if (card == 'y') {
                if (t2[m] == 0)
                    t2[m] = t;
                 else
                    cout << ta << " " << m << " " << t << endl;
            }

            else if ( card == 'r')
                cout << ta << " " << m << " " << t << endl;

        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long int
#define mp make_pair
#define ss second
#define ff first
const ll mod=1000000009;

int main()
{
   fast;

   string s,s1;
   cin>>s>>s1;
   int n;
   cin>>n;
   int a[2][101][2]={0};
   bool v1[101]={0},v2[101]={0};
   while(n--)
   {
        int t,num;
        char team,card;
        cin>>t>>team>>num>>card;

        if(team=='a')
        {
            if(card=='y')
            a[0][num][0]++;
            else
            a[0][num][1]++;

            if(v1[num]==0 && (a[0][num][0]==2 || a[0][num][1]==1))
           { cout<<s1<<" "<<num<<" "<<t<<endl;v1[num]=1;}
        }
        else
        {
             if(card=='y')
            a[1][num][0]++;
            else
            a[1][num][1]++;

            if(v2[num]==0 &&(a[1][num][0]==2 || a[1][num][1]==1))
            {cout<<s<<" "<<num<<" "<<t<<endl;v2[num]=1;}
        }
   }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long int
#define mp make_pair
#define ss second
#define ff first
const ll mod=1000000009;

int main()
{
   fast;

   string s,s1;
   cin>>s>>s1;
   int n;
   cin>>n;
   int a[2][101][2]={0};
   while(n--)
   {
        int t,num;
        char team,card;
        cin>>t>>team>>num>>card;

        if(team=='a')
        {
            if(card=='y')
            a[0][num][0]++;
            else
            a[0][num][1]++;

            if(a[0][num][0]==2 || a[0][num][1]==1)
            cout<<s1<<" "<<num<<" "<<t<<endl;
        }
        else
        {
             if(card=='y')
            a[1][num][0]++;
            else
            a[1][num][1]++;

            if(a[1][num][0]==2 || a[1][num][1]==1)
            cout<<s<<" "<<num<<" "<<t<<endl;
        }
   }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long int
#define mp make_pair
#define ss second
#define ff first
const ll mod=1000000009;

int main()
{
   fast;

   string s,s1;
   cin>>s>>s1;
   int n;
   cin>>n;
   int a[2][101][2]={0};
   while(n--)
   {
        int t,num;
        char team,card;
        cin>>t>>team>>num>>card;

        if(team=='a')
        {
            if(card=='y')
            a[0][num][0]++;
            else
            a[0][num][1]++;

            if(a[0][num][0]==2 || a[0][num][1]>=1)
            cout<<s1<<" "<<num<<" "<<t<<endl;
        }
        else
        {
             if(card=='y')
            a[1][num][0]++;
            else
            a[1][num][1]++;

            if(a[1][num][0]==2 || a[1][num][1]>=1)
            cout<<s<<" "<<num<<" "<<t<<endl;
        }
   }
 return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
	string s, t;
	cin >> s >> t;
	int n;
	cin >> n;
	map<int, int> home, away;
	map<int, bool> kicked_home, kicked_away;
	for (int i = 0; i < n; i++) {
		int minute;
		char type;
		int number;
		char card;
		cin >> minute >> type >> number >> card;
		if (card == 'r') {
			if (type == 'h') {
				if (kicked_home.count(number)) continue;
				cout << s << ' ';
				cout << number << ' ' << minute << '\n';
				kicked_home[number] = true;
			}
			else {
				if (kicked_away.count(number)) continue;
				cout << t << ' ';
				cout << number << ' ' << minute << '\n';
				kicked_away[number] = true;
			}

		} else {
			if (type == 'h') {
				if (kicked_home.count(number)) continue;
				home[number]++;
				if (home[number] == 2) {
					cout << s << ' ' << number << ' ' << minute << '\n';
					kicked_home[number] = true;
				}
			} else {
				if (kicked_away.count(number)) continue;
				away[number]++;
				if (away[number] == 2) {
					cout << t << ' ' << number << ' ' << minute << '\n';
					kicked_away[number] = true;

				}

			}
		}

	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
	string s, t;
	cin >> s >> t;
	int n;
	cin >> n;
	map<int, int> home, away;
	map<int, bool> kicked_home, kicked_away;
	for (int i = 0; i < n; i++) {
		int minute;
		char type;
		int number;
		char card;
		cin >> minute >> type >> number >> card;
		if (card == 'r') {
			if (type == 'h') {
				if (kicked_home.count(number)) continue;
				cout << s << ' ';
				cout << number << ' ' << minute << '\n';
				kicked_home[number] = true;
			}
			else {
				if (kicked_away.count(number)) continue;
				cout << t << ' ';
				cout << number << ' ' << minute << '\n';
				kicked_away[number] = true;
			}

		} else {
			if (type == 'h') {
				if (kicked_home.count(number)) continue;
				home[number]++;
				if (home[number] == 2) {
					cout << s << ' ' << number << ' ' << minute << '\n';
				}
			} else {
				if (kicked_away.count(number)) continue;
				away[number]++;
				if (away[number] == 2) {
					cout << t << ' ' << number << ' ' << minute << '\n';
				}

			}
		}

	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
	string s, t;
	cin >> s >> t;
	int n;
	cin >> n;
	map<int, int> home, away;
	for (int i = 0; i < n; i++) {
		int minute;
		char type;
		int number;
		char card;
		cin >> minute >> type >> number >> card;
		if (card == 'r') {
			if (type == 'h')
				cout << s << ' ';
			else
				cout << t << ' ';
			cout << number << ' ' << minute << '\n';
		} else {
			if (type == 'h') {
				home[number]++;
				if (home[number] == 2) {
					cout << s << ' ' << number << ' ' << minute << '\n';
				}
			} else {
				away[number]++;
				if (away[number] == 2) {
					cout << t << ' ' << number << ' ' << minute << '\n';
				}

			}
		}

	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
	string s, t;
	cin >> s >> t;
	int n;
	cin >> n;
	map<int, int> home, away;
	map<int, bool> kicked_home, kicked_away;
	for (int i = 0; i < n; i++) {
		int minute;
		char type;
		int number;
		char card;
		cin >> minute >> type >> number >> card;
		if (card == 'r') {
			if (type == 'h') {
				if (kicked_home.count(number)) continue;
				cout << s << ' ';
				cout << number << ' ' << minute << '\n';
				kicked_home[number] = true;
			}
			else {
				if (kicked_away.count(number)) continue;
				cout << t << ' ';
				cout << number << ' ' << minute << '\n';
				kicked_away[number] = true;
			}

		} else {
			if (type == 'h') {
				home[number]++;
				if (home[number] == 2) {
					cout << s << ' ' << number << ' ' << minute << '\n';
				}
			} else {
				away[number]++;
				if (away[number] == 2) {
					cout << t << ' ' << number << ' ' << minute << '\n';
				}

			}
		}

	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
	string s, t;
	cin >> s >> t;
	int n;
	cin >> n;
	map<int, int> home, away;
	map<int, bool> kicked_home, kicked_away;
	for (int i = 0; i < n; i++) {
		int minute;
		char type;
		int number;
		char card;
		cin >> minute >> type >> number >> card;
		if (card == 'r') {
			if (type == 'h') {
				if (kicked_home.count(number)) continue;
				cout << s << ' ';
				cout << number << ' ' << minute << '\n';
				kicked_home[number] = true;
			}
			else {
				if (kicked_away.count(number)) continue;
				cout << t << ' ';
				cout << number << ' ' << minute << '\n';
				kicked_away[number] = true;
			}

		} else {
			if (type == 'h') {
				if (kicked_home.count(number)) continue;
				home[number]++;
				if (home[number] == 2) {
					cout << s << ' ' << number << ' ' << minute << '\n';
				}
				kicked_home[number] = true;
			} else {
				if (kicked_away.count(number)) continue;
				away[number]++;
				if (away[number] == 2) {
					cout << t << ' ' << number << ' ' << minute << '\n';
				}
				kicked_away[number] = true;

			}
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
set<int>h1,a1;
int main()
{
	string h,a;
	char n,p;
	int n1,m,o;
	cin >> h;
	cin >> a;
	cin >> n1;
	while(n1--)
	{
		cin >> m >> n >> o >> p;
		if(p=='r')
		{
			if(n=='a')
			{
			cout << a <<" "<< o <<" "<< m<<"\n";
		    }
			else
			{
			cout << h <<" "<< o <<" "<< m<<"\n";
		    }
		}
		else
		{
			if(n=='a')
			{
				int si1=a1.size();
				a1.insert(o);
				int si2=a1.size();
				if(si1==si2)

				cout << a <<" "<< o <<" "<< m<<"\n";

			}

			else
			{
				int si1=h1.size();
				h1.insert(o);
				int si2=h1.size();
				if(si1==si2)
				cout << h <<" "<< o <<" "<< m<<"\n";
			}
		}
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<utility>
#include<cstring>
#include<cmath>
#define LL long long int
#define mod 1000000007
#define vi vector<int>
#define vvi vector < vi >
#define pii pair<int,int>
#define all(c) c.begin(),c.end()
#define sf(x) scanf("%d",&x);
#define sf2(x,y) scanf("%d%d",&x,&y);
#define mem(a,val) memset(a,val,sizeof(a))
//#define for<(i,a,b) for(i=a;i<b;i++)
//#define for=(i,a,b) for(i=a;i<=b;i++)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define f first
#define s second
using namespace std;
int main()
{   int t,i,j,n,num,min,A[101],B[101];
    pair<pair<int,char>,pair<int,char> > p[101];
    char qw,card;
    string home,away;
    cin>>home>>away;
    cin>>n;
    mem(A,0);mem(B,0);
    for(i=0;i<n;i++)
    {   cin>>min>>qw>>num>>card;
        p[i]=mp(mp(min,qw),mp(num,card));
    }
    sort(p,p+n);
    for(i=0;i<n;i++)
    {   min=p[i].f.f;
        qw=p[i].f.s;
        num=p[i].s.f;
        card=p[i].s.s;
        if(qw=='h')
        {   if(card=='y'&&A[num]!=-1)
                A[num]++;
            if((A[num]==2||card=='r')&&A[num]!=-1)
            {   cout<<home<<" "<<num<<" "<<min<<endl;
                //A[num]=0;
                A[num]=-1;
            }
        }
        else if(qw=='a')
            {   if(card=='y'&&B[num]!=-1)
                    B[num]++;
                if((B[num]==2||card=='r')&&B[num]!=-1)
                {   cout<<away<<" "<<num<<" "<<min<<endl;
                    //B[num]=0;
                    B[num]=-1;
                }
            }
    }
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    if(n%2==0)
    {
        cout<<"white"<<endl;
        cout<<1<<" "<<2;
    }
    else
        cout<<"black";
    return 0;
}


#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int
using namespace std ;

int main()
{
    string s1, s2;
    cin>>s1;
    cin>>s2;
    int n, u, v, card[100][2]={};
    char ch,car;
    vector<int> a1, a2, a3;
    cin>>n;
    while(n--)
    {
        cin>>u>>ch>>v>>car;
        if(car=='r')
        {
            if(ch=='h'&&card[v][0]<2)
            {
                a1.push_back(0);
                a2.push_back(v);
                a3.push_back(u);
                card[v][0]=2;
            }
            else if (ch=='a'&&card[v][1]<2)
            {
                a1.push_back(1);
                a2.push_back(v);
                a3.push_back(u);
                card[v][0]=2;
            }
        }
        else if(ch=='h')
        {
            if(card[v][0]==1)
            {
                a1.push_back(0);
                a2.push_back(v);
                a3.push_back(u);
                card[v][0]=2;
            }
            else
            {
                card[v][0]++;
            }
        }
        else
        {
            if(card[v][1]==1)
            {
                a1.push_back(1);
                a2.push_back(v);
                a3.push_back(u);
                card[v][0]=2;
            }
            else
            {
                card[v][1]++;
            }
        }
    }
    n=a1.size();
    for(int i=0; i<n; i++)
    {
        if(a1[i]==0)
            cout<<s1<<" "<<a2[i]<<" "<<a3[i]<<endl;
        else
            cout<<s2<<" "<<a2[i]<<" "<<a3[i]<<endl;
    }
	return 0;
}


#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int
using namespace std ;

int main()
{
    string s1, s2;
    cin>>s1;
    cin>>s2;
    int n, u, v, card[100][2]={};
    char ch,car;
    vector<int> a1, a2, a3;
    cin>>n;
    while(n--)
    {
        cin>>u>>ch>>v>>car;
        if(car=='r')
        {
            if(ch=='h'&&card[v][0]<2)
            {
                a1.push_back(0);
                a2.push_back(v);
                a3.push_back(u);
                card[v][0]=2;
            }
            else if (ch=='a'&&card[v][1]<2)
            {
                a1.push_back(1);
                a2.push_back(v);
                a3.push_back(u);
                card[v][1]=2;
            }
        }
        else if(ch=='h')
        {
            if(card[v][0]==1)
            {
                a1.push_back(0);
                a2.push_back(v);
                a3.push_back(u);
                card[v][0]=2;
            }
            else
            {
                card[v][0]++;
            }
        }
        else
        {
            if(card[v][1]==1)
            {
                a1.push_back(1);
                a2.push_back(v);
                a3.push_back(u);
                card[v][1]=2;
            }
            else
            {
                card[v][1]++;
            }
        }
    }
    n=a1.size();
    for(int i=0; i<n; i++)
    {
        if(a1[i]==0)
            cout<<s1<<" "<<a2[i]<<" "<<a3[i]<<endl;
        else
            cout<<s2<<" "<<a2[i]<<" "<<a3[i]<<endl;
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ppp pair<char, pair<int,int> >
int main(){
	string ht,at;
	cin>>ht>>at;
	vector<ppp>v;
	int i,j,n,t,no;
	char co,wt;
	int htn[100],atn[100];
	memset(htn,0,sizeof(htn));
	memset(atn,0,sizeof(atn));
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t>>wt>>no>>co;
		if(co=='r'){
			if(wt=='a'&&atn[no]!=-1){
				v.push_back(make_pair(wt,make_pair(no,t)));
				atn[no]=-1;
			}
			//atn[no]=-1;
			else if(wt=='h'&&htn[no]!=-1){
			v.push_back(make_pair(wt,make_pair(no,t)));
			htn[no]=-1;
			}

		}
		else if(co=='y'){
			if(wt=='a'&&atn[no]!=-1){
			atn[no]++;
			if(atn[no]==2)
			v.push_back(make_pair(wt,make_pair(no,t)));
			}
			else if(wt=='h'&&htn[no]!=-1){
			htn[no]++;
			if(htn[no]==2)
			v.push_back(make_pair(wt,make_pair(no,t)));
			}
		}
	}
	for(i=0;i<v.size();i++){
		if(v[i].first=='a')
		cout<<at<<" ";
		else
		cout<<ht<<" ";
		cout<<v[i].second.first<<" "<<v[i].second.second<<"\n";
	}

}


#include<bits/stdc++.h>
using namespace std;
#define ppp pair<char, pair<int,int> >
int main(){
	string ht,at;
	cin>>ht>>at;
	vector<ppp>v;
	int i,j,n,t,no;
	char co,wt;
	int htn[100],atn[100];
	memset(htn,0,sizeof(htn));
	memset(atn,0,sizeof(atn));
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t>>wt>>no>>co;
		if(co=='r'){
			if(wt=='a'&&atn[no]!=-1&&atn[no]<2){
				v.push_back(make_pair(wt,make_pair(no,t)));
				atn[no]=-1;
			}
			//atn[no]=-1;
			else if(wt=='h'&&htn[no]!=-1&&htn[no]<2){
			v.push_back(make_pair(wt,make_pair(no,t)));
			htn[no]=-1;
			}

		}
		else if(co=='y'){
			if(wt=='a'&&atn[no]!=-1){
			atn[no]++;
			if(atn[no]==2)
			v.push_back(make_pair(wt,make_pair(no,t)));
			}
			else if(wt=='h'&&htn[no]!=-1){
			htn[no]++;
			if(htn[no]==2)
			v.push_back(make_pair(wt,make_pair(no,t)));
			}
		}
	}
	for(i=0;i<v.size();i++){
		if(v[i].first=='a')
		cout<<at<<" ";
		else
		cout<<ht<<" ";
		cout<<v[i].second.first<<" "<<v[i].second.second<<"\n";
	}

}


#include<bits/stdc++.h>
using namespace std;
#define ppp pair<char, pair<int,int> >
int main(){
	string ht,at;
	cin>>ht>>at;
	vector<ppp>v;
	int i,j,n,t,no;
	char co,wt;
	int htn[100],atn[100];
	memset(htn,0,sizeof(htn));
	memset(atn,0,sizeof(atn));
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t>>wt>>no>>co;
		if(co=='r'){
			v.push_back(make_pair(wt,make_pair(no,t)));
		}
		else if(co=='y'){
			if(wt=='a'){
			atn[no]++;
			if(atn[no]==2)
			v.push_back(make_pair(wt,make_pair(no,t)));
			}
			else{
			htn[no]++;
			if(htn[no]==2)
			v.push_back(make_pair(wt,make_pair(no,t)));
			}
		}
	}
	for(i=0;i<v.size();i++){
		if(v[i].first=='a')
		cout<<at<<" ";
		else
		cout<<ht<<" ";
		cout<<v[i].second.first<<" "<<v[i].second.second<<"\n";
	}

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string home,away;
    cin>>home>>away;
    ll n;
    cin>>n;
    map<ll,ll>m1,m2;

    for(ll t=0;t<n;t++)
    {
        ll tm,x;
        char c,s;
        cin>>tm>>c>>x>>s;
        if(s=='y')
        {
        if(c=='h')
        {
            if(m1[x]==1)
            {
                cout<<home<<" "<<x<<" "<<tm<<endl;
            }
            else
            {
                m1[x]++;
            }
        }

        else
        {
             if(m2[x]==1)
            {
                cout<<away<<" "<<x<<" "<<tm<<endl;
            }
            else
            {
                m2[x]++;
            }
        }
        }
        else
        {
            if(c=='h')
            {
                if(m1[x]<2)
                {

                 cout<<home<<" "<<x<<" "<<tm<<endl;
                 m1[x]=2;
                }

            }
            else
            {
                if(m2[x]<2)
                {
                cout<<away<<" "<<x<<" "<<tm<<endl;
                m2[x]=2;
                }

            }
        }

    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string home,away;
    cin>>home>>away;
    ll n;
    cin>>n;
    map<ll,ll>m1,m2;

    for(ll t=0;t<n;t++)
    {
        ll tm,x;
        char c,s;
        cin>>tm>>c>>x>>s;
        if(s=='y')
        {
        if(c=='h')
        {
            m1[x]++;
            if(m1[x]==2)
            {
                cout<<home<<" "<<x<<" "<<tm<<endl;
            }

        }

        else
        {
            m2[x]++;
             if(m2[x]==2)
            {
                cout<<away<<" "<<x<<" "<<tm<<endl;
            }

        }
        }
        else
        {
            if(c=='h')
            {
                if(m1[x]<2)
                {

                 cout<<home<<" "<<x<<" "<<tm<<endl;
                 m1[x]=3;
                }

            }
            else
            {
                if(m2[x]<2)
                {
                cout<<away<<" "<<x<<" "<<tm<<endl;
                m2[x]=3;
                }

            }
        }

    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string home,away;
    cin>>home>>away;
    ll n;
    cin>>n;
    map<ll,ll>m1,m2;

    for(ll t=0;t<n;t++)
    {
        ll tm,x;
        char c,s;
        cin>>tm>>c>>x>>s;
        if(s=='y')
        {
        if(c=='h')
        {
            if(m1[x])
            {
                cout<<home<<" "<<x<<" "<<tm<<endl;
            }
            else
            {
                m1[x]=1;
            }
        }

        else
        {
             if(m2[x])
            {
                cout<<away<<" "<<x<<" "<<tm<<endl;
            }
            else
            {
                m2[x]=1;
            }
        }
        }
        else
        {
            if(c=='h')
            {
                 cout<<home<<" "<<x<<" "<<tm<<endl;

            }
            else
            {
                cout<<away<<" "<<x<<" "<<tm<<endl;

            }
        }

    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string home,away;
    cin>>home>>away;
    ll n;
    cin>>n;
    map<ll,ll>m1,m2;

    for(ll t=0;t<n;t++)
    {
        ll tm,x;
        char c,s;
        cin>>tm>>c>>x>>s;
        if(s=='y')
        {
        if(c=='h')
        {
            if(m1[x])
            {
                cout<<home<<" "<<x<<" "<<tm<<endl;
            }
            else
            {
                m1[x]=1;
            }
        }

        else
        {
             if(m2[x])
            {
                cout<<home<<" "<<x<<" "<<tm<<endl;
            }
            else
            {
                m2[x]=1;
            }
        }
        }
        else
        {
            if(c=='h')
            {
                 cout<<home<<" "<<x<<" "<<tm<<endl;

            }
            else
            {
                cout<<away<<" "<<x<<" "<<tm<<endl;

            }
        }

    }
}


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

typedef long long ll;
typedef pair<int, int> pii;

const int MAX = (int)2e5 + 99;
const int INF = (int)1e9 + 99;

int b[MAX];
bool used[MAX];
pair<int, long long> par[MAX];

pair<int, int> find_set(int v) {
    if (par[v].first == v) return par[v];
    pair<int, long long> ans = find_set(par[v].first);
    if (!used[v]) {
        par[v].first = ans.first;
        par[v].second += ans.second;
    }
    used[v] = 1;
    return par[v];
}

int main(int argc, char ** argv) {
    int n;

    cin >> n;
    for (int i=1; i<=n; ++i) {
        cin >> b[i];
    }

    map<int, vector<int>> pos, neg;
    for (int i=n; i>0; --i) {
        int val = i - b[i];
        if (val < 0) neg[val*(-1)].push_back(i);
        else pos[val].push_back(i);
        par[i] = {i, b[i]};
    }

    for (int i=1; i<=n; ++i) {
        int val = i - b[i];
        if (val < 0) {
            val *= -1;
            neg[val].pop_back();
            if (!neg[val].empty()) par[i].first = neg[val].back();
        }
        else {
            pos[val].pop_back();
            if (!pos[val].empty()) par[i].first = pos[val].back();
        }
    }

    long long ans = 0;
    for (int i=1; i<=n; ++i) {
        if (!used[i])
            par[i] = find_set(i);
        ans = max(ans, par[i].second);
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;

const int MAX = (int)2e5 + 99;
const int INF = (int)1e9 + 99;

int b[MAX];
bool used[MAX];
pair<int, long long> par[MAX];

pair<int, int> find_set(int v) {
    if (par[v].first == v) return par[v];
    pair<int, long long> ans = find_set(par[v].first);
    if (!used[v]) {
        par[v].first = ans.first;
        par[v].second += ans.second;
    }
    used[v] = 1;
    return par[v];
}

int main(int argc, char ** argv) {
    int n;

    cin >> n;
    for (int i=1; i<=n; ++i) {
        cin >> b[i];
    }

    map<int, vector<int>> pos, neg;
    for (int i=n; i>0; --i) {
        int val = i - b[i];
        if (val < 0) neg[val*(-1)].push_back(i);
        else pos[val].push_back(i);
        par[i] = {i, b[i]};
    }

    for (int i=1; i<=n; ++i) {
        int val = i - b[i];
        if (val < 0) {
            val *= -1;
            neg[val].pop_back();
            if (!neg[val].empty()) par[i].first = neg[val].back();
        }
        else {
            pos[val].pop_back();
            if (!pos[val].empty()) par[i].first = pos[val].back();
        }
    }

    long long ans = 0;
    for (int i=1; i<=n; ++i) {
        par[i] = find_set(i);
        ans = max(ans, par[i].second);
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;

const int MAX = (int)2e5 + 99;
const int INF = (int)1e9 + 99;

int b[MAX];

int main(int argc, char ** argv) {
    int n;

    cin >> n;
    for (int i=1; i<=n; ++i) {
        cin >> b[i];
    }

    map<int, vector<int>> pos, neg;
    for (int i=n; i>0; --i) {
        int val = i - b[i];
        if (val < 0) neg[val*(-1)].push_back(i);
        else pos[val].push_back(i);
    }

    long long ans = 0;
    for (int i=1; i<=n; ++i) {
        int val = i - b[i];
        long long sum = 0;
        if (val < 0) {
            val *= -1;
            for (int id : neg[val])
                sum += b[id];
            neg[val].clear();
        }
        else {
            for (int id : pos[val])
                sum += b[id];
            pos[val].clear();
        }
        ans = max(ans, sum);
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{long long int n,max=0;
    cin >> n;
    int a[n]; int b[200001];
    for(int i=0;i<200001;++i)
    b[i]=0;
    for(int i=0;i<n;++i)
    cin >> a[i];
    for(int i=0;i<n;++i)
    {if(b[i]!=1)
    {long long int sum=a[i];
        for(int j=i+1;j<n;++j)
        {if(a[j]-a[i]==j-i)
            {b[j]=1;
                sum=sum+a[j];
            }
        }
        if(sum >max)
        max=sum;
    } }
    cout<<max;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{long long int n,max=0;
    cin >> n;
    int a[n]; long long int b[800001];
    for(int i=0;i<800001;++i)
    b[i]=0;
    for(int i=0;i<n;++i)
    cin >> a[i];
    for(int i=0;i<n;++i)
    {if(a[i]-a[0]-i<=0)
        b[abs(a[i]-a[0]-i)]+=a[i];
        else
        b[2*abs(a[i]-a[0]-i)]+=a[i];
    }
    for(int i=0;i<800001;++i)
    {if(b[i]>max)
        max=b[i];
    }
    cout<<max;}


#include<bits/stdc++.h>
using namespace std;
	long long dp[400001];
int main()
{
	int n;
//	cout<<"rocmk";
	cin>>n;
	int a[n],b[n];
	for(int i=0;i<n;++i) cin>>a[i];

	for(int i=0;i<n;++i)
	{
		b[i]=a[i]-i;
	}
	long long ans=INT_MIN;
	for(int i=0;i<n;++i)
	{

		dp[b[i]+2000]+=a[i];
		ans=max(ans,dp[b[i]+2000]);
	}
	cout<<ans<<"\n";
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
	long long dp[400001];
int main()
{
	int n;
//	cout<<"rocmk";
	cin>>n;
	int a[n],b[n];
	for(int i=0;i<n;++i) cin>>a[i];

	for(int i=0;i<n;++i)
	{
		b[i]=a[i]-i;
	}
	long long ans=INT_MIN;
	for(int i=0;i<n;++i)
	{

		dp[b[i]+200000]+=a[i];
		ans=max(ans,dp[b[i]+200000]);
	}
	cout<<ans<<"\n";
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
	long long dp[600001];
int main()
{
	int n;
//	cout<<"rocmk";
	cin>>n;
	int a[n],b[n];
	for(int i=0;i<n;++i) cin>>a[i];

	for(int i=0;i<n;++i)
	{
		b[i]=a[i]-i;
	}
	long long ans=INT_MIN;
	for(int i=0;i<n;++i)
	{

		dp[b[i]+200000]+=a[i];
		ans=max(ans,dp[b[i]+200000]);
	}
	cout<<ans<<"\n";
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
	long long dp[400001];
int main()
{
	int n;
//	cout<<"rocmk";
	cin>>n;
	int a[n],b[n];
	for(int i=0;i<n;++i) cin>>a[i];

	for(int i=0;i<n;++i)
	{
		b[i]=a[i]-i;
	}
	long long ans=INT_MIN;
	for(int i=0;i<n;++i)
	{

		dp[b[i]+200000]+=a[i];
		ans=max(ans,dp[b[i]+2000]);
	}
	cout<<ans<<"\n";
	return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
   int n ;
   cin >> n;
   int arr[n] ;
   for( int i=0 ; i<n ; i++ )
   {
       cin >> arr[i] ;
   }
   if( n==1 )
   {
       cout << arr[0] << endl ;
   }
   else
   {
       int start , end , sum=0 , maxi = INT_MIN ;
       for( int i=0 ; i<n-1 ; i++ )
       {
           sum=0;
           start = i ;
           sum = sum + arr[start] ;
           for( int j=i+1 ; j<n ; j++ )
           {
               if( (arr[j]-arr[start])==(j-start) )
               {
                   sum = sum + arr[j] ;
                   start = j ;
               }
           }
           //cout << "sum : " <<sum << endl ;
           maxi = max( maxi , sum ) ;
       }
       maxi = max( maxi , arr[n-1] ) ;
       cout << maxi << endl ;
   }
}


#include <iostream>
#include <climits>
using namespace std;
#define int long long
int32_t main()
{
     ios_base::sync_with_stdio(false);  cin.tie(NULL);
   int n ;
   cin >> n;
   int arr[n] ;
   for( int i=0 ; i<n ; i++ )
   {
       cin >> arr[i] ;
   }
   if( n==1 )
   {
       cout << arr[0] << endl ;
   }
   else
   {
       int start , end , sum=0 , maxi = INT_MIN ;
       for( int i=0 ; i<n-1 ; i++ )
       {
           sum=0;
           start = i ;
           sum = sum + arr[start] ;
           for( int j=i+1 ; j<n ; j++ )
           {
               if( (arr[j]-arr[start])==(j-start) )
               {
                   sum = sum + arr[j] ;
                   start = j ;
               }
           }
           //cout << "sum : " <<sum << endl ;
           maxi = max( maxi , sum ) ;
       }
       maxi = max( maxi , arr[n-1] ) ;
       cout << maxi << endl ;
   }
}


#include <iostream>
#include <climits>
#include <map>
using namespace std;
#define int long long
int32_t main()
{
   ios_base::sync_with_stdio(false);  cin.tie(NULL);
   int n ;
   cin >> n;
   int arr[n] ;
   for( int i=0 ; i<n ; i++ )
   {
       cin >> arr[i] ;
   }
   map< int , int > mp ;
   for( int i=0 ; i<n ; i++ )
   {
       int ans = arr[i] - i ;
       mp[ ans ] = mp[ ans ] + arr[i] ;
   }
   int maxi = INT_MIN ;
   for( auto it=mp.begin() ; it!=mp.end() ; it ++ )
   {
       maxi = max( maxi , it->second ) ;
   }
   cout << maxi << endl ;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
   int n ;
   cin >> n;
   int arr[n] ;
   for( int i=0 ; i<n ; i++ )
   {
       cin >> arr[i] ;
   }
   if( n==1 )
   {
       cout << arr[0] << endl ;
   }
   else
   {
       int start , end , sum=0 , maxi = INT_MIN ;
       for( int i=0 ; i<n-1 ; i++ )
       {
           sum=0;
           start = i ;
           sum = sum + arr[start] ;
           for( int j=i+1 ; j<n ; j++ )
           {
               if( (arr[j]-arr[start])==(j-start) )
               {
                   sum = sum + arr[j] ;
                   start = j ;
               }
           }
           //cout << "sum : " <<sum << endl ;
           maxi = max( maxi , sum ) ;
       }
       cout << maxi << endl ;
   }
}


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

long long i,x,n,cap,Maxi,poz;
struct grup{
long Dif;
long long Sum;
}t;

     long Find(grup A[],int dif)
     {
        for(int i=1;i<=cap;i++)
            if(A[i].Dif==dif)
               return i;
        return 0;
     }

int main()
{
  cin>>n;
  Maxi=0;
  grup A[n+2];
  for(i=1;i<=n;i++)
  {
    cin>>x;
    if((poz=Find(A,i-x)))
        {
        A[poz].Sum+=x;
        if(A[poz].Sum>Maxi)
            Maxi=A[poz].Sum;
        }
       else
       {
           cap++;
           A[cap].Dif=i-x;
           A[cap].Sum=x;
           if(x>Maxi)
              Maxi=x;
       }
  }
  cout<<Maxi;
}

/*
long n,i;
long long Maxi;
struct city{
  int Beauty;
  long long Solution;
};
vector<city> City;

    void Sum(vector<city> &V,int it)
    {
        for(int i=it+1;i<=n;i++)
            if(V[i].Beauty-V[it].Beauty==i-it)
              {
               V[it].Solution+=V[i].Solution;
               break;
              }
        if(V[it].Solution>Maxi)
            Maxi=V[it].Solution;
    }

int main()
{
    cin>>n;
    City.resize(n+1);
    for(i=1;i<=n;i++)
    {
      cin>>City[i].Beauty;
      City[i].Solution=City[i].Beauty;
    }
    Maxi=City[n].Solution;

    for(i=n-1;i>=1;i--)
        Sum(City,i);

    cout<<Maxi;
    return 0;
}
*/


#include <iostream>
using namespace std;

long long i,x,n,cap,Maxi,poz;
struct grup{
long Dif;
long long Sum;
}t,A[200000];

     long Find(grup A[],int dif)
     {
        for(int i=1;i<=cap;i++)
            if(A[i].Dif==dif)
               return i;
        return 0;
     }

int main()
{
  cin>>n;
  Maxi=0;
  for(i=1;i<=n;i++)
  {
    cin>>x;
    if((poz=Find(A,i-x)))
        {
        A[poz].Sum+=x;
        if(A[poz].Sum>Maxi)
            Maxi=A[poz].Sum;
        }
       else
       {
           cap++;
           A[cap].Dif=i-x;
           A[cap].Sum=x;
           if(x>Maxi)
              Maxi=x;
       }
  }
  cout<<Maxi;
}

/*
long n,i;
long long Maxi;
struct city{
  int Beauty;
  long long Solution;
};
vector<city> City;

    void Sum(vector<city> &V,int it)
    {
        for(int i=it+1;i<=n;i++)
            if(V[i].Beauty-V[it].Beauty==i-it)
              {
               V[it].Solution+=V[i].Solution;
               break;
              }
        if(V[it].Solution>Maxi)
            Maxi=V[it].Solution;
    }

int main()
{
    cin>>n;
    City.resize(n+1);
    for(i=1;i<=n;i++)
    {
      cin>>City[i].Beauty;
      City[i].Solution=City[i].Beauty;
    }
    Maxi=City[n].Solution;

    for(i=n-1;i>=1;i--)
        Sum(City,i);

    cout<<Maxi;
    return 0;
}
*/


#include <iostream>
using namespace std;

long long Poz[200000],Neg[20000],x,n,i,Max;

int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        if(x-i>0)
        {
            Poz[x-i]+=x;
            Max=max(Poz[x-i],Max);
        }
        else
        {
            Neg[i-x]+=x;
            Max=max(Max,Poz[x-i]);
        }
    }

    cout<<Max;
return 0;
}

/*
long long i,x,n,cap,Maxi,poz;
struct grup{
long Dif;
long long Sum;
}t,A[200000];

     long Find(grup A[],int dif)
     {
        for(int i=1;i<=cap;i++)
            if(A[i].Dif==dif)
               return i;
        return 0;
     }

int main()
{
  cin>>n;
  Maxi=0;
  for(i=1;i<=n;i++)
  {
    cin>>x;
    if((poz=Find(A,i-x)))
        {
        A[poz].Sum+=x;
        if(A[poz].Sum>Maxi)
            Maxi=A[poz].Sum;
        }
       else
       {
           cap++;
           A[cap].Dif=i-x;
           A[cap].Sum=x;
           if(x>Maxi)
              Maxi=x;
       }
  }
  cout<<Maxi;
}

*/

/*
long n,i;
long long Maxi;
struct city{
  int Beauty;
  long long Solution;
};
vector<city> City;

    void Sum(vector<city> &V,int it)
    {
        for(int i=it+1;i<=n;i++)
            if(V[i].Beauty-V[it].Beauty==i-it)
              {
               V[it].Solution+=V[i].Solution;
               break;
              }
        if(V[it].Solution>Maxi)
            Maxi=V[it].Solution;
    }

int main()
{
    cin>>n;
    City.resize(n+1);
    for(i=1;i<=n;i++)
    {
      cin>>City[i].Beauty;
      City[i].Solution=City[i].Beauty;
    }
    Maxi=City[n].Solution;

    for(i=n-1;i>=1;i--)
        Sum(City,i);

    cout<<Maxi;
    return 0;
}
*/


#include <iostream>
using namespace std;

long long i,x,n,cap,Maxi,poz;
struct grup{
long Dif;
long long Sum;
}t,A[200000];

     long Find(grup A[],int dif)
     {
        for(int i=1;i<=cap;i++)
            if(A[i].Dif==dif)
               return i;
        return 0;
     }

int main()
{
  cin>>n;
  Maxi=0;
  for(i=1;i<=n;i++)
  {
    x=2*(i-1)+1;
    if((poz=Find(A,i-x)))
        {
        A[poz].Sum+=x;
        if(A[poz].Sum>Maxi)
            Maxi=A[poz].Sum;
        }
       else
       {
           cap++;
           A[cap].Dif=i-x;
           A[cap].Sum=x;
           if(x>Maxi)
              Maxi=x;
       }
  }
  cout<<Maxi;
}

/*
long n,i;
long long Maxi;
struct city{
  int Beauty;
  long long Solution;
};
vector<city> City;

    void Sum(vector<city> &V,int it)
    {
        for(int i=it+1;i<=n;i++)
            if(V[i].Beauty-V[it].Beauty==i-it)
              {
               V[it].Solution+=V[i].Solution;
               break;
              }
        if(V[it].Solution>Maxi)
            Maxi=V[it].Solution;
    }

int main()
{
    cin>>n;
    City.resize(n+1);
    for(i=1;i<=n;i++)
    {
      cin>>City[i].Beauty;
      City[i].Solution=City[i].Beauty;
    }
    Maxi=City[n].Solution;

    for(i=n-1;i>=1;i--)
        Sum(City,i);

    cout<<Maxi;
    return 0;
}
*/


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

long n,i;
long long Maxi;
struct city{
  int Beauty;
  long long Solution;
};
vector<city> City;

    void Sum(vector<city> &V,int it)
    {
        for(int i=it+1;i<=n;i++)
            if(V[i].Beauty-V[it].Beauty==i-it)
              {
               V[it].Solution+=V[i].Solution;
               break;
              }
        if(V[it].Solution>Maxi)
            Maxi=V[it].Solution;
    }

int main()
{
    cin>>n;
    City.resize(n+1);
    for(i=1;i<=n;i++)
    {
      cin>>City[i].Beauty;
      City[i].Solution=City[i].Beauty;
    }
    Maxi=City[n].Solution;

    for(i=n-1;i>=1;i--)
        Sum(City,i);

    cout<<Maxi;
    return 0;
}


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

int n,i;
long Maxi;
struct city{
  int Beauty;
  long Solution;
};
vector<city> City;

    void Sum(vector<city> &V,int it)
    {
        for(int i=it+1;i<=n;i++)
            if(V[i].Beauty-V[it].Beauty==i-it)
              {
               V[it].Solution+=V[i].Solution;
               break;
              }
        if(V[it].Solution>Maxi)
            Maxi=V[it].Solution;
    }

int main()
{
    cin>>n;
    City.resize(n+1);
    for(i=1;i<=n;i++)
    {
      cin>>City[i].Beauty;
      City[i].Solution=City[i].Beauty;
    }
    Maxi=City[n].Solution;

    for(i=n-1;i>=1;i--)
        Sum(City,i);

    cout<<Maxi;
    return 0;
}


#include <iostream>
using namespace std;

long long Poz[400000],Neg[40000],x,n,i,Max;

int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        if(x-i>0)
        {
            Poz[x-i]+=x;
            Max=max(Poz[x-i],Max);
        }
        else
        {
            Neg[i-x]+=x;
            Max=max(Max,Neg[i-x]);
        }
    }

    cout<<Max;
return 0;
}

/*
long long i,x,n,cap,Maxi,poz;
struct grup{
long Dif;
long long Sum;
}t,A[200000];

     long Find(grup A[],int dif)
     {
        for(int i=1;i<=cap;i++)
            if(A[i].Dif==dif)
               return i;
        return 0;
     }

int main()
{
  cin>>n;
  Maxi=0;
  for(i=1;i<=n;i++)
  {
    cin>>x;
    if((poz=Find(A,i-x)))
        {
        A[poz].Sum+=x;
        if(A[poz].Sum>Maxi)
            Maxi=A[poz].Sum;
        }
       else
       {
           cap++;
           A[cap].Dif=i-x;
           A[cap].Sum=x;
           if(x>Maxi)
              Maxi=x;
       }
  }
  cout<<Maxi;
}

*/

/*
long n,i;
long long Maxi;
struct city{
  int Beauty;
  long long Solution;
};
vector<city> City;

    void Sum(vector<city> &V,int it)
    {
        for(int i=it+1;i<=n;i++)
            if(V[i].Beauty-V[it].Beauty==i-it)
              {
               V[it].Solution+=V[i].Solution;
               break;
              }
        if(V[it].Solution>Maxi)
            Maxi=V[it].Solution;
    }

int main()
{
    cin>>n;
    City.resize(n+1);
    for(i=1;i<=n;i++)
    {
      cin>>City[i].Beauty;
      City[i].Solution=City[i].Beauty;
    }
    Maxi=City[n].Solution;

    for(i=n-1;i>=1;i--)
        Sum(City,i);

    cout<<Maxi;
    return 0;
}
*/


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

long i,x,n,cap,Maxi,poz;
struct grup{
int Dif;
long long Sum;
}t;

     long Find(grup A[],int dif)
     {
        for(int i=1;i<=cap;i++)
            if(A[i].Dif==dif)
               return i;
        return 0;
     }

int main()
{
  cin>>n;
  Maxi=0;
  grup A[n+2];
  for(i=1;i<=n;i++)
  {
    cin>>x;
    if((poz=Find(A,i-x)))
        {
        A[poz].Sum+=x;
        if(A[poz].Sum>Maxi)
            Maxi=A[poz].Sum;
        }
       else
       {
           cap++;
           A[cap].Dif=i-x;
           A[cap].Sum=x;
           if(x>Maxi)
              Maxi=x;
       }
  }
  cout<<Maxi;
}

/*
long n,i;
long long Maxi;
struct city{
  int Beauty;
  long long Solution;
};
vector<city> City;

    void Sum(vector<city> &V,int it)
    {
        for(int i=it+1;i<=n;i++)
            if(V[i].Beauty-V[it].Beauty==i-it)
              {
               V[it].Solution+=V[i].Solution;
               break;
              }
        if(V[it].Solution>Maxi)
            Maxi=V[it].Solution;
    }

int main()
{
    cin>>n;
    City.resize(n+1);
    for(i=1;i<=n;i++)
    {
      cin>>City[i].Beauty;
      City[i].Solution=City[i].Beauty;
    }
    Maxi=City[n].Solution;

    for(i=n-1;i>=1;i--)
        Sum(City,i);

    cout<<Maxi;
    return 0;
}
*/


#include <iostream>
using namespace std;

long long Poz[400000],Neg[40000],x,n,i,Max;

int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        if(x-i>0)
        {
            Poz[x-i]+=x;
            Max=max(Poz[x-i],Max);
        }
        else
        {
            Neg[i-x]+=x;
            Max=max(Max,Poz[x-i]);
        }
    }

    cout<<Max;
return 0;
}

/*
long long i,x,n,cap,Maxi,poz;
struct grup{
long Dif;
long long Sum;
}t,A[200000];

     long Find(grup A[],int dif)
     {
        for(int i=1;i<=cap;i++)
            if(A[i].Dif==dif)
               return i;
        return 0;
     }

int main()
{
  cin>>n;
  Maxi=0;
  for(i=1;i<=n;i++)
  {
    cin>>x;
    if((poz=Find(A,i-x)))
        {
        A[poz].Sum+=x;
        if(A[poz].Sum>Maxi)
            Maxi=A[poz].Sum;
        }
       else
       {
           cap++;
           A[cap].Dif=i-x;
           A[cap].Sum=x;
           if(x>Maxi)
              Maxi=x;
       }
  }
  cout<<Maxi;
}

*/

/*
long n,i;
long long Maxi;
struct city{
  int Beauty;
  long long Solution;
};
vector<city> City;

    void Sum(vector<city> &V,int it)
    {
        for(int i=it+1;i<=n;i++)
            if(V[i].Beauty-V[it].Beauty==i-it)
              {
               V[it].Solution+=V[i].Solution;
               break;
              }
        if(V[it].Solution>Maxi)
            Maxi=V[it].Solution;
    }

int main()
{
    cin>>n;
    City.resize(n+1);
    for(i=1;i<=n;i++)
    {
      cin>>City[i].Beauty;
      City[i].Solution=City[i].Beauty;
    }
    Maxi=City[n].Solution;

    for(i=n-1;i>=1;i--)
        Sum(City,i);

    cout<<Maxi;
    return 0;
}
*/


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

int n,i;
long long Maxi;
struct city{
  int Beauty;
  long long Solution;
};
vector<city> City;

    void Sum(vector<city> &V,int it)
    {
        for(int i=it+1;i<=n;i++)
            if(V[i].Beauty-V[it].Beauty==i-it)
              {
               V[it].Solution+=V[i].Solution;
               break;
              }
        if(V[it].Solution>Maxi)
            Maxi=V[it].Solution;
    }

int main()
{
    cin>>n;
    City.resize(n+1);
    for(i=1;i<=n;i++)
    {
      cin>>City[i].Beauty;
      City[i].Solution=City[i].Beauty;
    }
    Maxi=City[n].Solution;

    for(i=n-1;i>=1;i--)
        Sum(City,i);

    cout<<Maxi;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int n;
    cin>>n;
    ll a[n];
    ll b[400005];
    ll c[400005];
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]-(i+1)>0)b[a[i]-(i+1)]+=a[i];
        else
        {
            c[abs(a[i]-(i+1))]+=a[i];
        }
    }
    int *ans1=max_element(b,b+400005);
    int *ans2=max_element(c,c+400005);
    cout<<max(*ans1,*ans2);

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    int b[400005];
    int c[400005];
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]-(i+1)>0)b[a[i]-(i+1)]+=a[i];
        else
        {
            c[abs(a[i]-(i+1))]+=a[i];
        }
    }
    int *ans1=max_element(b,b+400005);
    int *ans2=max_element(c,c+400005);
    cout<<max(*ans1,*ans2);

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int n;
    cin>>n;
    ll a[n];
    ll b[400005];
    ll c[400005];
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]-(i+1)>0)b[a[i]-(i+1)]+=a[i];
        else
        {
            c[abs(a[i]-(i+1))]+=a[i];
        }
    }
    ll *ans1=max_element(b,b+400005);
    ll *ans2=max_element(c,c+400005);
    cout<<max(*ans1,*ans2);

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
const int MAX = 1e5 + 10;
const double exps = 1e-8;

inline int max(ll a, ll b) { return a > b ? a : b; }
inline int min(int a, int b) { return a > b ? b : a; }
int n;
map<ll, ll> a;
int main() {
    scanf("%d", &n);
    ll k, m = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> k;
        a[k - i] += k;
        m = max(m, a[k - i]);
    }
    cout << m;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
const int MAX = 1e5 + 10;
const double exps = 1e-8;

inline int max(ll a, ll b) { return a > b ? a : b; }
inline int min(int a, int b) { return a > b ? b : a; }
int n;
struct node {
    int b, c;
} a[N];
bool cmp(node x, node y) { return x.c > y.c; }
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        int t;
        scanf("%d", &t);
        a[i].c = i - t;
        a[i].b = t;
    }
    sort(a + 1, a + n + 1, cmp);
    ll sum = a[1].b, m = sum, pre = a[1].c;
    for (int i = 2; i <= n; ++i) {
        if (a[i].c == pre)
            sum += a[i].b;
        else {
            m = max(m, sum);
            sum = a[i].b;
            pre = a[i].c;
        }
    }
    m = max(m, sum);
    cout << m;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
const int MAX = 1e5 + 10;
const double exps = 1e-8;

inline int max(ll a, ll b) { return a > b ? a : b; }
inline int min(int a, int b) { return a > b ? b : a; }
int n;
struct node {
    ll b, c;
} a[N];
bool cmp(node x, node y) { return x.c > y.c; }
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        ll t;
        scanf("%lld", &t);
        a[i].c = i - t;
        a[i].b = t;
    }
    sort(a + 1, a + n + 1, cmp);
    ll sum = a[1].b, m = sum, pre = a[1].c;
    for (int i = 2; i <= n; ++i) {
        if (a[i].c == pre)
            sum += a[i].b;
        else {
            m = max(m, sum);
            sum = a[i].b;
            pre = a[i].c;
        }
    }
    m = max(m, sum);
    cout << m;
}


#include <bits/stdc++.h>
using namespace std;
int n;
long long b, ansm;
map<int, long long> ans;
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &b);
        ansm = max(ans[b - i] += b, ansm);
    }
    printf("%lld", ansm);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MOD 1000000007
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int
#define pb push_back
#define pob pop_back
//               When something is important enough, you do it even if the odds are not in your favor.
LI dp[200002],n;
void solve(LI st,LI arr[]){
    if(st==-1) return;
    LI i,max=arr[st];
    fo(i,st+1,n){
       if(arr[i]-arr[st]==i-st){
        if(dp[i]!=-1){if(dp[i]+arr[st]>max) max=dp[i]+arr[st];}
        else{
            solve(i,arr);
            if(dp[i]+arr[st]>max) max=dp[i]+arr[st];
        }
       }
    }
    dp[st]=max;
    solve(st-1,arr);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
        cin>>n;
        memset(dp,-1,sizeof(dp));
        LI arr[n],i;
        fo(i,0,n) cin>>arr[i];
        solve(n-1,arr);
        LI max=0;
        fo(i,0,200002){if(max<dp[i]) max=dp[i];}
        cout<<max<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MOD 1000000007
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int
#define pb push_back
#define pob pop_back
//               When something is important enough, you do it even if the odds are not in your favor.
std::map<LI, std::vector<LI>> m;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
        LI n;cin>>n;
        LI arr[n],i;
        fo(i,0,n) cin>>arr[i];
        fo(i,0,n){
            LI d=arr[i]-i-1;
            m[d].pb(arr[i]);
        }
        LI max=0;
        for(auto x:m){
          LI a=0;
          for(auto it:x.second){
            a+=it;
          }
          if(max<a) max=a;
        }
        cout<<max<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MOD 1000000007
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int
#define pb push_back
#define pob pop_back
//               When something is important enough, you do it even if the odds are not in your favor.
std::map<LI, std::vector<LI>> m;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
        LI n;cin>>n;
        LI arr[n],i;
        fo(i,0,n) cin>>arr[i];
        fo(i,0,n){
            LI d=arr[i]-i-1;
            m[d].pb(arr[i]);
        }
        LLI max=0;
        for(auto x:m){
          LLI a=0;
          for(auto it:x.second){
            a+=it;
          }
          if(max<a) max=a;
        }
        cout<<max<<endl;
    }
    return 0;
}


#include<iostream>
#include<iomanip>
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
	long long int b,n,i,j,s=0,t=0;
	cin>>n;
	long long int a[n];
	for(i=1;i<=n;i++)
	{
		cin>>b;
		a[i]=b-i;
	}
	for(i=1;i<=n;i++)
	{
		s=a[i]+i;
		for(j=i+1;j<=n;j++)
		{
			if(a[i]==a[j])
			s=s+a[j]+j;
			t=max(t,s);
		}
	}
	cout<<max(s,t);
}


#include<iostream>
#include<iomanip>
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
	long long int b,n,i,j,s=0,t=0,maxm=400001;
	cin>>n;
	long long int a[n];
	long long int arr[maxm];
	for(i=1;i<maxm;i++)
	{
	arr[i]=0;
	}
	for(i=1;i<=n;i++)
	{
		cin>>b;
		a[i]=b-i;
	}
	for(i=1;i<=n;i++)
	{
		s=a[i]+i;
		arr[a[i]]=arr[a[i]]+s;
	}
	for(i=1;i<maxm;i++)
	{
		t=max(t,arr[i]);
	}
	cout<<t;
}


#include<iostream>
#include<iomanip>
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
	long long int c,n,i,j,s=0,t=0;
	cin>>n;
	long long int a[n+1],b[n+1],arr[n+1];
	for(i=0;i<n;i++)
	{
		cin>>c;
		b[i]=i+1;
		a[i]=c-b[i];

	}
	vector<pair<int,int> >v;
	for(i=0;i<n;i++)
	{
		v.push_back(make_pair(a[i],b[i]));
	}
	sort(v.begin(),v.end());
	for(i=0;i<n;i++)
	{
		arr[i]=v[i].first+v[i].second;
	}
	s=arr[0];
	for(i=0;i<n-1;i++)
	{
		if(v[i].first==v[i+1].first)
		s=s+arr[i+1];
		else
		{
		t=max(t,s);
		s=arr[i+1];
	    }

	}
    cout<<max(t,s);
}


#include<iostream>
#include<cstdio>
using namespace std;
long long n,b[200001],ans[400001],maxx;
inline long long read()
{
	int r=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		r=(r<<3)+(r<<1)+(ch^48);
		ch=getchar();
	}
	return r*w;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		b[i]=read();
	for(int i=1;i<=n;i++)
		maxx=max(maxx,ans[b[i]-i+n]=b[i]+ans[b[i]-i+n]);
	printf("%lld",maxx);
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
long long n,b[200001],ans[600001],maxx;
inline long long read()
{
	long long r=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		r=(r<<3)+(r<<1)+(ch^48);
		ch=getchar();
	}
	return r*w;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		b[i]=read();
	for(int i=1;i<=n;i++)
		maxx=max(maxx,ans[b[i]-i+n]=b[i]+ans[b[i]-i+n]);
	printf("%lld",maxx);
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n,b[200001],ans[400001],maxx;
inline int read()
{
	int r=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		r=(r<<3)+(r<<1)+(ch^48);
		ch=getchar();
	}
	return r*w;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		b[i]=read();
	for(int i=1;i<=n;i++)
		maxx=max(maxx,ans[b[i]-i+n]=b[i]+ans[b[i]-i+n]);
	printf("%d",maxx);
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
long long n,b[200001],ans[400001],maxx;
inline long long read()
{
	long long r=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		r=(r<<3)+(r<<1)+(ch^48);
		ch=getchar();
	}
	return r*w;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		b[i]=read();
	for(int i=1;i<=n;i++)
		maxx=max(maxx,ans[b[i]-i+n]=b[i]+ans[b[i]-i+n]);
	printf("%lld",maxx);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=a;i<b;i++)
#define eb emplace_back
#define mp make_pair
typedef long long int lli;
typedef unsigned long long int ulli;
const int INF=INT_MAX;
const lli MOD=10e8+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    std::cout.precision(30);
	int n;cin>>n;
	int b;cin>>b;
	if(n==1)	{cout<<b<<endl;return 0;}
	set<int> s;s.insert(b);
	map<int,lli> mp;mp.insert(pair<int,lli>(b,b));

	forr(i,1,n)
	{
		cin>>b;
		if(s.find(b-i)==s.end())	{s.insert(b-i);mp.insert(pair<int,lli>(b-i,b));}
		else 						{mp[b-i]+=b;}
	}

	lli maxi=INT_MIN;
	for(auto itr=mp.begin();itr!=mp.end();itr++)
	{
		maxi=max(maxi,itr->second);
	}
	cout<<maxi<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=a;i<b;i++)
#define eb emplace_back
#define mp make_pair
typedef long long int lli;
typedef unsigned long long int ulli;
const int INF=INT_MAX;
const lli MOD=10e8+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    std::cout.precision(30);
	int n;cin>>n;
	vector<int> b(n+1,0);cin>>b[1];
	vector<int> dp(n+1);dp[1]=b[1];
	if(n==1)	{cout<<b[1]<<endl;return 0;}
	forr(i,2,n+1)
	{
		cin>>b[i];
		int flag=1;
		for(int j=1;j<i;j++)
		{
			if(b[i]-b[j]==i-j)	{dp[i]=max(dp[i],dp[j]+b[i]);flag=0;}
		}
		if(flag)	dp[i]=b[i];
	}

	int maxi=INT_MIN;

	//~ forr(i,0,n+1)	cout<<dp[i]<<" ";
	//~ cout<<endl;
	forr(i,0,n+1)	maxi=max(maxi,dp[i]);
	cout<<maxi<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=a;i<b;i++)
#define eb emplace_back
#define mp make_pair
typedef long long int lli;
typedef unsigned long long int ulli;
const int INF=INT_MAX;
const lli MOD=10e8+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    std::cout.precision(30);
	int n;cin>>n;
	int b;cin>>b;
	if(n==1)	{cout<<b<<endl;return 0;}
	set<int> s;s.insert(b);
	map<int,int> mp;mp.insert(pair<int,int>(b,b));

	forr(i,1,n)
	{
		cin>>b;
		if(s.find(b-i)==s.end())	{s.insert(b-i);mp.insert(pair<int,int>(b-i,b));}
		else 						{mp[b-i]+=b;}
	}

	int maxi=INT_MIN;
	for(auto itr=mp.begin();itr!=mp.end();itr++)
	{
		maxi=max(maxi,itr->second);
	}
	cout<<maxi<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=a;i<b;i++)
#define eb emplace_back
#define mp make_pair
typedef long long int lli;
typedef unsigned long long int ulli;
const int INF=INT_MAX;
const lli MOD=10e8+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    std::cout.precision(30);
	int n;cin>>n;
	vector<int> b(n+1,0);cin>>b[1];
	vector<int> dp(n+1);dp[1]=b[1];
	if(n==1)	{cout<<b[1]<<endl;return 0;}
	forr(i,2,n+1)
	{
		cin>>b[i];
		int flag=1;
		for(int j=1;j<i;j++)
		{
			if(b[i]-b[j]==i-j)	{dp[i]=max(dp[i],dp[j]+b[i]);flag=0;}
		}
		if(flag)	dp[i]=b[i];
	}

	int maxi=INT_MIN;

	forr(i,0,n+1)	cout<<dp[i]<<" ";
	cout<<endl;
	forr(i,0,n+1)	maxi=max(maxi,dp[i]);
	cout<<maxi<<endl;

    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;

const int maxn = 200100;

int n;

struct E{
	ll b,c;
}a[maxn];

bool cmp(E x,E y){
	return x.c < y.c;
}

ll read(){ int f=1,s=0; char ch = getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; else ch = getchar(); } while(ch>='0' && ch<='9'){ s = s * 10 + ch - '0'; ch = getchar(); } return s * f; }

int main(){
	n = read();
	for(int i=1;i<=n;i++) a[i].b = read();

	for(int i=1;i<=n;i++) a[i].c = i - a[i].b;

	sort(a+1,a+1+n,cmp);

	ll ans = 0,tmp = a[1].b;
	a[0].c = -1; a[n+1].c = -1;
	for(int i=2;i<=n+1;i++){
		if(a[i].c != a[i-1].c) {
			ans = max(ans, tmp);
			tmp = a[i].b;
		}
		else tmp += a[i].b;
	}

	printf("%lld\n",ans);

	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;

const int maxn = 200100;

int n;

struct E{
	ll b,c;
}a[maxn];

bool cmp(E x,E y){
	return x.c < y.c;
}

ll read(){ int f=1,s=0; char ch = getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; else ch = getchar(); } while(ch>='0' && ch<='9'){ s = s * 10 + ch - '0'; ch = getchar(); } return s * f; }

int main(){
	n = read();
	for(int i=1;i<=n;i++) a[i].b = read();

	for(int i=1;i<=n;i++) a[i].c = i - a[i].b;

	sort(a+1,a+1+n,cmp);

	ll ans = 0,tmp = a[1].b;
	for(int i=2;i<=n+1;i++){
		if(a[i].c != a[i-1].c) {
			ans = max(ans, tmp);
			tmp = a[i].b;
		}
		else tmp += a[i].b;
	}

	printf("%lld\n",ans);

	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;

const int maxn = 200100;

int n;

struct E{
	ll b,c;
}a[maxn];

bool cmp(E x,E y){
	return x.c < y.c;
}

ll read(){ int f=1,s=0; char ch = getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; else ch = getchar(); } while(ch>='0' && ch<='9'){ s = s * 10 + ch - '0'; ch = getchar(); } return s * f; }

int main(){
	n = read();
	for(int i=1;i<=n;i++) a[i].b = read();

	for(int i=1;i<=n;i++) a[i].c = i - a[i].b;

	sort(a+1,a+1+n,cmp);

	ll ans = 0,tmp = a[1].b;

	for(int i=2;i<=n+1;i++){
		if(a[i].c != a[i-1].c) {
			ans = max(ans, tmp);
			tmp = a[i].b;
		}
		else tmp += a[i].b;
	}
	ans = max(ans,tmp);

	printf("%lld\n",ans);

	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;

const int maxn = 100100;

int n;

struct E{
	ll b,c;
}a[maxn];

bool cmp(E x,E y){
	return x.c < y.c;
}

ll read(){ int f=1,s=0; char ch = getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; else ch = getchar(); } while(ch>='0' && ch<='9'){ s = s * 10 + ch - '0'; ch = getchar(); } return s * f; }

int main(){
	n = read();
	for(int i=1;i<=n;i++) a[i].b = read();

	for(int i=1;i<=n;i++) a[i].c = i - a[i].b;

	sort(a+1,a+1+n,cmp);

	ll ans = 0,tmp = a[1].b;
	for(int i=2;i<=n+1;i++){
		if(a[i].c != a[i-1].c) {
			ans = max(ans, tmp);
			tmp = a[i].b;
		}
		else tmp += a[i].b;
	}

	printf("%lld\n",ans);

	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;

const int maxn = 100100;

int n;

struct E{
	int b,c;
}a[maxn];

bool cmp(E x,E y){
	return x.c < y.c;
}

ll read(){ int f=1,s=0; char ch = getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; else ch = getchar(); } while(ch>='0' && ch<='9'){ s = s * 10 + ch - '0'; ch = getchar(); } return s * f; }

int main(){
	n = read();
	for(int i=1;i<=n;i++) a[i].b = read();

	for(int i=1;i<=n;i++) a[i].c = i - a[i].b;

	sort(a+1,a+1+n,cmp);

	int ans = 0,tmp = a[1].b;
	for(int i=1;i<=n;i++){
		if(a[i].c != a[i-1].c) {
			ans = max(ans, tmp);
			tmp = a[i].b;
		}
		else tmp += a[i].b;
	}

	printf("%d\n",ans);

	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;

const int maxn = 100100;

int n;

struct E{
	int b,c;
}a[maxn];

bool cmp(E x,E y){
	return x.c < y.c;
}

ll read(){ int f=1,s=0; char ch = getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; else ch = getchar(); } while(ch>='0' && ch<='9'){ s = s * 10 + ch - '0'; ch = getchar(); } return s * f; }

int main(){
	n = read();
	for(int i=1;i<=n;i++) a[i].b = read();

	for(int i=1;i<=n;i++) a[i].c = i - a[i].b;

	sort(a+1,a+1+n,cmp);

	int ans = 0,tmp = a[1].b;
	for(int i=2;i<=n+1;i++){
		if(a[i].c != a[i-1].c) {
			ans = max(ans, tmp);
			tmp = a[i].b;
		}
		else tmp += a[i].b;
	}

	printf("%d\n",ans);

	return 0;
}


#include<iostream>
using namespace std;

int main() {

	int city;
	while (cin >> city) {
		//宣告
		int beauty[210000] = { 0 };
		bool took[210000] = { 0 };
		//輸入
		for (int i = 1; i <= city; i++) {
			cin >> beauty[i];
		}

		long long int sum = 0;
		int cnt = 0;
		for (int i = 1; i <= city && cnt < 3; i++) {
			if (took[i] != 1) {
				took[i] = 1;
				long long int tmp = beauty[i];
				for (int j = i + 1; j <= city; j++) {
					if (took[j] != 1 && j - i == beauty[j] - beauty[i]) {
						tmp += beauty[j];
						took[j] = 1;
					}
				}
				if (tmp > sum) {
					sum = tmp;
					cnt++
				}
			}
		}

		cout << sum << endl;
	}

	return 0;
}


#include<iostream>
using namespace std;

//宣告
int beauty[210000] = { 0 };

int main() {

	int city;
	cin >> city;

	//輸入
	for (int i = 1; i <= city; i++) {
		cin >> beauty[i];
	}

	long long int sum = 0;
	for (int i = 1; i <= city; i++) {
		long long int tmp = beauty[i];
		for (int j = i + 1; j <= city; j++) {
			if (j - i == beauty[j] - beauty[i]) {
				tmp += beauty[j];
			}
		}
		if (tmp > sum) {
			sum = tmp;
		}
	}

	cout << sum << endl;

	return 0;
}


#include<iostream>
using namespace std;

int main() {

	int city;
	while (cin >> city) {
		//宣告
		int beauty[110000] = { 0 };
		bool took[110000] = { 0 };
		//輸入
		for (int i = 1; i <= city; i++) {
			cin >> beauty[i];
		}

		int sum = 0;
		for (int i = 1; i <= city; i++) {
			if (took[i] != 1) {
				took[i] = 1;
				int tmp = beauty[i];
				for (int j = i + 1; j <= city; j++) {
					if (j - i == beauty[j] - beauty[i] && took[j] != 1) {
						tmp += beauty[j];
						took[j] = 1;
					}
				}
				if (tmp > sum) sum = tmp;
			}
		}

		cout << sum << endl;
	}

	return 0;
}


#include<iostream>
using namespace std;

//宣告
long long int k[500001] = { 0 };

int main() {

	int city;
	cin >> city;

	//輸入
	for (int i = 1; i <= city; i++) {
		int tmp = 0;
		cin >> tmp;
		if (tmp - i >= 0) {
			k[tmp - i] += tmp;
		}
	}
	int max = 0;
	for (int i = 0; i <= 400000; i++) {
		if (k[i] > max) max = k[i];
	}
	cout << max << endl;
	return 0;
}


#include<iostream>
using namespace std;

int main() {

	int city;
	while (cin >> city) {
		//宣告
		int beauty[210000] = { 0 };
		bool took[210000] = { 0 };
		//輸入
		for (int i = 1; i <= city; i++) {
			cin >> beauty[i];
		}

		long long int sum = 0;
		for (int i = 1; i <= city; i++) {
			if (took[i] != 1) {
				took[i] = 1;
				long long int tmp = beauty[i];
				for (int j = i + 1; j <= city; j++) {
					if (j - i == beauty[j] - beauty[i] && took[j] != 1) {
						tmp += beauty[j];
						took[j] = 1;
					}
				}
				if (tmp > sum) sum = tmp;
			}
		}

		cout << sum << endl;
	}

	return 0;
}