akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"


template <typename T, typename K> struct P {
	T a; K b;
};

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
vector <P <ll, ll> >prime_factorize( ll N );
ll pow( ll a, ll n);
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
int main( void ){
	// initialize();
	ll N, K;
	cin >> N >> K;
	ll ans = N%K;
	ans = min(ans, K-ans);
	cout << ans << endl;
}

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

/*
 * @fn eratosthenes
 * @brief O(NloglogN)~=(N)
 * @param N: その数まで
 * @return 0 or 1 の配列 (boolは都合が悪い)
 */
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}

/*
 * @fn prime_factorize
 * @brief O(√N): 素因数分解
 * @param N: 素因数分解する数
 * @return vec: (a: 素数, b: 個数)
 */
vector <P <ll, ll> >prime_factorize( ll N ){
	vector <P <ll, ll> > vec;
	int lim = sqrt( N ) + 1;
	rep( i, 2, N + 1 ){
		if (i >= lim){
			vec.push_back( P <ll, ll>{N, 1} );
			break;
		}
		if (N % i == 0){
			vec.push_back( P <ll, ll>{i, 0} );
			while(N % i == 0){
				N /= i;
				vec.back().b++;
			}
		}
	}
	return vec;
}
/*
 * @fn pow
 * @brief a^n
 * @param a: 基数
 * @param n: 指数
 */
ll pow( ll a, ll n) {
	ll res = 1;
	while (n > 0){
		if (n & 1) res = res * a;
		a = a * a;
		n >>= 1;
	}
	return res;
}

void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int p[N],n;
long long ans=0;
class RMQ
{
    private:
        pair<int,int> f[N][20];
        int log[N]={-1};
    public:
        RMQ(){memset(f,-0x3f3f3f3f,sizeof(f));}
        void insert()
        {
            for(int i=1;i<=n;i++)
            {
                log[i]=log[i>>1]+1;
                f[i][0].first=p[i],f[i][0].second=i;
            }
            for(int j=1;(1<<j)<=n;j++)
                for(int i=1;i+(1<<j)-1<=n;i++)
                    f[i][j]=max(f[i][j-1],f[i+(1<<j-1)][j-1]);
        }
        int query(int l,int r)
        {
            int k=log[r-l+1];
            return max(f[l][k],f[r-(1<<k)+1][k]).second;
        }
}st;
int find1(int x,int now)
{
    int l=1,r=x,res=0;
    while(l<=r)
    {
        int mid=l+r>>1,k=st.query(mid,x);
        if(p[k]>now) res=k,l=mid+1;
        else r=mid-1;
    }
    return res;
}
int find2(int x,int now)
{
    int l=x,r=n,res=n+1;
    while(l<=r)
    {
       int mid=l+r>>1,k=st.query(x,mid); 
       if(p[k]>now) res=k,r=mid-1;
       else l=mid+1;
    }
    return res;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&p[i]);
    st.insert();
    for(int i=1;i<=n;i++)
    {
        int a=find1(i-1,p[i]);
        int b=find1(a-1,p[i]);
        int c=find2(i+1,p[i]);
        int d=find2(c+1,p[i]);
        cerr<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<(a-b)*(c-i)+(i-b)*(d-c)<<endl;
        ans+=(long long)((a-b)*(c-i)+(i-a)*(d-c))*p[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> v = {0};
  
  for (int i = 1; i < 101; i++){
    if (A % i == 0 && B % i == 0){
      v.push_back(i);
    }
  }  
  int k = v.size() - K;
  cout << v.at(k) << endl;  
}
    
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int w, a, b; cin >> w >> a >> b;
  int ans = 0;
  if(min(a, b)+w < max(a,b))ans = max(a,b)-(min(a,b)+w);
  cout << ans << endl;
  system("pause");
}

Measured memory_bytes: 504
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    long double ans = 0.0;
    vector<pair<double, string>> P(N);
    for (int i = 0; i < N; ++i) {
        cin >> P[i].first >> P[i].second;
        if (P[i].second == "BTC") ans += P[i].first * 380000.0;
        else ans += P[i].first;
    }
    cout << setprecision(6) << ans << endl;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  string s;
  cin >> s;
  if (s.at(0)==s.at(1)&&s.at(1)==s.at(2)) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b;
    string s;
    cin >> a >> b;
    cin >> s;
    int n=s.size();
    bool flag1=false;
    bool flag2=true;
    for (int i=0;i<n;i++) {
        if (s[i]=='-') {
            flag1=true;
            if (a!=i || b!=n-1-i) flag2=false;
        }
    }
    if (flag1 && flag2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import fractions

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

ans = my_list[0]

for i in range(n):
    ans = ans * my_list[i] // fractions.gcd(ans, my_list[i])

ret = 0

for i in range(n):
    ret = ret + (ans // my_list[i])

print(ret % 1000000007)


Measured memory_bytes: 6112
#include<bits/stdc++.h>
using namespace std;
const long long MOD=1000000007;


int main(){
  
  long long n,k;
  cin>>n>>k;
  long long a[n],r=0,l=0;
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      if(a[i]>a[j]) r++;
      else if(a[i]<a[j]) l++;
    }
  }
  long long ans=(k*r)%MOD+k*(k-1)/2%MOD*(l+r)%MOD;
  cout<<ans%MOD<<endl;
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <tuple>
#include <vector>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define ALL(x) begin(x), end(x)
using namespace std;

const int dy[] = { -1, 1, 0, 0 };
const int dx[] = { 0, 0, 1, -1 };
const char *dc = "SNEW";
const char *rev_dc = "NSWE";
int index_of(char c) { return strchr(dc, c) - dc; }

constexpr int H = 103;
constexpr int W = 103;
int main() {
    // input
    int n, x0, y0, t; scanf("%d%d%d%d", &n, &x0, &y0, &t);
    x0 = 2 * x0 + 1;
    y0 = 2 * y0 + 1;
    array<array<bool, W>, H> f = {};
    while (n --) {
        int xs, ys, xe, ye; scanf("%d%d%d%d", &xs, &ys, &xe, &ye);
        xs = 2 * xs + 1;
        ys = 2 * ys + 1;
        xe = 2 * xe + 1;
        ye = 2 * ye + 1;
        if (xs == xe) {
            REP3 (y, min(ys, ye), max(ys, ye) + 1) {
                f[xs][y] = true;
            }
        } else if (ys == ye) {
            REP3 (x, min(xs, xe), max(xs, xe) + 1) {
                f[x][ys] = true;
            }
        } else {
            assert (false);
        }
    }
    vector<tuple<int, int, char, char> > poss;
    REP (i, 4) {
        if (not f[x0 + dx[i]][y0 + dy[i]]) continue;
        poss.emplace_back(x0, y0, '*', dc[i]);
    }
    while (t --) {
        int d; char c; scanf("%d %c", &d, &c);
        // solve
        while (d --) {
            vector<tuple<int, int, char, char> > next_poss;
            for (auto pos : poss) {
                int x, y; char dc_i; tie(x, y, ignore, dc_i) = pos;
                int i = index_of(dc_i);
                if (not f[x + dx[i]][y + dy[i]]) continue;
                int nx = x + 2 * dx[i];
                int ny = y + 2 * dy[i];
                REP (j, 4) if (rev_dc[j] != dc[i]) {
                    if (i != j and not f[nx + dx[j]][ny + dy[j]]) continue;
                    next_poss.emplace_back(nx, ny, dc[i], dc[j]);
                }
            }
            poss = next_poss;
            sort(ALL(poss));
            poss.erase(unique(ALL(poss)), poss.end());
        }
        poss.erase(remove_if(ALL(poss), [&](tuple<int, int, char, char> a) {
            char c1, c2; tie(ignore, ignore, c1, c2) = a;
            return c1 != c and c2 != c;
        }), poss.end());
    }
    // output
    sort(ALL(poss));
    poss.erase(unique(ALL(poss), [](tuple<int, int, char, char> a, tuple<int, int, char, char> b) {
        return get<0>(a) == get<0>(b) and get<1>(a) == get<1>(b);
    }), poss.end());
    for (auto pos : poss) {
        printf("%d %d\n", (get<0>(pos) - 1) / 2, (get<1>(pos) - 1) / 2);
    }
    return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
	deque<int> s1;
	deque<pair<int, int>> s2;
	char c;
	int sum = 0;
	for(int i = 0; cin >> c; ++i) {
		if(c == '\\') s1.eb(i);
		else if(c == '/' && len(s1) > 0) {
			int j = s1.back(); s1.pop_back();
			int a = i - j;
			sum += a;
			while(len(s2) > 0 && s2.back().first > j) {
				a += s2.back().second; s2.pop_back();
			}
			s2.eb(mp(j, a));
		}
	}
	P(sum);
	p(len(s2));
	rep(i, 0, len(s2)) {
		cout << " " << s2[i].second;
	}
	P("");
	return 0;
}

Measured memory_bytes: 3256
#include<bits/stdc++.h>
using namespace std;
int cek[50];
long long int power(long long int a, long long int b)
{
    if(b == 0)
        return 1;
    else
    {
        long long int ret = 1;
        while(b>0)
        {
            if(b%2==1)
            {
                ret = (ret*a);
            }
            b /= 2;
            a = (a*a);
        }
        return ret;
    }
}
int main()
{
    long long int n,k,i,j,x,y,m;
    scanf("%lld %lld",&n,&k);
    long long int arr[n];
    for(i=0;i<n;i++)
    {
        scanf("%lld",&arr[i]);
        long long int temp = arr[i];
        int idx = 0;
        while(temp > 0)
        {
            if(temp % 2 == 1)
            {
                cek[idx]++;
            }
            idx++;
            temp /= 2;
        }
    }
    long long int can = k;
    int bit = 0;
    while(can > 0)
    {
        bit++;
        can /= 2;
    }
    long long int xora = 0;
    long long int byk = n;
    if(byk&1)
        byk--;
    for(i=bit-1;i>=0;i--)
    {
        if(cek[i] <= (byk/2))
        {
            if(xora + power(2,i) <= k)
            {
                xora += power(2,i);
            }
        }
    }
    long long int jwb = 0;
    for(i=0;i<n;i++)
    {
        jwb += (xora^arr[i]);
    }
    printf("%lld\n",jwb);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a, b, k; cin >> a >> b >> k;
    int aa = a;
    aa -= k;
    if (aa < 0){
        aa = 0;
        b -= k-a;
        if (b < 0) b = 0;
    }
    cout << aa << " " << b << endl;
    return 0;
}

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

int main() {

  int N,D;
  cin >> N >> D;
  
  vector<vector<int>> X(N,vector<int>(D));
  for ( int i = 0 ; i < N ; i++ ){
  	for ( int j = 0 ; j < D ; j++ ){
    	cin >> X.at(i).at(j) ;
    }
  }
  int cnt = 0 ;
  for ( int i = 0 ; i < N-1 ; i++ ){
  	for ( int j = i + 1 ; j < N ; j++ ){
      	double distance = 0;
    	for ( int k = 0 ; k < D ; k++ ){
        	distance += pow( ( X.at(j).at(k) - X.at(i).at(k) ) , 2.0);
        }
      if ( sqrt(distance) == (int) sqrt(distance) )
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String s = sc.next();
      if(s.matches("[A]{0,1}KIH[A]{0,1}B[A]{0,1}R[A]{0,1}"))System.out.println("YES");
      else System.out.println("NO");
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>

using namespace std;

// http://d.hatena.ne.jp/pogin/20121001/1349069143
inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

template<class T> inline string toString(T x) {
	ostringstream sout;
	sout << x;
	return sout.str();
}

int main() {
	while (true) {
		string s;
		cin >> s;
		if (s == "0000") {
			break;
		}
		if (toInt(s) % 1111 == 0) {
			cout << "NA" << endl;
			continue;
		}
		
		int ans = 0;
		while (s != "6174") {
			ans++;
			sort(s.begin(), s.end());
			string min = s;
			string max;
			max = min;
			reverse(max.begin(), max.end());
			//cout << "max: " << max << " min: " << min << endl;
			int next = toInt(max) - toInt(min);
			//cout << "next: " << next << endl;
			string next_string = toString<int>(next);
			int next_length = next_string.length();
			if (next_length <= 3) {
				for (int i = next_length; i < 4; i++) {
					next_string.append("0");
				}
			}
			s = next_string;
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1260
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int res = 0;
		while (sc.hasNext()) {
			char[] c = sc.next().toCharArray();
			
			int tmp = 0;
			for (int i = 0; i < c.length; i++) {
				if ('0' <= c[i] && c[i] <= '9') {
					tmp *= 10;
					tmp += c[i] - '0';
				} else {
					res += tmp;
					tmp = 0;
				}
			}
			res += tmp;
		}
		
		System.out.println(res);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 17160
# D

n = int(input())
a_l = [int(x) for x in input().split()]

a_l.sort(reverse=True)
ans = -a_l[0]
now = a_l[0]
count = 1
for i in range(n):
    if i % 2 == 0:
        ans += now
    else:
        ans += now
        now = a_l[count]
        count += 1
print(ans)

Measured memory_bytes: 31520
import java.util.*;
import java.io.*;
public class Main
{   
    public static long knapSack(int value[],int weight[],long dp[][],int w)
    {
        for(int i=0;i<dp.length;i++)
        for(int j=0;j<dp[i].length;j++)
        {
            dp[i][j]=Integer.MAX_VALUE;
        }
        for(int i=0;i<dp.length;i++)dp[i][0]=0;
        for(int i=1;i<dp.length;i++)
        {
            for(int j=1;j<dp[i].length;j++)
            {
                if(value[i-1]<=j)
                {
                    dp[i][j]=Math.min(weight[i-1]+dp[i-1][j-value[i-1]],dp[i-1][j]);
                }
                else dp[i][j]=dp[i-1][j];
            }
        }
        
        long ans=0;
        for(int j=0;j<dp[0].length;j++)
        {
            if(dp[dp.length-1][j]<=w)
            {
                ans=j;
            }
        }
        return ans;
    }
	public static void main(String[] args)throws IOException {
		    FastReader kb=new FastReader();
            int sum=0;
            int n=kb.nextInt(),w=kb.nextInt();
            int value[]=new int[n];
            int weight[]=new int[n];
            for(int i=0;i<n;i++)
            {
                weight[i]=kb.nextInt();value[i]=kb.nextInt();sum+=value[i];
            }
            long dp[][]=new long[n+1][sum+1];
            System.out.println(knapSack(value,weight,dp,w));
	}
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
  
}















Measured memory_bytes: 125832
import java.util.Arrays;
import java.util.Scanner;

class Main{




	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		long pow = 1000000000+7;

		int[] data = new int[n];
		for(int i=0;i < n;i++){
			data[i] = sc.nextInt();
		}
		Arrays.sort(data);
		
		
		if(n%2==1){					//人数が奇数
			if(data[0] !=0){
				System.out.println(0);
				return;
			}
			for(int i = 1;i < n-1;i++){
				if(data[i] != data[i+1]){
					System.out.println(0);
					return;
				}
				i++;
			}
			
			int ans = 1;
			for(int i = 0;i <(data.length-1)/2;i++){
				ans *= 2;
				ans %= pow;
			}

			System.out.println(ans);	
		}else{					//人数が偶数
			if(data[0] ==0){
				System.out.println(0);
				return;
			}
			for(int i = 0;i < n-1;i++){
				if(data[i] != data[i+1]){
					System.out.println(0);
					return;
				}
				i++;
			}
			
			int ans = 1;
			for(int i = 0;i <data.length/2;i++){
				ans *= 2;
				ans %= pow;
			}

			System.out.println(ans);	
			
			
		}
		


	}
}

class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




Measured memory_bytes: 50772
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			x = in.readLine();
			String[] nm = x.split(" ");
			int n = Integer.parseInt(nm[0]);
			int m = Integer.parseInt(nm[1]);
			
			int[][] md = new int[n + 1][m + 1];
			
			for (int i = 0; i < n; i++) {
				x = in.readLine();
				String[] e = x.split(" ");
				
				md[i][m] = 0;
				for (int j = 0; j < m; j++) {
					if (i == 0) md[n][j] = 0;
					
					md[i][j] = Integer.parseInt(e[j]);
					md[i][m] = md[i][m] + md[i][j];
					md[n][j] = md[n][j] + md[i][j];
				}
			}
			
			md[n][m] = 0;
			for (int i = 0; i < n; i++) {
				md[n][m] = md[n][m] + md[i][m];
			}
			
			for (int i = 0; i < (n + 1); i++) {
				for (int j = 0; j < (m + 1); j++) {
					if (j != 0) System.out.print(" ");
					System.out.print(md[i][j]);
				}
				System.out.println();
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 32940
import java.util.Scanner;

public class Main{
	
	

	public static void main(String[] args) {
		
	Scanner sc=new Scanner(System.in);
    int r=sc.nextInt();
    int D=sc.nextInt();
    int x2000=sc.nextInt();
    int temp=x2000;
    for(int i=0;i<10;i++) {
    	temp=r*temp-D;
    	System.out.println(temp);
    }
   
    

	
	
	
    

		
	}
	

	
}
		



Measured memory_bytes: 22228
from queue import Queue

N, M = map(int, input().split())
d = {}
for i in range(1, N+1):
    d[i] = []
for i in range(M):
    x, y, z = map(int, input().split())
    d[x].append(y)
    d[y].append(x)

isChecked = [False for i in range(N)]
ans = 0
for k in d:
    if isChecked[k-1]:
        continue
    ans += 1
    q = Queue()
    q.put(k)
    while not q.empty():
        v = q.get()
        if isChecked[v-1]:
            continue
        isChecked[v-1] = True
        for u in d[v]:
            q.put(u)

print(ans)


Measured memory_bytes: 84832
def resolve():
    N,x = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    Acouont = 0
    ans = 0
    if sum(A) < x:
        print(N-1)
    else:
        for i in range(N):
            Acouont = Acouont + A[i]
            #print (Acouont)
            if Acouont > x:
                break
            ans += 1
        print(ans)   
resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<int, ll> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
// const ll MAXN = 

string s, t;
vector<int> pos[27];
/********** Good Luck :) **********/
int main()
{
    TIME(main);
    IOS();
    cin >> s >> t;
    REP (i, SZ(s)) {
        pos[s[i] - 'a'].eb(i);
    }

    int cur = -1;
    ll sum = 0;
    for (auto c : t) {
        if (pos[c - 'a'].empty()) {
            cout << -1 << endl;
            return 0;
        } else {
            if (pos[c - 'a'].back() <= cur) {
                cur = -1;
                sum += SZ(s);
            }
            int id = *upper_bound(ALL(pos[c - 'a']), cur);
            cur = id;
        }
    }

    cout << sum + cur + 1 << endl;
    return 0;
}


Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	ll A[100001] = {};
	rep1(i, N) {
		cin >> A[i];
		A[i] += A[i - 1];
	}
	ll k1[2] = {};
	ll k2[2] = {};

	rep1(i, N) {
		if (i % 2) {
			if (A[i] - k1[0] + k1[1] <= 0) k1[1] += 1 - A[i] + k1[0] - k1[1];
			if (A[i] - k2[0] + k2[1] >= 0) k2[0] += 1 + A[i] - k2[0] + k2[1];
		}
		else {
			if (A[i] - k1[0] + k1[1] >= 0) k1[0] += 1 + A[i] - k1[0] + k1[1];
			if (A[i] - k2[0] + k2[1] <= 0) k2[1] += 1 - A[i] + k2[0] - k2[1];
		}

	}

	ll kotae = min(k1[0] + k1[1], k2[0] + k2[1]);
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 1024
N,M=gets.split.map(&:to_i)
LRS=M.times.map { gets.split.map(&:to_i) }
min_l = LRS[0][0]
min_r = LRS[0][1]
LRS.each do |lr|
  min_l = lr[0] if min_l < lr[0]
  min_r = lr[1] if min_r > lr[1]
end

cnt=0

N.times do |n|
  cnt+=1 if n+1 >= min_l && n+1 <= min_r
end

p cnt


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector <vector<int>>;
using vvl = vector <vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n, x, m;
  cin >> n >> x >> m;
  vector <ll> as(m + 1);
  map<ll, int> s;
  as[0] = x;
  s[x] = 0;
  int len = 0;
  int st = 0;
  ll sum = as[0];
  ll ans = as[0];
  n--;
  for (int i = 0; i < m && n > 0; i++) {
    as[i + 1] = (as[i] * as[i]) % m;
    if (s.find(as[i + 1]) != s.end()) {
      len = i + 1 - s[as[i + 1]];
      for (int j = 0; j < s[as[i + 1]]; j++) sum -= as[j];
      st = s[as[i + 1]];
      break;
    }
    ans += as[i + 1];
    n--;
    sum += as[i + 1];
    s[as[i + 1]] = i + 1;
  }
  if (n > 0) {
    ans += (n / len) * sum;
    for (int j = 0; j < (n % len); j++) {
      ans += as[st + j];
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
   int n, a=0, b=0, c=0, d=0;
   cin >> n;
   vector<int> vec(n);
   for(int i=0; i<n; i++) cin >> vec.at(i);
   for(int i=0; i<n; i++) {
       if(vec.at(i)%2==0) a++;
   }
   for(int i=0; i<n; i++) {
       if(vec.at(i)%6==0) b++;
   }
   for(int i=0; i<n; i++) {
       if(vec.at(i)%10==0) c++;
   }
   for(int i=0; i<n; i++) {
       if(vec.at(i)%30==0) d++;
   }

   if(a+d-b-c==0) cout << "APPROVED";
   else cout << "DENIED";
}

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

using ll = long long;

ll ans[90];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ans[0] = 2;
	ans[1] = 1;
	for (int i = 2; i <= 86; i++) {
		ans[i] = ans[i-1] + ans[i-2];
	}
	int n; cin >> n;
	cout << ans[n] << '\n';

	return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
    /* Credits: Thomas Draper */
    if ((first == last) || (first == k) || (last == k))
        return false;
    Iterator itr1 = first;
    Iterator itr2 = last;
    ++itr1;
    if (last == itr1)
        return false;
    itr1 = last;
    --itr1;
    itr1 = k;
    --itr2;
    while (first != itr1){
        if (*--itr1 < *itr2){
            Iterator j = k;
            while (!(*itr1 < *j)) ++j;
            iter_swap(itr1,j);
            ++itr1;
            ++j;
            itr2 = k;
            rotate(itr1,j,last);
            while (last != j){
                ++j;
                ++itr2;
            }
            rotate(k,itr2,last);
            return true;
        }
    }
    rotate(first,k,last);
    return false;
}

void Main(){
    int D; cin >> D;
    VI c(26); REP(i,26) cin >> c[i];
    int s[D][26]; REP(i,D)REP(j,26) cin >> s[i][j];
    VI last(26,0);
    VI ans(D);

    int day = 3;

    REP(i,D){
        int maxscore = -INF, type = -1;

        REP(j,26) if(chmax(maxscore, c[j]*(i+1-last[j]))) type = j;
        last[type] = i+1;
        ans[i] = type+1;
    }

    REP(i,D) cout << ans[i] << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first



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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int x,a,b;
    cin >>x>>a>>b;

    if(a >= b){
        puts("delicious");
    }else if(b-a <= x){
        puts("safe");
    }else{
        puts("dangerous");
    }
    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

#include<vector>

#include<string>

#include<algorithm>

#include<cmath>

#include<cstdlib>

#include<utility> 

#include<cstdio> 

#define vii vector< pair<int,int> >

#define vi vector<int>

#define INF 1000000007

#define ff first

#define ss second

#define lli long long int

#define ulli unsigned long long int

using namespace std;

int main() {

 ios_base::sync_with_stdio(false);

    cin.tie(NULL);

  lli x,k,d;

  cin>>x>>k>>d;

  x=abs(x);

  if(x>0 && (x/d)>=k){

    cout<<abs(x-(k)*d);

  }

  else {

    lli ans=x-(x/d)*d;

    k-=x/d;

    if(k%2==0)

    cout<<ans;

    else cout<<min(abs(ans-d),abs(ans+d));

  }

  cout<<endl;

}

Measured memory_bytes: 3648
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end

p 3*inp[0]**2

Measured memory_bytes: 1788
# tameshi 
n = input()
lis = []
ans = 0
for i in xrange(n):
    com = raw_input()
    if   com[0] == 'i':
        lis.append(com[7:])
    elif com[6] == ' ':
        try:
            lis.pop(~lis[::-1].index(com[7:]))
        except:
            pass
    elif com[6] == 'F':
        lis.pop()
    else:ans += 1
  
print ' '.join( map(str, reversed(lis[ans:])) )

Measured memory_bytes: 61500
import sys

input = sys.stdin.readline

A = []
b = []
B = [[0, 0, 0] for _ in range(3)]

for _ in range(3):
    A.append(list(map(int, input().split())))

N = int(input())

for _ in range(N):
    b.append(int(input()))

for value in b:
    for i in range(3):
        for j in range(3):
            if A[i][j] == value:
                B[i][j] = 1

bingo = False

if B[0][0] == 1:
    if B[0][1] == 1 and B[0][2] == 1:
        bingo = True
    if B[1][0] == 1 and B[2][0] == 1:
        bingo = True
    if B[1][1] == 1 and B[2][2] == 1:
        bingo = True

if B[1][1] == 1:
    if B[1][0] == 1 and B[1][2] == 1:
        bingo = True
    if B[0][1] == 1 and B[2][1] == 1:
        bingo = True
    if B[0][2] == 1 and B[2][0] == 1:
        bingo = True   

if B[2][2] == 1:
    if B[0][2] == 1 and B[1][2] == 1:
        bingo = True
    if B[2][0] == 1 and B[2][1] == 1:
        bingo = True
    
if bingo:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 3064
now_ans = 100000


def kotae(A, a_tree, a_tree_sum):
    ans = (a_tree - 1) * 10 + abs(a_tree_sum - A)
    if a_tree == 0:
        ans = 100000
    return ans

def calc_final(A, B, C, a_tree, b_tree, c_tree, a_tree_sum, b_tree_sum, c_tree_sum):
    global now_ans

    ans = 0
    ans += kotae(A, a_tree, a_tree_sum)
    ans += kotae(B, b_tree, b_tree_sum)
    ans += kotae(C, c_tree, c_tree_sum)
    if ans < now_ans:
        now_ans = ans



def calc_data(tree_data, A, B, C, a_tree, b_tree, c_tree, index, a_tree_sum, b_tree_sum, c_tree_sum ):
    if a_tree_sum >= A and b_tree_sum >= B and c_tree_sum >= C:
        calc_final(A, B, C, a_tree, b_tree, c_tree, a_tree_sum, b_tree_sum, c_tree_sum)
        return
    if index == len(tree_data) - 1:
        calc_final(A, B, C, a_tree, b_tree, c_tree, a_tree_sum, b_tree_sum, c_tree_sum)
        return
    if a_tree_sum < A:
        calc_data(tree_data, A, B, C, a_tree + 1, b_tree, c_tree, index + 1, a_tree_sum + tree_data[index + 1], b_tree_sum, c_tree_sum)
    if b_tree_sum < B:
        calc_data(tree_data, A, B, C, a_tree, b_tree + 1, c_tree, index + 1, a_tree_sum, b_tree_sum + tree_data[index + 1], c_tree_sum)

    if c_tree_sum < C:
        calc_data(tree_data, A, B, C, a_tree, b_tree, c_tree + 1, index + 1, a_tree_sum, b_tree_sum, c_tree_sum + tree_data[index + 1])

    calc_data(tree_data, A, B, C, a_tree, b_tree, c_tree, index + 1, a_tree_sum, b_tree_sum, c_tree_sum)


def main():
    global now_ans
    num, A, B, C = list(map(int, input().split()))
    tree_data = [int(input()) for i in range(num)]
    tree_data.sort(reverse=True)


    calc_data(tree_data, A, B, C, 1, 0, 0, 0, tree_data[0], 0, 0)
    calc_data(tree_data, A, B, C, 0, 1, 0, 0, 0, tree_data[0], 0)
    calc_data(tree_data, A, B, C, 0, 0, 1, 0, 0, 0, tree_data[0])
    calc_data(tree_data, A, B, C, 0, 0, 0, 0, 0, 0, 0)



    print(now_ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

const int mod = 1000000007;

signed main() {
  int N, M; cin >> N >> M;
  vector<bool> t(N, true);
  rep(i, M) {
    int a; cin >> a;
    t[a] = false;
  }
  
  vector<int> dp(N+1, 0);
  dp[0] = 1;
  rep(i, N) {
    if(!t[i]) continue;
    if(t[i+1]) {
      dp[i+1] += dp[i];
      dp[i+1] %= mod;
    }
    if(i < N-1 && t[i+2]) {
      dp[i+2] += dp[i];
      dp[i+2] %= mod;
    }
  }

  cout << dp[N] << endl;

}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

int a[100010];
int main(){
	int n;
	cin>>n;
	
	for (int i = 0; i < n; ++i){
		int x;
		cin>>x;
		if(x==0){
			a[x]++;
			a[x+1]++;
			continue;
		}else{
			a[x]++;
			a[x-1]++;
			a[x+1]++;
		}
	}

	if(n==1){
		cout<<1<<endl;
		return 0;
	}

	sort(a,a+n,greater<int>());

	cout<<a[0]<<endl;


	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
 
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}
 
const ll big=1777777777;
int exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    ll t=exp(x,y/2);
    return (t*t)%big;
}
 
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll in(ll x){
    return exp(x,big-2);
}

bool ok(vector<int> &a,int n){
    rep(i,n-1)if(a[i]>a[i+1])return false;
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
    
    int x,a,b;cin >> x >> a >> b;
    if(b-a<=0)cout << "delicious" << endl;
    else if(b-a<=x)cout << "safe" << endl;
    else cout << "dangerous" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long yy(long long x,long long n)
{
    long long ans;
    if(n%x == 0)
    {
    	 return n*2-x;
	}
    ans = n/x*x*2+yy(n%x,x);
    return ans;
}
int main()
{
    long long n,x;
    long long ans;
    cin>>n>>x;
    ans= yy(x,n-x)+n;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import itertools
n,m,q = map(int, input().split())
qlist = []

for _ in range(q):
    qlist.append(list(map(int,input().split())))

tmplist = list(range(1,m+1))
point = 0

for A in list(itertools.combinations_with_replacement(tmplist, n)):
    pointtmp = 0
    for tmp in qlist:
        if A[tmp[1]-1] - A[tmp[0]-1] == tmp[2]:
            pointtmp += tmp[3]
    if pointtmp > point:
        point = pointtmp

print(point)
            

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

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	lint ans=0;
	rep(i,n+1) if(i%3!=0 && i%5!=0) ans+=i;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3752
from collections import defaultdict

H, W = map(int, input().split())
field = [[c == '#' for c in input()] for _ in range(H)]
counted = [[False] * W for _ in range(H)]
detected = [[False] * W for _ in range(H)]

b_count = defaultdict(int)
w_count = defaultdict(int)
another_group = [(0, 0)]
group = 0
while another_group:
    i, j = another_group.pop()
    detected[i][j] = True
    if counted[i][j]:
        continue
    
    stack = [(i, j)]
    while stack:
        i, j = stack.pop()
        if field[i][j]:
            b_count[group] += 1
        else:
            w_count[group] += 1
        #print(i, j, group)
        counted[i][j] = True
        for di, dj in ((0, 1), (1, 0), (0, -1), (-1, 0)):
            if 0 <= i+di < H and 0 <= j+dj < W:
                if not detected[i+di][j+dj]:
                    if field[i+di][j+dj] == field[i][j]:
                        another_group.append((i+di, j+dj))
                    else:
                        detected[i+di][j+dj] = True
                        stack.append((i+di, j+dj))
                
    group += 1         

ans = 0
for bk, bv in b_count.items():
    ans += bv * w_count[bk]

print(ans)

Measured memory_bytes: 44196
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(ll)(n);++i)
#define _repe3(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define _rrepe2(i,n) for(ll i=(ll)(n);i>=0;i--)
#define _rrepe3(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)
#define rrepe(...) _overload3(__VA_ARGS__,_rrepe3,_rrepe2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll N;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    solve();
}

// 入力はすべて整数である。
// 1 <= N <= 10^{12}

// ll N
// 答えを整数として出力せよ。
void solve(){
    ll ans=0;
    for(ll i=2;i*i<=N;++i){
        if(N%i==0){
            ll cnt=0;
            while(N%i==0){
                ++cnt;
                N/=i;
            }

            ll sub=1;
            while(cnt>0){
                cnt-=sub;
                if(cnt>=0)++ans;
                ++sub;
            }
        }
    }
    if(N>1)++ans;
    cout<<ans<<endl;
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, tmp, count =0, ans=2e9;
    cin >> N;

    for(int i=0; i<N; i++){
	count=0;
	cin >> tmp;
	while(true){
	    if(tmp%2==0){
		count++;
		tmp /=2;
	    }
	    else
		break;
	}
	ans = min(ans, count);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    IOS;
    //ll t;cin>>t;while(t--)
    {
        ll a,b,c,d,i,j,k,l,m,n,sum=0,temp=0,f=0,cnt=0;
        cin>>n;
        if(n>=30)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;

    }
}


Measured memory_bytes: 3644
#include<cstdio>

int main(){
    int n;
    scanf("%d", &n);
    int ans = 0;
    for(int i=0;i<n;i++){
        int x;
        int j = i+1;
        scanf("%d", &x);
        if((j*x)%2 != 0) ans++;
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b, x;
  cin >> a >> b >> x;
  if(a <= x){
    if(x <= a + b){
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}

Measured memory_bytes: 3636
ans=n=int(input())
s=input()
a=[0]
for i in s:
    if i==".":
        a+=[a[-1]+1]
    else:
        a+=[a[-1]]
w=s.count(".")
for i in range(n+1):
    ans=min(ans,i-a[i]+w-a[i])
print(ans)

Measured memory_bytes: 16984
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <string>
using namespace std;
typedef long long ll;

int main(void){
    ll a,b,c,d;
    string num;
    vector<ll> n(4);
    cin >> num;
    a = num[0] - '0';
    b = num[1] - '0';
    c = num[2] - '0';
    d = num[3] - '0';
    bool flag = 0;
    for(ll i = 0;i < 2; i++){
        for(ll j = 0;j < 2; j++){
            for(ll k = 0;k < 2; k++){
                char op1,op2,op3;
                ll tmp = a;
                if(i == 0){
                    tmp += b;
                    op1 = '+';
                }else if(i == 1){
                    tmp -= b;
                    op1 = '-';
                }
                if(j == 0){
                    tmp += c;
                    op2 = '+';
                }else if(j == 1){
                    tmp -= c;
                    op2 = '-';
                }
                if(k == 0){
                    tmp += d;
                    op3 = '+';
                }else if(k == 1){
                    tmp -= d;
                    op3 = '-';
                }
                if(tmp == 7){
                    flag = 1;
                    cout << a << op1 << b << op2 << c << op3 << d << '=' << '7' << endl;
                    break;
                }
                // cout << num[0] << plumi[i] << num[1] << plumi[j] << num[2] << plumi[k] << num[3] << endl;
            }
            if(flag) break;
        }
        if(flag) break;
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	S := ReadString()
	fmt.Println(strings.ReplaceAll(S, ",", " "))
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }

func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include<iostream>
#include<bits/stdc++.h>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <map>
typedef long long ll;
using namespace std;
typedef pair<string,int> PAIR;


int main()
{
	
	ll n,m;
	cin>>n>>m;
	int ans = 0;
	int x = 1;
	while(n>1)
	{
		n/=m;
		ans++;
	}
	if(n==0)
	cout<<ans<<endl;
	else cout<<ans+1<<endl;
	return 0;
 } 

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

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

int H, W;
void dijkstra(int sx, int sy, int gx, int gy, vector<string>& s, vector<vector<int>>& dist) {
  const int inf = 1e9;
  dist = vector<vector<int>>(H, vector<int>(W, inf));
  dist[sy][sx] = 0;
  priority_queue<tuple<int,int,int>> pq;
  pq.emplace(0, sx, sy);
  while (!pq.empty()) {
    int d, x, y;
    tie(d, x, y) = pq.top();pq.pop();
    d = -d;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
      if (s[ny][nx] == '#') continue;
      int nd = d + 1;
      if (dist[ny][nx] > nd) {
        dist[ny][nx] = nd;
        pq.emplace(-nd, nx, ny);
      }
    }
  }
}

int main(void) {
  cin >> H >> W;
  vector<string> s(H);
  int cnt = 0;
  for (int i = 0; i < H; i++) {
    cin >> s[i];
    for (int j = 0; j < W; j++) {
      if (s[i][j] == '.') cnt++;
    }
  }
  vector<vector<int>> dist;
  dijkstra(0, 0, W-1, H-1, s, dist);
  if (dist[H-1][W-1] == 1e9) cout << -1 << endl;
  else cout << cnt - (dist[H-1][W-1] + 1) << endl;

  return 0;
}

Measured memory_bytes: 256