#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5+10,inf = 0x3f3f3f3f; struct node{ int t,p,f; }; node a[N]; int n,x,t,p,head = 1,tail = 1,ans; int find(int p) { for(int i = head;i < tail;i++) if(a[i].p >= p && a[i].f == 0) { a[i].f = 1; return 0; } return p; } int main() { cin >> n; for(int i=1;i<=n;i++) { cin >> x >> p >> t; if(x == 0) { ans += p; a[tail].t = t; a[tail].f = 0; a[tail++].p = p; } else { while(head < tail && t - a[head].t > 45)head ++; ans += find(p); } } cout << ans; return 0; }