Which Team Should Receive the Sponsor Prize?
Source: aizu

Problem A
Which Team Should Receive the Sponsor Prize?

In ICQC (International Collegiate Quiz Contest), participating teams compete the speed of answering a difficult quiz. The winner is, of course, the team that gives the correct answer first. In addition to this, in the contest this year, a sponsor prize will be provided to the team with the time of giving the correct answer closest to 2023 seconds after the start of the contest.

Given the list of elapsed times from the start of the contest before giving the correct answer for all the participating teams, decide which team is to be provided the sponsor prize.

Input

The input consists of multiple datasets, each in the following format. The number of datasets does not exceed 50.

n
a1 a2 ⋯ an


The integer n is the number of participating teams within the range between 2 and 100, inclusive. The teams are numbered 1 through n. ak (k = 1, ..., n) is a positive integer not exceeding 104. It represents the elapsed time in seconds before the correct answer was given by the team numbered k. You may assume that one unique team has the elapsed time before answering correctly closest to 2023 seconds.

The end of the input is indicated by a line consisting of a zero.

Output

For each dataset, output in a line the team number of the team to be provided the sponsor prize.

Sample Input
2
123 4567
3
2024 2020 2023
5
2020 2020 2021 2024 2026
3
1599 2222 1599
8
2 2 3 3 4 4 5 1
4
7777 6666 8888 9999
0

Output for the Sample Input
1
3
4
2
7
2


C++ solution:
#include <stdio.h>
#include <stdlib.h>

#define SEC 2023

int main()
{
  int n;
  int a[101] = { 0 };

  while (1) {
    scanf("%d", &n);

    if (n == 0) break;

    for (int i = 1; i < n + 1; i++) {
      scanf("%d", &a[i]);
      a[i] = abs(SEC - a[i]);
    }

    int min = 10000;
    int team = 0;

    for (int i = 1; i < n + 1; i++) {
      if (a[i] < min) {
        min = a[i];
        team = i;
      }
    }

    printf("%d\n", team);
  }

  return 0;
}

Go solution:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for {
		// Read number of teams
		if !scanner.Scan() {
			break
		}
		nStr := scanner.Text()
		n, err := strconv.Atoi(nStr)
		if err != nil || n == 0 {
			break
		}

		// Read team times
		if !scanner.Scan() {
			break
		}
		timesStr := strings.Fields(scanner.Text())
		if len(timesStr) != n {
			continue // skip invalid input
		}

		// Find team with time closest to 2023
		minDiff := math.MaxInt32
		team := 1
		for i := 0; i < n; i++ {
			time, err := strconv.Atoi(timesStr[i])
			if err != nil {
				continue // skip invalid time
			}
			diff := int(math.Abs(float64(time - 2023)))
			if diff < minDiff {
				minDiff = diff
				team = i + 1
			}
		}

		fmt.Println(team)
	}
}

Java solution:
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            if (n == 0) break;
            
            int closestTeam = 1;
            int minDiff = Integer.MAX_VALUE;
            
            for (int i = 0; i < n; i++) {
                int time = sc.nextInt();
                int diff = Math.abs(time - 2023);
                if (diff < minDiff) {
                    minDiff = diff;
                    closestTeam = i + 1;
                }
            }
            System.out.println(closestTeam);
        }
        sc.close();
    }
}

JavaScript solution:
/* Generated by the Nim Compiler v1.6.14 */
var framePtr = null;
var excHandler = 0;
var lastJSError = null;
var NTI33554456 = {size: 0,kind: 31,base: null,node: null,finalizer: null};
var NTI486539304 = {size: 0, kind: 24, base: null, node: null, finalizer: null};
var NTI33555128 = {size: 0, kind: 17, base: null, node: null, finalizer: null};
var NTI33555130 = {size: 0, kind: 17, base: null, node: null, finalizer: null};
var NTI33555083 = {size: 0, kind: 17, base: null, node: null, finalizer: null};
var NTI33555165 = {size: 0, kind: 22, base: null, node: null, finalizer: null};
var NTI33554439 = {size: 0,kind: 28,base: null,node: null,finalizer: null};
var NTI33554440 = {size: 0,kind: 29,base: null,node: null,finalizer: null};
var NTI33555164 = {size: 0, kind: 22, base: null, node: null, finalizer: null};
var NTI33555112 = {size: 0, kind: 17, base: null, node: null, finalizer: null};
var NTI33555113 = {size: 0, kind: 17, base: null, node: null, finalizer: null};
var NTI33555120 = {size: 0, kind: 17, base: null, node: null, finalizer: null};
var NTI33555122 = {size: 0, kind: 17, base: null, node: null, finalizer: null};
var NNI33555122 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []};
NTI33555122.node = NNI33555122;
var NNI33555120 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []};
NTI33555120.node = NNI33555120;
var NNI33555113 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []};
NTI33555113.node = NNI33555113;
NTI33555164.base = NTI33555112;
NTI33555165.base = NTI33555112;
var NNI33555112 = {kind: 2, len: 5, offset: 0, typ: null, name: null, sons: [{kind: 1, offset: "parent", len: 0, typ: NTI33555164, name: "parent", sons: null}, 
{kind: 1, offset: "name", len: 0, typ: NTI33554440, name: "name", sons: null}, 
{kind: 1, offset: "message", len: 0, typ: NTI33554439, name: "msg", sons: null}, 
{kind: 1, offset: "trace", len: 0, typ: NTI33554439, name: "trace", sons: null}, 
{kind: 1, offset: "up", len: 0, typ: NTI33555165, name: "up", sons: null}]};
NTI33555112.node = NNI33555112;
var NNI33555083 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []};
NTI33555083.node = NNI33555083;
NTI33555112.base = NTI33555083;
NTI33555113.base = NTI33555112;
NTI33555120.base = NTI33555113;
NTI33555122.base = NTI33555120;
var NNI33555130 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []};
NTI33555130.node = NNI33555130;
NTI33555130.base = NTI33555113;
var NNI33555128 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []};
NTI33555128.node = NNI33555128;
NTI33555128.base = NTI33555113;
NTI486539304.base = NTI33554456;

function makeNimstrLit(c_33556801) {
      var result = [];
  for (var i = 0; i < c_33556801.length; ++i) {
    result[i] = c_33556801.charCodeAt(i);
  }
  return result;
  

  
}

function mnewString(len_33556893) {
        return new Array(len_33556893);
  

  
}

function toJSStr(s_33556807) {
                    var Temporary5;

  var result_33556808 = null;

    var res_33556842 = newSeq_33556825((s_33556807).length);
    var i_33556843 = 0;
    var j_33556844 = 0;
    Label1: do {
        Label2: while (true) {
        if (!(i_33556843 < (s_33556807).length)) break Label2;
          var c_33556845 = s_33556807[i_33556843];
          if ((c_33556845 < 128)) {
          res_33556842[j_33556844] = String.fromCharCode(c_33556845);
          i_33556843 += 1;
          }
          else {
            var helper_33556857 = newSeq_33556825(0);
            Label3: do {
                Label4: while (true) {
                if (!true) break Label4;
                  var code_33556858 = c_33556845.toString(16);
                  if ((((code_33556858) == null ? 0 : (code_33556858).length) == 1)) {
                  helper_33556857.push("%0");;
                  }
                  else {
                  helper_33556857.push("%");;
                  }
                  
                  helper_33556857.push(code_33556858);;
                  i_33556843 += 1;
                    if (((s_33556807).length <= i_33556843)) Temporary5 = true; else {                      Temporary5 = (s_33556807[i_33556843] < 128);                    }                  if (Temporary5) {
                  break Label3;
                  }
                  
                  c_33556845 = s_33556807[i_33556843];
                }
            } while (false);
++excHandler;
            try {
            res_33556842[j_33556844] = decodeURIComponent(helper_33556857.join(""));
--excHandler;
} catch (EXCEPTION) {
 var prevJSError = lastJSError;
 lastJSError = EXCEPTION;
 --excHandler;
            res_33556842[j_33556844] = helper_33556857.join("");
            lastJSError = prevJSError;
            } finally {
            }
          }
          
          j_33556844 += 1;
        }
    } while (false);
    if (res_33556842.length < j_33556844) { for (var i = res_33556842.length ; i < j_33556844 ; ++i) res_33556842.push(null); }
               else { res_33556842.length = j_33556844; };
    result_33556808 = res_33556842.join("");

  return result_33556808;

}

function raiseException(e_33556667, ename_33556668) {
    e_33556667.name = ename_33556668;
    if ((excHandler == 0)) {
    unhandledException(e_33556667);
    }
    
    throw e_33556667;

  
}

function addInt(a_33556940, b_33556941) {
        var result = a_33556940 + b_33556941;
    checkOverflowInt(result);
    return result;
  

  
}

function chckRange(i_33557189, a_33557190, b_33557191) {
      var Temporary1;

  var result_33557192 = 0;

  BeforeRet: do {
      if (!(a_33557190 <= i_33557189)) Temporary1 = false; else {        Temporary1 = (i_33557189 <= b_33557191);      }    if (Temporary1) {
    result_33557192 = i_33557189;
    break BeforeRet;
    }
    else {
    raiseRangeError();
    }
    
  } while (false);

  return result_33557192;

}

function setConstr() {
        var result = {};
    for (var i = 0; i < arguments.length; ++i) {
      var x = arguments[i];
      if (typeof(x) == "object") {
        for (var j = x[0]; j <= x[1]; ++j) {
          result[j] = true;
        }
      } else {
        result[x] = true;
      }
    }
    return result;
  

  
}
var ConstSet1 = setConstr(17, 16, 4, 18, 27, 19, 23, 22, 21);

function nimCopy(dest_33557140, src_33557141, ti_33557142) {
  var result_33557151 = null;

    switch (ti_33557142.kind) {
    case 21:
    case 22:
    case 23:
    case 5:
      if (!(isFatPointer_33557131(ti_33557142))) {
      result_33557151 = src_33557141;
      }
      else {
        result_33557151 = [src_33557141[0], src_33557141[1]];
      }
      
      break;
    case 19:
            if (dest_33557140 === null || dest_33557140 === undefined) {
        dest_33557140 = {};
      }
      else {
        for (var key in dest_33557140) { delete dest_33557140[key]; }
      }
      for (var key in src_33557141) { dest_33557140[key] = src_33557141[key]; }
      result_33557151 = dest_33557140;
    
      break;
    case 18:
    case 17:
      if (!((ti_33557142.base == null))) {
      result_33557151 = nimCopy(dest_33557140, src_33557141, ti_33557142.base);
      }
      else {
      if ((ti_33557142.kind == 17)) {
      result_33557151 = (dest_33557140 === null || dest_33557140 === undefined) ? {m_type: ti_33557142} : dest_33557140;
      }
      else {
        result_33557151 = (dest_33557140 === null || dest_33557140 === undefined) ? {} : dest_33557140;
      }
      }
      nimCopyAux(result_33557151, src_33557141, ti_33557142.node);
      break;
    case 24:
    case 4:
    case 27:
    case 16:
            if (src_33557141 === null) {
        result_33557151 = null;
      }
      else {
        if (dest_33557140 === null || dest_33557140 === undefined || dest_33557140.length != src_33557141.length) {
          dest_33557140 = new Array(src_33557141.length);
        }
        result_33557151 = dest_33557140;
        for (var i = 0; i < src_33557141.length; ++i) {
          result_33557151[i] = nimCopy(result_33557151[i], src_33557141[i], ti_33557142.base);
        }
      }
    
      break;
    case 28:
            if (src_33557141 !== null) {
        result_33557151 = src_33557141.slice(0);
      }
    
      break;
    default: 
      result_33557151 = src_33557141;
      break;
    }

  return result_33557151;

}

function chckIndx(i_33557184, a_33557185, b_33557186) {
      var Temporary1;

  var result_33557187 = 0;

  BeforeRet: do {
      if (!(a_33557185 <= i_33557184)) Temporary1 = false; else {        Temporary1 = (i_33557184 <= b_33557186);      }    if (Temporary1) {
    result_33557187 = i_33557184;
    break BeforeRet;
    }
    else {
    raiseIndexError(i_33557184, a_33557185, b_33557186);
    }
    
  } while (false);

  return result_33557187;

}

function mulInt(a_33556948, b_33556949) {
        var result = a_33556948 * b_33556949;
    checkOverflowInt(result);
    return result;
  

  
}

function subInt(a_33556944, b_33556945) {
        var result = a_33556944 - b_33556945;
    checkOverflowInt(result);
    return result;
  

  
}

function genericReset(x_33557171, ti_33557172) {
  var result_33557173 = null;

    result_33557173 = null;
    switch (ti_33557172.kind) {
    case 21:
    case 22:
    case 23:
    case 5:
      if (isFatPointer_33557131(ti_33557172)) {
              result_33557173 = [null, 0];
      
      }
      
      break;
    case 19:
            result_33557173 = {};
    
      break;
    case 18:
    case 17:
      if ((ti_33557172.kind == 17)) {
      result_33557173 = {m_type: ti_33557172};
      }
      else {
        result_33557173 = {};
      }
      
      break;
    case 24:
    case 27:
    case 28:
            result_33557173 = [];
    
      break;
    case 4:
    case 16:
            result_33557173 = new Array(x_33557171.length);
      for (var i = 0; i < x_33557171.length; ++i) {
        result_33557173[i] = genericReset(x_33557171[i], ti_33557172.base);
      }
    
      break;
    default: 
      break;
    }

  return result_33557173;

}

function absInt(a_33556988) {
    var Temporary1;

  var result_33556989 = 0;

    if ((a_33556988 < 0)) {
    Temporary1 = (a_33556988 * -1);
    }
    else {
    Temporary1 = a_33556988;
    }
    
    result_33556989 = Temporary1;

  return result_33556989;

}

function rawEcho() {
          var buf = "";
      for (var i = 0; i < arguments.length; ++i) {
        buf += toJSStr(arguments[i]);
      }
      console.log(buf);
    

  
}
var inp_486539267 = makeNimstrLit(require("fs").readFileSync("/dev/stdin","utf8"));
var inpc_486539268 = [0];

function add_33556419(x_33556420, x_33556420_Idx, y_33556421) {
          if (x_33556420[x_33556420_Idx] === null) { x_33556420[x_33556420_Idx] = []; }
      var off = x_33556420[x_33556420_Idx].length;
      x_33556420[x_33556420_Idx].length += y_33556421.length;
      for (var i = 0; i < y_33556421.length; ++i) {
        x_33556420[x_33556420_Idx][off+i] = y_33556421.charCodeAt(i);
      }
    

  
}

function newSeq_33556825(len_33556827) {
  var result_33556828 = [];

    result_33556828 = new Array(len_33556827); for (var i = 0 ; i < len_33556827 ; ++i) { result_33556828[i] = null; }
  return result_33556828;

}

function unhandledException(e_33556663) {
    var buf_33556664 = [[]];
    if (!(((e_33556663.message).length == 0))) {
    buf_33556664[0].push.apply(buf_33556664[0], makeNimstrLit("Error: unhandled exception: "));;
    buf_33556664[0].push.apply(buf_33556664[0], e_33556663.message);;
    }
    else {
    buf_33556664[0].push.apply(buf_33556664[0], makeNimstrLit("Error: unhandled exception"));;
    }
    
    buf_33556664[0].push.apply(buf_33556664[0], makeNimstrLit(" ["));;
    add_33556419(buf_33556664, 0, e_33556663.name);
    buf_33556664[0].push.apply(buf_33556664[0], makeNimstrLit("]\x0A"));;
    var cbuf_33556665 = toJSStr(buf_33556664[0]);
      if (typeof(Error) !== "undefined") {
    throw new Error(cbuf_33556665);
  }
  else {
    throw cbuf_33556665;
  }
  

  
}

function raiseOverflow() {
    raiseException({message: makeNimstrLit("over- or underflow"), parent: null, m_type: NTI33555122, name: null, trace: [], up: null}, "OverflowDefect");

  
}

function checkOverflowInt(a_33556938) {
        if (a_33556938 > 2147483647 || a_33556938 < -2147483648) raiseOverflow();
  

  
}

function raiseRangeError() {
    raiseException({message: makeNimstrLit("value out of range"), parent: null, m_type: NTI33555130, name: null, trace: [], up: null}, "RangeDefect");

  
}

function addChars_251658415(result_251658417, result_251658417_Idx, x_251658418, start_251658419, n_251658420) {
    var old_251658421 = (result_251658417[result_251658417_Idx]).length;
    (result_251658417[result_251658417_Idx].length = chckRange(addInt(old_251658421, n_251658420), 0, 2147483647));
    Label1: do {
      var iHEX60gensym4_251658435 = 0;
      var i_486539381 = 0;
      Label2: do {
          Label3: while (true) {
          if (!(i_486539381 < n_251658420)) break Label3;
            iHEX60gensym4_251658435 = i_486539381;
            result_251658417[result_251658417_Idx][chckIndx(addInt(old_251658421, iHEX60gensym4_251658435), 0, (result_251658417[result_251658417_Idx]).length - 1)] = x_251658418.charCodeAt(chckIndx(addInt(start_251658419, iHEX60gensym4_251658435), 0, (x_251658418).length - 1));
            i_486539381 = addInt(i_486539381, 1);
          }
      } while (false);
    } while (false);

  
}

function addChars_251658411(result_251658413, result_251658413_Idx, x_251658414) {
    addChars_251658415(result_251658413, result_251658413_Idx, x_251658414, 0, ((x_251658414) == null ? 0 : (x_251658414).length));

  
}

function addInt_251658436(result_251658437, result_251658437_Idx, x_251658438) {
    addChars_251658411(result_251658437, result_251658437_Idx, ((x_251658438) + ""));

  
}

function addInt_251658457(result_251658458, result_251658458_Idx, x_251658459) {
    addInt_251658436(result_251658458, result_251658458_Idx, x_251658459);

  
}

function HEX24_352321539(x_352321540) {
  var result_352321541 = [[]];

    addInt_251658457(result_352321541, 0, x_352321540);

  return result_352321541[0];

}

function isFatPointer_33557131(ti_33557132) {
  var result_33557133 = false;

  BeforeRet: do {
    result_33557133 = !((ConstSet1[ti_33557132.base.kind] != undefined));
    break BeforeRet;
  } while (false);

  return result_33557133;

}

function nimCopyAux(dest_33557144, src_33557145, n_33557146) {
    switch (n_33557146.kind) {
    case 0:
      break;
    case 1:
            dest_33557144[n_33557146.offset] = nimCopy(dest_33557144[n_33557146.offset], src_33557145[n_33557146.offset], n_33557146.typ);
    
      break;
    case 2:
          for (var i = 0; i < n_33557146.sons.length; i++) {
      nimCopyAux(dest_33557144, src_33557145, n_33557146.sons[i]);
    }
    
      break;
    case 3:
            dest_33557144[n_33557146.offset] = nimCopy(dest_33557144[n_33557146.offset], src_33557145[n_33557146.offset], n_33557146.typ);
      for (var i = 0; i < n_33557146.sons.length; ++i) {
        nimCopyAux(dest_33557144, src_33557145, n_33557146.sons[i][1]);
      }
    
      break;
    }

  
}

function raiseIndexError(i_33556754, a_33556755, b_33556756) {
    var Temporary1;

    if ((b_33556756 < a_33556755)) {
    Temporary1 = makeNimstrLit("index out of bounds, the container is empty");
    }
    else {
    Temporary1 = (makeNimstrLit("index ") || []).concat(HEX24_352321539(i_33556754) || [],makeNimstrLit(" not in ") || [],HEX24_352321539(a_33556755) || [],makeNimstrLit(" .. ") || [],HEX24_352321539(b_33556756) || []);
    }
    
    raiseException({message: nimCopy(null, Temporary1, NTI33554439), parent: null, m_type: NTI33555128, name: null, trace: [], up: null}, "IndexDefect");

  
}

function getchar_486539269() {
  var result_486539270 = 0;

  BeforeRet: do {
    var res_486539271 = inp_486539267[chckIndx(inpc_486539268[0], 0, (inp_486539267).length - 1)];
    inpc_486539268[0] = addInt(inpc_486539268[0], 1);
    result_486539270 = res_486539271;
    break BeforeRet;
  } while (false);

  return result_486539270;

}

function HEX2AHEX3D_486539282(x_486539284, x_486539284_Idx, y_486539285) {
    x_486539284[x_486539284_Idx] = mulInt(x_486539284[x_486539284_Idx], y_486539285);

  
}

function nextInt_486539276(base_486539277) {
  var result_486539278 = [0];

    var get_486539279 = false;
    var sgn_486539280 = false;
    Label1: do {
        Label2: while (true) {
        if (!true) break Label2;
          var c_486539281 = ((getchar_486539269()) | 0);
          if ((32 < c_486539281)) {
          get_486539279 = true;
          if ((c_486539281 == 45)) {
          sgn_486539280 = true;
          }
          else {
            result_486539278[0] = addInt(mulInt(result_486539278[0], 10), subInt(c_486539281, 48));
          }
          
          }
          else {
          if (get_486539279) {
          break Label1;
          }
          }
        }
    } while (false);
    if (sgn_486539280) {
    HEX2AHEX3D_486539282(result_486539278, 0, -1);
    }
    
    result_486539278[0] = subInt(result_486539278[0], base_486539277);

  return result_486539278[0];

}

function newSeq_486539316(len_486539318) {
  var result_486539319 = [];

    result_486539319 = new Array(len_486539318); for (var i = 0 ; i < len_486539318 ; ++i) { result_486539319[i] = 0; }
  return result_486539319;

}

function solve_486539295(n_486539296, a_486539297) {
  var result_486539298 = 0;

  BeforeRet: do {
    var te1_486539299 = 1000000000;
    var res_486539300 = -1;
    Label1: do {
      var i_486539305 = 0;
      var i_486539386 = 0;
      Label2: do {
          Label3: while (true) {
          if (!(i_486539386 < n_486539296)) break Label3;
            i_486539305 = i_486539386;
            var te2_486539306 = absInt(subInt(a_486539297[chckIndx(i_486539305, 0, (a_486539297).length - 1)], 2023));
            if ((te2_486539306 < te1_486539299)) {
            te1_486539299 = te2_486539306;
            res_486539300 = addInt(i_486539305, 1);
            }
            
            i_486539386 = addInt(i_486539386, 1);
          }
      } while (false);
    } while (false);
    result_486539298 = res_486539300;
    break BeforeRet;
  } while (false);

  return result_486539298;

}

function join_486539351(a_486539353, sep_486539354) {
  var result_486539355 = [];

    result_486539355 = nimCopy(null, [], NTI33554439);
    Label1: do {
      var i_486539370 = 0;
      var x_486539371 = 0;
      var i_486539390 = 0;
      Label2: do {
          Label3: while (true) {
          if (!(i_486539390 < (a_486539353).length)) break Label3;
            i_486539370 = i_486539390;
            x_486539371 = a_486539353[chckIndx(i_486539390, 0, (a_486539353).length - 1)];
            if ((0 < i_486539370)) {
            result_486539355.push.apply(result_486539355, sep_486539354);;
            }
            
            result_486539355.push.apply(result_486539355, HEX24_352321539(x_486539371));;
            i_486539390 = addInt(i_486539390, 1);
          }
      } while (false);
    } while (false);

  return result_486539355;

}

function main_486539307() {
          var Temporary6;

  BeforeRet: do {
    var res_486539312 = [];
    Label1: do {
        Label2: while (true) {
        if (!true) break Label2;
          var n_486539313 = nextInt_486539276(0);
          if ((n_486539313 == 0)) {
          break Label1;
          }
          
          var resultHEX60gensym2_486539333 = newSeq_486539316(chckRange(n_486539313, 0, 2147483647));
          Label3: do {
            var iHEX60gensym2_486539338 = 0;
            var i_486539374 = 0;
            Label4: do {
                Label5: while (true) {
                if (!(i_486539374 < n_486539313)) break Label5;
                  iHEX60gensym2_486539338 = i_486539374;
                  resultHEX60gensym2_486539333[chckIndx(iHEX60gensym2_486539338, 0, (resultHEX60gensym2_486539333).length - 1)] = nextInt_486539276(0);
                  i_486539374 = addInt(i_486539374, 1);
                }
            } while (false);
          } while (false);
          Temporary6 = resultHEX60gensym2_486539333;
          resultHEX60gensym2_486539333 = genericReset(resultHEX60gensym2_486539333, NTI486539304);
          var a_486539346 = nimCopy(null, Temporary6, NTI486539304);
          res_486539312.push(solve_486539295(n_486539313, a_486539346));;
        }
    } while (false);
    rawEcho(join_486539351(res_486539312, makeNimstrLit("\x0A")));
    break BeforeRet;
  } while (false);

  
}
main_486539307();

Python solution:
while 1:
    n = int(input())
    if n == 0:
        break
    else:
        a = list(map(int, input().split()))
        ans = 0
        for i in range(1, n):
            if abs(a[i] - 2023) < abs(a[ans] - 2023):
                ans = i
        print(ans + 1)

Ruby solution:
while true
    n = gets.to_i
    break if n == 0
    idx = diff = 10000
    arr = gets.chomp.split.map(&:to_i)
    arr.each_with_index{|v, i|
        if diff > (v - 2023).abs
            diff = (v - 2023).abs
            idx = i + 1
        end
    }
    puts idx
end