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.



Sample input:
3


Sample output:
1 2
1

Submission status: Wrong Answer

Solution code:
from collections import deque
N=int(input())
if N%2==1:
    a=[[0 for j in range(N-i-1)] for i in range(N-1)]
    K=N//2
    #i->j(i<j)
    #a[i-1][j-i-1]
    for k in range(1,K+1):
        x=1
        for i in range(N-1):
            y,x=x,(x+k)%N
            if x==0:
                x=N
            if y==0:
                y=N
            p,q=min(x,y),max(x,y)
            #print(k,i,p,q,x,y)
            a[p-1][q-p-1]=k

    for i in range(N-1):
        for j in range(N-i-1):
            if a[i][j]==0:
                a[i][j]=K+1
    for i in range(N-1):
        print(*a[i])
else:
    K=N//2
    q=deque([i for i in range(1,N+1)])
    X=[]
    X.append(q.popleft())
    X.append(q.popleft())
    index=0
    while(len(q)>0):
        if index%2==0:
            X.append(q.pop())
        else:
            X.append(q.popleft())
        index+=1
    print(X)
    a=[[0 for j in range(N-i-1)] for i in range(N-1)]
    for k in range(K):
        for i in range(N-1):
            x,y=(X[i]+k)%N,(X[i+1]+k)%N
            if x==0:
                x=N
            if y==0:
                y=N
            p,q=min(x,y),max(x,y)
            a[p-1][q-p-1]=k+1
    for i in range(N-1):
        print(*a[i])

Submission status: Wrong Answer

Solution code:
import math
N = int(input())


if(N < 5):
    for i in range(1,N):
        ansList = []
        for j in range(i+1,N+1):
            if((i+j) % 2 == 1):
                ansList.append(1)
            else:
                ansList.append(2)
        print(' '.join(map(str, ansList)))
elif(N%2 == 0):
    for i in range(1,N):
        ansList = []
        for j in range(i+1,N+1):
            dif = j-i
            num = 0
            while(1):
                num += 1
                if(dif % 2 == 1):
                    break
                dif = dif // 2
            ansList.append(num)
        print(' '.join(map(str, ansList)))
else:
    for i in range(1,N):
        ansList = []
        for j in range(i+1,N+1):
            dif = j-i
            if(j == N):
                ansList.append(math.ceil(math.log2(N+2)))
            else:
                num = 0
                while(1):
                    num += 1
                    if(dif % 2 == 1):
                        break
                    dif = dif // 2
                ansList.append(num)
        print(' '.join(map(str, ansList)))

Submission status: Wrong Answer

Solution code:
N=int(input())
for i in range(N-1):
    print(*[i+1 for i in range(N-i-1)])

Submission status: Wrong Answer

Solution code:
n = int(input())
even = [[1]]
odd = [[2,2],[1]]
if n % 2 == 0:
  for i in range(n//2-1):
    last = even
    even = []
    for x in last:
      even.append(x + [i+2,i+2])
    even.append([i+2,i+2])
    even.append([1])
  for x in even:
    print(' '.join(list(map(str,x))))
else:
  for i in range(n//2-1):
    last = odd
    odd = []
    for x in last:
      odd.append(x + [i+3,i+3])
    odd.append([i+3,i+3])
    odd.append([1])
  for x in odd:
    print(' '.join(list(map(str,x))))

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n - 1):
  for j in range(n - 1 - i):
    print(j + 1, " ", end='')
  print('')

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[1,2]*n
for i in range(n):
    print(*l[:n-i-1])

Submission status: Wrong Answer

Solution code:
#D問題
N = int(input())

odd = []
for i in range(N):
    if i%2 == 0:
        pass
    else:
        if i == 1:
            odd.append(2)
        else:
            old = odd[-1]
            if odd.count(old) >= old-1:
                odd.append(old+1)
            else:
                odd.append(2)

for i in range(N-1):
    for j in range(N-i-1):
        if j%2 == 0:
            print(1,end=" ")
        else:
            print(odd[(j-1)//2],end=" ")
    print()

Submission status: Wrong Answer

Solution code:
N = int(input())

N = N-1
j = 1
for i in range(0,N):
	if i % 2 == 0:
		print(" ".join(map(str,[j+1] +[j] * (N-i-1) )))
	else:
		print(" ".join(map(str,[j]*(N-i))))
		j+=1

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n-1):
    x=[str(j+1) for j in range(n-i-1)]
    print(" ".join(x))

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = [[-1]*N for i in range(N)]

for i in range(N-1):
    for j in range(i,N):
        if (j-i)%2:
            ans[i][j] = 1
        else:
            ans[i][j] = 2

if N%2 and N>3:
    ans[0][-1] = 3

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

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
    print(*range(1,n-i))

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(1,n+1):
    for j in range(i+1,n+1):
        print(i, end=' ')
    print()

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()

used = [[False]*n for _ in range(n)]
ans = [[-1]*n for _ in range(n)]

complete = (n*(n-1)//2) // (n-1)


for pitch in range(1, complete + 1):
    cnt = 0
    bef = 0
    while cnt < n-1:
        nex = bef + pitch
        src = min(bef, nex%n)
        dst = max(bef, nex%n)

        ans[src][dst] = pitch
        used[src][dst] = True
        bef = nex%n

        cnt += 1

for i in range(n):
    for j in range(i+1, n):
        if not used[i][j]:
            ans[i][j] = complete + 1

for i in range(n):
    print(*ans[i][i+1:])

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
    x=[str(i+1) for i in range(n-i)]
    print(" ".join(x))

Submission status: Wrong Answer

Solution code:
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N = int(input())

    for i in range(1, N):
        for j in range(i + 1, N + 1):
            if i % 2 == j % 2:
                print('1 ', end='')
            else:
                print('2 ', end='')
        print('')

sol()

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
mod = 10**9+7 #出力の制限
N = 10**5
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
# a = cmb(n,r)
n = onem()

for i in range(n-1):
    k = [i+1 for i in range(n-1-i)]
    if i == 0 and n % 2 == 0:
        k[-1] = 1
    print(jo(k))

Submission status: Wrong Answer

Solution code:
n = int(input()) - 1
for i in reversed(range(1, n + 1)):
	print(" ".join([str(j % 2 + 1) for j in range(i)]))

Submission status: Wrong Answer

Solution code:
n=int(input())

for j in range(n-1,0,-1):
    for i in range(j-1):
        if i%2==0:
            print(1,end=' ')
        elif i<3:
            print((i+3)//2,end=' ')
        else:
            print(3)
    if (j-1)%2==0:
        print(1)
    elif j-1<3:
        print((j+2)//2)
    else:
        print(3)

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in reversed(range(1, n + 1)):
	print(" ".join([str(j % 2 + 1) for j in range(i)]))

Submission status: Wrong Answer

Solution code:
n=int(input())
if n==2:print(1);exit()
if n==3:print(1,1);print(2);exit()
a=[[0]*n for _ in range(n)]
for i in range(n):a[i]=[i*2+1]*n
for i in range(n):
  for j in range(i+1,n):a[j][i]=(i+1)*2
for i in range(n):
  if n//2==i:
    print(*a[i][:-i-1],end=" ")
    if n%2==0:print(a[i-1][-i-1])
    else:print(a[i][-i-2])
  elif i!=0:print(*a[i][:-i])
  else:print(*a[i])

Submission status: Wrong Answer

Solution code:
from collections import deque
N=int(input())
if N%2==1:
    a=[[0 for j in range(N-i-1)] for i in range(N-1)]
    K=N//2
    #i->j(i<j)
    #a[i-1][j-i-1]
    for k in range(1,K+1):
        x=1
        for i in range(N-1):
            y,x=x,(x+k)%N
            if x==0:
                x=N
            if y==0:
                y=N
            p,q=min(x,y),max(x,y)
            #print(k,i,p,q,x,y)
            a[p-1][q-p-1]=k

    for i in range(N-1):
        for j in range(N-i-1):
            if a[i][j]==0:
                a[i][j]=K+1
    for i in range(N-1):
        print(*a[i])
else:
    K=N//2
    q=deque([i for i in range(1,N+1)])
    X=[]
    X.append(q.popleft())
    X.append(q.popleft())
    index=0
    while(len(q)>0):
        if index%2==0:
            X.append(q.pop())
        else:
            X.append(q.popleft())
        index+=1
    #print(X)
    a=[[0 for j in range(N-i-1)] for i in range(N-1)]
    for k in range(1,K+1):
        for i in range(N-1):
            x,y=(X[i]+k)%N,(X[i+1]+k)%N
            if x==0:
                x=N
            if y==0:
                y=N
            p,q=min(x,y),max(x,y)
            a[p-1][q-p-1]=k
    for i in range(N-1):
        print(*a[i])

Submission status: Wrong Answer

Solution code:
n=int(input())

ans1=[1]*(n//2)
ans2=[]
a=2
c=0
for i in range((n-1)//2):
    for j in range(a-1):
        c+=1
        ans2.append(a)
        if c==(n-1)//2:
            break
    if c==(n-1)//2:
        break
    a+=1
ans=[1]*(n-1)
for i in range(n-1):
    if i%2==1:
        ans[i]=ans2[(i-1)//2]
for i in range(n-1,0,-1):
    for j in range(i):
        if j==i-1:
            print(ans[j])
        else:
            print(ans[j],end=' ')

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  for i in range(1,n)[::-1]:
    l=['1']*i
    print(' '.join(l))

main()
# print(main())

Submission status: Wrong Answer

Solution code:
N = int(input() )
for num in range(N):
    tmp_list = [num + 1] * (N - 1 - num)
    print(" ".join(map(str,tmp_list) ) )

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    count = 0
    for i in range(n-1):
        count += 1
        for j in range(n-1-i):
            print(count,end = ' ')

        print()


main()

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(1,n):
    cnt = 0
    for j in range(i,n):
        if cnt%2 == 0:
            if j == n-1:
                print(1)
            else:
                print(1,end = ' ')
        else:
            if j == n-1:
                print(2)
            else:
                print(2,end = ' ')
        cnt += 1

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
mod = 10**9+7 #出力の制限
N = 10**5
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
# a = cmb(n,r)
n = onem()

for i in range(n-1):
    k = [i+1 for i in range(n-1-i)]
    print(jo(k))

Submission status: Wrong Answer

Solution code:
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()
K = 2**(N.bit_length()-1)

#print(N,K)

for i in range(1,N):
    tmp = []
    for j in range(i+1,N+1):
        x, y = i%K, j%K
        z = abs(x-y)
        ans = min(z,K-z)
        if ans == 0:
            ans = K//2+1

        tmp.append(str(ans))

    print(' '.join(tmp))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
c=0
for i in range(n):
    c=0
    for j in range(n-i,1,-1):
        c=c+1
        print(str(c),end=" ")
        #else:
         #   print(2,end=" ")
    print()

Submission status: Wrong Answer

Solution code:
#D問題
N = int(input())
for i in range(N-1):
    for j in range(N-i-1):
        if j%2 == 0:
            print(1,end=" ")
        else:
            print(((j-1)//2)+2,end=" ")
    print()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
for i in range(n):
    for j in range(n-i,1,-1):
        if(j==n-i):
            print(1,end=" ")
        else:
            print(2,end=" ")
    print()

Submission status: Wrong Answer

Solution code:
n=int(input())

for j in range(n-1,0,-1):
    for i in range(j-1):
        if i%2==0:
            print(1,end=' ')
        elif i<3:
            print((i+3)//2,end=' ')
        else:
            print((i+1)//4+2)
    if (j-1)%2==0:
        print(1)
    elif j-1<3:
        print((j+2)//2)
    else:
        print(j//4+2)

Submission status: Wrong Answer

Solution code:
n = int(input())

for i in range(n-1):
  l = list(range(1, n-i))
  print(" ".join(map(str,l)))

Submission status: Wrong Answer

Solution code:
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()
K = 2**(N.bit_length()-1)

#print(N,K)

for i in range(1,N):
    tmp = []
    for j in range(i+1,N+1):
        x, y = i%K, j%K
        z = abs(x-y)
        ans = min(z,K-z)+1

        tmp.append(str(ans))

    print(' '.join(tmp))

Submission status: Wrong Answer

Solution code:
N = int(input())


for i in range(1, N):
    for j in range(N-i):
        print(i, end=" ")
    print()

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    ans = [[-1 for j in range(N - i - 1)] for i in range(N - 1)]
    if N % 2 == 0:
        for i in range(N - 1): ans[i][0] = 1
        ans[0][N-2] = 1
        for i in range(N - 2):
            for j in range(1, N - i - 1):
                ans[i][j] = (i + 2) // 2 + 1

    else:
        for i in range(N - 2): ans[i][0] = 1
        ans[0][N-3] = 1
        for i in range(N - 3):
            for j in range(1, N - i - 2):
                ans[i][j] = (i + 2) // 2 + 1
        for i in range(N-1): ans[i][-1] = (N + 1)//2

    #print(ans)
    for i in range(N-1):
        print(" ".join(map(str, ans[i])))
          
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())

if(N%2 == 0 or N==3):
    for i in range(1,N):
        ansList = []
        for j in range(i+1,N+1):
            if((i+j) % 2 == 1):
                ansList.append(1)
            else:
                ansList.append(2)
        print(' '.join(map(str, ansList)))
else:
    for i in range(1,N):
        ansList = []
        for j in range(i+1,N+1):
            if(j == N):
                ansList.append(3)
            elif((i+j) % 2 == 1):
                ansList.append(1)
            else:
                ansList.append(2)
        print(' '.join(map(str, ansList)))

Submission status: Wrong Answer

Solution code:
N=int(input())

ANS=[[0]*N for i in range(N)]


def line(NOW,k):

    ANS[k][k+1]=NOW+1
    for i in range(k+2,N):
        ANS[k][i]=NOW
        ANS[k+1][i]=NOW


for k in range((N-1)//2):
    line(k+1,k*2)

if N%2==0:
    ANS[N-2][N-1]=N//2

#print(ANS)

for i in range(N-1):
    print(*ANS[i][i+1:])

Submission status: Wrong Answer

Solution code:
n = int(input())

k = int(n/2)

for i in range(n-1):
        a = []
        if i < k:
                for j in range(i+1,n):
                        if j < k:
                                a.append(i+j+2)
                        else:
                                a.append(1)
                print(*a)
        else:
                for j in range(i+1,n):
                        if j < k:
                                a.append(1)
                        else:
                                a.append(i+j+2)
                print(*a)

Submission status: Wrong Answer

Solution code:
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()

for i in range(1,N):
    tmp = []
    for j in range(i+1,N+1):
        if i%2 == j%2:
            ans = 1
        else:
            ans = 2
        tmp.append(str(ans))

    print(' '.join(tmp))

Submission status: Wrong Answer

Solution code:
N = int(input())
def calc(i, j):
    if j-i == 2 or (j-i == 1 and i % 2): return 1
    if (j-i==1 and j % 2) or (j-i==3 and i % 2): return 2
    return (j-1)//2 - (i-1)//2 + 1

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())

for i in range(1,n):
    for j in range(n-i-1):
        print(i,end=" ")
    print(i)

Submission status: Wrong Answer

Solution code:
n=int(input())

for j in range(n-1,0,-1):
    for i in range(j-1):
        if i%2==0:
            print(1,end=' ')
        else:
            print((i+3)//2,end=' ')
    if (j-1)%2==0:
        print(1)
    else:
        print((j+2)//2)

Submission status: Wrong Answer

Solution code:
N = int(input())

for i in range(N):
    ans = [i + 1] * (N - i - 1)
    print(' '.join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import itertools
n = int(input())
it = itertools.count(1)
for y in range(n - 1):
    print(*[next(it) for x in range(n - y - 1)])

Submission status: Wrong Answer

Solution code:
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
  print(l, m)
  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):
    t += str(L[i][j]) + " "
  print(t)

Submission status: Wrong Answer

Solution code:
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()

for i in range(N-1):
    print(' '.join([str(i+1)]*(N-i-1)))

Submission status: Wrong Answer

Solution code:
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N = int(input())

    for i in range(1, N):
        for _ in range(i + 1, N + 1):
            print('{} '.format(i), end='')
        print('')


sol()

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
for i in xrange(n-1):
  a = []
  for j in xrange(n-1-i):
    a.append(j+1)
  print ' '.join(map(str, a))

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
ans = ""
for i in range(n):
  for j in range(i + 1, n):
    ixorj = i ^ j
    cnt = 1
    while ixorj >= 2:
      cnt += 1
      ixorj //= 2
    ans += str(cnt)
    if j != n-1:
      ans += " "
  if i != n-2:
    ans += "\n"
print(ans)

Submission status: Time Limit Exceeded

Solution code:
input = raw_input

N = int(input())

levels = [[0 for j in range(501)] for i in range(501)]

nums = [0 for i in range(501)]
nums[2] = 1
nums[3] = 2

graphs = [None for i in range(501)]
graph2 = [[None, None, None], [None, None, 1], [None, 1, None]]
graphs[2] = graph2
graph3 = [[None for i in range(3+1)] for j in range(3+1)]
graph3[1][2] = 2
graph3[1][3] = 1
graph3[2][1] = 2
graph3[2][3] = 1
graph3[3][1] = 1
graph3[3][2] = 1
graphs[3] = graph3

def get_graph(cur_graph, nodes):
    n_nodes = len(nodes)

    old_graph = graphs[n_nodes]
    #print(old_graph, cur_graph, n_nodes)
    new_nodes = nodes
    old_nodes = list(range(1, n_nodes+1))

    for i, new_node1 in enumerate(new_nodes):
        old_node1 = i + 1
        for j, new_node2 in enumerate(new_nodes):
            if i == j:
                continue
            old_node2 = j + 1
            #print(new_node1, new_node2, old_node1, old_node2)
            cur_graph[new_node1][new_node2] = old_graph[old_node1][old_node2] + 1

    return cur_graph

for n in range(4, N+1):
    n1 = n // 2 
    n2 = n1

    if n % 2 == 1:
        n1 += 1

    nodes1 = [i for i in range(1, n1+1)]
    nodes2 = [i for i in range(n1+1, n+1)]

    cur_graph = [[None for i in range(n+1)] for j in range(n+1)]
    for node1 in nodes1:
        for node2 in nodes2:
            cur_graph[node1][node2] = 1
            cur_graph[node2][node1] = 1

    nums[n] = 1 + max(nums[n1], nums[n2])

    min_level = 2
    cur_graph = get_graph(cur_graph, nodes1)
    cur_graph = get_graph(cur_graph, nodes2)

    graphs[n] = cur_graph


cur_graph = graphs[N]
for i in range(1, N+1):
    out_txt = " ".join([str(cur_graph[i][j]) for j in range(i+1, N+1)])
    print(out_txt)
#out = nums[N]

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

levels = [[0 for j in range(501)] for i in range(501)]

nums = [0 for i in range(501)]
nums[2] = 1
nums[3] = 2

graphs = [None for i in range(501)]
graph2 = [[None, None, None], [None, None, 1], [None, 1, None]]
graphs[2] = graph2
graph3 = [[None for i in range(3+1)] for j in range(3+1)]
graph3[1][2] = 2
graph3[1][3] = 1
graph3[2][1] = 2
graph3[2][3] = 1
graph3[3][1] = 1
graph3[3][2] = 1
graphs[3] = graph3

def get_graph(cur_graph, nodes):
    n_nodes = len(nodes)

    old_graph = graphs[n_nodes]
    #print(old_graph, cur_graph, n_nodes)
    new_nodes = nodes
    old_nodes = list(range(1, n_nodes+1))

    for i, new_node1 in enumerate(new_nodes):
        old_node1 = i + 1
        for j, new_node2 in enumerate(new_nodes):
            if i == j:
                continue
            old_node2 = j + 1
            #print(new_node1, new_node2, old_node1, old_node2)
            cur_graph[new_node1][new_node2] = old_graph[old_node1][old_node2] + 1

    return cur_graph

for n in range(4, N+1):
    n1 = n // 2 
    n2 = n1

    if n % 2 == 1:
        n1 += 1

    nodes1 = [i for i in range(1, n1+1)]
    nodes2 = [i for i in range(n1+1, n+1)]

    cur_graph = [[None for i in range(n+1)] for j in range(n+1)]
    for node1 in nodes1:
        for node2 in nodes2:
            cur_graph[node1][node2] = 1
            cur_graph[node2][node1] = 1

    nums[n] = 1 + max(nums[n1], nums[n2])

    min_level = 2
    cur_graph = get_graph(cur_graph, nodes1)
    cur_graph = get_graph(cur_graph, nodes2)

    graphs[n] = cur_graph


cur_graph = graphs[N]
for i in range(1, N+1):
    out_txt = " ".join([str(cur_graph[i][j]) for j in range(i+1, N+1)])
    print(out_txt)
#out = nums[N]

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations

def solve():
    N = int(input())
    #(i,j) -> E[i-1][j-2], i < j
    E = [[0 for j in range(N+1)] for i in range(N+1)]
    E[1][2] = 1
    cl = {1}
    for j in range(3,N+1):
        for i in range(j-1,0,-1):
            cl_ = cl.copy()
            for k in range(i+1,j):
                if E[i][k] == E[k][j]:
                    cl_ -= {E[i][k]}
            if cl-cl_:
                if cl_:
                    E[i][j] = min(cl_)
                else:
                    E[i][j] = max(cl)+1
                    cl.add(E[i][j])
            else:
                E[i][j] = 1
                
                    
    
    res = '\n'.join(' '.join(map(str,e[i+2:])) for i, e in enumerate(E[1:]))
    return str(res)

if __name__ == '__main__':
    print(solve())

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    #(i,j) -> E[i-1][j-2], i < j
    E = [[0 for j in range(N+1)] for i in range(N+1)]
    E[1][2] = 1
    cl = {1}
    for j in range(3,N+1):
        for i in range(j-1,0,-1):
            if all(E[i][k] != E[k][j] for k in range(i+1,j)):
                E[i][j] = 1
            else:
                cl_ = cl - set(E[i][k] for k in range(i+1,j) if E[i][k] == E[k][j]) - {0}
                if cl_:
                    E[i][j] = min(cl_)
                else:
                    E[i][j] = max(cl)+1
                    cl.add(E[i][j])
                    
    
    res = '\n'.join(' '.join(map(str,e[i+2:])) for i, e in enumerate(E[1:]))
    return str(res)

if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

"""
奇閉路がないので二部グラフ
まずは最大の二部グラフを作る．
左右それぞれのグループ内の頂点同士を結ぶ辺がない．
この時点でスケールの小さい同問題に帰着，グループ内で二部グラフを作れば良い．
ただ，これを素直にやると構築が面倒そう．

レベルの最大値の最小値はN<=2^mなる最小のm
つまりNの二進数表記での桁数

レベル1 : 000..111...
レベル2 : 00..11..00..11..
みたいに分けるか．
これ，二進数で各bitが異なる頂点とつなげば良い．すでにあるならば無視
"""
def main():
    mod=10**9+7
    N=I()
    M=2**(N-1).bit_length()
    
    ans=[[-1]*N for _ in range(N)]
    
    for k in range(M):#二進数の桁数
        for i in range(N):
            for j in range(i+1,N):
                if (i>>k &1)^(j>>k &1):#iとjのkbit目が違うならば
                    if ans[i][j]==-1:
                        ans[i][j]=k+1
                        
    for i in range(N):
        print(' '.join(map(str, ans[i][i+1:])))
    
    

main()

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    ans = [[0] * (N+1) for _ in range(N+1)]
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            for k in range(10):
                if (i >> k & 1) != (j >> k & 1):
                    ans[i][j] = k+1
                    break
    for i in range(1, N):
        print(*ans[i][i+1:])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

def calc(i,j):
    x = i^j
    for k in range(20):
        if((x>>k)&1):
            return k+1

ans = [[0]*n for _ in range(n)]
for i in range(n-1):
    for j in range(i+1,n):
        ans[i][j] = calc(i,j)

for i in range(n-1):
    print(' '.join(map(str,ans[i][i+1:])))

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
ans = [[None]*(n-i-1) for i in range(n-1)]
vs = [list(range(n))]
level = 1
def sub(l):
    if len(l)==1:
        return []
    v = len(l)//2
    for i in l[:v]:
        for j in l[v:]:
#             print(i,j)
            ans[i][j-i-1] = level
    return [l[:v], l[v:]]
while True:
    nvs = []
    for l in vs:
        nvs.extend(sub(l))
    if not nvs:
        break
    vs = nvs
    level += 1
write("\n".join(" ".join(map(str, ans[i])) for i in range(n-1)))

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n - 1):
    for j in range(i + 1, n):
        print(((i ^ j) &- (i ^ j)).bit_length(), end=" ")
    print()

Submission status: Accepted

Solution code:
#二部グラフにできるのか
#ここからよ
#実は奇サイクルを含まない=二部グラフとなる
#それぞれのレベルで奇サイクルかどうか
#二部グラフを考えて残りでもどんどん二部グラフを考えるイメージ

#最終的には1or2の状態で残る
N=int(input())
ans=[[0]*N for j in range(N)]
#nはvecの長さ
#次の通路のレベル
def dfs(n,vec,level):
    global ans
    #print(vec)
    #print(n)
    l=vec[:n//2]
    r=vec[n//2:]
    for i in l:
        for j in r:
            ans[i][j]=level
    if len(l)>1:
        dfs(len(l),l,level+1)
    if len(r)>1:
        dfs(len(r),r,level+1)


dfs(N,[i for i in range(N)],1)
for i in range(N-1):
    a=[]
    for j in range(N):
        if i<j:
            a.append(str(ans[i][j]))
    print(" ".join(a))

Submission status: Accepted

Solution code:
N = int(input())
ans = []

for i in range(N-1):
    ans.clear()
    for j in range(i + 1, N):
        ans.append(list(bin(i ^ j)[::-1]).index('1') + 1)
    print(*ans)