akhauriyash/Code-Regression huggingface dataset:
from collections import deque
N,M,K=map(int,input().split())
friend=[deque([]) for _ in range(N+1)]
block=[deque([]) for _ in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  friend[a].append(b)
  friend[b].append(a)
for i in range(K):
  c,d=map(int,input().split())
  block[c].append(d)
  block[d].append(c)
stack=deque()
group=[-1]*(N+1)
visited=[-1]*(N+1)
dic={}
for i in range(1,N+1):
  stack.append(i)
  main=i
  cnt=0
  while len(stack)>0:
    now=stack.popleft()
    if group[now]!=-1:
        continue
    stack.extend(friend[now])
    group[now]=main
    cnt+=1
  if cnt!=0:
    dic[main]=cnt

for i in range(1,N+1):
  ans=dic[group[i]]
  ans-=1
  ans-=len(friend[i])
  for j in block[i]:
    if group[j]==group[i]:
      ans-=1
  print(ans)

Measured memory_bytes: 158520
n, h = map(int, input().split())
e = [[int(i) for i in input().split()] for i in range(n)] 
x=0
a_list = [e[i][0] for i in range(n)]
t_list = [e[i][1] for i in range(n)]
a=max(a_list)
t_list=sorted((i for i in t_list if i >a),reverse=True)
if h>sum(t_list):
  h=h-sum(t_list)
  x=len(t_list)+(-(-h//a))
else:
  for i in range(len(t_list)):
    h=h-t_list[i]
    x=x+1
    if h<=0:
      break 
print(x)

Measured memory_bytes: 23868
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
ll a,b,c,d;
int main(){
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    ll ans=a*c;
    ans=max(ans,max(a*d,b*c));
    ans=max(ans,b*d);
    printf("%lld\n",ans);


    return 0;
}


Measured memory_bytes: 3828
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

#define INF 1e9

int main(){
  int n;
  string s;
  cin >> s;
  n = s.length();
  vector<int> a;
  vector<int> b;
  b.push_back(0);
  for(int i=0;i<n-1;i++){
    if(s[i] == 'R' && s[i+1] == 'L') a.push_back(i);
    if(s[i] == 'L' && s[i+1] == 'R') b.push_back(i+1);
  }
  b.push_back(n);
  int ans[n];
  int p,q,r;
  for(int i=0;i<n;i++){
    ans[i] = 0;
  }

  for(int i=0;i<a.size();i++){
    p = b[i];
    q = a[i];
    r = b[i+1]-1;
    ans[q] += 1;
    ans[q+1] += 1;
    ans[q] += (q-p)/2;
    ans[q+1] += (q-p) - (q-p)/2;
    ans[q] += (r-q-1) - (r-q-1)/2;
    ans[q+1] += (r-q-1)/2;
  }

  for(int i=0;i<n;i++){
    cout << ans[i] << ' ';
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 1532
using System;
namespace inonoa{
    class Inonoa{
        static void Main(){
            int n = int.Parse(Console.ReadLine());
            string[] sa = Console.ReadLine().Split();
            int[] a = new int[n];
            for(int i=0;i<n;i++){
                a[i] = int.Parse(sa[i]);
            }

            Array.Sort(a);

            int kosuu = 0;
            int now = 0;
            int ans = 0;
            for(int i=0;i<n;i++){
                if(a[i]!=now){
                    if(kosuu>=now){ans += kosuu-now;} else{ans += kosuu;}
                    now=a[i];
                    kosuu=1;
                    }
                else{kosuu++;}
            }
            if(kosuu>=now){ans += kosuu-now;} else{ans += kosuu;}
            Console.WriteLine(ans);
        }
    }
}

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

using namespace std;

#define PB push_back
#define ALL(v) (v).begin(), (v).end()
#define SZ size()
#define FOR(i, a, n) for(long long (i) = (a); (i) < (n); (i)++)
#define REP(i, n) FOR((i), 0, (n))
#define SHOW(v) cout << (v) << endl
#define SHOW2(a, b) cout << (a) << " " << (b) << endl
#define SHOW3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define GET(v) cin >> (v)
#define GET2(a, b) cin >> (a) >> (b)
#define GET3(a, b, c) cin >> (a) >> (b) >> (c)
#define MOD 1000000007
template<class T> void GETV(T &v) { REP(i, v.size()) { GET(v[i]); } }
template<class T> void SHOWV(T &v) { REP(i, v.size()) { SHOW(v[i]); } }

typedef long long ll;

double absd(double a)
{
    return a > 0 ? a : -a;
}

int main()
{
    int n;
    double t, a;
    GET3(n, t, a);
    
    vector<int> v(n);
    GETV(v);
    
    double x = 0.0;
    int ans = 0;
    REP(i, n) {
        if(i == 0) {
            x = t - (v[i] * 0.006);
            ans = 1;
        }
        else {
            if(absd(a - x) > absd(a - (t - (v[i] * 0.006)))) {
                x = t - (v[i] * 0.006);
                ans = i + 1;
            }
        }
    }
                         
    SHOW(ans);
    
    return 0;
}



Measured memory_bytes: 256
/* 
/*-----------------------------------------------*/
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long int ll;
typedef vector<ll> vll;
/*-----------------------------------------------*/
// #define DBGMODE
#ifdef DBGMODE
	#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
	#define debug(...)
#endif
/*-----------------------------------------------*/

/*-----------------------------------------------*/
int main() {
	#ifdef DBGMODE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	char c;
	scanf(" %c", &c);
	if (c == 'A') c = 'T';
	else if (c == 'T') c = 'A';
	else if (c == 'C') c = 'G';
	else if (c == 'G') c = 'C';
	printf("%c\n", c);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 2e5 + 5;
pair<int, int> a[N];
int ans[N];

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

    int n;
    cin >> n;

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

    sort(a, a + n);

    for (int i = 0; i < n; i++) {
        if (i < n / 2)
            ans[a[i].second] = a[n / 2].first;
        else
            ans[a[i].second] = a[n / 2 - 1].first;
    }

    for (int i = 0; i < n; i++) {
        cout << ans[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

using graph = vector<vector<int>>;

pair<int, vector<int>> t_sort(const graph& g){
    const int n = g.size();
    vector<int> sorted;
    vector<int> in(n, 0);
    vector<int> dis(n, 0);

    for(int v=0; v<n; v++){
        for(const auto& to: g[v]){
            in[to]++;
        }
    }

    queue<int> que;

    for(int i=0; i<n; i++){
        if(in[i] == 0){
            que.push(i);
        }
    }

    while(!que.empty()){
        int now = que.front(); que.pop();
        sorted.emplace_back(now);
        for(const auto& to: g[now]){
            in[to]--;
            dis[to] = max(dis[to], dis[now] + 1);
            if(in[to] == 0){
                que.push(to);
            }
        }
    }

    return {*max_element(dis.begin(), dis.end()), sorted};
;}


int solve(int n, const graph& g) {
    auto res = t_sort(g);  
    
    if (res.second.size() != n) {
        return -1;
    } else {
        return res.first + 1;
    }
}

int main() {
    int n; cin >> n;
    
    auto a = make_v(n, n - 1, 0);
    REP(i, n)REP(j, n - 1) {
        cin >> a[i][j];
        --a[i][j];
    }

    auto encode = [](int i, int j) {
        return (i + 2) * (i + 1) / 2 - (i - j) - 1;
    };

    graph g(n * (n - 1) / 2);
    REP(i, n)REP(j, n - 2) {
        int x1 = i, x2 = i, y1 = a[i][j], y2 = a[i][j + 1];
        if (x1 > y1) swap(x1, y1);
        if (x2 > y2) swap(x2, y2);

        g[encode(y1 - 1, x1)].push_back(encode(y2 - 1, x2));
    }
    

    cout << solve(n * (n - 1) / 2, g) << endl;

    return 0;
}


Measured memory_bytes: 39412
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Usize1},
};

struct UnionFind {
    c: std::cell::RefCell<Box<[isize]>>,
}

use std::mem::swap;

impl UnionFind {
    pub fn new(n: usize) -> Self {
        Self {
            c: std::cell::RefCell::new(vec![-1; n].into_boxed_slice()),
        }
    }

    pub fn find(&self, mut x: usize) -> usize {
        let c = &mut *self.c.borrow_mut();
        let mut r = x;
        while c[r] >= 0 {
            r = c[r] as usize;
        }
        while x != r {
            let t = c[x] as usize;
            c[x] = r as isize;
            x = t;
        }
        r
    }

    pub fn unite(&mut self, mut x: usize, mut y: usize) -> (usize, usize) {
        x = self.find(x);
        y = self.find(y);
        let c = &mut *self.c.borrow_mut();
        if x != y {
            if c[x] < c[y] {
                swap(&mut x, &mut y);
            }
            c[x] += c[y];
            c[y] = x as isize;
        }
        (x, y)
    }

    pub fn size(&self, mut x: usize) -> usize {
        x = self.find(x);
        -self.c.borrow()[x] as usize
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        es: [(Usize1, Usize1); m],
    }
    let mut uf = UnionFind::new(n);
    for (a, b) in es {
        uf.unite(a, b);
    }
    println!("{}", (0..n).map(|i| uf.size(i)).max().unwrap());
}


Measured memory_bytes: 9172
#include <stdio.h>

int main(){
int x,y,z,tyo = 0,hisi = 0;

while(scanf("%d,%d,%d",&x,&y,&z) != EOF){
if(x*x + y*y == z*z) tyo++;
if(x == y) hisi++;
}

printf("%d\n%d\n",tyo,hisi);

return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define SQ(X) ((X)*(X))
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
struct UnionFind{
	int par[10010],rank[10010];
	void init(int n){
		for(int i=0;i<n;i++){
			par[i]=i;
			rank[i]=0;
		}
	}
	int find(int x){
		if(par[x]==x)return x;
		else return par[x]=find(par[x]);
	}
	void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x==y)return;
		if(rank[x]>rank[y])par[y]=x;
		else{
			if(rank[x]==rank[y])rank[y]++;
			par[x]=y;
		}
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
}uf;
struct edge{
	int a,b;
	double len;
	edge(){a=b=0;len=0.0;}
	edge(int a,int b,double len):a(a),b(b),len(len){};
	bool operator<(const edge& a) const{
		return len > a.len;
	}
};
int N,M;
double x[10010],y[10010];
int p[200010],q[200010];
double dist(int a,int b){
	return sqrt(SQ(x[a]-x[b])+SQ(y[a]-y[b]));
}
vector<edge> es;
int main(){
	scanf("%d %d",&N,&M);
	for(int i=0;i<N;i++){
		scanf("%lf %lf",&x[i],&y[i]);
	}
	double ans = 0.0;
	for(int i=0;i<M;i++){
		scanf("%d %d",&p[i],&q[i]);
		p[i]--;
		q[i]--;
		es.pb(edge(p[i],q[i],dist(p[i],q[i])));
	}
	sort(all(es));
	uf.init(N);
	for(int i=0;i<es.size();i++){
		int a = es[i].a;
		int b = es[i].b;
		if(uf.same(a,b))ans += es[i].len;
		else{
			uf.unite(a,b);
		}
	}
	printf("%.12f\n",ans);
	return 0;
}

Measured memory_bytes: 3948
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
typedef  long long LL;
const int N = 1e5+5;
int ret[N],cur[N];
int main(){
  int n,m;
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;++i)ret[i]=1,cur[i]=0;
  cur[1]=1;
  while(m--){
    int x,y;
    scanf("%d%d",&x,&y);
    if(cur[x]){
      if(ret[x]==1)cur[x]=0;
      cur[y]=1;
    }
    --ret[x];++ret[y];
  }
  int ans=0;
  for(int i=1;i<=n;++i)if(cur[i])++ans;
    printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int x,a,b;
    cin >> x >> a >> b;
    int da = abs(x-a);
    int db = abs(x-b);
    if(da<db){
        put("A");
    }else{
        put("B");
    }
    return 0;
}


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

#define Pi acos(-1)

using namespace std;

int main()
{
  int N, M, sum = 0, res;

  cin >> N >> M;

  int ara[M];

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

  for(int i = 0; i < M; i++)
  {
      sum += ara[i];
  }

  if(sum > N)
  {
      cout << "-1\n";
  }

  else
  {
      res = N - sum;

      cout << res << "\n";
  }

}


Measured memory_bytes: 3660
N = int(input())

A_list = list(map(int, input().split()))

B_list = list(map(int, input().split()))

C_list = list(map(int, input().split()))


last_meal = -100

res = 0

for meal in A_list:
        res += B_list[meal - 1]
        if meal == last_meal + 1:
                res+= C_list[meal-2]
        last_meal = meal


print(res)

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong N;
	vector<llong> A;
	vector<llong> pm = {1, -1};
	vector<vector<llong> > rui;

	cin >> N;
	A.resize(N);
	rui.resize(2, vector<llong>(N+1, 0));
	llong sum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	for (int i = 0; i < N; ++i) {
		rui[0][i+1] = rui[0][i] + A[(i-1+N)%N]*pm[i%2];
		rui[1][i+1] = rui[1][i] + A[(i-1+N)%N]*pm[(i+1)%2];
	}

	for (int i = 0; i < N; ++i) {
		cout << 2*rui[i%2][i+1] - rui[i%2][N] << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define mp make_pair
using namespace std;
int w, h, k;
char ch[810][810];
bool vis[810][810];

const int xx[4] = {0, 1, 0, -1};
const int yy[4] = {1, 0, -1, 0};

vector<pair<int, int> > pt;
queue<pair< pair<int, int>, int> > Q;
void bfs(int x, int y, int time)
{
	Q.push(mp(mp(x, y), 0));
	vis[x][y] = 1;
	while(!Q.empty())
	{
		pair< pair<int, int>, int> now = Q.front();
		pt.pb(now.X);
		if(now.Y == k) break;
		Q.pop();
		for(int i = 0; i < 4; i ++)
		{
			int x = now.X.X + xx[i];
			int y = now.X.Y + yy[i];
			if(vis[x][y]) continue;
			if(x <= 0 || y <= 0 || x > h || y > w) continue;
			if(ch[x][y] == '#') continue;
			vis[x][y] = 1;
			Q.push(mp(mp(x, y), now.Y + 1));
		}
	}
}

int main()
{
	cin >> h >> w >> k;
	for(int i = 1; i <= h; i ++)
		scanf("%s", ch[i] + 1);
	int stx, sty;
	for(int i = 1; i <= h; i ++)
		for(int j = 1; j <= w; j ++)
			if(ch[i][j] == 'S')
				{stx = i; sty = j; break;}

	if(stx == 1 || sty == 1 || stx == w || sty == h) {cout << 0 << endl; return 0;}
	//cout << stx << " " << sty << endl;
	vis[stx][sty] = 1;
	bfs(stx, sty, 0);
	while(!Q.empty())
	{
		pt.push_back(Q.front().X);
		Q.pop();
	}
	int n = pt.size(), dis = 1e7;
	for(int i = 0; i < n; i ++)
	{
		int x = pt[i].X;
		int y = pt[i].Y;
		dis = min(dis, x - 1);
		dis = min(dis, y - 1);
		dis = min(dis, h - x);
		dis = min(dis, w - y);
	}
	cout << 1 + ceil((double)dis / k);
	return 0;
}


Measured memory_bytes: 9972
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char b[4];
	long long a,c;
	cin>>a>>b[0]>>b[1]>>b[2]>>b[3];
	c=(b[0]-'0')*100+(b[2]-'0')*10+b[3]-'0';
	cout<<a*c/100;
	return 0;
}
//It's AC.I'm SURE.

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    LL a,b; cin >> a >> b;
    if(a*b <= 0){
        cout << "Zero" << endl;
        return 0;
    }

    if(a > 0){
        cout << "Positive" << endl;
    }else{
        LL cnt = b-a+1;
        if(cnt%2 == 0){
            cout << "Positive" << endl;
        }else{
            cout << "Negative" << endl;

        }
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define ll long long
#define ld long double
#define int ll
#define pb push_back
#define ii pair<int,int>
#define llll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<ii>
#define vllll vector<llll>
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define arrin(x,n) int x[n]; for(int o=0;o<n;o++) cin>>x[o]
#define arrout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<'='<<x<<endl
#define deb2(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
#define deb3(x,y,z) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<" "<<#z<<'='<<z<<endl
#define debarr(arr,n) for(int o=0;o<n;o++) deb2(o,arr[o])
#define IO freopen("input.txt", "r", stdin); freopen("output.txt", "w+", stdout)
const double pi = 3.14159265358979323846;

ll power(ll a, ll b){//a^b
    ll res=1;
    //a=a%MOD;
    while(b>0){
        if(b&1)
		{res=(res*a);
		//res%=MOD;
		b--;}
        a=(a*a);
        //a%=MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int C(int n,int k)
{
	int ans=1;
	if(k>n-k)
	k=n-k;
	for(int i=1;i<=k;i++)
	ans*=(n-i+1),ans/=i;
	return ans;
}

void solve()
{

	int i=0,j=0,k=0,n,m,p,sum=0,cnt=0;
	cin>>n;
	string s;
	cin>>s;
	vi w,r;
	for(i=0;i<n;i++)
	{
	    if(s[i]=='R')
	    r.pb(i);
	    else
	    w.pb(i);
	}
	if(r.size()==0)
	cout<<0;
	else if(w.size()==0)
	cout<<0;
	else
	{
	    i=0;j=r.size()-1;
	    while(i<w.size() and j>=0)
	    {
	        if(w[i]>r[j])
	        break;
	        sum++;
	        i++;
	        j--;
	        
	    }
	    cout<<sum;
	}
}
int32_t main() {
    fast
    //IO;
	//cout<<fixed<<setprecision(6);
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  

Measured memory_bytes: 5692
// https://atcoder.jp/contests/dp/tasks/dp_x

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

const int N_MAX = 1e3;
const int W_MAX = 1e4;
const int S_MAX = 1e4;
const int DP_MAX = S_MAX + W_MAX + 1;

struct blk {
  int w, s, v;
  bool operator < (const blk &b) const {
    return w + s < b.w + b.s;
  }
};

int N;
blk b[N_MAX];

ll dp[DP_MAX];

void solve() {
  sort(b, b + N);
  // REP(i, N) printf("(%d %d %d)%c", b[i].w, b[i].s, b[i].v, i + 1 == N ? '\n' : ' ');
  REP(i, N) {
    int w = b[i].w;
    int s = b[i].s;
    int v = b[i].v;
    // for (int j = min(s + w, W_MAX); j >= w; j--) {
    //   dp[j] = max(dp[j], dp[j - w] + v);
    // }
    for (int j = s; j >= 0; j--) {
      dp[j + w] = max(dp[j + w], dp[j] + v);
    }
    // DUMP(dp, 11);
  }
  ll ans = 0;
  REP(j, DP_MAX) ans = max(ans, dp[j]);
  printf("%lld\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, N) {
    int w, s, v;
    scanf("%d%d%d", &w, &s, &v);
    b[i] = { w, s, v };
  }
}

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

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

void solve(){
    ll x,y;
    cin >> x >> y;

    ll A = abs(abs(y) - abs(x));
    if (x == 0 || y == 0) {
        if (x > y) {
            cout << A + 1 << endl;
        }else{
            cout << A << endl;
        }
        return;
    }

    if (x*y < 0) {
        cout << A + 1 << endl;
        return;
    } else {
        if (abs(x) < abs(y)) {
            if (x < y) {
                cout << A << endl;
                return;
            }else{
                cout << A + 2 << endl;
                return;
            }
        }

        if (x > y) {
            cout << A + 2 << endl;
            return;
        }else{
            cout << A << endl;
        }
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
   string a,b;
   cin >> a >> b;
   a+= b;
   int n = stoi(a);
   for (int i = 0;i*i <= n;i++){
      if (i*i == n) {
         cout << "Yes" << endl;
         return 0;
      }
   }
   cout << "No" << endl;
   
   return 0;
}



Measured memory_bytes: 256
package main
 
import "fmt"
 
func main() {
  var N, A, B int
  fmt.Scan(&N)
  if N == 1 {
    fmt.Println("Hello World")
  } else if N == 2 {
    fmt.Scan(&A)
    fmt.Scan(&B)
    fmt.Println(A+B)  
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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;
}

int main()
{
    int N, X, Y;
    cin >> N >> X >> Y;
    X--;
    Y--;
    vector<int> res(N, 0);
    vector<vector<int>> dp(N, vector<int>(N));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            dp[i][j] = abs(i - j);
        }
    }
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            chmin(dp[i][j], dp[i][X] + dp[Y][j] + 1);
            chmin(dp[i][j], dp[i][Y] + dp[X][j] + 1);
        }
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            res[dp[i][j]]++;
        }
    }
    for (int d = 1; d < N; d++) cout << res[d] << endl;

    return 0;
}


Measured memory_bytes: 18932
import math
a,b,h,m=map(int,input().split())
#x^2+y^2=b^2
#x^2+y^2=a^2
#3-> 90ど
#1-> 30ど(pi/6)
#1分 -> 0.5ど(pi/360)
#60分→360ど
#1分 -> 6ど (pi/30)
ado = math.pi*(h/6 + m/360)
bdo = math.pi*(m/30)
ax = a*math.cos(ado)
ay = a*math.sin(ado)
bx = b*math.cos(bdo)
by = b*math.sin(bdo)
print(math.sqrt((bx-ax)**2 + (by-ay)**2))

Measured memory_bytes: 9576
h, w, k = map(int, input().split())
tizu = [list(input()) for _ in range(h)]
ans = [[0 for _ in range(w)] for _ in range(h)]
pos = 0
bef = 0
bef_flg = True
for i in range(h):
    pos_tmp = pos
    f_st = False
    if "#" in tizu[i]:
        bef_flg = False
        pos += 1
        for j in range(w):
            if tizu[i][j] == "#":
                if f_st:
                    pos += 1
                f_st = True
            ans[i][j] = pos
    else:
        if bef_flg:
            bef += 1
        else:
            for j in range(w):
                ans[i][j] = ans[i - 1][j]

for i in range(bef - 1, -1, -1):
    for j in range(w):
        ans[i][j] = ans[i + 1][j]
for row in ans:
    print(*row)



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

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

using namespace std;

int main(void)
{
	ui N{};
	cin >> N;
	vector<ull> originalBits(N);
	map<ull, ul> mapA{};

	for (size_t i = 0; i < N; ++i)
	{
		cin >> originalBits[i];

		if (mapA.find(originalBits[i]) == mapA.end())
		{
			mapA[originalBits[i]] = 0; // 初めて出現した場合ゼロ初期化
		}
		++mapA[originalBits[i]]; // 残り使用可能回数を出現回数インクリメント
	}
	
	bool ans{ true };

	if(mapA.size() == 1)
	{
		if (mapA.find(0) != mapA.end()
			&& mapA[0] == N)
		{
			ans = true;
		}
		else
		{
			ans = false;
		}
	}
	else if(mapA.size() == 2)
	{
		for (auto p : mapA)
		{
			if (p.first == 0)
			{
				ans &= (p.second == N / 3);
			}
			else
			{
				ans &= (p.second == (N * 2) / 3);
			}
		}
	}
	else if (mapA.size() == 3)
	{
		ull res = accumulate(mapA.begin(), mapA.end(), 0, [](ull res, pair<ull, ul> p) {
			return (res ^ p.first);
		});
		ans = !res && accumulate(mapA.begin(), mapA.end(), true, [&N](bool res, pair<ull, ul> p) {
			return (res & (p.second == N / 3));
		});
	}
	else
	{
		ans = false;
	}

	string ans_txt = ans ? "Yes" : "No";
	cout << ans_txt << endl;

	return 0;
}


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

const int inf = 1e9;
const ll linf = 1e18;

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

    int r, g; cin >> r >> g;
    cout << 2*g - r << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
dp = [[[[1] * 4 for i in range(4)] for j in range(4)] for k in range(n+1)]
dp[3][1][2][0] = 0
dp[3][1][0][2] = 0
dp[3][2][1][0] = 0
if n > 3:
    for i in range(4,n + 1):
        for j in range(4):
            for k in range(4):
                dp[i][3][j][k] = sum(dp[i-1][j][k])
                dp[i][0][j][k] = sum(dp[i-1][j][k])
                if j == 1 and k == 0:
                    dp[i][2][j][k] = 0
                else:
                    dp[i][2][j][k] = sum(dp[i - 1][j][k])
                if j == 0 and k == 2:
                    dp[i][1][j][k] = 0
                elif j == 2 and k == 0:
                    dp[i][1][j][k] = 0
                elif k == 2:
                    dp[i][1][j][2] = sum(dp[i - 1][j][k]) - dp[i - 1][j][2][0]
                elif j == 2:
                    dp[i][1][2][k] = sum(dp[i - 1][j][k]) - dp[i-1][2][k][0]
                else:
                    dp[i][1][j][k] = sum(dp[i - 1][j][k])
ans = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans += dp[n][i][j][k] % (10**9 + 7)
print(ans % (10**9 + 7))


Measured memory_bytes: 3440
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            m = 500*i + 100*j + 50*k
            if m == x:
                count += 1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}

int main(){
    iostream_init();
    int N;
    while(cin >> N) {
        vector<pair<int, int>> list;
        REP(i, N) {
            int x, y;
            cin >> x >> y;
            list.push_back(make_pair(x, y));
        }

        LL answer = 0;
        REP(b, 2) {
            LL answer1 = 0;
            set<pair<int, int>> left;
            set<pair<int, int>> right;
            REP(i, N) {
                int x = list[i].first;
                int y = list[i].second;
                left.insert(make_pair(x, i));
                right.insert(make_pair(y, i));
            }
            int cur = 0;
            REP(i, N) {
                const int left_max = (--left.end())->first;
                const int left_max_idx = (--left.end())->second;
                const int right_min = (right.begin())->first;
                const int right_min_idx = (right.begin())->second;
                const bool left_ok = (cur < left_max);
                const bool right_ok = (right_min < cur);
                const int left_d = abs(cur - left_max);
                const int right_d = abs(cur - right_min);
                int next = INT_MIN;
                int idx = -1;
                if ((i + b) % 2 == 0) {
                    if (!left_ok) {
                        break;
                    }
                    next = left_max;
                    idx = left_max_idx;
                } else {
                    if (!right_ok) {
                        break;
                    }
                    next = right_min;
                    idx = right_min_idx;
                }
                assert(next != INT_MIN);
                assert(idx != -1);
                left.erase(make_pair(list[idx].first, idx));
                right.erase(make_pair(list[idx].second, idx));
                answer1 += abs(next - cur);
                cur = next;
            }
            answer1 += abs(0 - cur);
            answer = max(answer, answer1);
        }
        cout << answer << endl;
    }
    return 0;
}


Measured memory_bytes: 10484
#include<bits/stdc++.h>
#define line cout<<endl;
#define space cout<<" ";
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI 3.141592653589793238
typedef long long int ll;

using namespace std;

const int N = 1e9+7;

vector<ll> v(100005);
ll dp[100005];

ll findans(ll n)
{
    if(n<0)
    {
        return INT_MAX;
    }
    if(n==0)
    {
        return 0;
    }

    if(dp[n]!=-1)
    {
        return dp[n];
    }

    return dp[n] =  min(abs(v[n-2]-v[n])+findans(n-2),abs(v[n-1]-v[n])+findans(n-1));

}

ll findans_iterative(ll n)
{
        dp[0]  = 0;
        dp[1]= abs(v[0]-v[1]);

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

void solve()
{
    memset(dp,-1,sizeof(dp));
    ll n;
    cin>>n;

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

    //ll ans = findans(n-1);
    ll ans = findans_iterative(n);
    cout<<ans;

}


int main()
{
   ll t;
   t = 1;
  // cin>>t;

   while(t--)
   {
       solve();
       cout<<endl;
   }




}













Measured memory_bytes: 4648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep1(i, n) for(ll i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  ll n;
  cin >>n;
  vector<ll> a(n),b(n),c(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];
  sort(a);
  sort(c);
  ll ans = 0;
  rep(i,n){//b[i]
    
    //aを処理
    ll l = 0;
    ll r = n;
    while(l<r-1){//lとrが2以上離れている間繰り返す
      ll m = (l+r)/2;//m = middle
      if(a[m] < b[i]) l = m;
      if(a[m] >= b[i]) r = m;
    }//while
    //ここで候補を2つまで絞れた
    ll arange;
    if(a[l] < b[i]) arange = l+1;
    if(a[l] >= b[i]) arange = l;
    
    //bを処理
    l = 0;
    r = n;
    while(l<r-1){//lとrが2以上離れている間繰り返す
      ll m = (l+r)/2;//m = middle
      if(c[m] <= b[i]) l = m;
      if(c[m] > b[i]) r = m;
    }//while
    //ここで候補を2つまで絞れた
    ll crange;
    if(c[l] <= b[i]) crange = n-l-1;
    if(c[l] > b[i]) crange = n-l;
    
    ans += arange*crange;
  }//i
  cout << ans << endl;
}

Measured memory_bytes: 2688
#include <stdio.h>
#define swap(a,b) (a ^= b,b = a ^ b,a ^= b)

int main(void) {
	int w,n,a[31],i,x,y;
	scanf("%d %d",&w,&n);
	for(i=1;i<=w;i++) {
		a[i]=i;
	}
	for(i=0;i<n;i++) {
		scanf("%d,%d",&x,&y);
		swap(a[x],a[y]);
	}
	for(i=1;i<=w;i++) {
		printf("%d\n",a[i]);
	}
	return 0;
}

Measured memory_bytes: 596
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

A, B = input().split()

A = int(A)
B = int(B.replace(".", ""))

print(A * B // 100)

Measured memory_bytes: 9704
#include<bits/stdc++.h>
//#include<tr1::unordered_map>
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,a,n) for(int i=n;i>=a;--i)
#define pb push_back
#define fi first
#define se second
#define io std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
const int  maxn=1e5+50;
ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
ll qpow(ll a,ll n)
{
    ll r=1%P;
    for (a%=P; n; a=a*a%P,n>>=1)if(n&1)r=r*a%P;
    return r;
}
bool cmp(int a,int b)
{
  return a>b;
}
ll mp[65][65];
ll ans;
void fen(ll x)
{   ll ans2=0;
    ll ans5=0;
    while(x%5==0)
    {
      x/=5;
      ans5++;
    }
    while(x%2==0)
    {
      x/=2;
      ans2++;
    }
    for(int i=0;i<=64;i++)
      for(int j=0;j<=64;j++)
      {
        if(ans2+i>=18&&ans5+j>=18)
           ans+=mp[i][j];
      }
    mp[ans2][ans5]++;
}
int main()
{  io;
   int n;
   cin>>n;
   for(int i=1;i<=n;i++)
   {
     double x;
     cin>>x;
     ll y=llround(x*1000000000.0);
     fen(y);
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 3648
n = int(input())
h=list(map(int,input().split()))
dp=[0]*(n)
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#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 VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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


int main(){
	string S;
	cin>>S;

	cout<<S[0]<<S.length()-2<<S[S.length()-1]<<endl;
	return 0;
}



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


int main(void){
  string s;
  int dir,qn;
  
  cin >> s >> qn;
  dir = 1;
  for (int i=0; i<qn; i++){
    int t,f;
    cin >> t;
    if (t==1) dir*=-1;
    else { //t==2
      char c;
      cin >> f >> c;
      f = f==1?1:-1;
      if (dir*f>0) s.insert(s.begin(),c);
      else s.push_back(c);
    }
//    cout << dir << " " << s << endl;
  }
  if (dir<0) reverse(s.begin(), s.end());
  cout << s << endl;
  return 0;
}


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

int main(){
    int n;
    string s, t;
    cin >> n >> s >> t;

    string str;
    for(int i = 0; i < n; i++){
        str.push_back(s[i]);
        str.push_back(t[i]);
    }

    cout << str << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
     
    int main(){
    	int A, B, C, X;
    	scanf("%d %d %d %d", &A, &B, &C, &X);
    	
    	int i, j, k, count=0;
    	for(i=0; i<=A; i++){
    		for(j=0; j<=B; j++){
    			for(k=0; k<=C; k++){
    				if(500*i + 100*j + 50*k == X)	count++;
    			}
    		}
    	}
    	
    	printf("%d\n", count);
    	
    	return 0;
    }

Measured memory_bytes: 128
s = list(input())

for i in range(len(s) // 2):
    if s[i] != s[len(s) - i - 1]:
        print("No")
        exit()

l = s[0:(len(s) - 1) // 2]
for i in range(len(l) // 2):
    if l[i] != l[len(l) - i - 1]:
        print("No")
        exit()

l = s[(len(s) + 3) // 2 - 1:len(s)]
for i in range(len(l) // 2):
    if l[i] != l[len(l) - i - 1]:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

ll divl[40000];
ll cnt[40000];
ll dp[105][40000];
ll dp2[105][40000];
ll sum[40000];
int main() {
    init();
    ll N,K;
    cin >> N >> K;
    ll sqN = (ll)sqrt(N);

    repe(i, 1, sqN + 1) divl[i] = N / i;
    repe(i, 1, sqN) cnt[i] = divl[i] - divl[i + 1];
    cnt[sqN] = divl[sqN] - sqN;

    // dp[i+1][k] i番目の整数がkであるような個数
    // dp2[i+1][k] i-1番目の整数がkのときにとりうることのできるsqNより大きい整数の個数和
    // sum[k] dp[i][1]~dp[i][k]までの個数
    
    dp[0][1] = 1;
    repe(i, 1, sqN + 1) sum[i] = 1;
    rep(i,K){
        repe(j,1,sqN+1){
            // dp -> dp
            (dp[i + 1][1] += dp[i][j]) %= MOD;
            (dp[i + 1][sqN + 1] += MOD - dp[i][j]) %= MOD;
            
            // sum -> dp2
            (dp2[i + 1][j] += cnt[j]*sum[j]) %= MOD;

            // dp2 -> dp
            (dp[i + 1][1] += dp2[i][j]) %= MOD;
            (dp[i + 1][j + 1] += MOD - dp2[i][j]) %= MOD;
        }

        sum[0] = 0;
        // imos
        repe(j,1,sqN+1){
            (dp[i + 1][j + 1] += dp[i + 1][j]) %= MOD;
            sum[j] = sum[j - 1] + dp[i + 1][j];
        }
    }

    ll ans = 0;
    repe(j, 1, sqN + 1)(ans += dp[K][j]) %= MOD;
    repe(j, 1, sqN + 1)(ans += dp2[K][j]) %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 65664
# maspy
p=list(map(int,input()))

def solve(n):
    dp=0,1
    for i in n:
        a=min(dp[0]+i,dp[1]+10-i)
        b=min(dp[0]+i+1,dp[1]+10-i-1)
        dp=a,b
    return dp[0]
print(solve(p))

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

int main() {
	int n;
	while(cin >> n, n) {
		vector<int> v;
		int f;
		for(int i = 0; i < n; i++) {
			int tmp;
			cin >> tmp; v.push_back(tmp);
		}
		cin >> f;

		int l, r;
		l = 0; r = v.size() - 1;
		int ans = 0;
		while(l <= r) {
			int m;
			m = (l + r) / 2;
			ans++;
			if(v[m] == f)
				break;
			else if(v[m] < f)
				l = m + 1;
			else
				r = m - 1;
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int main() {
    string s; cin >> s;
    cout << (s == "ARC" ? "ABC" : "ARC") << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int a[8]={1,2,4,8,16,32,64,128};
int main(){
	int n;
	cin>>n;
	int i;
	for(i=0;i<8;i++){
		if(a[i]>n){
			i--;
			break;
		}
	}
	cout<<a[i]<<endl;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let x: i64 = iterator.next().unwrap().parse().unwrap();
    let y: i64 = iterator.next().unwrap().parse().unwrap();

    let ans =
        if x == y {
            0
        } else if x > 0 && y == 0 {
            x + 1
        } else if x < 0 && y == 0 {
            -x
        } else if x >= 0 && y >= 0 {
            if x <= y {
                y - x
            } else {
                x - y + 2
            }
        } else if x >= 0 && y < 0 {
            if x <= -y {
                (-y) - x + 1
            } else {
                x - (-y) + 1
            }
        } else if x < 0 && y >= 0 {
            if -x <= y {
                y - (-x) + 1
            } else {
                (-x) - y + 1
            }
        } else {
            if -x <= -y {
                (-y) - (-x) + 2
            } else {
                (-x) - (-y)
            }
        };

    return ans.to_string();
}


Measured memory_bytes: 4352
a,b,x = map(int,input().split())
import math
if a**2*b / 2 <=  x:
    alpha = math.degrees(math.atan(2 * (a**2 * b - x) / a**3))
else:
    alpha =  math.degrees(math.atan(a*b**2 / (2*x) ))
    
print(alpha)

Measured memory_bytes: 3060
package main

import (
	"math"
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪func•*¨*•.¸¸♪

type point struct {
	x float64
	y float64
}

func dist(p1,p2 point) float64 {
	return math.Sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y))
}

func gaishin(a,b,c int, p []point) point {
	aa := (p[b].x-p[c].x)*(p[b].x-p[c].x)+(p[b].y-p[c].y)*(p[b].y-p[c].y)
	bb := (p[c].x-p[a].x)*(p[c].x-p[a].x)+(p[c].y-p[a].y)*(p[c].y-p[a].y)
	cc := (p[a].x-p[b].x)*(p[a].x-p[b].x)+(p[a].y-p[b].y)*(p[a].y-p[b].y)
	deno := aa*(bb+cc-aa)+bb*(cc+aa-bb)+cc*(aa+bb-cc)
	x := (aa*(bb+cc-aa)*p[a].x+bb*(cc+aa-bb)*p[b].x+cc*(aa+bb-cc)*p[c].x)/deno
	y := (aa*(bb+cc-aa)*p[a].y+bb*(cc+aa-bb)*p[b].y+cc*(aa+bb-cc)*p[c].y)/deno
	
	return point{x,y}
}

func isStraight(a,b,c int, p []point) bool {
	aa := (p[b].x-p[c].x)*(p[b].x-p[c].x)+(p[b].y-p[c].y)*(p[b].y-p[c].y)
	bb := (p[c].x-p[a].x)*(p[c].x-p[a].x)+(p[c].y-p[a].y)*(p[c].y-p[a].y)
	cc := (p[a].x-p[b].x)*(p[a].x-p[b].x)+(p[a].y-p[b].y)*(p[a].y-p[b].y)
	if aa*(bb+cc-aa)+bb*(cc+aa-bb)+cc*(aa+bb-cc)==0 {
		return true
	}
	return false
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	n := scanInt()
	
	p := make([]point, n)

	for i := 0; i < n; i++ {
		p[i] = point{scanFloat64(), scanFloat64()}
	}

	ca := make([]point, 0)

	for i := 0; i < n; i++ {
		for j := i+1; j < n; j++ {
			ca = append(ca,point{(p[i].x+p[j].x)/2,(p[i].y+p[j].y)/2})
			for k := j+1; k < n; k++ {
				if isStraight(i,j,k,p) {
					continue
				}
				
				ca = append(ca, gaishin(i,j,k,p))

			}
		}
	}

	mi := float64(10000)

	for _, e := range ca {
		ma := float64(0)
		for i := 0; i < n; i++ {
			ma = math.Max(ma, dist(e,p[i]))
		}
		mi = math.Min(mi,ma)
	}

	fmt.Println(mi)

}


Measured memory_bytes: 2432
import itertools
n = int(input())
a_ = list(map(int, input().split()))
q_ = list(map(int, input().split()))
a = ""
q = ""
for i in range(n):
    a += str(a_[i])
    q += str(q_[i])

l = list(map(str, range(1, n+1)))
p = itertools.permutations(l, n)

d_ = []
for v in p:
    str_ = ""
    for c in v:
        str_ += str(c)
    d_.append(str_)
d_.sort()

dict_ = {}
for i, v in enumerate(d_):
    dict_[v] = i + 1

print(abs(dict_[a] - dict_[q]))

Measured memory_bytes: 9004
# dfs使えばいいんじゃないかな
n, m = gets.chomp.split.map(&:to_i)
graph = Array.new(n).map{[]}
m.times do
  a, b = gets.chomp.split.map(&:to_i)
  graph[a-1] << b-1
  graph[b-1] << a-1
end
# p graph
Track = Struct.new(:nowpath, :visited)

paths = [Track.new(graph[0], [0])]
ans = 0
while paths.size > 0 do
  cur = paths.pop
  ans += cur.visited.size == n ? 1 : 0
  # puts "next available: #{cur.nowpath}"
  cur.nowpath.each do |next_id|
    unless cur.visited.include?(next_id)
      # p cur.visited
      next_track = Track.new(graph[next_id], cur.visited.clone << next_id)
      paths << next_track
    end
  end
end

puts ans

Measured memory_bytes: 2300
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

ll solve(ll N, ll M);

int main() {

    ll N, M;

    cin >> N >> M;

    ll ans;

    if (abs(N - M) > 1) {
        ans = 0;
    }
    else {
        ans = solve(N, M);
    }

    cout << ans;

    return 0;
}

ll solve(ll N, ll M) {
    ll tmp = 1, x = pow(10, 9) + 7;

    repl(i, 1, N + 1) {
        tmp *= i;
        if (tmp > x) {
            tmp %= x;
        }
    }
    repl(i, 1, M + 1) {
        tmp *= i;
        if (tmp > x) {
            tmp %= x;
        }
    }
    if (N == M) {
        tmp *= 2;
        if (tmp > x) {
            tmp %= x;
        }
    }

    return tmp;
}



Measured memory_bytes: 3676
import bisect

n = int(input())
l = list(map(int, input().split()))

l.sort()
cnt = 0


for i in range(n-2):
  for j in range(i+1, n-1):
    sum = l[i] + l[j]
    index = bisect.bisect_left(l, sum)
    cnt += index - j - 1

print(cnt)

Measured memory_bytes: 9300
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;

int main(){
	int N;
	cin>>N;
	vector<int> mt(N);
	for(int i = 0; i < N; i++){
		cin>>mt[i];
	}
	int h = mt[0];
	int ct = 1;
	for(int i = 1; i < N; i++){
		if(h <= mt[i])ct++;
		h = max(h, mt[i]);
	}
	cout<<ct<<endl;
	return 0;

}

Measured memory_bytes: 256