| f | from decimal import Decimal, getcontext, ROUND_HALF_UP | f | from decimal import Decimal, getcontext, ROUND_HALF_UP | 
             | import sys |  | import sys | 
             |  |  |  | 
            | n | def compute_pi(prec): | n | def compute_pi(precision): | 
             |     getcontext().prec = prec + 5 |  |     getcontext().prec = precision + 5 | 
             |     C = 426880 * Decimal(10005).sqrt() |  |     coeff = 426880 * Decimal(10005).sqrt() | 
             |     M = Decimal(1) |  |     M = Decimal(1) | 
             |     L = Decimal(13591409) |  |     L = Decimal(13591409) | 
             |     X = Decimal(1) |  |     X = Decimal(1) | 
             |     K = Decimal(6) |  |     K = Decimal(6) | 
            | n |     S = L | n |     total_sum = L | 
             |     for k in range(1, prec): |  |     for k in range(1, precision): | 
             |         M = M * (K ** 3 - 16 * K) / k ** 3 |  |         M = M * (K ** 3 - 16 * K) / k ** 3 | 
             |         L += 545140134 |  |         L += 545140134 | 
             |         X *= -262537412640768000 |  |         X *= -262537412640768000 | 
             |         term = M * L / X |  |         term = M * L / X | 
            | n |         S += term | n |         total_sum += term | 
             |         if term == 0: |  |         if term == 0: | 
             |             break |  |             break | 
             |         K += 12 |  |         K += 12 | 
            | n |     pi = C / S | n |     return coeff / total_sum | 
             |     return pi |  |  | 
             |  |  |  | 
            | n | def sin_series(x, terms): | n | def series_sine(x, num_terms): | 
             |     getcontext().prec += 2 |  |     getcontext().prec += 2 | 
             |     x_power = x |  |     x_power = x | 
             |     factorial = Decimal(1) |  |     factorial = Decimal(1) | 
            | n |     sin_x = x | n |     sine_result = x | 
             |     sign = -1 |  |     sign = -1 | 
            | n |     for i in range(3, terms * 2, 2): | n |     for i in range(3, num_terms * 2, 2): | 
             |         x_power *= x * x |  |         x_power *= x * x | 
             |         factorial *= i * (i - 1) |  |         factorial *= i * (i - 1) | 
             |         term = x_power / factorial |  |         term = x_power / factorial | 
            | n |         sin_x += sign * term | n |         sine_result += sign * term | 
             |         sign *= -1 |  |         sign *= -1 | 
             |         if term == 0: |  |         if term == 0: | 
             |             break |  |             break | 
             |     getcontext().prec -= 2 |  |     getcontext().prec -= 2 | 
            | n |     return +sin_x | n |     return +sine_result | 
             |  |  |  | 
            | n | def cos_series(x, terms): | n | def series_cosine(x, num_terms): | 
             |     getcontext().prec += 2 |  |     getcontext().prec += 2 | 
             |     x_power = Decimal(1) |  |     x_power = Decimal(1) | 
             |     factorial = Decimal(1) |  |     factorial = Decimal(1) | 
            | n |     cos_x = Decimal(1) | n |     cosine_result = Decimal(1) | 
             |     sign = -1 |  |     sign = -1 | 
            | n |     for i in range(2, terms * 2, 2): | n |     for i in range(2, num_terms * 2, 2): | 
             |         x_power *= x * x |  |         x_power *= x * x | 
             |         factorial *= i * (i - 1) |  |         factorial *= i * (i - 1) | 
             |         term = x_power / factorial |  |         term = x_power / factorial | 
            | n |         cos_x += sign * term | n |         cosine_result += sign * term | 
             |         sign *= -1 |  |         sign *= -1 | 
             |         if term == 0: |  |         if term == 0: | 
             |             break |  |             break | 
             |     getcontext().prec -= 2 |  |     getcontext().prec -= 2 | 
            | n |     return +cos_x | n |     return +cosine_result | 
             |  |  |  | 
            | n | def round_to_significant_digits(x, digits): | n | def significant_digit_round(value, digits): | 
             |     if x.is_zero(): |  |     if value.is_zero(): | 
             |         return Decimal(0) |  |         return Decimal(0) | 
             |     else: |  |     else: | 
            | n |         sign, digits_tuple, exponent = x.as_tuple() | n |         sign, digits_tuple, exponent = value.as_tuple() | 
             |         num_digits = len(digits_tuple) |  |         num_digits = len(digits_tuple) | 
             |         adjusted_exponent = exponent + num_digits - digits |  |         adjusted_exponent = exponent + num_digits - digits | 
             |         quantize_exp = Decimal('1e{}'.format(adjusted_exponent)) |  |         quantize_exp = Decimal('1e{}'.format(adjusted_exponent)) | 
            | n |         return x.quantize(quantize_exp, rounding=ROUND_HALF_UP) | n |         return value.quantize(quantize_exp, rounding=ROUND_HALF_UP) | 
             |  |  |  | 
            | n | def main(): | n | def perform_calculations(): | 
             |     A = Decimal(sys.stdin.readline().strip()) |  |     angle_degrees = Decimal(sys.stdin.readline().strip()) | 
             |     E = int(sys.stdin.readline().strip()) |  |     precision = int(sys.stdin.readline().strip()) | 
             |     if E < 4 or E > 1000: |  |     if precision < 4 or precision > 1000: | 
             |         print('Precision E must be between 4 and 1000') |  |         print('Precision must be between 4 and 1000') | 
             |         return |  |         return | 
            | n |     getcontext().prec = E + 10 | n |     getcontext().prec = precision + 10 | 
             |     pi = compute_pi(getcontext().prec) |  |     pi_result = compute_pi(getcontext().prec) | 
             |     angle_rad = A * pi / Decimal(200) |  |     angle_radians = angle_degrees * pi_result / Decimal(200) | 
             |     terms = E + 5 |  |     terms_required = precision + 5 | 
             |     sin_x = sin_series(angle_rad, terms) |  |     sine_value = series_sine(angle_radians, terms_required) | 
             |     cos_x = cos_series(angle_rad, terms) |  |     cosine_value = series_cosine(angle_radians, terms_required) | 
             |     tan_x = sin_x / cos_x |  |     tangent_value = sine_value / cosine_value | 
             |     tan_x = round_to_significant_digits(tan_x, E) |  |     tangent_value = significant_digit_round(tangent_value, precision) | 
             |     tan_str = '{0}'.format(tan_x.normalize()) |  |     tangent_string = '{0}'.format(tangent_value.normalize()) | 
             |     if '.' in tan_str: |  |     if '.' in tangent_string: | 
             |         integer_part, fractional_part = tan_str.split('.') |  |         integer_part, fractional_part = tangent_string.split('.') | 
             |         significant_digits = len(integer_part.lstrip('-') + fractional_p |  |         significant_digits = len(integer_part.lstrip('-') + fractional_p | 
             | art) |  | art) | 
             |     else: |  |     else: | 
            | n |         integer_part = tan_str.lstrip('-') | n |         integer_part = tangent_string.lstrip('-') | 
             |         significant_digits = len(integer_part) |  |         significant_digits = len(integer_part) | 
            | n |     if significant_digits < E: | n |     if significant_digits < precision: | 
             |         zeros_needed = E - significant_digits |  |         zeros_needed = precision - significant_digits | 
             |         if '.' in tan_str: |  |         if '.' in tangent_string: | 
             |             tan_str += '0' * zeros_needed |  |             tangent_string += '0' * zeros_needed | 
             |         else: |  |         else: | 
            | n |             tan_str += '.' + '0' * zeros_needed | n |             tangent_string += '.' + '0' * zeros_needed | 
             |     print(tan_str) |  |     print(tangent_string) | 
             | if __name__ == '__main__': |  | if __name__ == '__main__': | 
            | t |     main() | t |     perform_calculations() |