Problem:
Lottery Fun Time
The biggest fun of lottery is not in receiving the (usually a tiny amount of) prize money, but in dreaming of the big fortune you may possibly (that is, virtually never) receive.
You have a number of lottery tickets at hand, each with a six-digit number. All the numbers are different, of course. Tomorrow is the drawing day and the prizes are the following.
The first prize of $300,000$ yen is won by the ticket with exact match of all the six digits with the six-digit first prize winning number.
The second prizes of $4,000$ yen are won by all of the tickets with their last four digits matching the four-digit second prize winning number.
The third prizes of $500$ yen are won by all of the tickets with their last two digits matching any of the three two-digit third prize winning numbers.
The six digits on the lottery tickets and all of the winning numbers may start with zeros.
The last two digits of all the prize winning numbers are made different so that tickets winning the third prize cannot also win the first nor the second prizes. Note that this rule also made the last two digits of the first and the second prize winning numbers different.
To enjoy the climax of the lottery fun time, you decided to calculate the possible maximum amount you may win with your tickets. You have too many tickets to hand-calculate it, but it should also be your joy to write a program for making the calculation.
Input
The first line of the input has a positive integer $n$ ($n \leq {10}^{5}$), which is the number of tickets you have at hand. Each of the following $n$ lines has the six-digit number on one of your tickets. All the $n$ numbers are different from one another.
Output
Output in a line a single integer, which is the maximum possible total of winning prizes with the tickets you have.
Sample Input 1
7
034207
924837
372745
382947
274637
083907
294837
Sample Output 1
309500
Sample Input 2
10
012389
456789
234589
678989
890189
567889
123489
263784
901289
345689
Sample Output 2
304500
For the first sample, the following combination of prize winners allows the maximum total amount of $309500$ yen.
The first prize winner of $382947$ makes one ticket with that number win $300000$ yen.
The second prize winner of $4837$ makes two tickets, $924837$ and $294837$, win $4000$ yen each.
The third prize winners $07$ and $45$ make three tickets, $034207$, $083907$, and $372745$, win $500$ yen each. $37$ cannot be a third prize winner, as the second prize winner, $4837$, has the final two digits of $37$. The ticket $274637$, thus, wins nothing. You have no more tickets to win whatever the remaining third prize winner may be.
For the second sample, nine out of the ten tickets have the same last two digits, $89$, and thus the third prize winner of $89$ allows nine third prizes, totaling $4500$ yen. This is more than the second prize of $4000$ yen possibly won by one of these nine tickets. The only remaining ticket $263784$ should, of course, win the first prize.

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
const ll INF = 1LL << 60;

int main(){
    ll n;
    cin >> n;
    vector<string> s(n);
    unordered_map<string, ll> two_cnt, four_cnt;
    rep(i, n){
        cin >> s[i];
        string last_two = s[i].substr(4, 2);
        string last_four = s[i].substr(2, 4);
        two_cnt[last_two]++;
        four_cnt[last_four]++;
    }

    vector<pair<ll, string>> count;
    for(auto [last_two, cnt] : two_cnt){
        count.push_back({cnt, last_two});
    }
    sort(count.rbegin(), count.rend());

    vector<pair<ll, string>> top5;
    rep(i, min((int)count.size(), 5)){
        top5.push_back(count[i]);
    }
    while(top5.size() <= 5){
        top5.push_back({0, "-1"});
    }

    vector<pair<ll, string>> count2;
    for(auto [last_four, cnt] : four_cnt){
        string last_two = last_four.substr(2, 2);
        count2.push_back({cnt, last_two});
    }
    sort(count2.rbegin(), count2.rend());

    vector<ll> distribution = {1, 2, 3, 3, 3};
    ll ans = 0;
    do{
        ll temp = 0;
        set<string> se;
        rep(i, 5){
            if(distribution[i] == 1 || distribution[i] == 3)se.insert(top5[i].second);
        }

        rep(i, 5){
            if(distribution[i] == 1){
                if(top5[i].first != 0 && top5[i].second != "-1")temp += 300000;
            }else if(distribution[i] == 2){
                if(top5[i].first == 0)continue;
                if(top5[i].first != 0 && top5[i].second != "-1"){
                    rep(j, count2.size()){
                        if(!se.count(count2[j].second)){
                            temp += 4000 * count2[j].first;
                            break;
                        }
                    }

                }
            }else if(distribution[i] == 3){
                if(top5[i].first == 0 || top5[i].second == "-1")continue;
                temp += 500 * top5[i].first;
            }
        }
        ans = max(ans, temp);

    }while(next_permutation(distribution.begin(), distribution.end()));

    cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 7536
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

bool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, const auto& b) { return a < b ? a = b, 1 : 0; }

const ll INF = 1e18;
ll mod = 998244353;

ifstream in;
ofstream out;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if (argc > 2) {
        in.open(argv[1]);
        cin.rdbuf(in.rdbuf());
        out.open(argv[2]);
        cout.rdbuf(out.rdbuf());
    }

    ll n;
    cin >> n;
    vector<string> s(n);
    for (auto& x : s) cin >> x;

    vector<vector<ll>> v4(100, vector<ll>(100, 0));
    vector<ll> v2(100, 0);
    for (auto x : s) {
        v4[stoll(x.substr(4, 2))][stoll(x.substr(2, 2))]++;
        v2[stoll(x.substr(4, 2))]++;
    }

    for (auto& x : v4) {
        sort(x.rbegin(), x.rend());
    }

    ll ans = 300000;
    for (int i = 0; i < 100; i++) {
        ll sum = accumulate(v4[i].begin(), v4[i].end(), 0LL);
        for (int j = 0; j < 100; j++) {
            for (int k = j + 1; k < 100; k++) {
                for (int l = k + 1; l < 100; l++) {
                    if (i == j || i == k || i == l)
                        continue;
                    ll total = v4[i][0] + v2[j] + v2[k] + v2[l];
                    if (sum + v2[j] + v2[k] + v2[l] == n) {
                        chmax(ans, v4[i][0] * 4000 + (total - v4[i][0]) * 500);
                        if (v4[i][0])
                            chmax(ans, 300000 + (total - v4[i][0]) * 500);
                        if (v2[j])
                            chmax(ans, 300000 + v4[i][0] * 4000 + (total - v4[i][0] - v2[j]) * 500);
                        if (v2[k])
                            chmax(ans, 300000 + v4[i][0] * 4000 + (total - v4[i][0] - v2[k]) * 500);
                        if (v2[l])
                            chmax(ans, 300000 + v4[i][0] * 4000 + (total - v4[i][0] - v2[l]) * 500);
                    } else {
                        chmax(ans, 300000 + v4[i][0] * 4000 + (total - v4[i][0]) * 500);
                    }
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 6556
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    
    map<string,int> MA,MB;
    
    ll ans=0;
    
    for(int i=0;i<N;i++){
        string S;cin>>S;
        MA[S.substr(2)]++;
        MB[S.substr(4)]++;
    }
    
    vector<array<ll,3>> X(100);
    
    for(int i=0;i<100;i++){
        string A=to_string(i);
        while(si(A)<2) A="0"+A;
        
        if(MB.count(A)){
            X[i][0]=300000;
            for(int j=0;j<100;j++){
                int x=j*100+i;
                string B=to_string(x);
                while(si(B)<4) B="0"+B;
                if(MA.count(B)) chmax(X[i][1],4000LL*MA[B]);
            }
            X[i][2]=500*MB[A];
        }
    }
    
    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            if(i==j) continue;
            vl T;
            for(int k=0;k<100;k++){
                if(i==k||j==k) continue;
                T.pb(X[k][2]);
            }
            sort(all(T));
            reverse(all(T));
            chmax(ans,X[i][0]+X[j][1]+T[0]+T[1]+T[2]);
        }
    }
    
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 4276
final_rank: 9

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

using ll = long long;

bool chmin(auto &a, auto b) { return a > b ? a = b, true : false; }
bool chmax(auto &a, auto b) { return a < b ? a = b, true : false; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<ll> a(100), b(10000), c(1000000);
    while(N--) {
        int x;
        cin >> x;
        a[x % 100]++;
        b[x % 10000]++;
        c[x % 1000000]++;
    }
    vector<ll> B(100), C(100);
    for(int i = 0; i < 10000; i++) {
        chmax(B[i % 100], b[i]);
    }
    for(int i = 0; i < 1000000; i++) {
        chmax(C[i % 100], c[i]);
    }
    vector<pair<ll, int>> P(100), Q(100);
    for(int i = 0; i < 100; i++) {
        P[i] = make_pair(B[i], i);
        Q[i] = make_pair(C[i], i);
    }
    sort(P.rbegin(), P.rend());
    sort(Q.rbegin(), Q.rend());
    P.erase(P.begin() + 5, P.end());
    Q.erase(Q.begin() + 5, Q.end());
    ll ans = 0;
    vector<int> v(100);
    iota(v.begin(), v.end(), 0);
    for(int x : v) for(int y : v) for(int z : v) {
        if(x == y || y == z || z == x) continue;
        for(auto [pc, p] : P) for(auto [qc, q] : Q) {
            if(p == q) continue;
            if(p == x || p == y || p == z) continue;
            if(q == x || q == y || q == z) continue;
            chmax(ans, 500 * (a[x] + a[y] + a[z]) + 4000 * pc + 300000 * qc);
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 11324
final_rank: 11

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;cin >> n;
  vi a(n);cin >> a;
  auto f = [](vi a,int mod){
    int n = sz(a);
    rep(i,0,n)a[i] %= mod;
    sort(ALL(a));
    vector<pll> v;
    rep(i,0,n){
      if(v.empty())v.emplace_back(1,a[i]);
      else if(v.back().second == a[i])v.back().first++;
      else v.emplace_back(1,a[i]);
    }
    sort(ALL(v),greater<pll>());
    vector<pll> res; // count, val
    set<int> st;
    rep(i,0,sz(v)){
      if(sz(res) >= 5)break;
      auto [k,l] = v[i];
      if(st.count(l%100))continue;
      st.insert(l%100);
      res.emplace_back(k,l%100);
    }
    return res;
  };
  vector<vector<pll>> v(3);
  v[0] = f(a,1000000);
  v[1] = f(a,10000);
  v[2] = f(a,100);
  rep(i,0,3)v[i].emplace_back(0,MOD+i);
  rep(i,0,3)v[2].emplace_back(0,-1-i);
  ll res = 0;
  rep(i,0,sz(v[0]))rep(j,0,sz(v[1]))rep(k,0,sz(v[2]))rep(k2,k,sz(v[2]))rep(k3,k2,sz(v[2])){
    set<int> st;
    st.insert(v[0][i].second);st.insert(v[1][j].second);st.insert(v[2][k].second);st.insert(v[2][k2].second);st.insert(v[2][k3].second);
    if(sz(st) == 5){
      chmax(res,v[0][i].first*300000 + v[1][j].first*4000 + (v[2][k].first+v[2][k2].first+v[2][k3].first)*500);
    }
  }
  cout << res << endl;
  

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 6604
final_rank: 6

code_snippet: //#define Plus_Cat ""
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define Fi first
#define Se second
#define ll long long
#define Pli pair<ll,int>
#define RCL(a,b,c,d) memset(a,b,sizeof(c)*(d))
#define FOR(i,a,b) for(int i(a);i<=(int)(b);++i)
#define DOR(i,a,b) for(int i(a);i>=(int)(b);--i)
#define tomax(a,...) ((a)=max({(a),__VA_ARGS__}))
#define tomin(a,...) ((a)=min({(a),__VA_ARGS__}))
#define EDGE(g,i,x,y) for(int i=(g).h[(x)],y=(g)[(i)].v;~i;y=(g)[(i=(g)[i].nxt)>0?i:0].v)
#define main Main();signed main(){ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);return Main();}signed Main
using namespace std;
constexpr int N(1e5+10),M(1e6+10),A1(999999),A2(9999),A3(99);

namespace IOEcat {
#define isD(ch) ('0'<=(ch)&&(ch)<='9')
#define DE(...) E(#__VA_ARGS__,__VA_ARGS__)
	struct Icat {

		inline char getc() {
			return getchar();
		}

		template<class T>void operator ()(T &x) {
			static bool sign(0);
			static char ch(0);
			x=0,sign=0;
			while(ch=getc(),!isD(ch))if(ch=='-')sign=1;
			do x=(x<<1)+(x<<3)+(ch^48);
			while(ch=getc(),isD(ch));
			if(sign)x=-x;
		}

		template<class T,class...Types>void operator ()(T &a,Types &...args) {
			return (*this)(a),(*this)(args...);
		}

	} I;
	struct Ocat {

		inline void putc(const char c) {
			putchar(c);
		}

		template<class T>void operator ()(T x,const char lst='\n') {
			static int top(0);
			static char st[50];
			if(x<0)putc('-'),x=-x;
			do st[++top]=x%10^48,x/=10;
			while(x);
			while(top)putc(st[top--]);
			putc(lst);
		}

		template<class T,class...Types>void operator ()(const T a,const char lst='\n',const Types ...args) {
			return (*this)(a,lst),(*this)(args...);
		}

	} O;
	struct Ecat {

		template<class T>void operator ()(const char *fmt,const T a) {
			cerr<<fmt<<":"<<a<<".\n";
		}

		template<class T,class...Types>void operator ()(const char *fmt,const T a,const Types ...args) {
			while(*fmt^',')cerr<<*fmt++;
			return cerr<<':'<<a<<", ",(*this)(++fmt,args...);
		}
	} E;

} using namespace IOEcat;

char s[7];
int n;
ll ans;
struct Node {
	int cnt,pos;
	friend bool operator <(Node a,Node b) { return a.cnt^b.cnt?a.cnt>b.cnt:a.pos<b.pos; }
} c1[M],c2[M],c3[M];
struct node {
	int a1,a2,a3;

	void Input() {
		scanf("%s",s),a1=0;
		FOR(i,0,5)a1=a1*10+(s[i]^'0');
		a2=a1%10000,a3=a1%100,++c1[a1].cnt,++c2[a2].cnt,++c3[a3].cnt;
//		DE(a1,a2,a3);
	}
} a[N];

signed main() {
#ifdef Plus_Cat
	freopen(Plus_Cat ".in","r",stdin),freopen(Plus_Cat ".out","w",stdout);
#endif
	I(n);
	FOR(i,0,A1)c1[i].pos=i;
	FOR(i,0,A2)c2[i].pos=i;
	FOR(i,0,A3)c3[i].pos=i;
	FOR(i,1,n)a[i].Input();
	sort(c1,c1+A1+1),sort(c2,c2+A2+1),sort(c3,c3+A3+1);
	if(n)ans=300000;//1
	tomax(ans,(ll)4000*c2[0].cnt);//2
	tomax(ans,(ll)500*(c3[0].cnt+c3[1].cnt+c3[2].cnt));//3
	FOR(i,0,A1)if(c1[i].cnt)FOR(j,0,5)if(c1[i].pos%100!=c2[j].pos%100)tomax(ans,300000+(ll)4000*c2[j].cnt);
	//12
	FOR(i,0,A1)if(c1[i].cnt) {
		vector<int> Cnt;
		FOR(k,0,5)if(c1[i].pos%100!=c3[k].pos)Cnt.push_back(c3[k].cnt);
		sort(Cnt.begin(),Cnt.end(),greater<>());
		tomax(ans,300000+(ll)500*(Cnt[0]+Cnt[1]+Cnt[2]));
	}//13
	FOR(j,0,5) {
		vector<int> Cnt;
		FOR(k,0,5)if(c2[j].pos%100!=c3[k].pos)Cnt.push_back(c3[k].cnt);
		sort(Cnt.begin(),Cnt.end(),greater<>());
		tomax(ans,(ll)4000*c2[j].cnt+(ll)500*(Cnt[0]+Cnt[1]+Cnt[2]));
	}//23
	FOR(i,0,A1)if(c1[i].cnt)FOR(j,0,5)if(c1[i].pos%100!=c2[j].pos%100) {
		vector<int> Cnt;
		FOR(k,0,5)if(c1[i].pos%100!=c3[k].pos&&c2[j].pos%100!=c3[k].pos)Cnt.push_back(c3[k].cnt);
		sort(Cnt.begin(),Cnt.end(),greater<>());
//		if((ll)4000*c2[j].cnt+(ll)500*(Cnt[0]+Cnt[1]+Cnt[2])==10000) {
//			DE(i,c1[i].pos,j,c2[j].pos);
//			DE(c2[j].cnt,Cnt[0],Cnt[1],Cnt[2]);
//		}
		tomax(ans,300000+(ll)4000*c2[j].cnt+(ll)500*(Cnt[0]+Cnt[1]+Cnt[2]));
	}//123
	O(ans,'\n');
	return 0;
}
accuracy: 0.2631578947368421
time_ms: 50
memory_kb: 14072
final_rank: 16

code_snippet: #include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <tuple>
#include <ranges>
namespace ranges = std::ranges;
namespace views = std::views;
// #include "Src/Number/IntegerDivision.hpp"
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// #include "Src/Algebra/Group/AdditiveGroup.hpp"
// #include "Src/DataStructure/FenwickTree/FenwickTree.hpp"
// #include "Src/DataStructure/SegmentTree/SegmentTree.hpp"
// using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
int N;
std::string S[100010];
int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cin >> N;
    for (auto& s : S | views::take(N)) {
        std::cin >> s;
        ranges::reverse(s);
    }
    ranges::sort(S | views::take(N));
    std::vector<int> next2(N), next4(N);
    for (int i = 0, j = 0 ; i < N ; i = j) {
        while (j < N and S[i].substr(0, 2) == S[j].substr(0, 2)) j++;
        for (int k = i ; k < j ; k++) next2[k] = j;
    }
    for (int i = 0, j = 0 ; i < N ; i = j) {
        while (j < N and S[i].substr(0, 4) == S[j].substr(0, 4)) j++;
        for (int k = i ; k < j ; k++) next4[k] = j;
    }
    std::vector dp(N + 1, std::vector(4, std::vector<long long>(4, -1LL)));
    dp[0][0][0] = 0;
    for (int i = 0 ; i < N ; i++) for (int j = 0 ; j < 4 ; j++) for (int k = 0 ; k < 4 ; k++) if (dp[i][j][k] != -1) {
        dp[i + 1][j][k] = std::max(dp[i + 1][j][k], dp[i][j][k]);
        if (!(j & 1)) dp[next2[i]][j | 1][k] = std::max(dp[next2[i]][j | 1][k], dp[i][j][k] + 300000);
        if (!(j & 2)) dp[next2[i]][j | 2][k] = std::max(dp[next2[i]][j | 2][k], dp[i][j][k] + (long long)(next4[i] - i) * 4000);
        if (k + 1 < 4) dp[next2[i]][j][k + 1] = std::max(dp[next2[i]][j][k + 1], dp[i][j][k] + (long long)(next2[i] - i) * 500);
    }
    long long ans = 0;
    for (int i = 0 ; i < 4 ; i++) for (int j = 0 ; j < 4 ; j++) ans = std::max(ans, dp[N][i][j]);
    std::cout << ans << '\n';
}
accuracy: 1
time_ms: 30
memory_kb: 39288
final_rank: 13

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define rep(i, a, b) for (ll i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  ll n;
  cin >> n;
  vll As(n);
  map<ll, ll> cnt4;
  map<ll, ll> cnt2;
  rep(i, 0ll, n) {
    cin >> As[i];
    cnt4[As[i] % 10000]++;
    cnt2[As[i] % 100]++;
  }

  vector<pair<ll, ll>> _last2s;
  for (auto [key, val] : cnt2) {
    _last2s.emplace_back(val, key);
  }
  sort(rbegin(_last2s), rend(_last2s));

  ll ans = 0;
  rep(secondPrize, 0, 10000) {
    ll secondPrizeLast2 = secondPrize % 100;
    vector<ll> last2s;
    rep(k, 0, 10) {
      if (sz(_last2s) > k) {
        if (_last2s[k].second == secondPrizeLast2) continue;
        last2s.push_back(_last2s[k].first);
        if (last2s.back() == 0) last2s.pop_back();
      }
    }
    sort(rbegin(last2s), rend(last2s));

    // no 1st prize
    {
      ll now = 4000ll * cnt4[secondPrize];
      if (sz(last2s) > 0) now += 500ll * last2s[0];
      if (sz(last2s) > 1) now += 500ll * last2s[1];
      if (sz(last2s) > 2) now += 500ll * last2s[2];
      ans = max(ans, now);
    }
    // yes 1st prize
    {
      ll now = 4000ll * cnt4[secondPrize];
      if (!last2s.empty()) {
        last2s.pop_back();
        now += 300'000ll;
      }
      if (sz(last2s) > 0) now += 500ll * last2s[0];
      if (sz(last2s) > 1) now += 500ll * last2s[1];
      if (sz(last2s) > 2) now += 500ll * last2s[2];
      if (now == 310000) {
        cerr << secondPrize << endl;
        cerr << sz(last2s) << endl;
        cerr << last2s[0] << endl;
        cerr << last2s[1] << endl;
        cerr << last2s[2] << endl;
      }
      ans = max(ans, now);
    }
  }

  cout << ans << endl;

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4404
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define ov4(a, b, c, d, name, ...) name
#define rep3(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep2(i, a, b) rep3(i, a, b, 1)
#define rep1(i, n) rep2(i, 0, n)
#define rep0(n) rep1(aaaaa, n)
#define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
#define per(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define fore(e, v) for(auto&& e : v)
#define all(a) begin(a), end(a)
#define si(a) (int)(size(a))
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define eb emplace_back

template<typename T, typename S> bool chmin(T& a, const S& b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S> bool chmax(T& a, const S& b) { return a < b ? a = b, 1 : 0; }

const int INF = 1e9 + 100;
const ll INFL = 3e18 + 100;

#define i128 __int128_t

struct _ {
    _() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); }
} __;

using vb = vector<bool>;
using vs = vector<string>;
struct S2{
    ll M;
    vector<pair<ll, string>> best;
    S2(const vs& S) {
        map<string, ll> cnt;
        ll N = S.size();
        for (auto _s : S) {
            string s = _s.substr(4, 2);
            cnt[s] += 500;
        }
        for (auto [s, val] : cnt) {
            best.eb(val, s);
        }
        sort(all(best));
        reverse(all(best));
        if (best.size() > 5)
            best.resize(5);
        M = best.size();
    }
    ll solve(string a, string b) {
        vector<bool> is_ok(M);
        rep(i, M) is_ok[i] = best[i].second != a && best[i].second != b;
        ll ret = 0, cnt = 0;
        rep(i, M) {
            if (is_ok[i] && cnt < 3) {
                ret += best[i].first;
                cnt++;
            }
        }
        return ret;
    }
};

int main() {
    ll N;
    cin >> N;
    vs S(N);
    rep(i, N) cin >> S[i];
    S2 S2_ins(S);
    set<string> st;
    map<string, ll> mx4_mp;
    rep(i, N) {
        string s4 = S[i].substr(2, 4);
        string s2 = S[i].substr(4, 2);
        st.insert(s2);
        mx4_mp[s4] += 4000;
    }
    map<string, ll> mx2_mp;
    for (auto [s4, val] : mx4_mp) {
        string s2 = s4.substr(2, 2);
        chmax(mx2_mp[s2], val);
    }

    // cout << "mx4_mp\n";
    // for (auto [s, val] : mx4_mp) {
    //     cout << s << " " << val << "\n";
    // }

    // cout << "mx2_mp\n";
    // for (auto [s, val] : mx2_mp) {
    //     cout << s << " " << val << "\n";
    // }

    ll ans = 0;
    rep(sa_int, 100) {
        string sa = to_string(sa_int);
        rep(sb_int, 100) {
            string sb = to_string(sb_int);
            if (sa == sb) continue;
            ll tmp = mx2_mp[sb];
            if (st.count(sa)) tmp += 300000;
            tmp += S2_ins.solve(sa, sb);
            chmax(ans, tmp);
            // if (chmax(ans, tmp) || (sa == "47" && sb == "37"))
                // cout << sa << " " << sb << ": " << mx2_mp[sa] << " " << S2_ins.solve(sa, sb) << " " << tmp << "\n";
        }
    }
    cout << ans << "\n";
}
accuracy: 1
time_ms: 20
memory_kb: 7324
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0)->sync_with_stdio(0);
  int n;cin>>n;
  vector<int>a(n);
  vector<int>cnt4(10000),cnt2(100);
  for(int i=0;i<n;++i){
    cin>>a[i];
    ++cnt4[a[i]%10000];
    ++cnt2[a[i]%100];
  }
  int ans=0;
  for(int i=0;i<101;++i)for(int j=0;j<101;++j){
    if(i<100&&i==j)continue;
    int sum=0;
    if(i<100&&cnt2[i])sum=max(sum,300000);
    if(j<100){
      int mx=0;
      for(int k=j;k<10000;k+=100){
        mx=max(mx,cnt4[k]);
      }
      sum=max(sum,4000*mx);
    }
    if(i<100&&j<100){
      for(int k=i;k<10000;k+=100){
        for(int l=j;l<10000;l+=100){
          if(k==l)continue;
          if(1<=cnt4[k])sum=max(sum,300000+4000*cnt4[l]);
        }
      }
    }
    priority_queue<int>que;
    for(int k=0;k<100;++k){
      if(k==i||k==j)continue;
      que.push(cnt2[k]);
    }
    for(int k=0;k<3&&!que.empty();++k){
      sum+=500*que.top();
      que.pop();
    }
    /*
    if(ans<sum){
      cout<<i<<','<<j<<endl;
    }
    */
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
}
accuracy: 1
time_ms: 120
memory_kb: 3520
final_rank: 12

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

using ll = long long;
#define foa(s, v)    for(auto& s : v)
#define rng(i, l, r) for(int i = int(l); i < int(r); i++)
#define rep(i, n)    rng(i, 0, n)
#define sz(x)        int(x.size())
#define all(x)       begin(x), end(x)

int n;

void solve() {
	map<int, map<int, int>> mp;
	rep(i, n) {
		int x;
		cin >> x;
		mp[x % 100][x % 10000]++;
	}
	vector<pair<int, int>> ab;
	for(auto [key, val] : mp) {
		int mx = 0;
		int sum = 0;
		for(auto [k2, v2] : val) {
			mx = max(mx, v2);
			sum += v2;
		}
		ab.emplace_back(mx, sum);
	}
	ll ans = 0;
	if(ab.size() >= 5) {
		multiset<int> st;
		for(auto [u, v] : ab) st.insert(v);
		for(auto [u, v] : ab) {
			st.erase(st.find(v));
			ll tmp = 0;
			tmp += 4000ll * u;
			tmp += 500ll * (*st.rbegin() + *next(st.rbegin()) + *next(next(st.rbegin())));
			tmp += 300000;
			ans = max(ans, tmp);
			st.insert(v);
		}
	} else {
		vector<int> p;
		auto dfs = [&](auto dfs) -> void {
			if(p.size() == ab.size()) {
				if(count(all(p), 0) > 1) return;
				if(count(all(p), 1) > 1) return;
				if(count(all(p), 1) > 3) return;
				ll tmp = 0;
				rep(j, p.size()) {
					if(p[j] == 0)
						tmp += 300000;
					else if(p[j] == 1)
						tmp += ab[j].first * 4000ll;
					else
						tmp += ab[j].second * 500ll;
				}
				ans = max(ans, tmp);
			} else {
				rep(j, 3) {
					p.push_back(j);
					dfs(dfs);
					p.pop_back();
				}
			}
		};
		dfs(dfs);
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	while(cin >> n) solve();
}
accuracy: 1
time_ms: 10
memory_kb: 3712
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(a) begin(a),end(a)

int main(){
	int n;
	cin >> n;
	vector<int> cnt1(100);
	vector<int> cnt2(10000);
	string s;
	for(int i = 0;i < n;i++){
		cin >> s;
		cnt1[stoi(s.substr(4,2))]++;
		cnt2[stoi(s.substr(2,4))]++;
	}
	ll ans = 0;
	vector<pair<int,int>> vp1(100);

	for(int i = 0;i < 100;i++) vp1[i] = {cnt1[i],i};
	sort(ALL(vp1));
	reverse(ALL(vp1));
	for(int i = 0;i < 10000;i++){
		vector<int> v;
		v.reserve(99);
		for(int j = 0;j < 100;j++)if(vp1[j].second != i%100){
			v.push_back(vp1[j].second);
		}
		if(cnt1[v[0]] + cnt1[v[1]] + cnt1[v[2]] + cnt1[i%100] == n){
			ans = max(ans,(ll)(cnt1[v[0]] + cnt1[v[1]] + cnt1[v[2]])*500LL + cnt2[i]*4000LL);
			if(cnt1[v[2]] != 0) ans = max(ans,(ll)(cnt1[v[0]] + cnt1[v[1]] + cnt1[v[3]])*500LL + cnt2[i]*4000LL + 300000);
			else if(cnt1[v[1]] != 0) ans = max(ans,(ll)(cnt1[v[0]] + cnt1[v[2]] + cnt1[v[3]])*500LL + cnt2[i]*4000LL + 300000);
			else if(cnt1[v[0]] != 0) ans = max(ans,(ll)(cnt1[v[1]] + cnt1[v[2]] + cnt1[v[3]])*500LL + cnt2[i]*4000LL + 300000);
		}else{
			ans = max(ans,(ll)(cnt1[v[0]] + cnt1[v[1]] + cnt1[v[2]])*500LL + cnt2[i]*4000LL + 300000);
		}

	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3484
final_rank: 1

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,0,N) {
        string S;
        cin >> S;
        A[i] = stoi(S);
    }
    vector<ll> B(100,0), C(10000,0);
    rep(i,0,N) B[A[i]%100]++, C[A[i]%10000]++;
    vector<pair<int,ll>> P;
    rep(i,0,100) P.push_back({B[i],i});
    sort(ALL(P));
    reverse(ALL(P));
    P.resize(5);
    ll ANS = 0;
    rep(i1,0,5) {
        rep(i2,0,5) {
            rep(i3,0,5) {
                if (i1==i2 || i1==i3 || i2==i3) continue;
                rep(j,0,10000) {
                    if (j % 100 == P[i1].second || j % 100 == P[i2].second || j % 100 == P[i3].second) continue;
                    if (P[i1].first + P[i2].first + P[i3].first + B[j%100] < N) chmax(ANS, (P[i1].first + P[i2].first + P[i3].first)*500 + C[j]*4000 + 300000);
                    else chmax(ANS, (P[i1].first + P[i2].first + P[i3].first)*500 + C[j]*4000);
                }
            }
        }
    }
    cout << ANS << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3568
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }

    vector<int> cnt2(100), cnt4(10000);
    for (int i = 0; i < N; i++) {
        int T = stoi(S[i]);
        cnt2[T % 100]++;
        cnt4[T % 10000]++;
    }

    vector<pair<int, int>> two(100);
    for (int i = 0; i < 100; i++) {
        two[i] = {cnt2[i], i};
    }
    sort(two.rbegin(), two.rend());

    ll ans = 0;
    for (int i = 0; i < 10000; i++) {
        for (int j = 0; j < 100; j++) {
            if (i % 100 == j) {
                continue;
            }

            ll sum = 0;

            {
                int cnt = 0;
                int idx = 0;
                while (cnt < 3 && idx < 100) {
                    auto [v, k] = two[idx++];

                    if (k == j || k == i % 100) {
                        continue;
                    }

                    cnt++;
                    sum += v * 500;
                }
            }

            sum += cnt4[i] * 4000;
            if (cnt2[j] > 0) {
                sum += 300'000;
            }

            ans = max(ans, sum);
        }
    }

    cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 6176
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }

    vector<int> cnt2(100), cnt4(10000);
    for (int i = 0; i < N; i++) {
        int T = stoi(S[i]);
        cnt2[T % 100]++;
        cnt4[T % 10000]++;
    }

    ll ans = 300000;
    for (int i = 0; i < 10000; i++) {
        for (int j = 0; j < 100; j++) {
            if (i % 100 == j) {
                continue;
            }
            for (int k = j + 1; k < 100; k++) {
                if (i % 100 == k) {
                    continue;
                }

                ll res = 0;
                if (cnt2[i % 100] + cnt2[j] + cnt2[k] < N) {
                    res = 300000;
                }
                res += cnt4[i] * 4000;
                res += cnt2[j] * 500;
                res += cnt2[k] * 500;
                if (res > 300000) {
                }

                ans = max(ans, res);
            }
        }
    }

    cout << ans << endl;
}
accuracy: 0.21052631578947367
time_ms: 70
memory_kb: 3972
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }

    vector<int> cnt2(100), cnt4(10000);
    for (int i = 0; i < N; i++) {
        int T = stoi(S[i]);
        cnt2[T % 100]++;
        cnt4[T % 10000]++;
    }

    ll ans = 300000;
    for (int i = 0; i < 10000; i++) {
        for (int j = 0; j < 100; j++) {
            if (i % 100 == j) {
                continue;
            }
            for (int k = j + 1; k < 100; k++) {
                if (i % 100 == k) {
                    continue;
                }

                ll res = 0;
                if (cnt4[i] + cnt2[j] + cnt2[k] < N) {
                    res = 300000;
                }
                res += cnt4[i] * 4000;
                res += cnt2[j] * 500;
                res += cnt2[k] * 500;

                ans = max(ans, res);
            }
        }
    }

    cout << ans << endl;
}
accuracy: 0.05263157894736842
time_ms: 60
memory_kb: 3424
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }

    vector<int> cnt2(100), cnt4(10000);
    for (int i = 0; i < N; i++) {
        int T = stoi(S[i]);
        cnt2[T % 100]++;
        cnt4[T % 10000]++;
    }

    ll ans = 0;
    for (int i = 0; i < 10000; i++) {
        for (int j = 0; j < 100; j++) {
            if (i % 100 == j) {
                continue;
            }
            for (int k = j + 1; k < 100; k++) {
                if (i % 100 == k) {
                    continue;
                }

                ll res = 0;
                if (cnt4[i] + cnt2[j] + cnt2[k] < N) {
                    res = 300000;
                }
                res += cnt4[i] * 4000;
                res += cnt2[j] * 500;
                res += cnt2[k] * 500;

                ans = max(ans, res);
            }
        }
    }

    cout << ans << endl;
}
accuracy: 0.05263157894736842
time_ms: 60
memory_kb: 3488
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }

    vector<int> cnt2(100), cnt4(10000);
    for (int i = 0; i < N; i++) {
        int T = stoi(S[i]);
        cnt2[T % 100]++;
        cnt4[T % 10000]++;
    }

    ll ans = 0;
    for (int i = 0; i < 10000; i++) {
        for (int j = 0; j < 100; j++) {
            if (i % 100 == j) {
                continue;
            }
            for (int k = j + 1; k < 100; k++) {
                if (i % 100 == k) {
                    continue;
                }

                ll res = 0;
                if (cnt4[i] + cnt2[j] + cnt2[k] != N) {
                    res = 300000;
                }
                res += cnt4[i] * 4000;
                res += cnt2[j] * 500;
                res += cnt2[k] * 500;

                ans = max(ans, res);
            }
        }
    }

    cout << ans << endl;
}
accuracy: 0.05263157894736842
time_ms: 60
memory_kb: 3388
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
template<int mod>istream &operator>>(istream &is,static_modint<mod> &a){long long b;is>>b;a=b;return is;}
istream &operator>>(istream &is,modint &a){long long b;cin>>b;a=b;return is;}
#endif
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) static_cast<void>(0)
#define debugg(...) static_cast<void>(0)
#define esper(...) static_cast<void>(0)
template<typename T1,typename T2>ostream &operator<<(ostream &os,const pair<T1,T2>&p){os<<p.first<<' '<<p.second;return os;}
#endif
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>istream &operator>>(istream &is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T>istream &operator>>(istream &is,vector<T> &a){for(auto &i:a)is>>i;return is;}
template<typename T1,typename T2>void operator++(pair<T1,T2>&a,int n){a.first++,a.second++;}
template<typename T1,typename T2>void operator--(pair<T1,T2>&a,int n){a.first--,a.second--;}
template<typename T>void operator++(vector<T>&a,int n){for(auto &i:a)i++;}
template<typename T>void operator--(vector<T>&a,int n){for(auto &i:a)i--;}
#define reps(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) reps(i,0,n)
#define all(x) x.begin(),x.end()
#define pcnt(x) __builtin_popcountll(x)
#define fin(x) return cout<<x<<'\n',static_cast<void>(0)
ll myceil(ll a,ll b){return (a+b-1)/b;}
template<typename T,size_t n,size_t id=0>
auto vec(const int (&d)[n],const T &init=T()){
  if constexpr (id<n)return vector(d[id],vec<T,n,id+1>(d,init));
  else return init;
}
void SOLVE();
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(16);
  #ifdef LOCAL
  clock_t start=clock();
  #endif
  int testcase=1;
  //cin>>testcase;
  for(int i=0;i<testcase;i++){
    SOLVE();
  }
  #ifdef LOCAL
  cerr<<"time:";
  cerr<<(clock()-start)/1000;
  cerr<<"ms\n";
  #endif
}
void SOLVE(){
  int n;
  cin>>n;
  vector<string>s(n);
  cin>>s;
  bool al=true;
  rep(i,n-1)al&=stoi(s[i].substr(4))==stoi(s[i+1].substr(4));
  if(al){
    int ans=300000;
    vector<int>cnt(10000,0);
    rep(i,n)cnt[stoi(s[i].substr(2))]++;
    chmax(ans,*max_element(all(cnt))*4000);
    chmax(ans,n*500);
    fin(ans);
  }
  sort(all(s),[](string a,string b){return stoi(a.substr(2))<stoi(b.substr(2));});
  vector<vector<int>>cnt(10000,vector<int>(100,0));
  rep(i,n)cnt[stoi(s[i].substr(2))][stoi(s[i].substr(4))]++;
  int ans=0;
  auto left(cnt),right(cnt);
  reps(i,1,10000)rep(j,100)left[i][j]+=left[i-1][j];
  for(int i=9998;i>=0;i--)rep(j,100)right[i][j]+=right[i+1][j];
  rep(i,10000){
    vector<int>sum(100,0);
    int c=i%100;
    int non=0;
    if(i)rep(j,100){
      if(j!=c)sum[j]+=left[i-1][j];
      else non+=left[i-1][j];
    }
    if(i!=9999)rep(j,100){
      if(j!=c)sum[j]+=right[i+1][j];
      else non+=right[i+1][j];
    }
    sort(all(sum),greater<int>());
    sum.resize(4);
    int sec=0;
    rep(j,100)sec+=cnt[i][j];
    rep(bit,16)if(pcnt(bit)<=3){
      int sc=0;
      rep(j,4)if(bit>>j&1)sc+=sum[j];
      int now=sec*4000+sc*500;
      if(sec+sc!=n-non)now+=300000;
      if(chmax(ans,now))debug(i,bit,sum,sc);
    }
    // if(sec)debug(i,sec);
    // if(sec+sum[0]+sum[1]!=n)chmax(ans,(sum[0]+sum[1])*500+sec*4000+300000);
    // else{
    //   chmax(ans,(sum[0]+sum[1])*500+sec*4000);
    //   if(sum[0]+sum[2]+sec!=n)chmax(ans,(sum[0]+sum[2])*500+sec*4000+300000);
    // }
    // if(sum[0]+sec!=n)chmax(ans,sec*4000+sum[0]*500+300000);
    // if(sec!=n)chmax(ans,sec*4000+300000);
    // chmax(ans,sec*4000);
    // if(i==3728)debug(ans,sum,sec);
  }
  cout<<ans<<endl;
}
accuracy: 1
time_ms: 100
memory_kb: 19044
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
template<int mod>istream &operator>>(istream &is,static_modint<mod> &a){long long b;is>>b;a=b;return is;}
istream &operator>>(istream &is,modint &a){long long b;cin>>b;a=b;return is;}
#endif
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) static_cast<void>(0)
#define debugg(...) static_cast<void>(0)
#define esper(...) static_cast<void>(0)
template<typename T1,typename T2>ostream &operator<<(ostream &os,const pair<T1,T2>&p){os<<p.first<<' '<<p.second;return os;}
#endif
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>istream &operator>>(istream &is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T>istream &operator>>(istream &is,vector<T> &a){for(auto &i:a)is>>i;return is;}
template<typename T1,typename T2>void operator++(pair<T1,T2>&a,int n){a.first++,a.second++;}
template<typename T1,typename T2>void operator--(pair<T1,T2>&a,int n){a.first--,a.second--;}
template<typename T>void operator++(vector<T>&a,int n){for(auto &i:a)i++;}
template<typename T>void operator--(vector<T>&a,int n){for(auto &i:a)i--;}
#define reps(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) reps(i,0,n)
#define all(x) x.begin(),x.end()
#define pcnt(x) __builtin_popcountll(x)
#define fin(x) return cout<<x<<'\n',static_cast<void>(0)
ll myceil(ll a,ll b){return (a+b-1)/b;}
template<typename T,size_t n,size_t id=0>
auto vec(const int (&d)[n],const T &init=T()){
  if constexpr (id<n)return vector(d[id],vec<T,n,id+1>(d,init));
  else return init;
}
void SOLVE();
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(16);
  #ifdef LOCAL
  clock_t start=clock();
  #endif
  int testcase=1;
  //cin>>testcase;
  for(int i=0;i<testcase;i++){
    SOLVE();
  }
  #ifdef LOCAL
  cerr<<"time:";
  cerr<<(clock()-start)/1000;
  cerr<<"ms\n";
  #endif
}
void SOLVE(){
  int n;
  cin>>n;
  vector<string>s(n);
  cin>>s;
  bool al=true;
  rep(i,n-1)al&=stoi(s[i].substr(4))==stoi(s[i+1].substr(4));
  if(al){
    int ans=300000;
    vector<int>cnt(10000,0);
    rep(i,n)cnt[stoi(s[i].substr(2))]++;
    chmax(ans,*max_element(all(cnt))*4000);
    chmax(ans,n*500);
    fin(ans);
  }
  sort(all(s),[](string a,string b){return stoi(a.substr(2))<stoi(b.substr(2));});
  vector<vector<int>>cnt(10000,vector<int>(100,0));
  rep(i,n)cnt[stoi(s[i].substr(2))][stoi(s[i].substr(4))]++;
  int ans=0;
  auto left(cnt),right(cnt);
  reps(i,1,10000)rep(j,100)left[i][j]+=left[i-1][j];
  for(int i=9998;i>=0;i--)rep(j,100)right[i][j]+=right[i+1][j];
  rep(i,10000){
    vector<int>sum(100,0);
    int c=i%100;
    if(i)rep(j,100)if(j!=c)sum[j]+=left[i-1][j];
    if(i!=9999)rep(j,100)if(j!=c)sum[j]+=right[i+1][j];
    sort(all(sum),greater<int>());
    sum.resize(4);
    int sec=0;
    rep(j,100)sec+=cnt[i][j];
    rep(bit,16)if(pcnt(bit)<=3){
      int sc=0;
      rep(j,4)if(bit>>j&1)sc+=sum[j];
      int now=sec*4000+sc*500;
      if(sec+sc!=n)now+=300000;
      chmax(ans,now);
    }
    // if(sec)debug(i,sec);
    // if(sec+sum[0]+sum[1]!=n)chmax(ans,(sum[0]+sum[1])*500+sec*4000+300000);
    // else{
    //   chmax(ans,(sum[0]+sum[1])*500+sec*4000);
    //   if(sum[0]+sum[2]+sec!=n)chmax(ans,(sum[0]+sum[2])*500+sec*4000+300000);
    // }
    // if(sum[0]+sec!=n)chmax(ans,sec*4000+sum[0]*500+300000);
    // if(sec!=n)chmax(ans,sec*4000+300000);
    // chmax(ans,sec*4000);
    // if(i==3728)debug(ans,sum,sec);
  }
  cout<<ans<<endl;
}
accuracy: 0.6842105263157895
time_ms: 30
memory_kb: 16956
final_rank: 15