akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

struct Mystruct {
  int cost;
  VI a;

  Mystruct(int input_a, VI input_b) {
    cost = input_a;
    a = input_b;
  }
  // bool operator<(const Mystruct &another) const
  // {
  //     if(cost == another.cost){
  //         return mp < another.mp;
  //     }
  //     return cost < another.cost;//年齢を比較
  // };
};

int main() {
  int n, m, x;
  cin >> n >> m >> x;

  vector<Mystruct> v;

  REP(i, n) {
    int tmp_c;
    VI tmp_a(m);
    cin >> tmp_c;
    REP(j, m) {
      cin >> tmp_a[j];
    }
    v.push_back(Mystruct(tmp_c, tmp_a));
  }

  int ans = pow(10, 9);

  // {0, 1, ..., n-1} の部分集合の全探索
  for (int bit = 0; bit < (1 << n); ++bit) {
    /* bit で表される集合の処理を書く */
    auto s = bitset<12>(bit);
    int sum_cost = 0;
    VI tmp_status(m, 0);
    REP(i, n) {
      if (s[i]) {
        sum_cost += v[i].cost;
        VI tmp_a = v[i].a;
        REP(j, m) {
          tmp_status[j] += tmp_a[j];
        }
      }
    }

    bool flag = true;
    REP(i,m){
      if(tmp_status[i] <x){
        flag = false;
      }
    }
    if(flag){
      ans = min(ans, sum_cost);
    }
  }

  if(ans == pow(10,9)){
    ans = -1;
  }

  ANS(ans);

  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
    int N,A[200000],K,Q,i,point[200000],tmp;

    scanf("%d %d %d",&N,&K,&Q);

    for(i=0; i<N; i++){
        point[200000] = 0;//初期化
    }
    for(i=0; i<Q; i++){
        scanf("%d",&tmp);
        A[i] = tmp;
        point[tmp-1]++;
    }

    for(i=0; i<N; i++){
        point[i] = point[i] - Q + K;

        if(point[i] <= 0){
            printf("No\n");
        } else {
            printf("Yes\n");
        }
    }

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define db "knapsack"
#define fi first
#define se second
#define endl '\n'
const int INF = 1e9 + 1;
const int maxN = 1e5 + 2;
const int mod = 1e9 + 7;
typedef long long ll;
typedef int Array[maxN];
typedef ll LLArray[maxN];
typedef pair<int, int> PII;
typedef PII PIIArray[maxN];

void docfile()
{
    if (ifstream("FORM.inp"))
    {
        freopen("FORM.inp", "r", stdin);
        freopen("FORM.out", "w", stdout);
    }
    else if (ifstream(db".inp"))
    {
        freopen(db".inp", "r", stdin);
        freopen(db".out", "w", stdout);
    }
}

//-----------------------------------------------------------------------------
int n, m;
Array a;

void solve()
{
    m = a[1];
    for(int i = 2; i <= n; i++)
    {
        m = max(m, a[i]-1);
        if(m > a[i])
        {
            cout << "No";
            return;
        }
    }
    cout << "Yes";
}

void input()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    solve();
}

int main()
{
    docfile();
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    input();
}


//-----------------------------------------------------------------------------
/*
template <typename T>
void write (T a)
{
    if (a < 0)
    {
        putchar ('-');
        write (-a);
        return;
    }
    if (a < 10)
    {
        putchar ('0' + a);
        return;
    }
    write (a / 10);
    putchar ((char)('0' + (a % 10)));
}

void read(long long& x)
{
    x = 0;
    int f = 1;
    char ch = getchar();
    while (!isdigit(ch))
        f = ch == '-' ? - f : f, ch = getchar();
    while (isdigit(ch))
        x = x * 10 + ch - '0', ch = getchar();
    x *= f;
}
*/




Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
 
int main(void){
	int n,a[65],i,mx=1;
	cin >> n;
	for(i=1; i<=n; i++){
		cin >> a[i];
		if(abs(a[i])>abs(a[mx])){
			mx = i;
		}
	}
	cout << (2*n-1) << endl;
	for(i=1; i<=n; i++){
		cout << mx << " " << i << endl;
	}
	if(a[mx]>=0){
		for(i=1; i<n; i++){
			cout << i << " " << (i+1) << endl;
		}
	}else{
		for(i=n; i>1; i--){
			cout << i << " " << (i-1) << endl;
		}
	}
	return 0;
}

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

int main() {
	int64_t n, k;
	cin >> n >> k;
	vector<vector<int64_t>>vec(n, vector<int64_t>(2));
	for (int i = 0; i < n; i++) cin >> vec.at(i).at(0) >> vec.at(i).at(1);
	sort(vec.begin(), vec.end());
	for (int i = 0; i < n; i++) {
		int64_t a = vec.at(i).at(0);
		int64_t b = vec.at(i).at(1);
		if (k > b)k -= b;
		else {
			cout << a << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 8712
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

signed main(){
    
    int n; cin >> n;
    int m = INF;
    for(int i = 0; i < 5; i++){
        int val; cin >> val;
        m = min(m, val);
    }

    cout << (n + m - 1) / m + 4 << endl;
        
    return 0;
}



Measured memory_bytes: 256
require 'prime'

N = gets.to_i
def comb(n, r)
    f = [1]
    (1..n).each do |i|
        f << f[i - 1]*i
    end
    return f[n] / (f[r] * f[n - r])
end

factors = {}
(1..N).each do |n|
    primes = n.prime_division
    primes.each do |k, v|
        if factors.key?(k)
            factors[k] += v
        else
            factors[k] = v
        end
    end
end

ans = 0
candidate2 = 0
candidate4 = 0
candidate14 = 0
candidate24 = 0
candidate74 = 0

factors.each_value do |v|
    candidate2 += 1 if v >= 2    
    candidate4 += 1 if v >= 4    
    candidate14 += 1 if v >= 14    
    candidate24 += 1 if v >= 24    
    candidate74 += 1 if v >= 74    
end

# (74)
ans += candidate74

# (4, 14)
ans += candidate14 * (candidate4 - 1)

# (2, 24)
ans += candidate24 * (candidate2 - 1)

# (2, 4, 4)
ans += comb(candidate4, 2) * (candidate2 - 2) if candidate4 >= 2

puts ans

Measured memory_bytes: 2044
// AOJ 2155: Infected Computer
// 2017.10.20 bal4u@uu
// 2018.2.4

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { int t, s, d; } T;
T tbl[20002], *end;
char f[20002];

int cmp(T *a, T *b) { return a->t - b->t; }

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, m, ans;
	T *t;
	char *q;

	while (n = in()) {
		m = in();
		memset(f, 0, n+1);
		end = tbl + m; for (t = tbl; t < end; t++) t->t = in(), t->s = in(), t->d = in();
		qsort(tbl, m, sizeof(T), cmp);
		f[1] = 1; for (t = tbl; t < end; t++) f[t->d] |= f[t->s];
		ans = 0, q = f+1; while (n--) ans += *q++;
		printf("%d\n", ans);
	}
	return 0;
}



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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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( a > b ) { a = b; return 1; } return 0; }

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

signed main(){
    int N, sum = 0; cin >> N;
    vector<int> a( N );
    REP( i, N ) {
        cin >> a[i];
        sum += a[i];
    }

    int cursum = 0;
    int ans = INF;
    REP( i, N - 1 ){
        cursum += a[i];
        chmin( ans, abs( cursum - ( sum - cursum ) ) );
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	if(n % 10 == 3) cout << "bon" << endl;
	else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) cout << "pon" << endl;
	else cout << "hon" << endl;
	return 0;
}

Measured memory_bytes: 3624
{-# LANGUAGE BangPatterns, MultiWayIf #-}

import Control.Applicative
import Control.Monad
import Data.List

solve :: String -> Int
solve xs = go 0 0 xs
  where
    go !ans !s []     = ans + s
    go !ans !s (y:ys)
        | y == 'S'  = go ans (s + 1) ys
        | otherwise = if s == 0
            then go (ans + 1) s ys
            else go ans (s - 1) ys

main :: IO ()
main = do
    xs <- getLine
    print $ solve xs

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

int main() {
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
	cout<<"Yes"<<endl;
}
else{
	cout<<"No"<<endl;
}
	return 0;
}


Measured memory_bytes: 3100
#pragma GCC optimize("O3")
#pragma GCC optimize("avx")

#include <stdio.h>
#include <algorithm>
#include <utility>

template <const unsigned int N>
struct FastInput{
    char Input[N];
    char* input;
    FastInput(void):Input(), input(Input){ fread_unlocked(Input, sizeof(char), N, stdin); }
    inline int getint(void){
        int res = 0, c; while((c = *(input++) - '0') >= 0) res = 10 * res + c;
        return res;
    }
};

constexpr unsigned int MAX_INPUT = 7500'000;
FastInput<MAX_INPUT> Input;

template <const unsigned int N>
struct FastOutput{
    char Output[N];
    char* ptr;
    FastOutput(void):Output(), ptr(Output){}
    ~FastOutput(void){ fwrite_unlocked(Output, sizeof(char), ptr - Output, stdout); }
    inline void write(int x){
        if(!x) *(ptr++) = '0';
        else{
            char* ptr2 = ptr;
            while(x){ *ptr2++ = '0' + (x % 10); x /= 10; }
            char* ptr3 = ptr2;
            while(ptr < ptr2) std::swap(*(ptr++), *(--ptr2));
            ptr = ptr3;
        }
        *(ptr++) = '\n';
    }
};
constexpr unsigned int MAX_OUTPUT = 2500'000;
FastOutput<MAX_OUTPUT> Output;

constexpr unsigned int MAX_N = 200'001;
int A[MAX_N];
int Lis[MAX_N + 1];

struct edge{
    int to; 
    edge* next;
};

edge Edge[2 * MAX_N + 1];
edge* begin[MAX_N];
edge* e_ptr = Edge;
inline void append(const int u, const int v){
    e_ptr -> to = v;
    e_ptr -> next = begin[u];
    begin[u] = e_ptr++;
}

int Ans[MAX_N];
bool visited[MAX_N];

struct stack_type{
    int vertex;
    int val;
};
stack_type Stack[2 * MAX_N + 1];
stack_type * stack = Stack;
inline stack_type* pop(void){ return --stack; }
inline void push(const int v, const int value){ *(stack++) = {v, value}; }
inline bool empty(void){ return stack == Stack; }

struct Index{
    int index;
    int val;
};
Index Restore[MAX_N];

int main(void){
    int n = Input.getint();
    for(int i = 0; i < n; ++i) A[i] = Input.getint();
    Lis[0] = 0; std::fill(Lis + 1, Lis + n, INT32_MAX);
    for(int i = 1; i < n; ++i){
        int u = Input.getint() - 1, v = Input.getint() - 1;
        append(u, v); append(v, u);
    }
    visited[0] = true; push(0, 0);
    while(!empty()){
        const stack_type* p = pop();
        const int v = p ->vertex, value = p -> val;
        if(value == -1){ Lis[Restore[v].index] = Restore[v].val; }
        else{
            if(Lis[value] < A[v]){
                Restore[v].index = value + 1; Restore[v].val = INT32_MAX;
                Lis[value + 1] = A[v]; Ans[v] = value + 1;
            }
            else{
                int ok = 0, ng = value;
                while(ng - ok > 1){
                    const int mid = (ok + ng) >> 1;
                    if(Lis[mid] < A[v]) ok = mid; else ng = mid;
                }
                Restore[v].index = ng; Restore[v].val = Lis[ng];
                Lis[ng] = A[v]; Ans[v] = value;
            }
            push(v, -1);
            for(edge* itr = begin[v]; itr; itr = itr -> next) if(!visited[itr -> to]){ 
                visited[itr -> to] = true; push(itr -> to, Ans[v]);
            }
        }
    }
    for(int i = 0; i < n; ++i) Output.write(Ans[i]);
    return 0;
}

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

int main() {
  int n;
  ll ans = 0;
  cin >> n;
  vector<int>a(n+1);
  rep(i,n+1) cin >> a[i];
  rep(i,n){
    int b;
    cin >> b;
    if(a[i]-b >= 0) ans += b;
    else if(a[i]+a[i+1]-b >= 0){
      ans += b;
      a[i+1] -= b-a[i];
    }
    else{
      ans += a[i]+a[i+1];
      a[i+1] = 0;
    }
  }
  cout << ans << endl;
    
}

Measured memory_bytes: 640
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
ll n;int N=1000000,pr[100005],k,ans;bool f[1000005];
void work(){
	for(int i=2;i<=N;i++){
		if(f[i]==1){
			for(int j=i*2;j<=N;j+=i)
			f[j]=0;
			pr[++k]=i;
		}
	}
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;memset(f,1,sizeof f);f[1]=0;work();
	for(int i=1;i<=k;i++){
		int now=pr[i];
		if(n%now==0){
			int sum=0;
			while(n%now==0){
				sum++;n/=now;
			}
//			printf("%d %d ",now,sum);
			for(int i=1;;i++){
				if(i*(i+1)/2>sum){
					/*printf("%d\n",i-1);*/ans+=i-1;break;
				}
			}
		}
	}
	if(n>1)ans++;
	cout<<ans<<endl;
	return 0;
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int n, k;
  string s;
  Solver2(LL n, LL k) : n(n), k(k){};

  void solve() {
    cin >> s;
    s[k - 1] = 'a' + (s[k - 1] - 'A');
    cout << s << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, k;
  std::cin >> n >> k;

  Problem::Solver2 sol(n, k);
  sol.solve();
  return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

void solve() {

}

int main() {
  int n;
  cin >> n;
  printf("%.10f\n",2.0*n*M_PI);
  
  return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1000000007;
int main() {
	ll i,j,k,l,m,n,t;
	const clock_t begin_time = clock();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>m;
  	
    
      cout<<(n-1)*(m-1)<<endl;
    

	//cout << float( clock () - begin_time ) /  CLOCKS_PER_SEC<<endl;
	return 0;
}  	


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std ;
using ll = long long ;

int main(){
	ll n,q ; cin >> n >> q ;
	string s ; cin >> s ;
	vector<ll> sum(n+1,0) ;
	for(int i=2;i<=n;i++){
		sum.at(i) = sum.at(i-1)+(s.at(i-2)=='A'&&s.at(i-1)=='C') ;
	}
	for(int i=0;i<q;i++){
		ll l,r ;
		cin >> l >> r ;
		if(l==1){
			cout << sum.at(r) << endl ;
			continue ;
		}
		cout << sum.at(r)-sum.at(l-1)-(s.at(l-2)=='A'&&s.at(l-1)=='C') << endl ;
	}
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fto(i, s, e) for(int i = (s); i <= (e); ++i)
#define fto1(i, s, e) for(int i = (s); i < (e); ++i)
#define fdto(i, s, e) for(int i = (s); i >= (e); --i)
#define fit(it, var) for(auto it = (var).begin(); it != (var).end(); ++it)
#define frit(it, var) for(auto it = (var).rbegin(); it != (var).rend(); ++it)
 
#define bc __builtin_popcountll
#define onb(x, bit) (((x >> bit) & 1) != 0)
#define y1 ansdj
 
#define ll long long
#define ii pair<int, int>
#define x first
#define y second
#define pb push_back
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
 
template<class T1, class T2> ostream& operator<< (ostream &os, pair<T1, T2> const &v) {
	return os << '(' << v.x << ", " << v.y << ')';
}
 
template<class T> ostream& operator<< (ostream &os, vector<T> const &v) {
	for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i < sz(v)-1) os << ' '; }
	return os;
}
 
template<class T> void bug(T const &v) { cout << v << endl; }
template<class T, class... Args> void bug(T const &v, Args const&... args) { cout << v << ' '; bug(args...); }
 
double const pi = acos(-1);
#define oo 1000000007
#define OO 1000000000000000003LL
int const maxn = 2e5+3;
 
int n;
pair<ll, ll> a[maxn], f[maxn], g[maxn];
ll ans;
 
int main() {
	#ifdef KITTENS
		freopen("main.inp", "r", stdin);
		freopen("main.out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
	cin >> n;
 
	fto (i, 1, n) {
		cin >> a[i].x >> a[i].y;
	}
 
	sort(a+1, a+1+n);
 
	f[1] = a[1];
	fto (i, 2, n) {
		if (a[i].x > f[i-1].y) break;
		f[i] = {a[i].x, min(f[i-1].y, a[i].y)};
	}
 
	g[n] = a[n];
	fdto (i, n-1, 1) {
		if (a[i].y < g[i+1].x) break;
		g[i] = {g[i+1].x, {min(g[i+1].y, a[i].y)}};
	}
  
  	fto (i, 1, n) {
      if (!f[i].x) f[i] = {1, 0};
      if (!g[i].x) g[i] = {1, 0};
    }
  
  	g[n+1] = {1, 0};
 
	fto (i, 1, n) {
		ans = max(ans, f[i].y - f[i].x + 1 + g[i+1].y - g[i+1].x + 1);
		if (i > 1 && i < n) {
			ii val = {1, 0};
			if (g[i+1].x <= f[i-1].y) val = {g[i+1].x, min(f[i-1].y, g[i+1].y)};
			ans = max(ans, a[i].y - a[i].x + 1 + val.y - val.x + 1);
		}
	}
 
	bug(ans);
 
	#ifdef KITTENS
		cerr << 0.001*clock() << endl;
	#endif
	return 0;
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

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

  sort(a.begin(), a.end());
  double m = (double)(a[n-1]+1)/2;
  double d = a[n-1];
  int res;
  for (int i = 0; i < n-1; i++) {
    if (abs(a[i]-m)<d) {
      res = i;
      d = abs(a[i]-m);
    }
  }

  cout << a[n-1] << " " << a[res] << endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define MOD 1000000007LL
using namespace std;

typedef long long ll;


ll mod_pow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1)res=res*x%MOD;
		x=x*x%MOD;
		n>>=1;
	}
	return res;
}

int n;
string s;
ll dp[5001][5001];

int main(void){
	scanf("%d",&n);
	cin >> s;
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=i;j++){
			dp[i+1][j+1]=(dp[i+1][j+1]+(dp[i][j]*2LL)%MOD)%MOD;
			dp[i+1][max(j-1,0)]=(dp[i+1][max(j-1,0)]+dp[i][j])%MOD;
		}
	}
	int len=s.size();
	ll res=dp[n][len];
	res=res*mod_pow((MOD+1LL)/2LL,len)%MOD;
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 116992
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# ------------------- fast io --------------------
from math import gcd, ceil
 
def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi
 
 
def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans
 
def lcm(a, b): return a * b // gcd(a, b)
 
 
def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

N = int(input())
A = list(map(int, input().split()))
MOD = int(1e9) + 7

ans = 0
acc = 0
for i in A:
    ans += i * acc
    acc += i
    ans %= MOD
    acc %= MOD

print(ans)


Measured memory_bytes: 95892
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 210;
int n,pos,ans[N],cnt[2],a[N];
char t[N];

int tot;
char s[N];
inline int Query(poly v){
	printf("? ");
	for (auto i:v) printf("%d ",i);
	puts(""),fflush(stdout);
	scanf("%s",s+1);
	return s[1]=='R';
	/*poly cnt(2);
	for (auto i:v) cnt[a[i]]++;
	printf("%d\n",cnt[1]>cnt[0]);
	return cnt[1]>cnt[0];*/
}

int main(){
	n=read();
//	scanf("%s",t+1);
//	For(i,1,2*n) a[i]=t[i]=='R';
	int l=1,r=n+1,ret=0,ret1=0;
	poly tmp;
	For(i,1,n) tmp.pb(i);
	int ret_=Query(tmp);
	while (l<=r){
		int mid=l+r>>1;
		poly v;
		For(i,mid,mid+n-1) v.pb(i);
		ret1=Query(v);
		if (ret1!=ret_) ret=mid,r=mid-1;
			else l=mid+1; 
	}
	--ret,ans[ret]=ret_;
	poly v,v2;
	For(i,ret+1,ret+n-1) v.pb(i);
	For(i,1,ret-1){
		v.pb(i),ans[i]=Query(v),v.pop_back();
		if (cnt[ans[i]]<n/2) v2.pb(i),cnt[ans[i]]++;
	}
	For(i,ret+n,n*2){
		v.pb(i),ans[i]=Query(v),v.pop_back();
		if (cnt[ans[i]]<n/2) v2.pb(i),cnt[ans[i]]++;
	}
	For(i,ret+1,ret+n-1){
		v2.pb(i),ans[i]=Query(v2),v2.pop_back();
	}
	printf("! ");
	For(i,1,n*2) printf("%c",ans[i]?'R':'B');
	puts(""),fflush(stdout);
}


Measured memory_bytes: 3800
def try(balls, b ,c)
  return 1 if balls.empty?
  nxt = balls.first
  bl = balls.drop(1)
  if nxt > b and nxt > c
    try(bl, nxt, c) + try(bl, b, nxt)
  elsif nxt > b
    try(bl, nxt, c)
  elsif nxt > c
    try(bl, b, nxt)
  else
    0
  end
end

$<.gets.to_i.times do
  balls = $<.gets.split.map(&:to_i)
  puts try(balls.drop(1), balls.first, 0).nonzero? ? "YES" : "NO"
end


Measured memory_bytes: 6856
import sys

#文字列wordの文字の種類の構成の表現のためのリストを返す関数
def connection_count(word)->list:
    i=0
    a=[]
    count=1
    while i<(len(word)-1):
        while word[i]==word[i+1]:
            count+=1
            i+=1
            if i>=(len(word)-1):
                break
        a.append(count)
        count=1
        i+=1
    if a[-1]==1:
        a.append(count)
    return a

#S:文字列、K：繰り返す回数
S=input()
K=int(input())

#Sが一文字の場合(例外処理）
if len(S)==1:
    print(K//2)
    sys.exit()

#Sの文字の種類の構成を表現するためのリスト
connection=connection_count(S)

#すべての文字が同じ場合
if len(connection)==1:
    print(((connection[0]*K)//2))
#最初と最後の文字が異なる場合
elif S[0]!=S[-1]:
    connection2=list(map(lambda x:x//2,connection))
    print((sum(connection2)*K))
#最初と最後の文字が同じ場合（すべての文字が同じ場合を除く）
else:
    t=S*2
    connection2=list(map(lambda x:x//2,connection))
    connection3=list(connection_count(t))
    connection4=map(lambda x:x//2,connection3)
    a=sum(connection2)
    b=sum(connection4)
    ans=a+(b-a)*(K-1)
    print(ans)


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif




signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> p(M);
    vector<string> S(M);
    rep(i,M){
        cin >> p[i] >> S[i];
        p[i]--;
    }

    vector<int> ac(N, 0), pena(N,0);
    int totalAC = 0, total_pena=0;
    
    rep(i,M){
        if(ac[p[i]]==0){
            if(S[i]=="AC") ac[p[i]]++;
            else pena[p[i]]++;
        }
    }
    rep(i,N){
        if(ac[i]>0){
            totalAC++;
            total_pena += pena[i];
        }
    }
    cout << totalAC << " " << total_pena << endl;
    
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define b first
#define a second
/// TONI BO$$ was here
/// #MLC

using namespace std;
pair <int,int> v[200001];
int main()
{
    int i,tp,n;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%d%d",&v[i].a,&v[i].b);
    }
    sort(v+1,v+1+n);
    tp=0;
    for(i=1; i<=n; i++)
    {
        if(tp+v[i].a>v[i].b)
        {
            printf("No");
            return 0;
        }
        tp+=v[i].a;
    }
    printf("Yes");

    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] heights = new int[N];
        for(int i=0;i<N;i++){
            heights[i] = sc.nextInt();
        }
        System.out.println(frog1(heights,K));
    }

    static int frog1(int[] heights,int K){
        int[] dp= new int[heights.length];
        dp[0]= 0;
        dp[1]= Math.abs(heights[1]-heights[0]);
        for(int i=2;i<heights.length;i++){
            int min = Integer.MAX_VALUE;
            for(int k=1;k<=K;k++){
                if(i-k>=0){
                    int cost = dp[i-k] +Math.abs(heights[i]-heights[i-k]);
                    min = (min > cost) ? cost: min;
                }
            }
            dp[i] = min;
        }
        return dp[heights.length-1];
    }
}


Measured memory_bytes: 49956
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t A;
  double B;
  cin >> A >> B;
  const double eps = 1e-6;
  int64_t E = (int64_t)((B + eps) * 100.0);

  int64_t A0 = A / 100L;
  int64_t A1 = A % 100L;

  int64_t answer = A0 * E;
  answer += (A1 * E) / 100L;
  cout << answer << endl;
  return 0;
}


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

const ll p = 1e9+7;
const int MAXN = 2e5+5;

int a, b;

int main() {
	cin >> a >> b;
	if (a <= 0 && b >= 0) {
		cout << "Zero\n"; return 0;
	}

	if (a > 0) {
		cout << "Positive\n"; return 0;
	}

	cout << (((b-a+1)%2 == 0) ? "Positive\n" : "Negative\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;

typedef pair<int, int> E;

int INF = -1;

int main() {
  int n, u, k;
  cin >> n;
  int** G = new int*[n+1];
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    G[u] = new int[k+1];
    G[u][0] = k;
    for (int j = 1; j <= k; j++) {
      cin >> G[u][j];
    }
  }

  int cnt = 0;
  int* visit = new int[n+1];
  for (int i = 1; i <= n; i++) {
    visit[i] = INF;
  }

  queue<E> q;
  q.push(E(1, cnt));
  while (q.size()) {
    E e = q.front();
    q.pop();
    if (visit[e.first] != INF)
      continue;
    visit[e.first] = e.second;

    int len = G[e.first][0];
    for (int i = 1; i <= len; i++) {
      q.push(E(G[e.first][i], e.second + 1));
    }
  }

  for (int i = 1; i <= n; i++) {
    cout << i << " " << visit[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#include <list> 
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll getDigit(ll n) {
	ll cnt = 0;
	while (n != 0) {
		n /= 10;
		cnt++;
	}
	return cnt;
}
typedef pair<double, long long> pair_t;
bool comp(const pair_t& a, const pair_t& b) {
	if (a.first == b.first)return  a.second > b.second;
	else {
		return a.first > b.first;
	}
}

int main() {
	string s,ans="";
	cin >> s;
	rep(i, s.length()) {
		ans += 'x';
	}
	cout << ans << endl;
} 


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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll n;
    n = s.size();
    vector<ll> v(n,0);
    FOR(i,0,n){
      ll j = n-i-1;
      if(s[j]=='W'){
        v[j]++;
      }
    }
    FOR(i,1,n){
      v[n-i-1] += v[n-i];
    }
    ll res=0;
    FOR(i,0,n){
      if(s[i]=='B'){
        res+=v[i];
      }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 2196
def dist(i,j):
    return hypot(xy[i][0]-xy[j][0],xy[i][1]-xy[j][1])
    
def center(i,j,k):
    a,b = xy[i]
    c,d = xy[j]
    e,f = xy[k]
    
    #一直線上？
    pp = (e-a)*(b-d)-(c-a)*(b-f)
    if pp == 0:
        if (c-a) == 0:
            ratio = (f-b)/(d-b) 
            if ratio > 1: #(a,b),(c,d),(e,f)の順番
                return (e+a)/2,(f+b)/2
            elif ratio > 0: #(a,b),(e,f),(c,d)の順番
                return (c+a)/2,(d+b)/2
            else: #(e,f),(a,b),(c,d)の順番
                return (c+e)/2,(d+f)/2
        else:
            ratio = (e-a)/(c-a) 
            if ratio > 1: #(a,b),(c,d),(e,f)の順番
                return (e+a)/2,(f+b)/2
            elif ratio > 0: #(a,b),(e,f),(c,d)の順番
                return (c+a)/2,(d+b)/2
            else: #(e,f),(a,b),(c,d)の順番
                return (c+e)/2,(d+f)/2

    bunbo = 2*(a*(d-f)+c*(f-b)+e*(b-d))
    px = (a*a+b*b)*(d-f)+(c*c+d*d)*(f-b)+(e*e+f*f)*(b-d)
    px /= bunbo
    py = (a*a+b*b)*(e-c)+(c*c+d*d)*(a-e)+(e*e+f*f)*(c-a)
    py /= bunbo
    return px,py
    
###########################################################################
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

n = int(input())
#n,k = [int(i) for i in readline().split()]
#a = [int(i) for i in readline().split()]

xy = [[int(i) for i in readline().split()] for _ in range(n)]
xy += [[0,0]]
from math import hypot
if n==2:
    print(dist(0,1)/2)
    exit()


from itertools import combinations
L = list(range(n))

ans = 1000000000
for i,j,k in combinations(L,3):
    xy[-1] = center(i,j,k)
    d = max(dist(l,-1) for l in range(n))
    if ans > d:
        ans = d


for i,j in combinations(L,2):
    xx = (xy[i][0]+xy[j][0])/2
    yy = (xy[i][1]+xy[j][1])/2
    xy[-1] = [xx,yy]
    d = max(dist(l,-1) for l in range(n))
    if ans > d:
        ans = d

print(ans)
    
    
    

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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e5+5; 

int main(){
	fast;
// 	string s; cin >> s;
	ll n; cin >> n;
	ll arr[n+5];
	rep(i,1,n) cin >> arr[i];
	
	ll ans = 0;
	
	rep(i,2,n-1){
	    vector<ll> v;
	    v.pb(arr[i-1]);
	    v.pb(arr[i]);
	    v.pb(arr[i+1]);
	    sort(all(v));
	    ans += v[1] == arr[i];
	}
	
	cout << ans <<endl;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
        p: [usize; n], // v_1 v_2 ... v_n
    }

    let ans = {
        let mut ans = Vec::new();
        let mut sum = {
            let mut sum = 0;
            for j in 0..k {
                sum += p[j];
            }
            sum
        };
        ans.push(sum);
        for i in 0..n-k {
            sum -= p[i];
            sum += p[i+k];
            ans.push(sum);
        }
        let ans = ans.iter().max().unwrap();
        *ans
    };

    let ko = (ans as f32 + k as f32)/2.0;

    println!("{}",ko)
}


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

ll f(ll A, ll B, ll x){
    return A*x/B - A * (x/B);
}

int main(){
    ll A, B, N; cin >> A >> B >> N;
    if(N < B) cout << f(A, B, N) << endl;
    else cout << f(A, B, B-1) << endl;
}

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

using i64 = int64_t;

struct Cloth{
    int a, b, c;
};

int dp[202][202]={0};

int main(){
    int d, n;
    cin >> d >> n;
    vector<int> t;
    t.push_back(0);
    for(int i=0;i<d;++i){
        int tmp;
        cin >> tmp;
        t.push_back(tmp);
    }
    vector<Cloth> c;
    c.push_back((Cloth){0, 0, 0});
    for(int i=0;i<n;++i){
        int x, y, z;
        cin >> x >> y >> z;
        c.push_back((Cloth){x, y, z});
    }

    for(int i=1;i<=n;++i){
        if(t[1] < c[i].a || t[1] > c[i].b){
            dp[1][i] = -1;
        }
    }

    for(int i=2;i<=d;++i){
        for(int j=1;j<=n;++j){
            if(t[i] < c[j].a || t[i] > c[j].b)continue;
            for(int k=1;k<=n;++k){
                if(dp[i-1][k] == -1)continue;
                if(t[i-1] < c[k].a || t[i-1] > c[k].b)continue;
                dp[i][j] = max(dp[i][j], dp[i-1][k] + abs(c[j].c - c[k].c));
            }
        }
    }

    int ans = 0;
    for(int i=1;i<=n;++i)ans = max(ans, dp[d][i]);
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
int main(){
int S;
  cin>>S;
  int a=S/100;
  int b=S%100;
  bool x=1<=a && a<=12;
  bool y=1<=b && b<=12;
  if(x&&y)
    cout<<"AMBIGUOUS"<<endl;
  if(!x&&y)
    cout<<"YYMM"<<endl;
  if(x&&!y)
    cout<<"MMYY"<<endl;
    if(!x&&!y)
      cout<<"NA"<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
#define endl "\n"
#define ff first
#define ss second 
#define pb push_back
#define INF ll(1e18)
#define MOD 1000000007
#define debug(x) cout<<x<<"\n";
#define pll pair<ll,ll>
#define mp make_pair
#define Craig ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(v) v.begin(),v.end()
#define MAX 200015
#define vll vector<ll>

int main()
{ 
    Craig

    ll n,i,k=0,m,j=0,x=0,y=0,fl=0;
    string s;
    cin>>n;
    cin>>s;
    for(i=0;i<n;i++)
    {
       if(s[i]=='R')x++;
    }
    for(i=0;i<n;i++)
    {
        if(x==0)break;
        if(s[i]=='R')x--;

        else
        {
         k++;
         x--;
        }
        
    }
    cout<<k<<endl;
}

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

#define xx first
#define yy second

const int N = 21;
const int mod = 1e9 + 7;

int add(int x, int y) {
    return (x + y) % mod;
}
    
int a[N][N], dp[1 << N], ndp[1 << N];

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> a[i][j];
    fill(dp, dp + (1 << n), 0);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        for (int k = 0; k < (1 << n); k++)
            ndp[k] = dp[k];

        for (int j = 0; j < n; j++)
            if (a[i][j])
                for (int k = 0; k < (1 << n); k++)
                    if (!(k & (1 << j)))
                        ndp[k | (1 << j)] = add(ndp[k | (1 << j)], dp[k]);

        for (int k =0 ; k < (1 << n); k++)
            dp[k] = ndp[k];
    }
    cout << dp[(1 << n) - 1] << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


Measured memory_bytes: 20044
#include <bits/stdc++.h>
// #include "../../cxx-prettyprint/prettyprint.hpp"
 
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

// だれかのWAを直してみる
 
using namespace std;

typedef long long ll;
// typedef pair<int, int> P;
 
const ll INF = 1e18;
 
struct edge {
    ll to;
    ll cost;
};
 
// <最短距離, 頂点の番号>
using P = pair<ll, ll>;
 
int V;
vector<edge> G[100001];
vector<ll> d(100001);

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d.begin(), d.end(), INF);
    d[s] = 0;
    que.push(P(0, s));
 
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if (d[v] < p.first) continue;
 
        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
 
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述
 
	int N, M;
	cin >> N >> M;
 
	V = N+1;
 
	vector<int> L,R,C;
	int l,r,c;
	for(int i=0; i<M; i++){
		cin >> l >> r >> c;
		L.push_back(l);
		R.push_back(r);
		C.push_back(c);
	}
 
	for(int i=N;i>1;i--){
		edge e = {i-1, 0};
		G[i].push_back(e);
	}
	REP(i,M){
		edge e = {R[i], C[i]};
		G[L[i]].push_back(e);
	}
 
	dijkstra(1);
 
	// cout << d << "\n";
 
	cout << setprecision(15);
	
	if(d[N] == INF){
		cout << -1 << "\n";
	}
	else{
		cout << d[N] << "\n";
	}
 
return 0;
}


Measured memory_bytes: 11372
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int main() {
    ll n, t;
    ll ans = 0;
    cin >> n >> t;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a.at(i);
    }
    for (int i = 1; i < n; i++) {
        if (a.at(i) - a.at(i - 1) > t) {
            ans += t;
        }
        else ans += a.at(i) - a.at(i - 1);
    }
    ans += t;
    cout << ans << endl;
}

Measured memory_bytes: 1792
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    def nCr(n, r, mod):#mod=10**9+7 
        r = min(r, n-r)
        numer = denom = 1
        for i in range(1, r+1):
            numer = numer * (n+1-i) % mod
            denom = denom * i % mod
        return numer * pow(denom, mod-2, mod) % mod

    n,k = map(int, input().split())
    #k個ある青のボールをi個に分ける
    for i in range(1, k+1):
        if i > n-k+1:
            print(0)
        else:
            print((nCr(k-1, k-i, mod) * nCr(n-k+1, i, mod))% mod)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 3700
#include<cstdio>
int N,A[200010];
long long solve(){
	if(A[0])return-1;
	long long s=0;
	for(int i=0,j=0;i<N;i=j){
		while(j<N&&(j==i||A[j]==A[j-1]+1))++j;
		if(j<N&&A[j]>A[j-1])return-1;
		s+=A[j-1];
	}
	return s;
}
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++)scanf("%d",A+i);
	printf("%lld\n",solve());
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  multiset<long> primary; 

  int trans, curr; 
  cin >> curr; 
  primary.insert(-1); 
  primary.insert(curr);
  primary.insert(LONG_MAX); 


  for (int i = 1; i < N; i++){
    cin >> curr; 
    auto it = --primary.lower_bound(curr); 
    if(*it == -1){
        primary.insert(curr); 
    } else  {
        primary.erase(it);
        primary.insert(curr); 
    }
    
  }  
  cout << primary.size() - 2; 
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <math.h>
#include <string.h>
long long int i,j;

int main(void){
    char s[200100],t[200100];
    scanf("%s %s",s,t);
    int n=strlen(s);
    int r[26]={0},R[26]={0};
    for(i=0;i<n;i++){
        r[s[i]-'a']++;
        R[t[i]-'a']++;
    }
    for(i=0;i<26;i++){
        int num=r[i];
        for(j=0;j<26;j++){
            if(R[j]==num){
                R[j]=0;
                break;
            }
        }
        if(j==26){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std ;
typedef long long LL;
const int MAXN = 1 + 2e5;
typedef pair <int,int> II;

string s;

void solve(){
        cin >> s;
        string t;
        string t1;
        LL ans = 0;


        for (int i = 0; i < s.size(); i++){
            t1 += s[i];
            if (t1 != t){
                ans++;
                t = t1;
                t1 = "";
            }

           // cout << i + 1 << " " << t << " " << t1 << " " << ans << endl;
        }
        cout << ans;

}


int main(){
                        #define NAME "ABC"
                  //  freopen(NAME".inp","r",stdin);
                //    freopen(NAME".out","w",stdout);
                    ios_base::sync_with_stdio(0);
                    cin.tie();
                    solve();






return 0;
}


Measured memory_bytes: 720
n = int(input())

dams = list(map(int, input().split()))
ans_list = [0 for x in range(n)]

ans_list[0] = sum([dams[x]*(-1)**x for x in range(n)])

for i in range(1, n):
  ans_list[i] = -ans_list[i-1] + 2 * dams[i - 1]

print(" ".join(list(map(str, ans_list))))

#print(*ans_list)
  

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

const double KPI=acos(-1);

int main(){
    double a,b,x;
    scanf("%lf%lf%lf",&a,&b,&x);
    x/=a;
    if(a*b/2>=x){
        a=x*2/b;
        printf("%.7f\n",90.0-atan(a/b)/KPI*180.0);
    }
    else{
        double b_=2*x/a-b;
        double a_=a*b_/(b-b_);
        printf("%.7f\n",atan(b/(a+a_))/KPI*180.0);
    }
	return 0;
}


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

#define rep(i, n)	for(int i = 0; i < (int)(n); i++)

int a[100010];
bool pushed[100010];
int N;

int main() {
	int count = 0;

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	};

	int i = 1;
	while(i != 2) {
		if (pushed[i]) {
			count = -1;
			break;
		}

		pushed[i] = true;
		i = a[i];
		count++;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 768