akhauriyash/Code-Regression huggingface dataset:
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;
use std::collections::HashSet;

fn main() {
    let n: usize = read();
    let d: HashSet<i32> = (0..n).map(|_| read()).collect();
    println!("{}", d.len());
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;

	struct max_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	constexpr max_t max;
	constexpr min_t min;

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min();

	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
}

void Main()
{
	int H, W, K;
	std::cin >> H >> W >> K;
	boost::multi_array<bool, 2> field(boost::extents[H][W]), flag(boost::extents[H][W]);
	boost::multi_array<std::optional<int>, 2> count(boost::extents[H][W]);
	int sx, sy, gx, gy;
	std::cin >> sx >> sy >> gx >> gy;
	--sx; --sy; --gx; --gy;
	for (auto i : boost::irange(H))
	{
		for (auto j : boost::irange(W))
		{
			char c;
			std::cin >> c;
			if (c == '@')
			{
				field[i][j] = true;
			}
		}
	}
	std::queue<std::tuple<int, int, int>> queue;
	auto push = [&](int c, int i, int j)
	{
		if (i < 0 || H <= i || j < 0 || W <= j || field[i][j] || count[i][j].value_or(H * W) < c)
		{
			return false;
		}
		count[i][j] = c;
		queue.emplace(c, i, j);
		return true;
	};
	push(0, sx, sy);
	while (queue.size())
	{
		auto [c, i, j] = queue.front();
		queue.pop();
		if (flag[i][j])
		{
			continue;
		}
		flag[i][j] = true;
		for (int p = 1; p <= K && push(c + 1, i + p, j); ++p);
		for (int p = 1; p <= K && push(c + 1, i - p, j); ++p);
		for (int p = 1; p <= K && push(c + 1, i, j + p); ++p);
		for (int p = 1; p <= K && push(c + 1, i, j - p); ++p);
	}
	std::cout << count[gx][gy].value_or(-1) << std::endl;
}

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

Measured memory_bytes: 14876
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE


void solve (void)
{
  
  int N; cin>>N;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>vec[i];
     vec[i]--;
  }
  int cnt = 0;
  for (int i = 0; i < N; i++)
  {
    if(vec[vec[i]] == i)cnt++;
  }
  cout<<cnt/2<<endl;
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

const int N = 100001;
char a[N] = {};
int n, m;

int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		cin >> a[i];
	char ch = '%';
	for (int i=1;i<=n;i++) {
		if (a[i] == a[i+1]) a[i] = '$';
	}
	int ans = 0;
	for (int i=1;i<=n;i++)
		if (a[i] != '$') ans ++;
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 384
import sys
def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    S = [[int(a) for a in input().split()] for _ in range(N)]
    C = [[int(c) for c in input().split()] for _ in range(M)]
    for a, b in S:
        minDist = 10 ** 20
        minPoint = 0
        for i in range(M):
            if abs(a - C[i][0]) + abs(b - C[i][1]) < minDist:
                minDist = abs(a - C[i][0]) + abs(b - C[i][1])
                minPoint = i + 1
        print(minPoint)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
# ####################################################################
# import io
# import sys

# _INPUT = """\
# 1001
# 1079
# 432

# 12 5 2
# cabbabaacaba

# 10 2 3
# abccabaabb
# """
# sys.stdin = io.StringIO(_INPUT)
####################################################################
import sys
def p(*_a):
  return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################
yn = lambda b: print('Yes') if b else print('No')
####################################################################
N = int(input())

NO = ":("

a = (N-1) // 1.08

for i in range(100):
  b = a + i
  if int(b * 1.08) == N:
    print( int(b) )
    exit()

print(NO)


Measured memory_bytes: 9176
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]
ans = 0
for i in range(N):
  temp = 0
  for j in range(i + 1):
    temp += A[0][j]
  for j in range(i, N):
    temp += A[1][j]
  ans = max(ans, temp)
print(ans)

Measured memory_bytes: 3060
// in the name of Allah

#include <bits/stdc++.h>

#define endl '\n'
#define mod 1000000007
#define sz(x) ((int) (x.size()))

using namespace std;

long long x[123456];

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k, p = -1, cnt = 0;
	cin >> n >> k;
	for(int i=0; i<n; i++) {
		cin >> x[i];
		if(p == -1 && x[i] > 0) p = i;
	}
	long long t = 1e18;
	for(int i=0; i<n; i++) {
		if(n-i >= k) {
			if(x[i] >= 0 && x[i+k-1] >= 0) t = min(t, x[i+k-1]);
			else if(x[i] <= 0 && x[i+k-1] <= 0) t = min(t, abs(x[i]));
			else t = min(t, min(abs(x[i]), x[i+k-1]) + x[i+k-1] - x[i]);
		}
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
using namespace std;
#define loop(i,n) for(int i = 0; i < (n); i++)
#define loops(i,f,n) for(int i = (f); i < (n); i++)
#define VEC vector<int>
typedef pair<int, int>pii;
typedef pair<int, bool>pib;
// vector<VEC> v (n, VEC(n))
//loop(i,n)loop(j,n)dp[i][j]=-1;
//printf("%d\n", n);
int main()
{
	cin.tie(0);
	cin.sync_with_stdio(0);
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	cout << string(ty - sy, 'U') << string(tx - sx, 'R');
	cout << string(ty - sy, 'D') << string(tx - sx, 'L');
	cout << 'L';
	cout << string(ty - sy+1, 'U') << string(tx - sx+1, 'R');
	cout << 'D' << 'R';
	cout << string(ty - sy+1, 'D') << string(tx - sx+1, 'L');
	cout << 'U';
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    int a; string s;
    cin>>a>>s;
    cout<<(a>=3200?s:"red")<<endl;


    // cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int n, t, a, i;
	scanf("%d%d%d", &n, &t, &a);
	int dif=0, ans=0, min=a;
	for(i=1; i<n; i++){
		scanf("%d", &a);
		if(a<min){
			min=a;
		}else if(a==min+dif){
			ans++;
		}else if(a>min+dif){
			dif=a-min;
			ans=1;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

ll mypow(ll a, ll b) {
    if(b==0) return 1;
    ll ans = a;
    REP(i, b-1) ans *= a;
    return ans;
}

int main(void)
{
    string s;
    cin >> s;
    ll ans = 0;
    REP(i, mypow(2,s.size()-1)){
        int start = 0;
        REP(j, s.size()-1){
            if(i&(1<<j)){
                for (int k = j; k >= start; k--) {
                    ans+=(s[k]-'0') * mypow(10, j-k);
                }
                start = j+1;
            }
        }
        for (int k = s.size()-1; k >= start; k--) {
            ans+=(s[k]-'0') * mypow(10, (s.size()-1)-k);
        }
    }
    pr(ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	998244353//1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

int func(int a, int b)
{
	if (a < b)
		return func(b, a);
	int r;
	while (r = a % b)
	{
		a = b;
		b = r;
	}
	return b;
}

int main()
{
	int n;
	cin >> n;
	vector<int> s(n), r(n), g(n), b(n);
	int nr = 0, ng = 0, nb = 0;

	for (int i = 0; i < n; i++)
	{
		char c;
		cin >> c;
		if (c == 'R')
			s[i] = 1, r[nr++] = i;
		else if (c == 'G')
			s[i] = 2, g[ng++] = i;
		else
			s[i] = 4, b[nb++] = i;
	}

	ll re = 0;

	for (int i = 0; i < n - 2; i++)
		for (int j = i + 1; j < n - 1; j++)
			if (s[i] == s[j])
				continue;
			//	j以上の数から探索
			else
			{
				int k;
				int target = 2 * j - i;
				bool had = false;
				if (s[i] + s[j] == 3)
				{
					//	b
					k = lower_bound(b.begin(), b.begin() + nb, j + 1) - b.begin();
					re += (nb - k);
					if (binary_search(b.begin() + k, b.begin() + nb, target))
						re--;
				}
				else if (s[i] + s[j] == 5)
				{
					//	g
					k = lower_bound(g.begin(), g.begin() + ng, j + 1) - g.begin();
					re += (ng - k);
					if (binary_search(g.begin() + k, g.begin() + ng, target))
						re--;
				}
				else
				{
					//	r
					k = lower_bound(r.begin(), r.begin() + nr, j + 1) - r.begin();
					re += (nr - k);
					if (binary_search(r.begin() + k, r.begin() + nr, target))
						re--;
				}
			}
			

				
	printf("%lld", re);

	return 0;
}

Measured memory_bytes: 3320
n,m= map(int,input().split(' '))
arr=[0 for i in range(n)]

im= False
for i in range(m):
	x,y= map(int,input().split(' '))
	if x==1 and y==0 and n>1:
		im=True
	if arr[x-1]!=0 and arr[x-1]!=y:
		im=True
	arr[x-1]=y
if arr[0]==0 and n>1:
	arr[0]=1
if im:
	print(-1)
else:
	print(''.join(str(i) for i in arr))

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if((A + B) % 3 == 0 || A % 3 == 0 || B % 3 == 0) {
			System.out.println("Possible");
		} else {
			System.out.println("Impossible");
		}
	}
}


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

using namespace std;

using ll = long long;

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

    constexpr int n = 5;
    vector<pair<int, int>> order(n);
    for (int i = 0; i < n; ++i) {
        cin >> order[i].second;
        order[i].first = (order[i].second - 1) % 10;
    }
    sort(order.begin(), order.end());

    int take_time = order[0].second;
    for (int i = 1; i < n; ++i) {
        int add_time = (10 - (order[i].second % 10)) % 10;
        take_time += order[i].second + add_time;
    }

    cout << take_time << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	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; }
	template<class Type>struct is_vector : std::false_type {};
	template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
	template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
		if (v.empty())return out;
		constexpr bool is_vector_v = is_vector<T>::value;
		if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
		else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
		return out;
	}
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
	inline void putn() {}
	template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

	void solve() {
		IOS;
		int n,m;
		cin >> n >> m;
		vector<int> v(n), w(n);
		REP(i, n) {
			cin >> v[i] >> w[i];
		}
		vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
		REP(i, n) {
			REP(j, m+1) {
				dp[i + 1][j] = dp[i][j];
				if (j - w[i] >= 0) {
					chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
				}
			}
		}
		put(dp[n][m]);
	}
} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}



Measured memory_bytes: 6816
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

vector<int> c;
ll inf = (ll)(1e13);
int t[500010];

int main() {
	int n, m;
	cin >> n >> m;
	c.resize(m);

	for (int i = 0; i <= n; i++) 
		t[i] = inf;
	t[0] = 0;

	for (int i = 0; i < m; i++) 
		cin >> c[i];

	for (int i = 0; i < m ; i++)
		for (int j = c[i]; j <= n; j++)
			t[j] = min(t[j], t[j - c[i]] + 1);

	cout << t[n] << endl;
	return 0;
}

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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define outl(x) cout<< (x) << '\n'
#define pb(a) push_back(a)
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
  return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
  return a / gcd(a, b) * b;
}

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

int n, m;
int y[100001], p[100001];

vi v[100001];
map<int, int> mp;

int main()
{
  ci>> n >> m;
  for(int i = 0; i < m; i++) {
    ci>> p[i] >> y[i];
    v[p[i]].pb(y[i]);
  }

  bool endSort[100001] = {};
  
  for(int i = 0; i < m; i++) {
    if(!endSort[p[i]]) sort(v[p[i]].begin(), v[p[i]].end());
    endSort[p[i]] = true;

    printf("%06d%06d\n", p[i], lower_bound(v[p[i]].begin(), v[p[i]].end(), y[i]) - v[p[i]].begin() + 1);
  }
  
  return 0;
}


Measured memory_bytes: 7808
import java.util.*

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }

    val graph = Graph1(n)
    repeat(m) {
        val (x, y) = readLine()!!.split(' ').map { it.toInt() }
        graph.add(x - 1, y - 1)
    }

    println(graph.solve())
}

class Graph1 constructor(private val n: Int) {
    private val graph = Array(n) { mutableListOf<Int>() }
    private val dp = IntArray(100000) { -1 }

    fun add(x: Int, y: Int) {
        graph[x].add(y)
    }

    private fun rec(v: Int): Int {
        if (dp[v] != -1) return dp[v]

        var res = 0
        graph[v].forEach {
            res = Math.max(res, rec(it) + 1)
        }
        dp[v] = res
        return res
    }

    fun solve(): Int {
        var res = 0
        (0 until n).forEach {
            res = Math.max(res, rec(it))
        }
        return res
    }

}

class Graph2 constructor(private val n: Int) {
    private val graph = Array(n) { mutableListOf<Int>() }
    private val deg = IntArray(n) { 0 }
    private val dp = IntArray(100000) { -1 }

    fun add(x: Int, y: Int) {
        graph[x].add(y)
        deg[y]++
    }

    fun solve(): Int {

        val queue: Queue<Int> = ArrayDeque<Int>()
        deg.forEach {
            if (it == 0) {
                queue.add(it)
            }
        }

        while (queue.isNotEmpty()) {
            val v = queue.remove()
            graph[v].forEach {
                deg[it]--
                if (deg[it] == 0) {
                    queue.add(it)
                    dp[it] = Math.max(dp[it], dp[v] + 1)
                }
            }
        }

        var res = 0
        (0 until n).forEach {
            res = Math.max(res, dp[it])
        }
        return res
    }

}

Measured memory_bytes: 69664
#include<iostream>
#include<cstdio>
using namespace std;
bool check=0;
int n;
int main()
{
  scanf("%d",&n);
  for(int i=1;i<=9;i++)
  {
    for(int j=1;j<=9;j++)
    {
      if(i*j==n){
        check=1;
      }
    }
  }
  if(check==1)cout<<"Yes";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] ar = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = in.nextInt();
            boolean fl = true;
            int max = -1;
            for (int i = 0; i < n - 1; i++) {
                if (ar[i] <= ar[i + 1])
                    continue;
                if (ar[i] - 1 == ar[i + 1]) {
                    ar[i]--;
                    if (ar[i] < max) {
                        fl = false;
                        break;
                    }
                } else {
                    fl = false;
                    break;
                }
                max = Math.max(max, ar[i]);
            }
            if (fl)
                out.println("Yes");
            else
                out.println("No");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 40008
#include<bits/stdc++.h>
using namespace std;
int a[20][20],b[20],ma=0;
void sou(int n)
{
	bool y=true;
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		if(b[i]==1)
		{
			sum++;
			for(int j=1;j<=n;j++)
			{
				if(a[i][j]!=-1&&a[i][j]!=b[j])
				{
					y=false;break;
				}
			}
		}
		if(y==false)
		break;
	}
	if(y)
	{
		if(ma<sum)
		ma=sum;
	}
}
void er(int n)
{
	for(int i=0;i<(1<<n);i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				b[j+1]=1;
			}
		}
		sou(n);
		memset(b,0,sizeof(b));
	} 
}
int main()
{
	memset(a,-1,sizeof(a));
	int n,p=1;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int m;
		cin>>m;
		while(m--)
		{
			int h1,h2;
			cin>>h1>>h2;
			a[p][h1]=h2;
		}
		p++;
	}
	er(n);
	cout<<ma;
}

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

int main() {
  string hoge;
  int ans;
  cin >> hoge;
  if (hoge[0] == '1') ans++;
  if (hoge[1] == '1') ans++;
  if (hoge[2] == '1') ans++;
  
  cout << ans << endl;
}

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

void solve()
{
    int n;
    cin>>n;
    int ar[n+1]={0};
    int c=0;
    for(int i=1;i<=n;i++)
    {
        cin>>ar[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(i%2)
        {
            if(ar[i]%2)
                c++;
        }
    }
    cout<<c<<endl;
}
int main()
{
        solve();
}

Measured memory_bytes: 3560
////=====BIsmillahir Rahmanir Rahim =====////

/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
         Comilla University

*/
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
#define fi 2*acos(0.0)
#define ee 2.71828
#define ll  long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define edl printf("\n")
#define infinity 1e16
#define mod 1000000007
#define cn continue
#define csprint1 printf("Case %lld: ", cs++)
#define csprint2 printf("Case %lld:\n", cs++)
#define sf(a) scanf("%lld", &a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define all(v) v.begin(),v.end()
#define pfn(a) printf("%lld\n",a)
#define pfs(a) printf("%lld ",a)

// using namespace __gnu_pbds;
using namespace std;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<pl> vpi;
typedef vector<pl> vpl;
// typedef tree<pair<ll, int> , null_type, less<pair<ll, int> >, rb_tree_tag, tree_order_statistics_node_update> ost;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a <<","<< spc;
    err(++it, args...);
    cout<<edl;
}
///Bit manipulation

bool checkbit(int mask,int bit){return mask & (1<<bit);}
int setbit(int mask,int bit){ return mask | (1<<bit) ; }
int clearbit(int mask,int bit){return mask & ~(1<<bit);}
int togglebit(int mask,int bit){return mask ^ (1<<bit);}
int bitno(int mask) {return (int)__builtin_popcount(mask);}

/*----------------------Graph Moves----------------*/
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

///=====================================///
const long long maX=1e6+5;
ll divisor[maX];
int main(){
        ll n;
        sf(n);
        ll cc=0;
        for(ll i=1;i<n;i++){
            for(ll j=i;i*j<n;j++){
                if(i!=j)divisor[i*j]++;
                divisor[i*j]++;
            }
        }
        for(ll i=1;i<n;i+=1){
            cc+=divisor[i];
        }
        pfn(cc);
return 0;
}

Measured memory_bytes: 11532
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

	int q;
	cin >> q;

	for (int i = 0; i < q; i++)
	{
		string m;
		int a, b;
		string r;

		cin >> m >> a >> b;

		if (m == "replace")
		{
			cin >> r;
			s.replace(a, r.length(), r);
		}
		else if (m == "reverse")
		{
			string t = s.substr(a, b - a + 1);
			reverse(t.begin(), t.end());
			s.replace(a, t.length(), t);
		}
		else if (m == "print")
		{
			cout << s.substr(a, b - a + 1) << endl;
		}
	}
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    int N;cin>>N;
    vector<int>V(N+2);
    V[0]=0;V[N+1]=0;
    for(int i=1;i<N+1;i++)cin>>V[i];
    vector<int>V1(N+2);int sum1=0; 
    vector<int>V2(N+2);int sum2=0;
    V1[0]=0;V2[N+1]=0;
    for(int i=1;i<N+2;i++){
        sum1+=abs(V[i]-V[i-1]);V1[i]=sum1;
        sum2+=abs(V[N+2-i]-V[N+1-i]);V2[N+1-i]=sum2;
    }
    for(int i=0;i<N;i++){
        cout<<V1[i]+V2[i+2]+abs(V[i+2]-V[i])<<endl;
    }
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    cout << n << ":";
    for(int i = 2; i * i <= n; i++) {
            while(n % i == 0) {
                cout << ' ' << i;
                n /= i;
            }
    }
    if(n > 1) {
        cout << ' ' << n;
    }
    cout << '\n';
}


Measured memory_bytes: 3212
mod = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append(fact[-1] * i % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)

def combi_mod(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p


H, W, A, B = map(int, input().split())

if B < W / 2:
    not_ans = 0
    total = combi_mod((H - 1) + (W - 1), H-1, mod)
    for i in range(B):
        sq1h = H - A
        sq1w = i + 1
        sq2h = A
        sq2w = W - i
        n = combi_mod((sq1h -1) + (sq1w - 1), (sq1h -1), mod) * combi_mod((sq2h - 1) + (sq2w - 1), (sq2h - 1), mod) % mod
        not_ans = (not_ans + n) % mod
    ans = (total - not_ans) % mod
    print(ans)
        
else:
    ans = 0
    for i in range(B, W):
        sq1h = H - A
        sq1w = i + 1
        sq2h = A
        sq2w = W - i
        n = combi_mod((sq1h - 1) + (sq1w - 1), (sq1h - 1), mod) * combi_mod((sq2h - 1) + (sq2w - 1), (sq2h - 1), mod)
        ans = (ans + n) % mod
    ans %= mod
    print(ans)


Measured memory_bytes: 122240
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <map>
#include <string>
#include <queue>
using namespace std;

struct node {
    string nums;
    int pos, steps;
};

map<string, int> ans;

void bfs() {
    queue<node> q;
    q.push({ "01234567", 0, 0 });
    while (!q.empty()) {
        node cnt = q.front(); q.pop();
        if (ans.find(cnt.nums) != ans.end()) continue;
        ans[cnt.nums] = cnt.steps;
        int pos = cnt.pos;
        if (pos - 1 >= 0 && pos != 4) {
            swap(cnt.nums[pos], cnt.nums[pos - 1]);
            q.push({ cnt.nums, pos - 1, cnt.steps + 1 });
            swap(cnt.nums[pos], cnt.nums[pos - 1]);
        }
        if (pos + 1 <= 7 && pos != 3) {
            swap(cnt.nums[pos], cnt.nums[pos + 1]);
            q.push({ cnt.nums, pos + 1, cnt.steps + 1 });
            swap(cnt.nums[pos], cnt.nums[pos + 1]);
        }
        if (pos - 4 >= 0) {
            swap(cnt.nums[pos], cnt.nums[pos - 4]);
            q.push({ cnt.nums, pos - 4, cnt.steps + 1 });
            swap(cnt.nums[pos], cnt.nums[pos - 4]);
        }
        if (pos + 4 <= 7) {
            swap(cnt.nums[pos], cnt.nums[pos + 4]);
            q.push({ cnt.nums, pos + 4, cnt.steps + 1 });
            swap(cnt.nums[pos], cnt.nums[pos + 4]);
        }
    }
}

int main() {
    bfs();
    string line;
	while (getline(cin, line)) {
		line.erase(remove(line.begin(), line.end(), ' '), line.end());
		cout << ans[line] << endl;
	}
    return 0;
}



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

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

const ll MAX_N = 2e5 + 10, MOD = 1e9 + 7;
ll n, ans, TWO;
ll sz[MAX_N];
vector <int> adj[MAX_N];

int _sum(int a, int b) {
    int c = a + b;
    if (MOD <= c)
        c -= MOD;

    return c;
}

int _sub(int a, int b) {
    int c = a - b;
    if (c < 0)
        c += MOD;

    return c;
}

int _mul(int a, int b) {
    int c = 1LL * a * b % MOD;
    return c;
}

int _pow(int a, int b) {
    if (!b)
        return 1;

    int res = _pow(a, b >> 1);
    res = _mul(res, res);

    if (b & 1)
        res = _mul(res, a);

    return res;
}

int dfs(int v, int p = 0) {
    sz[v] = 1;
    for (int u: adj[v])
        if (u != p)
            sz[v] += dfs(u, v);

    return sz[v];
}

void calc(int v, int p = 0) {
    int res1 = _pow(TWO, n - 1);
    int res2 = _mul(_sub(1, _pow(TWO, n - sz[v])), _pow(TWO, sz[v] - 1));
    for (int u: adj[v])
        if (u != p) {
            calc(u, v);
            res2 = _sum(res2, _mul(_sub(1, _pow(TWO, sz[u])), _pow(TWO, n - sz[u] - 1)));
        }

    ans = _sum(ans, _mul(TWO, _sub(1, _sum(res1, res2))));
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int v, u;
        cin >> v >> u;
        v--, u--;

        adj[v].push_back(u);
        adj[u].push_back(v);
    }

    dfs(0);
    TWO = _pow(2, MOD - 2);
    calc(0);

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

Measured memory_bytes: 26112
def main():
    H, W = map(int,input().split())
    visited = [[False]*W for _ in range(H)]
    q = []
    for y in range(H):
        S = input()
        for x, s in enumerate(S):
            if s == "#":
                q.append((y, x))
                visited[y][x] = True

    ans = -1
    while q:
        ans += 1
        nq = []
        for y, x in q:
            if 0 < x and not visited[y][x-1]:
                visited[y][x-1] = True
                nq.append((y,x-1))
            if x < W-1 and not visited[y][x+1]:
                visited[y][x+1] = True
                nq.append((y,x+1))
            if 0 < y and not visited[y-1][x]:
                visited[y-1][x] = True
                nq.append((y-1, x))
            if y < H-1 and not visited[y+1][x]:
                visited[y+1][x] = True
                nq.append((y+1,x))
        if nq:
            q = nq
        else:
            break

    print(ans)

if __name__ == '__main__':
    main()

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

namespace ConsoleApp7
{
	class Program
	{
		static void Main(string[] args)
		{
				string[] a = Console.ReadLine().Split(' ');
				string[] z = Console.ReadLine().Split(' ');

				var t = a[0];
				var f = a[1];
				var r = a[2];
				var l = a[3];
				var b = a[4];
				var bo = a[5];

				var bt = z[0];
				var bf = z[1];
				var br = z[2];
				var bl = z[3];
				var bb = z[4];
				var bbo = z[5];

				if (t == bt && bo == bbo)
				{
					if (f == bf && r == br && l == bl && b == bb
						|| f == br && r == bb && b == bl && l == bf
						|| f == bb && r == bl && l == br && b == bf
						|| f == bl && r == bf && l == bb && b == br)
					{
						Console.WriteLine("Yes");
					}
					else
						Console.WriteLine("No");
				}
				else if (f == bt && b == bbo)
				{
					if (t == bf && r == bl && l == br && bo == bb
						|| t == bl && r == bb && l == bf && bo == br
						|| t == br && r == bf && l == bb && bo == bl
						|| t == bb && r == br && l == bl && bo == bf)
					{
						Console.WriteLine("Yes");
					}
					else
						Console.WriteLine("No");
				}
				else if (r == bt && l == bbo)
				{
					if (t == bf && f == br && b == bl && bo == bb
						|| t == bl && f == bf && b == bb && bo == br
						|| t == bb && f == bl && b == br && bo == bf
						|| t == br && f == bb && b == bf && bo == bl)
					{
						Console.WriteLine("Yes");
					}
					else
						Console.WriteLine("No");
				}
				else if (l == bt && r == bbo)
				{
					if (t == bf && f == bl && b == br && bo == bb
						|| t == bl && f == bb && b == bf && bo == br
						|| t == bb && f == br && b == bl && bo == bf
						|| t == br && f == bf && b == bb && bo == bl)
					{
						Console.WriteLine("Yes");
					}
					else
						Console.WriteLine("No");
				}
				else if (b == bt && f == bbo)
				{
					if (t == bf && r == br && l == bl && bo == bb
						|| t == bl && r == bf && l == bb && bo == br
						|| t == bb && r == bl && l == br && bo == bf
						|| t == br && r == bb && l == bf && bo == bl)
					{
						Console.WriteLine("Yes");
					}
					else
						Console.WriteLine("No");
				}
				else if (bo == bt && t == bbo)
				{
					if (f == bf && r == bl && l == br && b == bb
						|| f == bl && r == bb && l == bf && b == br
						|| f == bb && r == br && l == bl && b == bf
						|| f == br && r == bf && l == bb && b == bl)
					{
						Console.WriteLine("Yes");
					}
					else
						Console.WriteLine("No");
				}

				else
				{
					Console.WriteLine("No");
				}
		}
	}
}



Measured memory_bytes: 15908
#include<bits/stdc++.h>
#define pb push_back
#define int long long
//#define M 1000000007
#define M 998244353
using namespace std;
const int inf=4e18;
const double pi=3.14159265358979;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int r;cin>>r;
	cout<<r*r<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

//ミョ(-ω- ?)
int main() {
    ll a,b;
    cin >> a >> b;
    auto p = prime_factorize(gcd(a,b));
    cout << p.size()+1 << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using LP = pair<int, int>;
using ll = long long;

#define for0(i, n) for (int i = 0; i < (n); ++i)
#define for1(i, n) for (int i = 1; i <= (n); ++i)
#define sz(x) int(x.size())


int main(){
  int N, K;
  cin >> N >> K;
  vector<ll> H(N);
  for0(i, N) cin >> H[i];

  vector<ll> COST(N, 1e9+7); 
  COST[0] = 0;
  for0(here, N){
    for1(diff, K){
      if(here+diff>N-1) break;

      COST[here+diff] = min(COST[here+diff], COST[here] + abs(H[here] - H[here+diff]));
    }
  }

  cout << COST[N-1] << endl;

  return 0;
}


Measured memory_bytes: 1792
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
ret = -1
for i in range(10**n+1):
    x = str(i)
    if len(x)!=n:
        continue
    flg = True
    for s,c in sc:
        if x[s-1]!=str(c):
            flg = False
    if flg:
        ret = x
        break
print(ret)

Measured memory_bytes: 39152
package main

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

func main() {
	scanInit()

	s := nextStr()

	sum := 0
	nowblack := 0
	for i := 0; i < len(s); i++ {
		if s[i] == 'B' {
			nowblack++
		} else {
			sum += nowblack
		}
	}

	fmt.Println(sum)
}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2176
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int n; cin >> n;
	string S, T; cin >> S >> T;
	rep (i, n) {
		cout << S[i];
		cout << T[i];
	}
	cout << endl;
	return;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll M;
  cin>>M;
  ll ans = 0;
  ll sum = 0;
  ll d, c;
  for(ll i=0;i<M;++i) {
    cin>>d>>c;
    ans += c;
    sum += d*c;
  }
  ans--;
  if(sum%9==0) cout<<ans+sum/9-1<<endl;
  else cout<<ans+sum/9<<endl;
}



Measured memory_bytes: 3564
def main():
    N,K = map(int, input().split())
    h = list(map(int, input().split()))
    # 初期化
    # 初期条件
    # ループ
    # テーブルから解を得る
    INF = float('inf')
    dp = [INF] * N
    dp[0] = 0
    for i in range(N-1):
        for j in range(1, min(K+1, N-i)):
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
    print(dp[-1])

main()


Measured memory_bytes: 55136
package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var s string

	fmt.Scan(&s)

	count0 := strings.Count(s, "0")
	count1 := strings.Count(s, "1")
	fmt.Println(2 * int(math.Min(float64(count0), float64(count1))))
}


Measured memory_bytes: 1280
#include<iostream>
#include<cstring>
#define ll long long
using namespace std;
const int maxn = 2e3+5;
const int M = maxn*3;
ll f[M][M<<1],inv[M];
ll n,m;
ll quick_pow(ll a,ll b)
{
    ll s = 1;
    while(b)
    {
        if(b&1) s = (s*a)%m;
        a = (a*a)%m;
        b>>=1;
    }
    return s%m;
}
int main()
{
    cin>>n>>m;
    n *= 3;
    ll t = 1;
    for(int i=1;i<=n;i++)
    {
        inv[i] = quick_pow(i,m-2);
        t = (t*i)%m;
        //cout<<inv[i]<<endl;
    }
    f[0][M] = 1;
    for(int i=1;i<=n;i++)
    {
        for(int j=-i;j<=i;j++)
        {
            f[i][j+M] = (f[i][j+M] + f[i-1][j-1+M]*inv[i])%m;
            if(i>=2) f[i][j+M] = (f[i][j+M] + f[i-2][j+1+M]*inv[i])%m;
            if(i>=3) f[i][j+M] = (f[i][j+M] + f[i-3][j+M]*inv[i])%m;
            //cout<<i<<" "<<j<<" "<<f[i][j+M]<<endl;
        }
    }
    ll ans = 0;
    for(int i=0;i<=n;i++) ans = (ans+f[n][i+M])%m;
    cout<<(ans*t)%m<<endl;
    return 0;
}


Measured memory_bytes: 563584
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N; cin>>N;
  vector<long long>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  long long a=0;
  for(int i=1;i<N;i++){
    if(A[i]==A[i-1]){
      if(a==0)a=A[i];
      else{
        cout<<a*A[i]<<endl;
        return 0;
      }
      A[i]=0;
    }
  }
  cout<<0<<endl;
}

Measured memory_bytes: 3980
#include <iostream>
#include <cassert>
#include <cstring>
#include <vector>

using namespace std;

vector<vector<short>> a;
vector<vector<long long int>> dp;

const long long int p = 1e9 + 7;
int n;

long long int find(int i, long long int mask){
    if(dp[i][mask]!=-1) return dp[i][mask];

    if(i==0){
        long long int temp=0;
        for(int j=0 ; j<n ; j++){
            if(a[i][j])
                if(mask & (1<<j))
                    temp = 1;
        }
        dp[i][mask] = temp;
        return dp[i][mask];
    }

    long long int temp = 0;
    for(int j=0 ; j<n ; j++){
        if(a[i][j]==1){
            if(mask&(1<<j)){
                temp += find(i-1,mask^(1<<j));
                if(temp>p) temp-=p;
            }
        }
    }
    dp[i][mask] = temp;
    return dp[i][mask];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while(t--){
        cin >> n;
        a = vector<vector<short>> (n,vector<short>(n));
        for(int i=0 ; i<n ; i++){
            for(int j=0 ; j<n ; j++){
                cin >> a[i][j];
            }
        }
        dp = vector<vector<long long int>> (n,vector<long long int>((1<<n),-1));

        cout << find(n-1,(1<<n)-1) << "\n";
    }
    return 0;
}



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

using namespace std;

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

	int n;
	cin >> n;

	map<string, int> mp;
	for(int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		mp[s] += 1;
	}

	cout << "AC" << ' ' << "x" << ' ' << mp["AC"] << '\n';
	cout << "WA" << ' ' << "x" << ' ' << mp["WA"] << '\n';
	cout << "TLE" << ' ' << "x" << ' ' << mp["TLE"] << '\n';
	cout << "RE" << ' ' << "x" << ' ' << mp["RE"] << '\n';

	return 0;
}


Measured memory_bytes: 3664