Problem:
 Score: 600 points    Problem Statement  AtCoder's head office consists of N rooms numbered 1 to N . For any two rooms, there is a direct passage connecting these rooms.  For security reasons, Takahashi the president asked you to set a level for every passage, which is a positive integer and must satisfy the following condition:   For each room i\ (1 \leq i \leq N) , if we leave Room i , pass through some passages whose levels are all equal and get back to Room i , the number of times we pass through a passage is always even.   Your task is to set levels to the passages so that the highest level of a passage is minimized.      Constraints   N is an integer between 2 and 500 (inclusive).         Input  Input is given from Standard Input in the following format:  N       Output  Print one way to set levels to the passages so that the objective is achieved, as follows:  a_{1,2}  a_{1,3}  ...  a_{1,N}  a_{2,3}  ...  a_{2,N}  .  .  .  a_{N-1,N}   Here a_{i,j} is the level of the passage connecting Room i and Room j .  If there are multiple solutions, any of them will be accepted.        Sample Input 1 3      Sample Output 1 1 2
1  The following image describes this output:   For example, if we leave Room 2 , traverse the path 2 \to 3 \to 2 \to 3 \to 2 \to 1 \to 2 while only passing passages of level 1 and get back to Room 2 , we pass through a passage six times.

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
tmpl = list(range(1,N+1))

lines = [[0]*(N+1) for _ in range(N+1)]

def solve(tmpl,cnt):
    global lines

    L = len(tmpl)
    if L == 1:
        return

    aa,bb = tmpl[:L//2],tmpl[L//2:]
    for a in aa:
        for b in bb:
            if a < b:
                lines[a][b] = str(cnt)
            else:
                lines[b][a] = str(cnt)

    solve(aa,cnt+1)
    solve(bb,cnt+1)

solve(tmpl,1)

for i in range(1,N):
    print(' '.join(lines[i][i+1:N+1]))

Solution (Python):
n = int(input())
g = [[0]*n for i in range(n)]
for s in range(n-1):
  for t in range(s+1,n):
    i,j = s,t
    ed = 1
    while j-i > 3:
      ed += 2
      i //= 4
      j //= 4
    g[s][t] = ed + 1 - (j-i)%2
for i in range(n):
  print(" ".join(map(str,g[i][i+1:])))

Solution (Python):


def main():
    N = int( input())
    ANS = [ [0]*N for _ in range(N)]
    for i in range(11):
        if N <= pow(2,i):
            M = i
            break
    
    
    
    for t in range(1,M+1):
        w = pow(2,t-1)
        for s in range(1,N+1, 2):
            if w*s >= N:
                break
            for i in range(N-s*w):
                if ANS[i][i+w*s] == 0:
                    ANS[i][i+w*s] = t
    for i in range(N-1):
        print( " ".join( map( str, ANS[i][i+1:])))
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = [[0]*N for i in range(N)]
for i in range(N):
    for k in range(10):
        for j in range(2**k-1,N-i-1,2**(k+1)):
            A[i][j] = k+1
for i in A[:-1]:
    for j in i:
        if j == 0:
            break
        print(j,end = " ")
    print()

Solution (Python):



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())



ans = [[0]*n for i in range(n)]

L = list(range(n))
def iro(a,b,l): 
    if b-a <= 1: return 
    mid = a + (b-a)//2
    for i in L[a:mid]:
        for j in L[mid:b]:
            ans[i][j] = l
    iro(a,mid,l+1)
    iro(mid,b,l+1)



iro(0,n,1)


for i,ai in enumerate(ans[:-1]):
    print(*ai[i+1:])

Solution (Python):
def f(V, k):
    n = len(V)
    for i in range(0, n, 2):
        for j in range(1, n, 2):
            Ans.append((V[i], V[j], k))
    V1 = [V[i] for i in range(0, n, 2)]
    V2 = [V[i] for i in range(1, n, 2)]
    if len(V1) > 1:
        f(V1, k+1)
    if len(V2) > 1:
        f(V2, k+1)

N = int(input())
V = list(range(1, N+1))
Ans = []
k = 1
f(V, 1)

Edge = [[None]*(N+1) for _ in range(N+1)]

for i, j, c in Ans:
    Edge[i][j] = c
    Edge[j][i] = c

for i in range(1, N):
    print(*Edge[i][i+1:])

Solution (Python):
from functools import lru_cache
N = int(input())


@lru_cache(maxsize=1000)
def get_v(i, j, c, r):

    if i < c // 2 <= j:
        return r
    elif j < c // 2:
        return get_v(i, j, c // 2, r + 1)
    else:
        return get_v(i - c // 2, j - c // 2, c - c // 2, r + 1)


for k in range(N - 1):
    print(*[get_v(k, m, N, 1) for m in range(k + 1, N)])

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)





N = int(input())

for i in range(1,N):
    row = []
    for j in range(i+1,N+1):
        k=1
        bit = 1
        while (i&bit) == (j&bit):
            k += 1
            bit <<= 1
        row.append(k)
    print(*row)

Solution (Python):
from itertools import product

def solve(l, r, offset=1):
    size = r-l
    if size==2:
        Ans[l][l+1] = offset
    elif size==3:
        Ans[l][l+1] = offset
        Ans[l][l+2] = offset
        Ans[l+1][l+2] = offset+1
    else:
        c = (l+r)//2
        solve(l, c, offset+1)
        solve(c, r, offset+1)
        for a, b in product(range(l, c), range(c, r)):
            Ans[a][b] = offset

N = int(input())
Ans = [[0]*N for _ in range(N)]
solve(0, N)
for i, a in enumerate(Ans, 1):
    print(" ".join(map(str, a[i:])))

Solution (Python):
N = int(input())

L = [[0] * N for _ in range(N)]

def nasu(l, r, x):
  if l == r:
    return
  if r - l == 1:
    return
  m = (r + l) // 2
  for i in range(l, m):
    for j in range(m, r):
      L[i][j] = x
  nasu(l, m, x + 1)
  nasu(m, r, x + 1)

nasu(0, N, 1)

for i in range(N - 1):
  t = ""
  for j in range(i + 1, N - 1):
    t += str(L[i][j]) + " "
  t += str(L[i][N - 1])
  print(t)