akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main() {
	string S, T;
	cin >> S >> T;
	int ans = 0;
	for (int i = 0; i < S.size(); i++) if (S[i] != T[i]) ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3920
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int h[10] = { 6,2,5,5,4,5,6,3,7,6 };
bool b[10] = { false };
int dp[10100][10];
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a;
		cin >> a;
		b[a] = true;
	}
	for (int i = 0; i < n + 10; i++) {
		for (int j = 0; j < 10; j++) {
			dp[i][j] = -1;
		}
	}
	for (int i = 0; i < 10; i++) {
		dp[0][i] = 0;
	}
	for (int i = 0; i <= n; i++) {
		if (dp[i][0] == -1) {
			continue;
		}
		for (int j = 1; j < 10; j++) {
			if (!b[j]) {
				continue;
			}
			if (dp[i + h[j]][0] == -1) {
				for (int k = 0; k < 10; k++) {
					dp[i + h[j]][k] = dp[i][k];
					if (j == k) {
						dp[i + h[j]][k]++;
					}
				}
			}
			else {
				int kari[10];
				int sl = 0, sr = 0;
				for (int k = 0; k < 10; k++) {
					kari[k] = dp[i][k];
					if (j == k) {
						kari[k]++;
					}
					sl += dp[i + h[j]][k];
					sr += kari[k];
				}
				bool bo = true;
				if (sl != sr) {
					if (sl > sr) {
						bo = false;
					}
				}
				else {
					int l = 9, r = 9;
					while (1) {
						if (l == 0 && r == 0) {
							bo = false;
							break;
						}
						if (dp[i + h[j]][l] == 0) {
							l--;
							continue;
						}
						if (kari[r] == 0) {
							r--;
							continue;
						}
						if (l == r && dp[i + h[j]][l] == kari[r]) {
							l--;
							r--;
							continue;
						}
						else if (l < r) {
							break;
						}
						else if (l > r) {
							bo = false;
							break;
						}
						else if (dp[i + h[j]][l] < kari[r]) {
							break;
						}
						else if (dp[i + h[j]][l] > kari[r]) {
							bo = false;
							break;
						}
					}
				}
				if (bo) {
					for (int k = 0; k < 10; k++) {
						dp[i + h[j]][k] = kari[k];
					}
				}
			}
		}
	}
	for (int i = 9; i > 0; i--) {
		for (int j = 0; j < dp[n][i]; j++) {
			cout << i;
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3968
import java.util.*;

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

		int n = stdIn.nextInt();
		int[] S = new int[n];
		for (int i=0; i<n; i++) {
			S[i] = stdIn.nextInt();
		}

		int q = stdIn.nextInt();
		int[] T = new int[q];
		for (int i=0; i<q; i++) {
			T[i] = stdIn.nextInt();
		}
		
		Arrays.sort(S);
		Arrays.sort(T);

		int count = 0;
		for (int i=0; i<q; i++) {
			if(Arrays.binarySearch(S,T[i]) >= 0)
				count++;
		}

		System.out.println(count);
	}
}

Measured memory_bytes: 76060
#include<stdio.h>
#include<string.h>
 
int main(){
 
  int n,i;
  char s[101];
  int cnt=0;

    scanf("%d",&n);
    scanf("%s",s);
  for(i=0;i<n;i++){
    if(s[i]=='R')cnt++; }

  if(cnt>n/2) printf("Yes");
  else	printf("No");
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <map>
#include <queue>
using namespace std;
const int maxn=2e5+10;
const int INF=0x3f3f3f3f;
int head[6*maxn],vis[6*maxn],dis[6*maxn];
struct point{
    int to,next,val;
}pt[6*maxn];
struct node{
    int va;
    int nod;
    friend bool operator < (node a,node b)
    {
        return a.va>b.va;
    }
};
map<pair<int,int>,int>mp;
int cnt,q;
void init()
{
    q=0;
    memset(head,-1,sizeof(head));
}
void add(int u,int v,int val)
{
    pt[q].next=head[u];
    pt[q].to=v;
    pt[q].val=val;
    head[u]=q++;
}
int get_id(int u,int v)
{
    if (mp[make_pair(u,v)]!=0)
        return mp[make_pair(u,v)];
    return mp[make_pair(u,v)]=cnt++;
}
void dir(int st)
{
    memset(dis,INF,sizeof(dis));
    memset(vis,0,sizeof(vis));
    node nu;
    nu.va=0;
    nu.nod=st;
    dis[st]=0;
    priority_queue<node>q;
    q.push(nu);
    while (!q.empty())
    {
        node nn=q.top();
        q.pop();
        if (vis[nn.nod])
            continue;
        //cout<<nn.nod<<"$$$$$$"<<endl;
        vis[nn.nod]=1;
        for (int i=head[nn.nod];i!=-1;i=pt[i].next)
        {
            int to=pt[i].to;
            if (dis[nn.nod]+pt[i].val<dis[to]&&!vis[to])
            {
                dis[to]=dis[nn.nod]+pt[i].val;
                //cout<<to<<"!!!!!"<<dis[to]<<endl;
                nu.va=dis[to];
                nu.nod=to;
                q.push(nu);
            }
        }

    }
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,m,u,v,id;
    while(cin>>n>>m)
    {
        init();
        cnt=n+1;
        mp.clear();
        while (m--)
        {
            cin>>u>>v>>id;
            int id_fir=get_id(u,id);
            int id_sec=get_id(v,id);
            add(u,id_fir,1);
            add(id_fir,u,1);
            add(id_fir,id_sec,0);
            add(id_sec,id_fir,0);
            add(id_sec,v,1);
            add(v,id_sec,1);
//            cout<<u<<"***"<<id_fir<<endl;
//            cout<<id_fir<<"***"<<id_sec<<endl;
//            cout<<id_sec<<"****"<<v<<endl;

        }
        dir(1);
//        for (int i=1;i<=n;i++)
//                cout<<dis[i]<<" ";
//        cout<<endl;
        if (dis[n]==INF)
            cout<<"-1"<<endl;
        else
            cout<<dis[n]/2<<endl;
    }
    return 0;
}


Measured memory_bytes: 54524
import sys
import numpy as np

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def main():
	N, K = LI()
	h_i = np.array(LI())
	dp = np.full(N, 10**10, dtype=int)
	dp[0] = 0
	for i in range(1, N):
		dp[i:i+K] = np.fmin(dp[i:i+K], dp[i-1] + np.abs(h_i[i:i+K] - h_i[i-1]))
		
	return dp[-1]


if __name__ == "__main__":
	print(main())

Measured memory_bytes: 22804
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << std::fixed << std::setprecision(10);

	int a, b;
	cin >> a >> b;
	cout << max(0, a - b * 2) << endl;

	return 0;
}

Measured memory_bytes: 256
def main():
    N=int(input())
    L=[int(x) for x in input().split()]
    L.sort()
    count=0

    dic={}

    for i in range(N):
        for j in range(i+1,N):
            if i:
                try:
                    start=dic[j]
                    count+=dic[j]-j-1
                except:
                    count+=N-j-1
                    continue
            else:
                start=j+1
            for k in range(start,N):
                if L[k]>=L[i]+L[j]:
                    dic[j]=k
                    break
                count+=1
                
                
                
    print(count)

main()


Measured memory_bytes: 44892
from sys import exit
 
N = int(input())
h = list(map(int,input().split()))

for i in range(N-1,0,-1):
    if h[i] < h[i-1]:
        h[i-1] -= 1
    
    if h[i] < h[i-1]:
        print("No")
        exit(0)

print("Yes")

Measured memory_bytes: 84880
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
  int N;
  cin >> N;
  int tmp_t = 0, tmp_x = 0, tmp_y = 0;
  REP(i, N){
    int t, x, y;
    cin >> t >> x >> y;
    int d = (t - tmp_t) - abs(x-tmp_x) - abs(y - tmp_y);
    if(d == 0 || (d % 2 == 0 && d > 0)){
    tmp_t = t; tmp_x = x; tmp_y = y;
    }else{
      no;
      return 0;
    }
  }
yes;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int R = sc.nextInt();
		int S = sc.nextInt();
		int P = sc.nextInt();
		String T = sc.next();
		int A[] = new int[T.length()];
		long sum = 0;
		for (int i = 0; i < T.length(); i++) {
			if (A[i] != 1) {
				switch (T.charAt(i)) {
				case 'r':
					sum += P;
					break;
				case 's':
					sum += R;
					break;
				default:
					sum += S;
					break;
				}
				if (i+K<T.length()&&T.charAt(i)==T.charAt(i+K)) {
					A[i+K] =1;
				}
			}
		}
		System.out.println(sum);
	}

}

Measured memory_bytes: 28548
N, K = map(int, input().split())

if K % 2 == 0:
    num = N // K
    num2 = N // (K // 2) - num
    ans = num ** 3 + num2 ** 3
    
else:
    num3 = N // K
    ans = num3 ** 3

print(ans)

Measured memory_bytes: 2940
#include<cstdio>
#include<cmath>
#include<cctype>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define LC(a) (a<<1)
#define RC(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
#define fin(name)  freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define FOR(i,start,end) for(int i=start;i<=end;i++)  
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
const int N=2e5+5;

int a[N],b[N];

bool cmp(int a,int b){
	return a<b;
}

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	FOR(i,1,n){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1,cmp);
	int tmp=a[1],cnt=1,idx=0;
	FOR(i,2,n){
		if(a[i]!=tmp){
			b[++idx]=cnt;
			tmp=a[i];
			cnt=1;
		}
		else
			cnt++;
	}	
	b[++idx]=cnt;
	sort(b+1,b+1+idx);
	k-=idx;
	int i=1,ans=0;
	while(i<=idx&&k<0){
		ans+=b[i++];
		k++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll power(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)

//your code here!
int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート 1,2,....9
}

int main(void){
    ll N, a[300100], ans=0;
    scanf("%lld", &N);
    rep(i, 3*N) scanf("%lld", a+i);
    qsort(a, 3*N, sizeof(ll), cmp);
    for(ll i=1; i<=N; i++) ans += a[3*N-2*i];
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 4860
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;


int main() {

    string S, T;
    int A, B;
    string U;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if(S == U) A--;
    if(T == U) B--;

    cout << A << " " << B << endl;

    
    
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256
A,B = map(int,input().split())
import math
a,b = math.ceil(A/0.08),int((A+1)//0.08)
c,d = math.ceil(B/0.1),int((B+1)//0.1)
if (a>=c)and(a<d):
  print(int(a))
elif (c>=a)and(c<b):
  print(int(c))
else:
  print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,a,n) for(ll i=a;i<(ll)(n);i++)

int main(){
    ll N; cin>>N;
    ll ans = 1;
    rep(i, N){
        ll T; cin>>T;
        ans = ans/__gcd(ans, T)*T;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */

const int MAX_C = 100;
lint cmb[MAX_C][MAX_C];
void cmb_init(){
    cmb[0][0] = 1;
    repn(i, 50) rep(j, i+1){
        if(j == 0) cmb[i][0] = 1;
        else if(j == i) cmb[i][i] = 1;
        else cmb[i][j] = cmb[i-1][j-1] + cmb[i-1][j];
    }
}

int main(){
    cmb_init();

    ii3(n,a,b);
    vector<lint> vec;
    rep(i, n){
        lint x; cin >> x; vec.push_back(x);
    }
    sort(all(vec), greater<lint>());

    bool flag = true;
    double avg = 0;
    rep(i, a){
        if(vec[i] != vec[0]){ flag = false; }
        avg += vec[i];
    }
    setpre(6); out(avg / a);

    if(flag){
        int k = 0;
        for(int i = a; i < n; i++){
            if(vec[i] != vec[0]) break;
            k++;
        }
        lint ans = 0;
        for(int i = 0; (i <= k && a+i <= b); i++){
            ans += cmb[a+k][a+i];
        }
        out(ans); return 0;
    }

    int m = 0, l = 0;
    rep(i, n){
        if(vec[i] == vec[a-1]){
            if(i < a-1) m++;
            else if(i > a-1) l++;
        }
    }
    lint ans = cmb[m+l+1][m+1];
    out(ans);
}

Measured memory_bytes: 256
#####segfunc######                                                              
def segfunc(x,y):
    return x+y

def init(init_val):
    #set_val                                                                    
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built                                                                      
    for i in range(num-2,-1,-1):
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])
    
def update(k,x):
    k+=num-1
    seg[k]=x
    while k+1:
        k=(k-1)//2
        seg[k]=segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p+=num-1
    q+=num-2
    res=ide_ele
    while q-p>1:
        if p&1==0:
            res=segfunc(res,seg[p])
        if q&1==1:
            res=segfunc(res,seg[q])
            q-=1
        p=p//2
        q=(q-1)//2
    if p==q:
        res=segfunc(res,seg[p])
    else:
        res=segfunc(segfunc(res,seg[p]),seg[q])
    return res

ide_ele=0
n,q=map(int,input().split())
num=2**(n-1).bit_length()
seg=[ide_ele]*2*num
a=list(map(int,input().split()))
init(a)
ans=0
for i in range(q):
    x,l,r=map(int,input().split())
    if x==0:
        update(l,seg[l+num-1]+r)
    else:
        print(query(l,r))


Measured memory_bytes: 177684
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (p, q, r) = {
      let v: Vec<u64> = read_vec();
      (v[0], v[1], v[2])
    };

    let mut v = vec![0; 3];
    v[0] = p + q;
    v[1] = p + r;
    v[2] = q + r;
    v.sort();
    println!("{}", v[0]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2e5+3;
int n,k,l;
struct DSU{
	int fa[MaxN],rank[MaxN];
	DSU() { for (int i=1;i<MaxN;++i) fa[i]=i,rank[i]=1; }
	int getfa(int x) {return (fa[x]==x) ? x : (fa[x]=getfa(fa[x]));}
	inline void uni(int a,int b) {
		a=getfa(a),b=getfa(b);
		if (a!=b) {
			if (rank[a]<rank[b]) {
				fa[a]=b;
				rank[b]+=rank[a];
			} else {
				fa[b]=a;
				rank[a]+=rank[b];
			}
		}
	}
}road,railway;
typedef pair<int,int> PII;
map<PII,int> mp;
int main() {
	scanf("%d%d%d",&n,&k,&l);
	for (int i=1;i<=k;++i) {
		int p,q;
		scanf("%d%d",&p,&q);
		road.uni(p,q);
	}
	for (int i=1;i<=l;++i) {
		int r,s;
		scanf("%d%d",&r,&s);
		railway.uni(r,s);
	}
	for (int i=1;i<=n;++i) {
		int x=road.getfa(i),y=railway.getfa(i);
		PII t=make_pair(x,y);
		if (!mp.count(t)) mp[t]=0;
		mp[t]++;
	}
	for (int i=1;i<=n;++i) {
		int x=road.getfa(i),y=railway.getfa(i);
		printf("%d ",mp[PII(x,y)]);
	}
	return 0;
}

Measured memory_bytes: 15232
def read_input():
    n = int(input())
    conds = []
    for _ in range(n):
        x, y, h = map(int, input().split())
        conds.append(((x, y), h))

    return n, conds


def manhattan(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])


def satisfy(cond, center):
    c, ch = center
    p, h = cond
    return ch == h + manhattan(p, c)


def zero_satisfy(cond, center):
    c, ch = center
    p, h = cond
    return ch <= manhattan(p, c)


def submit():
    n, conds = read_input()    

    if n == 1:
        p, h = conds[0]
        print("{} {} {}".format(p[0], p[1], h))
        return

    plus_conds = [c for c in conds if c[1] > 0]
    zero_conds = [c for c in conds if c[1] == 0]
    st = plus_conds[0]

    center_cands = []
    for i in range(101):
        for j in range(101):
            t = (i, j)
            th = st[1] + manhattan(st[0], t) # 仮にtがpより高い位置の頂点だとする
            center_cands.append((t, th))
    
    # 各条件について満たすか否かを判定していく
    for cond in plus_conds[1:]:
        center_cands = [c for c in center_cands if satisfy(cond, c)]

    # h=0の条件について、有効かどうか判定していく
    for cond in zero_conds:
        center_cands = [c for c in center_cands if zero_satisfy(cond, c)]

    # 全条件を満たすポイントは1つのはず
    center, h = center_cands[0]
    print("{} {} {}".format(center[0], center[1], h))
            

if __name__ == "__main__":
    submit()

Measured memory_bytes: 4716
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <inttypes.h>

int main(void){
	int n;

	scanf("%d",&n);
	n=n%10;
	if(n==2||n==4||n==5||n==7||n==9){
		printf("hon");
	}else if(n==0||n==1||n==6||n==8){
		printf("pon");
	}else{
		printf("bon");
	}
	return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <iomanip>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef long long ll;

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// constexpr inline ll mod = 1'000'000'007;
constexpr int max_n = 200'000;

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    int n; cin >> n;
    vector<int> num_r(n+1);
    rep(i,n){
        char c; cin >> c;
        num_r[i+1] = num_r[i] + (c == 'R');
    }

    int res = max_n;
    rep(i,n+1) {
        // [0,i) : R
        // [i,n] : W
        int tmpres = abs(i - num_r[n]) + (i - num_r[i]);
        res = min(res, tmpres);
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3972
N = int(input())

prime = [3, 5, 7, 11, 13]

# 約数が8個ということは、素因数分解した時の素因数の個数が0/7, 1/3, 1/1/1以外ありえない
zero_seven = 0
one_three = [a * (b ** 3) for a in prime for b in prime if a != b]
one_three = [i for i in one_three if i <= 200]
one_one_one = [a * b * c for a in prime for b in prime for c in prime
               if a != b and b != c and c != a]
one_one_one = [i for i in one_one_one if i <= 200]

ans = sorted(set(one_three + one_one_one))
if N <= 104:
    print(0)
elif 105 <= N <= 134:
    print(1)
elif 135 <= N <= 164:
    print(2)
elif 165 <= N <= 188:
    print(3)
elif 189 <= N <= 194:
    print(4)
elif 195 <= N:
    print(5)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  vector<vector<int>> cnt(h, vector<int>(w));
  rep(i,h) {
    vector<int> done(w);
    rep(j,w) {
    	if (s[i][j] == '#') continue;
      if (done[j]) continue;
      int l = 0;
      while (j+l < w) {
      	if (s[i][j+l] == '#') break;
        ++l;
      }
      rep(k,l) {
      	cnt[i][j+k] += l;
        done[j+k] = 1;
      }
    }
  }
  rep(j,w) {
    vector<int> done(h);
    rep(i,h) {
      if (s[i][j] == '#') continue;
      if (done[i]) continue;
      int l = 0;
      while (i+l < h) {
        if (s[i+l][j] == '#') break;
        ++l;
      }
      rep(k,l) {
        cnt[i+k][j] += l;
        done[i+k] = 1;
      }
    }
  }
  int ans = 0;
  rep(i,h)rep(j,w) ans = max(ans, cnt[i][j]-1);
  cout << ans << endl;
  return 0;
} 

Measured memory_bytes: 20096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define MP make_pair
#define F first
#define S second
#define ALL(v) (v).begin(), (v).end()
#define PUTS(x) cout << (x) << endl;
int main() {
    int n, m;
    cin >> n >> m;
    auto v = vector<pair<int, bool>>(n, MP(1, false));
    v[0].S = true;
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        v[x].F--;
        v[y].F++;
        if (v[x].S) v[y].S = true;
        if (v[x].F == 0) v[x].S = false;
    }
    auto ans = accumulate(ALL(v), 0, [](const auto &result, const auto &vec) {
        return result + (vec.S ? 1 : 0);
    });
    PUTS(ans);
}


Measured memory_bytes: 1024
#include<cstdio>
const int N=303;
int b[4],n,a;double f[N][N][N];
signed main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a),b[a]++;
	f[0][0][0]=0;
	for(int k=0;k<=b[3];k++)
	  for(int j=0;j+k<=b[2]+b[3];j++)
		for(int i=0;i+j+k<=b[1]+b[2]+b[3];i++)if(i+j+k){
		  f[i][j][k]=1.0*n/(i+j+k);
		  if(i)f[i][j][k]+=1.0*i/(i+j+k)*f[i-1][j][k];
		  if(j)f[i][j][k]+=1.0*j/(i+j+k)*f[i+1][j-1][k];
		  if(k)f[i][j][k]+=1.0*k/(i+j+k)*f[i][j+1][k-1];
		}
	printf("%.15lf",f[b[1]][b[2]][b[3]]);
	return 0;
}

Measured memory_bytes: 217216
#include<bits/stdc++.h>

using namespace std;
int main(){
    string s;
    string a,b;
    cin>>s;
    int l=s.length();
    for(int i=0;i<l;i++){
        if(i&1) a+='0',b+='1';
        else a+='1',b+='0';
    }
    int ans1=0;
    int ans2=0;
    for(int i=0;i<l;i++){
        if(a[i]!=s[i]) ans1++;
    }
    for(int i=0;i<l;i++){
        if(b[i]!=s[i]) ans2++;
    }
    cout<<min(ans1,ans2)<<endl;
    return 0;
}

Measured memory_bytes: 768
// 2011/07/21 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int wal[2][100];
		for(int i=0; i<n; i++)
			cin >> wal[0][i];
		wal[0][n] = 0;
		for(int i=0; i<n; i++)
			cin >> wal[1][i];
		wal[1][n] = 0;

		int cnt0 = 0;
		int bld = 0;
		int flr = 0;
		int memo[2];
		memo[0] = memo[1] = 0;
		while(wal[bld][flr]==1&&wal[bld][flr+1]==1)
			flr++;

		while(true){
			// cout << bld << ' ' << flr << endl;
			if(flr>=n-1)
				break;

			bld = (bld+1)%2;
			flr = flr+2;

			while(wal[bld][flr]==1&&wal[bld][flr+1]==1)
				flr++;

			while(wal[bld][flr]==2)
				flr--;

			if(memo[bld]>=flr){
				cnt0 = 300;
				break;
			}
			else
				memo[bld] = flr;

			cnt0++;
		}

		int cnt1 = 0;
		bld = 1;
		flr = 0;
		memo[0] = memo[1] = 0;
		while(wal[bld][flr]==1&&wal[bld][flr+1]==1)
			flr++;

		while(true){
			// cout << bld << ' ' << flr << endl;
			if(flr>=n-1)
				break;

			bld = (bld+1)%2;
			flr = flr+2;

			while(wal[bld][flr]==1&&wal[bld][flr+1]==1)
				flr++;

			while(wal[bld][flr]==2)
				flr--;

			if(memo[bld]>=flr){
				cnt1 = 300;
				break;
			}
			else
				memo[bld] = flr;

			cnt1++;
		}

		if(cnt0==300&&cnt1==300)
			cout << "NA" << endl;
		else if(cnt0<cnt1)
			cout << cnt0 << endl;
		else
			cout << cnt1 << endl;
	}

	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		while(true){
			String[] line = br.readLine().split(" ");
			int h = Integer.parseInt(line[0]);
			int w = Integer.parseInt(line[1]);
                        if( h==0 && w==0 ) break;
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					sb.append("#");
				}
				sb.append("\n");
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 25260
#include <iostream>
#include <vector>
using Vint = std::vector<int>;

Vint mult(std::vector<Vint> &A, Vint b){
    const int n = A.size();
    const int m = b.size();
    Vint c(n, 0);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            c[i] += A[i][j] * b[j];
        }
    }
    return std::move(c);
}

int main(void){
    int n, m; scanf("%d%d", &n, &m);
    std::vector<Vint> A(n, Vint(m));
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) scanf("%d", &A[i][j]);
    std::vector<int> b(m);
    for(int j = 0; j < m; j++) scanf("%d", &b[j]);
    Vint c = mult(A, b);
    for(int i = 0; i < n; i++) printf("%d\n", c[i]);
    return 0;
}


Measured memory_bytes: 3312
#include <stdio.h>
int main(){
int n,i;
scanf("%d",&n);
{
if(1<=n&&n<=9)
{i=n;
printf("%d",i);}
if(10<=n&&n<=99)
{printf("9");}
if(100<=n&&n<=999)
{i=9;
i+=n-99;
printf("%d",i);}
if(1000<=n&&n<=9999)
{printf("909");}
if(10000<=n&&n<=99999)
{i=909;
i+=n-9999;
printf("%d",i);}
if(n==100000)
{printf("90909");}
}
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<long long> x(N), y(N);
    for(int i=0; i<N; i++) cin >> x[i] >> y[i];

    long long ans = 1LL << 62;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            for(int k=0; k<N; k++){
                for(int l=0; l<N; l++){
                    long long x1 = x[i];
                    long long x2 = x[j];
                    long long y1 = y[k];
                    long long y2 = y[l];
                    if(x1 > x2) swap(x1, x2);
                    if(y1 > y2) swap(y1, y2);
                    int cnt = 0;
                    for(int m=0; m<N; m++)
                        if(x1 <= x[m] && x[m] <= x2 && y1 <= y[m] && y[m] <= y2) cnt++;
                    if(cnt >= K) ans = min(ans, (x2-x1)*(y2-y1));
                    }
                }
            }
        }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int an[SIZE];
void print_array(int arr[],int n){
    REP(i,n){
        printf("%d\n",arr[i]);
    }
}
struct data{
    int x,dir,id;
    data(int _x=0,int _dir=0,int _id=0):x(_x),dir(_dir),id(_id){}
    bool operator<(const data& b)const{return x<b.x;}
}a[SIZE];
int b[SIZE];
int main(){
    DRII(n,m);
    LL t;
    cin>>t;
    REP(i,n){
        RI(a[i].x);
        a[i].x%=m;
        a[i].id=i;
        char s[4];
        RS(s);
        if(s[0]=='1')a[i].dir=1;
        else a[i].dir=-1;
    }
    sort(a,a+n);
    bool dif=0;
    REPP(i,1,n){
        if(a[i].dir!=a[i-1].dir)dif=1;
    }
    if(!dif){
        if(a[0].dir==1){
            REP(i,n)an[a[i].id]=(a[i].x+t)%m;
        }
        else{
            REP(i,n)an[a[i].id]=((a[i].x-t)%m+m)%m;
        }
    }
    else{
        int st=0;
        while(a[st].dir==-1)st++;
        int neg=0,lst_neg=0;
        REP(i,n){
            if(a[i].dir==-1){
                neg+=2;
                if((a[i].x-a[st].x+m)%m<t%m*2)lst_neg++;
                if((a[i].x-a[st].x+m)%m+m<t%m*2)lst_neg++;
            }
        }
        int ch=(neg*(t/m)+lst_neg)%n;
        REP(i,n){
            if(a[i].dir==1)b[i]=(a[i].x+t)%m;
            else b[i]=((a[i].x-t)%m+m)%m;
        }
        sort(b,b+n);
        int st_new_pos=(a[st].x+t)%m;
        int new_st=0;
        while(b[new_st]<st_new_pos)new_st++;
        REP(i,n)
            an[a[(st+i+ch)%n].id]=b[(new_st+i)%n];
    }
    print_array(an,n);
    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 205
#define INF 10000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int V,M,R;
int r[10];
ll d[SIZE][SIZE];

void init_warshall_floyd(){
	rep(i,0,V) rep(j,0,V) d[i][j] = INF;
	rep(i,0,V) d[i][i] = 0;
}


void warshall_floyd(){
	rep(k,0,V) rep(i,0,V) rep(j,0,V){
		d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
	}
}

int main()
{
	cin >> V >> M >> R;
	rep(i,0,R)cin >> r[i];
	rep(i,0,R)r[i]--;
	init_warshall_floyd();
	int a,b;
	ll c;
	rep(i,0,M){
		cin >> a >> b >> c;
		a--;b--;
		d[a][b] = c;
		d[b][a] = c;
	}
	warshall_floyd();
	ll ans=INF;
	sort(r,r+R);
	do{
		ll crr=0;
		rep(i,0,R-1) crr += d[r[i]][r[i+1]];
		ans = min(crr,ans);
	}while(next_permutation(r,r+R));

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>

using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++ )

int main()
{
  string a, b;
  cin >> a >> b;
  if(a.length() < b.length()) {
    cout << "LESS" << endl;
  }else if(a.length() > b.length()) {
    cout << "GREATER" << endl;

  }else{
    bool check = false;
    REP(i, a.length()) {
      if(a[i] < b[i]) {
        cout << "LESS" << endl;
        check = true;
        break;
      }else if(a[i] > b[i]) {
        cout << "GREATER" << endl;
        check = true;
        break;
      }
    }
    if(!check) cout << "EQUAL" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl


int main(){
    int n,m,t;
    cin >> n >> m;
    map<int,ll,greater<ll>>map1;
    REP(i,n){
        cin >> t;
        map1[t]++;
    }
    int b,c;
    REP(i,m){
        cin >> b >> c;
        map1[c]+=b;
    }
    ll ans = 0;
    int count=n;
    for(const auto &x:map1){
        int y = x.first;
        ll z = x.second;
        if(count>=z){
            ans+=y*z;
            count-=z;
        }
        else{
            ans += (ll)y*count;
            break;
        }
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 13440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;

    string divide[4] = {"dream", "dreamer", "erase", "eraser"};
    
    reverse(s.begin(), s.end());
    for(int i = 0; i < 4; i++)
        reverse(divide[i].begin(), divide[i].end());

    bool can = true;
    for(int i = 0; i < s.size();){
        bool can2 = false;
        for(int j = 0; j < 4; j++){
            string d = divide[j];
            if(s.substr(i, d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }
        if(!can2){
            can = false;
            break;
        }
    }
    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define forx(i,a,b) for(int i=(a);i<(b);i++)
#define rep (i,n) forx(i,0,n)
typedef long long ll; 


int main()
{
    int n,m,x,s=0,t=0;
    cin>>n>>m>>x;
    forx(i,0,m){
      int p;
    cin>>p;
    if(p<x)s++;
    if(p>x) t++;
    }
    cout<<min(s,t)<<endl;

return 0;
}


Measured memory_bytes: 256
def smaller(x, y):
	if x < y:
		return x
	return y

def allzero(lst):
	for i in range(0, len(lst)):
		if lst[i] != 0:
			return False
	return True

def minimum(lst):
	min = 5000000000000000
	for i in range(0, len(lst)):
		min = smaller(min, lst[i])
	return min

N = int(input())
H = list(map(int, input().split()))
sum = 0
while not allzero(H):
	left = -1
	right = -1
	for i in range(0, N):
		if H[i] != 0:
			left = i
			break
	for i in range(left, N):
		if H[i] == 0:
			right = i
			break
	if right == -1:
		right = N
	min = minimum(H[left:right])
	sum += min
	for i in range(left, right):
		H[i] -= min
print(sum)

Measured memory_bytes: 39152
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int n,m;
  cin>>n>>m;
  int l_max=0,r_min=1000000;
  for(int i=0;i<m;i++){
    int l,r;
    cin>>l>>r;
    l_max=max(l,l_max);
    r_min=min(r,r_min);
  }
  if(l_max>r_min) cout<<0<<endl;
  else cout<<r_min-l_max+1<<endl;
  return 0;
}


Measured memory_bytes: 256
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let k: usize = sc.read();
    let mut a: Vec<usize> = sc.vec(n);
    a.sort();

    if is_needed(&a, 0, k) {
        println!("0");
        return;
    }

    let mut ok = n;
    let mut ng = 0;
    while ok - ng > 1 {
        let m = (ok + ng) / 2;
        if is_needed(&a, m, k) {
            ok = m;
        } else {
            ng = m;
        }
    }
    println!("{}", ok);
}

fn is_needed(a: &Vec<usize>, target: usize, k: usize) -> bool {
    if a[target] >= k {
        return true;
    }
    let n = a.len();
    let mut dp = vec![false; k];
    dp[0] = true;
    for i in 0..n {
        if i == target {
            continue;
        }
        for k in (0..k).rev() {
            if k + a[i] >= dp.len() {
                continue;
            }
            dp[k + a[i]] |= dp[k];
        }
    }
    for i in 0..k {
        if dp[i] && i + a[target] >= k {
            return true;
        }
    }
    false
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
//#define kk
#define int long long
#define FOR(a, b) for(int i=a; i<=b; i++)
#define REP(i, a, b) for(int i=a; i<=b; i++)
#define ff first
#define ss second
#define ll long long
#define inf 1000000000
#define pb push_back
#define mod 1000000007
 
const ll INF=1e18+5;
const int maxN=1e5+5;
typedef pair<int, int> pi;
 
vector<int> arr[maxN];
int dp[maxN][2];

void getWays(int v, int p){
	dp[v][0]=dp[v][1]=1;
	
	for(int child: arr[v]){
		if(child!=p){
			getWays(child, v);
			dp[v][0]=(dp[v][0]%mod*(dp[child][0]+dp[child][1])%mod)%mod;
			dp[v][1]=(dp[v][1]%mod*dp[child][0]%mod)%mod;
		}
	}
}

void solve(){
	int n;
	cin>>n;
	
	FOR(1, n-1){
		int a, b;
		cin>>a>>b;
		arr[a].pb(b);
		arr[b].pb(a);
	}
	
	getWays(1, -1);
	
	cout<<(dp[1][0]+dp[1][1])%mod<<endl;
}
 
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cout<<fixed<<setprecision(6);
	
	#ifdef kk
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	
	int T=1;
	//cin>>T;
	
	while(T--){		
		solve();
	}
}


Measured memory_bytes: 17496
n = int(input())
s = [str(input()) for _ in range(n)]
m = int(input())
t = [str(input()) for _ in range(m)]

orange = [0]
for i in s:
    a = s.count(i)
    b = t.count(i)
    orange.append(a - b)

print(max(orange))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std ;

int main () {
  int N ;
  cin >> N ;
  
  char line[N] ;
  int num1[N] = {} ;
  int num2[N] = {} ;
  
  for ( int i = 0 ; i < N ; i++ ) cin >> line[i] ;
  
  for(int i = 1 ; i < N ; i++ ) {
    num1[i] += num1[ i-1 ] ;
    if( line[i - 1 ] == 'W' ) num1[i]++ ;
  }
  for(int i = N-2 ; i >= 0 ; i-- ) {
    num2[i] += num2[ i+1 ] ;
    if( line[i + 1 ] == 'E' ) num2[i]++ ;
  }
  
  int ans = 10000000 ;
  
  for( int i = 0 ; i < N ; i++ ) {
    ans = min(ans,num1[i]+num2[i]) ;
  }
  
  cout << ans << endl ;
}

Measured memory_bytes: 2944
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>

using namespace std;

template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar_unlocked();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar_unlocked();

        if (c < '0' || c > '9') break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int main()
{
    int N;

    gc(N);

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        int l, r;

        gc(l);
        gc(r);

        ans += r - l + 1;
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin>>N>>S;
  int sum=0;
  for(int i=0;i<N-2;i++){
  if(S.at(i)=='A'){
  if(S.at(i+1)=='B'){
  if(S.at(i+2)=='C'){
    sum++;
  }
  }
  }
  } cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  int w[n];
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  int l = w[0];
  int r = accumulate(w + 1, w + n, 0);
  int d = abs(r - l);
  for (int i = 1; i < n - 1; i++) {
    l += w[i];
    r -= w[i];
    d = min(d, abs(r - l));
  }
  cout << d << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define int long long
#define F first
#define S second
#define pi pair <int, int>
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define watch(x) cout << (#x) << " = " << (x) << "\n"
#define PI 3.14159265359
#define MOD 1000000007
#define INF 1000000000000000005

using namespace std;

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T = 1;
	//cin >> T;
	while(T--){
		int n;
		cin >> n;
		int a[n];
		int i;
		for(i =0 ; i < n; i++){
			cin >> a[i];
		}
		int j, k;
		int ans = 0;
		sort(a, a+n);
		for(i = 0; i < n; i++){
			for(j = i + 1; j < n; j++){
				for(k = j + 1; k < n; k++){
					if(a[i] != a[j] && a[j] != a[k] && a[i] != a[k] && a[i] + a[j] > a[k]){
						ans++;
					}
				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


Measured memory_bytes: 3696
#include<stdio.h>
#include<math.h>
int main(void)
{
double a,b,x;
  double theta,tangent;
  scanf("%lf%lf%lf",&a,&b,&x);
  if(x>=((a*a*b)/2)){
  tangent = (2*b/a - 2*x/a/a/a);
  theta = atan(tangent)*(180/M_PI);
  }
  else{
    tangent = (2*x/a/b/b);
  theta = 90 - atan(tangent)*(180/M_PI);
  }
printf("%lf",theta);
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>

using namespace std;

int a[51];

int main(){
  int n, k;
  scanf("%d %d", &n, &k);
  for(int i = 0; i < n; ++i){
    scanf("%d", a + i);
  }
  int ans = 0;
  for(int i = 0; i < n; ++i){
    if(i >= k){
      break;
    }
    pair<int, int> prev_max = make_pair(a[i], i);
    for(int j = i + 1; j < n; ++j){
      if(a[j] > prev_max.first){
        prev_max.first = a[j];
        prev_max.second = j;
      }
    }
    ans += prev_max.first;
    swap(a[prev_max.second], a[i]);
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;
  int *a;
  int *b;
  int *c;
  int *d;
int q;
int64_t find(int val[],int index,int n,int m){
  if(index==n){
    int64_t score = 0;
    for(int i=0;i<q;i++){
      if(val[b[i]-1]-val[a[i]-1] == c[i]) score += d[i];
    }
    return score;
  }

  int64_t score = 0;
  int64_t scoreMax = 0;
  for(int i=val[index-1];i<=m;i++){
    val[index] = i;
    score = find(val,index+1,n,m);
    if(scoreMax<score)scoreMax = score;
  }
  return scoreMax;
}

signed main() {
  int n,m;
  cin >> n >> m >> q;
  
  a = new int[q];
  b = new int[q];
  c = new int[q];
  d = new int[q];

  
  for(int i=0;i<q;i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  
  int val[n] = {0};
  val[0] = 1;
  
  cout << find(val, 1, n, m) << endl;

  delete[] a;
  delete[] b;
  delete[] c;
  delete[] d;


  
  //  1 1 1 1 ... 1
  //  1 2 2 4 ... 5
  //  1 3 3 5 ... 5
  //  1 4 4
  //  1 5 5
  
  
  
  
  
  
  return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a;
	string s;
	cin>>a>>s;
	cout<<(a<3200?"red":s)<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int[] m = new int[n];
		for (int i = 0; i < n; ++i) {
			m[i] = sc.nextInt();
		}

		Arrays.sort(m);
		while (true) {
			for (int i = 0; i < n; ++i) {
				if (m[i] != 0) {
					for (int j = i; j < n - 1; ++j) {
						m[j + 1] = m[j + 1] % m[i];
					}
					Arrays.sort(m);
					break;
				}
			}
			if (m[n-2]==0) {
				System.out.println(m[n-1]);
				break;
			}
		}
	}
}

Measured memory_bytes: 50312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}

int main(){

  string s;
  cin >> s;
  if(s.size()%2){
    cout << "No" << endl;
    return 0;
  }

  FOR(i,0,s.size()){
    if(i%2){
      if(s[i]!='i'){
        cout << "No" << endl;
        return 0;
      }
    }else{
      if(s[i]!='h'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ll long long
using namespace std;

const int N = 1e5 + 7;
const long long oo = 1e18L + 5;

int n, h[N];
ll dp[N];

ll go(int i) {
    if (i == n) {
        return 0;
    }
    if (i > n) {
        return oo;
    }
    ll &ret = dp[i];
    if (ret != -1) {
        return ret;
    }
    ret = min(go(i + 1) + abs(h[i] - h[i + 1]), go(i + 2) + abs(h[i] - h[i + 2]));
    return ret;
}

int main() {
    memset(dp, -1, sizeof dp);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> h[i];
    }
    cout << go(1) << endl;
    return 0;
}

Measured memory_bytes: 2944