#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long INFLL = 1e12;
const long long MOD = 1000000007;
const long double eps = 1e-6;
const long long MOD2 = (1 << 30) + 1;
const long long dosz = 5e5;
void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
string s;
void solve() {
  long long n;
  cin >> n;
  cin >> s;
  long long ans = 0;
  for (long long i = n; i < s.size(); i += n) {
    if (s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) {
      ans++;
    }
  }
  cout << ans;
}
signed main() {
  fast_io();
  long long q = 1;
  while (q--) {
    solve();
  }
  return 0;
}

n = int(input())
moves = input()
i = n
count = 0
while(i < len(moves)):
    m = moves[i - 1]
    if(m == moves[i - 2] and m == moves[i - 3] and m == moves[i - 3]):
        count += 1
    i += n
print(count)


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.StringTokenizer;

public class C {

	private void add(int[] p, int a) {
		for (int j = 0; j < 30; j++) {
			if ((a & (1 << j)) != 0) {
				p[j]++;
			}
		}
	}

	private void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();

		int[] p = new int[30];
		for (int i = 0; i < n; i++) {
			add(p, nextInt());
		}

		int[] b = new int[30];
		for (int i = 0; i < m; i++) {
			b[nextInt()]++;
		}

		int res = 0;
		for (int i = 0; i < 30; i++) {
			int d = 1;
			for (int j = i; j < 30; j++) {
				if (p[j] * d >= b[i]) {
					res += b[i];
					p[j] -= b[i] / d;
					if (b[i] % d != 0) {
						p[j]--;
						add(p, (1 << j) - (b[i] % d) * (1 << i));
					}
					break;
				} else {
					b[i] -= p[j] * d;
					res += p[j] * d;
					p[j] = 0;
					d *= 2;
				}
			}
		}

		println(res);
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	private int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	private double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private void print(Object o) {
		writer.print(o);
	}

	private void println(Object o) {
		writer.println(o);
	}

	private void printf(String format, Object... o) {
		writer.printf(format, o);
	}

	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		Locale.setDefault(Locale.US);
		new C().run();
		System.err.printf("%.3f\n", 1e-3 * (System.currentTimeMillis() - time));
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	private void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(13);
		}
	}
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> mems;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    mems.push_back(a);
  }
  sort(mems.begin(), mems.end());
  vector<int> need(40);
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    need[a]++;
  }
  int out = 0;
  for (int i = 0; i < 32; i++) {
    int now = need[i];
    for (auto& it : mems) {
      if ((it & 1) && now) {
        now--;
        it -= 1;
        out++;
      }
    }
    for (auto& it : mems) {
      auto toSub = min(it, now);
      now -= toSub;
      it -= toSub;
      out += toSub;
      it /= 2;
    }
  }
  cout << out << endl;
  return 0;
}


import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.FileReader;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.File;
import java.io.Writer;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author monsterspy
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        Output out = new Output(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskC {
    <T extends Comparable<T>> T min(T [] A) {
        return A[imin(A)];
    }

    <T extends Comparable<T>> int imin(T [] A) {
        int res = 0, N = A.length;
        for (int i = 1; i < N; ++i)
            if (A[i].compareTo(A[res]) < 0)
                res = i;
        return res;
    }
    public void solve(int testNumber, FastScanner s, Output ww) {
        try{
            int N = s.nextInt();
            int X = s.nextInt() - 1;
            Long [] A = new Long[N];
            for(int i=0;i<N;i++)  A[i] = s.nextLong();

            long M = min(A), C = 0;
            int W; for (W = X; A[W] != M; --W) {
                --A[W]; ++C;
                if (W == 0)
                    W = N;
            }
            A[W] += C;

            for (int i = 0; i < N; ++i)
                A[i] -= M;
            A[W] += M * N;

            for(Long i : A) ww.print(i+" ");

        }catch(Exception e){
            e.printStackTrace();
        }
    }
}

class FastScanner {
    BufferedReader s;
    StringTokenizer st;

    public FastScanner(InputStream InputStream){
        st = new StringTokenizer("");
        s = new BufferedReader(new InputStreamReader(InputStream));
    }

    public FastScanner(File f) throws FileNotFoundException{
        st = new StringTokenizer("");
        s = new BufferedReader (new FileReader(f));
    }

    public int nextInt() throws IOException{
        if(st.hasMoreTokens())
            return Integer.parseInt(st.nextToken());
        else{
            st = new StringTokenizer(s.readLine());
            return nextInt();
        }
    }

    public long nextLong() throws IOException{
        if(st.hasMoreTokens())
            return Long.parseLong(st.nextToken());
        else{
            st = new StringTokenizer(s.readLine());
            return nextLong();
        }
    }

}

class Output {

    private final PrintWriter writer;

    public Output(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public Output(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void close() {
        writer.close();
    }

}

#include <bits/stdc++.h>
using namespace std;
long long n, x, a[100001];
signed main() {
  cin >> n >> x;
  long long mn = 9e18;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] < mn) {
      mn = a[i];
    }
  }
  for (long long i = 1; i <= n; ++i) {
    a[i] -= mn;
  }
  long long now = x, sum = mn * n;
  while (1) {
    if (a[now] == 0) {
      a[now] += sum;
      for (long long i = 1; i <= n; ++i) {
        cout << a[i] << ' ';
      }
      return 0;
    }
    --a[now];
    ++sum;
    now = now == 1 ? n : now - 1;
  }
  return 0;
}


primes = []
d = {}
for i in range(2, 100):
    if i not in d:
        primes.append(i)
        j = 2
        while i * j < 100:
            d[i*j] = 1
            j += 1

def solve(x,y,z):
    d = {}
    for p in primes:
        d[p] = 0

    for p in primes:
        if p > x and p > y and p > z:
            break
        while x%p == 0:
            x /= p
            d[p] += 1
        while y%p == 0:
            y /= p
            d[p] += 1
        while z%p == 0:
            z /= p
            d[p] += 1
    ans = 1
    for p in primes:
        ans *= d[p] + 1
    return ans

a,b,c = map(int,input().split(' '))
ans = 0
seen = {}

for i in range(1, a+1):
    for j in range(1, b+1):
        for k in range(1, c+1):
            p = i*j*k
            if p in seen:
                ans = (ans + seen[p]) % 1073741824
            else:
                temp = solve(i,j,k)
                ans = (ans + temp) % 1073741824
                seen[p] = temp

print(ans)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Cf236b {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskA {
    static final int MAX = 1000001;

    private List<Integer> generatePrimes(int n) {
        List<Integer> primes = new ArrayList<Integer>();
        if (n < 2) return primes;
        primes.add(2);
        if (n < 3) return primes;
        int[] buffer = new int[MAX];
        buffer[2] = 1;
        n++;
        for (int i = 3; i < n; i += 2) {
            if (buffer[i] == 0) {
                primes.add(i);
                for (int j = i * 2; j < n; j += i) {
                    buffer[j] = 1;
                }
            }
        }
        return primes;
    }

    private int countDivisor(int n, List<Integer> primes) {
        int res = 1;
        for (int p : primes) {
            if (n < p) break;
            int counter = 1;
            while (n % p == 0) {
                counter++;
                n /= p;
            }
            res *= counter;
        }
        return res;
    }

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        List<Integer> primes = generatePrimes(100);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int res = 0;
        int[] buffer = new int[MAX];

        buffer[1] = 1;

        for (int i = 1; i <= a; i++) {
            for (int j = 1; j <= b; j++) {
                for (int k = 1; k <= c; k++) {
                    int product = i * j * k;
                    if (buffer[product] == 0 && product > 1) {
                        buffer[product] = countDivisor(product, primes);
                    }
                    res += buffer[product];
                }
            }
        }

        out.println(res);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
}


import java.io.*;
import java.util.*;

public class Main {
	private static void solve() throws Exception {
		String s = in.readLine();

		boolean neg = false;
		if (s.startsWith("-")) {
			neg = true;
			s = s.substring(1);
		}

		if (neg) out.print("(");
		out.print("$");

		String st, nd;
		if (s.indexOf('.') != -1) {
			String[] t = s.split("\\.");
			st = t[0];
			if (t[1].length() > 2) {
				nd = t[1].substring(0, 2);
			} else {
				nd = t[1];
				while (nd.length() != 2) {
					nd += "0";
				}
			}
		} else {
			st = s;
			nd = "00";
		}

		if (st.length() > 3) {
			int k = st.length()%3 == 0 ? 3 : st.length()%3;
			String r = st.substring(0, k);
			st = st.substring(k);
			for (int i = 0; i < st.length(); i += 3) {
				r += "," + st.substring(i, i+3);
			}
			st = r;
		}

		out.print(st + "." + nd);

		if (neg) out.print(")");
		out.println();
	}

	public static void main(String[] args) throws Exception {
		in  = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		solve();
		out.flush();
	}

	private static BufferedReader in;
	private static PrintWriter    out;
}

import math
import sys
import collections

# imgur.com/Pkt7iIf.png

def getdict(n):
    d = {}
    if type(n) is list:
        for i in n:
            if i in d:
                d[i] += 1
            else:
                d[i] = 1
    else:
        for i in range(n):
            t = ii()
            if t in d:
                d[t] += 1
            else:
                d[t] = 1
    return d
def cdiv(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)

s = input()
t = s.split('.') if '.' in s else [s, '']
a, b = t[0], t[1]
b += '00'
neg = False
if a[0] == '-':
    neg = True
    a = a[1:]
r = []
for i in range(len(a), 0, -3):
    r.append(a[max(0, i-3):i])
r.reverse()
res = ','.join(r) + '.' + b[0:2]
print(f'(${res})') if neg else print(f'${res}')


s=input()
n= len(s)
print(4)
print("L",2)
print("R",n)
print("R",2)
print("R",2*n+1)

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
bool pal(string s, long long n) {
  for (long long i = 0; i < n / 2; i++) {
    if (s[i] != s[n - i - 1]) return false;
  }
  return true;
}
void solve() {
  string s;
  cin >> s;
  long long n = s.length();
  if (pal(s, n)) {
    cout << 0 << "\n";
    return;
  } else {
    cout << 3 << "\n";
    cout << "L " << 2 << "\n";
    cout << "R " << 2 << "\n";
    cout << "R " << 2 * n - 1 << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}


import java.io.File;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        boolean found = false;
        int ans = 0;
        for (int i = 0; Math.pow(n, i) <= m; ++i) {
            if (Math.pow(n, i) == m) {
                found = true;
                ans = i;
                break;
            }
        }
        if (!found)
            System.out.println("NO");
        else {
            System.out.println("YES");
            System.out.println(ans-1);
        }
    }

}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, L;
  while (scanf("%d", &K) == 1) {
    scanf("%d", &L);
    if (L < K)
      puts("NO");
    else if (L == K)
      printf("YES\n0\n");
    else {
      int ret = -1;
      long long hitung = K;
      for (int i = 1;; i++) {
        hitung *= K;
        if (hitung == L)
          ret = i;
        else if (hitung > L)
          break;
      }
      if (ret == -1)
        puts("NO");
      else {
        puts("YES");
        printf("%d\n", ret);
      }
    }
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
static const int mod = 1e9 + 7;
static const int mmx = 1e7 + 5;
bool chkbt(int n, int pos) { return (bool)(n & (1 << pos)); }
long long fun(long long n) {
  long long sum = 0;
  while (1) {
    long long r = n % 10;
    sum += r;
    n /= 10;
    if (n == 0) return sum;
  }
}
int main() {
  long long n, i;
  while (scanf("%lld", &n) == 1) {
    int l = log10(n) + 1;
    long long sum = 0;
    for (i = 0; i < l; i++) {
      sum = (sum * 10) + 9;
    }
    if (sum > n) sum /= 10;
    long long sum2 = n - sum;
    printf("%lld\n", fun(sum) + fun(sum2));
  }
  return 0;
}

def digitSum(x):
	s = 0
	while x != 0:
		s += x % 10
		x = (x//10)
	return s

n = int(input())
x = n
b = 1
s = 0
while x != 0:
	num1 = (x - 1)*b + (b-1)
	num2 = n - num1
	ans = digitSum(num1) + digitSum(num2)
	if ans > s:
		s = ans
	x = (x//10)
	b = b * 10
print(s)


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Map;
import java.util.Set;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;

public class MC {

	static BufferedReader br;
	static BufferedWriter bw;

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		bw = new BufferedWriter(new OutputStreamWriter(System.out));
		run();
		bw.close();
		br.close();
	}

	static void run() throws IOException {
		int[] args = gia();
		int[] c = gia();

		int n = args[0];
		int a = args[1];
		int b = -1;

		Map<Integer, Integer> map = new HashMap<>();
		Map<Integer, Boolean> valid = new HashMap<>();

		for (int i = 0; i < n; i++) {
			if (c[i] != a) {
				map.put(c[i], 0);
				valid.put(c[i], true);
			}
		}
		int freq = 0;

		for (int i = 0; i < n; i++) {
			int curr = c[i];
			if (curr == a) {
				freq++;
			} else if (valid.get(curr)){
				if (map.get(curr) >= freq) {
					map.put(curr, map.get(curr) + 1);
				} else {
					valid.put(curr, false);
				}
				//map.put(curr, map.ge(curr) + 1);
			}
		}

		for (Integer key : map.keySet()){
			if (valid.get(key) && map.get(key) >= freq) {
				b = key;
				break;
			}
		}

		bw.write(b+"");
	}

	static String[] gsa() throws IOException {
		return br.readLine().split(" ");
	}

	static double[] gda() throws IOException {
		String[] s = br.readLine().split(" ");
		double[] a = new double[s.length];
		for (int i = 0; i < s.length; i++) {
			a[i] = Double.parseDouble(s[i]);
		}
		return a;
	}

	static int[] gia() throws IOException {
		String[] s = br.readLine().split(" ");
		int[] a = new int[s.length];
		for (int i = 0; i < s.length; i++) {
			a[i] = Integer.parseInt(s[i]);
		}
		return a;
	}

	static long[] gla() throws IOException {
		String[] s = br.readLine().split(" ");
		long[] a = new long[s.length];
		for (int i = 0; i < s.length; i++) {
			a[i] = Long.parseLong(s[i]);
		}
		return a;
	}
}

#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int mod = 998244353;
int n, A;
int cnt[MX];
int main() {
  scanf("%d%d", &n, &A);
  set<pair<int, int> > w;
  for (int i = 1; i <= 1e6; i++) {
    w.insert(pair<int, int>(0, i));
  }
  for (int i = 1; i <= n; i++) {
    int c;
    scanf("%d", &c);
    auto iter = w.lower_bound(pair<int, int>(cnt[c], c));
    if (iter == w.end() || iter->second != c) continue;
    w.erase(iter);
    cnt[c]++;
    iter = w.insert(pair<int, int>(cnt[c], c)).first;
    if (c == A) {
      iter = w.upper_bound(pair<int, int>(cnt[c] - 1, INF));
      w.erase(w.begin(), iter);
    }
  }
  w.erase(pair<int, int>(cnt[A], A));
  auto iter = w.lower_bound(pair<int, int>(cnt[A], 0));
  if (iter == w.end())
    printf("-1\n");
  else
    printf("%d\n", iter->second);
  return 0;
}


import java.io.*;
import java.util.*;

public class Main{

	static int mod=(int)1e9+7;

	public static void main(String[] args) throws IOException {
		Writer out=new Writer(System.out);
		Reader in=new Reader(System.in);
//		int ts=in.nextInt();
		int ts=1;
		outer: while(ts-->0) {

			int n=in.nextInt();
			String [] s=new String[n];
			for(int i=0; i<n; i++) s[i]=in.next();
			int ans=Integer.MAX_VALUE;
			String s1=s[0];
			for(int i=0; i<=s1.length(); i++) {

				s1=s1.substring(1,s1.length())+s1.charAt(0);
//				out.println(s1);
				int cost=0;
				for(String temp: s) {
					int val=compare(s1,temp);
					if(val==-1) {
						out.println(val); continue outer;
					}
					else cost+=val;
				}
				ans=Math.min(cost, ans);
			}
			out.println(ans);

		}
		out.close();

	}

	static int compare(String s1, String s2) {
		if(s1.equals(s2)) return 0;
		for(int i=1; i<s2.length(); i++) {
			s2=s2.substring(1,s2.length())+s2.charAt(0);
			if(s1.equals(s2)) return i;
		}
		return -1;
	}

/*********************************** UTILITY CODE BELOW **************************************/

	static int abs(int a) {
		return a>0 ? a : -a;
	}

	static int max(int a, int b) {
		return a>b ? a : b;
	}

	static int min(int a, int b) {
		return a<b ? a : b;
	}
	static long pow(long n, long m) {
		if(m==0) return 1;
		long temp=pow(n,m/2);
		long res=((temp*temp)%mod);
		if(m%2==0) return res;
		return (res*n)%mod;
	}

	static class Pair{
		int u, v;

		Pair(int u, int v){this.u=u; this.v=v;}

		static void sort(Pair [] coll) {
			List<Pair> al=new ArrayList<>(Arrays.asList(coll));
			Collections.sort(al,new Comparator<Pair>() {
				public int compare(Pair p1, Pair p2) {
					return p1.u-p2.u;
				}
			});
			for(int i=0; i<al.size(); i++) {
				coll[i]=al.get(i);
			}
		}

	}

	static void sort(int[] a) {
		ArrayList<Integer> list=new ArrayList<>();
		for (int i:a) list.add(i);
		Collections.sort(list);
		for (int i=0; i<a.length; i++) a[i]=list.get(i);
	}

	static void sort(long a[]) {
		ArrayList<Long> list=new ArrayList<>();
		for(long i: a) list.add(i);
		Collections.sort(list);
		for(int i=0; i<a.length; i++) a[i]=list.get(i);
	}

	static int [] array(int n, int value) {
		int a[]=new int[n];
		for(int i=0; i<n; i++) a[i]=value;
		return a;
	}

	static class Reader{

		BufferedReader br;
		StringTokenizer to;

		Reader(InputStream stream){
			br=new BufferedReader(new InputStreamReader(stream));
			to=new StringTokenizer("");
		}

		String next() {
			while(!to.hasMoreTokens()) {
				try {
					to=new StringTokenizer(br.readLine());
				}catch(IOException e) {}

			}
			return to.nextToken();

		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0; i<n ;i++) a[i]=nextInt();
			return a;
		}
		long [] readLongArray(int n) {
			long a[]=new long[n];
			for(int i=0; i<n ;i++) a[i]=nextLong();
			return a;
		}

	}

	static class Writer extends PrintWriter{
		Writer(OutputStream stream){
			super(stream);
		}
		void println(int [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
		void println(long [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
	}

}

4
abcabcabc
bcabcabca
cabcabcab
cabcabcab

def fn(s1,s2):
    l1=list(s1)
    l2=list(s2)
    ans=0
    for i in range(len(l1)):
        if l1==l2:
            break
        l1=l1[1:]+[l1[0]]
        ans+=1
    if l1==l2:
        return ans
    else:
        print(-1)
        exit()
n1=int(input())
l=[]
if n1==1:
    print(0)
    exit()
for i in range(n1):
    l.append(str(input()))
l.sort()
m=(n1-1)//2
n=m+1
ans=[]
for i in range(n1):
    ans1=0
    for j in range(n1):
        ans1+=fn(l[j],l[i])
    ans.append(ans1)
print(min(ans))


#include <bits/stdc++.h>
using namespace std;
int n, num[101];
long long a;
int check(long long mid) {
  int mmin = mid, ret = num[0] - mid;
  for (int i = 1; i < 101; ++i) {
    ret = max(ret, 0);
    if (i & 1)
      ret += num[i];
    else {
      ret += (num[i] - mmin);
      mmin = min(mmin, num[i]);
    }
  }
  return !ret;
}
inline int id(long long x) {
  int ret = 0;
  while ((1LL << ret) < x) ++ret;
  if ((1LL << ret) == x) return ret << 1;
  return (ret << 1) - 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%I64d", &a);
    ++num[id(a)];
  }
  int left = 1, right = num[0], res = -1;
  while (left <= right) {
    int mid = (left + right) >> 1;
    if (check(mid)) {
      res = mid;
      right = mid - 1;
    } else
      left = mid + 1;
  }
  if (res == -1)
    puts("-1");
  else
    for (int i = res; i <= num[0]; ++i)
      printf("%d%c", i, i == num[0] ? '\n' : ' ');
  return 0;
}

from collections import Counter
from math import log2

powers = [2 ** p for p in range(64)]

def can():
    near = Counter()
    for num in set(nums):
        p = int(log2(num))
        near[p] += nums[num]
    seq_cp = seqs - Counter()
    for num in set(near):
        cnt = near[num]
        while cnt != 0 and num < 64:
            dif = min(cnt, seq_cp[powers[num]])
            cnt -= dif
            seq_cp[powers[num]] -= dif
            num += 1
        if cnt > 0:
            return False
    return True

n = int(input())

seq = list(map(int, input().split()))
cnt = Counter(seq)
nums = Counter(seq)

seqs = Counter()
cur_cnt = cnt[1]
cur_pow = 1
while cur_cnt != 0:
    nums[cur_pow] -= cur_cnt
    cur_pow *= 2
    if cur_cnt > cnt[cur_pow]:
        seqs[cur_pow // 2] = cur_cnt - cnt[cur_pow]
        cur_cnt = cnt[cur_pow]

for num in set(nums):
    addition = nums[num]
    nums[num] = 0
    nums[2 ** int(log2(num))] += addition

# remove elements with zero count
nums -= Counter()
seqs -= Counter()

cur_len = sum(seqs[num] for num in set(seqs))
res = []
cur_pow = 1

while can():
    res.append(cur_len)
    while seqs[cur_pow] == 0 and cur_pow <= 2 ** 63:
        cur_pow *= 2
    if cur_pow > 2 ** 63:
        break
    other_pow = 1
    while other_pow <= cur_pow:
        nums[other_pow] += 1
        other_pow *= 2
    seqs[cur_pow] -= 1
    cur_len -= 1

print(-1 if len(res) == 0 else ' '.join(map(str, reversed(res))))


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, f = 0;
  cin >> n >> m;
  char c;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c;
      if (c == 'C' || c == 'Y' || c == 'M') {
        f = 1;
      }
    }
  }
  if (f == 1)
    cout << "#Color" << endl;
  else
    cout << "#Black&White" << endl;
  return 0;
}

3 3 W W W W W W W W W B B B B B B B B B B B

#Black&White #Black&White #Black&White #Black&White #Black&White #Black&White #Black&White #Black&White #Black&White #Black&White #Color #Black&White #Black&White #Color #Black&White #Black&White #Color #Black&White #Color #Black&White #Black&White #Color #Black&White #Black&White #Color #Color #Color #Color #Black&White #Color #Black&White #Black&White #Black&White #Color #Black&White #Color #Color #Black&White #Black&White #Black&White #Black&White #Color #Color #Black&White #Black&White #Black&White #Black&White #Black&White #Color #Color

import java.util.*;
public class bob {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int r = in.nextInt();
        int c = in.nextInt();
        for(int i = 0; i < r; i++) {
            for(int k = 0; k < c; k++) {
                String inp = in.next();
                if(!inp.equals("W") && !inp.equals("B")&& !inp.equals("G")) {
                    System.out.println("#Color");
                    return;
                }
            }
        }
        System.out.println("#Black&White");
    }
}


import sys
lines = sys.stdin.readlines()
n = int(lines[0].strip())
arr = list(map(int, lines[1].strip().split(" ")))
arr.append(arr[-1])
res = []
maxChange = 0

left = 0
for i in range(1, n+1):
    if arr[i] == arr[i-1]:
        L = i - left
        res += [arr[left]]*(L//2) + [arr[i-1]]*(L-L//2)
        maxChange = max(maxChange, (L-1)//2)
        left = i

print(maxChange)
print(" ".join(map(str, res)))

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class prb327c {
	int n;
	short[] a;
	short[] a2;

	private void readInput() throws NumberFormatException, IOException {
		BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(bi.readLine());
		String ss = bi.readLine();
		a = new short[n];
		a2 = new short[n];
		for(int i=0; i<n; i++)
			a[i] = (short)(ss.charAt(2*i)-'0');
	}
	void solve(){
		int maxlen = 0;
		int len = 0;
		for(int i=0; i<n; i++)
			a2[i] = a[i];
		for(int i=1; i<n-1; i++){
			if (a[i]!=a[i-1] && a[i]!=a[i+1])
				len++;
			else{
				if (len>maxlen)
					maxlen = len;
				for(int j=0; j<len; j++)
					if (j<len/2)
						a2[i-len+j] = a2[i-len-1];
					else
						a2[i-len+j] = a2[i+1];
				len = 0;
			}
		}
		if (len>0){
			if (len>maxlen)
				maxlen = len;
			for(int j=0; j<len; j++)
				if (j<len/2)
					a2[n-1-len+j] = a2[n-1-len-1];
				else
					a2[n-1-len+j] = a2[n-1];
		}
		System.out.println((maxlen+1)/2);
		for(int i=0; i<n; i++)
			System.out.print(a2[i]+" ");
	}
	public static void main(String[] args) throws NumberFormatException, IOException {
		prb327c p = new prb327c();
		p.readInput();
		p.solve();
	}

}


a, b, s = map(int,input().split())
if (s - abs(a) - abs(b)) % 2 == 1 or s < abs(a) + abs(b):
    print('NO')
else:
    print('YES')

Yes Yes Yes Yes No No No Yes Yes Yes Yes No No No Yes No No Yes No No Yes Yes Yes No No Yes Yes No No Yes No Yes Yes Yes Yes No Yes Yes No No Yes No Yes No Yes No No No No No Yes Yes No Yes Yes No Yes Yes Yes No No No No Yes No No Yes Yes No Yes Yes No Yes No No Yes Yes No No Yes No Yes No No No No No Yes No No No No No No Yes Yes No Yes No No Yes No Yes Yes Yes No Yes Yes Yes No Yes No Yes No Yes Yes No Yes No No No Yes No No No Yes No Yes No No Yes Yes Yes No

import java.util.Scanner;

/**
 *
 * @author Mohammad Dehghan
 */
public class ACM {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x, y, s;
        x = scanner.nextInt();
        y = scanner.nextInt();
        s = scanner.nextInt();
        x = Math.abs(x);
        y = Math.abs(y);
        String str = "Yes";
        if ((x + y > s) || (((s - x - y) % 2) != 0)) {
            str = "No";
        }
        System.out.println(str);
    }

}


n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
d=[]
for i in range(1,p[0]+1):
    d+=[p[i]]
for i in range(1,q[0]+1):
    if(q[i] not in d):
        d+=[q[i]]
if(len(d)==n):
    print("I become the guy.")
else:
    print("Oh, my keyboard!")

I become the guy.
Oh, my keyboard!
Oh, my keyboard!
Oh, my keyboard!
I become the guy.
Oh, my keyboard!
I become the guy.
I become the guy.
Oh, my keyboard!
I become the guy.
I become the guy.
I become the guy.

import java.io.*;
import java.util.*;

public class A
{
   public static void main(String[] args)
   {
      Scanner scan = new Scanner(System.in);
      int n = scan.nextInt();
      boolean[] pass = new boolean[n+1];

      int p = scan.nextInt();
      for(int i = 0; i<p; i++)
      {
         int x = scan.nextInt();
         pass[x] = true;
      }

      p = scan.nextInt();
      for(int i = 0; i<p; i++)
      {
         int x = scan.nextInt();
         pass[x] = true;
      }

      boolean flag = true;

      for(int i = 1; i<=n; i++)
      {
         if(pass[i] == false)
            flag = false;
      }
      if(flag)
      {
         System.out.println("I become the guy.");
      }
      else
      {
         System.out.println("Oh, my keyboard!");
      }
   }
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int x = in.nextInt();
        if (x == 2) {
            out.println(-1);
        } else if (n == 1) {
            out.println(x - 1);
        } else {
            int tmp = n + 1;
            for (int i = 2; i * i <= tmp; ++i)
                if (tmp % i == 0) {
                    out.println(-1);
                    return;
                }
            tmp = n;
            int[] divs = new int[100];
            int ndivs = 0;
            for (int i = 2; i * i <= tmp; ++i)
                if (tmp % i == 0) {
                    divs[ndivs++] = i;
                    while (tmp % i == 0) tmp /= i;
                }
            if (tmp > 1) {
                divs[ndivs++] = tmp;
            }
            int gen = 2;
            while (true) {
                boolean ok = true;
                if (pow(gen, n, n + 1) != 1) ok = false;
                for (int i = 0; i < ndivs && ok; ++i) {
                    if (pow(gen, n / divs[i], n + 1) == 1) {
                        ok = false;
                    }
                }
                if (ok) break;
                ++gen;
            }
            long prod = 1;
            long res = -1;
            for (int pow = 0; pow < n; ++pow) {
                if (gcd(pow, n) == 1) {
                    if (prod < x) {
                        long got = prod + (x - 1 - prod) / (n + 1) * (n + 1);
                        if (got > res)
                            res = got;
                    }
                }
                prod = prod * gen % (n + 1);
            }
            out.println(res);
        }
    }

    private int gcd(int a, int b) {
        while (b > 0) {
            int t = a % b;
            a = b;
            b = t;
        }
        return a;
    }

    private long pow(long a, long k, long b) {
        if (k == 0) {
            return 1 % b;
        }
        if (k % 2 == 0) {
            return pow(a * a % b, k / 2, b);
        }
        return a * pow(a, k - 1, b) % b;
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    }

#include <bits/stdc++.h>
using namespace std;
long long pp;
int n, x, pr[110000];
long long mo(long long a) {
  if (a >= 0 && a < pp) return a;
  a %= pp;
  if (a < 0) a += pp;
  return a;
}
long long ksm(long long a, int b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = mo(ans * a);
    a = mo(a * a);
    b /= 2;
  }
  return ans;
}
void fenjie(int n) {
  for (int i = 2; i <= n; i++)
    if (n % i == 0) {
      pr[++pr[0]] = i;
      while (n % i == 0) n /= i;
    }
}
int main() {
  cin >> n >> x;
  for (int i = 2; i * i <= n + 1; i++)
    if ((n + 1) % i == 0) {
      printf("-1\n");
      return 0;
    }
  fenjie(n);
  pp = n + 1;
  for (int i = x - 1; i > 1; i--) {
    bool ok = 1;
    for (int j = 1; j <= pr[0]; j++)
      if (ksm(i, n / pr[j]) == 1) {
        ok = 0;
        break;
      }
    if (ok) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}


import sys
import math
c=int(input())

Ans=[]
F=[1]
for i in range(1,101):
    F.append(F[-1]*i)
for i in range(100):
    Ans.append([0]*100)

print(100)
cycles=1

Ans[0][1]=1
Ans[1][0]=1
Ans[1][2]=1
Ans[2][1]=1
Ans[0][2]=1
Ans[2][0]=1

m=3
while(cycles<c):
    Ans[0][m]=1
    Ans[m][0]=1
    inc=1
    for j in range(1,m):
        Ans[j][m]=1
        Ans[m][j]=1
        cycles+=inc
        inc+=1
        if(cycles+inc>c):
            break
    m+=1

A=""
for i in range(100):
    for j in range(100):
        A+=str(Ans[i][j])
    A+="\n"
sys.stdout.write(A)

#include <bits/stdc++.h>
using namespace std;
int graph[100][100];
int conn(int a) {
  if (a < 2) return 0;
  return (((a + 1) * (a) * (a - 1) / 6) - (a * (a - 1) * (a - 2) / 6));
}
int main() {
  int n;
  graph[1][0] = 1;
  graph[0][1] = 1;
  int size = 2;
  int step = 2;
  int k;
  cin >> n;
  while (n > 0) {
    for (k = 1; k < size + 1 && conn(k) <= n; k++) {
      graph[step][k - 1] = 1;
      graph[k - 1][step] = 1;
    }
    n -= conn(k - 1);
    step++;
    size = max(k, size);
  }
  cout << 100;
  for (int i = 0; i < 100; i++) {
    cout << endl;
    for (int j = 0; j < 100; j++) cout << graph[i][j];
  }
  return 0;
}


import java.io.*;
import java.lang.*;
import java.util.*;
public class ProgC {

		static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException  e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}
	int outgoing[];
	int incoming[];
	int diameter[];
	ArrayList<Integer>f;
	ArrayList<Integer>s;
	ArrayList<Integer>th;
	HashSet<Integer>visited = new HashSet<>();
	public static void main(String[] args) {
		ProgC cr = new ProgC();cr.run();
	}
	private void run() {
		FastReader fr = new FastReader();
		int n = fr.nextInt();
		int p = fr.nextInt();
		outgoing = new int[n+1];f = new ArrayList<>();
		s = new ArrayList<>();th = new ArrayList<>();
		incoming = new int[n+1];
		diameter = new int[n+1];
		for(int i=0;i<=n;i++)
			diameter[i] = Integer.MAX_VALUE;
		while(p-->0)
		{
			int a  =fr.nextInt();int b = fr.nextInt();int d = fr.nextInt();
			outgoing[a] = b;incoming[b] = a;diameter[a] =d;
		}
		int cnt = 0;
		for(int i=1;i<=n;i++)
		{
			if(!visited.contains(i) && incoming[i]==0 && outgoing[i]!=0)
			{
				visited.add(i);
				cnt++;
				f.add(i);
				dfs(outgoing[i],diameter[i]);
			}
		}

		System.out.println(cnt);
		for(int i=0;i<f.size();i++)
			System.out.println(f.get(i)+" "+s.get(i)+" "+th.get(i));
	}
	private void dfs(int i, int j) {

		visited.add(i);
		if(outgoing[i]==0)
		{
			s.add(i);
			th.add(j);
			return;
		}

		dfs(outgoing[i],Math.min(j, diameter[i]));

	}
}

import sys
input = sys.stdin.readline
for _ in range(1):
    n,m=[int(x) for x in input().split()]
    g,v=[[] for i in range(n)],[False for i in range(n)]
    s=[False for i in range(n)]
    for i in range(m):
        a,b,c=[int(x) for x in input().split()]
        s[b-1]=True
        g[a-1].append([b-1,c])
    ans=[]
    def helper(curr,start,dia):
        if len(g[curr])==0 and dia!=10000000000:
            ans.append([start+1,curr+1,dia])
            return
        for i in g[curr]:
            if v[i[0]]==False:
                v[i[0]]=True
                helper(i[0],start,min(dia,i[1]))
        return
    for i in range(n):
        if s[i]==False:
            v[i]=True
            helper(i,i,10000000000)
    print(len(ans))
    for i in ans:
        print(*i)


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author aryssoncf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        GChipGame solver = new GChipGame();
        solver.solve(1, in, out);
        out.close();
    }

    static class GChipGame {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt(), m = in.readInt();
            long[] V = in.readLongArray(n);
            long first = 0, second = 0;
            int[] arr = new int[n + 2];
            for (int ab = 2; ab <= 2 * m; ab++) {
                IntIntPair pair = solve(V, ab, arr, m);
                first += pair.first;
                second += pair.second;
            }
            long total = (long) m * m, rem = total - first - second;
            if (rem % 2 == 1) {
                throw new UnknownError();
            }
            long a = rem / 2, b = a;
            out.printLine(a, b, first, second);
        }

        IntIntPair solve(long[] V, int n, int[] arr, int ub) {
            int m = V.length;
            Arrays.setAll(arr, i -> (i < m ? (int) (V[i] % n) : (i % 2) * (n - 1)));
            int first = 0, second = 0;
            Arrays.sort(arr);
            boolean odd = false;
            for (int i = m; i >= 0; i--, odd = !odd) {
                int l = Math.max(arr[i] + 1, arr[odd ? m - 1 : m] / 2 + 1), r = Math.min(arr[i + 1], ub);
                int ll = Math.max(l, n - r), rr = Math.min(r, n - l), inc = Math.max(rr - ll + 1, 0);
                if (odd) {
                    first += inc;
                } else {
                    second += inc;
                }
            }
            return new IntIntPair(first, second);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public long[] readLongArray(int size) {
            long[] array = new long[size];
            for (int i = 0; i < size; i++) {
                array[i] = readLong();
            }
            return array;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            boolean isSpaceChar(int ch);

        }

    }

    static class IntIntPair implements Comparable<IntIntPair> {
        public final int first;
        public final int second;

        public IntIntPair(int first, int second) {
            this.first = first;
            this.second = second;
        }

        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }

            IntIntPair pair = (IntIntPair) o;

            return first == pair.first && second == pair.second;
        }

        public int hashCode() {
            int result = first;
            result = 31 * result + second;
            return result;
        }

        public String toString() {
            return "(" + first + "," + second + ")";
        }

        public int compareTo(IntIntPair o) {
            int value = Integer.compare(first, o.first);
            if (value != 0) {
                return value;
            }
            return Integer.compare(second, o.second);
        }

    }
}

#include <bits/stdc++.h>
using namespace std;
long long arr[100005], ans[2];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%lld", arr + i);
  }
  for (int sum = 1; sum <= m << 1; sum++) {
    vector<int> vec = {0};
    for (int i = 0; i < n; i++) {
      vec.push_back(arr[i] % sum);
    }
    vec.push_back(sum - 1);
    sort(vec.begin(), vec.end());
    for (int i = n + 1, t = 0; i; i--, t ^= 1) {
      int x = max(vec[i - 1], vec[n - t] / 2) + 1, y = min(vec[i], m);
      int a = max(x, sum - y), b = min(y, sum - x);
      if (a <= b) ans[t] += b - a + 1;
    }
  }
  long long x = ((long long)m * m - ans[0] - ans[1]) / 2;
  printf("%lld %lld %lld %lld\n", x, x, ans[1], ans[0]);
  return 0;
}


_ = input()
arr = list(map(int, input().split()))
best = None
for i in range(len(arr)):
    pos_at_zero = arr[i] % len(arr)
    if pos_at_zero > i:
        extra = len(arr) - pos_at_zero + i
    else:
        extra = i - pos_at_zero
    time_needed = arr[i] + extra
    #print(i, time_needed, extra, arr[i])
    if best is None or best[0] > time_needed:
        best = (time_needed, i)
print(best[1] + 1)

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 1; i <= n; i++) cin >> a[i];
  int ans;
  int m = INT_MAX;
  for (int i = 1; i <= n; i++) {
    int b;
    if (i > a[i])
      b = i;
    else {
      b = a[i] / n;
      b = b * n + i;
      if (b <= a[i]) b += n;
    }
    if (m > b) {
      m = b;
      ans = i;
    }
  }
  cout << ans << "\n";
  return 0;
}


//package baobab;

import java.io.*;
import java.util.*;

public class D {

    public static final boolean DEBUG_PRINTS = false;

    public static void main(String[] args) {
        Solver solver = new Solver();
    }

    static class Solver {
        IO io;

        public Solver() {
            this.io = new IO();
            try {
                solve();
            } finally {
                io.close();
            }
        }

        /****************************** START READING HERE ********************************/

        Graph mag(TreeSet<Integer> d, int deductions) {
            if (d.isEmpty()) {
                // base case 1: graph with a single node
                Graph g = new Graph();
                g.nextFreeNode++;
                return g;
            }
            if (d.size() == 1) {
                // base case 2: clique
                Graph g = new Graph();
                int last = d.last() - deductions + 1;
                g.nextFreeNode = last + 1;
                for (int i=1; i<=last; i++) {
                    for (int j=i+1; j<=last; j++) {
                        g.addBiEdge(i, j);
                    }
                }
                return g;
            }
            int dk = d.pollLast() - deductions;
            int d1 = d.pollFirst() - deductions;
            Graph g = mag(d, deductions+d1);

            // aN and vN new nodes
            int firstAnode = g.nextFreeNode;
            g.nextFreeNode += d1; // aN
            int lastAnode = g.nextFreeNode-1;
            g.nextFreeNode += (dk+1) - (lastAnode); // vN

            // make aN nodes connect to everything
            for (int i=firstAnode; i<=lastAnode; i++) {
                for (int j=1; j<g.nextFreeNode; j++) {
                    if (i==j) continue;
                    if (i>j && i>=firstAnode && i<=lastAnode && j>=firstAnode && j<=lastAnode) continue;
                    g.addBiEdge(i, j);
                }
            }
            return g;
        }

        void solve() {
            int n = io.nextInt();
            TreeSet<Integer> d = new TreeSet<>();
            for (int i=1; i<=n; i++) d.add(io.nextInt());
            Graph g = mag(d, 0);
            g.print();
        }

        void solve2() {
            int n = io.nextInt();
            PriorityQueue<IDval> q = new PriorityQueue<>(Collections.reverseOrder());
            for (int i=1; i<=n; i++) {
                q.add(new IDval(i, io.nextInt()));
            }
            int freeNodes = q.peek().val;

            List<String> ans = new ArrayList<>();
            Map<Integer, Integer> connsToFreeNodes = new HashMap<>();
            while (!q.isEmpty()) {
                IDval curr = q.poll();
                System.out.println("Polled " + curr.id + " , val " + curr.val);
                if (curr.val == 0) continue;

                List<IDval> putBack = new ArrayList<>();
                while (curr.val > 0) {
                    if (q.isEmpty()) {
                        connsToFreeNodes.put(curr.id, curr.val);
                        curr.val = 0;
                        break;
                    }
                    IDval next = q.poll();
                    if (next.val == 0) continue;
                    next.val--;
                    putBack.add(next);
                    curr.val--;
                    System.out.println("Connecting " + curr.id + " " + next.id);
                    ans.add(curr.id + " " + next.id);
                }
                putBack.add(curr);
                for (IDval next : putBack) q.add(next);
            }

            int sumOfCounts = 0;
            for (Map.Entry<Integer, Integer> n2f : connsToFreeNodes.entrySet()) {
                int real = n2f.getKey();
                int countFrees = n2f.getValue();
                sumOfCounts += countFrees;
            }

            // TODO freenode degrees must be in the set. How to divide sumOfCounts such that that happens?

            for (Map.Entry<Integer, Integer> n2f : connsToFreeNodes.entrySet()) {
                int real = n2f.getKey();
                int countFrees = n2f.getValue();
                if (countFrees > freeNodes) {
                    System.out.println("FAIL");
                }
                for (int i=n+1; i<=n+countFrees; i++) {
                    ans.add(real + " " + i);
                }

            }

            io.println(ans.size());
            for (String s : ans) io.println(s);
        }

        /************************** UTILITY CODE BELOW THIS LINE **************************/

        long MOD = (long)1e9 + 7;

        List<Integer>[] toGraph(IO io, int n) {
            List<Integer>[] g = new ArrayList[n+1];
            for (int i=1; i<=n; i++) g[i] = new ArrayList<>();
            for (int i=1; i<=n-1; i++) {
                int a = io.nextInt();
                int b = io.nextInt();
                g[a].add(b);
                g[b].add(a);
            }
            return g;
        }

        class Graph {
            HashMap<Integer, List<Integer>> edges;
            int nextFreeNode;
            int countEdges;

            public Graph() {
                edges = new HashMap<>();
                nextFreeNode = 1;
                countEdges = 0;
            }

            List<Integer> getSetNeighbors(Integer node) {
                List<Integer> neighbors = edges.get(node);
                if (neighbors == null) {
                    neighbors = new ArrayList<>();
                    edges.put(node, neighbors);
                }
                return neighbors;
            }

            void addBiEdge(Integer a, Integer b) {
                addEdge(a, b);
                addEdge(b, a);
            }

            void addEdge(Integer from, Integer to) {
                getSetNeighbors(to); // make sure all have initialized lists
                List<Integer> neighbors = getSetNeighbors(from);
                neighbors.add(to);
                countEdges++;
            }

            void print() {
                io.println(countEdges/2);
                for (int i=1; i<nextFreeNode; i++) {
                    for (Integer j : getSetNeighbors(i)) {
                        if (i<j) io.println(i + " " + j);
                    }
                }
            }

        }

        class IDval implements Comparable<IDval> {
            int id;
            int val;

            public IDval(int id, int val) {
                this.val = val;
                this.id = id;
            }

            @Override
            public int compareTo(IDval o) {
                if (this.val < o.val) return -1;
                if (this.val > o.val) return 1;
                return this.id - o.id;
            }
        }

        long pow(long base, int exp) {
            if (exp == 0) return 1L;
            long x = pow(base, exp/2);
            long ans = x * x;
            if (exp % 2 != 0) ans *= base;
            return ans;
        }

        long gcd(long... v) {
            /** Chained calls to Euclidean algorithm. */
            if (v.length == 1) return v[0];
            long ans = gcd(v[1], v[0]);
            for (int i=2; i<v.length; i++) {
                ans = gcd(ans, v[i]);
            }
            return ans;
        }

        long gcd(long a, long b) {
            /** Euclidean algorithm. */
            if (b == 0) return a;
            return gcd(b, a%b);
        }

        int[] generatePrimesUpTo(int last) {
            /* Sieve of Eratosthenes. Practically O(n). Values of 0 indicate primes. */
            int[] div = new int[last+1];
            for (int x=2; x<=last; x++) {
                if (div[x] > 0) continue;
                for (int u=2*x; u<=last; u+=x) {
                    div[u] = x;
                }
            }
            return div;
        }

        long lcm(long a, long b) {
            /** Least common multiple */
            return a * b / gcd(a,b);
        }

        private class ElementCounter {
            private HashMap<Long, Integer> elements;

            public ElementCounter() {
                elements = new HashMap<>();
            }

            public void add(long element) {
                int count = 1;
                Integer prev = elements.get(element);
                if (prev != null) count += prev;
                elements.put(element, count);
            }

            public void remove(long element) {
                int count = elements.remove(element);
                count--;
                if (count > 0) elements.put(element, count);
            }

            public int get(long element) {
                Integer val = elements.get(element);
                if (val == null) return 0;
                return val;
            }

            public int size() {
                return elements.size();
            }
        }

        class StringCounter {
            HashMap<String, Integer> elements;

            public StringCounter() {
                elements = new HashMap<>();
            }

            public void add(String identifier) {
                int count = 1;
                Integer prev = elements.get(identifier);
                if (prev != null) count += prev;
                elements.put(identifier, count);
            }

            public void remove(String identifier) {
                int count = elements.remove(identifier);
                count--;
                if (count > 0) elements.put(identifier, count);
            }

            public long get(String identifier) {
                Integer val = elements.get(identifier);
                if (val == null) return 0;
                return val;
            }

            public int size() {
                return elements.size();
            }
        }

        class DisjointSet {
            /** Union Find / Disjoint Set data structure. */
            int[] size;
            int[] parent;
            int componentCount;

            public DisjointSet(int n) {
                componentCount = n;
                size = new int[n];
                parent = new int[n];
                for (int i=0; i<n; i++) parent[i] = i;
                for (int i=0; i<n; i++) size[i] = 1;
            }

            public void join(int a, int b) {
                /* Find roots */
                int rootA = parent[a];
                int rootB = parent[b];
                while (rootA != parent[rootA]) rootA = parent[rootA];
                while (rootB != parent[rootB]) rootB = parent[rootB];

                if (rootA == rootB) {
                    /* Already in the same set */
                    return;
                }

                /* Merge smaller set into larger set. */
                if (size[rootA] > size[rootB]) {
                    size[rootA] += size[rootB];
                    parent[rootB] = rootA;
                } else {
                    size[rootB] += size[rootA];
                    parent[rootA] = rootB;
                }
                componentCount--;
            }

        }

        class LCAFinder {

            /* O(n log n) Initialize: new LCAFinder(graph)
             * O(log n) Queries: find(a,b) returns lowest common ancestor for nodes a and b */

            int[] nodes;
            int[] depths;
            int[] entries;
            int pointer;
            FenwickMin fenwick;

            public LCAFinder(List<Integer>[] graph) {
                this.nodes = new int[(int)10e6];
                this.depths = new int[(int)10e6];
                this.entries = new int[graph.length];
                this.pointer = 1;
                boolean[] visited = new boolean[graph.length+1];
                dfs(1, 0, graph, visited);
                fenwick = new FenwickMin(pointer-1);
                for (int i=1; i<pointer; i++) {
                    fenwick.set(i, depths[i] * 1000000L + i);
                }
            }

            private void dfs(int node, int depth, List<Integer>[] graph, boolean[] visited) {
                visited[node] = true;
                entries[node] = pointer;
                nodes[pointer] = node;
                depths[pointer] = depth;
                pointer++;
                for (int neighbor : graph[node]) {
                    if (visited[neighbor]) continue;
                    dfs(neighbor, depth+1, graph, visited);
                    nodes[pointer] = node;
                    depths[pointer] = depth;
                    pointer++;
                }
            }

            public int find(int a, int b) {
                int left = entries[a];
                int right = entries[b];
                if (left > right) {
                    int temp = left;
                    left = right;
                    right = temp;
                }
                long mixedBag = fenwick.getMin(left, right);
                int index = (int) (mixedBag % 1000000L);
                return nodes[index];
            }
        }

        class FenwickMin {
            long n;
            long[] original;
            long[] bottomUp;
            long[] topDown;

            public FenwickMin(int n) {
                this.n = n;
                original = new long[n+2];
                bottomUp = new long[n+2];
                topDown = new long[n+2];
            }

            public void set(int modifiedNode, long value) {
                long replaced = original[modifiedNode];
                original[modifiedNode] = value;
                // Update left tree
                int i = modifiedNode;
                long v = value;
                while (i <= n) {
                    if (v > bottomUp[i]) {
                        if (replaced == bottomUp[i]) {
                            v = Math.min(v, original[i]);
                            for (int r=1 ;; r++) {
                                int x = (i&-i)>>>r;
                                if (x == 0) break;
                                int child = i-x;
                                v = Math.min(v, bottomUp[child]);
                            }
                        } else break;
                    }
                    if (v == bottomUp[i]) break;
                    bottomUp[i] = v;
                    i += (i&-i);
                }
                // Update right tree
                i = modifiedNode;
                v = value;
                while (i > 0) {
                    if (v > topDown[i]) {
                        if (replaced == topDown[i]) {
                            v = Math.min(v, original[i]);
                            for (int r=1 ;; r++) {
                                int x = (i&-i)>>>r;
                                if (x == 0) break;
                                int child = i+x;
                                if (child > n+1) break;
                                v = Math.min(v, topDown[child]);
                            }
                        } else break;
                    }
                    if (v == topDown[i]) break;
                    topDown[i] = v;
                    i -= (i&-i);
                }
            }

            public long getMin(int a, int b) {
                long min = original[a];
                int prev = a;
                int curr = prev + (prev&-prev); // parent right hand side
                while (curr <= b) {
                    min = Math.min(min, topDown[prev]); // value from the other tree
                    prev = curr;
                    curr = prev + (prev&-prev);;
                }
                min = Math.min(min, original[prev]);
                prev = b;
                curr = prev - (prev&-prev); // parent left hand side
                while (curr >= a) {
                    min = Math.min(min,bottomUp[prev]); // value from the other tree
                    prev = curr;
                    curr = prev - (prev&-prev);
                }
                return min;
            }

        }

        class FenwickSum {
            public long[] d;

            public FenwickSum(int n) {
                d=new long[n+1];
            }

            /** a[0] must be unused. */
            public FenwickSum(long[] a) {
                d=new long[a.length];
                for (int i=1; i<a.length; i++) {
                    modify(i, a[i]);
                }
            }

            /** Do not modify i=0. */
            void modify(int i, long v) {
                while (i<d.length) {
                    d[i] += v;
                    // Move to next uplink on the RIGHT side of i
                    i += (i&-i);
                }
            }

            /** Returns sum from a to b, *BOTH* inclusive. */
            long getSum(int a, int b) {
                return getSum(b) - getSum(a-1);
            }

            private long getSum(int i) {
                long sum = 0;
                while (i>0) {
                    sum += d[i];
                    // Move to next uplink on the LEFT side of i
                    i -= (i&-i);
                }
                return sum;
            }
        }

        class SegmentTree {
            /** Query sums with log(n) modifyRange */
            int N;
            long[] p;

            public SegmentTree(int n) {
                /* TODO: Test that this works. */
                for (N=2; N<n; N++) N *= 2;
                p = new long[2*N];
            }

            public void modifyRange(int a, int b, long change) {
                muuta(a, change);
                muuta(b+1, -change);
            }

            void muuta(int k, long muutos) {
                k += N;
                p[k] += muutos;
                for (k /= 2; k >= 1; k /= 2) {
                    p[k] = p[2*k] + p[2*k+1];
                }
            }

            public long get(int k) {
                int a = N;
                int b = k+N;
                long s = 0;
                while (a <= b) {
                    if (a%2 == 1) s += p[a++];
                    if (b%2 == 0) s += p[b--];
                    a /= 2;
                    b /= 2;
                }
                return s;
            }

        }

        class Zalgo {

            public int pisinEsiintyma(String haku, String kohde) {
                char[] s = new char[haku.length() + 1 + kohde.length()];
                for (int i=0; i<haku.length(); i++) {
                    s[i] = haku.charAt(i);
                }
                int j = haku.length();
                s[j++] = '#';
                for (int i=0; i<kohde.length(); i++) {
                    s[j++] = kohde.charAt(i);
                }
                int[] z = toZarray(s);
                int max = 0;
                for (int i=haku.length(); i<z.length; i++) {
                    max = Math.max(max, z[i]);
                }
                return max;
            }

            public int[] toZarray(char[] s) {
                int n = s.length;
                int[] z = new int[n];
                int a = 0, b = 0;
                for (int i = 1; i < n; i++) {
                    if (i > b) {
                        for (int j = i; j < n && s[j - i] == s[j]; j++)  z[i]++;
                    }
                    else {
                        z[i] = z[i - a];
                        if (i + z[i - a] > b) {
                            for (int j = b + 1; j < n && s[j - i] == s[j]; j++) z[i]++;
                            a = i;
                            b = i + z[i] - 1;
                        }
                    }
                }
                return z;
            }

            public List<Integer> getStartIndexesWhereWordIsFound(String haku, String kohde) {
                // this is alternative use case
                char[] s = new char[haku.length() + 1 + kohde.length()];
                for (int i=0; i<haku.length(); i++) {
                    s[i] = haku.charAt(i);
                }
                int j = haku.length();
                s[j++] = '#';
                for (int i=0; i<kohde.length(); i++) {
                    s[j++] = kohde.charAt(i);
                }
                int[] z = toZarray(s);
                List<Integer> indexes = new ArrayList<>();
                for (int i=haku.length(); i<z.length; i++) {
                    if (z[i] < haku.length()) continue;
                    indexes.add(i);
                }
                return indexes;
            }

        }

        class StringHasher {

            class HashedString {
                long[] hashes;
                long[] modifiers;

                public HashedString(long[] hashes, long[] modifiers) {
                    this.hashes = hashes;
                    this.modifiers = modifiers;
                }
            }

            long P;
            long M;

            public StringHasher() {
                initializePandM();
            }

            HashedString hashString(String s) {
                int n = s.length();
                long[] hashes = new long[n];
                long[] modifiers = new long[n];
                hashes[0] = s.charAt(0);
                modifiers[0] = 1;
                for (int i=1; i<n; i++) {
                    hashes[i] = (hashes[i-1] * P + s.charAt(i)) % M;
                    modifiers[i] = (modifiers[i-1] * P) % M;
                }
                return new HashedString(hashes, modifiers);
            }

            /**
             * Indices are inclusive.
             */
            long getHash(HashedString hashedString, int startIndex, int endIndex) {
                long[] hashes = hashedString.hashes;
                long[] modifiers = hashedString.modifiers;
                long result = hashes[endIndex];
                if (startIndex > 0) result -= (hashes[startIndex-1] * modifiers[endIndex-startIndex+1]) % M;
                if (result < 0) result += M;
                return result;
            }

            // Less interesting methods below

            /**
             * Efficient for 2 input parameter strings in particular.
             */
            HashedString[] hashString(String first, String second) {
                HashedString[] array = new HashedString[2];
                int n = first.length();
                long[] modifiers = new long[n];
                modifiers[0] = 1;

                long[] firstHashes = new long[n];
                firstHashes[0] = first.charAt(0);
                array[0] = new HashedString(firstHashes, modifiers);

                long[] secondHashes = new long[n];
                secondHashes[0] = second.charAt(0);
                array[1] = new HashedString(secondHashes, modifiers);

                for (int i=1; i<n; i++) {
                    modifiers[i] = (modifiers[i-1] * P) % M;
                    firstHashes[i] = (firstHashes[i-1] * P + first.charAt(i)) % M;
                    secondHashes[i] = (secondHashes[i-1] * P + second.charAt(i)) % M;
                }
                return array;
            }

            /**
             * Efficient for 3+ strings
             * More efficient than multiple hashString calls IF strings are same length.
             */
            HashedString[] hashString(String... strings) {
                HashedString[] array = new HashedString[strings.length];
                int n = strings[0].length();
                long[] modifiers = new long[n];
                modifiers[0] = 1;
                for (int j=0; j<strings.length; j++) {
                    // if all strings are not same length, defer work to another method
                    if (strings[j].length() != n) {
                        for (int i=0; i<n; i++) {
                            array[i] = hashString(strings[i]);
                        }
                        return array;
                    }

                    // otherwise initialize stuff
                    long[] hashes = new long[n];
                    hashes[0] = strings[j].charAt(0);
                    array[j] = new HashedString(hashes, modifiers);
                }
                for (int i=1; i<n; i++) {
                    modifiers[i] = (modifiers[i-1] * P) % M;
                    for (int j=0; j<strings.length; j++) {
                        String s = strings[j];
                        long[] hashes = array[j].hashes;
                        hashes[i] = (hashes[i-1] * P + s.charAt(i)) % M;
                    }
                }
                return array;
            }

            void initializePandM() {
                ArrayList<Long> modOptions = new ArrayList<>(20);
                modOptions.add(353873237L);
                modOptions.add(353875897L);
                modOptions.add(353878703L);
                modOptions.add(353882671L);
                modOptions.add(353885303L);
                modOptions.add(353888377L);
                modOptions.add(353893457L);
                P = modOptions.get(new Random().nextInt(modOptions.size()));

                modOptions.clear();
                modOptions.add(452940277L);
                modOptions.add(452947687L);
                modOptions.add(464478431L);
                modOptions.add(468098221L);
                modOptions.add(470374601L);
                modOptions.add(472879717L);
                modOptions.add(472881973L);
                M = modOptions.get(new Random().nextInt(modOptions.size()));

            }
        }

        private static class Prob {

            /** For heavy calculations on probabilities, this class
             *  provides more accuracy & efficiency than doubles.
             *  Math explained: https://en.wikipedia.org/wiki/Log_probability
             *  Quick start:
             *      - Instantiate probabilities, eg. Prob a = new Prob(0.75)
             *      - add(), multiply() return new objects, can perform on nulls & NaNs.
             *      - get() returns probability as a readable double */

            /** Logarithmized probability. Note: 0% represented by logP NaN. */
            private double logP;

            /** Construct instance with real probability. */
            public Prob(double real) {
                if (real > 0) this.logP = Math.log(real);
                else this.logP = Double.NaN;
            }

            /** Construct instance with already logarithmized value. */
            static boolean dontLogAgain = true;
            public Prob(double logP, boolean anyBooleanHereToChooseThisConstructor) {
                this.logP = logP;
            }

            /** Returns real probability as a double. */
            public double get() {
                return Math.exp(logP);
            }

            @Override
            public String toString() {
                return ""+get();
            }

            /***************** STATIC METHODS BELOW ********************/

            /** Note: returns NaN only when a && b are both NaN/null. */
            public static Prob add(Prob a, Prob b) {
                if (nullOrNaN(a) && nullOrNaN(b)) return new Prob(Double.NaN, dontLogAgain);
                if (nullOrNaN(a)) return copy(b);
                if (nullOrNaN(b)) return copy(a);

                double x = Math.max(a.logP, b.logP);
                double y = Math.min(a.logP, b.logP);
                double sum = x + Math.log(1 + Math.exp(y - x));
                return new Prob(sum, dontLogAgain);
            }

            /** Note: multiplying by null or NaN produces NaN (repping 0% real prob). */
            public static Prob multiply(Prob a, Prob b) {
                if (nullOrNaN(a) || nullOrNaN(b)) return new Prob(Double.NaN, dontLogAgain);
                return new Prob(a.logP + b.logP, dontLogAgain);
            }

            /** Returns true if p is null or NaN. */
            private static boolean nullOrNaN(Prob p) {
                return (p == null || Double.isNaN(p.logP));
            }

            /** Returns a new instance with the same value as original. */
            private static Prob copy(Prob original) {
                return new Prob(original.logP, dontLogAgain);
            }
        }

        public class StronglyConnectedComponents {

            /** Kosaraju's algorithm */

            ArrayList<Integer>[] forw;
            ArrayList<Integer>[] bacw;

            /** Use: getCount(2, new int[] {1,2}, new int[] {2,1}) */
            public int getCount(int n, int[] mista, int[] minne) {
                forw = new ArrayList[n+1];
                bacw = new ArrayList[n+1];
                for (int i=1; i<=n; i++) {
                    forw[i] = new ArrayList<Integer>();
                    bacw[i] = new ArrayList<Integer>();
                }
                for (int i=0; i<mista.length; i++) {
                    int a = mista[i];
                    int b = minne[i];
                    forw[a].add(b);
                    bacw[b].add(a);
                }
                int count = 0;
                List<Integer> list = new ArrayList<Integer>();
                boolean[] visited = new boolean[n+1];
                for (int i=1; i<=n; i++) {
                    dfsForward(i, visited, list);
                }
                visited = new boolean[n+1];
                for (int i=n-1; i>=0; i--) {
                    int node = list.get(i);
                    if (visited[node]) continue;
                    count++;
                    dfsBackward(node, visited);
                }
                return count;
            }

            public void dfsForward(int i, boolean[] visited, List<Integer> list) {
                if (visited[i]) return;
                visited[i] = true;
                for (int neighbor : forw[i]) {
                    dfsForward(neighbor, visited, list);
                }
                list.add(i);
            }

            public void dfsBackward(int i, boolean[] visited) {
                if (visited[i]) return;
                visited[i] = true;
                for (int neighbor : bacw[i]) {
                    dfsBackward(neighbor, visited);
                }
            }
        }

        class DrawGrid {

            void draw(boolean[][] d) {
                System.out.print("  ");
                for (int x=0; x<d[0].length; x++) {
                    System.out.print(" " + x + " ");
                }
                System.out.println("");
                for (int y=0; y<d.length; y++) {
                    System.out.print(y + " ");
                    for (int x=0; x<d[0].length; x++) {
                        System.out.print((d[y][x] ? "[x]" : "[ ]"));
                    }
                    System.out.println("");
                }
            }

            void draw(int[][] d) {
                int max = 1;
                for (int y=0; y<d.length; y++) {
                    for (int x=0; x<d[0].length; x++) {
                        max = Math.max(max, ("" + d[y][x]).length());
                    }
                }
                System.out.print("  ");
                String format = "%" + (max+2) + "s";
                for (int x=0; x<d[0].length; x++) {
                    System.out.print(String.format(format, x) + " ");
                }
                format = "%" + (max) + "s";
                System.out.println("");
                for (int y=0; y<d.length; y++) {
                    System.out.print(y + " ");
                    for (int x=0; x<d[0].length; x++) {
                        System.out.print(" [" + String.format(format, (d[y][x])) + "]");
                    }
                    System.out.println("");
                }
            }

        }

        class BaseConverter {

            /* Palauttaa luvun esityksen kannassa base */
            public String convert(Long number, int base) {
                return Long.toString(number, base);
            }

            /* Palauttaa luvun esityksen kannassa baseTo, kun annetaan luku Stringinä kannassa baseFrom */
            public String convert(String number, int baseFrom, int baseTo) {
                return Long.toString(Long.parseLong(number, baseFrom), baseTo);
            }

            /* Tulkitsee kannassa base esitetyn luvun longiksi (kannassa 10) */
            public long longify(String number, int baseFrom) {
                return Long.parseLong(number, baseFrom);
            }
        }

        class Binary implements Comparable<Binary> {

            /**
             * Use example: Binary b = new Binary(Long.toBinaryString(53249834L));
             *
             * When manipulating small binary strings, instantiate new Binary(string)
             * When just reading large binary strings, instantiate new Binary(string,true)
             * get(int i) returns a character '1' or '0', not an int.
             */

            private boolean[] d;
            private int first; // Starting from left, the first (most remarkable) '1'
            public int length;

            public Binary(String binaryString) {
                this(binaryString, false);
            }
            public Binary(String binaryString, boolean initWithMinArraySize) {
                length = binaryString.length();
                int size = Math.max(2*length, 1);
                first = length/4;
                if (initWithMinArraySize) {
                    first = 0;
                    size = Math.max(length, 1);
                }
                d = new boolean[size];
                for (int i=0; i<length; i++) {
                    if (binaryString.charAt(i) == '1') d[i+first] = true;
                }
            }

            public void addFirst(char c) {
                if (first-1 < 0) doubleArraySize();
                first--;
                d[first] = (c == '1' ? true : false);
                length++;
            }

            public void addLast(char c) {
                if (first+length >= d.length) doubleArraySize();
                d[first+length] = (c == '1' ? true : false);
                length++;
            }

            private void doubleArraySize() {
                boolean[] bigArray = new boolean[(d.length+1) * 2];
                int newFirst = bigArray.length / 4;
                for (int i=0; i<length; i++) {
                    bigArray[i + newFirst] = d[i + first];
                }
                first = newFirst;
                d = bigArray;
            }

            public boolean flip(int i) {
                boolean value = (this.d[first+i] ? false : true);
                this.d[first+i] = value;
                return value;
            }

            public void set(int i, char c) {
                boolean value = (c == '1' ? true : false);
                this.d[first+i] = value;
            }

            public char get(int i) {
                return (this.d[first+i] ? '1' : '0');
            }

            @Override
            public int compareTo(Binary o) {
                if (this.length != o.length) return this.length - o.length;
                int len = this.length;
                for (int i=0; i<len; i++) {
                    int diff = this.get(i) - o.get(i);
                    if (diff != 0) return diff;
                }
                return 0;
            }

            @Override
            public String toString() {
                StringBuilder sb = new StringBuilder();
                for (int i=0; i<length; i++) {
                    sb.append(d[i+first] ? '1' : '0');
                }
                return sb.toString();
            }

        }

        class BinomialCoefficients {
            /** Total number of K sized unique combinations from pool of size N (unordered)
             N! / ( K! (N - K)! )   */

            /** For simple queries where output fits in long. */
            public long biCo(long n, long k) {
                long r = 1;
                if (k > n) return 0;
                for (long d = 1; d <= k; d++) {
                    r *= n--;
                    r /= d;
                }
                return r;
            }

            /** For multiple queries with same n, different k. */
            public long[] precalcBinomialCoefficientsK(int n, int maxK) {
                long v[] = new long[maxK+1];
                v[0] = 1; // nC0 == 1
                for (int i=1; i<=n; i++) {
                    for (int j=Math.min(i,maxK); j>0; j--) {
                        v[j] = v[j] + v[j-1]; // Pascal's triangle
                    }
                }
                return v;
            }

            /** When output needs % MOD. */
            public long[] precalcBinomialCoefficientsK(int n, int k, long M) {
                long v[] = new long[k+1];
                v[0] = 1; // nC0 == 1
                for (int i=1; i<=n; i++) {
                    for (int j=Math.min(i,k); j>0; j--) {
                        v[j] = v[j] + v[j-1]; // Pascal's triangle
                        v[j] %= M;
                    }
                }
                return v;
            }
        }

        class Trie {
            int N;
            int Z;
            int nextFreeId;
            int[][] pointers;
            boolean[] end;

            /** maxLenSum = maximum possible sum of length of words */
            public Trie(int maxLenSum, int alphabetSize) {
                this.N = maxLenSum;
                this.Z = alphabetSize;
                this.nextFreeId = 1;
                pointers = new int[N+1][alphabetSize];
                end = new boolean[N+1];
            }

            public void addWord(String word) {
                int curr = 0;
                for (int j=0; j<word.length(); j++) {
                    int c = word.charAt(j) - 'a';
                    int next = pointers[curr][c];
                    if (next == 0) {
                        next = nextFreeId++;
                        pointers[curr][c] = next;
                    }
                    curr = next;
                }
                end[curr] = true;
            }

            public boolean hasWord(String word) {
                int curr = 0;
                for (int j=0; j<word.length(); j++) {
                    int c = word.charAt(j) - 'a';
                    int next = pointers[curr][c];
                    if (next == 0) return false;
                    curr = next;
                }
                return end[curr];
            }

        }

        private class IO extends PrintWriter {
            private InputStreamReader r;
            private static final int BUFSIZE = 1 << 15;
            private char[] buf;
            private int bufc;
            private int bufi;
            private StringBuilder sb;

            public IO() {
                super(new BufferedOutputStream(System.out));
                r = new InputStreamReader(System.in);

                buf = new char[BUFSIZE];
                bufc = 0;
                bufi = 0;
                sb = new StringBuilder();
            }

            /** Print, flush, return nextInt. */
            private int queryInt(String s) {
                io.println(s);
                io.flush();
                return nextInt();
            }

            /** Print, flush, return nextLong. */
            private long queryLong(String s) {
                io.println(s);
                io.flush();
                return nextLong();
            }

            /** Print, flush, return next word. */
            private String queryNext(String s) {
                io.println(s);
                io.flush();
                return next();
            }

            private void fillBuf() throws IOException {
                bufi = 0;
                bufc = 0;
                while(bufc == 0) {
                    bufc = r.read(buf, 0, BUFSIZE);
                    if(bufc == -1) {
                        bufc = 0;
                        return;
                    }
                }
            }

            private boolean pumpBuf() throws IOException {
                if(bufi == bufc) {
                    fillBuf();
                }
                return bufc != 0;
            }

            private boolean isDelimiter(char c) {
                return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
            }

            private void eatDelimiters() throws IOException {
                while(true) {
                    if(bufi == bufc) {
                        fillBuf();
                        if(bufc == 0) throw new RuntimeException("IO: Out of input.");
                    }

                    if(!isDelimiter(buf[bufi])) break;
                    ++bufi;
                }
            }

            public String next() {
                try {
                    sb.setLength(0);

                    eatDelimiters();
                    int start = bufi;

                    while(true) {
                        if(bufi == bufc) {
                            sb.append(buf, start, bufi - start);
                            fillBuf();
                            start = 0;
                            if(bufc == 0) break;
                        }

                        if(isDelimiter(buf[bufi])) break;
                        ++bufi;
                    }

                    sb.append(buf, start, bufi - start);

                    return sb.toString();
                } catch(IOException e) {
                    throw new RuntimeException("IO.next: Caught IOException.");
                }
            }

            public int nextInt() {
                try {
                    int ret = 0;

                    eatDelimiters();

                    boolean positive = true;
                    if(buf[bufi] == '-') {
                        ++bufi;
                        if(!pumpBuf()) throw new RuntimeException("IO.nextInt: Invalid int.");
                        positive = false;
                    }

                    boolean first = true;
                    while(true) {
                        if(!pumpBuf()) break;
                        if(isDelimiter(buf[bufi])) {
                            if(first) throw new RuntimeException("IO.nextInt: Invalid int.");
                            break;
                        }
                        first = false;

                        if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                            if(ret < -214748364) throw new RuntimeException("IO.nextInt: Invalid int.");
                            ret *= 10;
                            ret -= (int)(buf[bufi] - '0');
                            if(ret > 0) throw new RuntimeException("IO.nextInt: Invalid int.");
                        } else {
                            throw new RuntimeException("IO.nextInt: Invalid int.");
                        }

                        ++bufi;
                    }

                    if(positive) {
                        if(ret == -2147483648) throw new RuntimeException("IO.nextInt: Invalid int.");
                        ret = -ret;
                    }

                    return ret;
                } catch(IOException e) {
                    throw new RuntimeException("IO.nextInt: Caught IOException.");
                }
            }

            public long nextLong() {
                try {
                    long ret = 0;

                    eatDelimiters();

                    boolean positive = true;
                    if(buf[bufi] == '-') {
                        ++bufi;
                        if(!pumpBuf()) throw new RuntimeException("IO.nextLong: Invalid long.");
                        positive = false;
                    }

                    boolean first = true;
                    while(true) {
                        if(!pumpBuf()) break;
                        if(isDelimiter(buf[bufi])) {
                            if(first) throw new RuntimeException("IO.nextLong: Invalid long.");
                            break;
                        }
                        first = false;

                        if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                            if(ret < -922337203685477580L) throw new RuntimeException("IO.nextLong: Invalid long.");
                            ret *= 10;
                            ret -= (long)(buf[bufi] - '0');
                            if(ret > 0) throw new RuntimeException("IO.nextLong: Invalid long.");
                        } else {
                            throw new RuntimeException("IO.nextLong: Invalid long.");
                        }

                        ++bufi;
                    }

                    if(positive) {
                        if(ret == -9223372036854775808L) throw new RuntimeException("IO.nextLong: Invalid long.");
                        ret = -ret;
                    }

                    return ret;
                } catch(IOException e) {
                    throw new RuntimeException("IO.nextLong: Caught IOException.");
                }
            }

            public double nextDouble() {
                return Double.parseDouble(next());
            }

        }

        void print(Object output) {
            io.println(output);
        }

        void done(Object output) {
            print(output);
            done();
        }

        void done() {
            io.close();
            throw new RuntimeException("Clean exit");
        }

        long min(long... v) {
            long ans = v[0];
            for (int i=1; i<v.length; i++) {
                ans = Math.min(ans, v[i]);
            }
            return ans;
        }

        double min(double... v) {
            double ans = v[0];
            for (int i=1; i<v.length; i++) {
                ans = Math.min(ans, v[i]);
            }
            return ans;
        }

        int min(int... v) {
            int ans = v[0];
            for (int i=1; i<v.length; i++) {
                ans = Math.min(ans, v[i]);
            }
            return ans;
        }

        long max(long... v) {
            long ans = v[0];
            for (int i=1; i<v.length; i++) {
                ans = Math.max(ans, v[i]);
            }
            return ans;
        }

        double max(double... v) {
            double ans = v[0];
            for (int i=1; i<v.length; i++) {
                ans = Math.max(ans, v[i]);
            }
            return ans;
        }

        int max(int... v) {
            int ans = v[0];
            for (int i=1; i<v.length; i++) {
                ans = Math.max(ans, v[i]);
            }
            return ans;
        }

        void debug(Object output) {
            if (DEBUG_PRINTS) {
                System.out.println(output);
            }
        }
    }

}

from sys import stdin
from sys import stdout

n = int(stdin.readline())
d = [0] + list(map(int, stdin.readline().split()))
e = []
for i in range(1, n+1):
	for u in range(d[i-1]+1, d[i]+1):
		for v in range(u+1, d[n-i+1]+2):
			e.append([u,v])
stdout.write("{}\n".format(len(e)))
for ei in e: stdout.write("{} {}\n".format(ei[0], ei[1]))