#include "bits/stdc++.h" #pragma region temp // utility namespace cmitf { using usize = std::size_t; using isize = std::ptrdiff_t; using bit_t = std::uint64_t; constexpr std::int64_t operator""_i64(unsigned long long n) noexcept { return static_cast(n); } constexpr std::int32_t operator""_i32(unsigned long long n) noexcept { return static_cast(n); } constexpr std::int16_t operator""_i16(unsigned long long n) noexcept { return static_cast(n); } constexpr std::uint64_t operator""_u64(unsigned long long n) noexcept { return static_cast(n); } constexpr std::uint32_t operator""_u32(unsigned long long n) noexcept { return static_cast(n); } constexpr std::uint16_t operator""_u16(unsigned long long n) noexcept { return static_cast(n); } constexpr usize operator""_uz(unsigned long long n) noexcept { return static_cast(n); } constexpr isize operator""_iz(unsigned long long n) noexcept { return static_cast(n); } constexpr bit_t operator""_bit(unsigned long long n) noexcept { return static_cast(n); } template constexpr T infty = std::numeric_limits::max() / Div - 10; constexpr std::int32_t infi32 = infty; // 1073741813 constexpr std::int64_t infi64 = infty; // 2305843009213693941 constexpr usize infusz = infi32; #if __cplusplus < 202002L constexpr std::int32_t popcount(std::uint64_t x) noexcept { x = x - ((x >> 1) & 0x5555555555555555); x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333); x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f; x = x + (x >> 8); x = x + (x >> 16); x = x + (x >> 32); return x & 0x0000007f; } #else using std::popcount; #endif template constexpr T ceil_div(const T a, const T b) { return (a + b - 1) / b; } template auto mk_vec(const usize n, const T& value) { return std::vector(n, value); } template auto mk_vec(const usize n, Args... args) { return std::vector(n, mk_vec(args...)); } namespace helper { template void zip_sort_renumber(const std::vector& order, std::vector& head, Tail&... tail) { const usize n = order.size(); std::vector sorted_head(n); for (usize i = 0; i < n; ++i) sorted_head[i] = head[order[i]]; head = std::move(sorted_head); if constexpr (sizeof...(Tail) != 0) zip_sort_renumber(order, tail...); } } // namespace helper template std::vector zip_sort(std::vector& head, std::vector&... tail) { const usize n = head.size(); std::vector> res(n); for (usize i = 0; i < n; ++i) res[i] = std::make_tuple(head[i], tail[i]..., i); std::sort(res.begin(), res.end()); std::vector order(n); for (usize i = 0; i < n; ++i) order[i] = std::get>>(res[i]); helper::zip_sort_renumber(order, head, tail...); return order; } template class presser { using size_type = std::size_t; std::vector m_v; public: size_type size() const noexcept { return m_v.size(); } void reserve(const size_type n) { m_v.reserve(n); } template void paste(const ForwardIterator first, const ForwardIterator last) { std::copy(first, last, std::back_inserter(m_v)); } template void paste(const Container& c) { std::copy(c.begin(), c.end(), std::back_inserter(m_v)); } void add(const T& v) { m_v.push_back(v); } size_type build() { std::sort(m_v.begin(), m_v.end()); m_v.erase(std::unique(m_v.begin(), m_v.end()), m_v.end()); return m_v.size(); } size_type get_idx(const T& val) const { return static_cast(std::lower_bound(m_v.begin(), m_v.end(), val) - m_v.begin()); } T get_val(const size_type i) const { return m_v[i]; } }; class rep { using value_type = usize; struct rep_iterator { value_type itr; constexpr rep_iterator(const value_type pos) noexcept : itr(pos) {} constexpr void operator++() noexcept { ++itr; } constexpr bool operator!=(const rep_iterator& other) const noexcept { return itr != other.itr; } constexpr value_type operator*() const noexcept { return itr; } }; const rep_iterator first, last; public: constexpr rep(const value_type first_, const value_type last_) noexcept : first(first_), last(std::max(first_, last_)) {} constexpr rep_iterator begin() const noexcept { return first; } constexpr rep_iterator end() const noexcept { return last; } }; // class rep class revrep { using value_type = usize; struct revrep_iterator { value_type itr; constexpr revrep_iterator(const value_type pos) noexcept : itr(pos) {} constexpr void operator++() noexcept { --itr; } constexpr bool operator!=(const revrep_iterator& other) const noexcept { return itr != other.itr; } constexpr usize operator*() const noexcept { return itr; } }; const revrep_iterator first, last; public: constexpr revrep(const usize first_, const usize last_) noexcept : first(last_ - 1), last(first_ - 1) {} constexpr revrep_iterator begin() const noexcept { return first; } constexpr revrep_iterator end() const noexcept { return last; } }; // class revrep template class rec_lambda { F f; public: explicit constexpr rec_lambda(F&& f_) : f(std::forward(f_)) {} template constexpr auto operator()(Args&&... args) const { return f(*this, std::forward(args)...); } }; // class rec_lambda class to4 { using value_type = usize; static constexpr value_type minus1 = std::numeric_limits::max(); static constexpr std::array dx = {minus1, 0, 1, 0, 0}, dy = {0, minus1, 0, 1, 0}; struct to4_iterator { int d; const value_type h, w, maxh, maxw; constexpr to4_iterator(const value_type h_, const value_type w_, const value_type maxh_, const value_type maxw_) noexcept : d(0), h(h_), w(w_), maxh(maxh_), maxw(maxw_) {} constexpr void operator++() noexcept { do { ++d; } while (d != 4 and (h + dx[d] == minus1 or h + dx[d] == maxh or w + dy[d] == minus1 or w + dy[d] == maxw)); } constexpr bool operator!=(const int other) const noexcept { return d != other; } constexpr std::pair operator*() const noexcept { return {h + dx[d], w + dy[d]}; } }; const to4_iterator i; public: constexpr to4(const value_type h, const value_type w, const value_type maxh, const value_type maxw) noexcept : i(h, w, maxh, maxw) {} constexpr to4_iterator begin() const noexcept { return i; } constexpr int end() const noexcept { return 4; } }; class to8 { using value_type = usize; static constexpr value_type minus1 = std::numeric_limits::max(); static constexpr std::array dx = {minus1, minus1, minus1, 0, 0, 1, 1, 1, 0}, dy = {minus1, 0, 1, minus1, 1, minus1, 0, 1, 0}; struct to8_iterator { int d; const value_type h, w, maxh, maxw; constexpr to8_iterator(const value_type h_, const value_type w_, const value_type maxh_, const value_type maxw_) noexcept : d(0), h(h_), w(w_), maxh(maxh_), maxw(maxw_) {} constexpr void operator++() noexcept { do { ++d; } while (d != 8 and (h + dx[d] == minus1 or h + dx[d] == maxh or w + dy[d] == minus1 or w + dy[d] == maxw)); } constexpr bool operator!=(const int other) const noexcept { return d != other; } constexpr std::pair operator*() const noexcept { return {h + dx[d], w + dy[d]}; } }; const to8_iterator i; public: constexpr to8(const value_type h, const value_type w, const value_type maxh, const value_type maxw) noexcept : i(h, w, maxh, maxw) {} constexpr to8_iterator begin() const noexcept { return i; } constexpr int end() const noexcept { return 8; } }; } // namespace cmitf // math namespace cmitf { constexpr std::int64_t pow_int(std::int64_t x, std::int64_t n) noexcept { assert(n >= 0); std::int64_t res = 1; while (n != 0) { if (n & 1) res = res * x; x = x * x; n >>= 1; } // res = x ^ n return res; } constexpr std::uint32_t ceil_log2(std::uint64_t v) noexcept { std::uint32_t res = 0; while ((1_u64 << res) < v) ++res; return res; } template class Static_Modint { using this_type = Static_Modint; std::uint32_t value; public: static constexpr std::uint32_t mod() noexcept { return MOD; } template static constexpr T mod() noexcept { return static_cast(MOD); } template >* = nullptr> static constexpr std::uint32_t normalize(const T v) noexcept { return static_cast(v % mod()); } template >* = nullptr> static constexpr std::uint32_t normalize(const T v) noexcept { if (v < 0) return static_cast(v % mod() + mod()); else return static_cast(v % mod()); } constexpr Static_Modint() noexcept : value(0) {} template constexpr Static_Modint(const T v) noexcept : value(normalize(v)) {} template static constexpr this_type raw(const T v) noexcept { this_type ret; ret.value = static_cast(v); return ret; } constexpr const std::uint32_t& val() const noexcept { return value; } constexpr this_type operator-() const noexcept { return value == 0 ? 0 : mod() - value; } constexpr bool operator==(const this_type& rhs) const noexcept { return value == rhs.value; } constexpr bool operator!=(const this_type& rhs) const noexcept { return value != rhs.value; } constexpr bool operator<(const this_type& rhs) const noexcept { return value < rhs.value; } constexpr bool operator<=(const this_type& rhs) const noexcept { return value <= rhs.value; } constexpr bool operator>(const this_type& rhs) const noexcept { return value > rhs.value; } constexpr bool operator>=(const this_type& rhs) const noexcept { return value >= rhs.value; } constexpr this_type& operator++() noexcept { ++value; if (value == mod()) value = 0; return *this; } constexpr this_type& operator--() noexcept { if (value == 0) value = mod(); --value; return *this; } constexpr this_type operator++(int) noexcept { this_type ret(*this); ++*this; return ret; } constexpr this_type operator--(int) noexcept { this_type ret(*this); --*this; return ret; } constexpr this_type operator+(const this_type& rhs) const noexcept { return this_type(*this) += rhs; } constexpr this_type operator-(const this_type& rhs) const noexcept { return this_type(*this) -= rhs; } constexpr this_type operator*(const this_type& rhs) const noexcept { return this_type(*this) *= rhs; } constexpr this_type operator/(const this_type& rhs) const noexcept { return this_type(*this) /= rhs; } constexpr this_type& operator+=(const this_type& rhs) noexcept { if ((value += rhs.value) >= mod()) value -= mod(); return *this; } constexpr this_type& operator-=(const this_type& rhs) noexcept { if (value < rhs.value) value += mod(); value -= rhs.value; return *this; } constexpr this_type& operator*=(const this_type& rhs) noexcept { value = static_cast(static_cast(value) * static_cast(rhs.value) % mod()); return *this; } constexpr this_type& operator/=(const this_type& rhs) noexcept { return *this *= rhs.inv(); } template constexpr this_type pow(T n) { this_type ret(1), x(*this); while (n != 0) { if (n & 1) ret *= x; x *= x; n >>= 1; } return ret; } constexpr this_type inv() const { std::int64_t s = mod(), t = static_cast(value), a = 0, b = 1; while (t != 0) { const std::int64_t u = s / t; s -= t * u; a -= b * u; auto k = s; s = t; t = k; k = a; a = b; b = k; } if (a < 0) a += mod(); return this_type::raw(a); } }; template class Static_Modint_Utility { using size_type = size_t; static inline size_type size = 1; public: static void upsize(const size_type n) { if (n > size) { for (size_type i = size + 1; i <= n; ++i) { fact.emplace_back(fact[i - 1] * T::raw(i)); inv.emplace_back(-inv[T::mod() % i] * (T::mod() / i)); fact_inv.emplace_back(fact_inv[i - 1] * inv[i]); } size = n; } } static inline std::vector fact = {1, 1}, inv = {0, 1}, fact_inv = {1, 1}; static T comb(const size_type n, const size_type r) { if (n < r) return 0; upsize(n); return fact[n] * fact_inv[n - r] * fact_inv[r]; } }; } // namespace cmitf // io namespace cmitf { template std::istream& operator>>(std::istream& is, std::pair& v) { is >> v.first >> v.second; return is; } template std::ostream& operator<<(std::ostream& os, const std::pair& v) { os << v.first << ' ' << v.second; return os; } template std::istream& operator>>(std::istream& is, std::vector& v) { for (auto& t : v) is >> t; return is; } template std::ostream& operator<<(std::ostream& os, const std::vector& v) { usize n = v.size(); os << v[0]; for (usize i = 1; i < n; ++i) os << ' ' << v[i]; return os; } template std::ostream& operator<<(std::ostream& os, const Static_Modint& v) { os << v.val(); return os; } inline void in() noexcept {} template inline void in(Head& h, Tail&... t) { std::cin >> h; in(t...); } inline void lout() { std::cout << '\n'; } template inline void lout(const Head& h, const Tail&... t) { std::cout << h; if constexpr (sizeof...(Tail) != 0) std::cout << ' '; lout(t...); } inline void sout() {} template inline void sout(const Head& h, const Tail&... t) { std::cout << h << ' '; sout(t...); } } // namespace cmitf #pragma endregion namespace cmitf { #pragma region using i16 = std::int16_t; using i32 = std::int32_t; using i64 = std::int64_t; using u16 = std::uint16_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using std::ignore; using std::make_pair; using std::make_tuple; using std::nullopt; using std::pair; using std::tuple; using Str = std::string; template using Vec = std::vector; template using Array = std::array; template using Que = std::queue; template using Stk = std::stack; template using Deq = std::deque; template using HeapQ = std::priority_queue; template using Set = std::set; template using MultiSet = std::multiset; template using Map = std::map; template using MultiMap = std::multimap; template using RevHeapQ = std::priority_queue, std::greater>; template using Opt = std::optional; #ifdef CMITF_DEBUG // output "Debug : names = values" #define pdebug(...) \ { \ std::cerr << "Debug : " << #__VA_ARGS__ << " = "; \ debug_impl::converter(__VA_ARGS__); \ } #else #define pdebug(...) #endif #pragma endregion void main_() { usize N; in(N); Vec F, G; for (const auto i : rep(0, N)) { int a; i64 b, t; in(a, b, t); if (a == 0) F.push_back(b + t); else G.push_back(b + t); } std::sort(F.begin(), F.end()); i64 ans = 0; for (const auto v : G) ans += i64(std::upper_bound(F.begin(), F.end(), v) - (std::lower_bound(F.begin(), F.end(), v))); lout(ans); } #undef pdebug } // namespace cmitf int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(15); freopen("input.txt", "r", stdin); std::size_t T = 1; // std::cin >> T; while (T--) cmitf::main_(); return 0; }