akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

int main(void)
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int minimum = max(A, C);
    int maximum = min(B, D);
    int ans = maximum - minimum;
    if (ans < 0)
    {
        ans = 0;
    }
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var m, n int
	fmt.Scan(&m, &n)
	lmax, rmin := 0, math.MaxInt32
	for i := 0; i < n; i++ {
		var l, r int
		fmt.Scan(&l, &r)
		if l > lmax {
			lmax = l
		}
		if r < rmin {
			rmin = r
		}
	}
	if lmax <= rmin{
		fmt.Println(rmin - lmax + 1)
	} else {
		fmt.Println(0)
	}
}

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

#define int long long

const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

int N, x[200], y[200];

signed main()
{
    while (cin >> N, N)
    {
        int maxX = 0, minX = 0, maxY = 0, minY = 0;
        for (int i = 1; i < N; i++)
        {
            int n, d;
            cin >> n >> d;
            x[i] = x[n] + dx[d];
            y[i] = y[n] + dy[d];
            maxX = max(maxX, x[i]);
            minX = min(minX, x[i]);
            maxY = max(maxY, y[i]);
            minY = min(minY, y[i]);
        }
        printf("%lld %lld\n", maxX - minX + 1, maxY - minY + 1);
    }
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;

int main()
{
	int k,x;
	cin >> k >> x;
	for (int i = x-(k-1); i <= x+(k-1); ++i)
	{
		if (i != x-(k-1))
		{
			cout << " ";
		}
		cout << i;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
using namespace std;
int main() {
  int a,b; scanf("%d%d",&a,&b); int cnt = 0;
  for(int x=2;x<=9;x++)
    for(int y=2;y<=9;y++) if(x * y <= a && x * 10 + y <= b) cnt++; printf("%d",cnt);
}


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

Int gcd(Int a, Int b) {
  return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
  return a * b / gcd(a, b);
}
// a x + b y = gcd(a, b)
Int extgcd(Int a, Int b, Int &x, Int &y) {
  Int g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

Int invMod(Int a, Int m) {
  Int x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;
  else                         return 0; // unsolvable
}

ll mod = 998244353;
#define SIZE 300000
ll inv[SIZE + 1];
ll kai[SIZE + 1];
ll invkai[SIZE + 1];
void invinit()
{
	inv[1] = 1;
	for (int i = 2; i <= SIZE; i++)
	{
		inv[i] = mod - (mod / i)*inv[mod%i] % mod;
	}
	kai[0] = invkai[0] = 1;
	for (int i = 1; i <= SIZE; i++)
	{
		kai[i] = kai[i - 1] * i%mod;
		invkai[i] = invkai[i - 1] * inv[i] % mod;
	}
}
ll com(ll a, ll b)
{
	if (b < 0 || a < b)return 0;
	return (invkai[b] * invkai[a - b]) % mod*kai[a] % mod;
}

signed main(){
  Int n,a,b,k,x,y;
  cin >> n >> a >> b >> k;

  invinit();
  Int g = gcd(a,b);
  a/=g; b/=g;
  if(k%g != 0) {
  cout << 0 << endl;
  return 0;  
  }else{
    k/=g;
  }


  extgcd(a,b,x,y);
  if(x < 0) {
    x += b; y-= a;
  }

  x*=(k%b); y*=(k%b); y+=k/b;
  {Int c = x/b;
  x -= c*b; y+= c*a;}

  ll ans = 0;
  while (x <= n && y >= 0) {
/*    cout << x << endl;
    cout << y << endl;
*/    ans = (ans + com(n,x)*com(n,y)%mod) % mod;

    x += b;
    y -= a;

  }

  cout << ans << endl;



}











Measured memory_bytes: 7296
#include <stdio.h>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, a, b, ta, he = 0;
  scanf("%lld%lld%lld", &n, &a, &b);
  vector<ll> h(n);
  vector<ll>::iterator it;
  for(i = 0; i < n; ++i) scanf("%lld", &h[i]);
  sort(h.begin(), h.end());
  ta = h[n - 1] / b + 2;
  while(ta != he + 1) {
    ll tmp = (ta + he) / 2, cnt = 0;
    it = upper_bound(h.begin(), h.end(), tmp * b);
    for(; it != h.end(); ++it)  cnt += (*it - (b * tmp) + a - b - 1) / (a - b);
    if(cnt <= tmp) ta = tmp;
    else he = tmp;
  }
  printf("%lld", ta);
  return 0;
}

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

using namespace std;
typedef long long ll;


int main(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
    ll sum = 0 ;
    int tot = 0;
    for(int i=a;i>=1;i--){
    	sum += 1;
    	tot++;
    	if(tot==d){
    		cout<<sum<<endl;
    		return 0;
		}
	}
    for(int i=b;i>=1;i--){
    	tot++;
    	if(tot==d){
    		cout<<sum<<endl;
    		return 0;
		}
	}
	for(int i=c;i>=1;i--){
    	sum -= 1;
    	tot++;
    	if(tot==d){
    		cout<<sum<<endl;
    		return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=205;
ll a[N],b[65];
char s[N];
int n;

void rmain(){
	read(n);
	rep(i,1,n) read(a[i]);
	scanf("%s",s+1);
	memset(b,0,sizeof b);
	per(i,n,1){
		ll x=a[i];
		if(s[i]=='1'){
			per(j,60,0){
				if(x>>j&1){
					x^=b[j];
				}
			}
			if(x){
				puts("1");
				return;
			}
		}
		else{
			per(j,60,0){
				if(x>>j&1){
					if(b[j]){
						x^=b[j];
					}
					else{
						b[j]=x;
						break;
					}
				}
			}
		}
	}
	puts("0");
}

int main(){
	int T; read(T);
	while(T--) rmain();
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int L;
  cin >> L;
  cout << fixed << setprecision(12) << L*L*L / 27.0 << endl;
  return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    //identify a prime number
    int mm=100005;
    vector<int> is_prime(mm,1);
    is_prime[0]=0;
    is_prime[1]=0;
    for(int i=2;i*i<mm;++i){
        if(!is_prime[i])continue;
        for(int j=i*2;j<mm;j+=i)is_prime[j]=0;
    }
    //identify a number like 2017
    vector<int> like_2017(mm,0);
    rep(i,mm){
        if(is_prime[i]&&is_prime[(i+1)/2])like_2017[i]=1;
    }
    //get the cumulative sum
    vector<int> csum(mm,0);
    csum[0]=0;
    rep(i,mm){
        csum[i+1]=csum[i]+like_2017[i];
    }

    int q;
    cin>>q;
    vector<int> l(q),r(q);
    rep(i,q){
        cin>>l[i]>>r[i];
    }
    rep(i,q){
        cout<<csum[r[i]+1]-csum[l[i]]<<endl;
    }




}

Measured memory_bytes: 5072
n = int(input())
ans = 0
a = input()
b = input()
c = input()
for i in range(n):
  if a[i] == b[i] == c[i]:
    pass
  elif a[i] == b[i] or a[i] == c[i] or b[i] == c[i]:
    ans += 1
  else:
    ans += 2
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int b[100];
int index[100];
bool used[100];
vector<int> ans;

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) { cin >> b[i]; b[i]--; index[i] = i; }
	
	rep(i, n) { if (b[i] > i) { cout << -1 << endl; return 0; } }
	
	rep(i, n) {
		for (j = n - 1; j > 0; j--) {
			if (used[j]) continue;
			if (b[j] == index[j]) break;
		}
		ans.push_back(index[j]);
		used[j] = true;
		int p = j;
		for (j = p + 1; j < n; j++) index[j]--;
	}
	
	for (i = n - 1; i >= 0; i--) cout << ans[i] + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::f64;
use std::f64::consts::PI;
fn main(){

    input!{
        a: f64,
        b: f64,
        h: f64,
        m: f64,
    }

    let jisin = 2.0*PI/12.0*h+2.0*PI/12.0*m/60.0; 
    let theta = (jisin-2.0*PI/60.0*m).abs();
    let c: f64 = (a.powi(2)+b.powi(2)-2.0*a*b*theta.cos()).sqrt();

    println!("{}", c);

}

Measured memory_bytes: 3040
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;
vector<ll>A;
void PushBack(ll a) {
	A.push_back(a);
}
void RandomAccess(ll a) {
	cout << A.at(a) << endl;
}
void PopBack() {
	A.pop_back();
}
int main() {
	ll Q; cin >> Q;
	ll N, a;
	for (ll i = 0; i < Q; i++) {
		cin >> N;
		if (N == 0) {
			cin >> a;
			PushBack(a);
		}
		else if (N == 1) {
			cin >> a;
			RandomAccess(a);
		}
		else {
			PopBack();
		}
	}
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    int n; cin >> n;
    int A[n+2] , dp[n+1];
    for(int i = 1 ;i <= n; i++){
        cin >> A[i];
        dp[i] = Mod;
    }
    dp[1]  = 0;
    for(int i = 1;i <= n; i++){
        int nxt = min(i+1 , n);
        int nxxt = min(i+2 , n);
        dp[nxt] = min(dp[nxt] , dp[i] + abs(A[nxt] - A[i]));
        dp[nxxt] = min(dp[nxxt] , dp[i] + abs(A[nxxt] - A[i]));
    }
    cout << dp[n] << endl;
    return 0;
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int N;
    cin >> N;

    vector<ll> A(N), B(N), C(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    for (int i = 0; i < N-1; i++) {
        cin >> C[i];
    }

    ll ans = B[A[0]];
    for (int i = 1; i < N; i++) {
        ans += B[A[i]];
        if (A[i] - A[i-1] == 1) {
            ans += C[A[i-1]];
        }
        // cout << i << " " << ans << endl;
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
import sys

def insert_sort(array):
    for i in range(0, len(array)):
        v = array[i]
        j = i - 1
        while (j >= 0) and (array[j] > v):
            array[j + 1] = array[j]
            j -= 1
        array[j + 1] = v
        print print_list(array)
    return array

def print_list(array):
    s = ""
    for n in array:
        s += str(n) + " "
    s = s.strip()
    return s
    
if __name__ == "__main__":
    array_num = int(sys.stdin.readline().strip())
    array = map(lambda x: int(x), list(sys.stdin.readline().strip().split(" ")))
    array = insert_sort(array)

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    int go(int a, const vector<string> &G) {
        set<int> fronts = {a};
        set<int> prev_fronts = {};
        vector<int> used(G.size(), 0);
        used[a] = true;
        int used_cnt = 1;
        int k = 1;
        while(true) {
            set<int> next_fronts;
            for(int now : fronts) {
                rep(i, G.size()) {
                    if(G[now][i] == '1') {
                        if(used[i]) {
                            if(not prev_fronts.count(i) and not next_fronts.count(i)) {
                                return -1;
                            }
                        } else {
                            next_fronts.insert(i);
                            used[i] = true;
                            used_cnt++;
                        }
                    }
                }
            }
            if(next_fronts.size() == 0) break;
            prev_fronts = fronts;
            fronts = next_fronts;
            k++;
        }
        //cerr << a << ": " << k << endl;
        return k;
    }
    bool solve() {
        int N; cin >> N;
        vector<string> S(N); cin >> S;
        int ans = -1;
        rep(i, N) set_max(ans, go(i, S));
        cout << ans << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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


    int3(k, a, b);
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;

    return 0;
}


Measured memory_bytes: 3652
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----
local function create_ndim_array(n, last_metatbl)
    local metatables = {}
    metatables[1] = last_metatbl
    for i=2,n do
        metatables[i] = {__index = function(parent, k)
            local child = setmetatable({}, metatables[i-1])
            rawset(parent, k, child)
            return child
        end}
    end
    return setmetatable({}, metatables[n])
end
local function carprod(seqs)
    return coroutine.wrap(function()
        if #seqs == 0 then
            coroutine.yield({})
            return
        end
        local s1 = seqs[1]
        for _,v in ipairs(s1) do
            for t in carprod({select(2, table.unpack(seqs))}) do
                coroutine.yield({v, table.unpack(t)})
            end
        end
    end)
end
-- E
local S = read.l():totable()
local T = {}
for i=1,#S do
    T[i] = tonumber(S[i])
end
local D = #T
local K = read.n()

local set = {{}, {false, true}, {}}
for i=1, D do
    set[1][i] = i
end
for i=0, K do
    table.insert(set[3], i)
end

local tbl = create_ndim_array(3, {__index = function() return 0 end})
tbl[0][true][0] = 1
for ss in carprod(set) do
    local ni, nm, nk = table.unpack(ss)
    for d=0,9 do
        local nd = T[ni]
        if nm then
            local source = tbl[ni-1][true]
            if d == nd then
                if d == 0 then
                    tbl[ni][nm][nk] = tbl[ni][nm][nk] + source[nk]
                else
                    tbl[ni][nm][nk] = tbl[ni][nm][nk] + source[nk-1]
                end
            else
                -- can't let nm == true
            end
        else
            if d >= nd then
                local source = tbl[ni-1][false]
                if d == 0 then
                    tbl[ni][nm][nk] = tbl[ni][nm][nk] + source[nk]
                else
                    tbl[ni][nm][nk] = tbl[ni][nm][nk] + source[nk-1]
                end
            else -- d < nd
                local source1 = tbl[ni-1][true]
                local source2 = tbl[ni-1][false]
                if d == 0 then
                    tbl[ni][nm][nk] = tbl[ni][nm][nk] + source1[nk] + source2[nk]
                else
                    tbl[ni][nm][nk] = tbl[ni][nm][nk] + source1[nk-1] + source2[nk-1]
                end
            end
        end
    end
end
local ans = tbl[D][false][K] + tbl[D][true][K]
print(ans)

Measured memory_bytes: 880
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

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 maxn=1e5+1e2;
int n;
int a[maxn];

inline void file() {
	freopen("AGC016B.in","r",stdin);
	freopen("AGC016B.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

int main() {
//	file();
	n=read();
	int cnt=0,Max=0;
	For (i,1,n) a[i]=read(),chkmax(Max,a[i]);
	For (i,1,n) {
		if (a[i]!=Max) ++cnt;
		if (Max!=a[i]+1 && Max!=a[i]) {
			puts("No"); return 0;
		}
	}
	if (Max==n-1 && cnt==0) { puts("Yes"); return 0; }
	if (cnt+1>Max) { puts("No"); return 0; }
	if (n-cnt<(Max-cnt)*2) { puts("No"); return 0; }
	puts("Yes");
	return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var (
		a, b int
	)
	fmt.Scan(&a, &b)
	if a < b {
		fmt.Print(pras(b, a))
	} else {
		fmt.Print(pras(a, b))
	}
}

func pras(j, p int) string {
	var t string
	for i := 0; i < j; i++ {
		t += strconv.Itoa(p)
	}
	return t
}


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

using namespace std;
int dp[105][105];
int main()
{
    int n;
    scanf("%d",&n);
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=2;i++)
        for(int j=1;j<=n;j++)
        scanf("%d",&dp[i][j]);
    for(int i=n;i>=1;i--)
        for(int j=n;j>=1;j--)
        {
           dp[i][j]=dp[i][j]+max(dp[i+1][j],dp[i][j+1]);
        }

       printf("%d\n",dp[1][1]);
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
  double n, k;
  cin >> n >> k;
  double ans = 0;
  for (int i = 1; i <= n; i++)
    ans += pow(0.5, ceil(log2(ceil(k/i)))) / n;
  printf("%.12f\n", ans);
  return 0;
}

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

// 素集合データ構造
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<long> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<long> sizes;

  UnionFind(long n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    rep(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  long find(long x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(long x, long y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

     // xの木がyの木より大きくなるようにする
     if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(long x, long y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  long size(long x) {
    return sizes[find(x)];
  }
};
int main() {long N; long M;
cin >> N >> M;
vector<long> a(M); vector<long> b(M);
rep(i, M) cin >> a.at(i) >> b.at(i);

long ans = 0;
rep(i, M){
    UnionFind uf(N + 1);
    rep(j, i) uf.unite(a.at(j), b.at(j));
    for(long j = i + 1; j < M; j++) uf.unite(a.at(j), b.at(j));
    if(uf.size(a.at(i)) != N || uf.size(b.at(i)) != N) ans++;
}


// UnionFind uf(N);
// uf.unite(0, 1);
// uf.unite(2, 0);
// long test = uf.find(0);
cout << ans << endl;
// cout << uf.size(2) << endl;

  return 0;
 
}

Measured memory_bytes: 256
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>> 
ld pie=3.141592653589793238462643383279;
int mod=1e9+7;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};


int dig(int a){
  int r=0;
  while(a!=0){
    int xp=a%10;
    a/=10; if(xp==1) ++r;
  }
  return r;
}

int fact[2000005];
int infact[2000005];

int inv(int a){
  int y=mod-2;
  int r=1;
  while(y!=0){
    if(y&1){
      r*=a; r%=mod;
    }
    y/=2; a*=a; a%=mod;
  }
  return r;
}

int po(int a,int y){
  int r=1;
  while(y!=0){
    if(y&1){
      r*=a; r%=mod;
    }
    y/=2; a*=a; a%=mod;
  }
  return r; 
}

void facto(){
  fact[0]=1;
  f(i,1,2000005) {fact[i]=i*fact[i-1]; fact[i]%=mod;}
  f(i,0,2000005) infact[i]=inv(fact[i]); 
}

int nck (int n,int k){
  if(k<0 || k>n) return 0;
  int ret=fact[n]; ret*=infact[k]; ret%=mod;
  ret*=infact[n-k]; ret%=mod;
  return ret;
}
void q1(){
  string s; cin>>s;
  if(s>="a" && s<="z") cout<<"a";
  else cout<<"A";
}
void q2(){
  int n,k; cin>>n>>k;
  int a[n]; f(i,0,n) cin>>a[i];
  sort(a,a+n);
  int s=0;
  f(i,0,k)s+=a[i];
  cout<<s;
}
void q3(){
  string ret="";
  int a; cin>>a;
  while(a!=0){
    a--;
    ret+=(a%26 +'a');
    a/=26;
  }
  reverse(ret.begin(),ret.end());
  cout<<ret;
}
void q4(){
  int n; cin>>n;
   int a[100005]={0};
   int s=0;
  f(i,0,n){
    int x; cin>>x;
    s+=x;
    a[x]++;
  }
  int q; cin>>q;
  while(q--){
    int b,c; cin>>b>>c;
    s-=a[b]*b;
    s+=a[b]*c;
    a[c]+=a[b];
    a[b]=0;
    cout<<s<<"\n";
  }
 
}
void q5(){
  int n; cin>>n;
  int x=0;
  int a[n]; f(i,0,n){
    cin>>a[i];
    x^=a[i];
  } 
   f(i,0,n) cout<<(x^a[i])<<" ";
}
int32_t main(){
#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  q2();
  return 0;
  facto();
  int k; cin>>k;
  string s; cin>>s;
  int l=k+s.size();
  int xp=s.size();
  // total = 26^l - those which do not contain subsequence
  // --- i= 0 to  xp-1 prefix present as subseqeunce and remaining have 25^(l-i)
  int ret=1;
  f(i,0,l){
    ret*=26; ret%=mod;
  }
  int sub=0;

  f(i,0,xp){
    // l choose i
    sub+= (nck(l,i)*po(25,l-i));
    sub%=mod; 
  }

  cout<<((ret-sub)%mod + mod) %mod <<"\n";
  return 0;
}


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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }

inline void proc_status()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) <<endl;
}

template <typename T> T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

const int Maxn = 1e5 + 100, Maxk = 100 + 10;

int N, K, A[Maxn], Dp[Maxn];

inline void Solve ()
{
	memset(Dp, 0x3f, sizeof Dp);
	Dp[1] = 0;
	for (int i = 1; i <= N; ++i)
	{
		for (int j = 1; j <= K; ++j)
			Chkmin(Dp[i + j], Dp[i] + abs(A[i + j] - A[i]));
	}
	cout<<Dp[N]<<endl;
}

inline void Input ()
{
	N = read<int>(), K = 2;
	for (int i = 1; i <= N; ++i) A[i] = read<int>();
}

int main()
{
#ifdef hk_cnyali
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
#endif
	Input();
	Solve();
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){int list[10000];int i,j;for(i=2;i<10002;i++)list[i-2]=i;for(j=2;j*j<10003;j++){if(list[j-2]!=0){for(i=1;j-2+list[j-2]*i<10001;i++){list[j-2+list[j-2]*i]=0;}}}int N=0;while(scanf("%d",&N)!=EOF){j=0;for(i=2;i<N;i++)if((list[i-2]!=0)&&(list[N-i-1]!=0))j++;printf("%d\n",j);}return 0;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define cmax(a,b) (a<(b)?a=(b):a)
#define cmin(a,b) (a>(b)?a=(b):a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
using namespace std;
 
#define Pr(f,...) //printf(f,##__VA_ARGS__),fflush(stdout)
 
const int N=2005;
 
int n,m,q,a[N][N],b[N][N],c[N][N];
char s[N][N];
 
int sum(int a[N][N],int l,int u,int r,int d){
return a[d][r]-a[d][l-1]-a[u-1][r]+a[u-1][l-1];
}
 
int main(){
#ifdef CURIOUSCAT
freopen("dat.in","r",stdin);
#endif	
scanf("%d%d%d",&n,&m,&q);
rep(i,1,n){
scanf("%s",s[i]+1);
rep(j,1,m)a[i][j]=s[i][j]-'0';
}
rep(i,2,n)rep(j,1,m)b[i][j]=a[i][j]==a[i-1][j]&&a[i][j];
rep(i,1,n)rep(j,2,m)c[i][j]=a[i][j]==a[i][j-1]&&a[i][j];
rep(i,1,n)rep(j,2,m){
a[i][j]+=a[i][j-1];
b[i][j]+=b[i][j-1];
c[i][j]+=c[i][j-1];
}
rep(i,2,n)rep(j,1,m){
a[i][j]+=a[i-1][j];
b[i][j]+=b[i-1][j];
c[i][j]+=c[i-1][j];
}
while(q--){
int l,u,r,d;
cin>>u>>l>>d>>r;
int ans=sum(a,l,u,r,d);
ans-=sum(b,l,u+1,r,d);
ans-=sum(c,l+1,u,r,d);
printf("%d\n",ans);
}
 
return 0;
}

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

int main(){
  long long int a,b,c,d,e;
  d=0;
  cin>>a>>b>>c;
  e=a;
  a=max(a-c,d);
  c=max(c-e,d);
  b=max(b-c,d);
  cout<<a<<" "<<b;
}

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

int main() {
  int N, A;
  cin >> N >> A;
  
  int amari;
  amari = N % 500;
  
  if(amari <= A){
    cout << "Yes" << endl;
  }
  else{cout << "No" << endl;}
}

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

vector<int> solve(int N, int L, vector<int> lengths)
{
    auto last_move = -1;
    for (auto i = 0; i+1 < N; i++)
        if (lengths[i] + lengths[i+1] >= L)
            last_move = i;
    if (last_move == -1) return {};

    auto order = vector<int>();
    order.push_back(last_move);
    for (auto i = last_move+1; i < N-1; i++)
        order.push_back(i);
    for (auto i = last_move-1; i >= 0; i--)
        order.push_back(i);
    reverse(begin(order), end(order));
    return order;
}

int main()
{
    ios_base::sync_with_stdio(false);

    int N, L; cin >> N >> L;

    auto lengths = vector<int>(N);
    for (auto& x : lengths) cin >> x;

    auto answer = solve(N, L, lengths);
    if (answer.empty()) cout << "Impossible" << "\n";
    else
    {
        cout << "Possible" << "\n";
        for (auto x : answer)
            cout << x+1 << "\n";
    }
}


Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  vector<int> A(a);
  for(int i = 0;i<a;i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  int sum = 0;
  for(int i = 0;i<b;i++){
    sum += A.at(a-i-1);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute;
using FieldOffsetAttribute = System.Runtime.InteropServices.FieldOffsetAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        if (n == 1)
        {
            Console.WriteLine("POSSIBLE");
            return;
        }
        var p = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
        var X = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var childlen = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();
        for (int i = 0; i < p.Length; i++) childlen[p[i]].Add(i + 1);
        Stack<int> stack = new Stack<int>();
        stack.Push(0);
        List<int> order = new List<int>();
        while (stack.Count > 0)
        {
            int elem = stack.Pop();
            order.Add(elem);
            foreach (var child in childlen[elem]) stack.Push(child);
        }
        Tuple<int, int>[] bw = new Tuple<int, int>[n];
        foreach (var elem in order.Reverse<int>())
        {
            //Xまで詰めたい
            List<bool> knapsack = new bool[X[elem] + 1].ToList();
            knapsack[0] = true;
            int totalSum = 0;
            foreach (var child in childlen[elem])
            {
                totalSum += bw[child].Item1;
                totalSum += bw[child].Item2;
                for (int i = knapsack.Count - 1; i >= 0; i--)
                {
                    if (!knapsack[i]) continue;
                    knapsack[i] = false;
                    if (i + bw[child].Item1 < knapsack.Count) knapsack[i + bw[child].Item1] = true;
                    if (i + bw[child].Item2 < knapsack.Count) knapsack[i + bw[child].Item2] = true;
                }
            }
            var count = knapsack.LastIndexOf(true);
            if(count == -1)
            {
                Console.WriteLine("IMPOSSIBLE");
                return;
            }
            bw[elem] = new Tuple<int, int>(totalSum - count, X[elem]);
        }
        Console.WriteLine("POSSIBLE");
    }
}


Measured memory_bytes: 13536
#include<cstdio>
#include<cstring>
#define INF 0x3f3f3f

int max(int x,int y)
{
	return x>y?x:y;
 } 
 int min(int x,int y)
 {
 	return x<y?x:y;
 }
int d[110][110];
void floyd(int n)
{
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				d[i][j]=min(d[i][j],(d[i][k]+d[k][j]));
			}
		}
	}
}
void into(int n)
{
	memset(d,INF,sizeof(d));
	for(int i=0;i<n;i++)
		d[i][i]=0;
}
int main()
{
	int n,m;
	int a,b,k;
	while(~scanf("%d",&n),n)
	{
		into(12);
		m=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d%d%d",&a,&b,&k);
			d[a][b]=d[b][a]=k;
			m=max(max(a,b),m);
		}
		floyd(m+1);
		int minn=INF;
		int kase;
		for(int i=0;i<=m;i++)
		{
			int ans=0;
			for(int j=0;j<=m;j++)
			{
				ans+=d[i][j]; 
			}
			if(ans<minn)
			{
				minn=ans;
				kase=i;
			}
			
		}
		printf("%d %d\n",kase,minn);
	}
	return 0;
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  auto a = make_vector(3, 3, 0);
  int n;

  while(cin >> a >> n){
    auto c = make_vector<bool>(3, 3, false);
    REP(_,n){
      int b; cin >> b;
      REP(i,3){
        REP(j,3){
          if(a[i][j] == b) c[i][j] = true;
        }
      }
    }

    //dump(c);

    bool ans = false;

    REP(i,3){
      if(c[i][0] and c[i][1] and c[i][2]) ans = true;
      if(c[0][i] and c[1][i] and c[2][i]) ans = true;
    }

    if(c[0][0] and c[1][1] and c[2][2]) ans = true;
    if(c[2][0] and c[1][1] and c[0][2]) ans = true;


    puts_all(ans ? "Yes" : "No");
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

    int ans = 0;

    int x = (s[0] == 'W');

    REP(i,s.size()){
        int y = (s[i] == 'W');
        if (x == y) continue;
        ans++;
        x = y;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;

int main()
{
  int n;
  string s1, s2;
  int result1 = 0;
  int result2 = 0;
  
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    if (s1 > s2) result1 += 3;
    else if (s1 < s2) result2 += 3;
    else { result1++; result2++; }
  }
  cout << result1 << " " << result2 << endl;

  return 0;
}


Measured memory_bytes: 3192
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}


double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
inline T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
inline T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int x;
	scanf("%d", &x);
	printf("%d\n", 360 / gcd(360, x));

	Please AC;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	cout << fixed;
	double A, B, H, M;
	cin >> A >> B >> H >> M;
	double diff = (5.5 * (H * 60 + M)) * M_PI / 180;
	if(B < A) {
		double tmp = B;
		B = A;
		A = tmp;
	}
	cout << setprecision(12)
		 << sqrt((B - A * sin(M_PI / 2 - diff)) * (B - A * sin(M_PI / 2 - diff)) + A * A * cos(M_PI / 2 - diff) * cos(M_PI / 2 - diff))
		 << "\n";
	return 0;
}


Measured memory_bytes: 4148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void dfs(int i, int j, vector<vector<int>> &map){
    if(map.at(i).at(j)==0) return;
    map.at(i).at(j)=0;
    vector<int> x={-1,0,1,-1,1,-1,0,1},y={-1,-1,-1,0,0,1,1,1};
    rep(k,8){
        dfs(i+x.at(k),j+y.at(k),map);
    }
}

int main(){
    while(true){
        int w,h; cin>>w>>h;
        int res=0;
        if(w==0 && h==0) break;
        vector<vector<int>> map(h+2,vector<int>(w+2,0));
        rep(i,h){
            rep(j,w){
                cin>>map.at(i+1).at(j+1);
            }
        }
        rep(i,h+2){
            rep(j,w+2){
                if(map.at(i).at(j)==1){
                    dfs(i,j,map);
                    res++;
                }
            }
        }
        cout<<res<<endl;
    }
}


Measured memory_bytes: 3372
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <climits>
#include <math.h>
#include <utility>
#include <ctime>
#include <cstdlib>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

int main() {
	char a, b;
	cin >> a >> b;
	if (a == 'H') {
		if (b == 'H') {
			cout << 'H' << endl;
			return 0;
		}
	}
	else {
		if (b == 'D') {
			cout << 'H' << endl;
			return 0;
		}
	}
	cout << 'D' << endl;
	return 0;
}

Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9
def dfs(cur, a, b, c):
    if cur == N:
        if min(a, b, c) > 0:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30  
        else:
            return INF
    ret0 = dfs(cur + 1, a, b, c) #l[cur+1]を使用しない
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10 ##l[cur+1]をAに使用
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10 ##l[cur+1]をBに使用
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10 ##l[cur+1]をCに使用
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
use std::collections::BinaryHeap;

fn input_duo<T: std::str::FromStr + Copy> () -> (T, T) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let s: Vec<T> = s.trim().split_whitespace().flat_map(str::parse).collect();
    (s[0], s[1])
}

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

fn main() {
    let (_, m) = input_duo::<usize>();
    let a: Vec<_> = input_arr::<isize>().into_iter().map(|v| v).collect();
    let mut heap = BinaryHeap::from(a);
    for _ in 0..m {
        if let Some(x) = heap.pop() {
            heap.push(x / 2);
        }
    }
    println!("{}", heap.into_iter().sum::<isize>());
}


Measured memory_bytes: 4024
def ascan; gets.split.map(&:to_i);end

field = (0..2).map{ascan}

ok = true

2.times do |y|
    2.times do |x|
        ok &= field[y][x+1] - field[y][x] == field[y+1][x+1] - field[y+1][x]
    end
end

2.times do |x|
    2.times do |y|
        ok &= field[y+1][x] - field[y][x] == field[y+1][x+1] - field[y][x+1]
    end
end

puts ok ? "Yes" : "No"

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

//#define max(a,b) a>b?a:b
//#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int sum() { return 0; }

template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

/*
const int nax = 1e6;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string ks,s = "";
	ll k;cin>>ks;
    k = stoi(ks);
    int n =  ks.length();
    ll cnt = n;
    for (int i = 0; i < n; ++i)
    {
        s += "7";
    }
    //if()
    while (cnt<=nax)
    {   //s += "7"
        int num = stoi(s);
        if(num % k){
            cout<<cnt;
            return 0;
        }
        cnt++;
        s += "7";
    }
    cout<<"-1";

    return 0;
}

*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    string s;cin>>s;
    int cntr =0;
    REP(i,n){
        if(s[i] == 'R')cntr++;
    }
    int cntr_in_left = 0;
    for (int i = 0; i < cntr; ++i)
    {
        if(s[i] == 'R')cntr_in_left++;
    }
    cout<<(cntr - cntr_in_left);
    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int H, W, N;
    cin >> H >> W >> N;

    map<pii, int> mp;
    int dy[] = {0, 0, 1, 1, 1, 0, -1, -1, -1};
    int dx[] = {0, 1, 1, 0, -1, -1, -1, 0, 1};
    for (int i = 0; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        for (int j = 0; j < 9; ++j) {
            int ny = a + dy[j];
            int nx = b + dx[j];
            if (ny < 1 || nx < 1 || ny + 1 >= H || nx + 1 >= W)
                continue;
            mp[{ny, nx}]++;
        }
    }

    static ll ans[10];
    ans[0] = (ll)(H - 2) * (W - 2);
    for (auto i : mp)
        ans[i.second]++, ans[0]--;
    for (auto i : ans)
        cout << i << '\n';
    return 0;
}


Measured memory_bytes: 56576