codeparrot/codecomplex huggingface dataset:
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Round364C {
	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = 0;
		
		String line = sc.nextLine();
		
		ArrayList<Character> poks = new ArrayList<Character>();
		boolean ex[] = new boolean[256];
		
		for(int i=0; i<n; i++)
		{
			if(!ex[line.charAt(i)])
			{
				ex[line.charAt(i)] = true;
				poks.add(line.charAt(i));
			}
		}
		
		
		int l = 0;
		int r = 0;
		int dist = 1;
		int occ[] = new int[256];
		occ[line.charAt(0)] = 1;
		
		int min = n;
		while(r < n)
		{
			if(dist == poks.size())
				min = Math.min(min, r - l + 1);
			if(l < r && dist == poks.size())
			{
				
				occ[line.charAt(l)]--;
				if(occ[line.charAt(l)] == 0)
					dist--;
				l++;
				continue;
			}
			if(r < n-1){
				occ[line.charAt(r+1)]++;
				if(occ[line.charAt(r+1)] == 1)
					dist++;
			}
			r++;
		}
		System.out.println(min);
		
	}
	
	static int n,k;
	static int dp[][][];
	
	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner(FileReader f) {
			br = new BufferedReader(f);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

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

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}
}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.util.*;

public class C{
	static String s;
	static long val[];
	static int N,size;
	static int index(char c){
		if(c <= 'Z'){
			return c - 'A';
		}else{
			return c - 'a' + ('Z' - 'A' + 1);
		}
	}

	static int l(int i){
		return (i<<1)+1;
	}
	static int r(int i){
		return (i<<1)+2;
	}

	static void setup(int l, int r, int i){
		if(l==r){
			val[i] = (1L<<index(s.charAt(l)));
		}else{
			int mid = (l+r)/2;
			setup(l,mid,l(i));
			setup(mid+1,r,r(i));
			val[i] = val[l(i)] | val[r(i)];
		}
	}

	static long query(int min, int max, int l, int r, int i){
		if(min <= l && r <= max){
			return val[i];
		}
		if(max < l || r < min)
			return 0;
		int mid = (l+r)/2;
		return query(min,max,l,mid,l(i)) | query(min,max,mid+1,r,r(i));
	}
	static long query(int min, int max){
		return query(min,max,0,N-1,0);
	}

	static int binarySearch(int start, long toFind){
		int max = N-1;
		int min = start;
		if(query(start,max) != toFind)
			return 1<<29;
		if(query(start,start) == toFind){
			return 1;
		}
		int ret = max - min + 1;
		while(min + 1 < max){
			int mid = (min+max)/2;
			if(query(start,mid) == toFind){
				max = mid;
			}else{
				min = mid;
			}
		}
		return max-start+1;
	}

	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		s = sc.next();
		int size = 1;
		while(size <= N) size*=2;
		val = new long[size*2];
		setup(0,N-1,0);

		long toFind = query(0,N-1,0,N-1,0);
		long ans = 1L<<29;
		for(int i = 0; i < N; i++)
			ans = Math.min(ans,binarySearch(i,toFind));
		System.out.println(ans);
	}
}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.HashSet;


public class C {

	private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	private static PrintStream out = System.out;

	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt(in.readLine());
		char[] s = in.readLine().toCharArray();
		HashSet<Character> all = new HashSet<Character>();
		for (char c : s)
			all.add(c);
		int totalCount = all.size();
		HashMap<Character, Integer> cnts = new HashMap<Character, Integer>();
		int ans = Integer.MAX_VALUE;
		int x = 0;
		for (int y = 0; y < n; ++y) {
			if (!cnts.containsKey(s[y]))
				cnts.put(s[y], 0);
			cnts.put(s[y], cnts.get(s[y]) + 1);
			if (cnts.size() < totalCount)
				continue;
			while (cnts.get(s[x]) > 1) {
				cnts.put(s[x], cnts.get(s[x]) - 1);
				++x;
			}
			ans = Math.min(ans, y - x + 1);
		}
		out.println(ans);
	}

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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		String in1 = in.readLine();
		String store = "";
		HashSet<Character> contain = new HashSet<Character>();
		for(int i = 0; i < n;i++){
			if(!contain.contains(in1.charAt(i))){
				store += in1.charAt(i);
				contain.add(in1.charAt(i));
			}
		}
		int[] index = new int[store.length()];
		for(int i = 0; i < store.length(); i++){
			index [i] = -1;
		}
		HashSet<Integer> index2 = new HashSet<Integer>();
		ArrayList<Integer> index3 = new ArrayList<Integer>();
		int min = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++){
			int index4 = store.indexOf(in1.charAt(i));
			if(index[index4] == -1){
				index[index4] = i;
				index2.add(i);
				index3.add(i);
			}
			else{
				index2.remove(index[index4]);
				index2.add(i);
				index3.add(i);
				index[index4] = i;
			}
			if(index2.size() == index.length){
				while(!index2.contains(index3.get(0))){
					index3.remove(0);
				}
				min = Math.min(min, i - index3.get(0)+ 1);
			}
			
		}
		System.out.println(min);
	}

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

public class Main {

	BufferedReader in;
	StringTokenizer str = null;
	PrintWriter out;
	
	private String next() throws Exception{
		while (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return str.nextToken();
	}
	
	private int nextInt() throws Exception{
		return Integer.parseInt(next());
	}
	
	private long nextLong() throws Exception{
		return Long.parseLong(next());
	}
	
	private double nextDouble() throws Exception{
		return Double.parseDouble(next());
	}

	final int oo = Integer.MAX_VALUE;
	
	int [][]s;
	int n, ALL;
	public void run() throws Exception{
		in =  new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		n = nextInt();
		char []a = next().toCharArray();
		s = new int[n][52];
		boolean []set = new boolean[52];

		for(int i = 0; i < n; ++i) {
			int pos = get(a[i]);
			if (!set[pos]) {
				++ALL;
				set[pos] = true;
			}
			for(int j = 0; j < 52; ++j) {
				if (i > 0) {
					s[i][j] += s[i-1][j];	
				}
				if (j == pos) {
					s[i][j]++;
				}
			}
		}

		int ret = oo;
		for(int i = 0; i < n; ++i) {
			ret = Math.min(ret, get(i));
		}

		out.println(ret);
		out.close();
	}

	private int get(int i) {
		int lo = i - 1, hi = n;
		while(hi - lo > 1) {
			int m = lo + (hi - lo) / 2;
			int c = 0;
			for(int j = 0; j < 52; ++j) {
				if (sum(j, i, m) > 0) {
					++c;
				}
			}
			if (c < ALL) {
				lo = m;
			} else {
				hi = m;
			}
		}

		if (hi != n) {
			return hi - i + 1;
		}
		return oo;
	}

	private int sum(int pos, int l, int r) {
		int ret = s[r][pos];
		if (l > 0) ret -= s[l - 1][pos];
		return ret;
	}

	private int get(char x) {
		if ('a' <= x && x <= 'z') return (int)(x - 'a');
		return (int)(x - 'A' + 26);
	}

	public static void main(String[] args) throws Exception{
		new Main().run();
	}
}
// 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.Set;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
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();
            String word = in.next();

            int cnt[] = new int[1000];

            int let = 0;
            Set<Character> set = new TreeSet<>();
            for (int i = 0; i < word.length(); i++) {
                set.add(word.charAt(i));
            }
            int uniq = set.size();
            int i = 0, j = -1;
            int ans = Integer.MAX_VALUE;
            while (i < N && j < N) {
                while (j + 1 < N && let < uniq) {
                    j++;
                    if (cnt[word.charAt(j)] == 0) {
                        let++;
                    }
                    cnt[word.charAt(j)]++;
                }
                if (let == uniq)
                    ans = Math.min(ans, j - i + 1);
                cnt[word.charAt(i)]--;
                if (cnt[word.charAt(i)] == 0) let--;
                i++;
            }
            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;
        }

        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.*;
import java.io.*;

public class C {
    public static void main(String[] args) throws IOException {
	BufferedReader in =
	    new BufferedReader(new InputStreamReader(System.in));
	int n = Integer.parseInt(in.readLine());
	char[] ps = in.readLine().toCharArray();
	HashMap<Character, TreeSet<Integer>> locs =
	    new HashMap<Character, TreeSet<Integer>>();
	HashSet<Character> poks = new HashSet<Character>();
	int lastNew = n;
	for (int i = 0; i < n; i++) {
	    if (!poks.contains(ps[i])) {
		poks.add(ps[i]);
		locs.put(ps[i], new TreeSet<Integer>());
		lastNew = i;
	    }
	    locs.get(ps[i]).add(i);
	}
	int max = lastNew;
	int minRange = max+1;
	for (int min = 0; min < n; min++) {
	    char pAtMin = ps[min];
	    Integer nextInd = locs.get(pAtMin).higher(min);
	    if (nextInd == null) break;
	    max = Math.max(max, nextInd);
	    minRange = Math.min(minRange, max-min);
	}
	System.out.println(minRange);
    }
}
// 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.HashSet;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author xwchen
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(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, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            String s = in.next();

            int[] cnt = new int[26];
            int[] cnt2 = new int[26];
            int j = 0;
            int res = n;
            HashSet<Character> set = new HashSet<Character>();
            for (char c : s.toCharArray()) {
                set.add(c);
            }
            int m = set.size();

            for (int i = 0; i < n; ++i) {
                if (Character.isLowerCase(s.charAt(i))) {
                    cnt[s.charAt(i) - 'a']++;
                } else {
                    cnt2[s.charAt(i) - 'A']++;
                }
                while (isOK(cnt, cnt2, m)) {
                    res = Math.min(res, i - j + 1);
                    if (Character.isLowerCase(s.charAt(j))) {
                        cnt[s.charAt(j) - 'a']--;
                    } else {
                        cnt2[s.charAt(j) - 'A']--;
                    }
                    ++j;
                }
            }
            out.println(res);
        }

        boolean isOK(int[] cnt, int[] cnt2, int m) {
            int c = 0;
            for (int i = 0; i < 26; ++i) {
                if (cnt[i] > 0) {
                    ++c;
                }
            }
            for (int i = 0; i < 26; ++i) {
                if (cnt2[i] > 0) {
                    ++c;
                }
            }
            return c >= m;
        }

    }
}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.HashSet;
public class C {
	public static void main(String args[]) {
		Kattio sc = new Kattio(System.in);
		int n = sc.getInt();
		String s = sc.getWord();
		int[] found = new int['z' + 1];
		int amount = 0;
		for(int i = 0; i<s.length(); i++) {
			char c = s.charAt(i);
			if(found[c] == 0) amount++;
			found[c]++;
		}
		int contains[] = new int['z' + 1];
		int min = n;
		int start = 0;
		int end = 0;
		int in = 0;
		while(true) {
			if(in<amount) {
				if(end == n) break;
				char c = s.charAt(end);
				if(contains[c] == 0) in++;
				contains[c]++;
				end++;
			} else {
				if(min>end-start) min = end-start;
				char c = s.charAt(start);
				if(contains[c] == 1) in--;
				contains[c]--;
				start++;
			}
		}
		System.out.println(min);


	}
}
class Kattio extends PrintWriter {
    public Kattio(InputStream i) {
	super(new BufferedOutputStream(System.out));
	r = new BufferedReader(new InputStreamReader(i));
    }
    public Kattio(InputStream i, OutputStream o) {
	super(new BufferedOutputStream(o));
	r = new BufferedReader(new InputStreamReader(i));
    }

    public boolean hasMoreTokens() {
	return peekToken() != null;
    }

    public int getInt() {
	return Integer.parseInt(nextToken());
    }

    public double getDouble() { 
	return Double.parseDouble(nextToken());
    }

    public long getLong() {
	return Long.parseLong(nextToken());
    }

    public String getWord() {
	return nextToken();
    }



    private BufferedReader r;
    private String line;
    private StringTokenizer st;
    private String token;

    private String peekToken() {
	if (token == null) 
	    try {
		while (st == null || !st.hasMoreTokens()) {
		    line = r.readLine();
		    if (line == null) return null;
		    st = new StringTokenizer(line);
		}
		token = st.nextToken();
	    } catch (IOException e) { }
	return token;
    }

    private String nextToken() {
	String ans = peekToken();
	token = null;
	return ans;
    }
}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * @author grozhd
 */
public class P3 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        String s = "";
        while (s.length() == 0) {
            s = sc.nextLine();
        }
        char[] pokemons = s.toCharArray();

        Set<Character> pokemonTypes = new HashSet<>();
        for (int i = 0; i < n; i++) {
            pokemonTypes.add(pokemons[i]);
        }

        int types = pokemonTypes.size();

        int l = 0;
        int r = 0;
        int min = n;
        Map<Character, Integer> currentPokemons = new HashMap<>();


        while (r < n) {
            while (currentPokemons.size() < types && r < n) {
                char pokemon = pokemons[r++];
                currentPokemons.merge(pokemon, 1, (a, b) -> a + b);
            }
            min = Math.min(r - l, min);

            while (currentPokemons.size() == types) {
                char pokemon = pokemons[l++];
                if (currentPokemons.get(pokemon) == 1) {
                    currentPokemons.remove(pokemon);
                } else {
                    min = Math.min(r - l, min);
                    currentPokemons.put(pokemon, currentPokemons.get(pokemon) - 1);
                }
            }
        }

        min = Math.min(min, r - l + 1);
        min = Math.max(min, types);

        System.out.println(min);

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

public class Main {


    void change(int [] all, char c, int val) {
        if (Character.isUpperCase(c))
            all[c - 'A' + 26] += val;
        else
            all[c - 'a'] += val;
    }

    int countDistinct(int [] a) {
        int res = 0;
        for (int i = 0 ; i< a.length ; i++) {
            if (a[i] > 0)
                res ++;
        }
        return res;
    }
    public void solve() throws IOException {
        int n = nextInt();
        String s = next();

        int [] all = new int[52];
        for (int i = 0 ; i < s.length() ; i++) {
            char c = s.charAt(i);
            change(all, c, 1);
        }
        int distinct = countDistinct(all);

        int [] window = new int[52];
        int best = n;
        for (int i = 0, j = 0 ; i < s.length() ; i++) {

            if (i > 0) {
                change(window, s.charAt(i-1), -1);
            }
            while (j < s.length()) {
                if (countDistinct(window) == distinct)
                    break;

                change(window, s.charAt(j), 1);
                j ++;
            }
            if (countDistinct(window) < distinct)
                break;

            best = Math.min(best, j - i);
        }
        out.println(best);
    }

    

    
    
    BufferedReader bf;
    StringTokenizer st;
    PrintWriter out;
    
    public String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) 
            st = new StringTokenizer(bf.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public Main() throws IOException {
        bf = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new OutputStreamWriter(System.out));		
        solve();
        bf.close();
        out.close();
    }
    
    public static void main(String args[]) throws IOException {
        new Main();
    }
}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.util.*;


public class Main {
	private static Scanner in = new Scanner(System.in);
	public static void main(String args[]){
		int n = in.nextInt();
		String s = in.next();
		if(n==1)
			System.out.println("1");
		else{
			int j=0,i=1,ans=s.length();
			int h[]=new int[128];
			h[(int)s.charAt(0)]=1;
			while(i<n){
				if(h[(int)s.charAt(i)]==0)
					ans = i-j+1;
				h[(int) s.charAt(i)]++;
				while(j<i && h[(int)s.charAt(j)]>1){
					h[(int)s.charAt(j)]--;
					j++;
					ans = Math.min(ans, i-j+1);
				}
				i++;
			}
			System.out.println(ans);
		}
	}
}
// Problem: 701_C. They Are Everywhere
// Time complexity: linear
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class CTask {


    public static void main(String[] args) throws IOException {
        MyInputReader in = new MyInputReader(System.in);
        HashMap<Character, Integer> m = new HashMap<Character, Integer>();
        int n = in.nextInt();
        char[] s = in.next().toCharArray();

        for (int i = 0; i < n; i++) {
            m.put(s[i], 0);
        }
        int mx = m.size();
        int start = 0;
        int end = 0;
        int min = Integer.MAX_VALUE;
        int cur = 0;
        while (end < n) {
            while (end < n && cur != mx) {
                int x = m.get(s[end]);
                if (x == 0) {
                    cur += 1;
                }
                m.put(s[end], x + 1);
                end += 1;
            }
            while (start <= end && cur == mx) {
                int x = m.get(s[start]);
                m.put(s[start], x - 1);
                if (x - 1 == 0) {
                    cur -= 1;
                }
                start += 1;
            }
            min = Math.min(min, end - start + 1);
        }
        System.out.println(min);
    }


    static class Pair {

        long x;
        long y;

        public Pair(long x, long y) {
            this.x = x;
            this.y = y;
        }

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

            Pair pair = (Pair) o;

            if (x != pair.x) return false;
            return y == pair.y;

        }

        @Override
        public int hashCode() {
            int result = (int) (x ^ (x >>> 32));
            result = 31 * result + (int) (y ^ (y >>> 32));
            return result;
        }
    }

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

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

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

    }

}