akhauriyash/Code-Regression huggingface dataset:
/********************************
*** ******** ********** *********
*** * ****** ********* * ********
*** ** ***** ******** *** *******
*** *** **** ******* ***** ******
*** **** *** ****** ******* *****
*** ***** ** ***** +++++++++ ****
*** ****** * **** *********** ***
*** *******  *** ************* **
*** ******** ** *************** *
**********_**********************
* |   /  / \  \     /    /\     *
* |  /  |   |  \   /    /  \    *
* | /   |   |   \ /    /    \   *
* |+\   |   |    |    /______\  *
* |  \  |   |    |   |        | *
* |   \  \_/     |   |        | *
********************************/
#include<bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define Pi 3.141592653589793238
#define nl cout<<'\n'
#define TEST cout<<"TEST",nl
#define all(a) a.begin(), a.end()
#define remax(a, b) (a = ((a<b) ? b : a))
#define remin(a, b) (a = ((a<b) ? a : b))
#define pr pair<lli,lli>
#define pb push_back
#define eb emplace_back
#define precise(a) cout<<fixed<<setprecision(a)
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr> 
#define P pair<lli,pr>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;

lli lcm(lli a,lli b){
    return ((a*b)/__gcd(a,b));
}

const lli N = 3005;
lli a[N], n, dp[N][N];

lli fun(lli l, lli r){
    if(l==r) return a[l];
    if(dp[l][r]!=-1) return dp[l][r];
    lli ans = max(a[l]-fun(l+1,r),a[r]-fun(l,r-1));
    return dp[l][r] = ans;
}
void solve(){
    cin >> n;
    NA(i,0,n) cin >> a[i];
    memset(dp, -1, sizeof dp);
    cout << fun(0,n-1);
    return;
}

int main(){
    fastIO; 
    lli t = 1; 
    // cin>>t;
    NA(i,0,t) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 70912
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000007
#define MOD 1000000007
#define ARRAY_MAX 1000005

int a[ARRAY_MAX];
int b[ARRAY_MAX];

int main(){

    int n,m,k;
    cin >> n >> m;

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

    ll height = 0,width = 0;//最大値が確定した行、列数

    ll ans = 1;

    for(ll i = n*m,w = 0;i > 0;i--,w++){

        if(a[i] && b[i]){
            height++;
            width++;
        }else if(a[i]){

            ans = (ans*width)%MOD;
            height++;

        }else if(b[i]){

            ans = (ans*height)%MOD;
            width++;

        }else{
            ans = ans*(height*width - w)%MOD;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2304
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    a, b = MII()
    cnt = a-1
    if b>=a: cnt+=1
    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b){
    if(b == 0)
        return a;
    return gcd(b, a % b);
}

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


int main(){
    long long N, ans=0;
    cin >> N;	
    vector<long long> t(N);
    for(int i=0; i<N; i++){
	cin >> t[i];
    }
    ans = t[0];
    for(int i=1; i<N; i++){
	ans = lcm(ans, t[i]);
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int A, B, C;

int main() {
  cin >> A >> B >> C;
  int ans = inf;
  for (int i = 0; i <= 26; ++i) {
    for (int j = 0; j <= 26; ++j) {
      for (int k = 0; k <= 26; ++k) {
        int a = A + 2 * i;
        int b = B + 2 * j;
        int c = C + 2 * k;
        int aans = i + j + k;
        int mi = min(a, min(b, c));
        aans += a - mi;
        aans += b - mi;
        aans += c - mi;
        chmin(ans, aans);
      }
    }
  }
  cout << ans << endl;
}

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

#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

//#define max(a,b) a>b?a:b
//#define min(a,b) a>b?b:a

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int sum() { return 0; }

template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }




const int MOD = 1e9+7;
char a[1005][1005];
int dp[1005][1005];


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	REP(i,n)REP(j,m) cin>>a[i][j];
	dp[0][0] = 1;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if(a[i][j] == '#') continue;
			if(i - 1 >= 0) dp[i][j] = (dp[i-1][j]+dp[i][j])%MOD;
			if(j -1 >= 0)  dp[i][j] = (dp[i][j-1]+dp[i][j])%MOD;
		}
	}
	cout<<dp[n-1][m-1] % MOD;
	return 0;
}


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

int main(){
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  for(int i = 0; i < N; i++){
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  for(int i = 0; i < N; i++){
    cout << S.at(i);
  }
  return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;



int main(){
	ll n,m=INF,ans=0;
	cin >> n;
	vector<ll> a(n);
	FOR(i,0,n){
		cin >> a[i];
		if(m>abs(a[i]))m=abs(a[i]);
		ans += abs(a[i]);
	}
	FOR(i,0,n-1){
		if(a[i]<0){
			a[i] *= -1;
			a[i+1] *= -1;
		}
	}
	if(a[n-1]<0){
		ans -= m*2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
from collections import defaultdict

n, m = map(int, input().split())
e = []
es = defaultdict(set)
for i in range(m):
    ee = tuple(sorted(map(int, input().split())))
    e.append(ee)
    es[ee[0]].add(ee[1])
    es[ee[1]].add(ee[0])

path = [None] * (n + 1)
path[1] = 1
num = 0
nodes = {1}
while nodes:
    new_nodes = set()
    for nd in nodes:
        for e in es[nd]:
            if path[e] is None:
                path[e] = nd
                num += 1
                new_nodes.add(e)
    nodes = new_nodes
if num == n - 1:
    print("Yes")
    for i in range(2, n + 1):
        print(path[i])
else:
    print("No")


Measured memory_bytes: 84316
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
f=[int(i) for i in input().split()]

# aとfの組み合わせはソートして逆向きが最適
# 帰納法で示す

# チームの成績x→単に成績x,メンバーiの成績→xi

# 0<=x<=a[-1]*f[0]な整数xがあったら
# 成績x以下にすることはできるか？という命題を考える

# gi=int(x/fi)は食べ物iで成績xiを出せる最大値
# 　aiがgiを超えてしまうと成績xi以下は修行しないと出せない
# 　ai<=giならその人の成績はxi以下になる
# なのでmax(ai-gi,0)は成績xi以下であるために必要な修行の回数

# よってsum=Σmax(ai-gi,0)は成績x以下を達成するのに、必要なチーム全体の総修行回数
# したってsum<=Kなら成績x以下にすることができる

# 各整数について命題はFalseかTrueを返す
# その順番は1から順にF...FT...Tとなる
# この一番左のTの整数xが求めたい最小値：チームの成績xの最小値

a.sort()
f.sort(reverse=True)

def score(x):
    syugyo = 0
    for A,F in zip(a,f):
        syugyo += max(A-int(x/F),0)
    if syugyo <= k:
        return True
    else:
        return False


left = 0
right = a[-1]*f[0]+1
while left < right-1:
    mid = (left+right)//2
    if score(mid):
        right = mid
    else:
        left = mid
print(left+1 if left != 0 else 0)
    
# 計算量は 1+2logN + N*log(2)N <= N*logN < 3.6 * 10^6 
# ぎりぎりセーフ？

Measured memory_bytes: 119500
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
int main() {
    int H,W; cin >> H >> W;
    vector<vector<char>> s(H,vector<char>(W));
    int white = 0;
    for (int h=0;h<H;h++) for (int w=0;w<W;w++) {
        cin >> s[h][w];
        if (s[h][w]=='.') white++;
    }
    vector<vector<int>> dist(H,vector<int>(W,-1));
    queue<pair<int,int>> que;
    
    dist[0][0] = 0; que.push(make_pair(0,0));
    
    while(!que.empty()){
        int x,y;
        tie(y,x) = que.front(); que.pop();
        for (int dir = 0;dir<4;dir++){
            int ny = y + dy[dir];
            int nx = x + dx[dir];
            if (ny<0||ny>=H||nx<0||nx>=W||dist[ny][nx] != -1||s[ny][nx]=='#') continue;
            dist[ny][nx] = dist[y][x] + 1;
            que.push(make_pair(ny,nx));
        }
    }
    if (dist[H-1][W-1]==-1) cout << -1 << endl;
    else cout << white - (dist[H-1][W-1]+1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





const int SIZE = 5005;

int num[SIZE];
ll a[SIZE], sdp[SIZE][2], dp[SIZE][SIZE][2];
vector<vector<int>> g;


void rec(int v, int par){
    num[v] = 1;
    for(auto &child : g[v]){
        if(child == par) continue;
        rec(child, v);
        num[v] += num[child];
    }
    
    for(int i = 0; i <= num[v]; i++){
        sdp[i][0] = sdp[i][1] = INF;
    }
    
    sdp[0][0] = a[v];
    if(a[v] > 0){
        sdp[0][1] = a[v];
    }
    
    int curnum = 0;
    for(auto &child : g[v]){
        if(child == par) continue;
        for(int i = curnum; i >= 0; i--){
            ll tmp0 = sdp[i][0], tmp1 = sdp[i][1];
            sdp[i][0] = sdp[i][1] = INF;
            for(int j = 0; j <= num[child]; j++){
                sdp[i + j][0] = min(sdp[i + j][0], tmp0 + dp[child][j][0]);
                if(dp[child][j][0] < 0 || dp[child][j][1] < INF / 2){
                    sdp[i + j + 1][0] = min(sdp[i + j + 1][0], tmp0);
                }
                if(a[v] > 0){
                    sdp[i + j][1] = min(sdp[i + j][1], tmp1 + dp[child][j][1]);
                    if(dp[child][j][0] < 0 || dp[child][j][1] < INF / 2){
                        sdp[i + j + 1][1] = min(sdp[i + j + 1][1], tmp1);
                    }
                }
            }
        }
        curnum += num[child];
    }
    for(int i = 0; i <= num[v]; i++){
        dp[v][i][0] = sdp[i][0];
        dp[v][i][1] = sdp[i][1];
    }
}


int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%lld", &a[i]);
    }
    g.resize(n);
    for(int i = 0; i < n - 1; i++){
        int u, v;
        scanf("%d %d", &u, &v);
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    
    for(int i = 0; i < SIZE; i++){
        for(int j = 0; j < SIZE; j++){
            dp[i][j][0] = dp[i][j][1] = INF;
        }
    }
    rec(0, -1);
    int ans = n;
    for(int i = 0; i <= n; i++){
        if(dp[0][i][0] < 0){
            ans = min(ans, i);
        }
        if(dp[0][i][1] < INF / 2){
            ans = min(ans, i);
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 392576
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  int n, m;
  readf("%s %s\n", &n, &m);
  int[int] drink;
  foreach (_; 0..n) {
    auto x = readln.chomp.split.to!(int[]);
    drink[x[0]] += x[1];
  }

  auto keys = drink.keys;
  keys.sort();
  int cnt;
  long sum;
  a:foreach (k; keys) {
    while (drink[k] > 0) {
      cnt++;
      sum += k;
      drink[k]--;
      if (cnt == m) {
        break a;
      }
    }
  }
  sum.writeln;
}


Measured memory_bytes: 12412
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.Collections;
import java.math.BigDecimal;
import java.util.LinkedList;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        LinkedList<Character> list;
        while (sc.hasNext()) {
            String s = sc.next();
            if (s.equals("-")) break;
            int n = sc.nextInt();
            list = new LinkedList<>();
            
            for (int i = 0; i < s.length(); i++) {
                list.addLast(s.charAt(i));
            }
            
            for (int i = 0; i < n; i++) {
                int m = sc.nextInt();
                for (int j = 0; j < m; j++) {
                    list.addLast(list.pollFirst());
                }
            }
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < list.size(); i++) {
                sb.append(list.get(i));
            }
            System.out.println(sb);
        }
    }
}

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

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

int main() {
    ll n, k, q;
    cin >> n >> k >> q;
    vector<ll> point(n, 0);
    ll a;
    rep(i, q) {
        cin >> a;
        a--;
        point[a]++;
    }

    rep(i, n) {
        ll current = k - (q - point[i]);
        if (current > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

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

int main()
{
ll k,a,b,temp=0;
cin>>k>>a>>b;
for(ll i=k;i<=b;i+=k)
{
if(i>=a)
{
cout<<"OK"<<endl;
temp=1;
break;
}
}
if(temp==0)
cout<<"NG"<<endl;

return 0;
}


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

using namespace std;

map<string,int>a;

string ch[10000];

int main(){
	int m,n;
	cin>>n;
	int k;
	for(int i=1;i<=n;i++)
	{
		cin>>ch[i];
		a[ch[i]]+=1;
	}
	cin>>m;
	for(int i=n+1;i<=n+m;i++)
	{
		cin>>ch[i];
		a[ch[i]]-=1;
	}
	int ans=0;
	for(int i=1;i<=n+m;i++)
	{
		ans=max(ans,a[ch[i]]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> intpair;
typedef std::pair<long long, long long> llpair;

#define mod 1000000007
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i, n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using namespace std;

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

	int q;
	cin >> q;
	rep(i, q) {
		int c, a, n;
		cin >> c >> a >> n;

		int ans = 0;

		int t = min(a, n);
		if (t >= c) {
			ans = c;
		}
		else {
			ans = t;
			c -= t;
			if (t == n) {
				a -= n;
				int p;
				p = min(c / 2, a);

				ans += p;

				if (p == a) {
					c -= a * 2;

					ans += c / 3;
				}
			}
			else {
				ans += c / 3;
			}
		}

		cout << ans << "\n";
	}

	return 0;
}



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

int main() {
    string s;
    cin >> s;
    if (s == "Sunny") cout << "Cloudy" << endl;
    else if (s == "Cloudy") cout << "Rainy" << endl;
    else if (s == "Rainy") cout << "Sunny" << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

  int p,q;
  int data[100];
  int c=0;
  int di;
  bool f;
  while(cin>>p>>q){
    p*=10;
    c=0;
    while(1){
      data[c]=p;
      f=false;
      for(int i=0;i<c;i++){
	if(p==data[i]){
	  di=i;
	  f=true;
	}
      }
      if(f) break;
      c++;
      cout<<p/q;
      p%=q;
      p*=10;
      if(p==0) break;
    }
    cout<<endl;
    if(p!=0){
      for(int i=0;i<di;i++){
	cout<<" ";
      }
      for(int i=di;i<c;i++){
	cout<<"^";
      }
      cout<<endl;
    }
  }

}

Measured memory_bytes: 1160
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


fn main() {
    input!{a:i64,b:i64};
    if a<=0 && b>=0 { println!("Zero"); return(); }

    if a<0 {
        println!("{}", if (a.abs()-b.abs())%2==0 {"Negative"} else {"Positive"});
    } else {
        println!("Positive");
    }
}

Measured memory_bytes: 4352
#define mod 1000000007
#define PI 3.14159265358979323846
#define inf 100000000000000000
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
#define _ <<" "<<
#define forn(i, n) for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;


signed main() {
    SPEED;
  	//freopen("test.txt","r",stdin);
    int n,k;cin>>n>>k;

    string s;cin>>s;

    int prev = 0;

    forn(i,n-1)
    	if(s[i] == s[i+1])
    		prev++;
    cout<<min(n-1, (prev + 2*k ));

}	
 
 

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

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))    
#define OUT(P) cout << (P) << endl    
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl    
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;    
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)    
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)    
typedef long long ll;    
const long DIVIDE = 1e9+7;

int sum_digits(int num);    
template <class T>    
vector<T> copy_vector(vector<T> vec);    
int gcd(int a, int b);    
// ****** print functions ****** //
template <class T, class U>
void print_pairs(const vector<pair<T, U>> pairs);
template <class K, class V>
void print_map(const map<K, V> m);


const string YES = "Yes";
const string NO = "No";
int main() {    
    int n;
    cin >> n;
    vector<pair<long, long>> works(n);
    for(int i=0; i<n; i++) {
        long a, b;
        cin >> a >> b;
        works[i] = make_pair(a, b);
    }

    sort(works.begin(), works.end(), [](const auto &w1, const auto &w2) { return w1.second < w2.second; });
    //for(int i=0; i<works.size(); i++) {
    //    cout << "(" << works[i].first << "," << works[i].second << ")" << endl;
    //}
    long total_time = works[0].first;
    long dead_line = works[0].second;
    bool work_is_ok = true;
    if(total_time > dead_line) work_is_ok = false;
    for(int i=1; i<n && work_is_ok; i++) {
        pair<long, long> work = works[i];
        total_time += work.first; 
        dead_line = work.second;
        //cout << "TOTAL: (" << total_time << "," << dead_line << ")" << endl;
        if(total_time > dead_line) {
            work_is_ok = false;
        }
    }

    string ans = (work_is_ok)? YES : NO;
    cout << ans << endl;

    return 0;    
}    

/******************************/    
/***** DECRARED FUNCTIONS *****/    
/******************************/    

int sum_digits(int num) {    
    int rtn = 0;    
    while(num != 0) {    
        int tmp = num % 10;    
        rtn += tmp;    
        num /= 10;    
    }    
    return rtn;    
}    

// vectorのコピー    
template <class T>    
vector<T> copy_vector(vector<T> vec) {    
    vector<T> rtn;    
    rtn.reserve(vec.size());    
    copy(vec.begin(), vec.end(), back_inserter(rtn));    
    return rtn;    
}    

// ユークリウッドの互除法    
int gcd(int a, int b) {    
    if(b==0) return a;    
    else return gcd(b, a % b);    
}

template <class T, class U>
void print_pairs(const vector<pair<T, U>> &pairs) {
    for(int i=0; i<pairs.size(); i++) { 
        cout << "(" << pairs[i].first << ", " << pairs[i].second << ")" << " "; 
    } 
    cout << endl;
}

template <class K, class V>
void print_map(const map<K, V> &m) {
    for(auto it=m.cbegin(); it!=m.cend(); it++) {
        cout << it->first << ": " << it->second << endl;
    }
}


Measured memory_bytes: 3456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.TreeSet;

import javax.print.attribute.standard.MediaSize.Other;
import javax.xml.bind.ParseConversionEvent;

public class Main {

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

		final int N = sc.nextInt();
		final int M = sc.nextInt();
		
		int[][] data = new int[M][2];
		
		for(int i = 0; i < M; i++){
			for(int j = 0; j < 2; j++){
				data[i][j] = sc.nextInt();
			}
		}
		
		int limit = 1;
		int count = 0;
		while(limit <= N){
			int max = Integer.MIN_VALUE;
			
			for(int i = 0; i < M; i++){
				if(data[i][0] <= limit && data[i][1] >= limit){
					max = Math.max(max, data[i][1]);
				}
			}
			
			if(max == Integer.MIN_VALUE){
				System.out.println("Impossible");
				return;
			}else{
				limit = max + 1;
				count++;
			}
		}
		
		System.out.println(count);
	}

}

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

#define INF 1000000000

using namespace std;

int main() {
    int n, ans = INF, now;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a.at(i);
    for (int i = -100; i <= 100; ++i) {
        now = 0;
        for (int j = 0; j < n; ++j) now += (i - a.at(j)) * (i - a.at(j));
        ans = min(ans, now);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<long long>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, s, t, q, sum, last, cnt, ans, a[100000];
string str,ss;
bool f;
char c[10000][10000];
struct Edge { LL to,cost; };
vector<Edge>vec[1000];
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n;
	rep(i, n) {
		LL x, y;
		cin >> x >> y;
		LL l = 0, r = 10000000000;
		while (r - l > 1) {
			LL mid = (l + r) / 2;
			if (x*y > mid * mid)l = mid;
			else r = mid;
		}
		LL now = l; l = 0, r = 10000000000;
		while (r - l > 1) {
			LL mid = (l + r) / 2;
			if (x*y > mid * now)l = mid;
			else r = mid;
		}
		if (x == 1 && y == 1)
			cout << 0 << endl;
		else
			cout << l - now - (x*y == (LL)sqrt(x*y)*(LL)sqrt(x*y) && x != y ? 1 : 0) + now * 2 - 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 2304
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;

inline int read() {
	char v = getchar();int x = 0,f = 1;
	while (!isdigit(v)) {if (v == '-')f = -1;v = getchar();}
	while (isdigit(v)) {x = x * 10 + v - 48;v = getchar();}
	return x * f;
}
const int N = 100001;
const int M = 500001;

int to[M],hd[N],nxt[M],tot;

inline void add(int u,int v) {to[++tot] = v;nxt[tot] = hd[u];hd[u] = tot;}

inline int min(int x,int y) {return x<y?x:y;}
inline int max(int x,int y) {return x>y?x:y;}

char p[N],lc;
bool vis[N];
long long ans,len,l,bg;
int k;

int main() {
	cin >> p;
	
	k = read();
	len = strlen(p);
	for (int i = 0;i < len;++i) {
		if (p[i] == lc) {
			l++;
		}
		else {
			if (l && !bg) bg = l;
			ans += 1LL * k * (l >> 1);
			lc = p[i];l = 1;
		}
	}
	if (l == len) {
		ans = 1LL * k * len >> 1;
	}
	else {
		if (p[len-1] == p[0]) {
			ans -= 1LL * (bg >> 1) * (k - 1);
			ans += 1LL * ((bg + l) >> 1) * (k-1) + (l>>1);
		}
		else {
			ans += 1LL * (l >> 1) * k;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

int main()
{
	long long N;
	cin >> N;
	long long A[N], dA[N];
	long long sum = 0;//Aの和
	long long x = 0;//取った回数
	REP(i,N){
		cin >> A[i];
		sum+=A[i];
	}
	if(sum % (N*(N+1)/2) != 0){
		cout << "NO" << endl;
	}else{
		x = sum/(N*(N+1)/2);
		REP(i,N){
			dA[i] = A[(i+1)%N]-A[i];
			if((x-dA[i])%N != 0 || (x-dA[i])<0){
				cout << "NO" << endl;
				return 0;
			}
		}
		cout << "YES" << endl;
	}
	return 0;
}

Measured memory_bytes: 1792
n,m=map(int,input().split())
h=list(map(int,input().split()))
a,b=[],[]
for i in range(m):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
s=[]
for i in range(m):
    if h[a[i]-1]<h[b[i]-1]:
        s.append(a[i])
    elif h[a[i]-1]>h[b[i]-1]:
        s.append(b[i])
    else:
        s.append(a[i])
        s.append(b[i])
d=len(set(s))
print(n-d)

Measured memory_bytes: 104896
#include<cstdio>
#include<cstring>
using namespace std;
#define N 45
long long dp[N][N][N],f[N][N][N][N],n;
char s[N][N];
long long calc(int a,int b,int c,int d)
{
	if(f[a][b][c][d]!=-1)return f[a][b][c][d];
	long long as=0;
	for(int i=a;i!=(b==n*2?1:b+1);i=i==n*2?1:i+1)
	for(int j=c;j!=(d==n*2?1:d+1);j=j==n*2?1:j+1)
	as+=dp[a][b][i]*dp[c][d][j]*(s[i][j]=='1');
	return f[a][b][c][d]=as;
}
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n*2;i++)scanf("%s",s[i]+1);
	memset(f,-1,sizeof(f));
	for(int i=1;i<=n*2;i++)dp[i][i][i]=1;
	for(int l=2;l<n*2;l++)
	for(int i=1;i<=n*2;i++)
	{
		int j=(i+l-1)%(2*n)+1;
		for(int k=i;k!=(j==n*2?1:j+1);k=k==n*2?1:k+1)
		for(int s=i==n*2?1:i+1;s!=(k==n*2?1:k+1);s=s==n*2?1:s+1)
		for(int t=j==1?n*2:j-1;t!=(k==1?n*2:k-1);t=t==1?n*2:t-1)
		dp[i][j][k]=(dp[i][j][k]+dp[s][t][k]*calc(i,s==1?n*2:s-1,t==n*2?1:t+1,j));
	}
	long long as=0;
	for(int i=2;i<=n*2;i++)as+=dp[i==n*2?1:i+1][i-1][1]*(s[1][i]=='1');
	printf("%lld\n",as);
}

Measured memory_bytes: 32896
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>

using namespace std;



int main(){
    int n;
    cin >> n;
    if(n%10 == 2 || n%10 == 4 || n%10 == 5  || n%10 == 7  || n%10 == 9 ){
        cout << "hon" << endl;
    }
    else if(n%10 == 0 || n%10 == 1 || n%10 == 6  || n%10 == 8){
        cout << "pon" << endl;
    }
    else if(n%10 == 3){
        cout << "bon" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 199

int top,S[MAX];
void initialize(void);
void push(int);
int pop(void);
int isEmpty(void);
int isFull(void);

int main(){

  int a,b,i;
  char s[MAX];
  
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+' && 1<=strlen(s) && strlen(s)<=99){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(s[0]=='-' && 1<=strlen(s) && strlen(s)<=99){
      a=pop();
      b=pop();
      push(b-a);
    }
    else if(s[0]=='*' && 1<=strlen(s) && strlen(s)<=99){
      a=pop();
      b=pop();
      push(a*b);
    }
    else push(atoi(s));
  }
  printf("%d\n",pop());
  return 0;
}




 
void initialize(void){
  top=0;
}

int isEmpty(void){
  return top==0;
}

int isFull(void){
  return top>=MAX-1;
}

void push(int x){
  if(isFull())
    printf("overflow\n");
  top++;
  S[top]=x;
}


int pop(void){
  if(isEmpty())
    printf("underflow\n");
  top--;
  return S[top+1];
}

Measured memory_bytes: 976
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = long.Parse(line[0]);
        var a = long.Parse(line[1]);
        var b = long.Parse(line[2]);
        if (a > b) { Console.WriteLine(0); goto end; }
        if (a != b && n == 1) { Console.WriteLine(0); goto end; }
        else if (a == b && n == 1) { Console.WriteLine(1); goto end; }
        var ret = (n - 2) * (b - a) + 1;
        Console.WriteLine(ret);
        end:;
    }
}

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

int N, W;
int w[105], v[105];
ll dp[105][100005];

ll solve() {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j < w[i]) {
                dp[i+1][j] = dp[i][j];
            } else {
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            }
        }
    }
    return dp[N][W];
}

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }
    cout << solve() << endl;
    return 0;
}

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

int q,l,r;
int tol[100001];
int sum[100001];

void gettol()
{
	for(int i=3;i<100000;i+=2)
	{
		int flag=0;
		
		if(((i+1)/2)%2==0 && ((i+1)/2)>2) continue;
		
		for(int j=3;j<(i/2);++j)
		{
			if(((i+1)/2)%j==0)
			{
				flag=1;
				break;
			}
			
			if(i%j==0)
			{
				flag=1;
				break;
			}
		}
		if(flag==0) tol[i]=1;
	}
}

void getsum()
{
	sum[1]=0;
	for(int i=3;i<100000;i+=2)
	{
		if(tol[i]==1) sum[i]=sum[i-2]+1;
		else sum[i]=sum[i-2];
	}
}

int main()
{
	gettol();
	getsum();
	cin>>q;
	
	for(int i=0;i<q;++i)
	{
		scanf("%d%d",&l,&r);
		
		printf("%d\n",sum[r]-sum[l-2]);
	}
	
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


// 約数列挙
vector<ll> divisor(ll n) {
    vector<ll> ret;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
            }
    }
    sort(begin(ret), end(ret));
    sort(ret.begin(), ret.end(), greater<ll>());
    return (ret);
}

int main(){
    ll n;
    cin >> n;
    vector<ll> v = divisor(n);

    ll ans = 0;
    for(auto d : v){
        if (d - 1 > n/d) ans += d-1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3712
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	int N;
	while (~scanf("%d", &N)) {
		vector<long long> A(N);
		for (int i = 0; i < N; ++ i)
			scanf("%lld", &A[i]);
		ll ans = 0;
		for (int n = 1; n <= N; ++ n) {
			sort(A.begin(), A.end());
			ll cycles = max(0LL, n == N ?
				A[0] - N :
				(A[N - n] - A[N - n - 1]) / (N + 1));
			reu(i, N - n, N)
				A[i] -= cycles * (N + 1 - n);
			rep(i, N - n)
				A[i] += cycles * n;
			ans += cycles * n;
			while (1) {
				sort(A.begin(), A.end());
				if (A[N - 1] - (n == N ? 0 : A[N - n - 1]) < N) break;
				rep(i, N - 1)
					A[i] += 1;
				A[N - 1] -= N;
				++ ans;
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
template <typename T>
struct BIT
{
    int n;
    vector<T> d;
    BIT(ll n = 0) : n(n), d(n + 1) {}
    void add(ll i, T x = 1)
    {
        for (i++; i <= n; i += i & -i)
        {
            d[i] += x;
        }
    }
    T sum(ll i)
    {
        T x = 0;
        for (i++; i; i -= i & -i)
        {
            x += d[i];
        }
        return x;
    }
    T sum(ll l, ll r)
    {
        return sum(r - 1) - sum(l - 1);
    }
};
int main()
{
    ll n, q;
    cin >> n >> q;
    vector<ll> c(n);
    vector<ll> v(n, -1);
    vector<ll> d[n];
    rep(i, n)
    {
        cin >> c[i];
        c[i]--;
        if (v[c[i]] != -1)
        {
            d[v[c[i]]].push_back(i);
        }
        v[c[i]] = i;
    }
    vector<P> qs[n];
    rep(i, q)
    {
        ll l, r;
        cin >> l >> r;
        l--;
        r--;
        qs[l].push_back(P(r, i));
    }
    vector<ll> ans(q);
    BIT<ll> a(n);
    for (ll x = n - 1; x >= 0; x--)
    {
        rep(y, d[x].size())
        {
            a.add(d[x][y], 1);
        }
        rep(i, qs[x].size())
        {
            ll y = qs[x][i].first;
            ll num = qs[x][i].second;
            ans[num] = y - x + 1 - a.sum(y);
        }
    }
    rep(i, q)
    {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 70884
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

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


int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  string c;
  cin >> c;

  const char W('W'), R('R');

  ll ans(0);
  ll l(0), r(N-1);
  while (l < r) {
    while (c[l] != W && l < N-1)
      l++;
    while (c[r] != R && r > 0)
      r--;
    if (l < r && c[l] == W && c[r] == R) {
      ans++;
      l++;
      r--;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3732
//前向星+SPFA
/*
edeg[]: 邻接表
dis[]: 最短路数组
vis[]: 出入队标记数组
cnt[]: 入队次数统计
head[u]:表示起点为u的最后一条边的标号，如果是-1表示没有以u为起点的边
init::初始化边
add::(u起点, v终点, w权值)
spfa::(s起点，n点数)[-1存在负环，反之为到点n最短路权值]

*/
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#define ll long long
#define maxn 210000
#define INF 9123372036854775807
using namespace std;
int N;
struct Edge
{
	int to;
	int next;//表示和该边有共同起点的上一条边的标号
	ll val;
}edge[maxn];
ll tot;
int head[maxn];
ll dis[maxn];
int vis[maxn];
int cnt[maxn];
void init()
{
	tot=0;
	memset(head,-1,sizeof(head));
}
void add(int u,int v,int w)
{
	edge[tot].to=v;
	edge[tot].val=w;
	edge[tot].next=head[u];
	head[u]=tot++;
}
void spfa(int s)
{
	memset(cnt,0,sizeof(cnt));
	memset(vis,0,sizeof(vis));
	queue<int> q;
	for(int i=1;i<=N;i++)
	{
		vis[i]=0;
		dis[i]=INF;
	}
	vis[s]=1;
	dis[s]=0;
	q.push(s);
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		vis[u]=0;
		for(int i=head[u];i!=-1;i=edge[i].next)
		{
			int v=edge[i].to;
			int w=edge[i].val;
			if(dis[u]+w<dis[v])
			{
				dis[v]=dis[u]+w;
				if(!vis[v])
				{
					vis[v]=1;
					
					q.push(v);
				}
			}
		}
	}
	//默认返回最后一个点最短距离，可更改
}
int main()
{
	cin>>N;
	init();
	for(int i=1;i<N;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		add(a,b,c);
		add(b,a,c);
	}
	

	int Q,K;
	
	cin>>Q>>K;
	spfa(K);
	//for(int i=1;i<=N;i++)
	//cout<<dis[i]<<' ';
	//cout<<endl;
	
	for(int i=1;i<=Q;i++)
	{
		int x,y;
		cin>>x>>y;
		cout<<dis[y]+dis[x]<<endl; 
	}
	return 0;
}



Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}



int main(){
   int n;
   cin>>n;
   vector<int> a(n);
   rep(i,n){
      cin>>a[i];      
   }
   sort(a.begin(),a.end());
   int ans=0;
   rep(i,n){
      for(int j=i+1;j<n;j++){
         for(int k=j+1;k<n;k++){
            if(a[i]!=a[j] && a[j]!=a[k]){
               if(a[i]+a[j]>a[k]){
                  if(a[i]+a[k]>a[j]){
                     ans++;
                  }
               }
            }
         }
      }
   }
   cout<<ans;


   


return 0;
}


Measured memory_bytes: 3608
r1,c1,r2,c2=map(int,input().split())
mod=10**9+7
n=[1]*(r2+c2+3)
for i in range(r2+c2+2):
  n[i+1]=(n[i]*(i+1))%mod
def g(a,b):
  x,y,z=n[a+b],n[a],n[b]
  return (((x*pow(y,mod-2,mod))%mod)*pow(z,mod-2,mod))%mod
print((g(r2+1,c2+1)-g(r2+1,c1)-g(r1,c2+1)+g(r1,c1))%mod)

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

typedef vector<int> vi;
typedef long long int ll;
#define clr(v, d)           memset(v, d, sizeof(v))
#define all(v)   (v.begin()),(v.end())
#define lp(i,n)     for(int i=0;i<n;i++)
#define sz(v)       v.size()
#define f           first
#define s           second
#define pb           push_back
#define MP           make_pair

ll m,n;
int arr[50];


int convert(ll num){
    int idx=0;
    while(num>0){
        arr[idx]=num%3;
        num=num/3;
        idx++;
    }
    return idx;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,k,x;
    cin>>n>>k;
    ll sum=0;
    lp(i,n) {
        cin>>x;
        if(x>=k) sum++;
    }
    cout<<sum;
    return 0;
}

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

int main() {
  int r, d, x;
  cin >> r >> d >> x;
  for (int i = 1; i <=10; i++) {
    int ans = r*x - d;
    x = ans;
    cout << ans << endl;
  }
  return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

vector<ll> enum_div(ll n){
	vector<ll> ret;
	for(ll i=1;i*i<=n;++i){
		if(n%i==0){
			ret.push_back(i);
			if(i*i!=n){
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

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

	int A=in(),B=in(),X=in();
	double H = (double)X/(double)(A*A);
	double T = atan2(2.0*(B-H),A);
	double L = B-A*tan(T);

	if(L<0){
		T = atan2(A*B*B,2*X);
	}
	
	printf("%.10lf\n",T*180.0/(4*atan(1.0)));
	return 0;
}

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

#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))

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

int main(){
ll N; cin>>N;
vi S(N);
vi sum(N+1,0);
REP(i,N){
 char tmp; cin>>tmp;
 if(tmp=='E'){
 S.at(i)=1;
 }else{
 S.at(i)=-1;
 }
 sum.at(i+1)=sum.at(i)+S.at(i);
}
ll ans=0;
REP(i,N){
	if((sum.at(i)-sum.at(N)+sum.at(i+1))>=ans){
		ans=sum.at(i)-sum.at(N)+sum.at(i+1);
		}

	}
cout<<(N-1-ans)/2<<endl;

}


Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define sz(A) int(A.size())
#define FIFO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(A) begin(A),end(A)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<pair<int,int>> vii;
const int N = 200005, MOD = 1000000007;
ll fact[N];
ll inve[N];
vi adj[N];
ll mulmod(ll a, ll b, ll p){
	ll x = 0, y = a%p;
	while(b>0){
		if(b%2==1) x = (x+y)%p;
		y = (1LL*y*2)%p;
		b = b/2;
	}
	return x%p;
}
ll fastexp(ll x, ll y, ll p){
	ll ans = 1;
	while(y > 0){
		if(y&1) ans = (1LL*ans*x)%p;
		y = y>>1;
		x = (1LL*x*x)%p;
	}
	return ans%p;
}
ll fastexpp(ll x, ll y, ll p){
	ll ans = 1;
	while(y > 0){
		if(y&1) ans = mulmod(ans,x,p);
		y = y>>1;
		x = mulmod(x,x,p);
	}
	return ans%p;
}
ll invmod(ll x, ll p){
	return fastexp(x,p-2,p)%p;
}
//plantilla mate
ll sz[N];
ll ways[N];
void dfs(int u, int parent) {
	sz[u] = 1;
	ways[u] = 1;
	for(auto v : adj[u]) {
		if(v == parent)continue;
		dfs(v, u);
		sz[u] += sz[v];
		ways[u] = (ways[u] * ways[v]) % MOD;
		ways[u] = (ways[u] * inve[sz[v]]) % MOD;
	}
	ways[u] = (ways[u] * fact[sz[u] - 1]) % MOD;
}

ll realways[N];
void reroot(int u, int parent) {
	realways[u] = ways[u];
	for(auto v : adj[u]) {
		if(v == parent)continue;
		
		ll romperu = (invmod(ways[v], MOD) * fact[sz[v]]) % MOD;
		romperu = (romperu * inve[sz[u] - 1]) % MOD;
		romperu = (romperu * fact[sz[u] - sz[v] - 1]) % MOD;
		ll szu = sz[u];
		ll waysu = ways[u];
		ways[u] = (ways[u] * romperu) % MOD;
		sz[u] -= sz[v];
	//	cout <<u << " " << ways[u] << "\n";
		ll unirv = (ways[u] * fact[szu - 1]) % MOD;
		unirv = (unirv * inve[sz[v] - 1]) % MOD;
		sz[v] = szu;
		unirv = (unirv * inve[sz[u]]) % MOD;
		ways[v] = (ways[v] * unirv) % MOD;
		
		reroot(v, u);
		
		ways[u] = waysu;
		sz[u] = szu;
	}
}
int main() {
	fact[0] = 1;
	for(int i = 1; i < N; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
	}
	for(int i = 0; i < N; i++) {
		inve[i] = invmod(fact[i], MOD);
	}
	int n;
	cin >> n;
	for(int i = 0, u, v; i < n -1; i++) {
		cin >> u >> v;
		u--, v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	dfs(0, 0);
	reroot(0, 0);
	for(int i = 0; i < n; i++) cout << realways[i] << "\n";
	return 0;
}


Measured memory_bytes: 21748