akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

int main(void) {
	string str;
	cin >> str;
	bool find = false;
	int s,t;
	s = t = -1;
	for (int i = 0; !find && i < str.length()-1; ++i) {
		if (str[i] == str[i+1]) {
			find = true;
			s = i+1;
			t = i+2;
		}
		if (i < str.length()-2 && str[i] == str[i+2]) {
			find = true;
			s = i+1;
			t = i+3;
		}
	}
	cout << s << " " << t << endl;
	return 0;
}


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

int main(){
int N, M;
cin >> N >> M;

vector<int> hw(M);
int hwday = 0;
for (int i = 0; i < M; i++)
{
    cin >> hw.at(i);
    hwday += hw.at(i);
}

int plday = N - hwday;

if (plday < 0)
{
    cout << -1 << endl;
    
}
else{
        cout << plday << endl;
    }




}

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

const int INF = 1e+9 * 2;
double eps = 1e-10;

int H = 10, W = 10;
int size[] = {5, 9, 13};
int dx[] = {0, 1, -1, 0, 0, 1, 1, -1, -1, 2, -2, 0, 0};
int dy[] = {0, 0, 0, 1, -1, 1, -1, 1, -1, 0, 0, 2, -2};

int main() {
	int x, y, s;
	int cnt[16][16] = {0};
	while(scanf("%d,%d,%d", &x, &y, &s) != EOF){
		s--;
		for(int i = 0; i < size[s]; ++i){
			cnt[x + dx[i]][y + dy[i]]++;
		}
	}
			int ans_c = 0, ans_m = 0;
		for(int i = 0; i < 10; ++i){
			for(int j = 0; j < 10; ++j){
				if(cnt[i][j] == 0)
					ans_c++;
				if(cnt[i][j] > ans_m)
					ans_m = cnt[i][j];
			}
		}
		cout << ans_c << endl;
		cout << ans_m << endl;
	return 0;
}

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

int main(void){
    int N,sum=0;
    cin>>N;
    int C[N],V[N];
    for(int i=0;i<N;i++){
        cin>>V[i];
    }
    for(int i=0;i<N;i++){
        cin>>C[i];
        int rieki=V[i]-C[i];
        if(rieki>0)
            sum+=rieki;;
    }
    cout<<sum<<endl;
    return 0;
}


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

using namespace std;

#define pb push_back
#define F first
#define S second
#define ALL(v) v.begin(),v.end()
#define fast_cin() ios_base::sync_with_stdio(0)

typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;

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

int faltu;

const int mod = 1e9+7;
const ll MAX = 4e18;
const ll MIN = -MAX;
const int imax = 2e9 + 100;

pair <vector <pll> , bool> solve_inc(vector <ll> a, int n)
{
	vector <pll> vec;
	int count_operations = 0;
	for(int i = 2; i <= n;)
	{
		if(a[i] >= a[i - 1])
		{
			i ++;
			continue;
		}
		if(count_operations > 2 * n)
			return {vector <pll> (), false};
		ll last = a[i - 1], mn = *max_element(ALL(a)), mnidx = (max_element(ALL(a)) - a.begin());
		for(int j = 1; j <= n; j++)
		{
			if(a[i] + a[j] >= last and a[j] < mn)
			{
				mn = a[j];
				mnidx = j;
			}
		}
		a[i] += a[mnidx];
		vec.pb({mnidx, i});
		count_operations ++;

	}
	return {vec, true};
}

pair <vector <pll>, bool> solve_dec(vector <ll> a, int n)
{
	vector <pll> vec;
	int count_operations = 0;
	for(int i = n - 1; i >= 1;)
	{
		if(a[i] <= a[i + 1])
		{
			i --;
			continue;
		}
		if(count_operations > 2 * n)
			return {vector <pll> (), false};
		ll last = a[i + 1], mx = *min_element(ALL(a)), mxidx = (min_element(ALL(a)) - a.begin());
		for(int j = 1; j <= n; j++)
		{
			if(a[i] + a[j] <= last and a[j] > mx)
			{
				mx = a[j];
				mxidx = j;
			}
		}
		a[i] += a[mxidx];
		vec.pb({mxidx, i});
		count_operations ++;
	}
	return {vec, true};
}

int main()
{
	time_t t1, t2;
	t1 = clock();

	int n;
	cin >> n;
	vector <ll> a(n + 1);
	for(int i = 1; i <= n; i++)
		cin >> a[i];

	pair <vector <pll>, bool> vec = solve_inc(a, n);
	if(vec.S == false)
		vec = solve_dec(a, n);

	if(vec.S)
	{
		cout << vec.F.size() << endl;
		for(auto &x: vec.F)
			cout << x.F << ' ' << x.S << endl;
	}

	t2 = clock();
	cerr << "time taken: " << t2 - t1 << endl;
	return 0;
}

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

vector<int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	string s;
	cin >> s;
	if(s[0] == 'S'){
		cout << "Cloudy" << endl;
	}else if(s[0] == 'C'){
		cout << "Rainy" << endl;
	}else{
		cout << "Sunny" << endl;
	}
}

Measured memory_bytes: 3596
#!/usr/bin/env python3

def main():
    N = int(input())
    A = list(map(int, ('0 ' + input() + ' 0').split()))

    c = 0
    for i in range(N + 1):
        c += abs(A[i + 1] - A[i])

    for i in range(1, N + 1):
        r = c - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1])
        print(r)


if __name__ == '__main__':
    main()



Measured memory_bytes: 14176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int R;
  cin >> N >> R;
  int Rin;
  if(N < 10){
    Rin = R + 100*(10-N);
  }
  else{
    Rin = R;
  }
  cout << Rin << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll a, b, c;
  cin >> a >> b >> c;
  
  ll d, e, f;
  cin >> d >> e >> f;
  
  vector<int> tukureru(f + 1, 0);
  for (int i = 0; i < f + 1; i++){
    for (int j = 0; j < f + 1; j++){
      if (c * i + d * j > f){
        break;
      }
      tukureru[c * i + d * j] = c * i + d * j;
    }
  }
  for (int i = 1; i <= f; i++){
    if (tukureru[i] == 0){
      tukureru[i] = tukureru[i-1];
    }
  }


  double noudo = 0;
  ll mizu, sato;
  int ok = 0;
  for (int i = 0; i <= 30; i++){
    for (int j = 0; j <= 30; j++){
      ll m = min(f - 100*a*i - 100*b*j, (a*i + b*j)*e);
      if (m < 0){
        break;
      }
      if (!ok && (i != 0 || j != 0)){
        mizu = 100*a*i + 100*b*j;
        sato = 0;
        ok = 1;
      }
      ll n = tukureru[m];
      double nownoudo = 100.0 * n / (100*a*i + 100*b*j + n);
      if (nownoudo > noudo){
        noudo = nownoudo;
        mizu = 100*a*i + 100*b*j;
        sato = n;
      }
    }
  }

  cout << mizu + sato << " " << sato << endl;

  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int S[10],C[10];
int p10[5];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	p10[0]=1;
	p10[1]=10;
	p10[2]=100;
	p10[3]=1000;
	p10[4]=10000;
	
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>S[i]>>C[i];
		S[i]=N-S[i];
	}
	for(i=(N==1?0:p10[N-1]);i<p10[N];i++) {
		int ng=0;
		FOR(j,M) if(i/p10[S[j]]%10!=C[j]) ng++;
		if(ng==0) return _P("%d\n",i);
	}
	cout<<-1<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		char[] str = sc.next().toCharArray();
		int max = -1;
		for(int i = 1; i < n; i++) {
			List<Character> listA = new ArrayList<>();
			List<Character> listB = new ArrayList<>();
			int cnt = 0;
			for(int j = 0; j < i; j++) {
				if(!listA.contains(str[j]))
					listA.add(str[j]);
			}
			for(int j = i; j < n; j++) {
				if(!listB.contains(str[j]))
					listB.add(str[j]);
			}
			for(int j = 0; j < listA.size(); j++) {
				char c = listA.get(j);
				if (listB.contains(c))
					cnt++;
			}
			if (cnt > max) max = cnt;		
		}
		out.println(max);
		
		out.close();
	}
	  private static long gcd(long m, long n) {
		    if(m < n) return gcd(n, m);
		    if(n == 0) return m;
		    return gcd(n, m % n);
		}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

Measured memory_bytes: 23124
N = int(input())
a_list = [int(input()) for i in range(N)]
_a_list = a_list[::]
_a_list.sort(reverse=True)
first =  _a_list[0]
second = _a_list[1]

for i in range(N):
    if a_list[i] == first:
        print(second)
    else:
        print(first)

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

using namespace std;

int main(){
    long long N;
    cin >> N;
    long long arr[N];
    long long cnt[N + 1] = {0};
    for(long long i = 0; i < N; i++){
        cin >> arr[i];
    }
    for(long long i = 0; i < N; i++){
        cnt[arr[i]]++;
    }
    long long x[N + 1] = {0}, sum = 0;
    for(long long i = 1; i <= N; i++){
        x[i] = cnt[i] * (cnt[i] - 1) / 2;
        sum += x[i];
    }
    for(long long i = 0; i < N; i++){
        long long y = cnt[arr[i]] - 1;
        long long ans = sum - x[arr[i]] + y * (y - 1) / 2;
        cout << ans << endl;
    }
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 100005;

int n;
int p[N];
vi adj[N];

int dfs(int cur) {
	vi match;
	for (int to : adj[cur]) {
		match.pb(dfs(to));
	}
	sort(rall(match));
	int res = 0;
	for (int i = 0; i < SZ(match); i++)
		res = max(res, match[i] + i + 1);
	return res;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n;
	for (int i = 1; i < n; i++) {
		cin >> p[i];
		p[i]--;
		adj[p[i]].pb(i);
	}
	cout << dfs(0) << endl;
	return 0;
}


Measured memory_bytes: 15488
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  cout<<(n-1)/(k-1)+((n-1)%(k-1)+k-2)/(k-1)<<endl;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())
s = input()

b_cnt = 0
ab_cnt = 0
for i in s:
    if i == "a":
        if ab_cnt < a + b:
            ab_cnt += 1
            print("Yes")
        else:
            print("No")
    elif i == "b":
        if ab_cnt < a + b and b_cnt < b:
            ab_cnt += 1
            b_cnt += 1
            print("Yes")
        else:
            print("No")
    else:
        print("No")


Measured memory_bytes: 53208
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>

using namespace std;

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


bool memo[8000000];
int m, n;

void furui(int n, int count)
{
	fill(memo,memo+8000000,true);

	int cnt=0;
	for(int i=m;i<=m+n;i++){
		if(memo[i-m]){
			memo[i-m]=false;
			for(int j=2*i;j<=n;j+=i){
				memo[j-m]=false;
			}
			cnt++;
			break;
			if(cnt==count)return;
		}

	}
	return;
}

int main()
{
	while(cin>>m>>n){
		if(m==0&&n==0)return 0;
		fill(memo,memo+8000000,true);

		int l=m;
		for(int k=0;k<n;k++){
			for(int i=l;i<=8000000;i++){
				if(memo[i-m]){
					l=i;
					memo[i-m]=false;
					for(int j=((m+i-1)/i)*i;j<=8000000;j+=i){
						memo[j-m]=false;
					}
					break;
				}
			}
			/*
			for(int i=m;i<=13;i++){
				cout<<i<<" memo[i-m]:"<<memo[i-m]<<" ";
			}
			cout<<endl;
			*/
		}
		for(int i=0;i<=8000000;i++){
			if(memo[i]){
				cout<<i+m<<endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 10880
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    int sum,f=0;
    cin>>sum;
    if(sum%4==0)
    {
        cout<<"Yes"<<endl;
        f=1;
    }
    else
    {
        int k=sum/4,i=0,num;
        while(i<=k)
        {
            num=i*4;
            int t=sum-num;
            if(t%7==0)
            {
                cout<<"Yes"<<endl;
                f=1;
                break;
            }
            else
            {
                num=0;
            }
            i++;
        }
    }
    if(f==0)
        cout<<"No"<<endl;
}



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

using namespace std;
int main() {
	int N, s ,min = 1000;
	long long int ans = 0;
	bool flag = true;
	cin >> N;
	for (int i = 0; i < N;i++) {
		cin >> s;
		ans += s;
		if (s%10 != 0) {
			flag = false;
			if (s < min) {
				min = s;
			}
		}
	}
	if (flag) {
		ans = 0;
	}
	else if(ans%10 == 0){
		ans -= min;
	}

	cout << ans << endl;

	return 0;
}



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

namespace Competitive
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());

            var digits = new List<int>();
            while (N > 0)
            {
                int n = (int)(N % 10);
                digits.Add(n);
                N /= 10;
            }

            bool flag = true;
            for (int i = 0; i < digits.Count - 1; i++)
            {
                if (digits[i] != 9) flag = false;
            }
            
            int ret = 0;
            for (int i = 0; i < digits.Count - 1; i++)
            {
                ret += 9;
            }
            ret += digits[digits.Count - 1];
            if (!flag) ret -= 1;
            
            Console.WriteLine(ret);


        }
    }
}

Measured memory_bytes: 11092
#include <stdio.h>


int main ()

{

    long long int a,b,c,i;

while(scanf("%lld %lld",&a,&b)!=EOF)
{   i=0;
    c=a+b;
    while(c>0)
    {
        c=c/10;
        i++;
    }
    printf("%lld\n",i);

}

return 0;
}



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

int abs(int x){
  if(x<0) return -x;
  else return x;
}

int main() {
    int N;
    cin >> N;
    vector<int> num(N);
    int a;
    for(int i=0;i<N;i++){
        cin >> a;
        num[i]=a-i-1;
    }
    sort(num.begin(),num.end());
    long long mid,ans=0;
    mid=num[(N-1)/2];

    for(int i=0;i<N;i++){
        ans+=abs(num[i]-mid);
    }
    cout << ans << endl;
}


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

int main(void) {
    int n;
    cin >> n;
    int ans = 1;
    int mcnt = 0;
    for (int num = 1; num <= n; num++) {
        int cnt = 0;
        int i = num;
        while (i % 2 == 0) {
            i /= 2;
            cnt++;
        }
        if (mcnt < cnt) {
            mcnt = cnt;
            ans = num;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
 		
int main() {
	
	int N,M,X;
	map<int,int> S;
	cin>>N>>M>>X;
	fx(M){
		int m;
		cin>>m;
		S[m]++;
	}
	int ans1=0,ans2=0;
	fx(X){
		if(S[x]>0){ans1++;}
	}
	fyg(N+1,X+1){
		if(S[y]>0){ans2++;}
	}
	ce(min(ans1,ans2))
	
}

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

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

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

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

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

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

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

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

fn main() {
    input!{
        w:i32,
        _a:i32,
        _b:i32
    }
    let mut a = _a;
    let mut b = _b;
    if a > b{
        swap(&mut a, &mut b);
    }
    let mut ans:i32 = b - (a+w);
    println!("{}",max(0, ans));
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cmath>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

const int p=998244353;
int n,x[210],y[210],pow2[210],ans;
bool flag[210][210];
struct data
{
    int id;
    double agl;
    bool operator<(const data &t) const
    {
        return agl<t.agl;
    }
} a[210];

double get(int y,int x)
{
    if (y<0 || !y && x<0)
        return atan2(-y,-x);
    return atan2(y,x);
}

int main()
{
    scanf("%d",&n);
    repu(i,1,n)
        scanf("%d%d",&x[i],&y[i]);
    pow2[0]=1;
    repu(i,1,n)
        pow2[i]=pow2[i-1]*2%p;
    ans=(pow2[n]+p-n-1)%p;
    repu(i,1,n)
    {
        int m=0;
        repu(j,i+1,n)
            a[++m]=(data){j,get(y[j]-y[i],x[j]-x[i])};
        sort(a+1,a+1+m);
        for (int j=1,k; j<=m; j=k)
        {
            for (k=j+1; k<=m && a[k].agl==a[j].agl; ++k);
            if (!flag[i][a[j].id])
            {
                (ans+=p-pow2[k-j+1]+k-j+2)%=p;
                repu(ii,j,k-1)
                {
                    flag[i][a[ii].id]=flag[a[ii].id][i]=1;
                    repu(jj,ii+1,k-1)
                        flag[a[ii].id][a[jj].id]=flag[a[jj].id][a[ii].id]=1;
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define N 131072
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
int mod=1e9+7;
LL f_pow(LL a,LL b){
    LL res=1,temp=a;
    while(b){
        if(b&1)res=res*temp%mod;
        temp=temp*temp%mod;
        b>>=1;
    }
    return res;
}
LL fra[200005];
LL rev[200005];
void build(){
    fra[0]=1;
    for(int i = 1;i<=200002;i++)
        fra[i]=fra[i-1]*i%mod;
    rev[200000]=f_pow(fra[200000],mod-2);
    for(int i = 199999;i>=0;i--)
    rev[i]=rev[i+1]*(i+1)%mod;
}
LL C(int a,int b){
   // printf("%lld %lld %lld %lld %lld\n",a,b,fra[a],rev[b],rev[a-b]);
    return fra[a]*rev[b]%mod*rev[a-b]%mod;
}
int main(){
    build();
    LL n,a,b,c;
    scanf("%lld %lld %lld %lld",&n,&a,&b,&c);
    LL mon=(100-c)*f_pow(100,mod-2)%mod;
    mon = f_pow(mon,mod-2);
    LL temp=a+b;
    a = a*f_pow(temp,mod-2)%mod;
    b = b*f_pow(temp,mod-2)%mod;
   // printf("%lld %lld %lld\n",a,b,mon);
    LL ans = 0;
    for(int i = 0;i<n;i++){
     //   printf("%lld\n",C(n-1+i,i));
        ans+=f_pow(a,n)*f_pow(b,i)%mod*C(n-1+i,i)%mod*mon%mod*(n+i)%mod;
      //  printf("%lld\n",ans);
        
        ans+=f_pow(a,i)*f_pow(b,n)%mod*C(n-1+i,i)%mod*mon%mod*(n+i)%mod;
      //  printf("%lld\n",ans);
        ans%=mod;
    }

    printf("%lld\n",ans);
}
/*
1 4 2 3
1 3 6 12
k(a+b) = a*b;
k*a+k*b = a*b;
b= (k*a)/(a-k);

k*(k+i)/i
*/

Measured memory_bytes: 3328
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    vector<int> H(N, 0);
    for (int i = 0; i < N; ++i) cin >> H[i];
    int cnt = 1;
    for (int i = 1; i < N; ++i) {
        bool T = true;
        for (int j = 0; j < i; ++j) {
            if (H[j] > H[i]) {
                T = false; break;
            }
        }
        if (T) cnt++;
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 3676
#include <stdio.h>

int main( void ){
// reader counts
  int intN;
  char strA[101];
  char strB[101];
  char strC[101];

scanf("%d %s %s %s" ,&intN, strA, strB, strC );

  int intSousa=0;
  int intCnt;

  
  for(intCnt=1;intCnt<=intN;intCnt++){
    if (( strA[intCnt-1]==strB[intCnt-1] ) && ( strB[intCnt-1]==strC[intCnt-1]  ) ){ 
      //printf("Ok\n");
    } else  if (( strA[intCnt-1]==strB[intCnt-1] ) && ( strB[intCnt-1]!=strC[intCnt-1]  ) ){
      //printf("A=B<>C\n");
      intSousa++;
    } else  if (( strA[intCnt-1]!=strB[intCnt-1] ) && ( strB[intCnt-1]==strC[intCnt-1]  ) ){
      //printf("A<>B=C\n");
      intSousa++;
    } else  if (( strA[intCnt-1]!=strB[intCnt-1] ) && ( strB[intCnt-1]!=strC[intCnt-1]  ) ){
       if ( strA[intCnt-1]==strC[intCnt-1] ) {
        //printf("A<>B<>C & A=C, \n");
         intSousa++;
       }else{
        //printf("A<>B<>C & A<>C, \n");
        intSousa++;
        intSousa++;
      }
    }
}
printf("%d\n",intSousa);

return 0;
}



Measured memory_bytes: 128
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: usize = read();
    let mut cnt: Vec<usize> = vec![0; 100010];
    let a: Vec<usize> = readnc();
    for ai in a {
        cnt[ai] += 1;
    }

    let mut ans = 0;
    let mut odd = 0;
    for i in 0..cnt.len() {
        if cnt[i] >= 2 {
            let dup = cnt[i] - 1;
            ans += dup / 2;
            odd += dup % 2;
        }
    }
    ans += (odd + 1) / 2;
    println!("{}", n - ans * 2);
}

Measured memory_bytes: 6396
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

LL H,W,h,w;

int main(){
    cin >> H >> W >> h >> w;

    if (H%h==0 && W%w==0){
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";
    int i,j;
    LL k=(1000000000LL-1)/(h*w-1);
    for (i=1; i<=H; i++,cout << "\n")
        for (j=1; j<=W; j++)
            if (i%h==0 && j%w==0) cout << -(k*(h*w-1)+1) << " ";
            else cout << k << " ";

    return 0;
}


Measured memory_bytes: 2944
// https://atcoder.jp/contests/dp/tasks/dp_u

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%d%c", a[i][j], j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 16;
const int A_IJ_MAX = 1e9;

const int S_MAX = 1 << N_MAX;
const ll INF = 1e18;

int N;
int a[N_MAX][N_MAX];

int S;
ll b[S_MAX];

ll memo[S_MAX];

ll memoize(int sup);

void make_score(int i, int s) {
  if (i == N) return;
  make_score(i + 1, s);
  ll b2 = b[s];
  int s2 = s | 1 << i;
  REP(j, i) if (s >> j & 1 > 0) b2 += a[i][j];
  b[s2] = b2;
  make_score(i + 1, s2);
}

ll memoize(int sup) {
  if (memo[sup] > -INF) return memo[sup];
  memo[sup] = b[sup];
  if (sup == 0) return memo[sup];
  int sup2 = sup & ~(-sup & sup);
  if (sup2 == 0) return memo[sup];
  int sub = sup2;
  do {
    memo[sup] = max(memo[sup], memoize(sub) + memoize(sup & ~sub));
    sub = (sub - 1) & sup2;
  } while (sub != sup2);
  return memo[sup];
}

void solve() {
  S = 1 << N;
  make_score(0, 0);
  // DUMP(b, S);

  fill(memo, memo + S, -INF);
  memoize(S - 1);
  // DUMP(memo, S);
  printf("%lld\n", memo[S - 1]);
}

void input() {
  scanf("%d", &N);
  REP(i, N) REP(j, N) scanf("%d", &a[i][j]);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 1280
#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];
    int q;
    cin >> q;
    vector<int> m(q);
    for (int i=0; i<q; i++) cin >> m[i];

    vector<bool> ans(q, false);
    for (int i=0; i<(1<<n); i++)
    {
        int sum=0;
        for (int j=0; j<n; j++)
        {
            if (i&(1<<j)) sum+=A[j];
        }
        for (int j=0; j<q; j++)
        {
            if(sum==m[j]) ans[j]=true;
        }
    }

    for (int i=0; i<q; i++)
    {
        if (ans[i]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


Measured memory_bytes: 3128
// finish date: 2018/01/24
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define bigmod 1000000007
#define INF 500000000


int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    int suger_goal;
    int maxSW = -1, maxS = -1;
    rep(i, 31) {
        int j = 0;
        if (i == 0) j = 1;
        while (100*(A * i + B * j) <= F) {
            suger_goal = (A * i + B * j) * E;
            rep(k, 31) {
                int l = 0;
                while (C * k + D * l <= suger_goal) {
//                    int iii = (100 * C * k + D * l);
//                    int jjj = ((A * i + B * j) * 100 + C * k + D * l);
//                    double aaa = (double) (100 * (C * k + D * l)) / ((A * i + B * j) * 100 + C * k + D * l);
//                    double bbb = (double) (100 * maxS) / maxSW;
                    if (maxSW == -1 || (double) (100 * (C * k + D * l)) / ((A * i + B * j) * 100 + C * k + D * l) >
                                       (double) (100 * maxS) / maxSW) {
                        if ((A * i + B * j) * 100 + C * k + D * l <= F) {
                            maxSW = (A * i + B * j) * 100 + C * k + D * l;
                            maxS = C * k + D * l;
                        }
                    }
                    l++;
                }
            }
            j++;
        }
    }
    cout << maxSW << " " << maxS << endl;

    return 0;
}



Measured memory_bytes: 256
read s

c0=`echo $s | grep -o '0' | wc -l`
c1=`echo $s | grep -o '1' | wc -l`

if [[ $c0 < $c1 ]]; then
    echo `expr $c0 \* 2`
else
    echo `expr $c1 \* 2`
fi


Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

ll gcd(ll a, ll b)
{
    if (a%b == 0)
        return(b);
    else
        return(gcd(b, a%b));
}

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


int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    ll cnt = b-a+1;
    ll a_c = a / c;
    ll a_d = a / d;
    ll a_cd = a / (lcm(c,d));

// cout << a_c << " " << a_d << endl;
    ll b_c = b / c;
    ll b_d = b / d;
    
// cout << b_c << " " << b_d << endl;
    ll b_cd = b / (lcm(c,d));

    ll kc = b_c-a_c;
    ll kd = b_d-a_d;
    ll kcd = b_cd-a_cd;

    if(a%c==0)kc++;
    if(a%d==0)kd++;
    if(a%(lcm(c,d)) == 0) kcd++;
// cout << kc << " " << kd << " " << kcd << endl;
    ll tmp = cnt -(kc+kd) + kcd ;
    cout << tmp << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;

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

using i64=long long;

i64 calc(i64 a, i64 b, i64 c){
  return abs(a)+abs(b)+abs(c);
}

int main(){

  int n, m; cin>> n>> m;
  vector<i64> x(n), y(n), z(n);
  rep(i, n) cin>> x[i]>> y[i]>> z[i];

  i64 mx=0;
  rep(bit, (1<<3)){
    int o1=(bit&1) ? 1 : -1,
        o2=(bit&2) ? 1 : -1,
        o3=(bit&4) ? 1 : -1;
    vector<i64> arr;
    rep(i, n) arr.push_back(x[i]*o1+y[i]*o2+z[i]*o3);
    sort(arr.rbegin(), arr.rend());
    i64 sum=0;
    rep(i, m) sum+=arr[i];
    mx=max(mx, sum);
  }

  cout<< mx<< endl;

  return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <fstream>
#include <iostream>
#include <algorithm>
#define ll long long
#define ull unsigned long long
#define pii pair <int, int>
#define rep(i,n) for (int i = 0; i < (int) (n); ++ i)
using namespace std;

namespace IO {
	const int BUF_SIZE = 1 << 13;
	char IBUF[BUF_SIZE];
	char *PIBUF = IBUF + BUF_SIZE - 1;

	inline int getchar() {
		if (++ PIBUF == IBUF + BUF_SIZE)
			fread(PIBUF = IBUF, 1, BUF_SIZE, stdin);
		return *PIBUF;
	}
}

#define getchar()  IO :: getchar()

template <typename T>
inline void getint(T &x) {
	x = 0;
	int b = 1, c = getchar();
	for (;!isdigit(c); c = getchar()) if (c == '-') b = -b;
	for (; isdigit(c); c = getchar()) x = (x<<3) + (x<<1) + (c^48);
	x *= b;
}

inline
void getstr(char *s) {
	int c = getchar();
	for (; isspace(c); c = getchar());
	for (;!isspace(c); c = getchar()) *s = c, ++ s;
	*s = 0;
}

const int M = 20;
const int N = 1 << 20;
int n, l, q;
int x[N];
int go[M][N];

int main() {
	scanf("%d", &n);
	rep(i, n) scanf("%d", &x[i]);
	scanf("%d", &l);
	rep(i, n) go[0][i] = upper_bound(x, x + n, x[i] + l) - x - 1;
	for (int j = 1; j < M; ++ j) rep(i, n) go[j][i] = go[j - 1][go[j - 1][i]];
	scanf("%d", &q);
	rep(tc, q) {
		int a, b; scanf("%d%d", &a, &b);
		if (a > b) swap(a, b);
		-- a, -- b;
		int ans = 0;
		for (int j = M - 1; j >= 0; -- j) if (go[j][a] < b) {
			ans += 1 << j;
			a = go[j][a];
		}
		printf("%d\n", ans + 1);
	}
	return 0;
}

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

int main(){
  int i,j,cnt=0;
  int n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  int mi=INT_MAX;
  for(i=0;i<n;i++){
    if(mi>max(a[n-1]-2*a[i],2*a[i]-a[n-1])){
      mi=max(a[n-1]-2*a[i],2*a[i]-a[n-1]);
      cnt=i;
    }
  }
  cout<<a[n-1]<<" "<<a[cnt];
}

Measured memory_bytes: 640
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 07-Mar-20 1:18:16 PM
	flamers will **** you
*/
//#include<flamers.h>

#include "bits/stdc++.h"
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define PB push_back
#define POB pop_back

using namespace std;

int main(){
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie();
	int a, b;
	cin>>a>>b;
	bool flag = false;
	for(int i = 1; i <= 1e4; i++) {
		if((int)(i * 0.08) == a && (int)(i * 0.1) == b) {
			flag = true;
			cout<<i<<endl;	
			break;
		}
	}
	if(!flag) cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256
#abc128b

n=int(raw_input())
l=[]
for i in xrange(n):
 c,p=map(str,raw_input().split())
 l.append([i+1,c,int(p)])
ll=sorted(l,key=lambda x:(x[1],-x[2]))
for i in xrange(n):
 print ll[i][0]


Measured memory_bytes: 2568
import java.util.Scanner;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int e[] = new int[a];
    int b[] = new int[a];
    int c[] = new int[a-1];
    int d = 0;
    int s = 0;
    for(int i = 0; i < a; i++){
      e[i] = sc.nextInt();
      if(i != 0){
        while(e[i] == e[i-1]){
          e[i] = sc.nextInt();
        }
      }
    }
    for(int i = 0; i < a; i++){
      b[i] = sc.nextInt();
    }
    for(int i = 0; i < a - 1; i++){
      c[i] = sc.nextInt();
    }
    for(int i = 0; i < a; i++){
      s = s + b[e[i]-1];
      if(d == e[i]-1 && i != 0){
        s = s + c[e[i-1]-1];
      }
      d = e[i];
    }
    System.out.println(s);
  }
}

Measured memory_bytes: 23380
#include<stdio.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2


int n, M[N][N];
int color[N],d[N],f[N],tt;


void dfs_visit(int u)
{
  int v;
  color[u] = GRAY;
  d[u] = ++tt;

  for(v = 0; v < n; v++)
    {
      if(M[u][v] == 0)continue;
      if(color[v] == WHITE)
	{
	  dfs_visit(v);
	}
    }

  color[u] = BLACK;
  f[u] = ++tt;

}

void dfs()
{
  int u;

  for(u = 0; u < n; u++)
    {
      color[u] = WHITE;
    }

  tt = 0;

   for(u = 0; u < n; u++)
     {
       if(color[u] == WHITE)dfs_visit(u);
     }
   for(u = 0; u < n; u++)
     {
       printf("%d %d %d\n",u+1,d[u],f[u]);
     }
}


int main()
{
  int u,v,k,i,j;

  scanf("%d",&n);

  for(i = 0; i < n; i++)
    {
      for(j = 0; j < n; j++)
	{
	  M[i][j] = 0;
	}
    }

  for(i = 0; i < n; i++)
    {
      scanf("%d %d",&u,&k);
      u--;
      for(j = 0; j < k; j++)
	{
	  scanf("%d",&v);
	  v--;
	  M[u][v] = 1;
	}
    }

  dfs();

  return 0;

}



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

#define V vector
typedef long long ll;

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define f(i,a) for(int i = 0 ; i < a ; i++)
#define ff first
#define ss second
#define all(x) (x).begin() ,(x).end()

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1



int main() {


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

	int t = 1;
	//cin >> t;

	while (t--)
	{
		int n , cnt = 0;
		string s;
		cin >> n >> s;

		int l = 0 , r = n - 1;

		while (l < n and s[l] == 'R')
			l++;
		while (r >= 0 and s[r] == 'W')
			r--;

		if (l >= n - 1 or r <= 0)
		{
			cout << "0\n";
			return 0;
		}

		while (l < r )
		{
			if (s[l] == 'W' and s[r] == 'R')
				swap(s[l] , s[r]) , cnt++ , l++ , r--;
			else if (s[l] == 'R') l++;
			else
				r--;
		}

		cout << cnt << "\n";
	}

	return 0;
}





Measured memory_bytes: 3712
#include <iostream>

using namespace std;

int main() {
	int N, D, ans;

	cin >> N >> D >> ans;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;

		ans += 1 + (D - 1) / A;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = numeric_limits<ll>::max();;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll T;
  cin >> T;
  
  while(T--){
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    vector<Pll> p(0);
    p.push_back(Pll(2LL, A)); p.push_back(Pll(3LL, B)); p.push_back(Pll(5LL, C));
    map<ll, ll> memo;
    memo[0LL] = 0LL;
    function<ll(ll)> func = [&](ll NN){
      if(memo.count(NN)) return memo[NN];
      if(NN == 1) return memo[1] = D;

      ll ans;
      if(INF / NN <= D) ans = INF;
      else ans = NN * D;

      for(int i = 0; i < 3; i++){
        ll div = p.at(i).first;
        ll cost = p.at(i).second;
        ll m = NN % div;
        chmin(ans, m * D + cost + func((NN-m)/div));
        if(m == 0) continue;
        ll n = div - m;
        chmin(ans, n * D + cost + func((NN+n)/div));
      }

      return memo[NN] = ans;
    };
    cout << func(N) << endl;
  }
}


Measured memory_bytes: 4404
<?php
function chmin($a, $b) {
    if ($a > $b){
        return $b;  # PHPは値をreturnしてそれを受け取らないと反映されない。https://qiita.com/7968/items/58015344ddab5d5a8b93#第2章-値渡し
    }else{
        return $a;
    };
}

fscanf(STDIN, "%d", $n);
$harray = array();
$harray = explode(' ', trim(fgets(STDIN)));  # explodeで行全部を配列に取り込む。

# dpテーブルを作って、無限を代入する。
# ここでは0から始めたので、dp[$i-1]はiまでたどり着くのに必要な最小コストを表す。
$dp = array();
for($i = 0; $i < $n; $i++){
    $dp[$i] = INF;
}

# 初期条件。最初の足場へ行くコストはゼロ。一つ目は1通りしかない。
$dp[0] = 0;
$dp[1] = abs($harray[1] - $harray[0]);

for($j=2; $j < $n; $j++){
    $dp[$j] = chmin($dp[$j], ($dp[$j-1] + abs($harray[$j] - $harray[$j-1])));
    # $j-2 の足場から来る場合と比較
    $dp[$j] = chmin($dp[$j], ($dp[$j-2] + abs($harray[$j] - $harray[$j-2])));
}
print $dp[$n - 1];

Measured memory_bytes: 18932
#include <iostream>
#include <algorithm>
#include <vector>

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(x) ((x)<(0)?-(x):(x))

using namespace std;
using ll = long long;
const int N = 1e5+3;

int a[N];

signed main(){
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int n;

	cin >> n;

	if (n & 1) {
		cout << 0 << endl;
		return 0;
	}

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

	sort(a, a + n);

	cout << a[n / 2] - a[n / 2 - 1] << endl;

	return 0;
}



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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int n;
vector<int> vec[100001];
bool visit[100001];
queue<pii> qu;

int main(){
  scanf("%d",&n);
  REP(i,n-1){
    int a,b;
    scanf("%d %d",&a,&b);
    vec[a].push_back(b);
    vec[b].push_back(a);
  }
  qu.push(pii(1,0));
  qu.push(pii(n,1));
  int sum[2] = {0};
  while(!qu.empty()){
    int v = qu.front().first;
    int turn = qu.front().second;
    qu.pop();
    if(visit[v]) continue;
    sum[turn]++;
    visit[v] = true;
    for(int i = 0;i<vec[v].size();i++){
      int to = vec[v][i];
      if(visit[to]) continue;
      qu.push(pii(to,turn));
    }
  }
  if(sum[0]>sum[1]){
    printf("Fennec\n");
  }else{
    printf("Snuke\n");
  }
}


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

int main(){
	string P;
	getline(cin,P);
	bool f=true;
	if(P.size()%2==0)f=false;
	int D=P.size()-1;
	int s=P.size()/2-1;
	int l=P.size()/2+1;
	//if(f==false)l++;
	int ans=0;
	for(int i=0;i<=s;i++)
	{
		if(P[i]=='i'&&P[D-i]!='i')ans++;
		if(P[i]=='w'&&P[D-i]!='w')ans++;
		if(P[i]=='('&&P[D-i]!=')')ans++;
		if(P[i]==')'&&P[D-i]!='(')ans++;
	}

	if(f==true){
		ans++;
		if(P[P.size()/2]=='i'||P[P.size()/2]=='w')ans--;
	}
	cout<<ans<<endl;
	return 0;
}


	

Measured memory_bytes: 1172
/*bismillah ->                                                                                                         << Suirkhanov Meyirlan >>
  GL HF


                                                                                                                      42

    bless my code =)
                                                                                                            NEVER FOLLOW YOUR RULES :D HAHAHAHA
*/


///scanf ("%d%d", &x, &y);
///printf("%d", &a)

#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define pii pair < int , int >
#define pll pair < ll, ll >
#define pb push_back
#define pf psuh_front
#define mp make_pair
#define fi first
#define se second
#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define eb emplace_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll N = 2 * 1e5 + 7;
const ld pi = 3.14159265359;
const int INF = 1e9 + 7;
const double eps = 1e-9;

const int xi[4] = {-1, 0, +1, 0};
const int yj[4] = {0, +1, 0, -1};
const int xxi[4] = {+1, 0, -1, 0};
const int yyj[4] = {0, -1, 0, +1};

ll n, a, b, x[N], ans;

int main(){

  //freopen("bridge.in", "r", stdin);
  //freopen("bridge.out", "w", stdout);

  fast
  randoperation;

  ///           ||
  ///start here \/

  cin >> n >> a >> b;

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

  for(int i = 1; i < n; i++){
    ans += min(a * abs(x[i] - x[i + 1]), b);
  }

  cout << ans;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long double pi = acos(-1.0); 
typedef long long ll;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, wei;
	cin >> n >> wei;
	vector<int> w(n);
	vector<int> v(n);
	for(int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
	}
    int dp[n + 1][100001];
	for(int i = 0; i < n + 1; i ++) {
		for(int j = 0; j < 100001; j++) {
			dp[i][j] = 1e9 + 1;
		}
	}
	dp[0][0] = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 100001; j++) {
			if(j >= v[i]) {
				dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
			}else {
				dp[i + 1][j] = dp[i][j];
			}
		}
	}
	int ans = 100000;
	while(dp[n][ans] > wei) {
		ans--;
	}
	cout << ans << endl;
}

Measured memory_bytes: 39680
function Main(input){
	input=input.split(/\n|\s/);
	input.forEach(function(e,i,a){a[i]=Number(a[i]);});
	function ArraySortNumeric(prev,next){return (prev - next);}
	var arr=[input[0],input[1],input[2]];
	arr.sort(ArraySortNumeric);
	
	arr[2]<<=input[3];
	
	console.log(arr[0]+arr[1]+arr[2]);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] p = new int[n+1];
		for(int i=1;i<=n;i++) {
			p[i] = sc.nextInt();
		}
		
		int cnt = 0;
		for(int i=1;i<n;i++) {
			if(i==p[i]) {
				int tmp = p[i];
				p[i] = p[i+1];
				p[i+1] = tmp;
				cnt++;
			}
		}
		
		if(p[n]==n)
			cnt++;
		
		System.out.println(cnt);
	}
}


Measured memory_bytes: 51600