akhauriyash/Code-Regression huggingface dataset:
S = input()
for i in range(2 ** len(S) - 1):
    work = S
    for j in range(1 ,len(S)):
        if i >> (j - 1) & 1:
            work = work[:2 * j - 1] + "+" + work[2 * j - 1:]
        else:
            work = work[:2 * j - 1] + "-" + work[2 * j - 1:]
    if eval(work) == 7:
        print("{0}=7".format(work))
        exit()

Measured memory_bytes: 38256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int a, b;
    scan(a, b);

    foreach (x ; 0 .. 100000) {
        auto p8 = x * 8 / 100;
        auto p10 = x * 10 / 100;
        if (p8 == a && p10 == b) {
            writeln(x);
            return;
        }
    }

    writeln(-1);
}




void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}





Measured memory_bytes: 256
#include <iostream>                                                                                                          

int main(){
   int N, A, B;
   std::cin >> N >> A >> B;

   int ans = 0;
   for(int i=1; i<=N; ++i){
      int sum = 0;
      int n = i;
      while(n>0){
         sum += n%10;
         n /= 10; 
      }   
      if(sum>=A && sum<=B) ans += i;
   }   
   std::cout << ans << std::endl;
   return 0;
}

Measured memory_bytes: 256
import operator as op
from functools import reduce
from collections import defaultdict
from math import ceil
def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom

n = int(input().strip())
nums = [int(i) for i in input().strip().split()]
ans = [0 for i in range(n)]
num_d = defaultdict(int)
for i in nums:
    num_d[i] += 1

ans_d = defaultdict(int)
s = 0
for each_num in num_d:
    if num_d[each_num] < 2:
        ans_d[each_num] = 0
        continue
    res = ncr(num_d[each_num],2)
    s += res
    ans_d[each_num] = res

for index,i in enumerate(nums):
    if num_d[i] - 1 < 2:
        ans[index] = s - ans_d[i]
    else:
        ans[index] = s - ans_d[i] + ncr(num_d[i] - 1,2)

for each in ans:
    print(each)


Measured memory_bytes: 33248
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define REP_IN(i, n, x) for (ll i = 0; i < n; i++)in>>x;
#define REP_OUT(i, n, x) for (ll i = 0; i < n; i++)out<<x<<endl;
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
#define endl '\n'
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N, K, ans=0;
    in >> N >> K;
    vector<ll> h(N);
    REP(i, N){
        in >> h[i];
        if(h[i] >= K) ans++;
    }
    out << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
  int a, b, c, result = 0;
  cin >> a >> b >> c;
  for(int val = a; val <= b; ++val) {
    if (c % val == 0) {
      result++;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3096
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let n = read::<i32>();
  let k = read::<i32>();
  let mut x = vec![];
  for _ in 0..n {
    let x_i = read::<i32>();
    x.push(x_i);
  }

  let mut dist = vec![];

  for i in 0..n - k + 1 {
    let idx = i as usize;
    dist.push(x[idx].abs() + (x[idx + (k - 1) as usize] - x[idx]).abs());
  }

  for i in k - 1..n {
    let idx = i as usize;
    dist.push(x[idx].abs() + (x[idx - (k - 1) as usize] - x[idx]).abs());
  }

  // println!("{:?}", dist);
  println!("{:?}", dist.iter().min().unwrap());
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
  string S, T;
  cin >> S >> T;

  for(int i = 0; i < S.size(); ++i){
    rotate(begin(S),begin(S)+1,end(S));
    if(S == T){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	string str;
	int flag=1;
	cin >> str;
	string dream = "maerd";
	string dreamer = "remaerd";
	string erase = "esare";
	string eraser = "resare";
	reverse(begin(str),end(str));
	while(flag!=0)
	{
		flag = 0;
		if(dream==str.substr(0,5))
		{
			str.replace(0,5,"");
			flag = 1;
		}
		if(dreamer==str.substr(0,7))
		{
			str.replace(0,7,"");
			flag = 1;
		}
		if(erase==str.substr(0,5))
		{
			str.replace(0,5,"");
			flag = 1;
		}
		if(eraser==str.substr(0,6))
		{
			str.replace(0,6,"");
			flag = 1;
		}
	}
	if(str=="")
	{
		cout << "YES" <<endl;
	}else{
		cout << "NO" <<endl;
	}
	return 0;
}

Measured memory_bytes: 640
/*input
8
657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

ll a[maxn];

ll neg[maxn];
ll pos[maxn];

int go(ll A,ll B){
	ll ret=0;
	while(A<B){
		A*=4;
		ret++;
	}
	return ret;
}

vector<pii> v;

int main()
{
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];


	neg[0]=neg[1]=0;
	for(int i=2;i<=n;i++){
		//cout<<i<<endl;
		int meow=go(a[i-2],a[i-1]);
		//cout<<i<<' '<<meow<<endl;
		neg[i]=neg[i-1];
		int pt=i;
		if(SZ(v)) for(int j=SZ(v)-1;j>=0;j--){
			if(meow==0) break;
			neg[i]+=2*meow*(pt-v[j].S);
			int tmp=min(meow,v[j].F);
			meow-=tmp;
			v[j].F-=tmp;
			if(v[j].F==0) v.pop_back();
			pt=v[j].S;
		}
		if(meow>0) neg[i]+=2*meow*(pt-1);
		{
			ll A=a[i-2],B=a[i-1];
			int cnt=-1;
			while(B<=A){
				cnt++;
				B*=4;
			}
			if(cnt>0){
				v.pb(MP(cnt,i));
				//cout<<v.back()<<'\n';
			}
		}
	}
	v.clear();
	reverse(a,a+n);
	pos[0]=pos[1]=0;
	for(int i=2;i<=n;i++){
		//cout<<i<<endl;
		int meow=go(a[i-2],a[i-1]);
		//cout<<i<<' '<<meow<<endl;
		pos[i]=pos[i-1];
		int pt=i;
		if(SZ(v)) for(int j=SZ(v)-1;j>=0;j--){
			if(meow==0) break;
			pos[i]+=2*meow*(pt-v[j].S);
			int tmp=min(meow,v[j].F);
			meow-=tmp;
			v[j].F-=tmp;
			if(v[j].F==0) v.pop_back();
			pt=v[j].S;
		}
		if(meow>0) pos[i]+=2*meow*(pt-1);
		{
			ll A=a[i-2],B=a[i-1];
			int cnt=-1;
			while(B<=A){
				cnt++;
				B*=4;
			}
			if(cnt>0){
				v.pb(MP(cnt,i));
				//cout<<v.back()<<'\n';
			}
		}
	}
	//REP(i,n+1) cout<<neg[i]<<" \n"[i==n];
	//REP(i,n+1) cout<<pos[i]<<" \n"[i==n];

	ll ans=INF64;
	for(int i=0;i<=n;i++){
		ans=min(ans,neg[i]+i+pos[n-i]);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 6016
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

const int MAX_N=1<<18;
const int INF=1e9;

int mx[2*MAX_N-1], part[2*MAX_N-1];
bool mada[2*MAX_N-1];
int m0;

void init(int n){
    m0=1;
    while(m0<n) m0*=2;
}
   
void eval(int k, int l, int r){
    if(mada[k]){
        mx[k]+=part[k];
        if(k<m0-1){
            part[2*k+1]+=part[k];
            part[2*k+2]+=part[k];
			mada[2*k+1]=1; mada[2*k+2]=1;
        }
        mada[k]=0;
		part[k]=0;
    }
}
     
void add(int a, int b, int x, int k, int l, int r){
    eval(k, l, r);
    if(r<=a || b<=l) return;
    if(a<=l && r<=b){
        part[k]=x;
		mada[k]=1;
        eval(k, l, r);
    }else{
        add(a, b, x, k*2+1, l, (l+r)/2);
        add(a, b, x, k*2+2, (l+r)/2, r);
        mx[k]=max(mx[2*k+1], mx[2*k+2]);
    }
}
     
int find(int a, int b, int k, int l, int r){
    eval(k, l, r);
    if(b<=l || r<=a){
        return 0;
    }
    if(a<=l && r<=b){
        return mx[k];
    }else{
        return max(find(a, b, 2*k+1, l, (l+r)/2), find(a, b, 2*k+2, (l+r)/2, r));
    }
}

int main()
{
	int n, m;
	cin>>n>>m;
	vector<int> r[200001];
	for(int i=0; i<n; i++){
		int l0, r0;
		cin>>l0>>r0;
		r[l0].push_back(r0);
	}
	int ans=max(0, n-m);
	init(m+2);
	for(int i=1; i<=m+1; i++){
		add(i, i+1, i, 0, 0, m0);
	}
	for(int i=0; i<=m; i++){
		if(r[i].empty()) continue;
		for(auto r0:r[i]){
			add(0, r0+1, 1, 0, 0, m0);
		}
		for(auto r0:r[i]){
			ans=max(ans, find(i+1, r0+1, 0, 0, m0)-m-1-i);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12544
import java.util.Scanner;


public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		for(; scanner.hasNext();)
		{
			float[] x = new float[4];
			float[] y = new float[4];
			
			String input = scanner.next();
			String[] words = input.split(",");
			for(int i=0; i<4; i++)
			{
				x[i] = Float.parseFloat(words[i*2]);
				y[i] = Float.parseFloat(words[i*2+1]);
			}
			
			double angle = 0;
			for(int i=0; i<4; i++)
			{
				int prev=0, next=0;
				switch (i)
				{
					case 0:
						prev = 3;
						next = 1;
						break;
					case 1:
						prev = 0;
						next = 2;
						break;
					case 2:
						prev = 1;
						next = 3;
						break;
					case 3:
						prev = 2;
						next = 0;
						break;
				}
				
				double a = Math.sqrt((x[prev]-x[next])*(x[prev]-x[next]) + (y[prev]-y[next])*(y[prev]-y[next]));
				double b = Math.sqrt((x[prev]-x[i])*(x[prev]-x[i]) + (y[prev]-y[i])*(y[prev]-y[i]));
				double c = Math.sqrt((x[i]-x[next])*(x[i]-x[next]) + (y[i]-y[next])*(y[i]-y[next]));
				double ang = Math.acos((b*b + c*c - a*a) / (2*b*c));
				
				angle += Math.toDegrees(ang);
			}
			
			System.out.println((int)(angle+0.5)==360 ? "YES" : "NO");
		}
	}
}

Measured memory_bytes: 26160
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	string s,t;
	cin>>s>>t;
	
	int ans=0;
	REP(i,s.size()){
		if(s[i]==t[i]){}
		else ans++;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3916
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i,j,k,ans=0;
  cin>>n;
  vector<int> l(n);
  for(i=0;i<n;i++) cin>>l.at(i);
  sort(l.begin(),l.end());
  for(i=0;i<n-2;i++){
    for(j=i+1;j<n-1;j++){
      for(k=j+1;k<n;k++){
        if(l.at(i)<l.at(j)&&l.at(j)<l.at(k)&&l.at(i)+l.at(j)>l.at(k)) ans++;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
# input
N = int(input())

otoshidama = 0
BTC_rate = 380000.0
for i in range(1, N + 1):
    x, u = map(str, input().split())
    
    # check
    if u == "BTC":
        otoshidama += float(x) * BTC_rate
    else:
        otoshidama += float(x)

print(otoshidama)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

void printarray(int a[], int n){
	for (int i=0; i<n; i++){
		if (i==n-1){
			cout << a[i] << endl;
		}
		else{
			cout << a[i] << ' ';
		}
	}

}

void insertionsort(int a[], int n){
	for (int i=0; i<n; i++){
		int v = a[i];
		int j = i-1;
		while (j >= 0 && a[j] > v){
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
		printarray(a,n);
	}
}


int main(){
	int n;
	cin >> n;
	int a[n];
	for (int i=0;i<n;i++){
		cin >> a[i];
	}
	insertionsort(a,n);

	return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>
int main()
{
    long long int i,j,n,max,s;
    double sum;
    scanf("%lld",&n);
    j=0;
    long long int a[n+10];
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
    }
    max=a[0];
    for(i=0;i<n;i++)
    {
        if(max<a[i])
        {
            max=a[i];
            j=i;
        }
    }
    a[j]=0;
    sum=max/2.0;
    for(i=0;i<n;i++)
    {
        sum=sum+a[i];
    }
   s=(long long int)sum;
   if(s==sum)
   {
       printf("%lld\n",s);
   }
   else
    printf("%.1lf\n",sum);
   return 0;

}


Measured memory_bytes: 128
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Map.Entry;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 1) {
            System.out.println(1); // 1/2 = 0.5??
            System.exit(0);
        }

        Map<Integer, Integer> an = new HashMap<Integer, Integer>();
        for (int i = 1; i <= n; i++) {
            int j = i;
            int c = 0;
            while (j % 2 == 0) {
                c += 1;
                j /= 2;
            }
            an.put(i, c);
        }

        int ans = 0;
        int max = 0;
        for(Entry<Integer, Integer> e : an.entrySet()) {
            if (e.getValue() > max) {
                max = e.getValue();
                ans = e.getKey();
            }
        }
        System.out.println(ans);
    }

}

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

#define ld long double

int N;
double dp[310][310][310];


double rec(int i, int j, int k) {
  if (dp[i][j][k] >= 0) return dp[i][j][k];
  if (i == 0 && j ==0 && k == 0) return 0.0;
  
  double res = 0.0;
  if (i > 0) res += rec(i-1, j, k) * i;
  if (j > 0) res += rec(i+1, j-1, k) * j;
  if (k > 0) res += rec(i, j+1, k-1) * k;
  res += N;
  res *= 1.0/(i+j+k);
  
  return dp[i][j][k] = res;
}


int main() {
  cin >> N;
  
  int one = 0, two = 0, three = 0;
  
  // one, two, three のカウント
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (a == 1) one++;
    if (a == 2) two++;
    if (a == 3) three++;
  }
  
  memset(dp, -1, sizeof(dp));
  
  cout << fixed << setprecision(10) << rec(one, two, three) << endl;
}

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

using namespace std;

const int MAX_N=3005;
long long comb[MAX_N][MAX_N];

int n;
long long modd;

void add(long long &a, long long b)
{
    a=(a+b)%modd;
}

void mult(long long &a, long long b)
{
    a=(a*b)%modd;
}

void subtr(long long &a, long long b)
{
    a=(a-b+modd)%modd;
}

long long f(int x) // pow(2,pow(2,n))
{
    long long ans=2;
    for(int i=0; i<x; i++)
    {
        mult(ans,ans);
        //cerr << i << " " << x << " " << ans << endl;
    }
    return ans;
}

long long dp2[MAX_N][MAX_N];

long long ways2(int nb_groups, int nb_objects)
{
    if(dp2[nb_groups][nb_objects]!=-1) return dp2[nb_groups][nb_objects];
    if(nb_groups==0) return dp2[nb_groups][nb_objects]=1;
    if(nb_groups>nb_objects) return dp2[nb_groups][nb_objects]=0;
    long long ans=ways2(nb_groups, nb_objects-1);
    add(ans,ways2(nb_groups-1, nb_objects-1));
    add(ans,nb_groups*ways2(nb_groups,nb_objects-1));
    return dp2[nb_groups][nb_objects]=ans;
}

long long dp[MAX_N];
long long macht2[MAX_N][MAX_N];
long long ways(int aantal)
{
    if(dp[aantal]!=-1) return dp[aantal];
    long long ans=0;
    for(int i=0; i<=aantal; i++) {
            add(ans,(macht2[n-aantal][i]*ways2(i,aantal))%modd);
            //cerr << i << " " << aantal << " " << ways2(i,aantal) << " " << macht2[n-aantal][i] << endl;
    }
    //cerr << "ans: " << ans << endl;
    mult(ans,f(n-aantal));
    return dp[aantal]=ans;
}

int main()
{
    //freopen("inp.in", "r", stdin);
    scanf("%d %lld", &n, &modd);
    //cerr << "11" << endl;
    for(int i=0; i<MAX_N; i++)
    {
        dp[i]=-1;
        for(int j=0; j<MAX_N; j++){
            comb[i][j]=1;
            macht2[i][j]=1;
            dp2[i][j]=-1;
        }
    }
    //cerr << "22" << endl;
    for(int i=1; i<MAX_N; i++)
    {
        //cerr << i << endl;
        mult(macht2[i][1],2*macht2[i-1][1]);
        //cerr << i << endl;
        if(i != 1) mult(macht2[1][i],2*macht2[1][i-1]);
    }
    //cerr << "33" << endl;
    for(int i=2; i<MAX_N; i++)
    {
        for(int j=2; j<MAX_N; j++)
        {
            mult(macht2[i][j],macht2[i][j-1]*macht2[i][1]);
        }
    }
    //cerr << "44" << endl;
    for(int i=2; i<MAX_N; i++)
    {
        for(int j=1; j<i; j++)
        {
            add(comb[i][j],comb[i-1][j-1]+comb[i-1][j]-1);
        }
    }
    //cerr << "55" << endl;
    long long ans=f(n);
    //cerr << "n: " << n << endl;
    //cerr << ans << endl;
    for(int i=1; i<=n; i++)
    {
        if(i&1)
        {
            //cerr << i << " " << comb[n][i] << endl;
            //cerr << "ways(" << i << "):" << ways(i) << endl;
            subtr(ans,(comb[n][i]*ways(i))%modd);
        }
        else
        {
            add(ans,(comb[n][i]*ways(i))%modd);
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 211968
#include <iostream>
#include <vector>

using namespace std;


int find_l(int N, int Q, string &s, vector<char> &ts, vector<char> &ds) {
//    左に落ちるのを探す
    int l_index = 0, r_index = N + 1;
    while ((r_index - l_index) > 1) {
        int target_index = (l_index + r_index) / 2;
        int current_cell = target_index;
        for (int i = 0; i < Q; i++) {
            char t = ts[i], d = ds[i];
            if (s[current_cell - 1] == t) {
                if (d == 'L') {
                    current_cell--;
                } else {
                    current_cell++;
                }
            }
            if (current_cell == 0) break;
            if (current_cell == (N + 1)) break;
        }
        if (current_cell != 0) {
            r_index = target_index;
        } else {
            l_index = target_index;
        }
    }
    return l_index;
}

int find_r(int N, int Q, string &s, vector<char> &ts, vector<char> &ds) {
//    右に落ちるのを探す
    int l_index = 0, r_index = N + 1;
    while ((r_index - l_index) > 1) {
        int target_index = (l_index + r_index) / 2;
        int current_cell = target_index;
        for (int i = 0; i < Q; i++) {
            char t = ts[i], d = ds[i];
            if (s[current_cell - 1] == t) {
                if (d == 'L') {
                    current_cell--;
                } else {
                    current_cell++;
                }
            }
            if (current_cell == (N + 1)) break;
            if (current_cell == 0) break;
        }
        if (current_cell != (N + 1)) {
            l_index = target_index;
        } else {
            r_index = target_index;
        }
    }
    return r_index;
}


int main() {
    int N, Q;
    cin >> N >> Q;
    string s;
    cin >> s;
    vector<char> ts(Q), ds(Q);
    for (int i = 0; i < Q; i++) {
        char t, d;
        cin >> t >> d;
        ts[i] = t;
        ds[i] = d;
    }

    int l_ans = find_l(N, Q, s, ts, ds);
    int r_ans = find_r(N, Q, s, ts, ds);
    cout << r_ans - l_ans - 1 << endl;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
ll n, ans, A, B;
ll a[N];

bool check(ll x) {
    ll C = A - B;
    ll base = B * x;
    ll cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (base < a[i]) {
            cnt += (a[i] - base + C - 1) / C;
        }
    }
    return cnt <= x;
}

int main() {
    cin >> n >> A >> B;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll l = 0, r = 1e9;
    while (l < r) {
        ll m = (r - l) / 2 + l;
        if (check(m))
            r = m;
        else
            l = m + 1;
    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 4380
def inpl(): return [int(i) for i in input().split()]

N, Y = inpl()
Y //= 1000
for i in range(-((N-Y)//9)+1):
    j = Y-N-i*9
    if j%4:
        continue
    j //= 4
    if j < 0:
        continue
    k = N-j-i
    if k < 0:
        continue
    print(i,j,N-j-i)
    break
else:
    print(-1, -1, -1)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath> 
#include <queue>
#include <functional>

using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
//static const int dx[4] = {1, -1, 0, 0};
//static const int dy[4] = {0, 0, 1, -1};

//static const ll MOD = 1e+9 + 7;
//static const int MAX = 10001;


int main() {
    int a, b; cin >> a >> b;
    if ((a + b) % 2 == 0) {
        cout << (a + b) / 2 << '\n';
    }
    else {
        cout << "IMPOSSIBLE\n";
    }

}


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

//#define int long long
#define MOD 1000000007


#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()
#define rall(i) (i).begin(),(i).end(),greater<int>()
using namespace std;

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T> void print(T x) { std::cout << x << '\n'; }
 
typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long


signed main(){
 
    ll A,B,Q;

    cin >>A>>B>>Q;
    vector<ll> s;
    vector<ll> t;
    vector<ll> x;

    ll inf = 1000000000000;

   s.pb(-inf);
    rep(i,A){
        ll temp;
        cin >> temp;
        s.pb(temp);
    }
    s.pb(inf);

    t.pb(-inf);
    rep(i,B){
        ll temp;
        cin >>temp;
        t.pb(temp);
    }
    t.pb(inf);

    rep(i,Q){
        ll temp;
        cin >>temp;
        x.pb(temp);
    }
    

    rep(i,Q){
        
        auto s2 = lower_bound(all(s),x[i]);
        auto t2 = lower_bound(all(t),x[i]);
        auto s1 = s2;
        s1--;
        auto t1 = t2;
        t1--;

        ll a1 = x[i]-*t1+abs(*s1-*t1);
        ll a2 = x[i]-*t1+abs(*s2-*t1);
        ll a3 = x[i]-*s1+abs(*t1-*s1);
        ll a4 = x[i]-*s1+abs(*t2-*s1);
        ll a5 = abs(x[i]-*t2)+abs(*s1-*t2);
        ll a6 = abs(x[i]-*t2)+abs(*s2-*t2);
        ll a7 = abs(x[i]-*s2)+abs(*t1-*s2);
        ll a8 = abs(x[i]-*s2)+abs(*t2-*s2);
          
        ll result = min({a1,a2,a3,a4,a5,a6,a7,a8});
        cout << result <<endl;

    }

    return 0;

 
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define mx 100005
#define inf 1000000007
using namespace std;

int n, v[2][3], h[3];

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

	for(int i = 0; i < n; i++){
		scanf("%d%d%d", &h[0], &h[1], &h[2]);
		for(int j = 0; j < 3; j++) v[(i+1)&1][j] = max(v[i&1][(j+1)%3], v[i&1][(j+2)%3]) + h[j];
	}
	printf("%d\n", max(max(v[n&1][0], v[n&1][1]), v[n&1][2]));
}

Measured memory_bytes: 256
N=gets.to_i
S=gets.chomp

ret = 0

('0'..'9').each do|i|
  ('0'..'9').each do|j|
    ('0'..'9').each do|k|
      a = S.index(i,0)
      next unless a
      b = S.index(j,a+1)
      next unless b
      c = S.index(k,b+1)
      if c
        ret += 1
        # p [[i,j,k],[a,b,c]]
      end
    end
  end
end

puts ret


Measured memory_bytes: 1916
import java.util.Scanner;

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

        int total = 0;
        int min = 100000;
        int minV = 0;
        for (int i = l; i < n + l; i++) {
            total += i;
            if (Math.abs(i) < min) {
                min = Math.abs(i);
                minV = i;
            }
        }

        System.out.println(total - minV);

    }
}


Measured memory_bytes: 21972
N = int(input())
A =list(map(int,input().split()))
L = [str(a) for a in A]
B = " ".join(L)
print(B)
for i in range(1,N):
	v = A[i]
	j = i -1
	while j>= 0 and A[j] >v:
		A[j+1] = A[j]
		j -= 1
	A[j+1] = v
	L = [str(a) for a in A]
	B = " ".join(L)
	print(B)


Measured memory_bytes: 5604
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define SZ(x) ((int)(x).size())

using namespace std;

typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

const int inf = 1 << 30;

string s, t;

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

	VVi dp(SZ(s) + 1, Vi(SZ(t) + 1, inf));
	dp[0][0] = 0;

	for (int i = -1; i < SZ(s); ++i)
		for (int j = -1; j < SZ(t); ++j)
		{
			if (!(~i) && !(~j))
				continue;

			if (!(i & (1 << 31)) && !(j & (1 << 31)))
			{
				if (s[i] == t[j])
					chmin(dp[i + 1][j + 1], dp[i][j]);
				else
					chmin(dp[i + 1][j + 1], dp[i][j] + 1);
			}

			if (i >= 0)
				chmin(dp[i + 1][j + 1], dp[i][j + 1] + 1);
			if (j >= 0)
				chmin(dp[i + 1][j + 1], dp[i + 1][j] + 1);

		}

	cout << dp[SZ(s)][SZ(t)] << endl;
}


Measured memory_bytes: 6880
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
    int N; cin >> N;

    vector<int> T(N);
    int total = 0;
    for (int i = 0; i < N; i++) {
        cin >> T[i];
        total += T[i];
    }

    int M; cin >> M;
    vector<int> drink(M);
    for (int i = 0; i < M; i++) {
        int p, x; cin >> p >> x; p--;
	drink[i] = total - T[p] + x;
    }

    for (int i = 0; i < M; i++) {
      cout << drink[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int main() {
	LL d;
	int n;
	int m;
	while (cin >> d&&d) {
		vector<LL> v;
		cin >> n >> m;
		int a;
		v.emplace_back(0);
		REP(i, n - 1) {
			cin >> a;
			v.emplace_back(a);
		}
		v.emplace_back(d);
		sort(v.begin(), v.end());
		LL ans = 0;
		REP(i, m) {
			cin >> a;
			LL left = 0, right = v.size() - 1;
			while (right - left > 1) {
				int mid = (right + left) / 2;
				if (v[mid] <= a)left = mid;
				else right = mid;
			}
			if (v[right] <= a) {
				ans += min(a - v[right], v[right + 1] - a);
			}
			else {
				ans += min(a - v[left], v[left + 1] - a);
			}
		}
		cout << ans << endl;

	}
}

Measured memory_bytes: 3824
package main

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

const Mod = 1e9 + 7

func main() {
	N := ReadInt()
	As := ReadInts(N)

	expected := make(map[int]int)
	for i := 1; Abs(N-i) < N; i += 2 {
		expected[Abs(N-i)]++
	}

	ans := 1
	for _, e := range expected {
		ans = (ans * e) % Mod
	}

	for _, a := range As {
		expected[a]--
		if expected[a] == 0 {
			delete(expected, a)
		}
	}

	if len(expected) > 0 {
		fmt.Println(0)
		return
	}

	fmt.Println(ans)
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func ReadInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = ReadInt()
	}
	return ret
}

var sc = bufio.NewScanner(os.Stdin)

func init()        { sc.Buffer(make([]byte, 256), 1e9); sc.Split(bufio.ScanWords) }
func Read() string { sc.Scan(); return sc.Text() }

func ReadInt() int {
	v, e := strconv.Atoi(Read())
	if e != nil {
		panic(e.Error())
	}
	return v
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int h, w; cin >> h >> w;
  int c[h][w];

  rep(i, h) rep(j, w) cin >> c[i][j];

  vector<pair<pi,pi>> ans;

  rep(i, h) {
    rep(j, w-1) {
      if (c[i][j] % 2) {
        --c[i][j];
        ++c[i][j+1];
        ans.eb(mp(i+1, j+1), mp(i+1, j+2));
      }
    }
  }

  rep(i, h-1) {
    if (c[i][w-1] % 2) {
      --c[i][w-1];
      ++c[i+1][w-1];
      ans.eb(mp(i+1, w), mp(i+2, w));
    }
  }

  printf("%d\n", si(ans));
  rep(i, si(ans)) {
    printf("%d %d %d %d\n", ans[i].fi.fi, ans[i].fi.se, ans[i].se.fi, ans[i].se.se);
  }
  
  return (0);
}

Measured memory_bytes: 6288
#coding:utf-8
#Simple Calculator

while 1:
    aopb = raw_input().split()
    if aopb[1] == "+":
        print int(aopb[0]) + int(aopb[2])
    elif aopb[1] == "-":
        print int(aopb[0]) - int(aopb[2])
    elif aopb[1] == "*":
        print int(aopb[0]) * int(aopb[2])
    elif aopb[1] == "/":
        print int(aopb[0]) / int(aopb[2])
    else:
        break

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

int k[maxn],d[maxn],c[maxn];
int col[maxn],vis[maxn],cas,dd[maxn];
vector<int> g[maxn];

void dfs(int u,int deep,int fa,int c){
	if(deep == 0) return ;
	if(dd[u] >= deep) return ;
	dd[u] = deep;
	if(col[u]==0) col[u] = c;
	// cout << u << " " << dd[u] << " " << col[u] << endl;
	for(int i=0; i<(int)g[u].size(); i++){
		int v = g[u][i];
		if(v == fa) continue;
		if(dd[v]>=deep) continue;
		dfs(v,deep-1,u,c);
	}
}


int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0; i<m; i++){
		int u,v; scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}

	int q = read();
	for(cas=1; cas<=q; cas++)
		scanf("%d%d%d",&k[cas],&d[cas],&c[cas]);
	
	for(int i=q; i>=1; i--)
		dfs(k[i],d[i]+1,0,c[i]);
	
	for(int i=1; i<=n; i++)
		cout << col[i] << endl;

    return 0;
}

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

using ll =                   long long int;
using pll =                  pair<ll, ll>;
#define endl                 "\n"
#define space                " "
#define TLE_na_ho            ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MAX_SIZE             1024
#define MOD                  1000000007
#define pb                   push_back
#define fi                   first
#define se                   second
#define rep(i,a,n)           for(ll i=a;i<n;i++)
#define repe(i,a,n)          for(ll i=a;i<=n;i++)
#define repr(i,a,n)          for(ll i=a;i>=n;i--)
#define ain(arr,n)           for(ll i1=0;i1<n;i1++ ) cin>>arr[i1]
#define aout(arr,n)          for(ll i1=0;i1<n;i1++ ) cout<<arr[i1]<<space

bool comp(ll a,ll b)
{
	return (a<b);
}

int main()
{
    TLE_na_ho;
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll p1=a*c;
    ll p2=a*d;
    ll p3=b*c;
    ll p4=b*d;
    ll maaxi=max({p1,p2,p3,p4},comp);
    cout<<maaxi;
}


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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,a[100001],d[200001];

void nhap()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        scanf("%d",&a[i]);
        d[i]=INT_MAX;
    }
}

void process()
{
    d[1]=0;
    for (int i=1;i<=n;++i)
    {
        d[i+1]=min(d[i+1],d[i]+abs(a[i+1]-a[i]));
        d[i+2]=min(d[i+2],d[i]+abs(a[i+2]-a[i]));
    }
    cout<<d[n];
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 1024
/*
 * Created By : pash123
 * 2020-09-13-17.19
*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

const int M=1e9+7;

int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll op1=a*c;
    ll op2=a*d;
    ll op3=b*c;
    ll op4=b*d;
    cout<<max(op1,max(op2,max(op3,op4)));
    return 0;
}


Measured memory_bytes: 3636
// " --- IN THE NAME OF ALLAH --- " // ;)
// ------------sphr_agz------------ // ;)
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

typedef long double ld;
typedef long long int lli;
typedef pair <lli, lli> pii;
#define pb push_back
#define recout(x) return cout << (x), 0
#define f first
#define s second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define stp(x) cout << setprecision(x) << fixed
#define mk make_pair
#define all(x) x.begin(), x.end()
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
const lli N = 3e2 + 3, N2 = 2e5, delta = 46639, mod = 1e9 + 7, oo = 2e5, LOG = 20, SQ = 300;
const ld PI = 3.141592653589793;

ld dp[N][N][N], p[N];
lli cnt[5];

int32_t main() {
	fast;
	stp(9);
	lli n, x;
	cin >> n;
	for (lli i = 0; i < n; i++) {
		cin >> x;
		cnt[x - 1]++;
	}
	for (lli i = 0; i <= n; i++) {
		p[i] = 1;
		for (lli j = 0; j < oo; j++)
			p[i] = 1 + p[i] * (ld) i / (ld) n;
	}
	for (lli i = 0; i <= n; i++)
		for (lli j = 0; j <= n; j++)
			for (lli k = 0; k <= n; k++) {
				if (!(i + j + k) || i + j + k > n)
					continue;
				dp[k][j][i] = p[n - (i + j + k)] + (k? dp[k - 1][j][i] * (ld) k / (ld) (i + j + k): 0) + (j? dp[k + 1][j - 1][i] * (ld) j / (ld) (i + j + k): 0) + (i? dp[k][j + 1][i - 1] * (ld) i / (ld) (i + j + k): 0);
			}
	cout << dp[cnt[0]][cnt[1]][cnt[2]] << '\n';
	return 0;
}


Measured memory_bytes: 432384
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main(void) {
  cout << fixed << setprecision(12);
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  double xx, yy;
  xx = abs(x1 - x2);
  yy = abs(y1 - y2);
  cout << sqrt(pow(xx,2)+pow(yy,2)) << endl;

  return 0;
}




Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long int
#define s(x)	cin>>x
#define p(x)	cout<<x<<"\n"
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 100000000000
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve() {
    int n;cin>>n;
    string s;cin>>s;
    int dp[n];
    clr(dp);
    if(s[0]=='R')
    dp[0]=1;
    Fo(i,1,n)
    {   if(s[i]=='R')
        dp[i]=dp[i-1]+1;
        else
        dp[i]=dp[i-1];
    }
    ll res=INF;
    int red=dp[n-1];
    if(red!=0)
    res=min(res,(ll)(red-dp[red-1]));
    else
    res=0;
    int pos=0;
    for(int i=n-1;i>=0;i--)
    {   if(s[i]!='W')
        {   pos=i;break;}
    }
    res=min(res,(ll)(pos+1-dp[pos]));
    p(res);
    
    
}


int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
   // cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    //u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 11596
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int price = sc.nextInt();
		int k = sc.nextInt();
		List<Integer> hate = new ArrayList<Integer>();
		for (int i = 0; i < k; i++) {
			hate.add(sc.nextInt());
		}
		boolean flg = false;
		int out = price;
		while (!flg) {
			List<Integer> list = new ArrayList<Integer>();
			list = getKeta(out);
			int like = 0;
			for (int i = 0; i < list.size(); i++) {
				if (!hate.contains(list.get(i))) {
					like++;
				}
			}
			if (like == list.size()) {
				flg = true;
			} else {
				out++;
			}

		}

		System.out.println(out);
	}

	public static List<Integer> getKeta(int n) {
		List<Integer> list = new ArrayList<>();
		while (n > 0) {
			list.add(n % 10);
			n /= 10;
		}
		return list;
	}
}

Measured memory_bytes: 32732
// {{{
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long int i32;
typedef unsigned long int u32;
typedef long long int i64;
typedef unsigned long long int  u64;
typedef pair<i32, i32> PII;
#define IN(x) cin >> x;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j-1, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define MP make_pair
#define PB push_back
#define PF push_front
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define DEBUG(x) cout << #x << ": " << x << endl;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
// }}}

const u32 MAX_N = 8000;
bool dpx[MAX_N][2*(MAX_N+1)];
bool dpy[MAX_N][2*(MAX_N+1)];

pair<u32, u32> c(string& s, u32 si) {
    u32 ret = 0;
    while(si < s.length() && s[si] == 'F') {
        ret++;
        si++;
    }
    if(si < s.length() && s[si] == 'T') {
        si++;
    }
    return MP(si, ret);
}

int main() {
    string s;
    u32 n;
    i32 x, y;
    cin >> s;
    n = s.length();
    n = n > 3 ? n : 3;
    cin >> x >> y;
    auto sid = c(s, 0);
    u32 si = sid.first;
    i32 d = sid.second;
    dpx[0][n] = dpx[1][d+n] = true;
    dpy[0][n] = true;
    u32 turn = 0;
    u32 jj[] = {1, 0};
    while(si < s.length()) {
        auto sid = c(s, si);
        si = sid.first;
        d = sid.second;
        turn++;
        REP(i, 2*n) {
            if(i + d <= 2 * n) {
                if(turn%2 == 0) {
                    dpx[turn/2+1][i+d] = dpx[turn/2+1][i+d] || dpx[turn/2][i];
                } else {
                    dpy[turn/2+1][i+d] = dpy[turn/2+1][i+d] || dpy[turn/2][i];
                }
            }
            if(0 <= i - d) {
                if(turn%2 == 0) {
                    dpx[turn/2+1][i-d] = dpx[turn/2+1][i-d] || dpx[turn/2][i];
                } else {
                    dpy[turn/2+1][i-d] = dpy[turn/2+1][i-d] || dpy[turn/2][i];
                }
            }
        }
        jj[turn%2]++;
    }

    if (dpx[jj[0]][x+n] && dpy[jj[1]][y+n]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 127232
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
typedef pair<double,double> PDD;
double sq(double a){
  return a*a;
}
double dist(PDD a, PDD b){
  return sqrt(sq(a.ff-b.ff)+sq(a.ss-b.ss));
}
double ra(PDD a, PDD b, PDD c){
  double ab=dist(a,b);
  double ac=dist(a,c);
  double bc=dist(b,c);
  double ana=acos(-(bc*bc-ab*ab-ac*ac)/(2*ab*ac))/2;
  double anb=acos(-(ac*ac-ab*ab-bc*bc)/(2*ab*bc))/2;
  double mn=0;
  double mx=ab;
  double md;
  double slpa=tan(ana);
  double slpb=tan(anb);
  forn(z,60){
    md=(mx+mn)/2;
    if(md*slpa>(ab-md)*slpb)
      mx=md;
    else
      mn=md;
  }
  mn=0;
  double r;
  forn(z,60){
    md=(mx+mn)/2;
    r=slpa*md;
    if((ab-(md+2*r))*slpb>r)
      mn=md;
    else
      mx=md;
  }
  return slpa*mn;
}
vector<pair<double,double> > pts(3);
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  forn(i,3)
    cin>>pts[i].ff>>pts[i].ss;
  double bst=0;
  forn(i,3)
    bst=max(bst,ra(pts[i],pts[(i+1)%3],pts[(i+2)%3]));
  cout<<setprecision(15);
  cout<<bst<<endl;
  return 0;
}


Measured memory_bytes: 384
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define OUT(x) out << (x) << endl;
#define M0(x) memset(x,0,sizeof(x))
#define MINF(x) memset(x,0x3f,sizeof(x))
#define MMINUS(a) memset(a,0xff,sizeof(a))

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1.0/LINF;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

using namespace std;

class CTypicalStairs {
public:
    ll N, M;
    ll dp[200000]{0};
    bool ok[200000];

    void solve(std::istream& in, std::ostream& out) {
        in >> N >> M;
        REP(i, N+1) ok[i] = true;
        REP(i, M) {
            ll tmp; in >> tmp;
            ok[tmp] = false;
        }
        dp[0] = 1;
        FOR(i, 0, N+1) {
            if (ok[i+1]) (dp[i+1] += dp[i]) %= MOD;
            if (ok[i+2]) (dp[i+2] += dp[i]) %= MOD;
        }
        OUT(dp[N]);
    }
};


int main() {
    CTypicalStairs solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1920
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll a,b;
    std::cin >> a>>b;
    if(b%a ==0){
        std::cout << a+b << std::endl;
    }else{
        std::cout << b-a << std::endl;
    }
}


Measured memory_bytes: 256