akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
string s;
int main(){
    cin>>s;
    s[5]=' ';
    s[13]=' ';
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
from collections import deque

def main():
    H, W = map(int, input().split())
    maze = [input() for _ in range(H)]

    def bfs(i, j):
        dist = [[-1 for _ in range(W)] for _ in range(H)] # dist to each node
        dist[i][j] = 0
        q = deque([(i, j)])
        max_d = 0

        while q:
            i, j = q.popleft()
            max_d = max(max_d, dist[i][j])
            if i+1 < H and maze[i+1][j] == '.' and dist[i+1][j] == -1:
                q.append((i+1, j))
                dist[i+1][j] = dist[i][j] + 1
            if i-1 >= 0 and maze[i-1][j] == '.' and dist[i-1][j] == -1:
                q.append((i-1, j))
                dist[i-1][j] = dist[i][j] + 1
            if j+1 < W and maze[i][j+1] == '.' and dist[i][j+1] == -1:
                q.append((i, j+1))
                dist[i][j+1] = dist[i][j] + 1
            if j-1 >= 0 and maze[i][j-1] == '.' and dist[i][j-1] == -1:
                q.append((i, j-1))
                dist[i][j-1] = dist[i][j] + 1

        return max_d
   
    ret = 0
    for i in range(H):
        for j in range(W):
            if maze[i][j] == '.':
                ret = max(ret, bfs(i, j))
    print(ret)


if __name__ == '__main__':
    main()

Measured memory_bytes: 20900
#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int > Pi;

string KAKEZAN(string a,string b){
  int maxlen = a.size() + b.size(), cnt = 0;
  vector<int> ret(maxlen+1,0);
  string ans;
  reverse(a.begin(),a.end()), reverse(b.begin(),b.end());
  for(int i = 0 ; i < a.size() ; i++){
    for(int j = 0 ; j < b.size() ; j++){
      ret[i+j] += (a[i]-'0') * (b[j]-'0');
    }
  }
  for(int i = 0 ; i < maxlen ; i++){
    ans += (ret[i] % 10) + '0';
    ret[i+1] += ret[i] / 10;
  }
  reverse(ans.begin(),ans.end());
  while(ans[cnt] == '0') cnt++;
  return ans.substr(cnt);
}

string pow_mod(string x, int n) {
  string ret = "1";
  while(n > 0){
    if(n & 1) ret = KAKEZAN( ret, x);
    x = KAKEZAN( x, x);
    n >>= 1;
  }
  return ret;
}

string dedecode(string s, int a){
  int buff = atoi(s.substr( max< int >( 0, a), 4 + min< int >( 0, a)).c_str());
  stringstream sss; sss << buff;
  return sss.str();
}
string decode(string s){
  string ext[] = { "", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"};

  string ret = "";
  for(int i = 4; (int)s.size() - i + 3 >= 0; i += 4){
    string temp = dedecode( s, s.size() - i);
    if(temp != "0") ret = temp + ext[i / 4 - 1] + ret;
  }
  return ret;
}

int main(){
  string m;
  int n;
  while(cin >> m >> n, n){
    cout << decode(pow_mod( m, n)) << endl;
  }
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second 
#define ll long long 
#define _for(i,j,k) for(int i=j;i<k;i++)
#define endl  '\n'
#define inf 1<<29
const int mod=1e9+7;
const int MAX=1e6+5;
ll a[MAX]; 
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	ll k,n,sum=0;
	cin>>k>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll Max=-1;
	for(int i=1;i<n;i++)
	{
		sum+=a[i]-a[i-1];
		Max=max(Max,a[i]-a[i-1]);
	}
	sum+=k-a[n-1]+a[0];
	Max=max(Max,k-a[n-1]+a[0]);
	cout<<sum-Max;	
}


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

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

            int[] data = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray();

            int searchNum = 1; //今探している数
            int index = 0; //今探している番号


            while (true)
            {
                if (data[index] == searchNum)
                {
                    searchNum++;
                }
                index++;

                if (index == data.Length)
                    break;
            }

            if (searchNum == 1)
                Console.WriteLine("-1");
            else
                Console.WriteLine(N - searchNum +1);
        }
    }
}


Measured memory_bytes: 34012
import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        int r = scan.nextInt();
        int n = scan.nextInt();
        while (r != 0 || n != 0) {
            for (int s = 0; s < r; s++) {

                for (int i = 0; i < n; i++) {
                    if (s == 0 || s == r - 1 || i == 0 || i == n - 1) {
                        System.out.print("#");
                    } else {
                        System.out.print(".");

                    }
                }
                System.out.println();
            }
            r = scan.nextInt();
            n = scan.nextInt();
            System.out.println();

        }
    }
}



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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;  // or pb_ds;

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#ifndef DEBUG
#define endl "\n"
#endif
#define fff ff
#define sss ss.ff
#define ttt ss.ss
#define INF (1 << 30)
#define LLF (1ll << 60)
#define PRIME (1000000007)
#define FASTIO std::ios::sync_with_stdio(false)
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define FILE_INPUT                  \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)

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

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<string> vs;

template <typename T, typename B = null_type>
using oset =
    tree<T, B, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order / order_of_key

const ld eps = 1e-12;

/*-----------------END TEMPLATE-----------------*/

vi vals;
vi valsR;

int(((((((((((((((main)))))))))))))))() {
  FASTIO;
  vi a(3);
  rep(i, 0, 3) cin >> a[i];
  sort(a.begin(), a.end());
  ll k;
  cin >> k;
  ll mult = (1 << k);
  cout << a[0] + a[1] + mult * a[2] << endl;
}

/*

0 1 2 3 4
      x

*/

Measured memory_bytes: 256
n = int(input())
Adj = [[0 for i in range(n)] for i in range(n)]

for i in range(n):
    u = list(map(int, input().split()))
    if u[1] > 0:
        for i in u[2: 2 + u[1]]:
            Adj[u[0] - 1][i - 1] = 1

for i in range(n):
    print(" ".join(map(str, Adj[i])))

Measured memory_bytes: 7728
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N;
  cin >> N;
  vvi XY(N, vi(2));
  cin >> XY;

  vi p(N);
  rep(i,N) p[i] = i;

  v(f80) distance;
  do {
    f80 d = 0;
    rep(i,N-1){
      d += sqrt(pow((XY[p[i]][0] - XY[p[i+1]][0]),2) + pow((XY[p[i]][1] - XY[p[i+1]][1]),2));
    }
    distance.emplace_back(d);
  } while(next_permutation(rng(p)));

  cout << accumulate(rng(distance), 0.0) / distance.size() << "\n";

}

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

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long

int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
				
int32_t main() {
	fast_cin();  
	int n, m, k; cin >> n >> m >> k;
	int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2;
	--x1, --x2, --y1, --y2;
	string s[n + 1];
	for (int i = 0; i < n; ++i) cin >> s[i];
	queue<pair<int, int> > q;
	q.push({x1, y1});
	int dist[n + 1][m + 1];
	bool vis[n + 1][m + 1];
	memset(vis, false, sizeof vis);
	memset(dist, 5, sizeof dist);
	dist[x1][y1] = 0;
	auto valid = [&](int x, int y) {
		return x >= 0 and x < n and y >= 0 and y < m and s[x][y] != '@';
	};
	while (!q.empty()) {
		auto [x, y] = q.front();
		q.pop();
		vis[x][y] = true;
		for (int dir = 0; dir < 4; ++dir) {
			for (int len = 1; len <= k; ++len) {
				int nx = x + dx[dir] * len, ny = y + dy[dir] * len;
				if (!valid(nx, ny)) break;
				if (vis[nx][ny] and dist[nx][ny] < dist[x][y] + 1) break;
				if (vis[nx][ny]) {
					assert(dist[nx][ny] == dist[x][y] + 1);
					continue;
				}
				dist[nx][ny] = dist[x][y] + 1;
				vis[nx][ny] = true;
				q.push({nx, ny});
			}
		}
	}
	int ans = dist[x2][y2];
	if (!vis[x2][y2]) ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 21900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define vmax 10000
constexpr ll inf = 1e18+7;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int main(){
  cout<<fixed<<setprecision(20);
  cin.tie(0);ios::sync_with_stdio(false);
  ll H,W,h,w;
  cin>>H>>W>>h>>w;
  cout<<H*W-H*w-h*W+h*w<<endl;
  return 0;
}


Measured memory_bytes: 256
<?php

$input = explode(" ", trim(fgets(STDIN)));
$n = $input[0];
$k = $input[1];

$input = explode(" ", trim(fgets(STDIN)));

//準備
$sum=0;
$arrSum[]=$sum;

foreach ($input as $item){
    $sum+=$item;
    $arrSum[]=$sum;
}


//1.どの区間を選択するか
$i = 0;
//1位
$topScore = 0;
//理論値

$lim = ($n - $k + 1);
while ($i < $lim) {
    //区間の和をScore
    $score = $arrSum[$i+$k] - $arrSum[$i];

    if ($topScore < $score) {
        $topScore = $score;
    }
    $i++;
}
//
////2.その場合の期待値はいくつか
////期待値の計算は、(1+Pi)/2 で良い
////スコア÷2と　K÷2の和が期待値
print ($topScore / 2 + $k / 2);


Measured memory_bytes: 29168
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;

int main() {
  int n, m;
  cin >> n >> m;
  vi v(m), dp(70000, INF);
  rep(i, m) {
    cin >> v[i];
    dp[v[i]] = 1;
  }
  dp[0] = 0;
  rep(i, 50008) {
    rep(j, m) { dp[i + v[j]] = min(dp[i] + 1, dp[i + v[j]]); }
  }
  cout << dp[n] << endl;
  return 0;
}

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

int main() {

  string s;
  cin >> s;

  long long int ans = s.size();

  for ( long long int i = 0; i < s.size() - 1; i++ ) {

    if ( s[i] != s[i+1] ) {
      long long int left = i + 1;
      long long int right = s.size() - i - 1;
      ans = min( max( left, right ), ans );
    }

  }

  cout << ans << endl;

  return 0;

}


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

//long long int dp[100][100000+1];
/*
long long int call(long long int i,long long int S,long long int p[],long long int w[])
{
	if(i<0)
		return 0;
	if(S<0)
		return 0;
	if(dp[i][S]!=-1)
		return dp[i][S];
	
	long long int ans=call(i-1,S,p,w);
	if(S>=w[i])
	{
		ans=max(ans,call(i-1,S-w[i],p,w)+p[i]);
	}
	dp[i][S]=ans;
	return dp[i][S];
}*/
int main()
{
	long long int n,W;
	cin>>n>>W;
	
	long long int p[n],w[n];
	
	for(long long int i=0;i<n;i++)
	{
		cin>>w[i]>>p[i];
	}

	//cout<<call(n-1,W,p,w);
	
	long long int dp[n+1][W+1];
	memset(dp,0,sizeof(dp));
	for(long long int i=1;i<=n;i++)
	{
		for(long long int j=1;j<=W;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(j>=w[i-1])
			{
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+p[i-1]);
			}
		}
	}
	cout<<dp[n][W];
	return 0;
}

Measured memory_bytes: 79104
N, K = map(int, input().split())
preans = []
for n in range(K, N+2):
    MIN = (0+n-1) * n / 2
    MAX = (N + (N-n+1)) * n / 2
    preans.append(MAX - MIN+1)
    
print(int(sum(preans)%(10**9 + 7)))

Measured memory_bytes: 16848
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n;
	cin >> n;

	if (n % 2 == 0) {

		cout << n/2-1 << endl;
	}
	else {
		cout << n / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <numeric>
#include <cstdio>
#include <cmath>
using namespace std;

typedef long long s64;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 100000;
const int MaxM = 100000;

int n, m;

struct halfEdge
{
	int v;
	halfEdge *next;
};
halfEdge adj_pool[MaxM * 2], *adj_tail = adj_pool;
halfEdge *adj[MaxN + 1];

inline void addEdge(const int &u, const int &v)
{
	adj_tail->v = v, adj_tail->next = adj[u];
	adj[u] = adj_tail++;
}

int col[MaxN + 1];
int coe[MaxN + 1];

bool vis[MaxN + 1];

int cir_u, cir_v;
bool is_odd = false;

void find_circle(int u, int prev)
{
	vis[u] = true;

	for (halfEdge *e = adj[u]; e; e = e->next)
	{
		if (!vis[e->v])
		{
			col[e->v] = -col[u];
			find_circle(e->v, u);
		}
		else if (e->v != prev)
		{
			cir_u = u, cir_v = e->v;
			if (col[e->v] == col[u])
				is_odd = true;
		}
	}
}

void dfs(int u, int prev)
{
	vis[u] = true;

	for (halfEdge *e = adj[u]; e; e = e->next)
		if (!vis[e->v])
		{
			dfs(e->v, u);
			col[u] += col[e->v];
			coe[u] += coe[e->v];
		}
}

int li_n, li[MaxN + 1];

inline s64 solve()
{
	col[1] = 1;
	find_circle(1, 0);

	int sum = accumulate(col + 1, col + n + 1, 0);
	s64 res = 0;

	if (is_odd)
	{
		if (sum & 1)
			return -1;

		col[cir_u] -= sum / 2;
		col[cir_v] -= sum / 2;
		res += abs(sum) / 2;
	}
	else
	{
		if (sum != 0)
			return -1;
		if (m == n)
			coe[cir_u] = 1, coe[cir_v] = -1;
	}

	for (int u = 1; u <= n; ++u)
		vis[u] = false;
	dfs(1, 0);

	li_n = 0;
	li[li_n++] = 0;
	for (int u = 1; u <= n; ++u)
	{
		if (!coe[u])
			res += abs(col[u]);
		else
		{
			if (coe[u] == 1)
				col[u] = -col[u];
			li[li_n++] = col[u];
		}
	}

	sort(li, li + li_n);

	int v = li[li_n / 2];
	for (int i = 0; i < li_n; ++i)
		res += abs(v - li[i]);

	return res;
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		int u = getint(), v = getint();
		addEdge(u, v);
		addEdge(v, u);
	}

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 10112
class DisjointSet
  def initialize(n)
    @rank = Array.new(n){0}
    @p = (0...n).to_a
  end

  def same(x, y)
    find_set(x) == find_set(y)
  end

  def unite(x, y)
    link(find_set(x), find_set(y))
  end

  def link(x, y)
    if @rank[x] > @rank[y]
      @p[y] = x
    else
      @p[x] = y

      if @rank[x] == @rank[y]
        @rank[y] += 1
      end
    end
  end

  def find_set(x)
    @p[x] = find_set(@p[x]) if x != @p[x]
    @p[x]
  end
end

n, q = gets.split.map(&:to_i)

ds = DisjointSet.new(n)

(0...q).each do |i|
  t, a, b = gets.split.map(&:to_i)

  if t == 0
    ds.unite(a, b)
  elsif t == 1
    puts ds.same(a, b) ? 1 : 0
  end
end


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

int main() {
	int a[3], ans = 0, max = 0;
	cin >> a[0] >> a[1] >> a[2];
	for (int i = 0; i < 3; i++)
	{
		ans += a[i];
		if (max < a[i]) max = a[i];
	}
	ans -= max;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()
#define ull unsigned long long
 
using namespace std;	

int main() {	
	int h1, m1, h2, m2, k;
	scanf ("%d%d%d%d%d", &h1, &m1, &h2, &m2, &k);
	int min = (h2 - h1) * 60 + m2 - m1;
	int ans = max(0, min - k);
	printf ("%d\n", ans);
	
	return 0;
}	


Measured memory_bytes: 3816
#include<bits/stdc++.h>
#define WR "txt"
#define N 200010

void Open() { freopen(WR".in", "r", stdin); freopen(WR".out", "w", stdout); }
void Close() { fclose(stdin); fclose(stdout); }
using namespace std;
int Read()  {
	int val = 0, opt = 1; char ch;
	while (!isdigit(ch = getchar() )) if (ch == '-') opt = -1;
	while (isdigit( ch )) (val *= 10) += ch - '0', ch= getchar();
	return val * opt;
}

int Up[N], Dn[N], Ans1, Ans2, Sum = 0, Max = 0;
int n, l[N], r[N];

void work()  {
	n = Read();
	int u, v;
	for (int i = 1;i <= n; i++)  {
		u = Read(), v = Read();
		Up[u]++, Dn[v]++;
		l[i] = u, r[i] = v;
	}
	for (int i = 1;i <= N - 10; i++)  {
		Max -= Dn[i];
		Max += Up[i];
		Up[i] += Up[i - 1];
		Dn[i] += Dn[i - 1];
		Ans2 = max(Ans2, Max);
	}
	for (int i = 1;i <= n; i++) 
		Ans1 = max(Ans1, Up[r[i] - 1] - Dn[l[i]]);
	printf("%d %d\n", Ans1, Ans2);
}

int main(void)  {
	//Open();
	work();
	//Close();
	return 0;
}


Measured memory_bytes: 6328
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(){
    
	int a, b; cin >> a >> b;
	int cons = 1,ans = 0;
	while (cons < b) {
		cons += (a - 1);
		ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
using namespace std;

int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s.erase(unique(all(s)), s.end());
    cout << s.size() << '\n';
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

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

	sort(all(v));

	for(int i = 1; i < n; i++){
		v[i] = (v[i-1]+v[i])/2.0;
	}
	cout << v[n-1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<int> w(n);
	int s2 = 0;
	for(int i = 0; i < n; ++i) {
		cin >> w[i];
		s2 += w[i];
	}
	
	int s1 = 0;
	int ans = 1e9;
	for(int i = 0; i < n; ++i) {
		s1 += w[i];
		s2 -= w[i];
		
		ans = min(ans, abs(s2 - s1));
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long N, std::vector<long long> A){
  vl x(N);
  ll temp = 0;
  rep(i,N) temp += (A[i] * (i%2==0 ? 1LL:-1LL));
  x[0] = temp/2;
  REP(i,1,N) x[i] = A[i-1]-x[i-1];
  rep(i,N) cout << 2*x[i] << (i==N-1 ? "\n":" ");
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


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

signed main(){
	int n;
	cin>>n;
	int v[n];
	r(i,n)cin>>v[i];
	int q;
	cin>>q;
	while(q--){
		int w,e,re;
		cin>>w>>e>>re;
		swap_ranges(v+w,v+e,v+re);
	}
	r(i,n){
		if(i)cout<<' ';
		cout<<v[i];
	}
	cout<<endl;
}


Measured memory_bytes: 3120
import numpy as np
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(N)]
count = 0
for i in range(N):
    count += (np.dot(A[i],B) + C > 0)
print(count)

Measured memory_bytes: 12664
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007;
vector<vector<int>>dp; // dp(i,j) probablity of coming j heads when i coins
vector<int>v;

int winner(int stones,int player){

        //cout<<stones<<" "<<player<<"\n";
        if(dp[player][stones]!=-1){
            return dp[player][stones];
        }
        int sz = v.size();
        for(int i=0;i<sz;i++){
            if(stones>=v[i] &&(winner(stones-v[i],1-player)==player)){
                return dp[player][stones] =player;
            }
        }
        return dp[player][stones] = 1-player;
}

void solve(){
    int n,k;cin>>n>>k;
    v.resize(n);
    dp.resize(2,vector<int>(k+1,-1));
    dp[0][0] = 1;
    dp[1][0]=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    string x = winner(k,0)==0 ? "First" : "Second";
    cout<<x<<"\n";
}

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

    cout.precision(10);
    int t=1;//cin>>t;
    while(t--){

        solve();
    }
    return 0;
}


Measured memory_bytes: 8824
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  Int ans=0;
  for(Int i=0;i<n;i++) ans+=a[i]-1;
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i <= k; i++)
#define PB push_back
#define MEM(n, val) memset((n), val, sizeof(n))
#define F first
#define S second
#define MP make_pair
#define LL long long
#define MOD 1000000007

int n, m;

class Data  {
public:
    int price, quantity;
};

class cmp   {
public:
    bool operator()(Data a, Data b)   {
        return a.price < b.price;
    }
};

Data datas[100010];



int main()  {
//    freopen("in.txt", "r", stdin);
    cin >> n >> m;
    FOR(i, 0, n - 1)   {
        cin >> datas[i].price >> datas[i].quantity;
    }
    sort(datas, datas + n, cmp());

//    int taken = 0;
    LL ans = 0;
    FOR(i, 0, n - 1)   {
        if(!m)    {
            break;
        }
        LL nisi = min(m, datas[i].quantity);
        ans += (nisi * datas[i].price);
        m -= nisi;
    }
    cout << ans << "\n";


    return 0;
}
/**
*/


Measured memory_bytes: 1024
n = int(input())

digit_dict = {}
for i in range(1,10):
    for j in range(1,10):
        now = i *10 + j
        new = {now:0}
        digit_dict.update(new)

ans = 0

for num in range(1, n+1):
    top = int(str(num)[0])
    end = int(str(num)[-1])
    if end == 0:
        continue
    if top == end:
        ans += 1

    now = top * 10 + end
    now_rev = end * 10 + top
    
    ans += digit_dict[now_rev] * 2
    digit_dict[now] += 1

print(ans)



Measured memory_bytes: 3064
import sys

def main():
  input = sys.stdin.readline
  road = [0 for _ in range(4)]
  for i in range(3):
    c1, c2 = map(int, input().split())
    road[c1-1] += 1
    road[c2-1] += 1

  if max(road) <= 2:
    print('YES')
  else:
    print('NO')


if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
#!/usr/bin/env python3
from math import gcd
# from numba import njit
from functools import reduce
# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left

# @njit
def solve(n,x,a):
    delta_a = (abs(a[i] - x) for i in range(n))
    return reduce(gcd,delta_a)



def main():
    # N = int(input())
    N,X = map(int,input().split())
    a = list(map(int,input().split()))
    print(solve(N,X,a))
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 20468
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

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

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi x(n),y(n);
    rep(i,n)cin>>x[i]>>y[i];
    map<pi,int> map;
    rep(i,n){
        rep(j,n){
            if(i==j)continue;
            map[{x[i]-x[j],y[i]-y[j]}]++;
        }
    }
    int s=0;
    for(pair<pi,int> e:map){
        s=max(s,e.se);
    }
    cout<<n-s<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a,b,c,d;
int ans;
int main(){
	cin>>a>>b>>c>>d;
	for(int i=0;i<=a;i++)
		for(int j=0;j<=b;j++)
			for(int k=0;k<=c;k++)
				if(i*500+j*100+k*50==d)ans++;
	cout<<ans;
	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define dbg(args...)    do { cerr << #args << ' ' ; print(args); } while(0); cerr << endl;
#define Max 100005
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PI acos(-1)
#define all(a) a.begin(), a.end()
long long limit = 4294967296;
int MOD = 1000000007;
template <typename T>
void print(const T& x)
{
    cerr<<x<<' ';
}

template <typename T1, typename... T2>
void print(const T1& first, const T2&... anst)
{
    print(first);
    print(anst ...) ;
}

/*direction array*/

/***4 moves***/
/*
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
*/
/***8 moves***/
/*
int dx[] = { 0,  0, -1, -1, -1, +1, +1, +1 } ;
int dy[] = {-1, +1, -1,  0, +1, -1,  0, +1 } ;
*/

/*direction array ends*/

ll gcd(ll a, ll b)
{
    return (b == 0 ? a : gcd(b, a % b));
}

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

int main()
{
    fastIO;
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    int d, t, s; cin>>d>>t>>s;
        ll x = t * s;

        if(x >= d)
            cout<<"Yes\n";
        else
            cout<<"No\n";

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include<cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<cmath>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	ll N,P;
	vector<ll> arr;
	cin>>N>>P;

	REP(i,N){
		ll a;
		cin>>a;
		arr.push_back(a);
	}

	ll i = 0;
	while(i < N){
		if(arr[i] % 2 == 1)break;
		i++;
	}

	if(i != N){
		printf("%lld",ll(pow(2,N-1)));
	}
	else{
		printf("%lld",(P == 1 ? 0 : ll(pow(2,N)) ));
	}

	return 0;
}


Measured memory_bytes: 256
from itertools import accumulate
n, q = map(int, input().split())
s = input()
*a, = accumulate([0,0]+[s[i-1:i+1]=="AC"for i in range(1,n)])
for i in range(q):
    l, r = map(int, input().split())
    print(a[r] - a[l])

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

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

	for (int i = 0; i < S.length(); i++) {
		int index = S[i] - 'A';
		index = (index + N) % 26;
		cout << (char)('A' + index);
	}
	cout << endl;


}






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

using namespace std;

int main(){
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<int64_t> A(x), B(y), C(z);
    for (auto &a: A) cin >> a;
    for (auto &b: B) cin >> b;
    for (auto &c: C) cin >> c;

    sort(A.begin(), A.end(), greater<int64_t>());
    sort(B.begin(), B.end(), greater<int64_t>());
    sort(C.begin(), C.end(), greater<int64_t>());

    vector<int64_t> D;

    for (const auto &a: A){
        for (const auto &b: B)
            D.push_back(a + b);
    }

    sort(D.begin(), D.end(), greater<int64_t>());
    vector<int64_t> E;

    for (int i = 0; i < min(k, x * y); i++){
        for (const auto &c: C)
            E.push_back(D[i] + c);
    }

    sort(E.begin(), E.end(), greater<int64_t>());

    for (int i = 0; i < k; i++)
        cout << E[i] << endl;
}

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

#define crap ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CY cout<<"Yes\n"
#define CN cout<<"No\n"
#define MOD 1000000007
using namespace std;
using ll = long long;
vector<ll> dp(100005,-1);
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// ll rec(vector<ll>v,int k,int l,ll ans,int i,int f1,int f2)
// {

//     if(l==k)
//         return ans;
//     if(f1==1)
//     {
//         if(i>=v.size())
//         return INT_MAX;
//     }

//     return min(rec(v,k,l+1,max(ans,v[i]),i+2),rec(v,k,l,ans,i+1));
// }
ll bs(vector<ll>v,ll n)
{
    ll c=0;
    bool s=1;
    while(s)
    {
        s=0;
        c++;
        for(int i=0;i<n-1;i++)
        {
            if(v[i]>v[i+1])
                {swap(v[i],v[i+1]);s=1;}
        }
    }
    return c;
}
void solve()
{
    ll n; cin>>n;
    vector<ll>v(n);
    rep(i,n) cin>>v[i];
    ll x=0;
    rep(i,n) x^=v[i];
    rep(i,n) cout<<(v[i]^x)<<" ";
}
int main() {
    crap;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r", stdin) ;
        freopen("output.txt","w", stdout) ;
        freopen("error.txt","w", stderr) ;
    #endif
    ll t;t=1;
// cin>>t;
    while(t--) solve();
}

Measured memory_bytes: 5544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}
void sorti(vi &a) {sort(a.begin(), a.end());}
void sortll(vll &a) {sort(a.begin(), a.end());}
void sortc(string &a) {sort(a.begin(), a.end());}
void sorts(vs &a) {sort(a.begin(), a.end());}

int main() {
  ll n;
  cin >> n;
  if (n < 357) {
    cout << 0 << endl;
    return 0;
  }
  string s = to_string(n);
  ll m = s.size();
  ll ans = 0;
  if (m >= 4) {
    for (ll i = 3; i < m; i++) {
      ans += pow(3, i);
      ans -= 3 * pow(2, i) - 3;
    }
  }
  string t;
  for (ll i = 0; i < m - 2; i++) t.push_back('3');
  t.push_back('5');
  t.push_back('7');
  while (t <= s) {
    ll a = 0, b = 0, c = 0;
    for (ll i = 0; i < m; i++) {
      if (t[i] == '3') a++;
      else if (t[i] == '5') b++;
      else if (t[i] == '7') c++;
    }
    if (a > 0 && b > 0 && c > 0) {
      ans++;
    }
    for (ll i = 0; i < m; i++) {
      if (t[m - 1 - i] == '3') {
        t[m - 1 - i] = '5';
        break;
      }
      else if (t[m - 1 - i] == '5') {
        t[m - 1 - i] = '7';
        break;
      }
      else if (t[m - 1 - i] == '7') t[m - 1 - i] = '3';
      if (i == m - 1) s[0] = '0';
    }
  }
  cout << ans << endl;
}

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

using namespace std;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define show(x) cerr << #x << x << endl

typedef long long ll;
typedef unsigned long long ull;

constexpr const int INT_INF=0x3f3f3f3f; // 1061109567
constexpr const ll LL_INF=0x3f3f3f3f3f3f3f3f; // 4557430888798830399

template <typename T> bool chmin(T &a, T b) {
    if (a > b) {a = b;return true;}return false;
}

template <typename T> bool chmax(T &a, T b) {
    if (a < b) {a = b;return true;}return false;
}

// INT
#define GCD(a, b) __gcd(a, b)
template <typename T> T LCM(T a, T b) {return a / GCD(a, b) * b;}
template <typename T> T EXTGCD(T a, T b, T& x, T& y) {
    T d = a;
    if (b != 0) {d=EXTGCD(b,a%b,y,x);y-=(a/b)*x;}
    else x=1,y=0;
    return d;
}
template <typename T> bool is_prime(T a) {
    for(int i=2;i*i<=a;i++)if(a%i==0)return 1;
    return 0;
}

// MOD
const ll MOD = 1000000000 + 7;
#define add(a, b) ((a % MOD) + (b % MOD)) % MOD
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define sub(a, b) ((a % MOD) + MOD - (b % MOD)) % MOD
template <typename T> T mod_inverse(T a, T mod, bool prime){ // if mod is prime, "prime" is true.
    if(prime){
        T tmp=mod-2,now=a,res=1;while(tmp){if(tmp&1)res=mul(res,now);now=mul(now,now);tmp>>=1;}
        return res;
    }else{T x,y;EXTGCD(a,mod,x,y);return (mod+x%mod)%mod;}
}
#define divide(a, b) ((a % MOD) * (mod_inverse(b, MOD, true))) % MOD

//
//
//  　　┓　　　┏
//  　＊┗┓　┏┛
//  　　　┫　┣　＊
//  　┏┳┻━┻┳┓
//  　┗┫　　　┣┛
//  ＊　┣　　━┃　＊        Merry Christmas!!
//  　┏┛　　〃┃
//  　┃●　　　┣━┳┓
//  　┗┻┳━━┛　┣┛
//  　＊　┃┏┓┣┓┃
//WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

int n, m, k;
string s;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    FILE *stream1;
    //FILE *stream2;
    stream1 = freopen("C:\\Users\\naruse\\CLionProjects\\competitive\\cmake-build-debug\\in.txt", "r", stdin);
    //stream2 = freopen("out.txt", "w", stdout);
    if (stream1 == nullptr) return 0;
    //if (stream2 == NULL) return 0;
#endif
    cin >> s;
    n = (int)s.size();
    ll cont = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'B') cont++;
        else {
            ans += cont;
        }
    }
    cout << ans << endl;
#ifdef  LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
    return 0;
}

Measured memory_bytes: 720
import sys
input = sys.stdin.readline

def solve():
    maxV = 12800

    H, W = map(int, input().split())
    Ass = [tuple(map(int, input().split())) for _ in range(H)]
    Bss = [tuple(map(int, input().split())) for _ in range(H)]

    dp = [[0]*(W) for _ in range(H)]
    diff = abs(Ass[0][0] - Bss[0][0])
    dp0 = 1<<maxV
    dp[0][0] = (dp0<<diff) | (dp0>>diff)
    for i in range(H):
        for j in range(W):
            diff = abs(Ass[i][j] - Bss[i][j])
            if i > 0:
                dp0 = dp[i-1][j]
                dp[i][j] |= (dp0<<diff) | (dp0>>diff)
            if j > 0:
                dp0 = dp[i][j-1]
                dp[i][j] |= (dp0<<diff) | (dp0>>diff)

    ans = maxV
    dpHW = dp[-1][-1]
    for i in range(2*maxV+1):
        if (dpHW>>i) & 1:
            j = abs(i-maxV)
            if j < ans:
                ans = j

    print(ans)


solve()


Measured memory_bytes: 26328
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int mod = 1e9 + 7;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

int P[200001];
ll kotae = 0;
int N;
int to[400001], ne[400001], he[200001];
int dfs(int v, int prev) {
	int kazu = 1;
	for (int u = he[v]; u; u = ne[u]) {
		if (to[u] != prev) {
			int k = dfs(to[u], v);
			kazu += k;
			kotae += P[k] - 1;
		}
	}
	kotae += P[N - kazu];
	return kazu;
}

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


	N = getint();
	int k = 1;
	rep(i, N - 1) {
		int a = getint(), b = getint();
		to[k] = b;
		ne[k] = he[a];
		he[a] = k++;
		to[k] = a;
		ne[k] = he[b];
		he[b] = k++;
	}
	P[0] = 1;
	rep1(i, N) P[i] = P[i - 1] * 2 % mod;

	dfs(1, 0);
	kotae %= mod;
	ll igai = ll(P[N - 1]) * N % mod;
	kotae = (igai - kotae + mod) % mod;
	kotae = kotae * modpow(P[N], mod - 2) % mod;

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 7936
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;

  ll ans = 0;
  for (ll i = 1; i <= n; ++i) {
    ll y = n/i;
    ans += y*(y+1)/2 * i;
  }
  cout << ans << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	ll n,c,k;cin>>n>>c>>k;
	vl t(n);
	rep(i,n){
		cin>>t[i];
	}
	sort(all(t));
	ll ans=0,cnt=1,m=0;
	for(int i=1;i<n;++i){
		ll d=t[i]-t[m];
		if(d<=k){
			cnt++;
		}
        else{
            ans++;
            m=i;
            cnt=1;
        }
        if(cnt==c){
            ans++;
            cnt=0;
			m=i+1;
        }
        
	}
    if(cnt!=0)ans++;
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
n,g[21][21],i;x,X;*c,t,T,f;D(S){for(memset(c=g,1,84),f=c[S]=0;T=S;)for(f|=1<<T,S=i=0;++i<=n;S=f&1<<i|c[i]>c[S]?S:i)t=c[T]+g[T][i],t<c[i]?c[i]=t:0;}main(y,Y){for(memset(g,scanf("%d%d",&n,&i),1764);~i;i--?g[g[x][X]=y,X][x]=Y:0)scanf("%d,%d,%d,%d",&x,&X,&y,&Y);D(x),y-=c[X],D(X);exit(!printf("%d\n",y-Y-c[x]));}

Measured memory_bytes: 0
'use strict'

function main(s) {

  const nums = s.split('\n')[0].split('');
  let ans = '';

  const dfs = (i, str) => {
    if (i === nums.length - 1) {
      str = str + nums[i];
      if (eval(str) === 7) {
        ans = (str + '=7');
      }
      return;
    } else {
      dfs(i + 1, str + nums[i] + '+');
      dfs(i + 1, str + nums[i] + '-');
    }
  }

  dfs(0, '');
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372