#!/usr/bin/env python3 # Formula acquired by fiddling in a spreadsheet. Not 100% sure about the mathematical reasoning behind it, # but it appears to generate lists of integers in which each pair only occurs once, so I guess it works 🤷 sets = [{(j + (i % 30) * 30 + ((i // 30 * j) % 31) * 30) % 930 + 1 for j in range(30)} for i in range(601)] if input() == "send": print(*sets[int(input())]) else: a, b = map(int, input().split()) # Why learn how to reverse a formula, if we can simply check for all sets where this pair originates from? 😄 print(next(i for i, s in enumerate(sets) if a in s and b in s))