akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> R;
typedef pair<double, R> Q;
const double INF = 1000000.0;

int n, m, s, g;

int V;
struct edge { int to, cost, maxspeed; };
vector<edge> G[30];
double d[30][30][31]; // city, before, speed

double dijkstra() {
  for (int i = 0; i < n; i++) for (int k = 0; k < n; k++) for (int j = 0; j <= 30; j++) d[i][k][j] = INF;
  d[s][s][0] = 0.0;
  priority_queue<Q, vector<Q>, greater<Q> > que;
  que.push(Q(0.0, R(P(s, 0), s)));
  while (!que.empty()) {
    Q q = que.top(); que.pop();
    double cost = q.first;
    int from = q.second.first.first, speed = q.second.first.second, before = q.second.second;
    if (cost > d[from][before][speed]) continue;
    for (int i = 0; i < G[from].size(); i++) {
      edge e = G[from][i];
      int to = e.to, length = e.cost, maxspeed = e.maxspeed;
      if (to == before) continue;
      for (int j = -1; j <= 1; j++) {
        int newspeed = speed + j;
        if (newspeed <= 0 || newspeed > maxspeed) continue;
        if (d[to][from][newspeed] > d[from][before][speed] + (double) length / newspeed) {
          d[to][from][newspeed] = d[from][before][speed] + (double) length / newspeed;
          que.push(Q(d[to][from][newspeed], R(P(to, newspeed), from)));
        }
      }
    }
  }
  double ans = INF;
  for (int i = 0; i < n; i++) ans = min(ans, d[g][i][1]);
  return ans;
}

int main() {
  while (1) {
    scanf("%d%d", &n, &m);
    if (n == 0) break;
    scanf("%d%d", &s, &g);
    s--; g--;
    int x, y, d, c;
    for (int i = 0; i < m; i++) {
      scanf("%d%d%d%d", &x, &y, &d, &c);
      x--; y--;
      edge e1, e2;
      e1.cost = e2.cost = d;
      e1.maxspeed = e2.maxspeed = c;
      e1.to = y, e2.to = x;
      G[x].push_back(e1);
      G[y].push_back(e2);
    }
    double ans = dijkstra();
    if (ans == INF) printf("unreachable\n");
    else printf("%f\n", ans);
    for (int i = 0; i < n; i++) G[i].clear();
  }
}



Measured memory_bytes: 3316
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>   
#include <stdio.h>    
 
using namespace std;
     
#define F first
#define S second
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, v[21], c[21], ans;

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                    

inline void Solve () {
   cin >> n;
   for (int i = 0; i < n; i ++) cin >> v[i];
   for (int i = 0; i < n; i ++) cin >> c[i];
   for (int mask = 0; mask < (1 << n); mask ++) {
      int sum = 0, cost = 0;
      for (int i = 0; i < n; i ++) {
         if (mask & (1 << i))
            sum += v[i], cost += c[i];
      }
      ans = max (ans, sum - cost);
   }
   cout << ans;
   
}                                     

int main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
// cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}


Measured memory_bytes: 256
a, b, c, d, e, f = gets.split.map(&:to_i)

water_patterns = []
0.step(f, 100 * a) do |water_a|
  water_a.step(f, 100 * b) do |water|
    water_patterns << water
  end
end
water_patterns.uniq!

sugar_patterns = []
0.step(f, c) do |sugar_a|
  sugar_a.step(f, d) do |sugar|
    sugar_patterns << sugar
  end
end
sugar_patterns.uniq!

ws_noverflow = water_patterns.product(sugar_patterns).select { |w, s| w + s <= f }
ws_dissolved = ws_noverflow.select { |w, s| s.fdiv(w + s) <= e.fdiv(100 + e) }

water, sugar = ws_dissolved.max_by { |w, s| s.fdiv(w + s) }

#rec = Hash.new do |h, k|
#  water, sugar = k
#
#  h[k] = case water + sugar <=> F
#  when 1
#    [0, 0]
#  when 0
#    [water, sugar]
#  when -1
#    sol = E.fdiv(100 + E)
#    if sol <= sugar.fdiv(water + sugar)
#      [h[[water + 100 * A, sugar]], h[[water + 100 * B, sugar]]]
#    else
#      [h[[water, sugar + C]], h[[water, sugar + D]], [water, sugar]].reject { |w, s| sol <= s.fdiv(w + s) }
#    end.max_by { |w, s| (w + s).zero? ? 0 : sugar.fdiv(w + s) }
#  end
#end
#
#water, sugar = rec[[0, 0]]

puts "#{water + sugar} #{sugar}"


Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll Q, H, S, D;
    cin >> Q >> H >> S >> D;
    ll M2[] = {D, 2 * S, 4 * H, 8 * Q}, M1[] = {S, 2 * H, 4 * Q};

    ll N;
    cin >> N;
    ll ans = (N / 2 * *min_element(M2, M2 + 4) + N % 2 * *min_element(M1, M1 + 3));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)


void solve(long long N, std::vector<long long> A){
    vector<ll> count(N, 0);
    REP(i, N){
        A.at(i)--;
        count.at(A.at(i))++;
    }
    ll total = 0;
    REP(i, N){
        if(count.at(i) >= 2){
            total += count.at(i) * (count.at(i) - 1) / 2;
        }
    }
    REP(i, N){
        ll ans = total;
        const ll v = A.at(i);
        ans -= count.at(v) * (count.at(v) - 1) / 2;
        if(count.at(v) >= 3){
            ans += (count.at(v) - 1) * (count.at(v) - 2) / 2;
        }
        cout << ans << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,i,y,s=0;
  cin>>n>>m;
  int a[m];
  for(i=0;i<m;i++)
  {
    cin>>a[i];
  	s+=a[i];
  }
  if(s>n)
    cout<<"-1";
  else
  {
    y=n-s;
    cout<<y;
  }
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
static const int N = 105; 
int cont;
int n;
void SelectionSort(int *a){
	int mini;
	for(int i=0;i<n;i++){
		mini=i;
		for(int j=i+1;j<n;j++)
			if(a[j]<a[mini]){
				mini=j;
			}
	    if(i!=mini){
	      swap(a[i],a[mini]);
		    cont++;	
    	}
	}
}
int main(){
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}

	SelectionSort(a); 
	for(int i=0;i<n;i++){
		if(i!=n-1)
			cout<<a[i]<<" ";
		else
			cout<<a[i]<<endl;
	}
	cout<<cont<<endl;
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ini(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll long long

int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//ll tt;	cin>>tt;	while(tt--)
	{
		ll n,i,j,k,x,y,ans,tot,type;
		cin>>x>>y;
		ll cnt[3];
		cin>>cnt[0]>>cnt[1]>>cnt[2];

		vector<pair<ll,ll>> v;

		for(i=0;i<3;i++)
		{
			for(j=0;j<cnt[i];j++)
			{
				cin>>k;
				v.pb({k,i});
			}
		}

		sort(v.rbegin(), v.rend());
		tot=x+y;
		ans=0;
		for(i=0;i<v.size();i++)
		{
			type = v[i].second;
			if(tot==0)	break;

			if(type==0)
			{
				if(x>0)
				{
					x--;
					tot--;
					ans+=v[i].first;
				}
				else	continue;
			}

			else if(type==1)
			{
				if(y>0)
				{
					tot--;
					y--;
					ans+=v[i].first;
				}
				else	continue;
			}

			else 
			{
				tot--;
				ans+=v[i].first;
			}

		}
		cout<<ans;
		
 	}
	cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
		
		
return 0;
}

Measured memory_bytes: 10604
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,c;
    cin>>a>>b>>c;
    
    int ans=a+b+c-max(a,max(b,c));
    cout1(ans)
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}

func main() {
	n := nextInt()
	weights := make([]int, n)

	left := 0
	right := 0

	for i := 0; i < n; i++ {
		weights[i] = nextInt()
		right += weights[i]
	}
	min := right

	for t := 0; t < n; t++ {
		var abs int

		if left < right {
			abs = right - left
		} else {
			abs = left - right
		}
		if min > abs {
			min = abs
		}
		right -= weights[t]
		left += weights[t]
	}

	fmt.Println(min)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int solve(string a, string b, string c) {
    int res = 1e8;
    vector<bool> ab(2000 + 1, true);
    vector<bool> bc(2000 + 1, true);
    vector<bool> ac(4000 + 1, true);

    auto match = [](char c1, char c2) { return (c1 == '?' || c2 == '?' || c1 == c2); };

    for (int i = 0; i < a.size(); i++)
        for (int j = i; j < a.size() && j - i < b.size(); j++)
            ab[i] = ab[i] && match(a[j], b[j - i]);
    for (int i = 0; i < b.size(); i++)
        for (int j = i; j < b.size() && j - i < c.size(); j++)
            bc[i] = bc[i] && match(b[j], c[j - i]);
    for (int i = 0; i < a.size() + b.size(); i++)
        for (int j = i; j < a.size() && j - i < c.size(); j++)
            ac[i] = ac[i] && match(a[j], c[j - i]);

    for (int i = 0; i <= 2000; i++)
        for (int j = 0; j <= 2000; j++)
            if (ab[i] && bc[j] && ac[i + j])
                res = min<int>(res, max({a.size(), i + b.size(), i + j + c.size()}));
    return res;
}

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    int ans = 1e8;
    ans = min(solve(a, b, c), ans);
    ans = min(solve(a, c, b), ans);
    ans = min(solve(b, a, c), ans);
    ans = min(solve(b, c, a), ans);
    ans = min(solve(c, a, b), ans);
    ans = min(solve(c, b, a), ans);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef pair<int, int> pii;

const int MAXN = 105;

int n;
char s[2*MAXN], respond[MAXN];

char ask(vector<int> pos) {
    string message = "?";
    for(int x: pos)
        message += " " + to_string(x + 1);
    printf("%s\n", message.c_str());
    fflush(stdout);

    char tmp[10];
    scanf("%s", tmp);
    string res(tmp);
    if (res == "Red")
        return 'R';
    if (res == "Blue")
        return 'B';

    exit(0);
}

char askSegment(int l) {
    vector<int> p;
    for(int i = l; i < l+n; ++i)
        p.push_back(i);
    return ask(p);
}

int main() {
    scanf("%d", &n);

    for(int i = 0; i < 2*n; ++i)
        s[i] = '?';
    s[2*n] = 0;

    // find balanced segment
    int balanceL = -1, balanceR = -1;

    int lo = 0, hi = n, res = -1;
    char cLo = askSegment(lo);
    char cHi = (cLo == 'R') ? 'B' : 'R';

    while (lo < hi-1) {
//        printf("%d %d\n", lo, hi);
        int mid = (lo + hi) / 2;
        char cMid = askSegment(mid);
        if (cMid == cLo) {
            lo = mid;
            cLo = cMid;
        } else {
            hi = mid;
            cHi = cMid;
        }
    }

    balanceL = hi;
    balanceR = hi + n - 2;

//    printf("%d %d\n", balanceL, balanceR);

    // find color outside balanced segment
    for(int i = 0; i < 2*n; ++i) {
        if (i < balanceL || i > balanceR) {
            vector<int> p;
            for(int j = balanceL; j <= balanceR; ++j)
                p.push_back(j);
            p.push_back(i);
            s[i] = ask(p);
        }
    }

//    printf("%s\n", s);

    // find color inside balanced segment
    vector<int> balanceSet;
    int cntR = 0, cntB = 0;
    for(int i = 0; i < 2*n; ++i) {
        if (s[i] == 'R' && cntR < n/2) {
            balanceSet.push_back(i);
            ++cntR;
        }
        if (s[i] == 'B' && cntB < n/2) {
            balanceSet.push_back(i);
            ++cntB;
        }
    }

    for(int i = balanceL; i <= balanceR; ++i) {
        vector<int> p = balanceSet;
        p.push_back(i);
        s[i] = ask(p);
    }

    printf("! %s\n", s);
    fflush(stdout);

    return 0;
}


Measured memory_bytes: 724
#include <stdio.h>

int main() {
	int a,b,c;
	int d = 0;
	scanf("%d %d %d", &a, &b, &c);
	for (int i = a; i <= b; i++) {
		if (c % i == 0) {
			d++;
		}
	}
	printf("%d\n", d);
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n, k;
    cin >> n >> k;
    int x[n], ans = 0;
    rep(i, n) cin >> x[i];
    rep(j, n){
        ans += 2 * min(k - x[j], x[j]);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){

int a,b,c;cin>>a>>b>>c;
if(a==b)cout<< c<<endl;
else if(a==c)cout<<b<<endl;
else cout << a << endl;


return 0;

}




Measured memory_bytes: 256
#include <stdio.h>

int linersearch(int *,int key);
int n;
int q;
int T[10000];

int main(){
  int i,j;
  int c=0;
  int S[10000];
  int Q[10000];
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&Q[i]);
  }
  for(i=0; i<n; i++){
    T[i] = -1;
  }
  
  for(i=0; i<n; i++){
    c += linerSearch(Q,S[i]);
  }
  printf("%d\n",c);
  return 0;
}

int linerSearch(int *A,int key){
  int i,j;
  A[q] = key;
  for(i=0; i<q; i++){
    if(A[i]==key){
      for(j=0;j < n;j++){
	if(A[i]==T[j]) {
	  //  printf("same %d, ",T[j]);
	  return 0;
	}
      }
      T[i] = key;
      return 1;
    }
  }
  return 0;
}




Measured memory_bytes: 2144
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>

using namespace std;

int main(){
	int n, s[3] = {0};
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(a[i] % 4 == 0){
			s[0]++;
		}
		else if(a[i] % 2 == 0){
			s[1] = 1;
		}
		else{
			s[2]++;
		}
	}
	
	if(s[0] > s[1] + s[2] - 2){
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
	
 	return 0;
}

Measured memory_bytes: 640
def solve(n,w):
    dp=[[0]*(n+1) for _ in range(n+1)]
    for kukan in range(2,n+1):
        for l in range(0,n+1-kukan):
            r=l+kukan
            #decide dp[l][l+kukan]
            if (kukan-2)%2==0:
                if abs(w[l]-w[r-1])<=1 and dp[l+1][r-1]==r-l-2:
                    dp[l][r]=dp[l+1][r-1]+2
                    continue
            for i in range(l+1,r):
                if dp[l][r]<(dp[l][i]+dp[i][r]):
                    dp[l][r]=dp[l][i]+dp[i][r]
    return dp[0][n]
            

n=int(input())
while(n!=0):
    w=list(map(int,input().split()))
    print(solve(n,w))
    n=int(input())


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

int main()
{
    int H, W;
    cin >> H >> W;

    vector<vector<string>> blocks(H, vector<string>(W));
    vector<bool> hasVerticalBlack(H, false);
    vector<bool> hasHorizontalBlack(W, false);

    for (int i = 0; i < H; i++)
    {
        string block;
        cin >> block;
        for (int j = 0; j < W; j++)
        {
            blocks.at(i).at(j) = block.at(j);
        }
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (blocks.at(i).at(j) == "#")
            {
                hasVerticalBlack.at(i) = true;
                hasHorizontalBlack.at(j) = true;
            }
        }
    }

    for (int i = 0; i < H; i++)
    {
        if (hasVerticalBlack.at(i))
        {
            for (int j = 0; j < W; j++)
            {
                if(hasHorizontalBlack.at(j)) {
                    cout << blocks.at(i).at(j);
                }
            }
        cout << endl;
        }
    }

}

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

██╗    ██╗██████╗ ██╗████████╗████████╗███████╗███╗   ██╗    ██████╗ ██╗   ██╗
██║    ██║██╔══██╗██║╚══██╔══╝╚══██╔══╝██╔════╝████╗  ██║    ██╔══██╗╚██╗ ██╔╝
██║ █╗ ██║██████╔╝██║   ██║      ██║   █████╗  ██╔██╗ ██║    ██████╔╝ ╚████╔╝
██║███╗██║██╔══██╗██║   ██║      ██║   ██╔══╝  ██║╚██╗██║    ██╔══██╗  ╚██╔╝
╚███╔███╔╝██║  ██║██║   ██║      ██║   ███████╗██║ ╚████║    ██████╔╝   ██║
 ╚══╝╚══╝ ╚═╝  ╚═╝╚═╝   ╚═╝      ╚═╝   ╚══════╝╚═╝  ╚═══╝    ╚═════╝    ╚═╝

     ███╗   ███╗   ██╗██████╗ ██████╗  █████╗ ██╗  ██╗██╗███╗   ███╗
     ████╗ ████║   ██║██╔══██╗██╔══██╗██╔══██╗██║  ██║██║████╗ ████║
     ██╔████╔██║   ██║██████╔╝██████╔╝███████║███████║██║██╔████╔██║
     ██║╚██╔╝██║   ██║██╔══██╗██╔══██╗██╔══██║██╔══██║██║██║╚██╔╝██║
     ██║ ╚═╝ ██║██╗██║██████╔╝██║  ██║██║  ██║██║  ██║██║██║ ╚═╝ ██║
     ╚═╝     ╚═╝╚═╝╚═╝╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝╚═╝     ╚═╝
*/
#define speed  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(n) for(int i=0;i<n;i++)
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define E "\n"
#define all(e) e.begin(),e.end()
#define F first
#define S second
#define pi (acos(-1))
#define rad(x) ((x*pi)/(ld)(180))
#define perc(x) fixed<<setprecision(x)
/*****
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define rot(p,angle) (p)*polar((double)(1),angle)
#define rot2(p,angle,a) ((p)-(a)) *(polar((ld)(1),angle)+ (a))
#define x real()
#define y imag()
*****/
typedef long long int ll; typedef unsigned long long ull; typedef long double ld;typedef complex<ld> point; typedef tuple<double,double,double> line;
ll gcd(ll x,ll y){if(!y)return x; return gcd(y,x%y);};   ll lcm(ll x,ll y){return (x*y)/__gcd(x,y);}

const int N=3e3+5;
ld dp[N][N],arr[N];

/*
ll solve(int i,int j)
{
    if(dp[i][j]!=-1 and i!=0)return dp[i][j];
    if(i==n)return 0;

    ll &ret = dp[i][j];

    if(j!=0)
    ret = max(ret,solve(i+1,0)+arr[i][0]);
    if(j!=1)
    ret = max(ret,solve(i+1,1)+arr[i][1]);
    if(j!=2)
    ret = max(ret,solve(i+1,2)+arr[i][2]);

    return ret;
}*/

int main(){ speed;
memset(dp,0,sizeof dp);

int n; cin>>n;

FOR(n)cin>>arr[i];

dp[0][0]=1-arr[0];
dp[0][1]=arr[0];

for(int i=1;i<n;i++)
{
    for(int j=0;j<=n;j++)
    {
        if(j<=i+1)
        {
            dp[i][j] =(dp[i-1][j]*(1 -arr[i]));

            if(j)
                 dp[i][j] += (dp[i-1][j-1]*(arr[i]));
        }
        else dp[i][j] = 0.0;
    }
}

ld ans = 0.0;
for(int i=(n+1)/2;i<=n;i++)ans+=dp[n-1][i];
cout<<perc(12)<<ans;
return 0;}


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define JD



int main(int argv, char* argc[])
{
    FASTIO

    #ifndef JD
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif

    ll n,m,k,mx=0;
    cin>>n>>m>>k;
    vll a(n+1),b(m);
    for(ll i=1;i<=n;++i)
    {
        cin>>a[i];
        a[i]+=a[i-1];
    }
    for(ll i=0;i<m;++i)
    {
        cin>>b[i];
        if(i)
        b[i]+=b[i-1];
    }

    for(ll i=0;i<=n;++i)
    {
        if(a[i]>k) break;
        ll d = upper_bound(all(b),k-a[i])-b.begin();
        chmax(mx,i+d);
    }
    cout<<mx<<"\n";


    return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;

	int counter = 0;

	string s = to_string(n);

	for(int i = 0; i < 4; ++i){
		if(s[i] == '2') ++counter;
		else continue;
	}

	cout << counter << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};//0 right 1 up 2left 3 down
bool map[2005][2005];
int dir[2005][2005][4];
int h,w,ans=0,tot;
int check(const int &x,const int &y,const int &d){
	if(dir[x][y][d]!=0)	return dir[x][y][d];
	if(map[x][y]||x>h||x<1||y>w||y<1)	return 0;
	return dir[x][y][d]=1+check(x+dx[d],y+dy[d],d);
}
int main(){
	scanf("%d %d ",&h,&w);
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++)
			if(getchar()=='#')	map[i][j]=true;
		getchar();
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(!map[i][j]){
				tot=1;
				for(int d=0;d<4;d++)	tot+=check(i+dx[d],j+dy[d],d);
				if(tot>ans)	ans=tot;
			}
		}
	}
	printf("%d",ans);
	return 0;
}

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

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double eps = 1e-7;
#define Loop(i, n) for(int i = 0; i < int(n); i++)
#define Loopll(i, n) for(ll i = 0; i < ll(n); i++)
#define Loop1(i, n) for(int i = 1; i <= int(n); i++)
#define Loopll1(i, n) for(ll i = 1; i <= ll(n); i++)
#define Loopr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = ll(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = int(n); i >= 1; i--)
#define Looprll1(i, n) for(ll i = ll(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
#define INF INFINITY
bool feq(double x, double y) { return abs(x - y) <= eps; }
bool inrange(ll x, ll t) { return x >= 0 && x < t; }
bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
int ceillog2(ll x) { int ret = 0;	x--; while (x > 0) { ret++; x >>= 1; } return ret; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

/*******************************************************/

int main() {
	int n; cin >> n;
	ll x; cin >> x;
	vll l(n); Loop(i, n) cin >> l[i];
	int cnt = 0;
	ll cur = 0;
	Loop(i, n) {
		cur += l[i];
		if (cur <= x) cnt++;
	}
	cout << cnt + 1 << endl;
}

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

typedef long long ll;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int oo = 0x3f3f3f3f;
 
template<typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48; 
    return x *= f;
}

const int N = 300;

int A, B;
int d[N + 5][N + 5], f[N + 5][N + 5];

int n = 202, m;
struct edge { int u, v, w; } e[N * N + 5];

bool chk() {
    for(int x = 1; x <= A; ++ x) 
        for(int y = 1; y <= B; ++ y) {
            int mn = oo;
            for(int a = 0; a <= 100; ++ a) 
                for(int b = 0; b <= 100; ++ b) if(f[a][b] >= 0) 
                    chkmin(mn, f[a][b] + a*x + b*y);

            if(mn != d[x][y]) return false;
        }
    return true;
}
int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif 

    read(A), read(B);
    for(int i = 1; i <= A; ++i) 
        for(int j = 1; j <= B; ++j) read(d[i][j]);

    memset(f, ~oo, sizeof f);
    for(int a = 0; a <= 100; ++ a) 
        for(int b = 0; b <= 100; ++ b) {
            for(int x = 1; x <= A; ++ x) 
                for(int y = 1; y <= B; ++y) {
                    chkmax(f[a][b], d[x][y] - a * x - b * y);
                }

            // if(f[a][b] >= 0) debug("%d %d %d \n", a, b, f[a][b]);
        }

    if(!chk()) return !puts("Impossible");

    puts("Possible");

    for(int a = 0; a <= 100; ++ a) 
        for(int b = 0; b <= 100; ++ b) {
            if(f[a][b] >= 0) e[++ m] = (edge) { a + 1, n - b, f[a][b] };
        }
    for(int a = 2; a <= 101; ++ a) e[++ m] = (edge) { a-1, a, -1 };
    for(int b = n-99; b<= n; ++ b) e[++ m] = (edge) { b-1, b, -2 };

    printf("%d %d\n", n, m);
    for(int i = 1; i <= m; ++i) {
        printf("%d %d ", e[i].u, e[i].v);

        if(e[i].w >= 0) printf("%d\n", e[i].w);
        else {
            puts(e[i].w == -1 ? "X" : "Y");
        }
    }
    printf("%d %d\n", 1, n);

    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



signed main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;
	VI X(N);
	vector<VI> modX(M);
	REP(i, N) cin >> X[i];
	SORT(X);
	REP(i, N) modX[X[i] % M].push_back(X[i]);

	int ans = 0;
	eREP(i, M/2) {
		if ((i + i) % M == 0) {
			ans += modX[i].size() / 2;
			continue;
		}
		int s = modX[i].size(), t = modX[M - i].size();
		ans += min(s, t);

		if (s < t) {
			int a = 0;
			while (t - 2 >= s&& a < modX[M - i].size() - 1) {
				if (modX[M - i][a] == modX[M - i][a + 1]) {
					ans++;
					t -= 2;
					a++;
				}
				a++;
				if (t - 2 < s || a >= modX[M - i].size() - 1) break;
			}		
		}
		else{
			int a = 0;
			while (s - 2 >= t && a < modX[i].size() - 1) {
				if (modX[i][a] == modX[i][a + 1]) {
					ans++;
					s -= 2;
					a++;
				}
				a++;
				if (s - 2 < t || a >= modX[i].size() - 1) break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define M 200007
using namespace std;
int n,a[M],b[M],p[M],l;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	b[n]=a[n];
	for(int i=n-1;i>=1;i--){
		int p=2,q=i,w=0;
		while(p*q<=n){
			w+=b[q*p],p++;
		}
		w%=2;
		b[i]=(a[i]-w+2)%2;
	}
	for(int i=1;i<=n;i++)if(b[i])p[++l]=i;
	cout<<l<<endl;
	for(int i=1;i<=l;i++)
		cout<<p[i]<<" ";
	return 0;
}

Measured memory_bytes: 2944
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

template <typename Tlist, typename Tfunc>
void __combination(
    Tlist const& list, typename Tlist::size_type const n, Tfunc const& func,
    Tlist& tmp, typename Tlist::size_type const i, typename Tlist::size_type const j)
{
    if (i == n)
    {
        func(tmp);
        return;
    }

    for (typename Tlist::size_type k = j; k != list.size() + (1 + i- n); ++k)
    {
        tmp[i] = list[k];
        __combination(list, n, func, tmp, i + 1, k + 1);
    }
}

template <typename Tlist, typename Tfunc>
void combination(
    Tlist const& list, typename Tlist::size_type const n, Tfunc const& func)
{
    Tlist tmp(n);
    __combination(list, n, func, tmp, 0, 0);
}


int main()
{
    uint64_t N;
    std::cin >> N;

    std::vector<uint64_t> inis(5);
    for (size_t i = 0; i < N; ++i) {
        std::string s;
        std::cin >> s;
        char c = s[0];
        switch (c) {
        case 'M':
            inis[0]++;
            break;
        case 'A':
            inis[1]++;
            break;
        case 'R':
            inis[2]++;
            break;
        case 'C':
            inis[3]++;
            break;
        case 'H':
            inis[4]++;
            break;
        default:
            break;
        }
    }
    uint64_t sum = 0;
    combination(inis, 3, [&sum](auto& v) {
            sum += std::accumulate(std::begin(v), std::end(v), 1ULL, [](auto acc, auto nn) {
                    return acc*nn;
                });
        });
    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            for (int i = 0; i < n + 2; ++i) {
                if (i == 0 || i == n + 1) {
                    StringBuilder sb = new StringBuilder();
                    for (int j = 0; j < m + 2; ++j) sb.append("#");
                    out.println(sb.toString());
                } else {
                    out.println("#" + in.next() + "#");
                }
            }
        }

    }

    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());
        }

    }
}



Measured memory_bytes: 21460
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    s = set(IS())
    t = 'abcdefghijklmnopqrstuvwxyz'
    for ti in t:
        if not ti in s:
            print(ti)
            return None
    print('None')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  rep(i, 6) {
    if (s[i] == '1') ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  endl           "\n"
#define  pb             push_back
#define  sym(s)         s="#"+s+"#";
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());

typedef  long long             ll;
typedef  unsigned long long    ull;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   N  =  3e+5+7;

vll adj[N];ll vis[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n;string s;
map<char,ll>map1;
//<<-----Implement Functions Here---->>//


//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n>>s;ll ans = 0;ll count1 = 0;
		for(ll i=0;i<n;i++)map1[s[i]]++;
		for(ll i=0;i<map1['R'];i++)if(s[i]=='W')count1++;
		cout<<min({map1['R'],map1['W'],count1});
}

int main(){
    fastio;randomINIT;

    //cin>>t;
    while(t--){
        MAIN();
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}

Measured memory_bytes: 10724
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <functional>

using namespace std;

int INF = 10000000;

int n;



int cast(int y,int m,int d)
{
	int sum = 0;

	for(int i = 999;i > 0;i--)
	{
		for(int j = 10;j > 0;j--)
		{
			for(int k = j%2 || i % 3 == 0 ? 20 : 19 ;k > 0;k--)
			{
				sum++;
				if(i == y && j == m && d == k)
				{
					return sum;
				}
			}
		}
	}


}


int main()
{
	cin >> n;

	for(int i = 0;i < n;i++)
	{

		int y,m,d;

		cin >> y >> m >> d;


		cout << cast(y,m,d) << endl;

	}

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(){
    int i,j,l,r,Q;
    vector<bool> issosu(100100,true),islike2017(100100,false);
    issosu[0] = false;
    issosu[1] = false;
    for(i = 2;i < 100099;i++){
        if(issosu[i]){
            if(issosu[(i + 1) / 2]){
                islike2017[i] = true;
            }
            for(j = i * 2;j < 100099;j += i){
                issosu[j] = false;
            }
        }
    }
    vector<int> ruisekiwa(100101,-1);
    for (i = 0; i < 100099; i++){
        if (islike2017[i]){
            ruisekiwa[i] = ruisekiwa[i - 1] + 1;
        }
        else{
            ruisekiwa[i] = ruisekiwa[i - 1];
        }
    }
    cin >> Q;
    for(i = 0;i < Q;i++){
        cin >> l >> r;
        cout << ruisekiwa[r] - ruisekiwa[l - 1] << endl;
    }
}

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


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}


int main()
{
	fastio;
	ll i,j,k,n,a[200010];
	cin>>k>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	ll ma=-1e9;
	for(i=0;i<n-1;i++)
		ma=max(ma,a[i+1]-a[i]);
	ma=max(ma,a[0]+k-a[n-1]);
	cout<<k-ma<<endl;
    return 0;
}





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

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n, m;
  while(cin >> n >> m) {
    if(!n) return 0;
    char a[100] = {};
    rep(j, 0, m) {
      char b;
      cin >> b;
      if(b == 'A') {
        rep(i, 0, n) {
          if(!a[i]) {
            a[i] = b;
            break;
          }
        }
      }else if(b == 'B') {
        int f = 0;
        dep(i, n - 1, 0) {
          if(a[i]) continue;
          int ff = 1;
          if(i + 1 < n && a[i + 1] == 'A') ff = 0;
          if(i - 1 > 0 && a[i - 1] == 'A') ff = 0;
          if(ff) {
            a[i] = b;
            f = 1;
            break;
          }
        }
        if(!f) {
          rep(i, 0, n) {
            if(!a[i]) {
              a[i] = b;
              break;
            }
          }
        }
      }else if(b == 'C') {
        int f = 0;
        rep(i, 0, n - 1) {
          if(!a[i]) continue;
          if(i + 1 < n && !a[i + 1]) {
            a[i + 1] = b;
            f = 1;
            break;
          }else if(i - 1 >= 0 && !a[i - 1]) {
            a[i - 1] = b;
            f = 1;
            break;
          }
        }
        if(!f) {
          if(n % 2) a[(n + 1) / 2 - 1] = b;
          else a[n / 2] = b;
        }
      }else {
        int mm = 0, re = 0, an;
        rep(i, 0, n) {
          if(!a[i]) re++;
          else break;
        }
        if(re > 0) {
          an = 0;
          mm = re - 1;
        }
        re = 0;
        dep(i, n - 1, 0) {
          if(!a[i]) re++;
          else break;
        }
        if(mm < re - 1) {
          an = n - 1;
          mm = re - 1;
        }
        re = 0;
        rep(i, 1, n - 1) {
          if(a[i]) continue;
          int l = 0, r = 0;
          dep(k, i - 1, 0) {
            if(!a[k]) l++;
            else break;
          }
          rep(k, i + 1, n) {
            if(!a[k]) r++;
            else break;
          }
          if(mm < min(l, r)) {
            an = i;
            mm = min(l, r);
          }
        }
        if(mm) a[an] = b;
        else {
          rep(i, 0, n) {
            if(!a[i]) {
              a[i] = b;
              break;
            }
          }
        }
      }
    }
    rep(i, 0, n) {
      if(a[i] == 'A' || a[i] == 'B' || a[i] == 'C' || a[i] == 'D') {
        cout << a[i];
      }else cout << '#';
    }
    cout << endl;
  }

}

Measured memory_bytes: 3116
n,m = map(int,input().split())
mod = 10**9+7

x = sorted(list(map(int,input().split())))
y = sorted(list(map(int,input().split())))

X = 0
for i in range(n-1):
    X += (i+1)*(n-i-1)*(x[i+1]-x[i])%mod
    X %= mod

Y = 0
for i in range(m-1):
    Y += (i+1)*(m-i-1)*(y[i+1]-y[i])%mod
    Y %= mod

print(X*Y%mod)

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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = 2147483647;
constexpr ll L_INF = 9223372036854775807LL;

//===




int main()
{
	int N;
	cin >> N;
	Vi D(N);
	for (int i = 0; i < N; ++i) {
		cin >> D[i];
	}

	sort(D.begin(), D.end());

	Vi time(N + 1);
	for (int i = 0; i < N; ++i) {
		if (i % 2 == 0) {
			time[i + 1] = D[i];
		}
		else {
			time[i + 1] = -D[i];
		}
	}

	int ans = I_INF;
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N + 1; ++j) {
			int diff = abs(time[i] - time[j]);
			diff = min(diff, 24 - diff);
			ans = min(ans, diff);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256