akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;

const long M = 1046527;
const long NIL = -1;
const long L = 14;

string H[M];

long getChar(char ch){
	if (ch == 'A') return 1;
	else if (ch == 'C') return 2;
	else if (ch == 'G') return 3;
	else if (ch == 'T') return 4;
	else return 0;
}

long getKey(string str){
	long sum = 0, p = 1, i;
	for (long i = 0; i < str.size(); i++){
		sum += p * (getChar(str[i]));
		p *= 5;
	}
	return sum;
}

long h1(long key){return key % M;}
long h2(long key){return 1 + (key % (M - 1));}

long find(string str){
	long key, h;
	key = getKey(str);
	for (long i = 0; ; i++){
		h = (h1(key) + i * h2(key)) % M;
		if (H[h] == str) return 1;
		else if (H[h].size() == 0) return 0;
	}
	return 0;
}

long insert(string str){
	long key, h;
	key = getKey(str);
	for (long i = 0; ; i++){
		h = (h1(key) + i * h2(key)) % M;
		if (H[h] == str) return 1;
		else if (H[h].size() == 0){
			H[h] = str;
			return 0;
		}
	}
}

int main(){
	long n;
	string str, com;
	cin >> n;
	for (long i = 0; i < n; i++){
		cin >> com >> str;
		if (com[0] == 'i') insert(str);
		else {
			if (find(str)) cout << "yes" << endl;
			else cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 25872
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define debug(n) cout<<"# "<<#n<<": "<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

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

int main()
{
	int n;
	cin>>n;
	rep(i,n){
		int a,b,c;
		cin>>a>>b>>c;
		int d[]={a,b,c};
		sort(d,d+3);
		
		if(d[0]*d[0]+d[1]*d[1]==d[2]*d[2])
			puts("YES");
		else
			puts("NO");
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

string day[7] =  {"Sunny", "Cloudy", "Rainy"};

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    cout << min(C, B / A) << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
V<int> dx = {-1, 1,  0, 0};
V<int> dy = { 0, 0, -1, 1};

const int INF = 1e9;

int main () {
    int h, w; cin >> h >> w;
    int sy, sx; cin >> sy >> sx; sy--; sx--;
    int gy, gx; cin >> gy >> gx; gy--; gx--;
    V<V<char>> c(h, V<char> (w));
    rep(i, h) rep(j, w) cin >> c[i][j];
    V<V<int>> d(h, V<int> (w, INF));
    d[sy][sx] = 0;
    deque<P> que;
    que.push_back({sx, sy});
    while (!que.empty()) {
        P p = que.front(); que.pop_front();
        int x = p.first, y = p.second;
        rep(i, 4) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
            if (c[ny][nx] == '#') continue;
            if (chmin(d[ny][nx], d[y][x])) {
                que.push_front({nx, ny});
            }
        }
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                int nx = x + i, ny = y + j;
                if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
                if (c[ny][nx] == '#') continue;
                if (chmin(d[ny][nx], d[y][x] + 1)) {
                    que.push_back({nx, ny});
                }
            }
        }
    }
    if (d[gy][gx] != INF) cout << d[gy][gx] << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 8584
(let* ((h (read))
    (w (read))
    (k (read))
    (c (make-array (list h w)))
    (ans 0))
    (dotimes (i h)
        (let ((a (read-line)))
            (dotimes (j w)
                (if (string= (char a j) ".")
                    (setf (aref c i j) ".")
                    (setf (aref c i j) "#")
                )
            )
        )
    )
    
    (loop for maskR below (expt 2 h) do
        (loop for maskC below (expt 2 w) do
            (let ((block_num 0))
                (loop for i below h do
                    (loop for j below w do
                        (if (and (= (logand (ash maskR (- i)) #b1) 0) (= (logand (ash maskC (- j)) #b1) 0) (string= (aref c i j) "#"))
                        ;;bitが0でマス目が#場合の処理
                            (incf block_num)
                        )
                    )
                )
                (if (= block_num k) (incf ans))
            )
        )
    )
    (princ ans)
)

Measured memory_bytes: 24524
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c) 
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<string> svec;

int main(){
    int n,ans=0;
    string a,b,c;
    cin>>n>>a>>b>>c;
    rep(i,n){
        if(a[i]==b[i]&&b[i]==c[i]) continue;
        else if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i]) ans+=2;
        else ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0517>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll n,k;
ll solve(){
    ll res = 0;
    bool hakusi = false;
    vector<ll> card;
    for(int i = 0; i < k;i++){
        ll c; cin >> c;
        if(c == 0) hakusi = true;
        else card.push_back(c);
    }
    sort(card.begin(),card.end());
    vector<pll> sec;
    
    
    ll l = card[0], r = card[0];
    for(int i = 1; i < card.size();i++){
        if(card[i] == card[i-1] + 1){
            r = card[i];
        }else{
            sec.push_back({l,r});
            l = r = card[i];
        }
    }
    sec.push_back({l,r});
    
    for(int i = 0; i < sec.size();i++){
        res = max(res,sec[i].second - sec[i].first + 1);
        if(sec[i].first != 1 || sec[i].second != n){
            res = max(res,sec[i].second - sec[i].first + 1 + hakusi);
        }
    }
    if(hakusi){
        for(int i = 1; i < sec.size();i++){
            if(sec[i-1].second+2 == sec[i].first){
                res = max(res,sec[i].second - sec[i-1].first + 1);
            }
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> n >> k,n){
        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 3892
n = int(input())
c = 1
s = 26
while True:
    if n <= s:
        break
    c += 1
    s += 26 ** c
a = ""
al = 'abcdefghijklmnopqrstuvwxyz'
for i in range(1,c+1):
    a += al[(n - 1) % 26]
    n = (n - 1) // 26
print(a[::-1])

Measured memory_bytes: 9176
import java.util.*;

/**
 * Created by Seiya on 2016/10/16.
 */

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();

        int a = N * 800;
        int b = N / 15;

        System.out.println(a - b * 200);

    } // mainMethod



} // MainClass


Measured memory_bytes: 21588
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
    [h, _] <- map read . words <$> getLine
    ass <- sequence $ replicate h B.getLine
    B.putStr $ solve ass

solve :: [B.ByteString] -> B.ByteString
solve = B.unlines
    . B.transpose . filter (B.elem '#')
    . B.transpose . filter (B.elem '#')

Measured memory_bytes: 1660
mod=10**9+7
def solve(n):
    if n==0:
        return 1
    res=0
    if n%2==1:
        temp=solve(n//2)
        res+=2*temp
        if n>=2:
            res+=temp-exact(n//2)
        return res%mod
    else:
        temp=solve(n//2)
        res+=temp
        res+=(temp-exact(n//2))*2
        return res%mod

def exact(n):
    if n==0:
        return 1
    m=n.bit_length()
    dp=[[0 for i in range(3)] for j in range(m)]
    dp[0][0]=1
    dp[0][1]=int(n%2==0)
    for i in range(1,m):
        for j in range(3):
            if j==0:
                if n>>i &1==1:
                    dp[i][j]=(dp[i-1][0]+dp[i-1][1]+dp[i-1][2])%mod
                else:
                    dp[i][j]=dp[i-1][0]
            elif j==1:
                if n>>i &1==1:
                    dp[i][j]=(dp[i-1][1]+dp[i-1][2])%mod
                else:
                    dp[i][j]=dp[i-1][0]
            elif j==2:
                if n>>i&1==1:
                    dp[i][j]=0
                else:
                    dp[i][j]=(dp[i-1][1]+dp[i-1][2])%mod
    return dp[-1][0]

N=int(input())
print(solve(N))


Measured memory_bytes: 74056
#include<iostream>
#include<map>
#include<vector>
using namespace std;
typedef pair<int, int> pii;

int calc(vector<vector<bool> > &mat){
  int res = 0;
  int n = mat.size();
  if(n == 1){
    return mat[0][0];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if(mat[i][j] == false)break;
      if(j == n - 1)res++;
    }
    for (int j = 0; j < n; j++) {
      if(mat[j][i] == false)break;
      if(j == n - 1)res++;
    }
  }
  for (int i = 0; i < n; i++) {
    if(mat[i][i] == false)break;
    if(i == n - 1)res++;
  }
  for (int i = 0; i < n; i++) {
    if(mat[i][n - 1 - i] == false)break;
    if(i == n - 1)res++;
  }
  return res;
}

int main(){
  int n, u, v, m;
  std::cin >> n >> u >> v >> m;
  map<int, pii> nhash, uhash;
  vector<vector<bool> > um(n, vector<bool>(n, false));
  vector<vector<bool> > nm = um;

  vector<vector<int> > umat(n, vector<int>(n));
  vector<vector<int> > nmat = umat;
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      std::cin >> umat[i][j];
      uhash[umat[i][j]] = pii(i, j);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      std::cin >> nmat[i][j];
      nhash[nmat[i][j]] = pii(i, j);
    }
  }
  for (int i = 0; i < m; i++) {
    int num;
    std::cin >> num;
    if(uhash.find(num) != uhash.end()){
      pii pos = uhash[num];
      um[pos.first][pos.second] = true;
    }
    if(nhash.find(num) != nhash.end()){
      pii pos = nhash[num];
      nm[pos.first][pos.second] = true;
    }
    // std::cout << num << std::endl;
    // std::cout << "um:" << calc(um) << std::endl;
    // for (int i = 0; i < n; i++) {
    //   for (int j = 0; j < n; j++) {
    //     std::cout << um[i][j];
    //   }
    //   std::cout << std::endl;
    // }
    // std::cout << "nm:" << calc(nm) << std::endl;
    // for (int i = 0; i < n; i++) {
    //   for (int j = 0; j < n; j++) {
    //     std::cout << nm[i][j];
    //   }
    //   std::cout << std::endl;
    // }
    // std::cout << std::endl;
    if(calc(um) >= u and calc(nm) >= v){
      std::cout << "DRAW" << std::endl;
      return 0;
    }else if(calc(um) >= u){
      std::cout << "USAGI" << std::endl;
      return 0;
    }else if(calc(nm) >= v){
      std::cout << "NEKO" << std::endl;
      return 0;
    }
  }
  std::cout << "DRAW" << std::endl;
  return 0;
}

Measured memory_bytes: 22272
package main

import "fmt"

func main() {
	var a, b, c, x, z int
	fmt.Scan(&a, &b, &c, &x)
	for ac := 0; ac <= a; ac++ {
		for bc := 0; bc <= b; bc++ {
			for cc := 0; cc <= c; cc++ {
				sum := 500*ac + 100*bc + 50*cc
				if sum == x {
					z++
				}
			}
		}
	}
	fmt.Println(z)
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll N,K;
    cin>>N>>K;
    if(N%K == 0)cout<<0;
    else cout<<1;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dbg(x) cerr << #x << " : " << x << endl;
#define endl '\n'
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin >> s >> t;
    int ans=0;
    for(int i=0;i<3;i++) ans+=(s[i]==t[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,ans;
char s[10010][11];
ll ba,bx,xa;
int main(){
	scanf("%lld",&n);
	rep(i,0,n)scanf(" %s",s[i]);
	rep(i,0,n){
		int cnt=0;
		char*p=s[i];
		while(p=strstr(p,"AB")){
			p++;
			cnt++;
		}
		int k=strlen(s[i]);
		if(s[i][0]=='B'){
			if(s[i][k-1]=='A')ba++;
			else bx++;
		}else if(s[i][k-1]=='A')xa++;
		ans+=cnt;
	}
	
	if(xa){
		ans+=ba;
		ans+=min(xa,bx);
	}else{
		if(ba){
			ans+=ba-1;
			if(bx)ans++;
		}
	}
//	printf("%d %d %d ",xa,ba,bx);
	printf("%lld",ans);
}


Measured memory_bytes: 256
N=int(input())
a=list(map(int,input().split()))
s=sum(a[1:])
t=a[0]
ans=abs(s-t)
for i in range(1,N-1):
  s-=a[i]
  t+=a[i]
  ans=min(ans,abs(s-t))
print(ans)

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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	int N; cin >> N;
	vector<int> a(N);
	REP(i,N) cin >> a[i];

	SORT(a);
	int al = 0;
	int bo = 0;
		
	REP(i,N){
		if(i%2 == 0) al += a[N-i-1];
		else bo += a[N-i-1];
	}

	cout << al - bo << endl;


	return 0;

}


Measured memory_bytes: 256
N,W = [int(s) for s in input().split()]
dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    w, v = [int(s) for s in input().split()]
    for sum_w in range(W+1):
        if sum_w - w >= 0:
            dp[i+1][sum_w] = max(dp[i][sum_w], dp[i][sum_w-w] + v)
        else:
            dp[i+1][sum_w] = dp[i][sum_w]
print(dp[N][W])

Measured memory_bytes: 119916
#include<bits/stdc++.h>
#include<iostream>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,n;cin>>h>>n;
    vector<ll>a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    vector<ll>c(h+1,inf);
    c[0]=0;
    rep(i,n){
        ll cnt=0;
        while(cnt*a[i]<=h){
            cnt++;
            if(cnt*a[i]>h){
                c[h]=min(c[h],cnt*b[i]);
            }else{
                c[cnt*a[i]]=min(c[cnt*a[i]],cnt*b[i]);
            }
        }
    }
    vector<vector<ll> >dp(h+2,vector<ll> (h+1,inf));
    dp[0][0]=0;
    rep(i,h+1){
        rep(j,h+1){
            dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
            if(j+i>h){
                dp[i+1][h]=min(dp[i][j]+c[i],dp[i+1][h]);
            }else{
                dp[i+1][j+i]=min(dp[i][j]+c[i],dp[i+1][j+i]);
            }
        }
    }
    cout<<dp[h+1][h]<<endl;
}

Measured memory_bytes: 782208
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For(i, 0, n)
#define rrep(i, n) rFor(i, n, 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int n, m;

void solve(){
    int max_score[n], min_score[n];
    memset(max_score, 0, sizeof(max_score));
    memset(min_score, 0, sizeof(min_score));
    rep(_, m){
        int S, K;
        scanf("%d%d", &S, &K);
        rep(__, K){
            int c;
            scanf("%d", &c);
            --c;
            max_score[c] += S;
            if(K == 1) min_score[c] += S;
        }
    }
    int ans = 0;
    rep(i, n)rep(j, n)if(i != j){
        chmax(ans, max_score[i] - min_score[j] + 1);
    }
    printf("%d\n", ans);
}

int main(){
    while(scanf("%d%d", &n, &m) && n){
        solve();
    }
}


Measured memory_bytes: 3304
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    vector<ll> b(n, 0);
    for (int i = n - 2; i >= 0; i--) {
        b[i] = (b[i + 1] + a[i+1]) % mod;
    }

    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        ans += (a[i] * b[i]) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6428
n, m = map(int, input().split())
li = [True]*(n+1)

for i in range(m):
    a = int(input())
    li[a] = False

dan = [0]*(n+1)
dan[0] = 1

for j in range(1,n+1):
    if li[j]:
        dan[j] += dan[j-1]
        if j >= 2:
            dan[j] += dan[j-2]

print(dan[n]%(10**9+7))

Measured memory_bytes: 463476
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            Console.WriteLine(N * N);
        }
    }
}



Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){

    while(true){

    int n;
    vector<int> a;
    vector<int> b;
    cin >> n;
    if(n==0) break;
    REP(i,n+1){
	int temp;
	cin >> temp;
	a.PB(temp);
    }
    int c,d;
    REP(i,n){
	b.PB(a[i+1]-a[i]);
    }
    c = b[0];
    d = b[b.size()-1];
    int c1,d1;
    REP(i,n){
	if(c == b[i]){
	    c1++;
	}else if(d == b[i]){
	    d1++;
	}
    }
    if(c1 < d1) c = d;
    else d = c;
    
    REP(i,n+1){
	bool flg = true;
	vector<int> temp;
	temp = a;
	temp.erase(temp.begin()+i);
	int sa = temp[1] - temp[0];
	REP(j,n-1){
	    if(sa != (temp[j+1]-temp[j])){
		flg = false;
	    }
	}
	if(flg){
	    cout << a[i] << endl;
	    break;
	}
    }

    }
    return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int N = read(), D = read();
    printf("%d\n", (N+2*D)/(2*D+1));
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n;cin>>n;
    vector<int>a(n);in(a,n);
    int money=1000,stock=0;
    for(int i=0;i<n;i++)
    {
        if(i!=(n-1) && a[i+1] > a[i])
        {

            stock+=money/a[i];
            money%=a[i];
        }
        else
        {
            money+=stock*a[i];
            stock=0;
        }
    }
    cout<<money<<endl;
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> arr(n), dp(n + 1);
	for(int i = 0; i < n; ++i) {
		cin >> arr[i];
	}

	dp[0] = 0; 
	dp[1] = abs(arr[0] - arr[1]); 
	for(int i = 2; i < n; ++i) {
		dp[i] = min(abs(arr[i - 2] - arr[i]) + dp[i - 2], abs(arr[i - 1] - arr[i]) + dp[i - 1]);
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int M1,M2,D1,D2;
    cin >> M1 >> D1 >> M2 >> D2;
    if(M1 < M2) cout << "1" << endl;
    else cout << "0" << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
const ll inf = 1e15 + 10;
const ll maxn = 3e3 + 163;
const ll alf = 26;
const ll dlm = 1e9+7;
const ll del = 10979 ;
const int eps = 1e-7 ;
const int maxq = 1e2+132 ;

int dp[maxn][maxn] ;
int mat[maxn][maxn] ;

int main()
{
    ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
    string s,t;
    cin>>s>>t;
    int ls = s.size() , lt = t.size() ;
    for(int i=1;i<=ls;i++){
        for(int  j=1;j<=lt;j++){
            char cs = s[i-1] , ct= t[j-1] ;
            if(cs==ct){
                dp[i][j] = dp[i-1][j-1] + 1;
                mat[i][j] = 1 ;
                continue;
            }
            int x = max(dp[i-1][j] , dp[i][j-1] ) ;
            dp[i][j] = x;
            if(dp[i-1][j]==x){
                mat[i][j] = 2;
            }else{
                mat[i][j] = 3;
            }
        }
    }
    int i = ls , j = lt ;
    //cout<<i<<" "<<j<<endl;
    string ans = "" ;
    while(i>0 && j>0 ){
        int t = mat[i][j] ;
        char x = s[i-1] ;
        if(t==1){
           // cout<<"+";
            i--, j--;
            ans+=x;
        }
        if(t==2)i-- ;
        if(t==3)j-- ;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}



Measured memory_bytes: 78080
# -*- coding: utf-8 -*-
import math
N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)

a = math.factorial(N)
b = a * 2 / N
ans = 0
for i in range(N-1):
    for j in range(i,N):
        m = ((X[i]-X[j])**2 + (Y[i]-Y[j])**2) ** (1/2)
        n = b * m
        ans += n
print(ans/a)  

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

int main(){
	int n,m;
	vector<string> u;
	cin >> n;
	for(int i=0;i<n;i++){
		string U;
		cin >> U;
		u.push_back(U);
	}
	cin >> m;
	int ans=0;
	for(int i=0;i<m;i++){
		string T;
		cin >> T;
		int judge=0;
		for(int j=0;j<u.size();j++){
			if(T==u[j]){
				ans++;
				judge++;
			}
		}
		if(judge==0) cout << "Unknown " << T << endl;
		else if(ans%2==1) cout << "Opened by " << T << endl;
		else if(ans%2==0&&judge!=0) cout << "Closed by " << T << endl;
	}

}

Measured memory_bytes: 3204
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

int main()
{
    int a, b;
    std::cin >> a >> b;
    std::cout << a * b << "\n";
    return 0;
}


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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

int main() {
  string s, t;
  cin >> s >> t;
  int ssize = s.size();

  vector<int> alpha[26];
  vector<vector<ll>> next(ssize, vector<ll>(26, 0));

  for (int i = 0; i < ssize; i++) {
    int temp = s[i] - 'a';
    alpha[temp].push_back(i);
  }

  for (int i = 0; i < ssize; i++) {
    int temp = s[i] - 'a';
    alpha[temp].push_back(i + ssize);
  }

  for (int a = 0; a < 26; a++) {
    int l = 0;
    for (int t = 0; t < alpha[a].size(); t++) {
      int r = alpha[a][t];
      for (int i = l; i < r; i++) {
        if (i > ssize) break;
        next[i % ssize][a] = (r - l) - (i - l);
      }
      l = r;
      if (l > ssize) break;
    }
  }
  // SHOW2(next);

  ll l = s.size() - 1, ans = 0;
  for (int i = 0; i < t.size(); i++) {
    int temp = t[i] - 'a';
    if (next[l][temp] == 0) {
      ans = -1;
      break;
    }
    ans += next[l][temp];
    l = (l + next[l][temp]) % ssize;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 25848
#include<stdio.h>

#define N 100001
#define NIL -1

struct Node{
  int p,d,left,right;
};

struct Node T[N];

int depth(int );
void print(int );
void print_node(int );
void print_element(int );

int count,n;

main() {
  int i,j;
  int id=0;
  int d=0;
  int n=0;
  int c=0;
  int a=0;

  scanf("%d",&n);
  if(n < 1 || N < n) return 0;

  for(i=0;i < n;i++){
    T[i].p = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }

  for(i=0;i < n;i++){
    scanf("%d %d",&id,&d);
    for(j=0;j < d;j++){
      scanf("%d",&c);

      if(j == 0) T[id].left = c;
      else T[a].right = c;

      T[c].p = id;
      a = c;
    }
  }
  
  for(i=0;i < n;i++){
    count = 0;
    T[i].d = depth(T[i].p);
  }
  
 for(i=0;i < n;i++){
   print(i);
 }

 return 0;
}


int depth(int d){

  if(d == NIL){
    return count;
  }

  else{
    count++;
    return depth(T[d].p);
  }
}

void print(int i){

  printf("node %d: ",i);
  printf("parent = %d, ",T[i].p);
  printf("depth = %d,",T[i].d);

  print_node(i);

  printf("[");

  if(T[i].left != NIL){
    printf("%d",T[i].left);
    print_element(T[i].left);
  }

  printf("]");
  printf("\n");
}

void print_node(int i){

  if(T[i].p == NIL) printf(" root, ");
  else if(T[i].left == NIL) printf(" leaf, ");
  else printf(" internal node, ");

}

void print_element(int i){

   if(T[i].right != NIL){
    printf(", %d",T[i].right);
    print_element(T[i].right);
  }
}

Measured memory_bytes: 2164
fn solve(aa: Vec<isize>, k: usize) -> isize {
    let sum: isize = aa.iter().sum();

    let mut divs = (1..)
        .take_while(|x| x * x <= sum)
        .filter(|x| sum % x == 0)
        .flat_map(|x| {
            if sum / x == x {
                vec![x]
            } else {
                vec![x, sum / x]
            }
        })
        .collect::<Vec<_>>();
    divs.sort();

    for &d in divs.iter().rev() {
        let mut rs: Vec<isize> = aa.iter().map(|&x| x % d).filter(|&x| x != 0).collect();
        rs.sort();

        let rsum = rs.iter().sum::<isize>();
        let need = rs
            .iter()
            .take(rs.len() - (rsum as usize) / (d as usize))
            .sum::<isize>();
        if need <= k as isize {
            return d;
        }
    }

    -1
}

#[test]
fn solve_test() {
    assert_eq!(solve(vec![8, 20], 3), 7);
    assert_eq!(solve(vec![3, 5], 10), 8);
    assert_eq!(solve(vec![10, 1, 2, 22], 5), 7);
    assert_eq!(solve(vec![1, 7, 5, 6, 8, 2, 6, 5,], 7), 5);
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let (_n, k) = parse_line!(usize, usize);
    let aa = parse_vec!(isize);

    println!("{}", solve(aa, k));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int n, m ,c , sum, cul;
 cin >> n >> m >> c;
 vector<int> b( m+1 );
 vector<int> a( m+1 );
 
 for (int i =0; i < m; i++){
 cin >> b.at(i); 
 }
  sum=0;
for (int j =0; j < n; j++){
 for (int i =0; i < m; i++){
 cin >> a.at(i); 
 }
  cul = 0;
 for (int i =0; i < m; i++){
 cul += b.at(i) * a.at(i); 
 }
 cul += c; 
 if (cul > 0 ){
   sum +=1;
 } 
}
cout << sum << endl; 
 return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your
        Scanner in = new Scanner(System.in);
        String a = in.next();
        String b = in.next();
        Lcs(a, b);


    }


    public static void Lcs(String a, String b) {

        int n = a.length()+1;
        int m = b.length()+1;

        int[][] t = new int[n][m];
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < m; j++) {

                if (a.charAt(i - 1) == b.charAt(j - 1)) {
                    t[i][j] = 1 + t[i - 1][j - 1];
                } else {
                    t[i][j] = Math.max(t[i][j - 1], t[i - 1][j]);
                }

            }
        }
        Print(t, a, b, n, m);
    }

    public static void Print(int[][] t, String a, String b, int n, int m) {

        StringBuilder sb = new StringBuilder();

        int i = n-1, j = m-1;
        while (i > 0 && j > 0) {
            if (a.charAt(i - 1) == b.charAt(j - 1)) {
                sb.append(a.charAt(i - 1));
                i--;
                j--;
            } else {
                if (t[i][j - 1] > t[i - 1][j]) {
                    j--;
                } else {
                    i--;
                }
            }
        }

        System.out.println(sb.reverse().toString());
    }
}


Measured memory_bytes: 80204
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long ;
using ld=long double;
 
int main(){
    ll n;
    cin>>n;
    vector<ld> a(n);
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a.begin(),a.end());
    ld sum=(a[0]+a[1])/2;
    for(int i=2;i<n;i++){
        sum=(sum+a[i])/2;
    }
    
    cout<<fixed<<setprecision(7)<<sum;
    return 0;
}

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

int main() {
	int n, m,tmp=-200;
	vector<string>ns(100), ms(100);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> ns.at(i);
	}
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> ms.at(i);
	}
	for (int i = 0; i < n; i++) {
		int count = 0;
		for (int l = 0; l < n; l++) {
			if (ns.at(i) == ns.at(l)) {
				count++;
			}
		}
		for (int k = 0; k < m; k++) {
			if (ns.at(i) == ms.at(k)) {
				count--;
			}
		}
		if (tmp < count) {
           tmp = count;
		}
	}
	for (int i = 0; i < m ; i++) {
		int count = 0;
		for (int l = 0; l < n; l++) {
			if (ms.at(i) == ns.at(l)) {
				count++;
			}
		}
		for (int k = 0; k < m; k++) {
			if (ms.at(i) == ms.at(k)) {
				count--;
			}
		}
		if (tmp < count) {
			tmp = count;
		}
	}
	if (tmp < 0) {
		tmp = 0;
	}
	cout << tmp ;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n,m,i,p,t[100000]={0},ac=0,wa=0;
    string s;
    cin >> n >> m;
    for(i=0;i<m;i++){
        cin >> p >> s;
        if(s=="WA" && t[p]!=-1) t[p]+=1;
        else if(t[p]!=-1){
            ac++;
            wa+=t[p];
            t[p]=-1;
        }
    }
    cout << ac << ' ' << wa;
    return 0;
}

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

#define flin            freopen("input.txt", "r", stdin); 
#define flout           freopen("output.txt", "w", stdout);
#define ll              long long
#define ull             unsigned long long
#define fastio          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl              '\n'
#define nll             '\0'
#define pb              push_back
#define bdyptb          return 0;
#define sorted(x)       sort(x.begin(), x.end())
#define reversed(x)     reverse(x.begin(), x.end())
#define all(x)          x.begin(), x.end()
#define mset(a, b)      memset(a, b, sizeof(a));
#define testcase        ll t,tt; cin>>tt; for(t=1;t<=tt;t++)

#define pi acos(-1.00)   
#define mx 1000007

using namespace std;

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

	int j=n-1, i=0, c=0;

	while(i<j)
	{
		if(s[i]=='W' and s[j]=='R')
			i++,j--,c++;
		if(s[i]=='R')
			i++;
		if(s[j]=='W')
			j--;
	}

	cout<<c<<nl;
    
}

Measured memory_bytes: 3756
// only log(n) new edges???
#include<bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define f first
#define s second 
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define int long long
#define forn(i, x, y) for(int i = x; i <= y; i++)
#define forev(i, y, x) for(int i = y; i >= x; i--)

using namespace std;

const int maxn = (int)3e5 + 100;
const int mod = (int)1e9 + 7;
const int P = (int)1e6 + 7;
const int inf = (int)1e9 + 7;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef long double ld;

using namespace std;

int n, h[maxn], pw[maxn], dp[maxn][5], prv[maxn];
int get(int l, int r){
  return (h[r] - (pw[r - l + 1] * h[l - 1]) % mod + mod) % mod;
}
string s;
main () {
  cin >> s;
  n = sz(s);
  s = '$' + s;
  pw[0] = 1;
  forn(i, 1, n){
    pw[i] = pw[i - 1] * 1ll * P % mod;
    h[i] = (h[i - 1] * 1ll * P % mod + s[i]) % mod;
  }
  forn(i, 1, maxn - 1)
    dp[i][1] = dp[i][3] = dp[i][2] = -inf;
  dp[1][1] = 1;
  forn(i, 2, n){
    forn(len, 1, min(i, 3ll)){
      int prev = i - len + 1;
      if(prev == 1){
        dp[i][len] = max(dp[i][len], 1ll);
      }
      else{
        forn(plen, 1, min(3ll, prev - 1)){
          if(get(prev, i) != get(prev - plen, prev - 1))
            dp[i][len] = max(dp[i][len], dp[prev - 1][plen] + 1);
        }
      }
   	}
  }
  cout << max(dp[n][3], max(dp[n][1], dp[n][2]));
}

Measured memory_bytes: 16960
N, M = map(int, input().split())
L = set(range(1,M+1,1))
suki = [1]*M
for i in range(N):
  indata = list(map(int, input().split()))
  K = set(indata[1:])
  Kbar = L-K
  for j in Kbar:
    suki[j-1]=0

ans = sum(suki)
print(ans)

Measured memory_bytes: 3064
from collections import Counter
N, P = map(int, input().split())
S = input()

ans = 0
if P in [2, 5]:
    for i, c in enumerate(S):
        if int(c) % P == 0:
            ans += i + 1
else:
    ct = Counter()
    ct[0] = 1
    prevmod = 0
    mods = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    for i in range(N-1, -1, -1):
        n = int(S[i])
        mod = (mods[n] + prevmod) % P
        ans += ct[mod]
        ct[mod] += 1
        prevmod = mod
        mods = [10 * a % P for a in mods]
print(ans)

Measured memory_bytes: 4452
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;

int main(){
    int N; cin >> N;
    vector<int> a(N), b(N);
    rep(i,N) cin >> a[i] >> b[i];
    vector<int> c(N), d(N);
    rep(i,N) cin >> c[i] >> d[i];


    priority_queue<int> que;
    int ans = 0;
    rep(i,2*N){

        rep(j,N){
            if (c[j] == i){
                vector<int> t;
                while (!que.empty()){
                    int y = que.top();que.pop();
                    if (d[j] > y){
                        ans++;
                        break;
                    }
                    else{
                        t.push_back(y);
                    }
                }
                rep(k,t.size()){
                    que.push(t[k]);
                }
            }
        }

        rep(j,N){
            if (a[j] == i){
                que.push(b[j]);
                break;
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    ll W, H, x, y;
    read(W, H, x, y);
    cout << fixed << setprecision(9) << (double)(W * H) / 2;
    cout << ' ';
    int ans = 0;
    if(2 * x == W && 2 * y == H) ans = 1;
    write(ans);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n;
    cin>>n;
    int cnt=0;
    rep(i,0,n){
        int a;
        cin>>a;
        cnt+=a%2;
    }
    cout<<(cnt%2==0 ? "YES" : "NO")<<endl;
}


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

int main() {
  for(int m, n; cin >> m >> n && (m|n);) {
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    int l = *max_element(a.begin(), a.end()), r = 1500001;
    while(r-l) {
      int mid = (l+r)/2;
      int x = 0, y = 1;
      for(int i = 0; i < n; ++i) {
        if(x + a[i] > mid) {
          x = a[i];
          ++y;
        } else {
          x += a[i];
        }
      }
      if(y <= m) {
        r = mid;
      } else {
        l = mid+1;
      }
    }
    cout << l << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
N = int(input())
H = list(map(int, input().split()))
DP = [None for k in range(N)]
DP[0] = 0
DP[1] = abs(H[1]-H[0])
for k in range(2,N):
	DP[k] = min(DP[k-1]+abs(H[k]-H[k-1]),DP[k-2]+abs(H[k]-H[k-2]))
print(DP[N-1])

Measured memory_bytes: 13980