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: Accepted

Solution code:
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    N = int(input())
    if N == 0:
        exit()
    L = list(map(int, input().split()))
    L = sorted(L)
    min_diff = float('inf')
    for l1, l2 in zip(L, L[1:]):
        min_diff = min(min_diff, abs(l1-l2))
    print(min_diff)


while True:
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
j = 0
while 1:
    m = int(input())
    if m == 0:
        break
    a = list(map(int,input().split()))
    min = 99999999999
    a.sort()
    for i in range(len(a)-1):
        num = a[i+1] - a[i]
        if min > num:
            min = num
    print(min)
    j += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def solve(n,a):
    
    a.sort()
    ans = abs(a[0]-a[1])
    for i in range(n-1):
        ans = min(ans,abs(a[i] - a[i+1]))
    return ans

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

Submission status: Accepted

Solution code:
def main():
    while True:
        s_num = int(input())
        
        if s_num == 0:
            return
        
        s_dat = input()
        s_dat = s_dat.split(" ")
        
        for j in range(len(s_dat)):
            s_dat[j] = int(s_dat[j])
            
        s_dat.sort()

        answer = sa(s_dat)
        print(answer)

def sa(array):
    min_dist = 1000000 + 1
    
    for i in range(len(array) - 1):
        dist = array[i + 1] - array[i]
        
        if dist <= min_dist:
            min_dist = dist

    return min_dist
    
main()

Submission status: Accepted

Solution code:
n=int(input())
while n!=0:
    a=list(map(int,input().split()))
    ans=10**18
    for i in range(len(a)):
        for j in range(len(a)):
            if i!=j:
                ans=min(ans,abs(a[i]-a[j]))
    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()))
    a.sort()
    ans=float("inf")
    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

    data = list(map(int, input().split()))
    data.sort()

    ans = 10**9
    for i in range(1, n):
        if data[i] - data[i-1] < ans:
            ans = data[i] - data[i-1]

    print(ans)

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:
e=1
while e==1:
    n = int ( input() )
    if n==0:
        break
    a = input().split(" ")
    for j in  range(n):
        a[j] = int( a[j])
    a.sort()

    sa=11451419

    for i in range ( n-1 ):
        sa = min (sa ,a[i+1] - a[i])

    print(sa)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
min_list = []
while True:
    n = int(input())
    if n == 0:
        break
    s = list(map(int, input().split()))
    s.sort(reverse=True)
    min1 = s[0] - s[1]
    for i in range(n-1):
        min1 = min(min1, s[i]-s[i+1])
    min_list.append(min1)

for i in range(len(min_list)):
    print(min_list[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
f = sys.stdin
while True:
    n = int(f.readline())
    if n == 0:
        break
    myset = set()
    diff = sys.maxsize
    for tmp in f.readline().split():
        tmp = int(tmp)
        for score in myset:
            if abs(tmp - score) < diff:
                diff = abs(tmp - score)
                if diff == 0:
                    break
        myset.add(tmp)
    print(diff)

Submission status: Accepted

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

    d = 11234567
    for i in range(n-1):
        d = min(d, s[i+1]-s[i])
    print(d)

Submission status: Accepted

Solution code:
def getMinGap(data):
	result = list()
	for n in range(len(data)):
		for m in range(n + 1, len(data)):
			result.append(abs(data[n] - data[m]))
	result = set(result)
	return min(result)

while  True:
	n = int(input())
	if n == 0:
		break
	data = [int(x) for x in input().split()]
	print(getMinGap(data))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
while 1:
    n=int(input())
    if n==0:
        break
    d=sorted(list(map(int,input().split())))
    mn=99999999
    for i in range(1,len(d)):
        mn=min(mn,d[i]-d[i-1])
    print(mn)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

Solution code:
while True:
	n,m = map(int,input().split())
	if n == 0 and m == 0:	
		break
	a = list(map(int,input().split()))
	a.sort()
	list1 = []
	for i in range(n):
		for j in range(i + 1, n):
		 	price1 = a[i] + a[j]
		 	list1.append(price1)
	list1.sort()
	list2 = list(filter(lambda p: m >= p, list1))


	if list2:
		print(max(list2))
	else:
		print("NONE")

Submission status: Runtime Error

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 == []:
        continue
    if n == 0:
        break
    print(min(l))

Submission status: Runtime Error

Solution code:
flg = True
while flg:
    n = int(input())
    if n == 0:
        flg = False
    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]))
    if l == []:
        continue
    print(min(l))