codeparrot/codecomplex huggingface dataset:
// Problem: 46_C. Hamsters and Tigers
// Time complexity: linear
import java.util.*;
import java.io.*;

public class Solution {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(new InputStreamReader(System.in));
        int n = sc.nextInt();
        String s = sc.next();
        sc.close();
        
        int cH = 0;
        for (int i=0; i < s.length(); i++)
            if (s.charAt(i) == 'H')
                cH++;
        
        int best = cH;
        
        for (int st=0; st < s.length(); st++) {
            int cur = st;
            int cnt = cH;
            for (int i=0; i < cH; i++) {
                if (s.charAt(cur) == 'H')
                    cnt--;
                cur++;
                if (cur == s.length()) cur = 0;
            }
            best = Math.min(best, cnt);
        }
        
        System.out.println(best);
    }
}
// Problem: 46_C. Hamsters and Tigers
// Time complexity: linear
import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int len = s.nextInt();
        s.nextLine();
        String l = s.nextLine();
        char[] ca = l.toCharArray();
        int h = 0;
        for (char c : ca)
            h += A(c);
        int cur = h;
        int i;
        for (i = 0; i < h; i++)
            cur -= A(ca[i]);
        int best = cur;
        while (i != h + len) {
            cur -= A(ca[i % len]);
            cur += A(ca[(i - h) % len]);
            best = best > cur ? cur : best;
            i++;
        }
        System.out.println(best);
    }

    public static int A(char x) {
        return x == 'H' ? 1 : 0;
    }
}
// Problem: 46_C. Hamsters and Tigers
// Time complexity: linear
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Homyak implements Runnable {
    private void solve() throws IOException {
        int n = nextInt();
        String seq = nextToken();
        int nh = 0;
        int nt = 0;
        for (int i = 0; i < n; ++i)
            if (seq.charAt(i) == 'H')
                ++nh;
            else
                ++nt;
        int res = n;
        for (int delta = 0; delta < n; ++delta) {
            int changed = 0;
            int at = delta;
            for (int i = 0; i < nh; ++i) {
                if (seq.charAt(at) != 'H')
                    ++changed;
                ++at;
                if (at >= n)
                    at = 0;
            }
            for (int i = 0; i < nt; ++i) {
                if (seq.charAt(at) != 'T')
                    ++changed;
                ++at;
                if (at >= n)
                    at = 0;
            }
            res = Math.min(res, changed / 2);
        }
        writer.println(res);
    }

    public static void main(String[] args) {
        new Homyak().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

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

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

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

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}
// Problem: 46_C. Hamsters and Tigers
// Time complexity: linear
import java.io.*;
import java.util.*;

public class C
{
	String line;
	StringTokenizer inputParser;
	BufferedReader is;
	FileInputStream fstream;
	DataInputStream in;
	
	void openInput(String file)
	{

		if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
		else
		{
			try{
		
				
			fstream = new FileInputStream(file);
			in = new DataInputStream(fstream);
			is = new BufferedReader(new InputStreamReader(in));
			}catch(Exception e)
			{
				System.err.println(e);
			}
		}

	}
	
	void readNextLine()
	{
		try {
			line = is.readLine();
			inputParser = new StringTokenizer(line, " ");
			//System.err.println("Input: " + line);
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}	
		
	}
	
	int NextInt()
	{
		String n = inputParser.nextToken();
		int val = Integer.parseInt(n);
		
		//System.out.println("I read this number: " + val);
		return val;
	}
	
	String NextString()
	{
		String n = inputParser.nextToken();
		return n;
	}
	
	void closeInput()
	{
		try {
			is.close();
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}
			
	}
	
	
	public static void main(String [] argv)
	{
		String filePath=null;
		if(argv.length>0)filePath=argv[0];
		C c = new C(filePath);
	}
	
	public C(String inputFile)
	{
        openInput(inputFile);
        
		readNextLine();
		int N=NextInt();
		boolean [] p = new boolean[N];
		readNextLine();
		int h=0;
		for(int i=0; i<N; i++)
		{
			p[i]=line.charAt(i)=='H';
			if(p[i])h++;
		}
		
		
		int ret=N;
		
		for(int i=0; i<N; i++)
		{
			int m=0;
			for(int j=i; j<i+h; j++)
			{
				int n=j%N;
				if(!p[n])m++;
			}
			ret=Math.min(ret, m);
		}
		
		System.out.println(ret);
		closeInput();
	}

	
	
}
// Problem: 46_C. Hamsters and Tigers
// Time complexity: linear
import java.io.*;
import java.util.*;

public class Main implements Runnable {

	public void _main() throws IOException {
		int n = nextInt();
		int[] a = new int[n];
		String s = next();
		for (int i = 0; i < n; i++)
			a[i] = s.charAt(i) == 'H' ? 1 : 0;
		int res = 10 * n;
		for (int i = 0; i < n; i++) {
			int[] b = new int[n];
			for (int j = 0; j < n; j++)
				b[j] = a[(i + j) % n];
			res = Math.min(res, solve(b, 0));
			res = Math.min(res, solve(b, 1));
		}
		out.print(res);
	}

	private int solve(int[] a, int x) {
		int n = a.length;		
		int j;
		for (j = n - 1; j >= 0; j--)
			if (a[j] == x)
				break;
		if (a[j] != x) return 0;
		int res = 0;
		for (int i = 0; i < j; i++)
			if (a[i] != x) {
				--j;
				while (j >= i && a[j] != x)
					--j;
				++res;
			}
		return res;
	}

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

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

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

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

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

	public static void main(String[] args) {
		Locale.setDefault(Locale.UK);
		new Thread(new Main()).start();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			_main();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(202);
		}
	}

}
// Problem: 46_C. Hamsters and Tigers
// Time complexity: linear
import java.io.*;
import java.math.*;
import java.util.*;

public class Solution {
	static PrintWriter out = new PrintWriter(System.out);
	
	public static void main(String[] args) throws Exception{
		StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		in.nextToken();
		int n = (int)in.nval;
		in.nextToken();
		String st = in.sval;
		char[] a = new char[n];
		for (int i = 0; i<n; i++)
			a[i] = st.charAt(i);
		int kH = 0;
		int kT = 0;
		for (int i =0; i<n; i++)
			if (a[i] == 'T') kT++;
			else kH++;
		int kol = 0;
		int min = Integer.MAX_VALUE;
		int poz;
		
		for (int i=0; i<n; i++)
		{
			kol = 0;
			if (a[i] == 'T') {
				for (int j = 0; j<kT; j++){
					poz = (i+j)%n;
					if (a[poz] == 'H') kol++;
				}
				if (kol < min) min = kol;
			}
			else {
				for (int j = 0; j<kH; j++){
					poz = (i+j)%n;
					if (a[poz] == 'T') kol++;
				}
				if (kol < min) min = kol;
			}
		}
		out.print(min);
		out.flush();
	}
}
// Problem: 46_C. Hamsters and Tigers
// Time complexity: linear
import java.io.*;
import java.util.*;

public class C {

    MyScanner in;
    PrintWriter out;

    public static void main(String[] args) throws Exception {
        new C().run();
    }

    public void run() throws Exception {
        in = new MyScanner();
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    public void solve() throws Exception {
        int n = in.nextInt();
        char[] a = in.next().toCharArray();
        int h = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] == 'H') h++;
        }
        char[] b = new char[2 * a.length - 1];
        for (int i = 0; i < b.length; i++) {
            b[i] = a[i % a.length];
        }
        int maxh = 0;
        int hh = 0;
        for (int i = 0; i < b.length - h; i++) {
            hh = 0;
            for (int j = 0; j < h; j++) {
                if (b[i + j] == 'H') hh++;
            }
            maxh = Math.max(maxh, hh);
        }
        /*for (int i = 0; i < b.length; i++) {
            out.print(b[i]);
        }
        out.println();*/
        //out.println(h + " " + maxh);
        out.println(h - maxh);
    }
    class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() throws Exception {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

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

        boolean nextBoolean() throws Exception {
            return Boolean.parseBoolean(next());
        }

        long nextLong() throws Exception {
            return Long.parseLong(next());
        }
    }
}
// Problem: 46_C. Hamsters and Tigers
// Time complexity: linear
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

public class Main { 
    public static StreamTokenizer in;
    public static PrintStream out;
    public static BufferedReader br;

    public static String readString() throws IOException {
        in.nextToken();
        return  in.sval;
        }

    public static double readDouble() throws IOException {
        in.nextToken();
        return in.nval;
        }

    public static int readInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }
    
    public static String readLine() throws IOException {
    return br.readLine();
    }
    
    public static int genans(String ss) {
    	
    	int n = ss.length();
    	char[] s = ss.toCharArray();
    	int res = 0;
    	while (true) {
    		int firstT = -1;
    		for (int i=0; i<n; i++)
    			if (s[i]=='T') { firstT = i; break; }
    		
    		int lastH = -1;
    		for (int i=n-1; i>=0; i--)
    			if (s[i]=='H') { lastH=i; break; }
    		
    		if (firstT<lastH) {
    			res++;
    			s[firstT] = 'H';
    			s[lastH] = 'T';
    		} else break;
    		
    	}	
    	return res;
    }
    
    public static void main(String[] args) throws IOException {

        in = new StreamTokenizer(new InputStreamReader (System.in) );
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintStream(System.out);

        readLine();
        String s = readLine();
        int n = s.length();
        String kk = s;
        int ans = n*100;
        for (int tr=0; tr<n+2; tr++) {
        	String kk2 = "";
        	for (int i=1; i<n; i++) kk2 = kk2 +kk.charAt(i);
        	kk2 = kk2 + kk.charAt(0);
        	kk = kk2;
        
        int cur = genans(kk);
        //out.println(kk+" "+cur);
        if (cur<ans) ans = cur;
        }
        
        out.println(ans);

    }
    

}
// Problem: 46_C. Hamsters and Tigers
// Time complexity: linear
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;
import java.math.*;

public class Main {        

    void run() throws IOException {
        int n = nint();
        char[] s = token().toCharArray();
        int h = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == 'H') h++;
        }
        int r = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int t = 0;
            for (int j = i; j < i + h; j++) {
                if (s[j % n] == 'T') t++;
            }
            r = min(r, t);
        }
        out.println(r);
    }

    class pair implements Comparable <pair> {
        int x, y;
        pair(int x, int y) {
            this.x = x;
            this.y = y;            
        }
        public int compareTo (pair p) {
            if (x != p.x) {
                return x - p.x;
            } else {
                return y - p.y;
            }
        }
    }

//    static PrintWriter out;
  //  static Scanner in;

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        //final String FILENAME = "jury"; in = new Scanner (new File (FILENAME + ".in")); out = new PrintWriter (new File(FILENAME + ".out"));
    //    in = new Scanner (System.in); out = new PrintWriter (System.out);
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        st = new StringTokenizer(" ");
        new Main().run();
        /*out = new PrintWriter (System.out);
        final int NUMBER_OF_TESTS = 35;
        for (int i = 1; i <= NUMBER_OF_TESTS; i++) {
            Scanner test = new Scanner (new File ("tests/" + i + ".in"));
            Scanner right = new Scanner (new File ("tests/" + i + ".out"));
            String get_right = right.nextLine();
            String get_test = new Main().run(test);
            if (get_right.equals(get_test)) {
                out.println("Test #" + i + ": " + "OK!");                
            } else {
                out.println("Test #" + i + ": " + "ERROR!");
                out.println("Expected: " + get_right);
                out.println("Received: " + get_test);
                break;
            }
        }*/
        out.close();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer st;

    String token() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int nint() throws IOException {
        return Integer.parseInt(token());
    }

    long nlong() throws IOException {
        return Long.parseLong(token());
    }

    double ndouble() throws IOException {
        return Double.parseDouble(token());
    }
}
// Problem: 46_C. Hamsters and Tigers
// Time complexity: linear
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;


public class C43 {

    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    
    static int nextInt() throws IOException {
        in.nextToken();
        return Integer.valueOf(in.sval);
    }
    
    static double nextDouble() throws IOException {
        in.nextToken();
        return Double.valueOf(in.sval);
    }
    
    static String nextString() throws IOException {
        in.nextToken();
        return in.sval;
    }
    
    static {
        in.ordinaryChars('0', '9');
        in.wordChars('0', '9');
        
        in.ordinaryChars('.', '.');
        in.wordChars('.', '.');
        
        in.ordinaryChars('-', '-');
        in.wordChars('-', '-');
    }

    public static void main(String[] args) throws IOException {
        int n = nextInt();
        char[] s = nextString().toCharArray();
        int h = 0;
        for (int i = 0; i < n; i++)
            if (s[i] == 'H')
                h++;
        
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int p = i, t = 0;
            for (int j = 0; j < h; j++, p = (p+1)%n)
                if (s[p] == 'T')
                    t++;
            ans = Math.min(ans, t);
        }
        
        out.println(ans);
        out.flush();
    }

}
// Problem: 46_C. Hamsters and Tigers
// Time complexity: linear
import java.util.*;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner cin = new Scanner(System.in);
		int n;
		n = cin.nextInt();
		String s = cin.next();
		int ans = n;
		int cntH = 0,cntT = 0;
		for(int i=0;i<n;i++)
		{
			if(s.charAt(i)=='H')cntH++;
		}
		cntT = n - cntH;
		for(int i=0;i+cntH<n;i++)
		{
			int tmp = 0;
			for(int j=i;j<i+cntH;j++)
				if(s.charAt(j)=='T')tmp++;
			if(ans>tmp)ans = tmp;
		}
		for(int i=0;i+cntT<n;i++)
		{
			int tmp = 0;
			for(int j=i;j<i+cntT;j++)
				if(s.charAt(j)=='H')tmp++;
			if(ans>tmp)ans = tmp;
		}
		System.out.println(ans);
	}

}
// Problem: 46_C. Hamsters and Tigers
// Time complexity: linear
import java.io.*;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class C implements Runnable {

    private static final boolean USE_FILE_IO = false;
    private static final String FILE_IN = "c.in";
    private static final String FILE_OUT = "c.out";

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tokenizer = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(new C()).start();
    }

    int n, h, t;
    char[] c;

    private void solve() throws IOException {
        n = nextInt();
        c = nextToken().toCharArray();
        if (c.length != n) {
            throw new IllegalStateException();
        }

        for (char l : c)
            if (l == 'H') {
                h++;
            }
        t = n - h;

        if (h == 0) {
            out.print(0);
            return;
        }

        int answer = Integer.MAX_VALUE;
        for (int hLo = 0; hLo < n; hLo++)
            if (c[hLo] == 'H') {
                int hHi = (hLo + h) % n;

                int current = 0;
                int j = hLo;
                while (j != hHi) {
                    if (c[j] == 'T') {
                        current++;
                    }
                    j = (j + 1) % n;
                }

                answer = Math.min(answer, current);
            }

        out.print(answer);
    }

    public void run() {
        long timeStart = System.currentTimeMillis();
        try {

            if (USE_FILE_IO) {
                in = new BufferedReader(new FileReader(FILE_IN));
                out = new PrintWriter(new FileWriter(FILE_OUT));
            } else {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }

            solve();

            in.close();
            out.close();
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        long timeEnd = System.currentTimeMillis();
        System.out.println("Time spent: " + (timeEnd - timeStart) + " ms");
    }

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

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

    private BigInteger nextBigInt() throws IOException {
        return new BigInteger(nextToken());
    }

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

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

}
// Problem: 46_C. Hamsters and Tigers
// Time complexity: linear
import java.io.*;
import java.util.*;

public class Main {
	private static boolean _READ_FROM_FILE = System.getProperty("ONLINE_JUDGE") == null;
	private static Scanner in;
	private static void core() {
		int n = in.nextInt();
		ArrayList<Character> all = new ArrayList<Character>();
		for (char ch : in.next().toCharArray()) {
			all.add(ch);
		}
		
		int res = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			int now = calc(all);
			res = Math.min(res, now);
			all.add(all.get(0));
			all.remove(0);
		}
		System.out.println(res);
	}
	private static int calc(ArrayList<Character> all) {
		int nh = 0;
		for (char ch: all) {
			if (ch == 'H')
				++nh;
		}
		int r1 = 0;
		for (int i = 0; i < nh; i++) {
			if (all.get(i) != 'H')
				++r1;
		}
		
		int nt = all.size() - nh;
		int r2 = 0;
		for (int i = 0; i < nt; i++) {
			if (all.get(i) != 'T')
				++r2;
		}
		return Math.min(r1, r2);
	}
	static void debug(Object...os) {
		System.out.println(Arrays.deepToString(os));
	}
	public static void main(String[] args) throws FileNotFoundException {
		if (_READ_FROM_FILE)
			System.setIn(new FileInputStream("in.in"));
		in = new Scanner(System.in);
		core();
	}
}
// Problem: 46_C. Hamsters and Tigers
// Time complexity: linear
import java.io.*;
import java.util.*;

public class Solution {

    StreamTokenizer in;
    PrintWriter out;

    public static void main(String[] args) throws Exception {
        new Solution().run();
    }

    public void run() throws Exception {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter (new OutputStreamWriter(System.out));
        solve();
        out.flush();
    }

    int nextInt() throws Exception {
        in.nextToken();
        return (int) in.nval;
    }

    String next() throws Exception {
        in.nextToken();
        return in.sval;
    }

    public void solve() throws Exception {
        int n=nextInt();
        String s=next();
        String ss = s + s;
        int t = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == 'T') {
                t++;
            }
        }
        if (t == 1 || t == n - 1) {
            out.println(0);
        } else {
            int sum = 0;
            for (int i = 0; i < t; i++) {
                if (s.charAt(i) == 'T') {
                    sum++;
                }
            }
            
            int max = sum;
            for (int i = 0; i < s.length(); i++) {
                if (ss.charAt(i) == 'T') {
                    if (ss.charAt(i + t) == 'H') {
                        sum--;
                    }
                } else {
                    if (ss.charAt(i + t) == 'T') {
                        sum++;
                        max = Math.max(max, sum);
                    }
                }
            }
           out.println(t - max);
        }
    }

}