codeparrot/codecomplex huggingface dataset:
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.io.*;
import java.util.*;
public final class round_364_c
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	
	public static void main(String args[]) throws Exception
	{
		int n=sc.nextInt();char[] arr=sc.next().toCharArray();int[] sum=new int[123];int[][] pre=new int[123][n+1];
		char[] a=new char[n+1];
		for(int i=1;i<=n;i++)
		{
			a[i]=arr[i-1];
		}
		boolean[] v=new boolean[123];
		for(int i=1;i<=n;i++)
		{
			sum[a[i]]++;v[a[i]]=true;
			for(int j=65;j<=90;j++)
			{
				pre[j][i]=sum[j];
			}
			for(int j=97;j<=122;j++)
			{
				pre[j][i]=sum[j];
			}
		}
		long min=Integer.MAX_VALUE;
		for(int i=1;i<=n;i++)
		{
			int low=0,high=n-i+1;boolean got=false;
			while(low<high)
			{
				int mid=(low+high)>>1;
				boolean curr=true;
				for(int j=65;j<=90;j++)
				{
					if(v[j])
					{
						if(pre[j][i+mid]-pre[j][i-1]<=0)
						{
							curr=false;
							break;
						}
					}
				}
				for(int j=97;j<=122;j++)
				{
					if(v[j])
					{
						if(pre[j][i+mid]-pre[j][i-1]<=0)
						{
							curr=false;
							break;
						}
					}
				}
				if(curr)
				{
					got=true;
					high=mid;
				}
				else
				{
					low=mid+1;
				}
			}
			if(got)
			{
				min=Math.min(min,(i+low)-i+1);
			}
		}
		out.println(min);
		out.close();
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;



public class C364C {

	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;

	static int n;
	static int[] a;
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		n = nextInt();
		int ans = n, cc, cur = 0;
		a = new int [52];
		char[] c = next().toCharArray();
		int l = 0, len = 0;
		for (int i = 0; i < n; ++i) {
			if (Character.isUpperCase(c[i])) {
				cur = 26 + c[i] - 'A';
			} else
				cur = c[i] - 'a';
			if (a[cur] == 0) {
				a[cur]++;
				len++;
				ans = i - l + 1;
			} else {
				a[cur]++;
				for (; l < i; ++l) {
					if (Character.isUpperCase(c[l])) {
						cc = 26 + c[l] - 'A';
					} else
						cc = c[l] - 'a';
					
					if (a[cc] > 1) {
						--a[cc];
					} else break;
				}
				if (i - l + 1 < ans) {
					ans = i - l + 1;
				}
			}
		}
	
		/*int l = 0, r = n - 1;
		for (l = 0; l < n; ++l) {
			if (Character.isUpperCase(c[l])) {
				if (a[26 + c[l] - 'A'] > 1) {
					a[26 + c[l] - 'A']--;
				} else break;
			} else {
				if (a[c[l] - 'a'] > 1) {
					a[c[l] - 'a']--;
				} else break;
				
			}
		}
		for (r = n - 1; r >= 0; --r) {
			if (Character.isUpperCase(c[r])) {
				if (a[26 + c[r] - 'A'] > 1) {
					a[26 + c[r] - 'A']--;
				} else break;
			} else {
				if (a[c[r] - 'a'] > 1) {
					a[c[r] - 'a']--;
				} else break;
				
			}
		}*/
		pw.print(ans);
		pw.close();
	}
	
	private static int sumf(int[] fen, int id) {
		int summ = 0;
		for (; id >= 0; id = (id & (id + 1)) - 1) 
 			summ += fen[id];
		return summ;
	}

	private static void addf(int[] fen, int id) {
		for (; id < fen.length; id |= id + 1) 
			fen[id]++;
	}

	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	private static String next() throws IOException {
		while (st==null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear

import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner in=new Scanner(new BufferedInputStream(System.in));
	int n=in.nextInt();
	char b[]=in.next().toCharArray();
	int bb[]=new int [b.length];

	int Mark[]=new int [26*2+1];
	int Mark1[]=new int [26*2+1];

	int ans=0;
	for(int i=0;i<b.length;i++){
		char f=b[i];
		int a;
		if(f>='a'&&f<='z')
			a=f-'a';
		else  a=f-'A'+26;
		bb[i]=a;
		if(Mark1[a] == 0){
			ans++;
			Mark1[a]=1;}
	 
}
//	System.out.println(ans);
	int i;
    // int L ,R ,nowsum ,Ans;
   int  L = 0 ,nowsum = 0 ,Ans = n,R = 0;
     //找到LR
     for(i = 0 ;i < n ;i ++)
     {
         if(Mark[bb[i]]==0) nowsum ++;
           Mark[bb[i]] ++;
           if(nowsum == ans) 
           {
              R = i;
              break;
           }
        
     }
//     System.out.println("r"+R);
     Ans = R - L + 1; 
     for(i = L ;i < n ;i ++)
     {
       
        if((--Mark[bb[i]])==0)
        {
           int ok = 0;
           for(int j = R + 1 ;j < n ;j ++)
           {
              
          
                 Mark[bb[j]] ++;
                 if(bb[j] == bb[i])
                 {
                    ok = 1;
                    R = j;
                    break;
                 }
              
           }
           if(ok==0) break;
        }
        if(Ans > R - i) Ans = R - i;
     }
    	 System.out.println(Ans);
	 


	}

}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;


public class theyareeverywhere {

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

        //SWEEP LINE BABYY
        
        int n = Integer.parseInt(r.readLine());
        
        char[] pokemans = r.readLine().toCharArray();
        
        int[] counts = new int[52];
        boolean[] exists = new boolean[52];
        
        for (int i = 0; i < pokemans.length; i++) {
            exists[index(pokemans[i])] = true;
        }
        
        int left = 0, right = 0;
        counts[index(pokemans[0])] = 1;
        
        int answer = 1000000000;
        
        while (left < n && right < n) {
            if (!valid(counts, exists)) {
                //move right
                right++;
                if (right < n)
                counts[index(pokemans[right])]++;
            } else {
                answer = Math.min(answer, right - left + 1);
                left++;
                if (left - 1 >= 0)
                counts[index(pokemans[left - 1])]--;
            }
        }
        
        w.println(answer);
        w.flush();
    }
    
    public static boolean valid(int[] counts, boolean[] exists) {
        for (int i = 0; i < counts.length; i++) {
            if (exists[i] && counts[i] == 0) return false;
        }
        return true;
    }
    
    public static int index(char c) {
        if (c >= 'a' && c <= 'z') {
            return c - 'a';
        } else {
            return c - 'A' + 26;
        }
    }

}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;

public class main {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static PrintWriter pw = new PrintWriter(System.out);
    public static String line;
    public static StringTokenizer st;
    public static ArrayList<ArrayList<Integer>> adjList;
    public static int[] dr = {-1, 0, 1, 0, -1, 1, 1, -1};
    public static int[] dc = {0, 1, 0, -1, 1, 1, -1, -1};

    public static void main(String[] args) throws Exception{
        int N = Integer.parseInt(br.readLine());
        char[] A = br.readLine().toCharArray();

        HashSet<Character> cndD = new HashSet<Character>();
        for(int i = 0; i < N; i++){
            cndD.add(A[i]);
        }

        int cnt = cndD.size();

        int a = 0;
        int b = 0;

        int ans = (1 << 30);
        HashMap<Character, Integer> d = new HashMap<Character, Integer>();
        while(b < N){
            if(d.containsKey(A[b])){
                if(A[a] == A[b]){
                    a++;
                    while(d.get(A[a]) > 1){
                        d.put(A[a], d.get(A[a])-1);
                        a++;
                    }
                } else{
                    d.put(A[b], d.get(A[b])+1);
                }
            } else{
                d.put(A[b], 1);
            }
            if(d.size() == cnt){
                ans = Math.min(b-a+1, ans);
            }
            b++;
        }

        pw.print(ans + "\n");
        pw.close();
        br.close();
    }
}

class Pair implements Comparable<Pair>{
    public int a, b;

    Pair(int a, int b){
        this.a = a;
        this.b = b;
    }

    @Override
    public int compareTo(Pair P){
        if(P.b != this.b){
            return b - P.b;
        } else if(P.a == this.a){
            return a - P.a;
        } else{
            return 0;
        }
    }

    public String toString(){
        return a + " " + b;
    }
}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            char[] poks = in.next().toCharArray();
            boolean[] was = new boolean[52];
            for (int i = 0; i < n; i++) {
                if (Character.isLowerCase(poks[i])) {
                    was[poks[i] - 'a'] = true;
                } else {
                    was[poks[i] - 'A' + 26] = true;
                }
            }
            int count = 0;
            for (int i = 0; i < 52; i++) {
                count += was[i] ? 1 : 0;
            }
            int[] vis = new int[52];
            int pre = 0;
            int chr = 0;
            int ans = Integer.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                int pos = poks[i] - 'a';
                if (Character.isUpperCase(poks[i])) {
                    pos = poks[i] - 'A' + 26;
                }

                if (vis[pos] == 0) {
                    chr++;
                }
                vis[pos]++;
                while (chr == count) {
                    ans = Math.min(ans, i - pre + 1);
                    pos = poks[pre] - 'a';
                    if (Character.isUpperCase(poks[pre])) {
                        pos = poks[pre] - 'A' + 26;
                    }
                    vis[pos]--;
                    if (vis[pos] == 0) chr--;
                    pre++;
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
            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());
        }

    }
}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * Created by pallavi on 22/7/16.
 */
public class C701 {
    public static int f(char c) {
        if (c >= 'a' && c <= 'z') {
            return c - 'a';
        } else {
            return 26 + c - 'A';
        }
    }

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

        int n = Integer.parseInt(reader.readLine());
        char[] ch = reader.readLine().toCharArray();

        LinkedList<Integer>[] p = new LinkedList[52];

        for (int i = 0; i < 52; i++) {
            p[i] = new LinkedList<>();
        }

        int[] fc = new int[n];

        for (int i = 0; i < n; i++) {
            int cc = f(ch[i]);
            p[cc].add(i);
            fc[i] = cc;
        }
        int en = 0;
        for (int i = 0; i < 52; i++) {
            if (p[i].size() > 0) en = Math.max(en, p[i].poll());
        }

        int mx = en + 1;

        for (int i = 0; i < n; i++) {
            if (p[fc[i]].size() == 0) break;
            en = Math.max(en, p[fc[i]].poll());
            mx = Math.min(mx, en - i);
        }

        System.out.println(mx);
    }
}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;


public class C {

	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int n = nextInt();
		char[]a = next().toCharArray();
		int[]cnt = new int[256];
		for (int i = 0; i < n; i++) {
			cnt[a[i]]++;
		}
		int alldiff = 0;
		for (int i = 0; i < 256; i++) {
			if (cnt[i] > 0)
				alldiff++;
		}
		Arrays.fill(cnt, 0);
		int diff = 0, right = -1, ans = n+5;
		for (int i = 0; i < n; i++) {
			if (right < i) {
				cnt[a[i]]++;
				diff = 1;
				right = i;
			}
			while (right < n-1 && diff < alldiff) {
				right++;
				cnt[a[right]]++;
				if (cnt[a[right]]==1)
					diff++;
			}
			if (diff==alldiff && right-i+1 < ans) {
				ans = right-i+1;
			}
			cnt[a[i]]--;
			if (cnt[a[i]]==0)
				diff--;
		}
		System.out.println(ans);
		pw.close();
	}
	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	private static String next() throws IOException {
		while (st==null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class TheyAreEverywhere {
    static StringTokenizer st;
    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in), 325678);
    static int[] id = new int[100000];

    public static void main(String[] args) throws IOException {
        int n = in();
        String s = next();
        int total = 0;
        int[] seq = new int[n];
        boolean[] c = new boolean[100000];
        for (int i = 0; i < n; i++) {
            seq[i] = s.charAt(i);
            if (!c[seq[i]]) {
                total++;
                c[seq[i]] = true;
            }
        }

        Arrays.fill(id, -1);
        int best = Integer.MAX_VALUE;
        TreeSet<Integer> q = new TreeSet<Integer>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return id[o1] - id[o2];
            }
        });
        for (int i = 0; i < n; i++) {
            q.remove(seq[i]);
            id[seq[i]] = i;
            q.add(seq[i]);
            if (q.size() == total) {
                //System.out.println("best: i=" + i + " id=" + id[q.first()]);
                best = Math.min(best, i - id[q.first()] + 1);
            }
            //System.out.println("i="+i+" " +q.toString());
        }

        System.out.println(best);

    }

    public static int in() throws IOException {
        return Integer.parseInt(next());
    }

    public static long inl() throws IOException {
        return Long.parseLong(next());
    }

    public static String next() throws IOException {
        if (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(bf.readLine());
        return st.nextToken();
    }

}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.util.*;
import java.io.*;

public class C{
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Solver solver = new Solver();
		solver.solve(in, out);
		out.close();
	}

	static class Solver{
		public void solve(InputReader in, PrintWriter out) {
			int n = in.nextInt();
			String s = in.next();
			HashMap<Character, Integer> map = new HashMap<>();
			for (int i = 0; i < n; ++ i) {
				map.put(s.charAt(i), 0);
			}
			int l = 0, r = 0, cnt = 0, ans = n;
			char c;
			while (l < n) {
				while (r < n && cnt < map.size()) {
					c = s.charAt(r);
					map.put(c, map.get(c) + 1);
					if (map.get(c) == 1) ++cnt;
					++r;
				}
				
				if (cnt == map.size() && r-l < ans)
					ans = r-l;
				
				c = s.charAt(l);
				map.put(c, map.get(c)-1);
				if (map.get(c) == 0) --cnt;
				++l;
			}
			out.println(ans);
		}
	}

	static class InputReader {
		BufferedReader reader;
		StringTokenizer tokenizer;

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

		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());
		}
	}
}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.util.*;

public class Q3a {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		in.nextLine();
		String s = in.nextLine();

		HashMap<Integer, Integer> seen = new HashMap<>();

		for (int i = 0; i < n; i++) {
			Character c = s.charAt(i);
			int ci = (int) c.charValue();
			// System.out.println(ci);
			seen.put(ci, seen.get(ci) == null ? 1 : seen.get(ci) + 1);
		}

		HashMap<Integer, Integer> sub = new HashMap<Integer, Integer>();
		int start = 0;
		int min = 10000000;
		for (int i = 0; i < n; i++) {
			Character c = s.charAt(i);
			int ci = (int) c.charValue();

			sub.put(ci, sub.get(ci) == null ? 1 : sub.get(ci) + 1);
			
			while(sub.size() == seen.size()) {
				min = Math.min(min, i - start + 1);
				c = s.charAt(start);
				start ++;
				ci = (int) c.charValue();
				if( sub.get(ci) == 1) 
					sub.remove(ci);
				else
					sub.put(ci, sub.get(ci) - 1);
			}
		}

		System.out.print(min);

		// System.out.println( seen_all_at - begin + 1);

		in.close();
	}
}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class C {
	public static void main(String[] args) throws IOException {
		File inputFile = new File("entradaC");
		if (inputFile.exists())
			System.setIn(new FileInputStream(inputFile));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		String line = "";
		while ((line = in.readLine()) != null) {
			int n = Integer.parseInt(line);
			char[] p = in.readLine().toCharArray();
			HashMap<Character, Integer> dif = new HashMap<>();
			for (int i = 0; i < p.length; i++)
				dif.put(p[i], 0);
			int ndif = dif.size();
			int head = 0, tail = 0, cnt = 0, ans = Integer.MAX_VALUE, cur;
			while (head < n) {
				cur = dif.get(p[head]);
				if (cur == 0)
					cnt++;
				dif.put(p[head], cur + 1);
				head++;
				if (cnt == ndif)
					ans = Math.min(ans, head - tail);
				while (tail < head && cnt == ndif) {
					cur = dif.get(p[tail]);
					if (cur == 1)
						cnt--;
					dif.put(p[tail], cur - 1);
					tail++;
					if (cnt == ndif)
						ans = Math.min(ans, head - tail);
				}
			}
			if (ndif == 1)
				ans = 1;
			out.append(ans + "\n");

		}
		System.out.print(out);
	}

	static int[] readInts(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		int a[] = new int[st.countTokens()], index = 0;
		while (st.hasMoreTokens())
			a[index++] = Integer.parseInt(st.nextToken());
		return a;
	}

	static long[] readLongs(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		long a[] = new long[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Long.parseLong(st.nextToken());
		return a;
	}

	static double[] readDoubles(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		double a[] = new double[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Double.parseDouble(st.nextToken());
		return a;
	}
}