Problem:


Selection of Participants of an Experiment

Dr. Tsukuba has devised a new method of programming training.
In order to evaluate the effectiveness of this method,
he plans to carry out a control experiment.
Having two students as the participants of the experiment,
one of them will be trained under the conventional method
and the other under his new method.
Comparing the final scores of these two,
he will be able to judge the effectiveness of his method.

It is important to select two students having the closest possible scores,
for making the comparison fair.
He has a list of the scores of all students
who can participate in the experiment.
You are asked to write a program which selects two of them
having the smallest difference in their scores.

Input

The input consists of multiple datasets, each in the following format.

n

a1 a2 &hellip; an

A dataset consists of two lines.
The number of students n is given in the first line.
n is an integer satisfying 2 ≤ n ≤ 1000.
The second line gives scores of n students.
ai (1 ≤ i ≤ n) is the score of the i-th student, which is a non-negative integer not greater than 1,000,000.

The end of the input is indicated by a line containing a zero.
The sum of n's of all the datasets does not exceed 50,000.

Output

For each dataset, select two students with the smallest difference in their scores,
and output in a line (the absolute value of) the difference.

Sample Input

5
10 10 10 10 10
5
1 5 8 9 11
7
11 34 83 47 59 29 70
0

Output for the Sample Input

0
1
5



Sample input:
5
10 10 10 10 10
5
1 5 8 9 11
7
11 34 83 47 59 29 70
0


Sample output:
0
1
5

Submission status: Wrong Answer

Solution code:
n=int(input())
data=list(map(int,input().split()))
data=sorted(data)
answer=1000000

for i in range(0,n-1):
    d=data[i+1]-data[i]
    
    if d<answer:
        answer=d
        
print(answer)

Submission status: Wrong Answer

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    a = sorted(list(map(int, input().split())))
    ans = 10000
    for i in range(n - 1):
        j = a[i + 1] - a[i]
        if j <= ans:
            ans = j
    print(ans)

Submission status: Wrong Answer

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    a = sorted(list(map(int, input().split())))
    ans = 10000
    for i in range(n - 1):
        j = a[i + 1] - a[i]
        if j < ans:
            ans = j
    print(ans)

Submission status: Wrong Answer

Solution code:
while True:
    n = int(input())
    a = list(map(int, input().split()))
    l = list()

    for i in range(1, n-1):
        for j in range(i+1,n):
            l.append(abs(a[i]-a[j]))
    if l == []:
        break
    if n == 0:
        break
    print(min(l))

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        if n == 0:
            break
        a = sorted(LI())
        r = inf
        for i in range(n-1):
            tr = a[i+1] - a[i]
            if r > tr:
                r = tr
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())

Submission status: Wrong Answer

Solution code:
f=lambda s,t:abs(s-t)

while 1:
    n=int(input())
    if not n:break
    a=sorted(list(map(int,input().split())))
    s,t=a[:2]
    for i in a[2:]:
        u=f(s,t)
        if u>abs(s-i):
            t=i
        elif u>abs(t-i):
            s=i
    print(f(s,t))

Submission status: Accepted

Solution code:
# AOJ 1608: Selection of Participants of an Experime...
# Python3 2018.7.13 bal4u

while True:
	n = int(input())
	if n == 0: break
	a = list(map(int, input().split()))
	a.sort()
	ans = a[1]-a[0]
	for i in range(2, n):
		if a[i]-a[i-1] < ans: ans = a[i]-a[i-1];
	print(ans)

Submission status: Accepted

Solution code:
n=int(input())
result=[]

while n!=0:
    data=list(map(int,input().split()))
    data=sorted(data)
    answer=1000000

    for i in range(0,n-1):
        d=data[i+1]-data[i]
    
        if d<answer:
            answer=d
        
    result.append(answer)
    
    n=int(input())

for i in range(0,len(result)):
    print(result[i])

Submission status: Accepted

Solution code:
anslist = []

while True:
    n = int(input())
    if not n:
        break

    a = list(map(int, input().split()))

    ans = 10 ** 10
    for i in range(n):
        for j in range(n):
            if i != j:
                ans = min(ans, abs(a[i] - a[j]))

    anslist.append(ans)

for i in anslist:
    print(i)

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0:
        break
    A = sorted(list(map(int, input().split())))
    ans = float('inf')
    for i in range(1, len(A)):
        ans = min(abs(A[i] - A[i - 1]), ans)
    print(ans)

Submission status: Accepted

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

while True:
    n = int(input())
    if n == 0:
        break
    else:
        aa = inpl()
        aa.sort()
        ans = INF
        for i in range(1,n):
            ans = min(aa[i] - aa[i-1],ans)
        print(ans)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    a = sorted(list(map(int, input().split())))
    ans = 1000001
    for i in range(n - 1):
        j = a[i + 1] - a[i]
        if j < ans:
            ans = j
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n=int(raw_input())
    if n==0: break
    a=sorted(map(int,raw_input().split()))
    d=10**9
    for i in xrange(n-1):
        d=min(d,a[i+1]-a[i])
    print d

Submission status: Accepted

Solution code:
while True:
    Sa = 1000000
    n = int(input())
    if n == 0:
        break
    Num_lis = list(map(int,input().split()))
    Num_lis = sorted(Num_lis)
    for i in range(n - 1):
        if Num_lis[i + 1] - Num_lis[i] < Sa:
            Sa = Num_lis[i + 1] - Num_lis[i]
    print(Sa)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0: break
    l = list(map(int,input().split()))
    r = []
    for i in range(n):
        for j in range(i+1,n):
            r += [abs(l[i]-l[j])]
    print(min(r))

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0: break
    l = sorted(list(map(int,input().split())))
    r = []
    for i in range(n-1):
        r += [l[i+1]-l[i]]
    print(min(r))

Submission status: Accepted

Solution code:
while 1:
    n = input()
    if n==0:
        break
    A = map(int, raw_input().split())
    ans = 1e18
    for i in xrange(n):
        for j in xrange(n):
            if i==j: continue
            ans = min(ans, abs(A[i]-A[j]))
    print ans

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    a=sorted(list(map(int,input().split())))
    print(min(a[i+1]-a[i] for i in range(n-1)))

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if not N:
        break
    A = sorted(map(int, input().split()))
    print(min(A[i+1] - A[i] for i in range(N-1)))

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    a = sorted(list(map(int, input().split())))
    minv = 1000000
    for i in range(n-1):
        minv = min(minv, a[i+1]-a[i])
    print(minv)

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if n==0:
     break
  a = [int(i) for i in input().split()]

  a.sort()
  mindiff = 10000000
  for i in range(n-1):
    mindiff = min(mindiff, a[i+1]-a[i])
  print(mindiff)

Submission status: Accepted

Solution code:
while int(input()) > 0:
    s = sorted(map(int, input().split()))
    print(min(abs(a - b) for (a, b) in zip(s, s[1:])))

Submission status: Accepted

Solution code:
while True:
    if int(input()) == 0:
        break
    s = sorted(map(int, input().split()))
    r = min(abs(x - y) for (x, y) in zip(s, s[1:]))
    print(r)

Submission status: Accepted

Solution code:
while True:
	n=int(input())
	if n==0:break
	a=list(map(int,input().split()))
	a.sort()
	saisho=1000000
	for i,iv in enumerate(a):
		if i!=0:
			saisho=abs(iv-b) if saisho > abs(iv-b)else saisho
		b=iv
	print(saisho)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    a = sorted(map(int,raw_input().split()))
    b = []
    for i in range(n-1):
        b.append(a[i+1]-a[i])
    print min(b)

Submission status: Accepted

Solution code:

def solve(N):
    A = list(map(int, input().split()))
    ans = 1e9
    for i in range(N):
        for j in range(N):
            if i != j:
                d = abs(A[i] - A[j])
                if ans > d:
                    ans = d
    print(ans)

while True:
    N = int(input())
    if N > 0:
        solve(N)
    else:
        break

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    while 1:
        n = int(input())
        if n ==0 :break
        line = list(map(int,input().strip().split()))
        diff = max(line)
        for i in range(n-1):
            for j in range(i+1,n):
                if diff > abs(line[i] - line[j]):diff = abs(line[i]-line[j])
        print(diff)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    while 1:
        n = int(input())
        if n ==0 :break
        line = list(map(int,input().strip().split()))
        diff = 1000000
        for i in range(n-1):
            for j in range(i+1,n):
                if diff > abs(line[i] - line[j]):diff = abs(line[i]-line[j])
        print(diff)

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0: break
    src = list(map(int,input().split()))
    src.sort()
    ans = 10**7
    for s1,s2 in zip(src,src[1:]):
        ans = min(ans, s2-s1)
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())

    if n == 0:
        break

    a = sorted(map(int, raw_input().split()))

    print min([a[i+1]-a[i] for i in range(n-1)])

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break

    a = list(map(int, input().split()))
    a.sort()
    mind = 1000000
    for i in range(len(a) - 1):
        mind = min(mind, a[i + 1] - a[i])
    print(mind)

Submission status: Accepted

Solution code:
while True:
    n = int(input())#人数の受け取り
    if n == 0:#０人or何も入力しないなら終了
        break
    a = list(map(int, input().split()))#各人の成績の受け取り
    l = list()#出力の受け取り用
    for i in range(0, n):#成績の比較
        for j in range(0, n):
            if i == j:
                continue
            l.append(abs(a[i]-a[j]))#絶対値を受け取り用のlistに入力
    else:#listが完成したら
        print(min(l))#成績の一番近い生徒の差を出力

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break

    a = sorted(list(map(int, input().split())))
    
    # 要素間の差を求め、最も差の小さい値を抽出する
    b = []
    for i, x in enumerate(a[:-1]):
        b.append(abs(x - a[i+1]))
    print(min(b))

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        if n == 0:
            break
        a = sorted(LI())
        r = inf
        for i in range(n-1):
            tr = a[i+1] - a[i]
            if r > tr:
                r = tr
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

while True:
    n = int(input())
    if n == 0:
        break
    l = list(map(int, input().split()))
    l.sort()
    l.reverse()
    min = 10**10
    for i in range(n-1):
        dif = l[i] - l[i+1]
        if dif < min:
            min = dif
    print(min)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    arr = list(map(int, input().split()))
    arr.sort()
    ge = arr[-1]
    for i in range(n - 1):
        tmp = arr[i + 1] - arr[i]
        if tmp < ge:
            ge = tmp
    print(ge)

Submission status: Accepted

Solution code:
while int(input()):
  l=sorted(map(int,input().split()))

  ll=range(len(l))
  m=[0 for _ in ll]
  m[1]=abs(l[0]-l[1])
  for i in ll[2:]:
    m[i]=min(m[i-1],abs(l[i]-l[i-1]))
  print(m[-1])

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    a = list(map(int, input().split()))
    ans = 100000000
    for i in range(n - 1):
        for j in range(i + 1, n):
            ans = min(ans, abs(a[i] - a[j]))
    print(ans)

Submission status: Accepted

Solution code:
BIG_NUM=10000000
while True:
    n=int(input())
    if n==0:
        break
    else:
        a=sorted(list(map(int,input().split())))
        tmp=BIG_NUM
        for i in range(n-1):
            tmp=min(tmp,a[i+1]-a[i])
        print(tmp)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    A = sorted(list(map(int, input().split())))
    D =[]
    for i in range(n - 1):
        D.append(A[i + 1] - A[i])
    print(min(D))

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    scores = [int(line) for line in input().split()]
    scores.sort()
    c = scores[1] - scores[0]
    for i in range(2, n):
        if scores[i] - scores[i - 1] < c:
            c = scores[i] - scores[i - 1]
    print(c)

Submission status: Accepted

Solution code:

while True:
    n = int(input())
    if n == 0: break
    dataset = list(map(int, input().split()))
    dataset.sort()

    minimumDiff = 99999999999999
    for i in range(0,n-1):
        temp = dataset[i+1] - dataset[i]
        if minimumDiff > temp:
            minimumDiff = temp
    print(minimumDiff)

Submission status: Accepted

Solution code:
n = int(input())

while n!=0:
    a = list(map(int,input().split()))
    data = []
    for i in range(len(a)-1):
        for j in range(i+1,len(a)):
            data.append(abs(a[i]-a[j]))
    n = int(input())
    print(min(data))

Submission status: Accepted

Solution code:
#入力数を入力し、0だったら入力を終わる
while True:
    num = int(input())
    if num == 0:break

    #入力をし、空リスト作成
    line = sorted(list(map(int,input().split())))
    kotae = []
    
    #差を求め、差が一番小さい値を出力する
    for i in range(0,num - 1):
        num1 = abs(line[i] - line[i + 1])
        kotae.append(num1)
    print(min(kotae))

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:break;
    a=list(map(int, input().split()))
    a.sort()
    ans=a[1]-a[0]
    for i in range(2, n):
        if a[i]-a[i-1]<ans:ans=a[i]-a[i-1]
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
while n != 0:
    a = list(map(int, input().split()))
    ans = float("inf")
    for i in range(n-1):
        for j in range(i+1, n):
            res = abs(a[i] - a[j])
            if ans > res:
                ans = res
    print(ans)
    n = int(input())

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    a = list(map(int,input().split()))
    Min = 9999999999
    a.sort()
    for i in range(n-1):
        Min = min(Min,abs(a[i] - a[i+1]))
    print(Min)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0:break
    a = list(map(int, input().split()))

    a = sorted(a)

    ans = 10000000

    for i in range(len(a)-1):
        if a[i+1]-a[i] < ans:
            ans = a[i+1]-a[i]

    print(ans)

Submission status: Accepted

Solution code:
def get_input():
    input_data = int(input())
    return input_data

def get_data_list():
    data_list = input().split()
    for i in range(len(data_list)):
        data_list[i] = int(data_list[i])
    return data_list

class Checker:
    def __init__(self, sorted_list):
        self.sorted_list = sorted_list
        self.a = 0
        self.b = 1
        self.min_num = float("inf")
        self.try_num = len(self.sorted_list) - 1 # for not subtract last + 1 from last

    def detect_min_num(self):
        for i in range(self.try_num):
            tmp_num = self.sorted_list[self.b] - self.sorted_list[self.a]
            if tmp_num <= self.min_num:
                self.min_num = tmp_num
            self.a, self.b = self.b, self.b + 1


if __name__ == "__main__":
    while True:
        student_num = get_input()
        if student_num == 0:
            break
        data_list = get_data_list()
        sorted_list = sorted(data_list)
        # print("data_list", data_list) # debug
        # print("sorted_list", sorted_list) # debug
        checker = Checker(sorted_list)
        checker.detect_min_num()
        min_num = checker.min_num
        # print("min_num", min_num) # debug
        print(min_num)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

while True:
  mans = inf
  n=int(input())
  if n == 0: exit()
  A=list(map(int,input().split()))
  for i in range(n-1):
    for j in range(i+1,n):
      mans = min(mans,abs(A[i]-A[j]))
  print(mans)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if(n == 0): break
    a = list(map(int,input().split()))
    a.sort()
    ans = 10**9
    for i in range(n-1):
        ans = min(ans,a[i+1]-a[i])
    print(ans)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:break
    a = sorted(list(map(int, input().split())))
    b = [a[i+1] - a[i] for i in range(n-1)]
    print(min(b))

Submission status: Accepted

Solution code:
while True:
    a = int(input())
    if a == 0:
        break
    b = sorted(list(map(int,input().split())))
    di = -1
    for i in range(a-1):
        h = b[i+1]-b[i]
        if di == -1 or h < di:
            di = h
    print(di)

Submission status: Accepted

Solution code:
l = []
for i in range(50000):
  n = int(input())
  if n == 0:
    break
  else:
    A = list(map(int,input().split()))
    for i in range(n):
      for j in range(i+1,n):
        l.append(abs(A[i]-A[j]))
    print(min(l))
    l.clear()

Submission status: Accepted

Solution code:
while True :
    n = int(input())
    if(n == 0) :
        break
    else :
        A = list(map(int, input().split()))
        d = 1000000
        
        for i in range(n - 1) :
            for j in range(i + 1, n) :
                s = abs(A[i] - A[j])
                if(s < d) :
                    d = s
                else :
                    pass
        
        print(d)

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans
    
    ### intチェック
    def is_integer(self, n):
        try:
            float(n)
        except ValueError:
            return False
        else:
            return float(n).is_integer()

    ### 幾何学問題用
    def dist(self, A, B):
        d = 0
        for i in range(len(A)):
            d += (A[i]-B[i])**2            
        d = d**(1/2)
        return d

    ### 絶対値
    def abs(self, n):
        if n >= 0:
            return n
        else:
            return -n

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

def printA(A):
    N = len(A)
    for i, n in enumerate(A):
        print(n, end='')
        if i != N-1:
            print(' ', end='')
    print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート（代入する必要なし）
# N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

while True:
    N = int(input())
    if N==0:
        break
    A = [int(x) for x in input().split()]

    ans = 1145141919

    A.sort()

    for i in range(N-1):
        if ans > abs(A[i]-A[i+1]):
            ans = abs(A[i]-A[i+1])

    print(ans)

Submission status: Accepted

Solution code:
ans_list = []

while True:
    n = int(input())
    if n == 0:
        break
    A = list(map(int,input().split()))
    ans = float("inf")
    for i in range(n):
        for j in range(i+1,n):
            res = abs(A[i]-A[j])
            ans = min(ans, res)
    ans_list.append(ans)

for ans in ans_list:
    print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

flag = True
ans_list = []
N = 1
while(flag == True):
	N = INT()
	if N == 0:
		flag = False
	else:
		A = LIST()
		A.sort()
		ans = abs(A[0] - A[1])
		for i in range(N - 1):
			ans = min(ans, abs(A[i] - A[i + 1]))
		ans_list.append(ans)

		# ans = abs(A[0] - A[1])
for ans in ans_list:
	print(ans)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0:
        break
    a = list(map(int,input().split()))
    a.sort()

    res = a[1]-a[0]
    for i in range(1,n):
        res = min(res,a[i]-a[i-1])
    print(res)

Submission status: Accepted

Solution code:
while True:
  n=int(input())
  if n==0:
    break
  a=list(map(int,input().split()))
  x=[]
  for i in range(n):
    for j in range(i+1,n):
      b=a[i]-a[j]
      if b<0:
        b=b*(-1)
      x.append(b)
  print(min(x))

Submission status: Accepted

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2,gcd
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    ans=[]

    while 1:
        n = INT()
        if n==0:
            break
        else:
            a=LIST()
            a.sort()
            mi=max(a)
            for i in range(n-1):
                for j in range(i+1,n):
                    mi=min(mi,a[j]-a[i])

            ans.append(mi)

    for x in ans:
        print(x)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
def MAP(): return map(int, input().split())

ans = []
while 1:
	n = INT()
	if n == 0:
		break
	a = LIST()
	a.sort()
	min_ = 100000000
	for i in range(n-1):
		min_ = min(min_, abs(a[i] - a[i+1]))
	ans.append(min_)
for x in ans:
	print(x)

Submission status: Accepted

Solution code:

while True:
	n = int(input())
	if n == 0: break
	score = list(map(int,input().split()))
	score.sort()
	ans = max(score)
	for i in range(1,n):
		aa = abs(score[i] - score[i-1])
		if ans > aa:
			ans = aa
	print(ans)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    x = list(map(int,input().split()))
    x = sorted(x)
    ans = 1000000
    for i in range(n-1):
        ans = min(ans,x[i+1]-x[i])
    print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

ans_list = []

while True:
    n = int(input())
    if n == 0:
        break
    A = list(map(int,input().split()))
    ans = float("inf")
    for (a, b) in combinations(A,2):
        ans = min(ans,abs(a-b))
    ans_list.append(ans)

for ans in ans_list:
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:break
    l=list(map(int,input().split()))
    l.sort()
    ans=l[-1]-l[0]
    for i in range(n-1):
        ans=min(ans,l[i+1]-l[i])
    print(ans)

Submission status: Accepted

Solution code:
def main(n):
    a = list(map(int, input().split()))
    a.sort()
    ans = 10 ** 20
    for i in range(n - 1):
        if ans > a[i + 1] - a[i]:
            ans = a[i + 1] - a[i]
    print(ans)

while 1:
    n = int(input())
    if n == 0:
        break
    main(n)

Submission status: Accepted

Solution code:
for v in range(1000):
  s = input()
  s = int(s)
  if s == 0:
    break
  else:
    x=[]
    A = input().split()
    B = [int(l) for l in A]
    for i in range(s):
      for j in range(s):
        if i==j:
          pass
        else:
          w=B[i]-B[j]
          w = abs(w)
          x.append(w) 
  print(min(x))

Submission status: Accepted

Solution code:

while True:
    min = 1000000
    n =(int)(input())
    if n==0:
        break
    a = list(map(int, input().split()))

    for i in range (n-1):
        for j in range (i+1,n):
            num = a[i]-a[j]
            if min>abs(num):
                min = abs(num)
    print(min)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    a = [int(x) for x in input().split()]
    ans = 10000000
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if abs(a[i]-a[j])<ans:
                ans = abs(a[i]-a[j])
    print(ans)

Submission status: Accepted

Solution code:
import itertools

while True:
    n = int(input())
    
    if n == 0:
    	break
    
    score_lst = [int(i) for i in input().split()]
    
    dist = 1000001
    
    for i1, i2 in itertools.combinations(score_lst, 2):
    	if abs(i1 - i2) < dist:
    		dist = abs(i1 - i2)
    		
    print(dist)

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0:
        break
    s = list(map(int, input().split()))
    ans = []
    for i in range(N-1):
        for j in range(N):
            if(i < j):
                if s[i] > s[j] or s[i] < s[j]:
                    tmp = abs(s[i]-s[j])
                    ans.append(tmp)
                if s[i] == s[j] and not i == j:
                    ans.append(0)
    print(min(ans))

Submission status: Accepted

Solution code:
while(True):
  n = int(input())
  if n == 0:
    break
  else:
    lis = list(map(int,input().split()))
    lis.sort()
    min = 10**9+7
    i = 0
    while(i<len(lis)-1):
      if lis[i+1] - lis[i] < min:
        min = lis[i+1] - lis[i]
      i += 1
    print(min)

Submission status: Accepted

Solution code:
ans = []

while True:
    n = int(input())
    if n == 0:
        break
    a = sorted(list(map(int, input().split())))
    min_ = a[-1]
    for i in range(1, n):
        min_ = min(min_, a[i] - a[i-1])
    ans.append(min_)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys
def main():
    while True:
        n = int(input())
        if not n:
            return
        aa = list(map(int,input().split()))
        ans = sys.maxsize
        for i in range(n):
            for j in range(n):
                if i == j:
                    continue
                ans = min(abs(aa[i]-aa[j]),ans)
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
while 1:
  n = int(input())
  if n == 0:
    break
  A = list(map(int, input().split()))
  A.sort()
  m = 1000000
  t=0
  for i in range(n):
    for j in range(1+i,n):
      t=abs(A[i]-A[j])
      if t<= m:
        m = t
  print(m)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    a = list(map(int,input().split()))
    a.sort()
    ans = 10**10
    for i in range(n-1):
        ans = min(ans, abs(a[i]-a[i+1]))
    print(ans)

Submission status: Accepted

Solution code:
#成績の差が最も小さい 2 人を選ぶプログラム

#1 行目には学生の人数 n (2 ≤ n ≤ 1000)
#2 行目には　 ai（1 ≤ i ≤ n）が i 番目の学生の成績
while True:
 #1行目nを読み込む
  n =int(input())
  #もしn==0ならbreak
  if n==0:
    break
  else :
     #配列a[i]を読み込む(1<=i<=n)
    a = sorted(list(map(int, input().strip().split())))
    
    a_sub = 1000000
    for i in range(n-1):
      if abs(a[i]-a[i+1]) < a_sub :
        a_sub =  abs(a[i]-a[i+1])
    print(a_sub)