QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#530853#9225. Fibonacci Fusionucup-team1264#AC ✓3711ms254156kbC++2028.8kb2024-08-24 17:26:452024-08-24 17:26:45

Judging History

你现在查看的是最新测评结果

  • [2024-08-24 17:26:45]
  • 评测
  • 测评结果:AC
  • 用时:3711ms
  • 内存:254156kb
  • [2024-08-24 17:26:45]
  • 提交

answer

// https://www.youtube.com/watch?v=wthasN45KuY
// You said I’d fly away
// But my walls have kept me down
// Now I’m lost and I’m afraid
// And I’m close to hit the ground
// 
// You said I’d fly away
// You said I’d fly anywhere
// But I keep on Falling

#ifndef ONLINE_JUDGE
#include "templates/debug.hpp"
#else
#define debug(...)
#endif

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;

class ZeroDivisionError : public std::exception {
public:
	const char* what() const throw() {return "BigInteger::divmod";}
};
class FFTLimitExceededError : public std::exception {
public:
	const char* what() const throw() {return "BigInteger::fft_mul";}
};

class BigInteger {
protected:
	using digit_t = long long;
	
	static constexpr int WIDTH = 8;
	static constexpr digit_t BASE = 1e8;
	static constexpr long long FFT_LIMIT = 512;
	static constexpr long long NEWTON_LIMIT = 512;
	static constexpr long long NEWTON_MIN_LEVEL = 16;
	
	digit_t* digits;
	int capacity, size;
	bool flag;
	
	inline void push(const digit_t&);
	inline void pop();
	
	inline int compare(const BigInteger&) const;	
	
	static inline BigInteger fft_mul(const BigInteger&, const BigInteger&);
	
	inline BigInteger move_l(int) const;
	inline BigInteger move_r(int) const;
	BigInteger newton_inv(int) const;
	inline std::pair<BigInteger, BigInteger> newton_div(const BigInteger&) const;
	
	template <class F>
	inline static BigInteger binary_op_helper(const BigInteger&, const BigInteger&, const F&);
	
public:
	inline void reserve(const int&);
protected:
	inline void resize(const int&);
	
public:
	BigInteger() : digits(nullptr), flag(true) {*this = 0;}
	
	BigInteger(const BigInteger& x) : digits(nullptr) {*this = x;}
	BigInteger(const long long& x) : digits(nullptr) {*this = x;}
	BigInteger(const std::string& s) : digits(nullptr) {*this = s;}
	BigInteger(const std::vector<bool>& b) : digits(nullptr) {*this = b;}
	template <class BoolIt>
	BigInteger(const BoolIt& begin, const BoolIt& end) : digits(nullptr) 
	{*this = std::vector<bool>(begin, end);}
	
	BigInteger& operator= (const BigInteger&);
	BigInteger& operator= (const long long&);
	BigInteger& operator= (const std::string&);
	BigInteger& operator= (const std::vector<bool>&);
	
	void clear();
	~BigInteger() {clear();}
	
	friend std::ostream& operator<< (std::ostream& out, const BigInteger& x) {
		if (!x.flag) out << '-';
		out << (long long) x.digits[x.size];
		for (int i = x.size - 1; i >= 1; i--) 
			out << std::setw(WIDTH) << std::setfill('0') << (long long) x.digits[i];
		return out;
	}
	friend std::istream& operator>> (std::istream& in, BigInteger& x) {
		std::string s; in >> s; x = s; 
		return in;
	}
	
	std::string to_string() const;
	long long to_long_long() const;
	std::vector<bool> to_binary() const;
	
	BigInteger operator- () const;
	BigInteger abs() const;
	
	bool operator== (const BigInteger&) const; 
#if __cplusplus >= 202002L
	auto operator<=> (const BigInteger&) const;
#else
	bool operator< (const BigInteger&) const;
	bool operator> (const BigInteger&) const; 
	bool operator!= (const BigInteger&) const;
	bool operator<= (const BigInteger&) const;
	bool operator>= (const BigInteger&) const;
#endif //__cplusplus >= 202002L
	
	BigInteger div2() const;
	std::pair<BigInteger, BigInteger> divmod(const BigInteger&, bool = false) const;
	
	BigInteger operator+ (const BigInteger&) const;
	BigInteger operator- (const BigInteger&) const;
	BigInteger operator* (const int&) const;
	BigInteger operator* (const BigInteger&) const;
	BigInteger operator/ (const long long&) const;
	BigInteger operator/ (const BigInteger&) const;
	BigInteger operator% (const long long&) const;
	BigInteger operator% (const BigInteger&) const;
	
	BigInteger pow(const long long&) const;
	BigInteger pow(const long long&, const BigInteger&) const;
	
	BigInteger root(const long long& = 2) const;
	
	BigInteger gcd(const BigInteger&) const;
	BigInteger lcm(const BigInteger&) const;
	
	BigInteger& operator+= (const BigInteger&);
	BigInteger& operator-= (const BigInteger&);
	BigInteger& operator*= (int);
	BigInteger& operator*= (const BigInteger&);
	BigInteger& operator/= (const long long&);
	BigInteger& operator/= (const BigInteger&);
	BigInteger& operator%= (const long long&);
	BigInteger& operator%= (const BigInteger&);
	
	BigInteger operator<< (const long long&);
	BigInteger operator>> (const long long&);
	BigInteger& operator<<= (const long long&);
	BigInteger& operator>>= (const long long&);
	
	BigInteger operator& (const BigInteger&);
	BigInteger operator| (const BigInteger&);
	BigInteger operator^ (const BigInteger&);
	BigInteger& operator&= (const BigInteger&);
	BigInteger& operator|= (const BigInteger&);
	BigInteger& operator^= (const BigInteger&);
	
	BigInteger& operator++ ();
	BigInteger operator++ (int);
	BigInteger& operator-- ();
	BigInteger operator-- (int);
};

inline void BigInteger::push(const digit_t& val) {
	if (size == capacity) {
		int new_capacity = 0;
		if (capacity < 1000) new_capacity = capacity << 1;
		else new_capacity = (capacity >> 1) * 3;
		if (new_capacity < 0) new_capacity = INT_MAX;
		digit_t* new_digits = new digit_t[new_capacity + 1];
		std::memcpy(new_digits, digits, sizeof(long long) * (capacity + 1));
		delete[] digits;
		digits = new_digits, capacity = new_capacity;
	}
	digits[++size] = val;
}
inline void BigInteger::pop() {digits[size--] = 0;}

inline int BigInteger::compare(const BigInteger& x) const {
	if (flag && !x.flag) return 1;
	if (!flag && x.flag) return -1;
	
	int sgn = (flag && x.flag ? 1 : -1);
	if (size > x.size) return sgn;
	if (size < x.size) return -sgn;
	
	for (int i = size; i >= 1; i--) {
		if (digits[i] > x.digits[i]) return sgn;
		if (digits[i] < x.digits[i]) return -sgn;
	}
	return 0;
}

inline void BigInteger::reserve(const int& sz) {
	if (sz < 0) return;
	if (digits != nullptr) delete[] digits;
	capacity = sz, size = 0;
	digits = new digit_t[sz + 1];
	std::memset(digits, 0, sizeof(digit_t) * (sz + 1));
}
inline void BigInteger::resize(const int& sz) {reserve(sz), size = sz;}

BigInteger& BigInteger::operator= (const BigInteger& x) {
	reserve(x.size + 1);
	flag = x.flag, size = x.size;
	std::memcpy(digits, x.digits, sizeof(digit_t) * (x.size + 1));
	return *this;
}
BigInteger& BigInteger::operator= (const long long& x) {
	flag = (x >= 0), reserve(4);
	if (x == 0) return size = 1, digits[1] = 0, *this;
	if (x == LLONG_MIN) return *this = "-9223372036854775808";
	long long n = std::abs(x);
	do {push(n % BASE), n /= BASE;} while (n);
	return *this;
}
BigInteger& BigInteger::operator= (const std::string& s) {
	flag = true, reserve(s.size() / WIDTH + 1);
	if (s.empty() || s == "-") return *this = 0;
	int i = 0; if (s[0] == '-') flag = false, i++;
	for (int j = s.size() - 1; j >= i; j -= WIDTH) {
		int start = std::max(i, j - WIDTH + 1), len = j - start + 1;
		push(std::stoll(s.substr(start, len)));
	}
	return *this;
}

BigInteger& BigInteger::operator= (const std::vector<bool>& b) {
	*this = 0;
	if (b.empty() || (b.size() == 1 && b[0] == 0)) return *this;
	BigInteger pow2 = 1;
	for (int i = b.size() - 1; i >= 0; i--, pow2 += pow2) if (b[i]) *this += pow2;
	return *this;
}

void BigInteger::clear() {if (digits != nullptr) delete[] digits, digits = nullptr;}

std::string BigInteger::to_string() const {std::stringstream ss; ss << *this; return ss.str();}
long long BigInteger::to_long_long() const {return std::stoll(to_string());}
std::vector<bool> BigInteger::to_binary() const {
	if (*this == 0) return {0};
	std::vector<bool> res;
	for (BigInteger x = *this; x != 0; x = x.div2()) res.emplace_back(x.digits[1] & 1);
	std::reverse(res.begin(), res.end());
	return res;
};

BigInteger BigInteger::operator- () const {
	if (*this == 0) return 0;
	BigInteger res = *this; res.flag = !flag; return res;
}
BigInteger BigInteger::abs() const {BigInteger res = *this; res.flag = true; return res;}

bool BigInteger::operator== (const BigInteger& x) const {return compare(x) == 0;}
#if __cplusplus >= 202002L
auto BigInteger::operator<=> (const BigInteger& x) const {return compare(x);}
#else
bool BigInteger::operator< (const BigInteger& x) const {return compare(x) < 0;}
bool BigInteger::operator> (const BigInteger& x) const {return compare(x) > 0;}
bool BigInteger::operator!= (const BigInteger& x) const {return compare(x) != 0;}
bool BigInteger::operator<= (const BigInteger& x) const {return compare(x) <= 0;}
bool BigInteger::operator>= (const BigInteger& x) const {return compare(x) >= 0;}
#endif //__cplusplus >= 202002L

BigInteger BigInteger::operator+ (const BigInteger& x) const {
	if (!x.flag) return *this - x.abs();
	if (!flag) return x - abs();
	
	BigInteger res; 
	res.flag = !(flag ^ x.flag);
	int n = std::max(size, x.size) + 1;
	res.reserve(n);
	digit_t carry = 0;
	for (int i = 1; i <= n; i++) {
		digit_t d1 = i <= size ? digits[i] : 0, d2 = i <= x.size ? x.digits[i] : 0;
		res.push(d1 + d2 + carry);
		carry = res.digits[i] / BASE;
		res.digits[i] %= BASE;
	}
	while (res.size > 1 && res.digits[res.size] == 0) res.pop();
	return res;
}
BigInteger BigInteger::operator- (const BigInteger& x) const {
	if (!x.flag) return *this + x.abs();
	if (!flag) return -(abs() + x);
	BigInteger res;
	if (*this < x) res.flag = false;
	digit_t carry = 0;
	int n = std::max(size, x.size);
	res.reserve(n);
	for (int i = 1; i <= n; i++) {
		digit_t d1 = i <= size ? digits[i] : 0, d2 = i <= x.size ? x.digits[i] : 0;
		if (res.flag) res.push(d1 - d2 - carry);
		else res.push(d2 - d1 - carry);
		if (res.digits[i] < 0) res.digits[i] += BASE, carry = 1;
		else carry = 0;
	}
	while (res.size > 1 && res.digits[res.size] == 0) res.pop();
	return res;
}

namespace __FFT {
	constexpr long long FFT_BASE = 1e4;
	constexpr double PI2 = 6.283185307179586231995927;
	constexpr double PI6 = 18.84955592153875869598778;
	
	constexpr int RECALC_WIDTH = 10;
	constexpr int RECALC_BASE = (1 << RECALC_WIDTH) - 1;
	
	struct complex {
		double real, imag;
		
		complex(double x = 0.0, double y = 0.0) : real(x), imag(y) {}
		
		complex operator+ (const complex& other) const {return complex(real + other.real, imag + other.imag);}
		complex operator- (const complex& other) const {return complex(real - other.real, imag - other.imag);}
		complex operator* (const complex& other) const {return complex(real * other.real - imag * other.imag, real * other.imag + other.real * imag);}
		
		complex& operator+= (const complex& other) {return real += other.real, imag += other.imag, *this;}
		complex& operator-= (const complex& other) {return real -= other.real, imag -= other.imag, *this;}
		complex& operator*= (const complex& other) {return *this = *this * other;}
	};
	
	complex* arr = nullptr;
	
	inline void init(int n) {
		if (arr != nullptr) delete[] arr, arr = nullptr;
		arr = new complex[n + 1];
	}
	
	template <const int n> 
	inline void fft(complex* a) {
		const int n2 = n >> 1, n4 = n >> 2;
		complex w(1.0, 0.0), w3(1.0, 0.0);
		const complex wn(std::cos(PI2 / n), std::sin(PI2 / n)), wn3(std::cos(PI6 / n), std::sin(PI6 / n));
		for (int i = 0; i < n4; i++, w *= wn, w3 *= wn3) {
			if (!(i & RECALC_BASE)) w = complex(std::cos(PI2 * i / n), std::sin(PI2 * i / n)), w3 = w * w * w;
			complex x = a[i] - a[i + n2], y = a[i + n4] - a[i + n2 + n4];
			y = complex(y.imag, -y.real);
			a[i] += a[i + n2], a[i + n4] += a[i + n2 + n4];
			a[i + n2] = (x - y) * w, a[i + n2 + n4] = (x + y) * w3;
		}
		fft<n2>(a), fft<n4>(a + n2), fft<n4>(a + n2 + n4);
	}
	template <> inline void fft<1>(complex* a) {}
	template <> inline void fft<0>(complex* a) {}
	template <> inline void fft<2>(complex* a) {
		complex x = a[0], y = a[1];
		a[0] += y, a[1] = x - y;
	}
	template <> inline void fft<4>(complex* a) {
		complex a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
		complex x = a0 - a2, y = a1 - a3;
		y = complex(y.imag, -y.real);
		a[0] += a2, a[1] += a3, a[2] = x - y, a[3] = x + y;
		fft<2>(a);
	}
	
	template <const int n> 
	inline void ifft(complex* a) {
		const int n2 = n >> 1, n4 = n >> 2;
		ifft<n2>(a), ifft<n4>(a + n2), ifft<n4>(a + n2 + n4);
		complex w(1.0, 0.0), w3(1.0, 0.0);
		const complex wn(std::cos(PI2 / n), -std::sin(PI2 / n)), wn3(std::cos(PI6 / n), -std::sin(PI6 / n));
		for (int i = 0; i < n4; i++, w *= wn, w3 *= wn3) {
			if (!(i & RECALC_BASE)) w = complex(std::cos(PI2 * i / n), -std::sin(PI2 * i / n)), w3 = w * w * w;
			complex p = w * a[i + n2], q = w3 * a[i + n2 + n4];
			complex x = a[i], y = p + q, x1 = a[i + n4], y1 = p - q;
			y1 = complex(y1.imag, -y1.real);
			a[i] += y, a[i + n4] += y1, a[i + n2] = x - y, a[i + n2 + n4] = x1 - y1;
		}
	}
	template <> inline void ifft<1>(complex* a) {}
	template <> inline void ifft<0>(complex* a) {}
	template <> inline void ifft<2>(complex* a) {
		complex x = a[0], y = a[1];
		a[0] += y, a[1] = x - y;
	}
	template <> inline void ifft<4>(complex* a) {
		ifft<2>(a);
		complex p = a[2], q = a[3];
		complex x = a[0], y = p + q, x1 = a[1], y1 = p - q;
		y1 = complex(y1.imag, -y1.real);
		a[0] += y, a[1] += y1, a[2] = x - y, a[3] = x1 - y1;
	}
	
	inline void dft(complex* a, int n) {
		if (n <= 1) return;
		switch (n) {
			case 1 << 2: fft<1 << 2>(a); break;
			case 1 << 3: fft<1 << 3>(a); break;
			case 1 << 4: fft<1 << 4>(a); break;
			case 1 << 5: fft<1 << 5>(a); break;
			case 1 << 6: fft<1 << 6>(a); break;
			case 1 << 7: fft<1 << 7>(a); break;
			case 1 << 8: fft<1 << 8>(a); break;
			case 1 << 9: fft<1 << 9>(a); break;
			case 1 << 10: fft<1 << 10>(a); break;
			case 1 << 11: fft<1 << 11>(a); break;
			case 1 << 12: fft<1 << 12>(a); break;
			case 1 << 13: fft<1 << 13>(a); break;
			case 1 << 14: fft<1 << 14>(a); break;
			case 1 << 15: fft<1 << 15>(a); break;
			case 1 << 16: fft<1 << 16>(a); break;
			case 1 << 17: fft<1 << 17>(a); break;
			case 1 << 18: fft<1 << 18>(a); break;
			case 1 << 19: fft<1 << 19>(a); break;
			case 1 << 20: fft<1 << 20>(a); break;
			case 1 << 21: fft<1 << 21>(a); break;
			case 1 << 22: fft<1 << 22>(a); break;
			case 1 << 23: fft<1 << 23>(a); break;
			case 1 << 24: fft<1 << 24>(a); break;
			case 1 << 25: fft<1 << 25>(a); break;
			case 1 << 26: fft<1 << 26>(a); break;
			case 1 << 27: fft<1 << 27>(a); break;
			case 1 << 28: fft<1 << 28>(a); break;
			case 1 << 29: fft<1 << 29>(a); break;
			case 1 << 30: fft<1 << 30>(a); break;
			case 1 << 31: fft<1 << 31>(a); break;
			throw FFTLimitExceededError();
		}
	}
	inline void idft(complex* a, int n) {
		if (n <= 1) return;
		switch (n) {
			case 1 << 2: ifft<1 << 2>(a); break;
			case 1 << 3: ifft<1 << 3>(a); break;
			case 1 << 4: ifft<1 << 4>(a); break;
			case 1 << 5: ifft<1 << 5>(a); break;
			case 1 << 6: ifft<1 << 6>(a); break;
			case 1 << 7: ifft<1 << 7>(a); break;
			case 1 << 8: ifft<1 << 8>(a); break;
			case 1 << 9: ifft<1 << 9>(a); break;
			case 1 << 10: ifft<1 << 10>(a); break;
			case 1 << 11: ifft<1 << 11>(a); break;
			case 1 << 12: ifft<1 << 12>(a); break;
			case 1 << 13: ifft<1 << 13>(a); break;
			case 1 << 14: ifft<1 << 14>(a); break;
			case 1 << 15: ifft<1 << 15>(a); break;
			case 1 << 16: ifft<1 << 16>(a); break;
			case 1 << 17: ifft<1 << 17>(a); break;
			case 1 << 18: ifft<1 << 18>(a); break;
			case 1 << 19: ifft<1 << 19>(a); break;
			case 1 << 20: ifft<1 << 20>(a); break;
			case 1 << 21: ifft<1 << 21>(a); break;
			case 1 << 22: ifft<1 << 22>(a); break;
			case 1 << 23: ifft<1 << 23>(a); break;
			case 1 << 24: ifft<1 << 24>(a); break;
			case 1 << 25: ifft<1 << 25>(a); break;
			case 1 << 26: ifft<1 << 26>(a); break;
			case 1 << 27: ifft<1 << 27>(a); break;
			case 1 << 28: ifft<1 << 28>(a); break;
			case 1 << 29: ifft<1 << 29>(a); break;
			case 1 << 30: ifft<1 << 30>(a); break;
			case 1 << 31: ifft<1 << 31>(a); break;
			throw FFTLimitExceededError();
		}
	}
}

BigInteger BigInteger::fft_mul(const BigInteger& a, const BigInteger& b) {
	static_assert(__FFT::FFT_BASE * __FFT::FFT_BASE == BASE);
	int least = (a.size + b.size) << 1, lim = 1 << std::__lg(least);
	if (lim < least) lim <<= 1;
	__FFT::init(lim);
	using __FFT::arr;
	for (int i = 0; i < a.size; i++) {
		arr[i << 1].real = a.digits[i + 1] % 10000;
		arr[i << 1 | 1].real = a.digits[i + 1] / 10000 % 10000;
	}
	for (int i = 0; i < b.size; i++) {
		arr[i << 1].imag = b.digits[i + 1] % 10000;
		arr[i << 1 | 1].imag = b.digits[i + 1] / 10000 % 10000;
	}
	__FFT::dft(arr, lim);
	for (int i = 0; i < lim; i++) arr[i] *= arr[i];
	__FFT::idft(arr, lim);
	BigInteger res;
	res.resize(a.size + b.size + 1);
	digit_t carry = 0;
	double inv = 0.5 / lim;
	for (int i = 0; i <= a.size + b.size; i++) {
		carry += (digit_t)(arr[i << 1].imag * inv + 0.5);
		carry += (digit_t)(arr[i << 1 | 1].imag * inv + 0.5) * 10000LL;
		res.digits[i + 1] += carry % BASE, carry /= BASE;
	}
	while (res.size > 1 && res.digits[res.size] == 0) res.pop();
	return res;
}

BigInteger BigInteger::operator* (const BigInteger& x) const {
	BigInteger zero = 0;
	if (*this == zero || x == zero) return zero;
	int n = size, m = x.size;
	long long lim = 1LL * n * m;
	
	if (lim >= FFT_LIMIT) {
		BigInteger res = fft_mul(*this, x);
		res.flag = !(flag ^ x.flag);
		return res;
	}
	
	BigInteger res;
	res.flag = !(flag ^ x.flag);
	res.resize(n + m + 2);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			res.digits[i + j - 1] += digits[i] * x.digits[j];
			res.digits[i + j] += res.digits[i + j - 1] / BASE;
			res.digits[i + j - 1] %= BASE;
		}
	}
	for (int i = 1; i <= n + m + 1; i++) {
		res.digits[i + 1] += res.digits[i] / BASE;
		res.digits[i] %= BASE;
	}
	while (res.size > 1 && res.digits[res.size] == 0) res.pop();
	return res;
}

BigInteger& BigInteger::operator*= (int x) {
	if (x == 0 || *this == 0) return *this = 0;
	if (x < 0) flag = !flag, x = -x;
	digit_t carry = 0;
	for (int i = 1; i <= size || carry; i++) {
		if (i > size) push(0);
		digit_t cur = digits[i] * x + carry;
		carry = cur / BigInteger::BASE;
		digits[i] = cur % BigInteger::BASE;
	}
	while (size > 1 && digits[size] == 0) pop();
	return *this;
}
BigInteger BigInteger::operator* (const int& x) const {BigInteger t = *this; return t *= x;}

BigInteger BigInteger::div2() const {
	BigInteger res = *this;
	for (int i = size; i >= 1; i--) {
		if ((res.digits[i] & 1) && (i > 1)) res.digits[i - 1] += BASE;
		res.digits[i] >>= 1;
	}
	while (res.size > 1 && res.digits[res.size] == 0) res.pop();
	return res;
}
BigInteger BigInteger::operator/ (const long long& x) const {
	if (x == 0) throw -1;
	if (*this == 0) return 0;
	if (x == 2) return div2();
	if (x == -2) {BigInteger res = div2(); res.flag = !res.flag; return res;}
	
	BigInteger res;
	res.flag = !(flag ^ (x >= 0));
	
	digit_t cur = 0, div = std::abs(x);
	res.resize(size);
	
	for (int i = size; i >= 1; i--) {
		cur = cur * BASE + digits[i];
		res.digits[i] = res.flag ? (cur / div) : (-cur / -div);
		cur %= div;
	}
	while (res.size > 1 && res.digits[res.size] == 0) res.pop();
	return res;
}

inline BigInteger BigInteger::move_r(int d) const {
	if (*this == 0 || d >= size) return 0;
	if (d == 0) return *this;
	BigInteger res; res.reserve(size - d + 1);
	for (int i = d + 1; i <= size; i++) res.push(digits[i]);
	return res;
}
inline BigInteger BigInteger::move_l(int d) const {
	if (*this == 0) return 0;
	if (d == 0) return *this;
	BigInteger res; res.reserve(size + d + 1);
	for (int i = 1; i <= d; i++) res.push(0);
	for (int i = 1; i <= size; i++) res.push(digits[i]);
	return res;
}

BigInteger BigInteger::newton_inv(int n) const {
	if (*this == 0) throw ZeroDivisionError();
	if (std::min(size, n - size) <= NEWTON_MIN_LEVEL) {
		BigInteger a; a.resize(n + 1);
		std::memset(a.digits, 0, sizeof(digit_t) * a.size);
		a.digits[n + 1] = 1;
		return a.divmod(*this, true).first;
	}
	int k = (n - size + 5) >> 1, k2 = k > size ? 0 : size - k;
	BigInteger x = move_r(k2);
	int n2 = k + x.size;
	BigInteger y = x.newton_inv(n2), a = y + y, b = (*this) * y * y;
	
	return a.move_l(n - n2 - k2) - b.move_r(2 * (n2 + k2) - n) - 1;
}

std::pair<BigInteger, BigInteger> BigInteger::newton_div(const BigInteger& x) const {
	int k = size - x.size + 5, k2 = k > x.size ? 0 : x.size - k;
	BigInteger x2 = x.move_r(k2);
	if (k2 != 0) x2 += 1;
	int n2 = k + x2.size;
	BigInteger u = (*this) * x2.newton_inv(n2);
	BigInteger q = u.move_r(n2 + k2), r = (*this) - q * x;
	while (r >= x) q += 1, r -= x;
	return std::make_pair(q, r);
}

std::pair<BigInteger, BigInteger> BigInteger::divmod(const BigInteger& x, bool dis_newton) const {
	static const int base = BigInteger::BASE;
	BigInteger a = abs(), b = x.abs();
	if (b == 0) throw ZeroDivisionError();
	if (a < b) return std::make_pair(0, flag ? a : -a);
	if (!dis_newton && size > NEWTON_LIMIT) return newton_div(x);
	
	int t = base / (x.digits[x.size] + 1);
	a *= t, b *= t;
	int n = a.size, m = b.size;
	BigInteger q = 0, r = 0;
	q.resize(n);
	for (int i = n; i >= 1; i--) {
		r *= base, r += a.digits[i];
		digit_t d1 = m < r.size ? r.digits[m + 1] : 0, d2 = m - 1 < r.size ? r.digits[m] : 0;
		int d = (d1 * base + d2) / b.digits[m];
		r -= b * d;
		while (!r.flag) r += b, d--;
		q.digits[i] = d;
	}
	q.flag = !(flag ^ x.flag), r.flag = flag;
	while (q.size > 1 && q.digits[q.size] == 0) q.pop();
	return std::make_pair(q, r / t);
}
BigInteger BigInteger::operator/ (const BigInteger& x) const {return divmod(x).first;}

BigInteger BigInteger::operator% (const long long& x) const {
	if (x == 2) return digits[1] & 1;
	if (x == 5) return digits[1] % 5;
	return *this - (*this / x * x);
} 
BigInteger BigInteger::operator% (const BigInteger& x) const {return divmod(x).second;}
BigInteger BigInteger::pow(const long long& x) const {
	BigInteger res = 1, a = *this;
	for (long long t = x; t != 0; t >>= 1) {
		if (t & 1) res *= a;
		a *= a;
	}
	return res;
}
BigInteger BigInteger::pow(const long long& x, const BigInteger& p) const {
	BigInteger res = 1, a = *this % p;
	for (long long t = x; t != 0; t >>= 1) {
		if (t & 1) res = res * a % p;
		a = a * a % p;
	}
	return res;
}

BigInteger BigInteger::root(const long long& m) const {
	if (*this == 0 || m == 1) return *this;
	static constexpr long long base = BigInteger::BASE;
	BigInteger n = *this, t = base, x = std::min(n, t.move_l((n.size + m) / m));
	int l = 0, r = base - 1;
	while (l < r) {
		int mid = (l + r) >> 1;
		x.digits[x.size] = mid;
		if (x.pow(m) <= n) l = mid + 1;
		else r = mid;
	}
	x.digits[x.size] = l;
	while (x.size > 1 && x.digits[x.size] == 0) x.pop();
	BigInteger x2 = (x * (m - 1) + n / x.pow(m - 1)) / m;
	while (x2 < x) std::swap(x2, x), x2 = (x * (m - 1) + n / x.pow(m - 1)) / m;
	return x;
}

BigInteger BigInteger::gcd(const BigInteger& x) const {
	BigInteger a = *this, b = x;
	if (a < b) std::swap(a, b);
	if (b == 0) return a;
	int t = 0;
	while (a % 2 == 0 && b % 2 == 0) a = a.div2(), b = b.div2(), t++;
	while (b > 0) {
		if (a % 2 == 0) a = a.div2();
		else if (b % 2 == 0) b = b.div2();
		else a -= b;
		if (a < b) std::swap(a, b);
	}
	while (t--) a += a;
	return a;
}
BigInteger BigInteger::lcm(const BigInteger& x) const {return *this / gcd(x) * x;}

BigInteger& BigInteger::operator+= (const BigInteger& x) {return *this = *this + x;}
BigInteger& BigInteger::operator-= (const BigInteger& x) {return *this = *this - x;}
BigInteger& BigInteger::operator*= (const BigInteger& x) {return *this = *this * x;}
BigInteger& BigInteger::operator/= (const long long& x) {return *this = *this / x;}
BigInteger& BigInteger::operator/= (const BigInteger& x) {return *this = *this / x;}
BigInteger& BigInteger::operator%= (const long long& x) {return *this = *this / x;}
BigInteger& BigInteger::operator%= (const BigInteger& x) {return *this = *this % x;}

BigInteger BigInteger::operator<< (const long long& x) {
	if (x <= 0) return *this;
	BigInteger res = *this;
	for (long long i = 1; i <= x; i++) res += res;
	return res;
}
BigInteger BigInteger::operator>> (const long long& x) {
	if (x <= 0) return *this;
	BigInteger res = *this;
	for (long long i = 1; i <= x; i++) res = res.div2();
	return res;
}
BigInteger& BigInteger::operator<<= (const long long& x) {return *this = *this << x;}
BigInteger& BigInteger::operator>>= (const long long& x) {return *this = *this >> x;}

template <class F>
inline BigInteger BigInteger::binary_op_helper(const BigInteger& x, const BigInteger& y, const F& func) {
	auto to_bin = [](BigInteger x) -> std::vector<bool> {
		if (x == 0) return {0};
		std::vector<bool> res;
		for (; x != 0; x = x.div2()) res.emplace_back(x.digits[1] & 1);
		return res;
	};
	std::vector<bool> a = to_bin(x), b = to_bin(y);
	int n = a.size(), m = b.size(), lim = std::max(n, m);
	std::vector<bool> res(lim, 0);
	for (int i = lim - 1; i >= 0; i--) 
		res[i] = func(i < n ? a[i] : 0, i < m ? b[i] : 0);
	std::reverse(res.begin(), res.end());
	return res;
}
BigInteger BigInteger::operator& (const BigInteger& x) {return binary_op_helper(*this, x, [](bool a, bool b) -> bool {return a & b;});}
BigInteger BigInteger::operator| (const BigInteger& x) {return binary_op_helper(*this, x, [](bool a, bool b) -> bool {return a | b;});}
BigInteger BigInteger::operator^ (const BigInteger& x) {return binary_op_helper(*this, x, [](bool a, bool b) -> bool {return a ^ b;});}
BigInteger& BigInteger::operator&= (const BigInteger& x) {return *this = *this & x;}
BigInteger& BigInteger::operator|= (const BigInteger& x) {return *this = *this | x;}
BigInteger& BigInteger::operator^= (const BigInteger& x) {return *this = *this ^ x;}

BigInteger& BigInteger::operator++ () {return *this += 1;}
BigInteger BigInteger::operator++ (int) {BigInteger t = *this; return *this += 1, t;}
BigInteger& BigInteger::operator-- () {return *this -= 1;}
BigInteger BigInteger::operator-- (int) {BigInteger t = *this; return *this -= 1, t;}


using BigInt = BigInteger;
map<int, BigInt> cache;

const BigInt& fib(int n) {
    if (cache.count(n)) return cache[n];
    if (cache.count(n - 1) && cache.count(n - 2)) {
        return cache[n] = cache[n - 1] + cache[n - 2];
    }
    int k = n / 2;
    if (n % 2 == 1) {
        return cache[n] = fib(k) * fib(k) + fib(k + 1) * fib(k + 1);
    } else {
        return cache[n] = fib(k) * (fib(k + 1) + fib(k + 1) - fib(k));
    }
}

vector<const BigInt*> fibRange(const BigInt &l, const BigInt &r, int estLen) {
    vector<const BigInt*> res;
    auto vl = (int)(estLen * 4.73 - 64), vr = (int)(estLen * 4.83 + 64);
    vl = max(vl, 1);
    auto v = views::iota(vl, vr);
    int nl = *ranges::partition_point(v, [&](int n) { return fib(n) < l; });
    while (fib(nl) <= r) {
        res.emplace_back(&fib(nl++));
    }
    return res;
}

template <typename T> vector<pair<T, i64>> runLengthEncoding(const vector<T>& v) {
    if (v.empty()) return {};
    vector<pair<T, i64>> res;
    T prev = v[0];
    int cnt = 1;
    for (int i = 1; i < v.size(); i++) {
        if (v[i] == prev) {
            cnt++;
        } else {
            res.emplace_back(prev, cnt);
            prev = v[i];
            cnt = 1;
        }
    }
    res.emplace_back(prev, cnt);
    return res;
}

vector<pair<BigInt, i64>> runLengthCombine(const vector<pair<BigInt, i64>>& v) {
    if (v.empty()) return {};
    vector<pair<BigInt, i64>> res;
    BigInt prev = v[0].first;
    int cnt = v[0].second;
    for (int i = 1; i < v.size(); i++) {
        if (v[i].first == prev) {
            cnt += v[i].second;
        } else {
            res.emplace_back(prev, cnt);
            prev = v[i].first;
            cnt = v[i].second;
        }
    }
    res.emplace_back(prev, cnt);
    return res;
}

#define int i64
void solve() {
    cache[0] = BigInt("0");
    cache[1] = BigInt("1");
    for (int i = 2; i <= 3000; i++) {
        cache[i] = cache[i - 1] + cache[i - 2];
    }
    int n; cin >> n;
    vector<pair<BigInt, int>> a(n);
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        a[i] = {s, s.size()};
    }
    vector<pair<BigInt, int>> check;
    sort(a.begin(), a.end());
    auto ra = runLengthEncoding(a);
    int ans = 0;
    for (const auto& [p, c]: ra) {
        const auto& [x, l] = p;
        for (const auto &y : fibRange(x + 1, x + x, l)) {
            if (*y == x + x) {
                ans += c * (c - 1) / 2;
            }
            else check.emplace_back(*y - x, c);
        }
    }
    sort(check.begin(), check.end());
    auto rck = runLengthCombine(check);
    int pnt = 0, m = ra.size();
    for (const auto &[x, c]: rck) {
        while (pnt < m && ra[pnt].first.first < x) pnt++;
        if (pnt == m) break;
        if (ra[pnt].first.first == x) {
            ans += c * ra[pnt].second;
        }
    }
    cout << ans << '\n';
}
#undef int

// Make bold hypotheses and verify carefully
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 4972kb

input:

6
50
8
8
5
72
354224848179261915070

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 380ms
memory: 56216kb

input:

28
200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...

output:

27

result:

ok 1 number(s): "27"

Test #3:

score: 0
Accepted
time: 69ms
memory: 33024kb

input:

5187
2640352926124261912741724778991366987330659389621881876017670644497364093930668042530271338851702874394631009332660937266680740235862107353443518003194307853104942996827176097428402408674756368623972812842571069642405111849826172879369776309763468485788964245903781380419155348915131587410703749...

output:

6073

result:

ok 1 number(s): "6073"

Test #4:

score: 0
Accepted
time: 119ms
memory: 20116kb

input:

200000
2
2
2
2
1
2
1
1
2
2
1
1
1
2
2
1
1
2
1
1
2
2
1
2
2
2
1
1
1
1
2
2
1
2
1
2
1
1
2
2
1
1
1
2
1
1
2
1
2
2
2
2
1
2
2
1
1
1
2
1
1
1
1
1
2
1
2
2
1
1
1
2
2
2
1
1
2
1
1
2
1
2
1
1
1
2
2
2
1
1
1
1
2
1
2
1
1
2
2
1
1
2
1
1
2
1
2
2
1
2
1
2
2
1
1
2
1
1
1
2
2
2
1
2
2
1
1
2
2
2
2
1
2
1
1
2
1
2
2
1
1
1
1
2
2
2
2...

output:

15003749259

result:

ok 1 number(s): "15003749259"

Test #5:

score: 0
Accepted
time: 420ms
memory: 107212kb

input:

200000
944176313232170622314
2590599414036674999101
753315073608896000424
9299685298577430049245
9361800333778142620806
8988699166328904060999
9606920674025578304023
4203331868598952026136
5183047027116137697788
3968714342776915029801
8130984095583566992354
3206443643596048048798
6248561214283254355...

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 726ms
memory: 82328kb

input:

200000
9
10
3
5
9
3
3
9
8
5
1
2
7
8
4
6
2
3
3
9
5
5
4
9
7
5
8
2
6
10
9
7
2
2
1
10
10
6
10
7
4
7
9
7
2
2
10
4
5
8
2
2
5
8
9
5
3
9
2
1
7
6
8
8
6
3
8
2
2
9
10
2
9
7
1
9
1
4
5
9
2
7
10
1
8
7
4
8
1
10
6
4
4
9
1
9
7
3
6
5
6
9
5
3
6
6
4
4
6
1
8
6
10
3
10
2
1
4
1
4
8
2
9
1
4
8
10
8
2
2
3
6
4
7
10
10
9
4
7
6...

output:

4388485679

result:

ok 1 number(s): "4388485679"

Test #7:

score: 0
Accepted
time: 438ms
memory: 107052kb

input:

200000
6828421000391895
1989111434563275
5896525738540342
7580233289915833
7220157112714422
6690072177484914
6664449707566084
8245839001391019
3008772159581769
8148007474169818
9400853099859484
6346860654847919
7403109176990407
2581313740335401
1273038733901266
9824983373567665
7206452987542085
7181...

output:

0

result:

ok 1 number(s): "0"

Test #8:

score: 0
Accepted
time: 425ms
memory: 101296kb

input:

200000
163414517
35065810
104946881
686842158
509604537
114869915
194658958
55736013
211143419
526188788
18298540
311113507
727676120
517103071
25044427
38567543
386683792
246028194
750300322
4412101
865997254
674545866
775054146
977862574
699213474
347544102
740489922
632436817
297903184
435135324
...

output:

59

result:

ok 1 number(s): "59"

Test #9:

score: 0
Accepted
time: 1499ms
memory: 160044kb

input:

2
2088564186870382794642016448725374479500907752342156600368614861600912666885211013490310624029649329209019866849808883315545780833167257516031795949145341911463438482795792374909577113387320732207052482556858037878075154734524317145645776084240387870219160545328462016106959746495953786767421892196...

output:

1

result:

ok 1 number(s): "1"

Test #10:

score: 0
Accepted
time: 368ms
memory: 37600kb

input:

200000
6
1
3
9
1
8
9
9
2
6
8
6
2
3
9
2
2
7
4
7
8
8
4
8
2
7
8
9
2
9
2
4
4
1
10
6
2
10
2
6
8
3
10
3
6
10
10
10
2
4
6
4
7
8
1
2
1
1
4
10
5
5
4
10
3
8
5
6
1
7
8
1
2
6
3
8
9
9
5
1
9
5
6
10
9
4
1
7
8
3
10
4
3
2
7
7
9
4
5
6
6
7
8
10
6
6
3
6
8
1
7
4
2
6
10
8
4
2
7
4
2
5
4
9
10
5
2
3
2
4
8
7
9
7
7
8
2
5
7
2
...

output:

4400854684

result:

ok 1 number(s): "4400854684"

Test #11:

score: 0
Accepted
time: 424ms
memory: 102660kb

input:

200000
3118333850638
35270102833223
62994441325054
21050207685515
79452732606523
43405025574846
14676822470608
40589739145551
72610266245240
95906978427970
59399311725881
80286412880911
98171197939601
15555757959003
68766133429050
11529744877477
36884730947747
93994258932707
21245575958503
287958909...

output:

0

result:

ok 1 number(s): "0"

Test #12:

score: 0
Accepted
time: 396ms
memory: 84620kb

input:

200000
1218982
621720
5848120
1753415
5889366
1747270
7735728
8089704
4279399
7927020
9269797
1332511
6334797
8964092
9525679
7325470
1527918
893049
8483303
1134021
8872739
532622
8977450
4503590
6512507
4903981
4892296
6522908
9237430
2297267
8063244
1546378
5054973
8702942
4392067
7868582
2029729
...

output:

5695

result:

ok 1 number(s): "5695"

Test #13:

score: 0
Accepted
time: 1506ms
memory: 159956kb

input:

2
2088564186870382794642016448725374479500907752342156600368614861600912666885211013490310624029649329209019866849808883315545780833167257516031795949145341911463438482795792374909577113387320732207052482556858037878075154734524317145645776084240387870219160545328462016106959746495953786767421892196...

output:

0

result:

ok 1 number(s): "0"

Test #14:

score: 0
Accepted
time: 879ms
memory: 87052kb

input:

7
1337338011484742791299410909385691591046809197321138600848517667449672944525104556519885455609314839827342014896149347803816156838828377155724440687227582622225528496005639283622580269360626125544811511998701746678193286138664078007880894120371020695543061391758951301196457121332483784041873539166...

output:

3

result:

ok 1 number(s): "3"

Test #15:

score: 0
Accepted
time: 1152ms
memory: 123204kb

input:

274
36199225654659696764078634911736913237817300779619275513532816361663892134832409526194170532894366762053993742963156407869241123825595148459428450874407641181641292360313933002704706339921470798414371554709977458935038423965022899542511184991008496997550268720067992926078576871685757638601127765...

output:

273

result:

ok 1 number(s): "273"

Test #16:

score: 0
Accepted
time: 1415ms
memory: 138660kb

input:

200000
4
3
8
5
8
9
4
10
1
3
7
1
3
10
1
10
10
7
8
2
8
9
6
6
1
2
2
6
6
7
10
7
1
3
6
2
8
4
3
3
8
9
4
3
9
6
4
1
6
3
3
5
4
2
3
9
3
3
6
7
6
1
5
5
2
10
2
1
5
9
6
7
3
2
9
1
3
8
8
3
10
7
5
5
6
9
10
8
1
5
6
2
1
8
5
4
1
7
9
9
2
8
9
8
5
7
4
9
3
3
4
7
9
1
8
1
5
9
8
8
7
10
1
4
2
3
7
8
6
1
10
10
8
9
4
10
4
5
5
6
9...

output:

4387062637

result:

ok 1 number(s): "4387062637"

Test #17:

score: 0
Accepted
time: 410ms
memory: 105176kb

input:

200000
8244945625103564139
31587720380738895055
95764870267791202443
90342450187757930095
57990438361916446378
37041843791326956160
92044245094014254241
52147231507776742459
57440162490738372914
75951472709544205529
91095641579841704038
6354859395638708014
13171197741013485755
31875767906879519150
2...

output:

0

result:

ok 1 number(s): "0"

Test #18:

score: 0
Accepted
time: 0ms
memory: 4896kb

input:

10
6
8
6
6
7
6
3
3
2
6

output:

12

result:

ok 1 number(s): "12"

Test #19:

score: 0
Accepted
time: 1519ms
memory: 159928kb

input:

2
2088564186870382794642016448725374479500907752342156600368614861600912666885211013490310624029649329209019866849808883315545780833167257516031795949145341911463438482795792374909577113387320732207052482556858037878075154734524317145645776084240387870219160545328462016106959746495953786767421892196...

output:

0

result:

ok 1 number(s): "0"

Test #20:

score: 0
Accepted
time: 422ms
memory: 105836kb

input:

200000
51732486464
15203118134
55665354475
37097810807
44823788729
92577384010
20189320156
62707564695
81665154265
89603063623
48003727587
14457078372
37230540002
65288477498
52282695470
76070393338
26054936545
14171092817
61770329497
85319218123
57730830347
20295186479
9036398880
63607160628
825711...

output:

1

result:

ok 1 number(s): "1"

Test #21:

score: 0
Accepted
time: 2ms
memory: 5132kb

input:

1000
7
2
6
10
8
6
1
4
5
4
8
6
9
4
1
5
1
5
2
10
6
8
10
10
1
3
4
2
10
1
9
2
7
6
7
9
10
6
9
8
3
2
10
7
6
5
4
3
1
10
5
3
5
1
8
6
5
10
5
7
10
4
9
1
10
9
4
8
8
7
8
5
9
1
5
6
2
10
1
10
9
10
10
10
1
5
3
10
10
3
3
9
10
3
9
1
5
7
6
5
2
9
7
9
10
4
9
1
7
7
5
8
10
8
8
5
5
6
1
5
5
6
10
2
1
1
2
5
9
5
3
5
6
8
5
3
8...

output:

108128

result:

ok 1 number(s): "108128"

Test #22:

score: 0
Accepted
time: 289ms
memory: 61120kb

input:

170297
36618903089511909212027904
295898671290484359833820549055
855922209609024693421257591054
104046893712788281969810034913
294974348216094859258128389147
898675289823399842963411259541
849917444544425201790051381287
554091687601993279655091754543
100543835187751461953816001432
324625661878684349...

output:

669637

result:

ok 1 number(s): "669637"

Test #23:

score: 0
Accepted
time: 1722ms
memory: 141040kb

input:

9
1554055664340235444670436446744662342403532554270354440324316254234564540613440405260344004460144314614345467104554712624142524427154124266304046362254623626323466324132625200314136012323044624260020307414632254233433163613166424734133322715601644464634614352434441422431546266431240655123113002704...

output:

0

result:

ok 1 number(s): "0"

Test #24:

score: 0
Accepted
time: 2ms
memory: 4924kb

input:

30
173224810532175
17167616931584
361
605
17167680176960
956658780060
4052737359577
497497353099204
1548072001901
190392490708530
789347852872433
5
804010804445736
139520616464
43988911432793
4052739537276
514224
2178304
25273161431631
53314112869
17114366064696
20097096794
26821231255228
4944012745...

output:

29

result:

ok 1 number(s): "29"

Test #25:

score: 0
Accepted
time: 212ms
memory: 44788kb

input:

100
11549310117176145486225764017375125851223984720694884717797775426631366931455266419214045399503089615971818090352858567015012529938870819767662704737995190471260542479965705803468920094883954929878415301662741322840828368641397254767329039284292920968364857914289821588505056486091849012400101879...

output:

36

result:

ok 1 number(s): "36"

Test #26:

score: 0
Accepted
time: 243ms
memory: 74092kb

input:

100223
94009034043768394308211497706411911232935573312371
90700235808140495519523074128684120917303691406421
72874906060637684247409916135076680433361225881761
80161826274205256086415063126094978143520789283159
98145703778166390989463238108464755254200147417281
70995217131009339533392756476859088949...

output:

0

result:

ok 1 number(s): "0"

Test #27:

score: 0
Accepted
time: 0ms
memory: 5096kb

input:

6
50
8
8
5
72
354224848179261915070

output:

4

result:

ok 1 number(s): "4"

Test #28:

score: 0
Accepted
time: 219ms
memory: 59208kb

input:

3161
7
14
130
1467
16244
105149
1241120
13689232
151890909
1684420994
10901848031
128682014414
1419326741506
15748353436059
101920677024935
1203048867903722
13269285156772499
147231358659594589
1632748057345119600
10567412357776757138
124734439986929988911
1375786096219966094366
15265241654400597567...

output:

3160

result:

ok 1 number(s): "3160"

Test #29:

score: 0
Accepted
time: 408ms
memory: 101524kb

input:

200000
7930099016
7136448262
4599143849
4725192685
4685680672
739140078
7214691825
5031750793
4820916507
6017675339
485443032
2327198454
8808146518
7746012012
713572475
4706110510
3560774990
7482541413
8975601524
3896030632
3018545943
7048325939
2370597692
7867568189
6902951191
333917381
112842576
9...

output:

7

result:

ok 1 number(s): "7"

Test #30:

score: 0
Accepted
time: 31ms
memory: 9316kb

input:

60123
4
3
4
7
5
7
5
1
2
6
9
10
7
4
2
1
8
6
4
6
4
2
8
6
2
8
5
4
5
7
1
10
7
5
1
9
7
4
8
8
8
5
2
6
8
4
6
4
9
7
3
9
5
6
2
8
10
2
10
2
1
4
9
5
10
9
7
2
1
9
3
9
10
1
8
7
6
5
7
1
4
10
5
9
8
10
4
10
4
9
3
7
4
4
10
4
1
7
4
10
4
9
10
2
2
8
3
7
1
1
6
4
10
9
9
4
8
3
4
7
5
7
6
10
10
2
8
1
8
10
6
9
4
7
3
8
2
5
6
...

output:

399686351

result:

ok 1 number(s): "399686351"

Test #31:

score: 0
Accepted
time: 2ms
memory: 4968kb

input:

20
11142320330634256153203413422244004724022423010341634226101444226235404243251
1510233372263004374041444256322353356243032432623343544033530634305504714430614564334410564323262245
3315442551434205740422347432544540327016564444656542244600440525402604662333366
53153452623340724302644316423336472713...

output:

0

result:

ok 1 number(s): "0"

Test #32:

score: 0
Accepted
time: 2ms
memory: 4976kb

input:

15
9227465
832040
701408733
2178309
267914296
433494437
165580141
1346269
5702887
3524578
102334155
24157817
14930352
63245986
39088169

output:

14

result:

ok 1 number(s): "14"

Test #33:

score: 0
Accepted
time: 32ms
memory: 12952kb

input:

10011
5327909559109070794570420158512927656597532686406620479564191583982981578330651724849734045529811497
9659152635523321620063357842120653540264735554377366787893904211734024058449827205523008852363337860
74727969709789190305111991663528709940303307406256850364862896747520682645094217166643105732...

output:

0

result:

ok 1 number(s): "0"

Test #34:

score: 0
Accepted
time: 63ms
memory: 22360kb

input:

10051
63063334260332707210045601560460743222655443603043556526226343270234640534370464564114515210165526527443654044521634373434642424304154632545440427364312534131536671541443033313334224226302334143144172200431314323334240461563243422303322351122343066463334623434
625665325411647124616714317265541...

output:

14

result:

ok 1 number(s): "14"

Test #35:

score: 0
Accepted
time: 423ms
memory: 105560kb

input:

200000
3231427058997
5671035772108
505876205893
9869979702346
336233080766
4805367039084
270125613380
929924360332
6390838551951
1896341268898
3923051450784
397979630166
6527843499305
1937207519921
9355189911971
953387547771
5307619807657
6689006266290
517624961010
1532034993156
1921439567851
331239...

output:

0

result:

ok 1 number(s): "0"

Test #36:

score: 0
Accepted
time: 2493ms
memory: 216524kb

input:

30
167491015938836604073444715975948275020752570351918554475806772549228015468626967999929915531115950274814727218152384400389926950026165552262394643249255747252904223055992443689134599380405599101636105379410012227917206510976118633243994494607279010051579617303878166798657109212106136099974387457...

output:

29

result:

ok 1 number(s): "29"

Test #37:

score: 0
Accepted
time: 228ms
memory: 37112kb

input:

200000
31520
9835
67679
91981
37157
27950
36846
70635
13880
18818
52443
46788
38014
56271
48270
28452
36146
82523
60850
55346
16869
95814
89245
98640
40746
68625
53391
63023
4402
36521
95532
52344
24072
70060
11619
12227
98964
78211
95010
83216
22122
46697
31271
85556
57237
82689
92115
88247
9186
85...

output:

555586

result:

ok 1 number(s): "555586"

Test #38:

score: 0
Accepted
time: 1311ms
memory: 135628kb

input:

2
7471143542670631923583760838674866685142093708045228091216520373087113961892117195149240140968159205634006625906479367372855893882103887377565868731323681755476477285090435798416695243644387513257156317699123267511524797133211810893688279220755514610253525742595752854587254548452737426517576583616...

output:

1

result:

ok 1 number(s): "1"

Test #39:

score: 0
Accepted
time: 47ms
memory: 10832kb

input:

80000
6
4
5
5
4
5
9
8
5
6
2
2
1
10
6
9
4
10
6
5
3
4
3
3
4
5
10
2
6
4
6
2
6
2
4
7
9
6
6
8
1
1
7
10
10
2
7
2
2
9
8
5
4
9
1
5
7
4
7
7
6
7
7
9
8
9
9
4
10
7
2
9
9
9
4
2
8
4
9
1
3
9
1
4
2
1
2
4
3
2
1
10
5
7
10
5
9
3
6
3
4
4
1
8
1
8
10
8
6
6
2
5
1
3
6
8
2
2
10
6
6
3
2
6
3
8
4
10
8
10
3
9
9
2
8
8
10
4
5
5
7...

output:

706251650

result:

ok 1 number(s): "706251650"

Test #40:

score: 0
Accepted
time: 1374ms
memory: 138852kb

input:

200000
9
1
4
4
5
2
4
9
7
5
3
6
6
8
4
7
2
1
9
10
8
2
1
4
9
3
10
8
1
5
5
8
2
9
3
1
9
3
9
4
9
10
4
5
4
4
2
1
1
7
5
7
7
3
6
8
10
6
4
1
5
2
5
5
9
4
10
2
10
7
9
5
2
7
4
9
7
5
2
1
4
7
6
7
10
9
10
2
10
4
9
1
7
5
7
3
1
4
5
2
6
6
2
4
8
8
7
9
10
4
10
2
1
10
10
5
10
1
1
6
7
8
8
7
5
8
3
8
1
1
10
8
9
10
7
3
8
6
4...

output:

4417250451

result:

ok 1 number(s): "4417250451"

Test #41:

score: 0
Accepted
time: 158ms
memory: 42628kb

input:

84752
86009844223237105273313186367406421847273312848013100091343
340516459610995530579473198046278412250343444815876655725270
62236463822700922600990709332929319814536375509143833251557
5611500219672931601067284378715174151735452175901717138530
64201778346042476353565735947990316834224189505881
609...

output:

420579

result:

ok 1 number(s): "420579"

Test #42:

score: 0
Accepted
time: 391ms
memory: 102644kb

input:

200000
7127173784651987052
4249291679502906721
9703708230592019478
4404701921242244700
2344941043578422215
3091914365064271594
9867051863259427168
9880844309023770200
7211977710785226267
1694381065563438860
201683809955321192
4085536489000602058
7553409623903962290
4033981640350364868
54455660173955...

output:

0

result:

ok 1 number(s): "0"

Test #43:

score: 0
Accepted
time: 1613ms
memory: 157248kb

input:

200000
9
9
2
10
3
4
3
9
7
7
8
5
9
9
7
5
8
5
7
1
5
6
3
2
7
5
7
7
2
9
8
6
2
1
8
1
3
4
10
2
3
4
4
7
4
10
8
6
1
5
3
3
3
5
5
8
6
9
3
6
5
4
2
8
10
9
1
5
1
4
8
9
4
3
4
9
10
3
6
2
10
3
3
6
6
7
4
9
5
2
1
8
8
7
308061521170126
7
4
6
1
9
3
9
9
3
1
10
8
7
2
9
10
6
2
6
10
8
5
1
5
1
7
9
5
3
6
1
4
2
6
2
8
5
3
1
6
...

output:

4397248166

result:

ok 1 number(s): "4397248166"

Test #44:

score: 0
Accepted
time: 211ms
memory: 30276kb

input:

156
18459619692692557705784877669569448552986613407875981372394172107449477143544507182981317111359110933094916231296859516709399078435198069511763391151449973008095601542066128297192521457018669738382503324519683244087838172215626103362576668917140635977557324975206273718561053735845026938082217687...

output:

155

result:

ok 1 number(s): "155"

Test #45:

score: 0
Accepted
time: 1442ms
memory: 141284kb

input:

200000
1
10
4
3
10
1
9
5
9
4
9
1
6
6
1
7
2
1
10
3
2
3
4
7
7
3
9
9
10
3
4
10
10
7
7
2
5
10
9
6
8
1
4
4
5
8
8
6
5
10
10
9
10
9
5
1
7
6
5
10
2
4
1
7
10
6
7
8
2
3
3
10
1
7
6
10
2
7
1
9
6
10
8
4
7
3
9
1
6
9
2
3
4
8
7
8
3
6
4
10
2
2
1
9
7
2
2
8
2
1
2
10
5
4
10
9
9
7
9
4
3
10
9
1
2
9
9
2
7
1
6
7
10
6
5
9
6...

output:

4407433502

result:

ok 1 number(s): "4407433502"

Test #46:

score: 0
Accepted
time: 132ms
memory: 42128kb

input:

51002
376123568879569384290612536925367837315702704676220875375604948366932308891841579226324979782110
28623980260058260408921525210046136035459718869538444006842678034295486291710095655185249062457587
21690449377523978494384257361181223226054780834691728496618681724478608654823982012150023238151530...

output:

81486

result:

ok 1 number(s): "81486"

Test #47:

score: 0
Accepted
time: 426ms
memory: 104488kb

input:

200000
478606336755874083
603529542039676573
240066379679942455
20635508638460497
945472883349378253
395868479387568634
865948317871000880
136079313625171264
764680881358360622
195117422398549932
143437863196805305
907507515211279442
723479709912499971
671617918537158715
439287855279754360
202716825...

output:

0

result:

ok 1 number(s): "0"

Test #48:

score: 0
Accepted
time: 1703ms
memory: 135568kb

input:

19
114661534643152246311744033174352334643324503262044605562234546544736534426056314403004340112331342520053464440541422433562206354434233744572233143044234304056542423441346156352252422334142225474302135741207345424432300443162054415443457163346015613444533444074633135446264371437171714063445404655...

output:

0

result:

ok 1 number(s): "0"

Test #49:

score: 0
Accepted
time: 424ms
memory: 105640kb

input:

200000
497856383454
506720870857
899176487457
12145678485
541966940864
272264831455
178825186059
7038707436
481602633783
181735126537
559631305498
335603421321
761406732158
369431205173
615437274239
923671138603
543441698085
733638673698
858564208935
726626729204
880133143653
415511404815
9211110013...

output:

1

result:

ok 1 number(s): "1"

Test #50:

score: 0
Accepted
time: 3711ms
memory: 254156kb

input:

5
2011068126132617886949194530211424837999019187297342375967282498616949073685995418305378991927261698758022155241855161670361072821581948280878066032787805987660111096801265330758292151243775781982581126595354464038574958455139626266660161003165949122588221798586300395825356961553839057885407409810...

output:

4

result:

ok 1 number(s): "4"

Test #51:

score: 0
Accepted
time: 116ms
memory: 20108kb

input:

200000
91
67
28
7
87
97
87
80
71
5
67
1
98
85
60
62
99
46
9
81
10
7
15
91
74
69
11
34
85
47
56
48
29
16
25
5
46
9
73
24
84
10
97
22
78
18
29
70
92
98
61
43
54
66
55
15
77
20
25
16
84
11
93
65
61
91
18
59
31
93
53
33
34
59
90
41
21
27
82
49
33
64
96
18
46
71
94
95
30
62
47
9
62
79
29
28
65
67
32
48
9...

output:

591328867

result:

ok 1 number(s): "591328867"

Extra Test:

score: 0
Extra Test Passed