akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input!{
        n:usize,
        mut b: [usize1;n]
    }
    let mut index = n-1;
    let mut c = vec![];
    let mut ans = true;
    loop {
        if b[index] == index {
            c.push(b.remove(index));
            index = b.len();
        }
        if index==0 {
            break;
        }
        index-=1;
    }
    // c.push(0);
    if c.len() != n {
        ans = false;
    }
    c.reverse();
    // println!("{:?}", c);
    if ans {
        for e in &c {
            println!("{}", e+1);
        }
    }else{
        println!("-1");
    }
    
}

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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}

string s,ch[]{"dream","dreamer","erase","eraser"};
bool dp[100030];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> s;
	dp[0]=1;
	for (int i=0;i<s.size();i++) if (dp[i]) {
		for (string &t:ch) {
			bool succ=1;
			for (int j=0;j<t.size();j++) if (i+j>=s.size() || s[i+j]!=t[j]) succ=0;
			if (succ) dp[i+t.size()]=1;
		}
	}

	cout << (dp[s.size()]?"YES":"NO") << endl;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+5;
multiset<int>st;
multiset<int>::iterator it;
int n,A[M];

int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		scanf("%d",&A[i]);
	}
	for(int i=n; i>=1; i--){
		it=st.upper_bound(A[i]);
		if(it!=st.end()) st.erase(it);
		st.insert(A[i]);
	}
	printf("%d\n",st.size());
	return 0;
}

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

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

	int h, w;
	cin >> h >> w;
	int dp[h][w], i, j;
	char grid[h][w];
	for(i = 0; i < h; i++){
	    for(j = 0; j < w; j++){
	        cin >> grid[i][j];
	        dp[i][j] = 0;
	    }
	}
	dp[0][0] = 1;
	for(i = 1; i < h; i++)
    {
	    if(grid[i-1][0] == '#' || grid[i][0] == '#' || dp[i-1][0] == 0)
	        dp[i][0] = 0;
	    else
	        dp[i][0] = 1;
	}
	for(j = 1; j < w; j++)
    {
	    if(grid[0][j-1] == '#' || grid[0][j] == '#' || dp[0][j-1] == 0)
	        dp[0][j] = 0;
	    else
	        dp[0][j] = 1;
    }
	for(i = 1; i < h; i++)
	{
	    for(j = 1; j < w; j++)
	    {
	        if(grid[i][j] != '#')
	        {
	            if(grid[i][j-1] != '#')
    	            dp[i][j] = (dp[i][j] + dp[i][j-1]) % 1000000007;
    	        if(grid[i-1][j] != '#')
    	            dp[i][j] = (dp[i][j] + dp[i-1][j]) % 1000000007;
	        }
	    }
	}
	cout << dp[h-1][w-1] << endl;

	return 0;
}


Measured memory_bytes: 8488
#include<stdio.h>
 
int main(void)
{
	int a,b,c,x,y;
	scanf("%d %d %d",&a,&b,&c);
 
	for(x=a;x<=b;x++){
		if(c%x==0)
		y++;
	}
   
 	 printf("%d\n",y);
 
  	return 0;
}



Measured memory_bytes: 2140
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

bool check(ll n){
	
	rep(i,1,sqrt(n)+1){
		if(pow(i,2) == n) return true;
	}
	
	return false;
}

signed main(){
	ll n,cnt = 0;
	cin >> n;
	ll p[n] = {};
	
	rep(i,0,n){
		cin >> p[i];
		if(p[i] != i+1) cnt++;
		
	}
	
	if(cnt == 2 || cnt == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	
	
    return 0;
}

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

int N;
char S[1000] = {0};
int ans = 0;

int main()
{
    scanf("%s",S);
    N = strlen(S);
        for(int j = 1; 2 * j < N; j++)
        {
            for(int k = 0; k <= j; k++)
            {
                if(k == j){ans = max(ans,j * 2);break;}
                if(S[k] != S[j + k])break;
            }
        }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String ns = sc.nextLine();
        int n;
        int sn=0;

        sc.close();
        n = Integer.parseInt(ns);
        for(int i=0; i<ns.length(); i++) {
            sn += Integer.parseInt("" + ns.charAt(i));
        }

        if(n%sn == 0) System.out.println("Yes");
        else System.out.println("No"); 
    }
}

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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int h,w,i,j,k,a[500][500],t,t1,t2;
	bool q=false;
	cin>>h>>w;
	for (i=0;i<h;i++){
		for (j=0;j<w;j++){
			cin>>t;
			a[i][j]=t%2;
		}
	}	
	vector<pair<pair<int,int>,pair<int,int>>> g;
	for (i=0;i<h;i++){
		if (i%2==0){
			for (j=0;j<w;j++){
				if (q==true){
					if (a[i][j]==1){
						g.push_back(make_pair(make_pair(t1,t2),make_pair(i,j)));
						t1=i;
						t2=j;
						q=false;
					}
					else {
						g.push_back(make_pair(make_pair(t1,t2),make_pair(i,j)));
						t1=i;
						t2=j;
					}
				}
				else {
					if (a[i][j]==1){
						t1=i;
						t2=j;
						q=true;
					}
				}
			}
		}
		else {
			for (j=w-1;j>=0;j--){
				if (q==true){
					if (a[i][j]==1){
						g.push_back(make_pair(make_pair(t1,t2),make_pair(i,j)));
						t1=i;
						t2=j;
						q=false;
					}
					else {
						g.push_back(make_pair(make_pair(t1,t2),make_pair(i,j)));
						t1=i;
						t2=j;
					}
				}
				else {
					if (a[i][j]==1){
						t1=i;
						t2=j;
						q=true;
					}
				}
			}
		}
	}
	cout<<g.size()<<"\n";
	for (i=0;i<g.size();i++){
		cout<<g[i].first.first+1<<" "<<g[i].first.second+1<<" "<<g[i].second.first+1<<" "<<g[i].second.second+1<<"\n";
	}
	return 0;
}

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

struct Card { char suit, value; };

void bubble(struct Card A[], int N)
{
	for (int i = 0; i < N; i++)
	{
		for (int j = N - 1; j >= i; j--)
		{
			if (A[j].value < A[j - 1].value)
			{
				Card t = A[j]; A[j] = A[j - 1]; A[j - 1] = t;
			}
		}
	}
}

void selection(struct Card A[], int N)
{
	for (int i = 0; i < N; i++)
	{
		int minj = i;
		for (int j = i; j < N; j++)
		{
			if (A[j].value < A[minj].value)
			{
				minj = j;
			}
		}
		Card t = A[i]; A[i] = A[minj]; A[minj] = t;
	}
}

void print(struct Card A[], int N)
{
	for (int i = 0; i < N; i++)
	{
		if( i > 0 ) cout << " ";
		cout << A[i].suit << A[i].value;
	}
	cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N)
{
	for (int i = 0; i < N; i++)
	{
		if (C1[i].suit != C2[i].suit)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	Card C1[100], C2[100];
	int N;
	char ch; // 一文字

	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> C1[i].suit >> C1[i].value;
	}

	for (int i = 0; i < N; i++)
	{
		C2[i] = C1[i]; // 値をコピーして行く
	}

	bubble(C1, N);
	selection(C2, N);

	print(C1, N);
	cout << "Stable" << endl;

	print(C2, N);
	if(isStable(C1, C2, N)){
		cout << "Stable" << endl;
	}else{
		cout << "Not stable" << endl;
	}

	return 0;
}


Measured memory_bytes: 3112
using System;
using System.Collections.Generic;

public class Problem_A
{
  static readonly HashSet<int> g1 = new HashSet<int>(new int[] { 1, 3, 5, 7, 8, 10, 12 });
  static readonly HashSet<int> g2 = new HashSet<int>(new int[] {4, 6, 9, 11});
  static readonly HashSet<int> g3 = new HashSet<int>(new int[] { 2 });

  public static void Main()
  {
    var inputs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    int x = inputs[0], y = inputs[1];

    if (g1.Contains(x) && g1.Contains(y)
        || g2.Contains(x) && g2.Contains(y)
        || g3.Contains(x) && g3.Contains(y))
      Console.WriteLine("Yes");
    else Console.WriteLine("No");
  }
}

Measured memory_bytes: 13396
def warshall_floyd(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


INF = 10**9 + 1

if __name__ == "__main__":
    N, M, L = map(int, input().split())
    D = [[INF] * N for _ in range(N)]
    for i in range(N):
        D[i][i] = 0
    for i in range(M):
        tmp = list(map(int, input().split()))
        D[tmp[0]-1][tmp[1]-1] = tmp[2]
        D[tmp[1]-1][tmp[0]-1] = tmp[2]
    Q = int(input())
    st = list()
    for i in range(Q):
        st.append(list(map(int, input().split())))

    D = warshall_floyd(D)

    for i in range(N):
        for j in range(N):
            if i == j:
                D[i][j] = 0
            elif D[i][j] <= L:
                D[i][j] = 1
            else:
                D[i][j] = INF

    D = warshall_floyd(D)

    for i in range(Q):
        ans = D[st[i][0]-1][st[i][1]-1] - 1
        if ans == INF - 1:
            print(-1)
        else:
            print(ans)


Measured memory_bytes: 74840
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
 
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
 
    ll ans = 0;
 
    int r[n+1]={0},g[n+1]={0},b[n+1]={0};
 
    for(int i=n-1 ; i>=0 ; i--)
    {
        if(s[i]=='R')
            r[i] = r[i+1]+1;
        else
            r[i] = r[i+1];
    }
 
      for(int i=n-1 ; i>=0 ; i--)
    {
        if(s[i]=='G')
            g[i] = g[i+1]+1;
        else
            g[i] = g[i+1];
    }
 
 
      for(int i=n-1 ; i>=0 ; i--)
    {
        if(s[i]=='B')
            b[i] = b[i+1]+1;
        else
            b[i] = b[i+1];
    }
 
 
 
    for(int i=0 ; i<n ; i++)
    {
        for(int j=i+1 ; j<n ; j++)
        {
            if(s[i]=='R' && s[j]=='B')
            {
                ans += g[j+1];
                if(j+(j-i) < n && s[j+(j-i)]=='G')
                    ans--;
            }
            else if(s[i]=='R' && s[j]=='G')
            {
                ans += b[j+1];
                 if(j+(j-i) < n && s[j+(j-i)]=='B')
                    ans--;
            }
            else if(s[i]=='G' && s[j]=='R')
            {
                ans += b[j+1];
                 if(j+(j-i) < n && s[j+(j-i)]=='B')
                    ans--;
            }
            else if(s[i]=='G' && s[j]=='B')
            {
                ans += r[j+1];
                 if(j+(j-i) < n && s[j+(j-i)]=='R')
                    ans--;
            }
            else if(s[i]=='B' && s[j]=='G')
            {
                ans += r[j+1];
                 if(j+(j-i) < n && s[j+(j-i)]=='R')
                    ans--;
            }
            else if(s[i]=='B' && s[j]=='R')
            {
                ans += g[j+1];
                 if(j+(j-i) < n && s[j+(j-i)]=='G')
                    ans--;
            }
        }
    }
    cout << ans;
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
int inf = 1000000000; //10e9
ll linf = 1000000000000000000; //10e18
 
int main() {

    ll N, K;
    cin >> N >> K;

    ll ans = min(N%K, K - N%K);

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3616
#include <algorithm>
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
inline char nc() {
	return getchar();
	static char buf[100000],*l=buf,*r=buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x) {
	x=0; int f=1,ch=nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x*=f; 
}
typedef long long ll;
const int maxn=200000+5;
int n; ll a[maxn]; int b[maxn];
ll c[maxn];
int sta[maxn],top;
inline bool invalid(int u,int v,int w) {
	return (a[v]-a[u])*(w-v)<=(a[w]-a[v])*(v-u); 
}
void rebuild() {
	int k=max_element(a+1,a+n+1)-a;
	rotate(a+1,a+k,a+n+1);
	rotate(b+1,b+k,b+n+1);
	a[++n]=a[1],b[n]=b[1];
}
void init() {
	for(int i=2;i<n;++i) c[i+1]=2*(b[i]+c[i])-c[i-1];
	for(int i=1;i<=n;++i) a[i]-=c[i];
}
double sol() {
	rebuild();
	init();
	for(int i=1;i<=n;++i) {
		while(top>1&&invalid(sta[top-1],sta[top],i)) --top;
		sta[++top]=i;
	}
	ll an=0;
	for(int i=1;i<top;++i) {
		int d=sta[i+1]-sta[i];
		an+=a[sta[i]]*(d+1)+a[sta[i+1]]*(d-1);
	}
	for(int i=1;i<n;++i) an+=c[i]*2;
	return an/(2.0*(n-1));
}
int main() {
	read(n);
	for(int i=1;i<=n;++i) read(a[i]);
	for(int i=1;i<=n;++i) read(b[i]);
	printf("%.12lf\n",sol());
	return 0;
}

Measured memory_bytes: 7852
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<stack>
#define pi 3.141592653589
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)
#define fi first
#define se second
using namespace std;

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



int main() {

	int n, k, l[50],ans=0;

	cin >> n >> k;
	rep(i, 0, n)cin >> l[i];
	sort(l, l + n);
	reverse(l, l + n);
	rep(i, 0, k) {
		ans += l[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n,-1) {}
    int root(int x) {
      if (d[x] < 0) return x;
      return d[x] = root(d[x]);
    }
    bool unite(int x, int y) {
      x = root(x); y = root(y);
      if (x == y) return false;
      if (d[x] > d[y]) swap(x,y);
      d[x] += d[y];
      d[y] = x;
      return true;
    }
    bool same(int x, int y) { return root(x) == root(y);}
    int size(int x) { return -d[root(x)];}
  };
vector<int> g[110000],block[110000];
signed main(){
    int n,m,k;cin >>n >> m >> k;
    UnionFind uf(n);
    rep(i,m){
        int a,b;cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
        uf.unite(a,b);
    }
    rep(i,k){
        int a,b;cin >> a >> b;
        a--;b--;
        block[b].push_back(a);
        block[a].push_back(b);

    }
    rep(i,n){
        int friends = uf.size(i) - block[i].size()-g[i].size()-1;
        // trace(friends);
        for(auto ng:block[i]){
            if(uf.same(ng,i))continue;
            friends++;
        }
        cout << friends << endl;
    }

    return 0;
}

Measured memory_bytes: 16652
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

typedef  long long ll;
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;}

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

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int main(){

    int a,b,c,d,out;
    cin>>a>>b;
    out=2*b-a;
    cout<<out<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define pb push_back
typedef long double ld;
typedef vector<ll> vll;
typedef vector<pair<ll,ll>> vpl;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const ll mod = 1e9+7;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
        ll n,k; cin >> n >> k;
        vll h(n+1);
        repA(i,1,n) cin >> h[i];

        vll d(n+1,INF);
        d[1]=0;

        repA(i,2,n){
            repA(j,1,k){
                if(i-j>=1)d[i] = min(d[i],d[i-j]+abs(h[i-j]-h[i]));
            }
        }
        cout << d[n] << endl;
    }
}


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

int n, a, b;
string s;

int main() {
	cin >> n >> a >> b >> s;
	
	int all = 0;	//国内 + 海外の参加者
	int part = 0;	//海外の参加者
	
	for (int i = 0; i < n; i++) {
		if (s[i] == 'a') {
			if (all < a + b) {
				cout << "Yes" << endl;
				all++;
			}
			else {
				cout << "No" << endl;
			}
		}
		else if (s[i] == 'b') {
			if (all < a + b && part < b) {
				cout << "Yes" << endl;
				all++;
				part++;
			}
			else {
				cout << "No" << endl;
			}
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

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

#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
namespace adaptor = boost::adaptors;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

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

/*
	int N;
	std::cin >> N;
	std::vector<int> vec(N);
	for (auto& v : vec)
	{
		std::cin >> v;
	}
*/

void Main()
{
	string str;
	std::cin >> str;

	int r = 0;
	int max_r = 0;
	for (int i = 0; i < (int)str.size(); ++i) {
		char ch = str[i];

		if (ch == 'R') {
			++r;
		}
		else {
			max_r = max(r, max_r);
			r = 0;
		}
	}
	max_r = max(r, max_r);

	cout << max_r;
	return;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

struct graph {
	int size;
	vector<list<int>> adj;
	vi h;
	graph(int n) : size(n), adj(n), h(n) {}
	void addEdge(int a, int b) {
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
};

vb vis(1e5, false);
int dfs(graph& g, int u) {
	vis[u] = true;
	int ans = 0;
	bool good = true;
	each(v, g.adj[u]) {
		if (g.h[u] <= g.h[v]) good = false;
		if (vis[v]) continue;
		ans += dfs(g, v);
	}
	if (good) ans++;
	return ans;
}

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

	int n, m;
	cin >> n >> m;
	graph g(n);
	loop(n) cin >> g.h[i];
	int a, b;
	loop(m) {
		cin >> a >> b;
		g.addEdge(a - 1, b - 1);
	}
	int ans = 0;
	loop(n) {
		if (!vis[i]) ans += dfs(g, i);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 14288
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            /* string s, t;
             char[] s2, t2;
             string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
             s = str[0];  
             t = str[1];
             */
            char[] s = Console.ReadLine().ToArray();
            Array.Sort(s);
            char[] t = Console.ReadLine().ToArray();
            Array.Sort(t);
            Array.Reverse(t);

            int ans = new string(s).CompareTo(new string(t));

            if (ans < 0)
            {
                Console.WriteLine("Yes");
            } else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

vs week = { 
    "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" 
    };

int main(){
    map<string, int> mw;
    rep(i, week.size()) {
        mw[week[i]] = i;
    }
    string s;
    cin >> s;
    cout << 7 - mw[s] << endl;
    return 0;
}


Measured memory_bytes: 256
from statistics import median

N = int(input())
items = list(map(int, input().split()))
items = [item - (k+1) for k, item in enumerate(items)]
items.sort()
ans = 0
for  i in range(len(items)):
  ans += abs(items[i]-items[N//2])
print(ans)

# n = int(input())
# a = list(map(int, input().split()))
# s = 0
# for i in range(n):
#     a[i] -= (i+1)
 
# a.sort()
# for i in range(n):
#     s += abs(a[i]-a[n//2])
 
# print(s)

Measured memory_bytes: 27364
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	if (n%k == 0)cout << 0;
	else
		cout << 1;
}



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

int main(){
    string a,b;
    cin >> a >> b;

    int A_nyuryokusu = stoi(b);
    int B_nyuryokusu = stoi(a);
    string A,B;
    for(int i=0;i<A_nyuryokusu;i++){
        A += a;
    }

    for(int i=0;i<B_nyuryokusu;i++){
        B += b;
    }

    if(A>=B) cout << B << endl;
    else cout << A <<endl; 
}

Measured memory_bytes: 256
K=int(input())
# K=15
lun=list(range(1,10))
i=0
while 1:
    ichi=lun[i]%10
    if ichi!=0:
        lun.append(lun[i]*10+ichi-1)
    lun.append(lun[i]*10+ichi)
    if ichi!=9:
        lun.append(lun[i]*10+ichi+1)
    i+=1
    if i==K:
        break
print(lun[i-1])


Measured memory_bytes: 15748
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair<int, int> pii;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=1; i<n; i++){
        cout << "? 1 " << i+1 << endl;
        cin >> a[i];
    }
    int lm_idx = max_element(a.begin(), a.end()) -a.begin();
    vector<int> ans(n);
    ans[0] = lm_idx+1;
    for(int i=0; i<n; i++){
        if(i == lm_idx) continue;
        cout << "? " << ans[0] << " " << i+1 << endl;
        int ret;
        cin >> ret;
        ans[ret] = i+1;
    }
    cout << "!";
    for(int i=0; i<n; i++){
        cout << " " << ans[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3672
from itertools import combinations
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,K,*A = map(int, read().split())

    ans = float('inf')
    for pattern in combinations(range(1,N), K-1):
        height = A[0]
        tmp = 0
        p_s = set(pattern)
        for i in range(1,N):
            if i in p_s:
                height += 1
                if A[i] >= height:
                    height = A[i]
                    continue
                tmp += height - A[i]
            height = max(height, A[i])
        ans = min(ans, tmp)
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep0(n) for (int i = 0; i < (int)(n); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define from1(obj) obj.begin() + 1, obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbp(p) cerr << #p << ":(" << p.first << ", " << p.second << ") "
#define dbpl(p) cerr << #p << ":(" << p.first << ", " << p.second << ")\n"
#define dbt3(t3) cerr << #t3 << ":(" << get<0>(t3) << ", " << get<1>(t3) << ", " << get<2>(t3) << ") "
#define dbt3l(t3) cerr << #t3 << ":(" << get<0>(t3) << ", " << get<1>(t3) << ", " << get<2>(t3) << ")\n"
#define dbt4(t4) cerr << #t4 << ":(" << get<0>(t4) << ", " << get<1>(t4) << ", " << get<2>(t4) << ", " << get<3>(t4) << ") "
#define dbt4l(t4) cerr << #t4 << ":(" << get<0>(t4) << ", " << get<1>(t4) << ", " << get<2>(t4) << ", " << get<3>(t4) << ")\n"
#define dbv(vec) cerr << #vec << ":{ "; for (auto e : vec) cerr << e << ", "; cerr << "}\n"
#define dbvp(vec) cerr << #vec << ":{ "; for (auto p : vec) cerr << "(" << p.first << ", " << p.second << "), "; cerr << "}\n"
#define dbvv(vv) cerr << #vv << ":{\n"; for (auto vec : vv) { cerr << "{ "; for (auto e : vec) cerr << e << ", "; cerr << "}\n"; } cerr << "}\n"
#define dbm(map) cerr << #map << ":{ "; for (auto p : map) cerr << "(" << p.first << ", " << p.second << "), "; cerr << "}\n"
#define YN(f) cout << (f ? "YES" : "NO") << "\n"
#define Yn(f) cout << (f ? "Yes" : "No") << "\n"
#define yn(f) cout << (f ? "yes" : "no") << "\n"
using ll = long long;
using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vb = vector<bool>;
using vvi = vector<vi>; using vvl = vector<vl>; using vvb = vector<vb>;
using pii = pair<int, int>; using pil = pair<int, ll> ; using pll = pair<ll, ll>; using pli = pair<ll, int>;
using vpii = vector<pii>; using vpll = vector<pll>;
using ti3 = tuple<int, int, int>; using tl3 = tuple<ll, ll, ll>;
using ti4 = tuple<int, int, int, int>; using tl4 = tuple<ll, ll, ll, ll>;
using mii = map<int, int>; using mil = map<int, ll>; using mll = map<ll, ll>; using mli = map<ll, int>;

const int INF = 1e8;
vi r, c;
vvi dp; // dp[i][j]:Ai~Ajのスカラー乗算の最小回数

int rec(int i, int j) {
	if (dp[i][j] != INF) return dp[i][j];
	int res = INF;
	rep2(k, i, j)	res = min(res, rec(i, k) + rec(k + 1, j) + r[i] * c[k] * c[j]);
	return dp[i][j] = res;
}

int main() {	
	// 行列の番号は0-ind, 0 ~ n-1
	int n; cin >> n;
	r.assign(n, 0); c.assign(n, 0);
	rep(i, n) cin >> r[i] >> c[i];
	dp.assign(n, {}); rep(i, n) dp[i].assign(n, INF);
	rep(i, n) rep(j, i + 1) dp[i][j] = 0;
	rep(i, n - 1) dp[i][i + 1] = r[i] * c[i] * c[i + 1];
	// dbvv(dp);
	rec(0, n - 1);
	// dbvv(dp);
	cout << dp[0][n - 1] << endl;
}


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

vector <int> two, three, six;
int n;
bool was;

void Print(int x)
{
	if (!was) was = true;
	else printf(" ");
	printf("%d", x);
}

int main()
{
	for (int i = 2; i <= 30000; i++)
		if (i % 6 == 0) six.push_back(i);
		else if (i % 2 == 0) two.push_back(i);
		else if (i % 3 == 0) three.push_back(i);
	scanf("%d", &n);
	if (n == 3) printf("2 5 63\n");
	else {
		int my2 = min(n - 2, int(two.size())) / 2 * 2;
		int my3 = min(n - my2, int(three.size())) / 2 * 2;
		int lft = n - my2 - my3;
		for (int i = 0; i < my2; i++)
			Print(two[i]);
		for (int i = 0; i < my3; i++)
			Print(three[i]);
		for (int i = 0; i < lft; i++)
			Print(six[i]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 512
using System;
    using System.Text;
    class Program
    {
        static void Main(string[] args)
        {
            int input = int.Parse(Console.ReadLine());
            int ret = 0;

            int count = input / 100;
            int mod = input % 100;

            int num;
            if (mod % 5 == 0)
            {
                num = mod / 5;
            }
            else
            {
                num = mod / 5 + 1;        
            }

            if (num <= count)
            {
                ret = 1;
            }

            Console.WriteLine(ret);

        }
    }

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[4], b[4]; cin>>a>>b;
	if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0]) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
n = int(input())
adjlis = []
for _ in range(n):
    lis=list(map(int,input().split()))
    adjlis.append(lis[2:])

visited = [False]*n
dislis = [n+1]*n
Q = [[1,0]]

def pull():
    return Q.pop(0)

def push(x):
    Q.append(x)

while len(Q)>0:
    cur = pull()
    curpoint = cur[0]
    count = cur[1]
    if not visited[curpoint-1]:
        visited[curpoint-1]=True
        dislis[curpoint-1] = count
        for i in adjlis[curpoint-1]:
            push([i,count+1])


for i in range(n):
    if dislis[i]==n+1:
        dislis[i] = -1
    print(i+1,dislis[i])
            


Measured memory_bytes: 5620
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
8
4
1
6
2
8
5
7
3

or

3
1
1
1

output:
4

or

1
"""

import sys
from bisect import bisect_left


def solve():
    dis_rec = [float('inf')] * array_length
    dis_rec[0] = array[0]
    length = 1

    for ele in array:
        if dis_rec[length - 1] < ele:
            dis_rec[length] = ele
            length += 1
        else:
            position = bisect_left(dis_rec, ele)
            dis_rec[position] = ele

    # display DIS
    # print(*dis_rec[:length])
    return length


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    array = list(map(int, _input[1:]))
    print(solve())

Measured memory_bytes: 19500
<?php
while( fscanf( STDIN, "%d", $n ) ){
  $cnt=0;
  for($a=0;$a<10;$a++){
    if($a>$n) break;
    for($b=0;$b<10;$b++){
      $t=$a+$b;
      if($t>$n) break;
      for($c=0;$c<10;$c++){
        $u=$t+$c;
        $d=$n-$u;
        if($d<0) continue;
        if($d>9) continue;
        ++$cnt;
      }
    }
  }
  printf("%d\n",$cnt);
}

Measured memory_bytes: 15064
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    
    int count = 0;
    
    if (s.substring(0, 1).equals("1")) {
      count ++;
    }
    if (s.substring(1, 2).equals("1")) {
      count ++;
    }
    if (s.substring(2, 3).equals("1")) {
      count ++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 21332
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;


int main() {
    llong a, b;
    llong d[] = {1, 1, 1, 1, 1};

    cin >> a >> b;
    d[a] = 0;
    d[b] = 0;

    if (d[1] == 1) cout << 1 << endl;
    if (d[2] == 1) cout << 2 << endl;
    if (d[3] == 1) cout << 3 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    string s;
    cin >> s;
    if(s[1] == 'B') cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(int i=0;i<N;++i)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(15);
  int N,K;cin >> N >> K;
  if(K==1) cout << 0 << endl;
  else cout << N-K << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){ 
  int r, g, b;
  cin >> r >> g >> b;
  int s = r*100 + g*10 + b;
  if (s % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main(){
    string s; int x;
    map<string, vector<int>> m;
    while(cin >> s >> x){
        m[s].emplace_back(x);
    }
    for (auto &&i : m) {
        sort(i.second.begin(),i.second.end());
        cout << i.first << "\n";
        for (int j = 0; j < i.second.size(); ++j) {
            if(j) printf(" ");
            printf("%d", i.second[j]);
        }
        puts("");
    }
    return 0;
}


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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 6e3 + 5;

int mod;

void add(int &a,int b)  {
    a += b;
    if (a >= mod)
        a -= mod;
}
void sub(int &a,int b)  {
    a -= b;
    if (a <  0)
        a += mod;
}
int mul(int a,int b)    {
    return  1ll * a * b % mod;
}
int Pow(int a,int b)    {
    int ans = 1;
    while (b)   {
        if(b & 1)   ans = mul(ans,a);
        a = mul(a,a);   b >>= 1;
    }
    return  ans;
}
int inv(int a,int p)    {
    return  a == 1 ? 1 : p - 1ll * p * inv(p % a,a) / a;
}

typedef pair<int,int>   ii;

int f[N][N];

int Fac[N];
int Inv[N];

int Ckn(int n,int k)    {
    if (n < k)  return  0;
    if (k < 0)  return  0;

    return  mul(Fac[n],mul(Inv[k],Inv[n - k]));
}

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

    int n;  cin >> n >> mod;

    Fac[0] = Inv[0] = 1;

    for(int i = 1 ; i < N ; ++i)    Fac[i] = mul(Fac[i - 1],i);     Inv[N - 1] = inv(Fac[N - 1],mod);
    for(int i = N - 2 ; i ; --i)    Inv[i] = mul(Inv[i + 1],i + 1);

    f[0][0] = 1;

    for(int i = 0 ; i < 3 * n ; ++i)
    for(int c = 0 ; c <= n ; ++c)   if (f[i][c])    {
        add(f[i + 1][c],f[i][c]);
        add(f[i + 2][c + 1],mul(f[i][c],i + 1));
        add(f[i + 3][c + 1],mul(f[i][c],(i + 1) * (i + 2)));
    }
    int ans = 0;

    for(int i = 0 ; i <= n ; ++i)
        add(ans,f[3 * n][i]);

    cout << ans << endl;
}

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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0, j = n - 1;;) {
		while (s[i] == 'R') i++;
		while (s[j] == 'W') j--;
		if (i < j) {
			s[i] = 'R';
			s[j] = 'W';
			ans++;
		}
		else break;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3696
import collections
_ = input()
A = collections.Counter(int(T) for T in input().split()).most_common()
Num4 = sum(A[T][1] for T in range(0,len(A)) if A[T][0]%4==0)
Num2 = sum(A[T][1] for T in range(0,len(A)) if A[T][0]%4!=0 and A[T][0]%2==0)
Odd  = sum(A[T][1] for T in range(0,len(A)) if A[T][0]%2!=0)
if Num2>0: Capacity = Num4
else: Capacity = Num4+1
if Capacity>=Odd: print('Yes')
else: print('No')

Measured memory_bytes: 28308
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  
  long x, y; rd(x, y);
  
  long count(long st, long ed){
    if(st>ed) return 0;
    long ret=1;
    while(st*2<=ed) st*=2, ret++;
    return ret;
  }

  writeln(max(count(x, y), count(x+1, y)));
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) write(e, " ");
  writeln();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
int n,x;
queue<int>q;
signed main(){
	cin>>n>>x;
	if(x==1||x==2*n-1){
		puts("No");
		return 0;
	}
	puts("Yes");
	
	for(int i=1;i<=2*n-1;i++){
		if(abs(x-i)>1)q.push(i);
	}
	for(int i=1;i<=2*n-1;i++){
		if(i==n)cout<<x<<endl;
		else if(i==n-1)cout<<x+1<<endl;
		else if(i==n+1)cout<<x-1<<endl;
		else{
			cout<<q.front()<<endl;
			q.pop();
		}
	}
	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)

#define WHITE 1//（未訪問）
#define GRAY 2//（訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3//（訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) //10^21
int M[N][N];//隣接行列
int color[N];

//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    int h[n];
    rep(i, n){
        cin >> h[i];
    }
    bool end_flg = false;
    bool seq_judge = false;
    bool now_judge = false;
    int cnt = 0;
    while(!end_flg){
        end_flg = true;
        seq_judge = false;
        rep(i, n){
            if(h[i] > 0){
                now_judge = true;
                end_flg = false;
            }else{
                now_judge = false;
            }
            
            //連続してtrue
            if(seq_judge){
                if(now_judge){
                    h[i]--;
                    seq_judge = true;
                    
                    if(i == n - 1){
                        cnt++;
                        seq_judge = true;
                    }
                }else{
                    cnt++;
                    seq_judge = false;
                }
            //先ほどはfalse
            }else{
                if(now_judge){
                    h[i]--;
                    seq_judge = true;
                    
                    if(i == n - 1){
                        cnt++;
                        seq_judge = false;
                    }
                }else{
                    seq_judge = false;
                }
            }
        }
        //printArray(h, n);
    }
    cout << cnt << endl;
}

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

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

  long long int res=1e15;
  for(int k=0;k<2;k++){
    long long int score=0;
    long long int sum=0;
    for(int i=0;i<n;i++){
      if((i+k)%2==0){
	//sum+a[i] must higher than 0
	if(sum+a[i]<=0){
	  score+=-(sum+a[i])+1;
	  sum=1;
	}
	else{
	  sum+=a[i];
	}
      }
      else{
	if(sum+a[i]>=0){
	  score+=(sum+a[i])+1;
	  sum=-1;
	}
	else{
	  sum+=a[i];
	}
      }

    }
    res=min(res,score);
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 640
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

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

int n,a[N];
signed main(){
    FastIO;
    cin>>n;
    ll sum=0;
    rep(i,1,n){
        cin>>a[i];
        sum=(sum+a[i])%mod;
    }
    ll ans=0;
    rep(i,1,n){
        sum=(sum-a[i]+mod)%mod;
        ans=(ans+a[i]*sum)%mod;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4432