akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

import bisect
from collections import defaultdict

AZ = "abcdefghijklmnopqrstuvwxyz"
def DD(arg): return defaultdict(arg)

N = int(input())
words = [w[::-1] for w in list(input().strip() for _ in range(N))]
words.sort()
Lsortwords = sorted([(i,words[i]) for i in range(N)],key = lambda x:-len(x[1]))

class SegmentTree:
  def __init__(self, n, op, e):
    self.n = n
    self.op = op
    self.e = e
    self.size = 2 ** ((n - 1).bit_length())
    self.node = [self.e] * (2 * self.size)
 
  def build(self, array):
    for i in range(self.n):
      self.node[self.size + i] = array[i]
    for i in range(self.size - 1, 0, -1):
      self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
 
  def update(self, i, val):
    i += self.size
    self.node[i] += val
    while i > 1:
      i >>= 1
      self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
 
  def get(self, l, r):
    l, r = l + self.size, r + self.size
    res_l, res_r = self.e, self.e
    while l < r:
      if l & 1:
        res_l = self.op(res_l, self.node[l])
        l += 1
      if r & 1:
        r -= 1
        res_r = self.op(self.node[r], res_r) 
      l, r = l >> 1, r >> 1
    return self.op(res_l, res_r)
  
ST = {l:SegmentTree(N,lambda a,b:a+b,0) for l in AZ}
check = [DD(int) for i in range(N)]
ans = 0
shori = 0
for i in range(len(Lsortwords[0][1]))[::-1]:
  for j,w in Lsortwords:
    if len(w) <= i: break
    if not check[j][w[i]]:
      ST[w[i]].update(j,1)
      check[j][w[i]] = 1
  while shori < N and len(Lsortwords[shori][1]) == i+1:
    w = Lsortwords[shori][1]
    p = w[:-1]
    q = w[-1]
    l = bisect.bisect_left(words,p)
    r = bisect.bisect(words,p+chr(97 + 26))
    ans += ST[q].get(l,r)-1
    shori += 1
    if shori == N: break
      
print(ans)

Measured memory_bytes: 342624
(function(input) {
    var p = input.replace(/\n$/, '').split('');
    var stack = [];
    var areaStack = [];
    //console.log(p);
    var sum = 0;
    for (var i = 0; i < p.length; i++) {
        var str = p[i];
        switch (str) {
            case '\\':
                stack.push(i);
                break;
            case '/':
                if (!stack.length) {
                    continue;
                }
                var begin = stack.pop()
                var sumArea = i - begin;
                sum += sumArea;
                while (true) {
                    if (!areaStack.length) {
                        break;
                    }
                    var a = areaStack.pop();
                    if (a.i >= begin) {
                        sumArea += a.area;
                    } else {
                        areaStack.push(a);
                        break;
                    }
                }
                areaStack.push({
                    i: begin,
                    area: sumArea
                });
        }
   //     console.log(stack);
    }
    //console.log(areaStack);
    console.log(sum);
    var msg = areaStack.length;
    var areaJoin = areaStack.map(function(e) { return e.area; }).join(' ');
    if (areaJoin) {
        msg += ' ' + areaJoin;
    }
    console.log(msg);
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9788
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		char[] array = new char[K];
		int last = 0;
		for(int i = 0; i < K; i++){
			array[i] = sc.next().charAt(0);
			//System.out.println(array[i]);
		}
		boolean flag = true;
		while(flag){
			flag = false;
			//System.out.println("for" + N);
			String str = "" + N;
			char[] arrayStr = new char[str.length()];
			for(int i = 0; i < str.length();i++){
				arrayStr[i] = str.charAt(i);
				//System.out.println(arrayStr[i]);
			}
			loop:
			for(int i = 0; i < arrayStr.length; i++){
				//int hikaku = Integer.parseInt(arrayStr[i]);
				//int hikaku = arrayStr[i];
				for(int j = 0;j < array.length;j++){
					if(arrayStr[i] == array[j]){
						flag = true;
						N++;
						break loop;
					}
				}
			}
		}
		System.out.println(N);
	}
}

Measured memory_bytes: 34516
import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))

    L = sorted(L)
    
    ans = 0
    #for i in range(N-1):
    #    for j in range((i+1), N):    
    #        c = bisect.bisect_left(L, L[i] + L[j], j+1)
    #        print(c)
    #        ans += c - j - 1

    for i in range(N):
        for j in range(i+1, N):
            m = bisect.bisect_right(L, L[j]-L[i])
            ans += max(i-m, 0)

    print(ans)

if __name__ == '__main__':
    main()



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

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];


ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

template <typename T> bool next_combination(const T first, const T last, int k) {
    const T subset = first + k;
    // empty container | k = 0 | k == n 
    if (first == last || first == subset || last == subset) {
        return false;
    }
    T src = subset;
    while (first != src) {
        src--;
        if (*src < *(last - 1)) {
            T dest = subset;
            while (*src >= *dest) {
                dest++;
            }
            iter_swap(src, dest);
            rotate(src + 1, dest + 1, last);
            rotate(subset, subset + (last - dest) - 1, last);
            return true;
        }
    }
    // restore
    rotate(first, subset, last);
    return false;
}

int main() {
    ll N, K;
    cin >> N >> K;

    vector<ll> h(N);
    for(ll i = 0; i < N; i++) cin >> h[i];

    vector<ll> dp(N);
    dp[0] = 0;

    for(ll i = 1; i < N; i++) {
        ll temp = 999999999;
        for(ll j = 1; j <= min(K, i); j++) temp = min(temp, abs(h[i-j]-h[i])+dp[i-j]);
        dp[i] = temp;
    }
    // for(ll i = 0; i < N-1; i++) {
    //     cout << dp[i] <<" " ;
    // }

    cout << dp[N-1] << endl;
    return 0;


    
}



Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int h,w;
    scanf("%d%d",&h,&w);
    int hae[64][64]={{0}};

    for(int i = 1;i <= h; i++){
        char str[64]={0};
        scanf("%s",str);
        for(int j = 1;j <= w; j++){
            hae[i][j] = str[j-1] - 48;
        }
    }
    int dp[64][64] = {{0}};

    for(int i = 1;i <= h; i++){
        for(int j = 1;j <= w; j++){
            if(i == 1 && j == 1)dp[i][j] = 0;
            else if(i == 1)dp[i][j] = dp[i][j-1]+hae[i][j];
            else if(j == 1)dp[i][j] = dp[i-1][j]+hae[i][j];
            else {
                dp[i][j] = min(dp[i-1][j]+hae[i][j],dp[i][j-1]+hae[i][j]);
            }
        }
    }
    printf("%d\n",dp[h][w]);
    return 0;
}

Measured memory_bytes: 1064
#include<stdio.h>
int main()
{
	for(;;)
	{
		int i,a[5],b[3]={0},w;
		for(i=0;i<5;++i)
		{
			if(scanf("%d",&a[i])-1)return 0;
			b[a[i]-1]++;
		}
		if((b[0]&&b[1]&&b[2])||(b[0]==5||b[1]==5||b[2]==5))puts("3\n3\n3\n3\n3");
		else
		{
			w=(!b[0]?2:(!b[1]?3:1));
			for(i=0;i<5;++i)printf("%d\n",(a[i]!=w)+1);
		}
	}
}

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

int n;

int check(string s)
{
  int x = 0;
  int three = 0, five = 0, seven = 0;
  for(int i = 0; i < s.size(); i++){
    x *= 10;
    x += s[i] - '0';
    if(s[i] == '3') three++;
    if(s[i] == '5') five++;
    if(s[i] == '7') seven++;
  }

  if(x > n) return 0;
  if(three == 0 or five == 0 or seven == 0) return 0;

  return 1;
}

int dfs(string s)
{
  if(s.size() > 9) return 0;

  int r = check(s);
  r += dfs(s + '3');
  r += dfs(s + '5');
  r += dfs(s + '7');
  return r;
}

int main()
{
  cin >> n;

  cout << dfs("") << endl;

  return 0;
}


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

int main(){
  long long X;
  cin >> X;
  long long Ans=(1LL<<(X+2));
  Ans-=2;
  cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int

using namespace std;
vector<pair<int,int > >adj[100010];
bool visit[100010];
int  dis[100010];
bool dfs(int v)
{
    visit[v]=1;
    bool ret=1;
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i].first;
        if(!visit[u])
        {
            dis[u]=dis[v]+adj[v][i].second;
            ret&=dfs(u);
            if(!ret)
                return 0;
        }
        else
            if(dis[u]!=dis[v]+adj[v][i].second)
            return 0;
    }
    return ret;
}

int main()
{

 int a;
 cin >>a;
 string b;
 cin>>b;
 for(int i=0;i<b.size();i++)
 {
     a*=10;
     a+=b[i]-'0';

 }


 int x=sqrt(a);
 if(x*x==a)
    cout <<"Yes";
 else
    cout << "No";
}



Measured memory_bytes: 2560
n,m,x,y=map(int,input().split())
x_list=list(map(int,input().split()))
y_list=list(map(int,input().split()))
x_list.append(x)
y_list.append(y)
x_list.sort()
y_list.sort()
if x_list[-1]<y_list[0]:
    print("No War")
else:
    print("War")

Measured memory_bytes: 3060
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
ans = 0
cnt = 0
for i in range(len(s)):
    if s[i] == 'R':
        cnt += 1
    else:
        cnt = 0
    ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 65472
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    if (N <= 3) {
        write(*max_element(all(A)));
        return 0;
    }

    vv<ll> dp = vvec(N, 3, -LINF);
    dp[0][0] = A[0];
    dp[1][1] = A[1];
    dp[2][0] = A[0] + A[2];
    dp[2][2] = A[2];
    dp[3][1] = A[3] + max(A[0], A[1]);
    rep(i, 4, N) {
        //if (i % 2 == 0) {
        //    dp[i][0] = max(dp[i][0], dp[i - 2][0] + A[i]);
        //    dp[i][1] = max(dp[i][1], dp[i - 2][1] + A[i]);
        //    dp[i][1] = max(dp[i][1], dp[i - 3][0] + A[i]);
        //    dp[i][2] = max(dp[i][2], dp[i - 2][2] + A[i]);
        //    dp[i][2] = max(dp[i][2], dp[i - 3][1] + A[i]);
        //    dp[i][2] = max(dp[i][2], dp[i - 4][0] + A[i]);
        //}
        //else {
        //    dp[i][1] = max(dp[i][0], dp[i - 2][1] + A[i]);
        //    dp[i][1] = max(dp[i][0], dp[i - 3][0] + A[i]);
        //}

        dp[i][0] = max(dp[i][0], dp[i - 2][0] + A[i]);
        dp[i][1] = max(dp[i][1], dp[i - 2][1] + A[i]);
        dp[i][1] = max(dp[i][1], dp[i - 3][0] + A[i]);
        dp[i][2] = max(dp[i][2], dp[i - 2][2] + A[i]);
        dp[i][2] = max(dp[i][2], dp[i - 3][1] + A[i]);
        dp[i][2] = max(dp[i][2], dp[i - 4][0] + A[i]);
    }

    ll ans;
    if (N % 2 == 0) {
        ans = max(dp[N - 2][0], dp[N - 1][1]);
    }
    else {
        ans = max({ dp[N - 3][0], dp[N - 2][1], dp[N - 1][2] });
    }
    write(ans);
}

Measured memory_bytes: 15860
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline void myassert(bool a,string s){ if(!a)cerr<<s<<endl,exit(0);}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=2e3+20;

vector<int>ed[maxn];

struct Edge {
	int u,v;
};
Edge OE[maxn],E[maxn<<1],T[maxn];
int ff[maxn<<1],ffw[maxn<<1];

int n,m,mtot;
int cf[maxn];
int ans=0;

int deep[maxn],fa[maxn];

void dfs(int u)
{
	for(int v:ed[u])
	{
		if(v==fa[u])continue;
		fa[v]=u;
		deep[v]=deep[u]+1;
		dfs(v);
	}
}

inline int lca(int u,int v)
{
	while(u!=v)
	{
		if(deep[u]>deep[v])swap(u,v);
		v=fa[v];
	}
	return u;
}

inline void take_cover0(int u,int v)
{
	int t=lca(u,v);
	while(u!=t)cf[u]++,u=fa[u];
	while(v!=t)cf[v]++,v=fa[v];
}

inline void init()
{
	n=read();mtot=m=read();
	REP(i,1,n-1)
	{
	 	int u=read(),v=read();
 	  	ed[u].push_back(v);
	 	ed[v].push_back(u);
		T[i]=(Edge){u,v};
	}
	REP(i,1,m)
	{
		int u=read(),v=read();
		OE[i]=E[i]=(Edge){u,v};
	}
	dfs(1);
	REP(i,1,m)take_cover0(E[i].u,E[i].v);
	REP(i,1,n)ans+=min(cf[i],2);
}

void solve(vector<int>tree,vector<int>edge)
{
	if(SZ(tree)==0)return;
	if(SZ(edge)<=1)
	{
		for(int i:edge)ffw[i]=0;
		return;
	}
	static int rd[maxn];
	memset(rd,0,sizeof(int)*(n+1));
	for(int i:tree)rd[T[i].u]++,rd[T[i].v]++;
	int U=0,V=0;
	REP(i,1,n)if(rd[i]==1){ U=i; break;}
	int j=0;
	vector<int>nedge,ntree;
	for(int i:tree)
		if(T[i].u==U || T[i].v==U)V=T[i].u^T[i].v^U;
		else ntree.push_back(i);

	vector<int>vis(2*m+1);
	
	for(int i:edge)
	{
		if(E[i].u==U || E[i].v==U)
		{
			if(j)
			{
				int a=E[j].u^E[j].v^U,b=E[i].u^E[i].v^U;
				if(a!=b)
				{
					ff[i]=ff[j]=++mtot; nedge.push_back(mtot);
					E[mtot]=(Edge){a,b};
					ffw[j]=(E[j].u!=a);
					ffw[i]=(E[i].v!=b);
					vis[i]=vis[j]=1;
				}else ffw[i]=1,ffw[j]=E[j].u != E[i].u;
				j=0;
			}else j=i;
		}else nedge.push_back(i);
	}
	if(j)
	{
		if(E[j].u==U)E[j].u=V;
		if(E[j].v==U)E[j].v=V;
		if(E[j].u!=E[j].v)nedge.push_back(j);
	}
	solve(ntree,nedge);
	for(int i:edge)if(vis[i])ffw[i]^=ffw[ff[i]];
}

inline void doing()
{
	printf("%d\n",ans);
	vector<int>tree,edge;
	REP(i,1,n-1)tree.push_back(i);
	REP(i,1,m)edge.push_back(i);
	solve(tree,edge);
	REP(i,1,m)
	{
		if(ffw[i])swap(OE[i].u,OE[i].v);
		printf("%d %d\n",OE[i].u,OE[i].v);
	}
}

int main()
{
	init();
	doing();
	return 0;
}


Measured memory_bytes: 70912
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int dp[maxn],deg[maxn];
vector<int> G[maxn];

int get(int u)
{
	if(dp[u]) return dp[u];
	for(auto it:G[u])
	dp[u]=max(dp[u],get(it)+1);
	return dp[u];
}

int main()
{
	int n,m,x,y;
	cin>>n>>m;
	
	while(m--) 
	{
		 cin>>x>>y;
		 deg[y]++;
		 G[x].push_back(y);
	}
	
	int ans=0;
	for(int i=1;i<=n;i++)
	if(deg[i]==0) ans=max(ans,get(i));
	
	cout<<ans<<endl;
	
	return 0;
 } 

Measured memory_bytes: 14432
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 10L^^9+7;

void main()
{
    auto N = readln.chomp.to!int;
    int[][] T;
    T.length = N;
    foreach (_; 0..N-1) {
        auto xy = readln.split.to!(int[]);
        auto x = xy[0]-1;
        auto y = xy[1]-1;
        T[x] ~= y;
        T[y] ~= x;
    }

    if (N == 1) {
        writeln(2);
        return;
    }

    auto DP = new long[][](N, 2);
    foreach (ref dp; DP) dp[] = -1;

    long solve(int i, int p, int b) {
        if (p != -1 && T[i].length == 1) return b == 0 ? 2 : 1;
        if (DP[i][b] == -1) {
            long r = 1;
            foreach (j; T[i]) if (j != p) {
                r = (r * solve(j, i, 0)) % P;
            }
            if (b == 0) {
                long s = 1;
                foreach (j; T[i]) if (j != p) {
                    s = (s * solve(j, i, 1)) % P;
                }
                r = (r + s) % P;
            }
            DP[i][b] = r;
        }
        return DP[i][b];
    }
    writeln(solve(0, -1, 0));
}

Measured memory_bytes: 23420
n, k = map(int, input().split())
a = list(map(int, input().split()))
pos = 1
if k < n:
    for _ in range(k):
        pos = a[pos - 1]
    print(pos)
else:
    lst = [1]
    for _ in range(n):
        pos = a[pos-1] 
        lst.append(pos)
    
    count = 0
    for num, i in enumerate(lst):
        if i == pos and count == 1:
            loop = num - before
            rem = (k - before) % loop
            print(lst[before + rem])
            break
        elif i == pos:
            count = 1
            before = num
    


Measured memory_bytes: 32408
#include <iostream>

int sum_of_digits(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main() {
    int N, A, B;
    std::cin >> N >> A >> B;

    int sum = 0;
    for (int n = 1; n <= N; n ++) {
        if (sum_of_digits(n) >=A && sum_of_digits(n) <= B) {
            sum += n;
        }
    }
    std::cout << sum << std::endl;
}


Measured memory_bytes: 256
///* BISMILLAH *///
#include<bits/stdc++.h>
using namespace std;
unsigned long long n,a[100000000],i;
int main()
{
cin>>n;
a[0]=2;
a[1]=1;
for(i=2;i<=n;i++)
a[i]=a[i-1]+a[i-2];
cout<<a[n];
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
	int N, M;
	int *p;
	int *ever_ac;
	int *result;//AC -> 1, WA -> 0
	int *history;
	int ac_number = 0;
	int wa_number = 0;
	char S[8];
	char ac[2] = "AC";
	char buf[64], *ch;
	int i;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	N = atoi(ch);
	ch = strtok(NULL, " ");
	M = atoi(ch);

	p = (int *)calloc(M, sizeof(int));
	result = (int *)calloc(M, sizeof(int));
	history = (int *)calloc(N, sizeof(int));
	ever_ac = (int *)calloc(N, sizeof(int));

	for(i = 0; i < N; i += 1) {
		history[i] = -1;
		ever_ac[i] = -1;
	}
	for(i = 0; i < M; i += 1) {
		p[i] = 0;
		result[i] = 0;
	}

	for(i = 0; i < M; i += 1) {
		fgets(buf, sizeof(buf), stdin);
		ch = strtok(buf, " ");
		p[i] = atoi(ch) - 1;
		ch = strtok(NULL, "\n");
		sprintf(S, "%s", ch);
		history[p[i]] = 0;
		if(strncmp(S, ac, 2) == 0) {
			//ac
			result[i] = 1;
			ever_ac[p[i]] = 1;
		} else {
			//wa
			result[i] = 0;
		}
	}

	for(i = 0; i < M; i += 1) {
		if(result[i] == 1) {
			//ac
			if(history[p[i]] == 0) {//ever ac
				history[p[i]] = 1;
				ac_number += 1;
			}
		} else if(result[i] == 0) {
			//wa
			if(history[p[i]] == 0 && ever_ac[p[i]] == 1) {//ever ac
				wa_number += 1;
			}
		}

	}

	printf("%d %d\n", ac_number, wa_number);

	free(p);
	free(result);
	free(history);
	return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>

int main(void){

	int N, K;
	int A[101][101] = {0};
	int d[101] = {0};
	int s[101] = {0};
	int ans = 0;

	scanf("%d %d", &N, &K);

	for(int i = 0; i < K; i++){
		scanf("%d", &d[i]);
		for(int j = 0; j < d[i]; j++){
			scanf("%d", &A[i][j]);
		}
	}

	for(int i = 0; i < K; i++){
		for(int j = 0; j < d[i]; j++){
			s[A[i][j] - 1]++;
		}
	}

	for(int i = 0; i < N; i++){
		if(s[i] == 0)
			ans++;
	}

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 1772
#include<bits/stdc++.h>
using namespace std;
vector<int> sz;
vector<int> parent;
int getParent(int A)
{
    while(parent[A]!=A)
    {
        parent[A] = parent[parent[A]];
        A = parent[A];
    }
    return A;
}
void Union(int A,int B)
{
    int pa = getParent(A);
    int pb = getParent(B);
    if(pa==pb)
        return;
    parent[pa] = pb;
    sz[pb] += sz[pa];
}
int main()
{
    int n,m;
    cin>>n>>m;
    parent.clear();
    sz.clear();
    parent.resize(n+1);
    sz.assign(n+1,1);
    for(int i=1;i<=n;i++)
        parent[i] = i;
    while(m--)
    {
        int u,v;
        cin>>u>>v;
        Union(u,v);
    }
    set<int> mySet;
    for(int i=1;i<=n;i++)
    {
        if(parent[i]==i)
        {
            mySet.insert(sz[i]);
        }
    }
    long long ans = 0;
    long long rem = 0;
    while(!mySet.empty())
    {
        ans += *mySet.begin()-rem;
        rem = ans;
        mySet.erase(mySet.begin());
    }
    cout<<ans;
}


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

using namespace std;

//#define MD 100010

long int nCr(long int n,long int r){
    if(r>n){
        return 0;
    }
    if(r*2>n){
        r=n-r;
    }
    if(r==0){
        return 1;
    }
    long int ans=n;
    for(long int i=2;i<=r;i++){
        ans*=(n-i+1);
        ans/=i;
    }
    return ans;
}

int main(){
    int n;
    cin>>n;
    vector<long int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    long int ansl=0,ansr=0,ma=0;
    sort(v.begin(),v.end());
    
    ansl=v[n-1];
    
    auto l = lower_bound(v.begin(),v.end(),ansl/2);
    if(*l==ansl/2){
        ansr=*l;
    }else if(*l==ansl){
        ansr=v[distance(v.begin(),l)-1];
    }else{
        if(distance(v.begin(),l)==0){
            ansr=*l;
        }else if(ansl%2==0){
            long int tmp1=abs(ansl/2-v[distance(v.begin(),l)]);
            long int tmp2=abs(ansl/2-v[distance(v.begin(),l)-1]);
            if(min(tmp1,tmp2)==tmp1){
                ansr=v[distance(v.begin(),l)];
            }else{
                 ansr=v[distance(v.begin(),l)-1];
            }
        }else{
            long int tmp1=abs((ansl/2+1)-v[distance(v.begin(),l)]);
            long int tmp2=abs((ansl/2+1)-v[distance(v.begin(),l)-1]);
            if(min(tmp1,tmp2)==tmp1){
                ansr=v[distance(v.begin(),l)];
            }else{
                 ansr=v[distance(v.begin(),l)-1];
            }
        }
    }
    
    cout<<ansl<<" "<<ansr<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,M,Pe;
double p;
vector<P> edges;
int num[1<<15];
double dp[1<<15];
double pow(int x)
{
	double res = 1.0;
	double r = p;
	while(x)
	{
		if(x&1)res*=r;
		r=r*r;
		x>>=1;
	}
	return res;
}
double rec(int S)
{
	if(dp[S]!=-1.0)return dp[S];
	if(S==0)return 0.0;
	double ret = 1.0;
	vector<int> v;
	for(int i=0;i<N;i++)if(S&(1<<i))v.pb(i);
	int sz = v.size();
	for(int i=1;i<(1<<sz);i++)
	{
		int T = S;
		for(int j=0;j<sz;j++)if(i&(1<<j))T-=(1<<v[j]);
		if(!(T&1))continue;
		ret -= rec(T)*pow((num[T]+num[S^T]-num[((1<<N)-1)^S])/2);
		//if(S==(1<<N)-1)cout << T << endl;
	}
	return dp[S]=ret;
}
int main()
{
	scanf("%d %d %d",&N,&M,&Pe);
	for(int i=0;i<M;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		u--;v--;
		edges.pb(P(u,v));
	}
	for(int i=0;i<(1<<N);i++)
	{
		for(int j=0;j<M;j++)
		{
			int u = edges[j].fi;
			int v = edges[j].sec;
			if(i&(1<<u) && !(i&(1<<v)))num[i]++;
			if(i&(1<<v) && !(i&(1<<u)))num[i]++;
		}
	}
	p = Pe/100.0;
	for(int i=0;i<(1<<N);i++)dp[i]=-1.0;
	//for(int i=1;i<(1<<N);i++)printf("%.12f\n",rec(i));
	printf("%.12f\n",rec((1<<N)-1));
	return 0;
}

Measured memory_bytes: 1444
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string o, e;
  cin >> o >> e;
  rep(i, 0, o.size()) {
    cout << o[i];
    if (i < e.size())
      cout << e[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

struct Node{
  int key;
  Node *parent,*left,*right;
};
Node *root,*NIL;

void find(int k){
  Node* x=root;
  while(x!=NIL){
    if(k<x->key){
      x=x->left;
    }else if(k==x->key){
      cout << "yes\n";
      return;
    }else{
      x=x->right;
    }
  }
  cout << "no\n";
}

void insert(int k){
  Node* y=NIL;
  Node* x=root;
  Node* z;
  z=(Node*)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL) root=z;
  else{
    if(y==NIL){
      root=z;
    }else{
      if(z->key<y->key) y->left=z;
      else y->right=z;
    }
  }
}

void inorder(Node* u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node* u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    string com;
    cin >> com;
    if(com=="print"){
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
    else if(com=="insert"){
      int z;
      cin >> z;
      insert(z);
    }
    else if(com=="find"){
      int z;
      cin >> z;
      find(z);
    }
  }
}

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

#define ll long long
#define endl '\n'

int n;

void test() {
    cin>>n;
    vector<int> a(n);
    int k=0;
    for (int& i:a) {cin>>i; k^=i;}
    for (int& i:a) {cout<<(k^i)<<' ';}
    cout<<endl;
}

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

    // int t;
    // cin >> t;
    // while (t--) {
    //     test();
    // }
    test();
    return 0;
}

Measured memory_bytes: 3960
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
    int M; cin >> M;
    cout << 24 + (24 - M) << endl;
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 2333333
int n,m,ff[SZ],nx[SZ],fs[SZ],sz[SZ],ea[SZ],eb[SZ];
Edg
int gf(int x) {return ff[x]?ff[x]=gf(ff[x]):x;}
void uni(int a,int b)
{
	int ga=gf(a),gb=gf(b);
	if(ga^gb) ff[ga]=gb;
}
int col[SZ];
char ch,B[1<<20],*S=B,*T=B;
#define getc() (S==T&&(T=(S=B)+fread(B,1,1<<20,stdin),S==T)?0:*S++)
#define isd(c) (c>='0'&&c<='9')
int aa,bb;int F(){
    while(ch=getc(),!isd(ch)&&ch!='-');ch=='-'?aa=bb=0:(aa=ch-'0',bb=1);
    while(ch=getc(),isd(ch))aa=aa*10+ch-'0';return bb?aa:-aa;
}
#define gi F()
#define BUFSIZE 5000000
namespace fob {char b[BUFSIZE]={},*f=b,*g=b+BUFSIZE-2;}
#define pob (fwrite(fob::b,sizeof(char),fob::f-fob::b,stdout),fob::f=fob::b,0)
#define pc(x) (*(fob::f++)=(x),(fob::f==fob::g)?pob:0)
struct foce {~foce() {pob; fflush(stdout);}} _foce;
namespace ib {char b[100];}
inline void pll(ll x)
{
    if(x==0) {pc(48); return;}
    //if(x<0) {pc('-'); x=-x;} //如果有负数就加上 
    char *s=ib::b;
    while(x) *(++s)=x%10, x/=10;
    while(s!=ib::b) pc((*(s--))+48);
}
void dfs(int x)
{
	for esb(x,e,b)
	{
		if(col[b]!=-1) continue;
		col[b]=(col[x]+(e&1)+1)%3; dfs(b);
	}
}
int main()
{
	memset(col,-1,sizeof(col));
	n=gi,m=gi;
	for(int i=1;i<=m;i++)
	{
		int a=gi,b=gi;
		ea[i]=a,eb[i]=b;
		ad_de(a,b);
		ad_de(b,a);
		uni(a,b);
	}
	ll ans=m;
	for(int i=1;i<=n;i++)
	{
		int f=gf(i); ++sz[f];
		nx[i]=fs[f]; fs[f]=i;
	}
	for(int i=1;i<=n;i++)
	{
		if(gf(i)!=i) continue;
		for(int x=fs[i];x;x=nx[x])
			if(col[x]==-1) dfs(x);
		bool good=1; int ce=0;
		ll cnt[3]={0,0,0};
		for(int x=fs[i];x;x=nx[x])
		{
			++cnt[col[x]];
			for esb(x,e,b)
				++ce, good&=col[b]==(col[x]+(e&1)+1)%3;
		}
		ce/=2;
		if(!good)
		{
			ans+=(ll)sz[i]*sz[i]-ce;
			continue;
		}
		if(cnt[0]&&cnt[1]&&cnt[2]);else continue;
		ans-=ce;
		ans+=cnt[0]*cnt[1];
		ans+=cnt[1]*cnt[2];
		ans+=cnt[2]*cnt[0];
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 36096
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    string s;
    cin>>s;
    vector<ll>v;
    for(int i=0;i+2<s.size();i++)
    {
        int c=0;
        for(int j=i;j<i+3;j++)
        {
            c=c*10+s[j]-'0';
        }
        v.push_back(abs(c-753));
    }
    sort(v.begin(),v.end());
    cout<<v[0]<<endl;
    return 0;
}


Measured memory_bytes: 256
// Try Tenka1
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let mut a = get!();
    let mut b = get!();
    let k = get!();
    
    for i in 0..k {
    	if i % 2 == 0 {
        	if a % 2 != 0 && a > 0 {
            	a -= 1;
            }
            a /= 2;
            b += a;
        } else {
        	if b % 2 != 0 && b > 0 {
            	b -= 1;
            }
            b /= 2;
            a += b;
        }
    }
	println!("{} {}", a, b);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;
template<class T> string toString(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}
int main(){
  int n, m, s, c, r, l;
  cin>>n>>m;
  vpi v;
  for(int i = 0; i < m; ++i){
    cin>>s>>c;
    v.push_back(make_pair(s-1, c));
  }
  if(n == 1){
    l = 0;
    r = 10;
  }
  if(n == 2){
    l = 10;
    r = 100;
  }
  if(n == 3){
    l = 100;
    r = 1000;
  }
  for(int x = l; x < r; ++x){
    bool ok = true;
    for(int i = 0; i < m; ++i){
      string y = toString(x);
      if(y[v[i].first] - '0' != v[i].second){
	ok = false;
      }
    }
    if(ok){
      cout<<x<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
using ll = long long;
typedef pair<int,int> P;
typedef pair<P,ll> PP;
using Graph = vector<vector<ll> >;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

int main(){
    ll m,d;
    cin >> m >> d;
    ll ans = 0;
    for(int i=1;i<=m;i++){
        for(int j=10;j<=d;j++){
            int d1 = j%10;
            int d10 = (j/10)%10;
            if(d1>=2&&d10>=2&&d1*d10==i)ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define MAXN 507
using namespace std;
int dist[MAXN][MAXN],ind[MAXN][MAXN],rev[MAXN*MAXN],n;
bool vi[MAXN][MAXN];
bool inside(int x,int y) {return x>=1 && x<=n && y>=1 && y<=n;}
void upd(int x,int y,int nd)
{
	int add=(nd>=ind[x][y])?0:1;
	if(inside(x+1,y) && dist[x+1][y]>dist[x][y]+add) {dist[x+1][y]=dist[x][y]+add; upd(x+1,y,nd);}
	if(inside(x-1,y) && dist[x-1][y]>dist[x][y]+add) {dist[x-1][y]=dist[x][y]+add; upd(x-1,y,nd);}
	if(inside(x,y+1) && dist[x][y+1]>dist[x][y]+add) {dist[x][y+1]=dist[x][y]+add; upd(x,y+1,nd);}
	if(inside(x,y-1) && dist[x][y-1]>dist[x][y]+add) {dist[x][y-1]=dist[x][y]+add; upd(x,y-1,nd);}
}
int main()
{
	int rez=0;
	scanf("%d",&n);
	for(int i=1;i<=n*n;i++)
	{
		scanf("%d",&rev[i]);
		ind[(rev[i]%n==0)?n:rev[i]%n][(rev[i]-1)/n+1]=i;
	}
	queue<int> q;
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i==1 || i==n || j==1 || j==n) {vi[i][j]=true; q.push(ind[i][j]);}
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		int x=rev[u]%n,y=(rev[u]-1)/n+1;
		if(x==0) x=n;
		if(inside(x+1,y) && !vi[x+1][y]) {vi[x+1][y]=true; q.push(ind[x+1][y]); dist[x+1][y]=dist[x][y]+1;}
		if(inside(x-1,y) && !vi[x-1][y]) {vi[x-1][y]=true; q.push(ind[x-1][y]); dist[x-1][y]=dist[x][y]+1;}
		if(inside(x,y+1) && !vi[x][y+1]) {vi[x][y+1]=true; q.push(ind[x][y+1]); dist[x][y+1]=dist[x][y]+1;}
		if(inside(x,y-1) && !vi[x][y-1]) {vi[x][y-1]=true; q.push(ind[x][y-1]); dist[x][y-1]=dist[x][y]+1;}
	}
	for(int i=1;i<=n*n;i++)
	{
		int x=rev[i]%n,y=(rev[i]-1)/n+1;
		if(x==0) x=n;
		rez+=dist[x][y];
		upd(x,y,i);	
		
	}
	printf("%d",rez);
}

Measured memory_bytes: 33992
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

//素因数分解
map<ll, int> prime_factor(ll n) {
    map<ll, int> ret;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1)
        ret[n] = 1;
    return ret;
}

int main() {
    ll N;
    cin >> N;
    auto pf = prime_factor(N);
    int res = 0;
    for(auto x : pf) {
        int tmp = 1;
        while(x.second - tmp >= 0) {
            x.second -= tmp;
            tmp++;
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

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

int main(){
    long N,K;
    cin >> K >> N;
    long A[N];
    for(long i=0; i<N; i++){
        cin >> A[i];
    }
    sort(A,A+N);

    long ans = A[N-1]-A[0];
    for(int i=0; i<N-1; i++){
        ans= min( ans, K-( A[i+1]-A[i] ) );
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 2e5 + 10;
char s[N];

int main() {
  scanf("%s", s);
  int n = strlen(s);
  int64 ret = 0, cnt = 0;
  for (int i = n - 1; i >= 0; --i) {
    cnt += (s[i] == 'W');
    if (s[i] == 'B') ret += cnt;
  }
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  rep(i,1,n+1){
    if(i%3!=0&&i%5!=0)res+=i;
  }
  cout<<res<<endl;
  return 0;
}

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

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

int main() {
  int S;
  int h, m, s;
  cin >> S;
  h = S / 3600;
  m = S % 3600 / 60;
  s = S % 60;
  cout << h << ':' << m << ':' << s << endl;
  return 0;
}



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

int main(){
  int n, x;
  cin >> n >> x;
  vector<int> an(n);
  for(int i=0; i<n; ++i) cin >> an[i];
  ll ans = 0;
  for(int i=0; i<n-1; ++i){
    int ca = max(0, an[i] +an[i+1] -x);
    ans += ca;
    an[i+1] = max(0, an[i+1] -ca);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3792
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int main() {
  int n,m;
  cin >> n >> m;

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

  int ans = 0;

  map<int, int> mp;
  for(int i = 0; i < m; i++){
    int a,b;
    cin >> a >> b;

    if(h[a] != h[b]){
      int high = (h[a] > h[b] ? a : b);

      if(mp[a] != -1){
        mp[a] = (h[high] > h[mp[a]] ? high : mp[a]);
      }
      if(mp[b] != -1){
        mp[b] = (h[high] > h[mp[b]] ? high : mp[b]); 
      }
    }
    else{
      mp[a] = -1;
      mp[b] = -1;
    }
  }

  for(auto p : mp){   
    if(p.first == p.second){
      ans++;
    }    
  }

  ans += n - mp.size();

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 8016
#include <iostream>
#include <iomanip> // setprecision
#include <cmath>

using namespace std;
typedef long long ll;
const double long PI = acos(-1);

void solve() {
  ll n, i;
  char S[10005];
  cin >> n;
  cin >> S;
  i = 0;
  while (S[i] != '\0') {
    ll tmp = ((S[i] - 'A') + n) % 26 + 'A';
    cout << char(tmp);
    i++;
  }
  cout << endl;
}

int main(void) {
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 256
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let n: usize = get_input().parse().unwrap();
    let mut d: Vec<i32> = Vec::with_capacity(n);

    for _i in 0..n {
        let v:i32 = get_input().parse().unwrap();
        d.push(v);
    }

    d.sort();
    d.dedup();

    println!("{}", d.len());
}

Measured memory_bytes: 4352
n=int(input())
s=input()
ans=n
sl=[0]
sr=[0]
c=0
for i in s:
    if i=="W":c+=1
    sl.append(c)
s=s[::-1]
c=0
for i in s:
    if i=="E":c+=1
    sr.append(c)
sr=sr[::-1]
for i in range(n):ans=min(ans,sl[i]+sr[i+1])
print(ans)

Measured memory_bytes: 20488
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
 
const int INT = 753;

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

  int m = 753;
  for(int i = 0; i < a.length(); i++)
  {
    int tmp = stoi(a.substr(i, 3));
    m = min(m, abs(INT - tmp));
  }

  cout << m;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
typedef long long int ll;
using namespace std;
string s, t;
int main(){
  cin >> s;
  cin >> t;
  int ans = 0;
  for(int i=0;i<3;i++) ans += (s[i] == t[i]);
  cout << ans << endl;
  return 0;
}
  

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

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

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(in);
		char[] s = sc.next().toCharArray();
		sc.close();
		int ans=700;
		for (char c : s) {
			if(c=='o')ans+=100;
		}
		out.println(ans);
	}
}


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

vector<long long int> v;

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

int main(void){
    
    int k;
    cin >> k;
    long long int sum=0;
    
    
    for(int i=1;i<=k;i++){
        for(int n=1;n<=k;n++){
            v.push_back( gcd(i, n) );
        }
    }
    
    //for(int i=0;i<v.size();i++) cout << v[i] << endl;
    int u = v.size();
    for(int i=0;i<u;i++) {
        
        long long int m = v[i];
        for(int n=1;n<=k;n++) {
            if(n==1) v[i] = gcd(m, n);
            else v.push_back( gcd(m, n) );
        }
    }
    
    for(int i=0;i<v.size();i++){
        sum += v[i];  
    } 
    
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 68968
#include <stdio.h>
#include <string.h>
int main(){
  int a[250];
  int N,i,count=0,flag = 0;
  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
    //printf("%d ",a[i]);
  }
  //printf("\n");
  while(1){
  	for(i=0;i<N;i++){
      if(a[i]%2 != 0) flag=1;
   	 a[i] = a[i]/2;
   	 
     }
    if(flag == 1) break;
    count++;
  }
  
  printf("%d\n",count);
  return 0;
}

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

int main() {
    int64_t N;
    cin >> N;
    const int64_t MAX = (1LL << (N - 1));

    vector<string> ans;
    ans.emplace_back("a");
    for (int64_t i = 1; i < N; i++) {
        vector<string> new_ans;
        for (const string& s : ans) {
            char m = *max_element(s.begin(), s.end());
            for (char add = 'a'; add <= m + 1; add++) {
                new_ans.push_back(s + add);
            }
        }
        ans = new_ans;
    }

    sort(ans.begin(), ans.end());
    for (const string& s : ans) {
        cout << s << endl;
    }
}

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

int main() {
  int r,D,x;
  cin >> r >> D >> x;
  for(int i =  0; i < 10; i++){
    x = r*x - D;
    cout << x;
    if(0 <= i && i <= 8){
      cout << endl;
    }
  }
}



Measured memory_bytes: 256
n, k, q = map(int, input().split())

list_A = []

for _ in range(q):
    i = int(input())
    list_A.append(i)

list_per = [0]*n

for i in list_A:
    i = i - 1
    list_per[i] = list_per[i] + 1

for i in list_per:
    if k - q + i > 0:
        print("Yes")

    else:
        print("No")


Measured memory_bytes: 8592
#include<iostream>
using namespace std;
int main(){
  int a,b,c,i,l,count;
  cin >> a >> b >> c;
  if (a+b >= c){
    cout << b+c;
  }else{
    i = c-b;
    l = a;
    count = 0;
    while(i >= 0 && l >= 0){
      count++;
      i--;
      l--;
    }
    cout << count + b*2;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int M = sc.nextInt();
			int D = sc.nextInt();
			if (D < 22) {
				System.out.println(0);
				return;
			}
			int count = 0;
			for (int i = 22; i <= D; i++) {
				int d2 = i / 10;
				int d1 = i % 10;
				if (d1 < 2) {
					continue;
				}
				if (d1 * d2 <= M) {
					count++;
				}
			}
			System.out.print(count);
		}
	}
}

Measured memory_bytes: 22484
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int dat[501][501];
int dx[]={0,0,1,1,-1,-1};
int dy[]={1,-1,-1,0,0,+1};
int bfs[501][501];
int main(){
	int a,b;
	scanf("%d%d",&b,&a);
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			if(j+1+a-(i+1)/2<0)printf("dededon\n");
			scanf("%d",&dat[i+1][j+1+a-(i+1)/2]);
		}
	}
	queue<pair<int,int> > Q;
	Q.push(make_pair(0,0));
	bfs[0][0]=1;
	while(Q.size()){
		int row=Q.front().first;
		int col=Q.front().second;
		Q.pop();
		for(int i=0;i<6;i++){
			if(0<=row+dx[i]&&row+dx[i]<=500&&0<=col+dy[i]&&col+dy[i]<=500&&!dat[row+dx[i]][col+dy[i]]&&!bfs[row+dx[i]][col+dy[i]]){
				bfs[row+dx[i]][col+dy[i]]=1;
				Q.push(make_pair(row+dx[i],col+dy[i]));
			}
		}
	}
	int ret=0;
	for(int i=1;i<500;i++){
		for(int j=1;j<500;j++){
			for(int k=0;k<6;k++){
				if(dat[i][j]&&bfs[i+dx[k]][j+dy[k]])ret++;
			}
		}
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 0