<jupyter_start><jupyter_text>[10077 - The Stern-Brocot Number System](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=1018) Tips and tricks at the end  Input<jupyter_code>%%file 1.in
5 7
878 323
1 1<jupyter_output>Writing 1.in<jupyter_text>The programming contest way?<jupyter_code>%%file 1.py

# This is pretty much binary search
def solve(m, n, ml, nl, mr, nr):
  mc, nc = ml + mr, nl + nr
  if m == mc and n == nc:
    print()
    return

  if m/n > mc/nc:
    print("R", end='')
    solve(m, n, mc, nc, mr, nr)
  else:
    print("L", end='')
    solve(m, n, ml, nl, mc, nc)

def main():
  while True:
    m, n = map(int, input().split())
    if m == 1 and n == 1:
      break
    solve(m, n, 0, 1, 1, 0)

if __name__ == "__main__":
    main()
!python 1.py < 1.in<jupyter_output>LRRL
RRLRRLRLLLLRLRRR<jupyter_text>The ipynb way<jupyter_code>def solve(m, n, ml, nl, mr, nr):
  mc, nc = ml + mr, nl + nr       # 4
  if m == mc and n == nc:         # 3
    print()                       # 1
    return

  if m/n > mc/nc:                 # 3 + max(then, else)
    print("R", end='')            # 2
    solve(m, n, mc, nc, mr, nr)   # T(n/2)
  else:
    print("L", end='')            # 2
    solve(m, n, ml, nl, mc, nc)   # T(n/2)<jupyter_output><empty_output><jupyter_text>$ T(n) = 4 + 3 + 1 + 3 + 2 + T(n/2) $$ T(n) = T(n/2) + 13 $$ T(n) = T(n/2) + O(1) $$ a = 1, b = 2, k = 0 $$ T(n) = O(n^0 log(n)) $$ T(n) = O(log (n)) $<jupyter_code>with open('1.in') as file:
  for line in file:
    m, n = map(int, line.split())
    if not (m == 1 and n == 1):
      solve(m, n, 0, 1, 1, 0)<jupyter_output>LRRL
RRLRRLRLLLLRLRRR<jupyter_text>Tips and tricks Supress the `newline` at the end from print<jupyter_code>print("Hey! there's a newline or ascii \\n at the end automátically")
print("see?")

print("Now, with end='' we skip the newline", end='')
print("<- See?")<jupyter_output>Hey! there's a newline or ascii \n at the end automátically
see?
Now, with end='' we skip the newline<- See?<jupyter_text>Reading input, aptly known as standard input or stdin for short.<jupyter_code>var = input("Come on! try typing something and then press enter")
print("This is what you wrote (very creative... I see):", var)<jupyter_output>Come on! try typing something and then press enterasdfdalsdk asdf
This is what you wrote (very creative... I see): asdfdalsdk asdf<jupyter_text>Now how about we read a couple of integers. First, `input()` always reads the whole line as a string. So we need to `split()` it and convert every element into the desired type. However if all the elements are of the same type, we can use the `map()` function. Here try typing `1 2` and then hit enter"<jupyter_code>a, b = map(int, input().split())
print(f"{a}+{b}={a+b}")<jupyter_output>1 2
1+2=3
{'fraction_non_alphanumeric': 0.15898535191139693, 'fraction_numerical': 0.024294390853876385, 'mean_word_length': 3.3209876543209877, 'pattern_counts': {'":': 1, '<': 26, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '159139', 'license': 'CC0-1.0', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1122, 'n_words': 365, 'path': 'notebooks/ah_divide_n_conquer_stern_brocot.ipynb', 'repo_name': 'AgustinAMaita/DataSet', 'size': '2799'}