akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        map<int, int> cnt;
        for(int i = 2; i * i <= n; i++){
            while(n % i == 0){
                cnt[i]++;
                n /= i;
            }
        }
        if(n > 1){
            cnt[n]++;
        }
        int ans = 0;
        for(auto &it : cnt){
            int val = 1;
            while(it.ss >= val){
                ans++;
                it.ss -= val;
                val++;
            }
        }
        cout << ans << '\n';
    }
}

Measured memory_bytes: 34616
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main{
	static int max = 2000000;
	static boolean[] isPrime = new boolean[max];
	public static void main(String[] args) {
		aryPrime();
		List<Integer> list = new ArrayList<Integer>();
		for(int i = 2; i < max; i++) {
			if(isPrime[i]) {
				list.add(i);
			}
		}
		long[] a = new long[list.size() + 1];
		for(int i = 0; i < list.size(); i++) {
			a[i + 1] = a[i] + list.get(i);
		}
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n = sc.nextInt();
			if(n == 0) break;
			System.out.println(a[n]);
		}
		sc.close();
	}
	static void aryPrime(){
        int l = isPrime.length;
        Arrays.fill(isPrime, true);
        isPrime[0] = false;
        isPrime[1] = false;
        for(int i = 2; i <= (int)Math.sqrt(l); i++) {
            if(isPrime[i]) {
                for(int j = i * 2; j < l; j += i) {
                    isPrime[j] = false;
                }
            }
        }
    }
}


Measured memory_bytes: 34376
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;

static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;

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

    LL n, m;
    cin >> n >> m;

    if( n - m > 1 || m - n > 1 ) cout << 0 << endl;
    else {
        LL dog = 1, monkey = 1;
        for( int i = 2; i <= n; ++i ) {
            dog = ( dog * i ) % MOD;

        }

        for( int i = 2; i <= m; ++i ) {
            monkey = ( monkey * i ) % MOD;

        }
        if( n == m ) cout << ( dog * monkey * 2 ) % MOD << endl;
        else cout << ( dog * monkey ) % MOD << endl;

    }

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a,b,i,ans;
	
	for(i=0;i<7;i++){
		scanf("%d %d",&a,&b);
		ans=a-b;
		printf("%d\n",ans);
	}
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, M;
ll AC[100100];
ll WA[100100];

void solve() {
    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        ll p;
        string re;
        cin >> p >> re;
        if (re == "AC") {
            AC[p] = 1;
        } else {
            if (AC[p] != 1) {
                WA[p] += 1;
            }
        }
    }
    ll ac = 0;
    ll wa = 0;
    for (int i = 1; i <= N; ++i) {
        ac += AC[i];
        if (AC[i] == 1) wa += WA[i];
    }
    printf("%ld %ld\n", ac, wa);
}

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


Measured memory_bytes: 1664
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int check(int,int,int);
int a[100][100];
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int n;
int main(void)
{
	int i,j,k,deg,dd,cnt,x,y,xx,yy,d;
	int flg;
	scanf("%d",&d);
	for(k=0;k<d;k++)	{
		if(k!=0)	printf("\n");
		scanf("%d",&n);
		for(i=0;i<n;i++)	{
			for(j=0;j<n;j++)	{
				a[i][j]=0;
			}
		}
		y=n-1;	x=0;	deg=0;
		a[y][x]=1;
		flg=1;
		while(flg==1)	{
			if(check(x,y,deg)==0)	{
				dd=(deg+1)%4;
				if(check(x,y,dd)==0)	{
					flg=0;
					break;
				}
				else {
					deg=dd;
					x=x+dx[deg];	y=y+dy[deg];
					a[y][x]=1;
				}
			}
			else {
				x=x+dx[deg];	y=y+dy[deg];
				a[y][x]=1;		
			}
		}
		for(i=0;i<n;i++)	{
			for(j=0;j<n;j++)	{
				if(a[i][j]==1)	{
					printf("#");
				}
				else {
					printf(" ");
				}
			}
			printf("\n");
		}
	}
	return 0;
}
int check(int x,int y,int d1)
{
	int xx,yy,flg,i,j,dd,x2,y2;
	xx=x+dx[d1];	yy=y+dy[d1];
	if(xx<0 || xx>=n || yy<0 || yy>=n)	{
		return 0;
	}
	x2=xx+dx[d1];	y2=yy+dy[d1];
	if(x2>=0 && x2<n && y2>=0 && y2<n && a[y2][x2]==1)	{
		return 0;
	}
	dd=(d1+1)%4;
	x2=xx+dx[dd];	y2=yy+dy[dd];
	if(x2>=0 && x2<n && y2>=0 && y2<n && a[y2][x2]==1)	{
		return 0;
	}	
	return 1;
}


Measured memory_bytes: 1032
def main():
	linie = input()
	vector = [int(x) for x in linie.split()]	
	if vector[0] + vector[1] > vector[2] + vector[3]:
		print("Left")
	if vector[0] + vector[1] == vector[2] + vector[3]:
		print("Balanced")
	if vector[0] + vector[1] < vector[2] + vector[3]:
		print("Right")
 
 
if __name__ == "__main__":
	main()

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
using namespace std;
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	long long N, M;
	scanf("%lld %lld", &N, &M);
	long long A[N];
	for (int i = 0; i < N; ++i) scanf("%lld", &A[i]);
	long long lcm = 1;
	for (int i = 0; i < N; ++i) {
		lcm = lcm * A[i] / 2 / gcd(lcm, A[i] / 2);
		if (lcm > M) {
			printf("0");
			return 0;
		}
	}
	for (int i = 0; i < N; ++i) {
		if (lcm % A[i] == 0) {
			printf("0");
			return 0;
		}
	}
	printf("%lld", (M / lcm + 1) / 2);
	return 0;
}

Measured memory_bytes: 896
// Contest No.: ABC175
// Problem No.: B
// Solver:      Jinmin Goh
// Date:        20200815

#include <cstring>
#include <iostream>
#include <cstdlib>
#include <list>
#include <array>
#include <atomic>
#include <algorithm>
#include <deque>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int nums[110];
map<int, int> mappingList;
vector<int> uniqueList;

int main() {
    int n;
    scanf("%d", &n);
    if(n < 3) {
        printf("0");
        return 0;
    }
    for(int i = 0; i < n; i++) {
        scanf("%d", &nums[i]);
    }
    //sort(nums, nums + n);

    

    int ans = 0;
    for(int i = 0; i < n - 2; i++) {
	    for(int j = i + 1; j < n - 1; j++) {
            for(int k = j + 1; k < n; k++) {
                if((nums[i] != nums[j]) && (nums[k] != nums[j]) && (nums[i] != nums[k]) && (nums[i] + nums[j] > nums[k]) && (nums[i] + nums[k] > nums[j]) && (nums[k] + nums[j] > nums[i])) {
                    ans++;
                }
            }
        }
    }

    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
bool comp(int a,int b){
return a>b;
}
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main()
{
	fast;
	string s1,s2; 		
	cin>>s1>>s2;
	
	ll l1,l2;
	l1=s1.length();
	l2=s2.length();
  vector<vector<int>> dp(3010, vector<int>(3010,0));
//	memset(dp,0,sizeof(dp));
	rep(i,0,l1+1)
	{
		rep(j,0,l2+1)
		{
			if(i==0||j==0)
			{
				dp[i][j]=0;
			//	continue;
			}
			else if(s1[i-1]==s2[j-1])
			{
				dp[i][j]=1+dp[i-1][j-1];
			//	continue;
			}
			else
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			
			
			
		//	cout<<dp[i][j]<<" ";
		}
	//	cout<<endl;
				
		
	}
    ll i=l1,j=l2;
    vector<char>c;
    
    while(i>0 && j>0)
    {
    	if(dp[i][j]==dp[i-1][j])
    	{
    		i--;
		}
		else if(dp[i][j]==dp[i][j-1])
		{
			j--;
		}
		else if(dp[i][j]!=dp[i-1][j-1])
		{
                      //  cout<<s1[i-1];

			c.push_back(s1[i-1]);
			i--;
			j--;
		}

		
	}
    //cout<<endl;
	reverse(c.begin(),c.end());
	for(auto x:c)
	cout<<x;
	 
	
	
	
	
	



}



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

import static java.lang.Integer.parseInt;

/**
 * Check answers
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int N = parseInt(br.readLine());
		String S = br.readLine();

		int ans = S.indexOf("xx") + 1;
		System.out.println(ans > 0 ? ans : N);
	}
}

Measured memory_bytes: 26836
K,N = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
sa = 0
for i in range(N-1):
  if sa < a[i+1]-a[i]:
    sa = a[i+1]-a[i]
last = a[0] + (K -a[-1])
if last > sa:
  sa = last
print(K - sa)

Measured memory_bytes: 26420
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i * i <= n; i++) {
		if (n % i)continue;
		if (i + 1 < n / i)ans += n / i - 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>

#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define abs(a) (((a) < 0) ? -(a) : (a))

#define FOR(var, to)          for (register int var = 0; var < to; var++)
#define FROMTO(var, from, to) for (register int var = from; var <= to; var++)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static inline int ri() {
	int a;
	scanf("%d", &a);
	return a;
}

static inline s64 rs64() {
	s64 a;
	scanf("%" SCNd64, &a);
	return a;
}

static inline void wi(int a) {
	printf("%d", a);
}

static inline void wu64(u64 a) {
	printf("%" PRIu64, a);
}

int main() {
	char s[5];
	scanf("%s", s);
	
	int res = 0;
	for (int i = 0; i < 4; i++) {
		if (s[i] == '+') res++;
		else res--;
	}
	
	wi(res);
	
	return 0;
}


Measured memory_bytes: 128
// 2011/07/12 Tazoe

#include <iostream>
#include <string>
using namespace std;

int trn(char rom)
{
	switch(rom){
		case 'I':
			return 1;
		case 'V':
			return 5;
		case 'X':
			return 10;
		case 'L':
			return 50;
		case 'C':
			return 100;
		case 'D':
			return 500;
		case 'M':
			return 1000;
	}

	return 0;
}

int main()
{
	while(true){
		string str;
		cin >> str;
		if(cin.eof())
			break;

		int sum = 0;
		for(int i=0; i<str.size()-1; i++)
			if(trn(str[i])>=trn(str[i+1]))
				sum += trn(str[i]);
			else
				sum -= trn(str[i]);
		sum += trn(str[str.size()-1]);

		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 0
import sys
import heapq


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    x, y, a, b, c = list(map(int, readline().split()))
    p = list(map(int, readline().split()))
    q = list(map(int, readline().split()))
    r = [-1 * i for i in list(map(int, readline().split()))]
    p.sort(reverse=True)
    q.sort(reverse=True)
    hq = p[:x] + q[:y]
    heapq.heapify(hq)
    heapq.heapify(r)
    while len(r):
        hqv = heapq.heappop(hq)
        rv = -heapq.heappop(r)
        if rv > hqv:
            heapq.heappush(hq, rv)
        else:
            heapq.heappush(hq, hqv)
            break
    print(sum(hq))


if __name__ == '__main__':
    solve()


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

typedef long long ll;
const int maxo = 1201;
const ll inf = std::numeric_limits<ll>::max();

std::map<ll, ll> p;

ll n, a, b, c, d;

ll cd(ll u, ll v) {
    return u / v + bool(u % v);
}

ll dm[3][2];

ll dfs(ll v) {
    if(v <= 0)
        return 0;
    if(v == 1)
        return d;
    if(p.find(v) != p.end())
        return p[v];
    ll r = inf;
    if(v <= inf / d)
        r = d * v;
    for(auto &&[x, y] : dm) {
        r = std::min({
            r,
            dfs(v / x) + y + std::abs(v - v / x * x) * d,
            dfs(cd(v, x)) + y + std::abs(v - cd(v, x) * x) * d
        });
    }
    p[v] = r;
    return r;
}

int main() {
    dm[0][0] = 2;
    dm[1][0] = 3;
    dm[2][0] = 5;
    int t;
    scanf("%d", &t);
    while(t--) {
        scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
        p.clear();
        dm[0][1] = a;
        dm[1][1] = b;
        dm[2][1] = c;
        printf("%lld\n", dfs(n));
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

ll n;
vector <ll> v(20);

bool solve(ll i, ll m) {
  if (m == 0) {
    return true;
  }
  if (i >= n) {
    return false;
  }
  bool res = solve(i+1, m) || solve(i+1, m-v.at(i));
  return res;
}

int main() {
  cin >> n;
  rep(i, n) cin >> v.at(i);
  ll m;
  cin >> m;
  rep(i, m) {
    ll tmp;
    cin >> tmp;
    if (solve(0, tmp)) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}


Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int m = (n+1)/2;
        if(m>=k) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* liblary */

/* main */

signed main() {
    ll P, Q, R;
    cin >> P >> Q >> R;
    cout << P + Q + R - max({P, Q, R}) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }

inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }



int main()
{
    // int t;
    // cin >> t;
    // while(t--)
    // {
    // }
    char a[100],b[100],c[100];
    cin >>a>>b;
    int flag=0;
    if(strlen(a)!=strlen(b)-1)
        {
            printf("No\n");
        }
    else{
    for(int i=0;i<strlen(a);i++)
    {
        if(a[i]!=b[i])
            flag=1;

    }
    if(flag==0)
        printf("Yes\n");
    else 
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 3620
def a_01matrix():
    H, W, A, B = [int(i) for i in input().split()]
    ans = [[int(not(row < B))] * A + [int(row < B)] * (W - A) for row in range(H)]
    return '\n'.join(''.join(map(str, row)) for row in ans)
    """
    左上 BxA マスと右下 (H-B)x(W-A) マスを0とし、残りを1とする。
    すると、W-A>=A なので、上からB行は0の数がA個、残りの行は1の数がA個となる。
    列についても同様のことが言え、結局、上のやり方で必ず条件を満たせる。
    """

print(a_01matrix())

Measured memory_bytes: 12916
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())
using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n], b[n], c[n-1];
    REP(i, n){
        cin >> a[i];
        a[i]--;
    }
    REP(i, n) cin >> b[i];
    REP(i, n-1) cin >> c[i];

    int result = b[a[0]];

    for(int i=1; i<n; i++){
        result += b[a[i]];
        if(a[i]-a[i-1]==1){
            result += c[a[i-1]];
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
 
using namespace std;
 
int main() {
  map<int,int> mymap;
  int n;
  cin>>n;
  int tmp;
  int maxn = 1;
  for (int i = 0; i < n; i++) {
    cin>>tmp;
    mymap[tmp]++;
  }
 
  for (auto m : mymap) {
    int num = m.first;
    int res = m.second;
    if (mymap.find(num + 1) != mymap.end()) {res += mymap[num + 1];}
    if (mymap.find(num + 2) != mymap.end()) {res += mymap[num + 2];}
    maxn = max(res,maxn);
  }
  cout<<maxn;
  return 0;
}

Measured memory_bytes: 3200
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N, M;

int main() {
    string S;
    cin >> N;
    cin >> S;
    M = count(S.cbegin(), S.cend(), 'R');

    if (2 * M > N) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    H,W,h,w = LI()
    f = False
    if H % h == 0 and W % w == 0:
        return 'No'
    if W % w == 0:
        H,W,h,w = W,H,w,h
        f = True

    p = 10**6*(w-1) - 1
    m = -(10**6)
    a = []
    for i in range(W):
        if i % w == 0:
            a.append(p)
        else:
            a.append(m)
    aa = [a] * H
    r = aa
    if f:
        r = [[aa[i][j] for i in range(H)] for j in range(W)]

    return 'Yes\n' + '\n'.join(' '.join(map(str,t)) for t in r)


print(main())


Measured memory_bytes: 12148
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        boolean f = false;
        for(int i=A; i<=B; i++) {
            if(i%K == 0) {
                f = true;
                break;
            }
        }
        if(f == true) System.out.println("OK");
		else System.out.println("NG");

		
	}
}

Measured memory_bytes: 35904
import math
a,r=map(int,input().split())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

ans=Base_10_to_n(a,r)
print(len(ans))

Measured memory_bytes: 38384
// template {{{
#![allow(clippy::many_single_char_names)]

#[allow(dead_code)]
mod ngtio {
    use ::std::collections::VecDeque;

    pub struct Buffer {
        buf: VecDeque<String>,
    }

    impl Buffer {
        pub fn new() -> Self {
            Self {
                buf: VecDeque::new(),
            }
        }

        fn load(&mut self) {
            while self.buf.is_empty() {
                let mut s = String::new();
                let length = ::std::io::stdin().read_line(&mut s).unwrap();
                if length == 0 {
                    break;
                }
                self.buf.extend(s.split_whitespace().map(|s| s.to_owned()));
            }
        }

        pub fn string(&mut self) -> String {
            self.load();
            self.buf
                .pop_front()
                .unwrap_or_else(|| panic!("入力が終了したのですが。"))
        }

        pub fn string_char_vec(&mut self) -> Vec<char> {
            let s = self.string();
            s.chars().collect::<Vec<_>>()
        }

        pub fn string_char_vec_trusted_len(&mut self, len: usize) -> Vec<char> {
            let s = self.string();
            let s = s.chars().collect::<Vec<_>>();
            assert_eq!(s.len(), len, "あら、思ったのと長さ違いますね……");
            s
        }

        pub fn char(&mut self) -> char {
            let string = self.string();
            let mut chars = string.chars();
            let res = chars.next().unwrap();
            assert!(
                chars.next().is_none(),
                "char で受け取りたいのも山々なのですが、さては 2 文字以上ありますね？"
            );
            res
        }

        pub fn read<T: ::std::str::FromStr>(&mut self) -> T
        where
            <T as ::std::str::FromStr>::Err: ::std::fmt::Debug,
        {
            self.string()
                .parse::<T>()
                .expect("Failed to parse the input.")
        }

        pub fn read_vec<T: ::std::str::FromStr>(&mut self, len: usize) -> Vec<T>
        where
            <T as ::std::str::FromStr>::Err: ::std::fmt::Debug,
        {
            (0..len).map(|_| self.read::<T>()).collect()
        }
    }

    macro_rules! define_primitive_reader {
        ($($ty:tt,)*) => {
            impl Buffer {
                $(
#[inline]
                    pub fn $ty(&mut self) -> $ty {
                        self.read::<$ty>()
                    }
                )*
            }
        }
    }

    define_primitive_reader! {
        u8, u16, u32, u64, usize,
        i8, i16, i32, i64, isize,
    }

    impl Default for Buffer {
        fn default() -> Self {
            Self::new()
        }
    }
}

#[allow(unused_imports)]
use std::{collections, iter, mem, ops};
// }}}

fn main() {
    let mut buf = ngtio::Buffer::new();
    let n = buf.usize();
    let ans = iter::repeat_with(|| buf.u32() == buf.u32())
        .take(n)
        .collect::<Vec<_>>()
        .windows(3)
        .find(|v| v[0] && v[1] && v[2])
        .is_some();
    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();

    int takahashiKaisu = c / b;
    if (c % b != 0) {
      takahashiKaisu++;
    }

    int aokiKaisu = a / d;
    if (a % d != 0) {
      aokiKaisu++;
    }

    System.out.println(takahashiKaisu <= aokiKaisu ? "Yes" : "No");

  }
}


Measured memory_bytes: 27088
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ar[] = new int[3];
		for (int i = 0; i < ar.length; i++) {
			ar[i] = sc.nextInt();
		}

		int min = 1000000000;
		int max = -1000000000;

		for (int i = 0; i < ar.length; i++) {
			if (ar[i] > max) {
				max=ar[i];
			}
			if (ar[i] < min) {
				min=ar[i];
			}

		}
		System.out.println(min+" "+max);

	}
}



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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 100*1000 + 10;
const ll inf = 1e18;


int n, cap;


void relax(ll& x, ll y) {
    x=min(x,y);
}

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

    vector<ll> dp(maxn, inf);//min weight to achieve i value
    dp[0]=0;


    cin>>n>>cap;
	
    while (n--) {
	ll wei, val; cin>>wei>>val;
	for (int i=maxn-1; i>=0; i--) {
	    if (dp[i]==inf) {
		continue;//impossible to achieve value=i
	    }
	    if (i+val<maxn) {
		relax(dp[i+val], dp[i]+wei);
	    }
	}
    }


    ll res=0;
    for (int i=0; i<maxn; i++) {
	if (dp[i]<=cap) {
	    res=i;
	}
    }

    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>

#define ll long long
#define mem(a) (memset(a,0,sizeof(a)))
const int maxn=100+5;

using namespace std;


int main() {
    char a[maxn],b[maxn],c[maxn];
    int pa=0,pb=0,pc=0;
    char turn = 'a';
    char ans;
    scanf("%s",a);
    scanf("%s",b);
    scanf("%s",c);
    while (true){
        switch (turn) {
            case 'a':
                if(pa==strlen(a)){
                    ans='A';
                    goto out;
                }
                turn = a[pa];
                pa++;
                break;
            case 'b':
                if(pb==strlen(b)){
                    ans='B';
                    goto out;
                }
                turn = b[pb];
                pb++;
                break;
            case 'c':
                if(pc==strlen(c)){
                    ans='C';
                    goto out;
                }
                turn = c[pc];
                pc++;
                break;
        }
    }
    out:printf("%c\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define all(x) (x).begin(),(x).end()

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

typedef long long ll;

using namespace std;

const int MAX_N = 100000;
int N;
int A[MAX_N];
map<int, int> mp;

int solve(){
    int answer = 0;
    int evenCnt = 0;
    REP(i,N) {
        if(A[i] == 0) mp[A[i]] = 1;
        else mp[A[i]] += 1;
    }
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        if(itr->second % 2 == 0){
            evenCnt += 1;
        }
        answer += 1;
    }
    return answer - evenCnt % 2;
}

int main() {
    // to shorten execution time for iostream
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    REP(i, N) cin >> A[i];
    cout << solve() << "\n";
    return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<vector<int>> c(3,vector<int>(3));
  for (int i=0; i<3; i++){
    for (int j=0; j<3; j++) cin >> c.at(i).at(j);
  }
  int x0 ,x1, y0, y1;
    x0=c.at(0).at(0) - c.at(0).at(1) ;
    x1=c.at(0).at(1) - c.at(0).at(2) ;
    y0=c.at(0).at(0) - c.at(1).at(0) ;
    y1=c.at(1).at(0) - c.at(2).at(0) ;   
    
    if(c.at(1).at(0) - c.at(1).at(1) == x0 &&\
       c.at(1).at(1) - c.at(1).at(2) == x1 &&\
       c.at(2).at(0) - c.at(2).at(1) == x0 &&\
       c.at(2).at(1) - c.at(2).at(2) == x1 &&\
       c.at(0).at(1) - c.at(1).at(1) == y0 &&\
       c.at(1).at(1) - c.at(2).at(1) == y1 &&\
       c.at(0).at(2) - c.at(1).at(2) == y0 &&\
       c.at(1).at(2) - c.at(2).at(2) == y1){
     cout << "Yes" << endl;
    }
    else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int A, B, x, y;
char s[105][105];
bool flag;
int main()
{
	scanf("%d%d", &A, &B);
	printf("100 100\n");
	if (A < B)
	{
		swap(A, B);
		flag = true;
	}
	else flag = false;
	B--;
	for (int i = 0; i < 100; i++)
		for (int j = 0; j < 100; j++)
			s[i][j] = '#';
	x = 0, y = 0;
	while (B)
	{
		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++)
				s[x + i][y + j] = '.';
		s[x + 1][y + 1] = '#';
		y += 4;
		if (y >= 100) x += 4, y = 0;
		A--, B--;
	}
	while (A)
	{
		s[x][y] = '.';
		y += 4;
		if (y >= 100) x += 4, y = 0;
		A--;
	}
	if (flag)
	{
		for (int i = 0; i < 100; i++)
			for (int j = 0; j < 100; j++)
				s[i][j] = (s[i][j] == '#'? '.' : '#');
	}
	for (int i = 0; i < 100; i++) puts(s[i]);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int y = sc.nextInt();
    for(int i = 0; i <= n; i++) {
      for(int j = 0; j <= n - i; j++) {
        int k = n - i - j;
        if(i * 10000 + j * 5000 + k * 1000 == y) {
          System.out.println(i + " " + j + " " + k);
          return;
        }
      }
    }
    System.out.println("-1 -1 -1");
  }
}

Measured memory_bytes: 23636
import java.util.Scanner;

 class Main{

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int input = scanner.nextInt();
		if (input >= 0 && input <= 86400) {
			int h = input / 3600;
			int m = (input%3600)/60;
			int s = (input%3600)%60;
			System.out.println(h + ":" + m + ":" + s);
		}
	}
}



Measured memory_bytes: 26140
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007 //1000000000000000003
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int X,A,B;

  cin>>X>>A>>B;

  if(A>=B){
    cout<< "delicious" <<"\n";
    return;
  }
  cout<< ( B-A>X ? "dangerous" : "safe" )<<"\n";

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


Measured memory_bytes: 256
acdic = {"S":[0]*13,"H":[0]*13,"C":[0]*13,"D":[0]*13}
n = int(input())
marklist = ["S","H","C","D"]
for i in range(n):
    m,l=input().split() 
    acdic[m][int(l)-1] = 1

for _ in marklist:
    for i in range(13):
        if acdic[_][i] == 0:
            print(_ + " "+ str(i+1))


Measured memory_bytes: 5600
#include <iostream>

u_int getArea(u_int d){
  u_int area = 0;
  for(u_int i = d; i <= 600 - d; i += d)
    area += i * i * d;
  return area;
}


int main(){
  u_int d;

  while(std::cin >> d)
    std::cout << getArea(d) << std::endl;

  return 0;
}

Measured memory_bytes: 1148
#include <iostream>
#include <cstdio>
using namespace std;
/*
void data(int l[], double d_sum[]) {
  puts("===== data =======");
  puts("l\td_sum");
  for(int j = 0; j < 10; ++j) {
	printf("%d\t%lf\n", l[j], d_sum[j]);
  }
  puts("==================");
}
*/
int main() {
  int l[10];
  double d_sum[10];
  int v1, v2;
  double time, d_train1;
  
  while(~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1, &v2)) {
	for(int i = 0; i < 10; ++i) {
	  if(i == 0) d_sum[i] = l[i];
	  else d_sum[i] = d_sum[i - 1] + l[i];
	}

	//data(l, d_sum);
	
	time = d_sum[9] / (double)(v1 + v2);
	d_train1 = v1 * time;

	for(int j = 0; j < 10; ++j) {
	  if(d_train1 <= d_sum[j]) {
		printf("%d\n", j + 1);
		break;
	  }
	}

	l[10] = {};
	d_sum[10] = {};
  }
  return 0;
}

Measured memory_bytes: 3156
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


void warshallFloyd(int N,vector<vector<ll>> &dist){
	rep(k,N)rep(i,N){
		if(dist[i][k] == LINF) continue;
		rep(j,N){
			if(dist[k][j] == LINF) continue;
            if(dist[i][j] > dist[i][k]+dist[k][j]){
                dist[i][j] = dist[i][k] + dist[k][j];
            }
		}
	}
}


int main(){
    int N,M,L; cin >> N >> M >> L;
    vector<vector<ll>> dist(N,vector<ll>(N,LINF));
    rep(i,N)rep(j,N) if(i == j) dist[i][j] = 0;
    rep(i,M){
        int A,B; cin >> A >> B;
        A--; B--;
        ll C; cin >> C;
        dist[A][B] = C;
        dist[B][A] = C;
    }

    warshallFloyd(N,dist);
    vector<vector<ll>> dist2(N,vector<ll>(N,LINF));
    rep(i,N)rep(j,N) if(i == j) dist2[i][j] = 0;
    rep(i,N)rep(j,N){
        if(i != j){
            if(dist[i][j] <= L) dist2[i][j] = 1;
        }
    }
    warshallFloyd(N,dist2);
    int Q; cin >> Q;
    while(Q--){
        int s,t; cin >> s >> t;
        s--; t--;
        if(dist2[s][t] == LINF){
            cout << -1 << "\n";
            continue;
        }
        cout << dist2[s][t]-1 << "\n";
    }
}
   


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
#define fr(x,a,b,c) for(int x = a; x <= b; x+=c)
using namespace std;
ll powmod(ll base,ll exponent,ll mod){
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
int arr[upperlimit];
int dp[upperlimit];
int main() {
	int n;
	sd(n);
	for(int i = 1; i <= n; i++){
		sd(arr[i]);
	}
	dp[1]=0;
	dp[2]=abs(arr[2]-arr[1]);
	for(int i = 3; i <= n; i++){
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	pd(dp[n]);
	return 0;
}

Measured memory_bytes: 4736
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

#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(a) (a).begin(), (a).end()

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    cout << ((a * b % 2 == 1) ? "Odd" : "Even") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int x,y;
    while (true){
        cin >> x >> y;
        if ((x==0) && (y==0)) break;
        if (x<=y) {
            cout << x << " " << y << "\n";
        } else cout << y << " " << x << "\n";
    }
    return 0;
}


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

struct Doll{
  int h,r;
  Doll(int a,int b){h=a;r=b;};
};

int n;
int h,r;
int m;
vector<Doll>doll;
int memo[201]={0};

bool comp(Doll a, Doll b){return a.h<b.h && a.r<b.r;};

int rec(int id)
{
  if(memo[id]!=0)return memo[id];

  int ans=0;
  for(int i=0;i<n+m;i++){
    if(comp(doll[i],doll[id]))ans=max(rec(i)+1,ans);
  }

  return memo[id]=ans;
}

int main()
{
  while(cin>>n,n){
    doll.clear();
    for(int i=0;i<200;i++)memo[i]=0;

    for(int i=0;i<n;i++){
      cin>>h>>r;
      doll.push_back(Doll(h,r));
    }
    cin>>m;
    for(int i=0;i<m;i++){
      cin>>h>>r;
      doll.push_back(Doll(h,r));
    }

    doll.push_back(Doll(1001,1001));

    cout<<rec(n+m)<<endl;
  }
}

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

int main(){
    string S;
    cin >> S;
    int ans = S.size()/2;
    for(int i=0; i<S.size()/2; i++){
        if(S[i] == S[S.size()-i-1]) ans -= 1;
    }
    cout << ans << endl;
}

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

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

    let answer = solve(&buf);

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

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

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let s: String = iterator.next().unwrap().to_string();

    let x: Vec<isize> = s.chars().map(|c| c.to_digit(10).unwrap() as isize).collect();
    let pc: isize = x.iter().sum();

    let mut ans: Vec<isize> = vec![0; n];
    for b in 0..2 {
        let npc = if b == 0 {
            pc + 1
        } else {
            pc - 1
        };

        if npc <= 0 {
            continue;
        }

        let mut r0: isize = 0;
        for i in 0..n {
            r0 = (r0 * 2) % npc;
            r0 += x[i];
        }

        let mut k: isize = 1;
        for i in (0..n).rev() {
            if x[i] == b {
                let mut r = r0;
                if b == 0 {
                    r = (r + k) % npc;
                } else {
                    r = (r - k + npc) % npc;
                }
                ans[i] = f(r) + 1;
            }
            k = (k * 2) % npc;
        }
    }

    let mut result = String::new();
    for i in 0..n {
        result.push_str(&format!("{}\n", ans[i]));
    }
    result.trim().to_string()
}

fn f(x: isize) -> isize {
    if x == 0 {
        return 0;
    }
    return f(x % pcnt(x)) + 1;
}

fn pcnt(mut x: isize) -> isize {
    let mut cnt = 0;
    while x > 0 {
        if x % 2 == 1 {
            cnt += 1;
        }
        x /= 2;
    }
    return cnt;
}


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

using ll = long long;
using db = double;
using pll = pair < ll, ll >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: 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...);
}
#else
#define trace(...)
#endif

#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;

int main(){
	ll n, k; cin >> n >> k;
	set<int>st;
	for(ll i = 0; i < k; i++) {
		ll d; cin >> d;
		while(d--){
			ll a; cin >> a;
			st.insert(a);
		}
	}
	cout << n - st.size() << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

template<const char ch, class T>
std::vector<T> FWHT(std::vector<T> a, const bool inv = false) {
	int n = (int) a.size();
	for(int len = 1; len < n; len += len) {
		for(int i = 0; i < n; i += 2 * len) {
			for(int j = 0; j < len; j++) {
				auto u = a[i + j], v = a[i + j + len];
				if(ch == '^') {
					a[i + j] = u + v;
					a[i + j + len] = u - v;
				}
				if(ch == '|') {
					if(!inv) {
						a[i + j + len] += a[i + j];
					} else {
						a[i + j + len] -= a[i + j];
					}
				}
				if(ch == '&') {
					if(!inv) {
						a[i + j] += a[i + j + len];
					} else {
						a[i + j] -= a[i + j + len];
					}
				}
			}
		}
	}
	if(ch == '^' && inv) {
		for(int i = 0; i < n; i++) {
			a[i] = a[i] / n;
		}
	}
	return a;
}

long long comb[55][55], val[55];

long long solve(const std::vector<int> &a, int k, int B) {
	int n = (int) a.size();
	for(int i = 0; i <= n; i++) {
		comb[i][0] = 1;
		for(int j = 1; j <= i; j++) {
			comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
		}
	}
	k = std::min(k, n);
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j < k; j++) {
			val[i] += comb[i][j];
		}
	}
	long long ans = 0;
	std::vector<long long> wtf;
	for(int f = 0; f < n; f++) {
		wtf.assign(1 << B, 0);
		for(int i = f+1; i < n; i++) {
			wtf[a[i] ^ a[f]]++;
		}
		wtf = FWHT<'|'>(wtf);
		for(auto &x : wtf) x = val[x];
		wtf = FWHT<'|'>(wtf, true);
		ans += wtf.back();
	}
	return ans;
}

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n, k, s, t;
	std::cin >> n >> k >> s >> t;
	if((s & t) != s) {
		std::cout << "0\n";
		return 0;
	}
	std::vector<int> a;
	int BITS = 0;
	{
		std::vector<int> bits;
		for(int i = 0; i < 20; i++) {
			int bA = (s >> i) & 1;
			int bO = (t >> i) & 1;
			assert(bO >= bA);
			if(bA != bO) {
				bits.push_back(i);
			}
		}
		BITS = (int) bits.size();
		while(n--) {
			int x;
			std::cin >> x;
			if((x & s) != s) continue;
			if((x & t) != x) continue;
			a.push_back(0);
			int lul = 0;
			for(auto pos : bits) {
				if((x >> pos) & 1) {
					a.back() |= 1 << lul;
				}
				lul++;
			}
		}
	}
	std::cout << solve(a, k, BITS) << '\n';
}

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


int main() {
  ll n;
  cin >> n;
  map<ll,ll> rec;
  vector<ll> c(n);
  vector<ll> v(0);
    
  for(long long i = 0; i < n; i++){
    cin >> c[i];
  }
  
 for(long long i = 0; i < n; i++){
    if(rec.count(c[i])){
      rec.at(c[i]) = rec.at(c[i]) + 1;
      if(rec.at(c[i]) == 2){
        v.push_back(c[i]);
      }
      if(rec.at(c[i]) == 4){
        v.push_back(c[i]);
      }
    }
    else{
      rec[c[i]] = 1;
    }
  }
 
  if(v.size() == 0 || v.size() == 1){
    cout << 0;
    return 0;
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
    cout << v[0] * v[1];
    
    
    
  return 0;
}

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

const int maxn = 1000000 + 5;
int n;
int mem[1000+5];

void Print()
{
    cout << "show" << endl;
    for(int i = 0; i < n; i++)
    {
        printf("%d ", mem[i]);
    }
    printf("\n");
}
int main()
{
    while(1)
    {
        scanf("%d", &n);
        if(!n) break;
        memset(mem, 0, sizeof(mem));
        for(int i = 0; i < n; i++)
        {
            scanf("%d", &mem[i]);
        }

        sort(mem, mem+n); //Print();
        int m = maxn;
        int d;
        for(int i = 0; i < n-1; i++)
        {
            d = mem[i+1]-mem[i];
            if(d < m) m = d;
        }

        cout << m << endl;
    }
}



Measured memory_bytes: 3236
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type Abbreviation ---------- */
using ll = long long;

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */
template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

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

    ll a[N];
    ll b[N];

    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
    }

    ll bsum = 0;
    ll bnum = 0;
    ll amax = -1;

    for (ll i = 0; i < N; i++) {
        amax = max(amax, a[i]);
    }

    for (ll i = 0; i < N; i++) {
        if (b[i] > amax) {
            bsum += b[i];
            bnum++;
        }
    }

    ll ret = 0;
    if (H > bsum) {
        ret += ceil(1.0 * (H - bsum) / amax);
        ret += bnum;
    } else {
        sort(b, b + N, greater<int>());
        ll sum = 0;
        ll p = 0;
        while (sum < H) {
            ret++;
            sum += b[p++];
        }
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 1792