akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define maxn 100005
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define pb push_back
#define pii pair<int,int>
using namespace std;

int n,k;
int a[5005];

bool Check(int mid){
    if(a[mid]>=k) return 1;
    bitset<5005> bs;
    bs[0]=1;
    for(int i=1;i<=n;i++){
        if(a[i]>5000) break;
        if(i!=mid) {
            bs|=bs<<a[i];
        }
    }
    for(int i=k-1;i>=k-a[mid];i--){
        if(bs[i]) return 1;
    }
    return 0;
}

int main(){

    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    int L=1,R=n,mid;
    while(L<=R){
        mid=L+R>>1;
        if(Check(mid)) R=mid-1;
        else L=mid+1;
    }
    cout<<R<<endl;


}




Measured memory_bytes: 256
#include <iostream>
#include <cmath>

bool isPrime(int n)
{
	int ub = (int)std::sqrt((float)n);
	for (int p=2; p<=ub; p++) {
		if (n%p==0) return false;
	}
	return true;
}

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n == 0) break;
		int res = 0;
		for (int k=3; k<=n/2; k++) {
			if (isPrime(k) && isPrime(n-k)) res++;
		}
		std::cout << res << std::endl;
	}
	return 0;
}



Measured memory_bytes: 3052
///////////////////// author : TrEbLeCleF /////////////////////
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;

#define pb(x) push_back(x)
#define deb(x) cerr <<#x<<" = "<<x<<"\n"
#define print(v,s,e) for(int i = s; i < e; i++)cout << v[i]<<" ";cout<<"\n";
#define INF 1e17
#define PI 3.14159265358979323846 
int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
/////////////////////////// GLOBAL ///////////////////////////

class Prime{
	private:
	int size;
	vector<int> v;
	public:
	Prime(int size){
		this->size = size;
		v.resize(this->size);
		v.assign(this->size,-1);
	}
	void pf(){
		int upto = this->size;
		v[1]=1;
		for(int i=2; i<upto; i++){
			if(v[i]==-1){
				v[i] = i;
				for(int j = 2; j*i<upto; j++){
					if(v[i*j]==-1){
						v[i*j] = i;
					}
				}
			}
		}
	}
	int spf(int n){
		return v[n];
	}
};


/////////////////////////// GLOBAL ///////////////////////////
void solve(){
	ll n;cin >> n;
	Prime p(1e7+2);
	p.pf();
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		int num = i;
		map<int, int> m;
		while(num!=1){
			int s= p.spf(num);
			m[s]++;
			num = num/s;
		}
		ll tmp=1;
		for(auto ele : m){
			tmp*= (ele.second+1);
		}
		ans += i*tmp;
	}
	cout << ans <<"\n";
	

}

int main(){ 
	#ifndef ONLINE_JUDGE
		clock_t tStart = clock();
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
		freopen("error.txt", "w", stderr);
	#endif 
    ios_base:: sync_with_stdio(false); 
   	cin.tie(0); 
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
	/* #ifndef ONLINE_JUDGE
    printf("\nRun Time -> %.10fs\n", (double)(clock()-tStart) / CLOCKS_PER_SEC);
    #endif  */
}

Measured memory_bytes: 42268
import sys

k,n=map(int,input().split())
a=list(map(int,input().split()))

  
b=[]
b.append(k+a[0]-a[n-1])

for i in range(n-1):
    b.append(abs(a[i+1]-a[i]))

b.remove(max(b))

print(sum(b))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

#define int long long

typedef pair<int, int> P;

int H, W, S;
vector< vector<int> > A;
bool m1[40][40][40][40];
P m2[40][40][40][40];
int m[50][50];

void setM(int x, int y, int val) {
	m[y+1][x+1] = val;
}
int getM(int x1, int y1, int x2, int y2) {
	return m[y2][x2] - m[y2][x1] - m[y1][x2] + m[y1][x1];
}
void initM() {
	REP(x, W+1) REP(y, H+1) {
		m[y+1][x] += m[y][x];
	}
	REP(x, W+1) REP(y, H+1) {
		m[y][x+1] += m[y][x];
	}
}

// [x1, x2) && [y1, y2)
P solve(int x1, int y1, int x2, int y2) {
	if (m1[x1][y1][x2][y2]) return m2[x1][y1][x2][y2];

	P res(1, S-(getM(0, 0, W, H) - getM(x1, y1, x2, y2)));
	if (res.second < 0) {
		res = P(-inf, -inf);
	}
	else {
		// [y1, y) [y, y2)
		FOR(y, y1+1, y2) {
			P a1 = solve(x1, y1, x2, y);
			P a2 = solve(x1, y, x2, y2);
			if (a1.first < 0 || a2.first < 0) continue;
			P a = P(a1.first+a2.first, min(a1.second, a2.second));
			res = max(res, a);
		}
		// [x1, x) [x, x2)
		FOR(x, x1+1, x2) {
			P a1 = solve(x1, y1, x, y2);
			P a2 = solve(x, y1, x2, y2);
			if (a1.first < 0 || a2.first < 0) continue;
			P a = P(a1.first+a2.first, min(a1.second, a2.second));
			res = max(res, a);
		}
	}
//	cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << res.first << " " << res.second << endl;
	return m1[x1][y1][x2][y2] = true, m2[x1][y1][x2][y2] = res;
}

signed main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	while (cin >> H >> W >> S, H || W || S) {
		fill(m[0], m[50], 0);
		fill(m1[0][0][0], m1[0][0][0]+40*40*40*40, false);
		A = vector< vector<int> >(H, vector<int>(W, 0));
		REP(y, H) REP(x, W) {
			cin >> A[y][x];
			setM(x, y, A[y][x]);
		}
		initM();
		int sum = 0;
		REP(y, H) REP(x, W) sum += A[y][x];
		P ans = solve(0, 0, W, H);
		assert(ans.first >= 0 && ans.second >= 0);
		cout << ans.first << " " << ans.second << endl;
	}
}

Measured memory_bytes: 43776
"""
B - Digital Gifts
"""
import datetime

if __name__ == '__main__':
    btcrate = 380000
    result = 0
    n = int(input())
    for i in range(n):
        x,u = input().split(' ')
        if(u == 'JPY'):
            result += float(x)
        else:
            result += float(x) * btcrate
    
    print(result)


Measured memory_bytes: 3312
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int a[2000], c[1001];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        c[a[i]]++;
    }
    int ans = 0;
    int i, j, k;
    for (i = 1; i <= 1000; i++) {
        if (c[i] >= 3) {
            ans += c[i] * (c[i] - 1LL) * (c[i] - 2LL) / 6LL;
        }
        for (j = i + 1; j <= 1000; j++) {
            if (c[i] >= 2 && j < i + i) {
                ans += c[i] * (c[i] - 1LL) / 2LL * c[j];
            }
            if (c[j] >= 2) {
                ans += c[j] * (c[j] - 1LL) / 2LL * c[i];
            }
            int su = i + j;
            for (k = j + 1; k <= 1000; k++) {
                if (k < su) {
                    ans += c[i] * c[j] * c[k];
                }
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char notes[110][10];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	vector<pair<ll, ll>>point;
	rep(i, n) {
		ll x, y;
		cin >> x >> y;
		point.push_back(make_pair(x, y));
	}
	sort(point.begin(), point.end());
	vector<pair<ll, ll>>dist;
	rep(i, n) {
		for (ll j = i + 1;j < n;++j) {
			ll nx = point[i].first - point[j].first;
			ll ny = point[i].second - point[j].second;
			dist.push_back(make_pair(nx, ny));
		}
	}
	sort(dist.begin(), dist.end());
	ll k = dist.size();
	ll ans = 1;
	ll res = 0;
	ll dx = dist[0].first;
	ll dy = dist[0].second;
	for (ll i = 1;i < k;++i) {
		if (dist[i].first != dx || dist[i].second != dy) {
			ans = max(ans, res);
			res = 1;
			dx = dist[i].first;
			dy = dist[i].second;
		}
		else {
			res++;
			ans = max(ans, res);
		}
	}
	cout << n - ans << endl;
	return 0;
}


Measured memory_bytes: 3660
N = int(input())

XYH = [list(map(int, input().split())) for _ in range(N)]
# 高さは一意に決まるのでhi>0のものをひとつ変数に持っておく
for x, y, h in XYH:
  if h >= 1:
    xt, yt, ht = x, y, h
    break
# greedy    
for cx in range(101):
  for cy in range(101):
    ch = ht + abs(cx-xt) + abs(cy-yt)
    for x, y, h in XYH:
        if h != max(ch - abs(x - cx) - abs(y - cy), 0):
          break
    else:
      print(cx, cy, ch)
      exit()
    

Measured memory_bytes: 3064
#include <stdio.h>

#define N 100

int main(){

  int i;
  int j;
  int min;
  int n;
  int tmp;
  int count=0;
  int data[N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&data[i]);
  }

  for(i=0;i<n-1;i++){
        min = i;
    for(j=i+1;j<n;j++){
      if( data[j] < data[min]){
	min = j;
      }
    }
    if(min != i){
	tmp = data[i];
	data[i] = data[min];
	data[min] = tmp;
	count++;
   }
  }
  for(i=0;i<n-1;i++){
    printf("%d ",data[i]);
  }
    printf("%d\n",data[i]);
    printf("%d\n",count);

    return 0;
}

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


int main() {

    int n, x;
    cin >> n >> x;
    int sum = 0;
    int mn = 10000;
    for (int i = 0; i < n; ++i) {
        int m; cin >> m;
        sum += m;
        mn = min(mn, m);
    }
    cout << n + (x-sum) / mn << endl;
    return 0;
}

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


int W,H;

int S[50][50];
int C[5];

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

#define INF 1e9

int dijkstra(){
    int dist[H+1][W+1][5]={};
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int k=0;k<=4;k++){
                dist[i][j][k]=INF;
            }
        }
    }

    dist[0][0][0]=0;
    priority_queue<tuple<int,int,int,int>> PQ;
    PQ.push(make_tuple(0,0,0,0));
    while(!PQ.empty()){
        int cost;
        int x,y,d;
        auto f=PQ.top();
        PQ.pop();
        cost=-get<0>(f);
        x=get<1>(f);
        y=get<2>(f);
        d=get<3>(f);

        if(dist[x][y][d]<cost) continue;
        
        if(x==H-1&&y==W-1) return cost;

        for(int i=0;i<4;i++){
            int nd=(d+i)%4;
            int neco=0;
            if(S[x][y]!=i) neco=C[i];

            int nx=x+dx[nd];
            int ny=y+dy[nd];

            if(nx<0||nx>=H||ny<0||ny>=W) continue;
            if(dist[nx][ny][nd]>dist[x][y][d]+neco){
                dist[nx][ny][nd]=dist[x][y][d]+neco;
                PQ.push(make_tuple(-dist[nx][ny][nd],nx,ny,nd));
            }
        }

    }
}

void solve(){
    for(int i=0;i<H;i++) for(int j=0;j<W;j++) cin>>S[i][j];
    for(int i=0;i<4;i++) cin>>C[i];

    cout<<dijkstra()<<endl;
}

int main(){
    while(1){
        cin>>W>>H;
        if(H==0&&W==0) break;
        solve();
    }

  return 0;
}



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

using namespace std;

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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

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

const ll INF = 1e12; // larger than the longuest distance of s and t.
const ll MOD = 1000000007;  // 1e9 + 7

// Returns the nearest position in left and right.
// The format is (left, right). left < x <= right.
tuple<ll, ll> nearest_pair(vector<ll>& t, ll x) {
  auto it = lower_bound(all(t), x);
  ll left, right;

  if (it == t.end()) {
    right = INF;
    --it;
    left = *it;
  } else if (it == t.begin()) {
    right = *it;
    left = -INF;
  } else {
    right = *it;
    --it;
    left = *it;
  }

  return make_tuple(left, right);
}

int main(int argc, char** argv) {
  ll A, B, Q;
  cin >> A >> B >> Q;
  vector<ll> s(A);
  vector<ll> t(B);
  rep(i, A) {
    cin >> s[i];
  }
  rep(i, B) {
    cin >> t[i];
  }
  rep(i, Q) {
    ll x;
    cin >> x;

    ll sl, sr;
    tie(sl, sr) = nearest_pair(s, x);

    ll tl, tr;
    tie(tl, tr) = nearest_pair(t, x);

    ll ans = INF;
    ans = min(ans, abs(x-sl) + abs(sl-tl));
    ans = min(ans, abs(x-sl) + abs(sl-tr));
    ans = min(ans, abs(x-sr) + abs(sr-tl));
    ans = min(ans, abs(x-sr) + abs(sr-tr));
    ans = min(ans, abs(x-tl) + abs(tl-sl));
    ans = min(ans, abs(x-tl) + abs(tl-sr));
    ans = min(ans, abs(x-tr) + abs(tr-sl));
    ans = min(ans, abs(x-tr) + abs(tr-sr));

    cout << ans << endl;
  }
}


Measured memory_bytes: 2944
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<fstream>
#include<map>
#include<bitset>
#include<unordered_map>
#include<cstring>
#include<cctype>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
ll fix_mod(ll x, ll y)
{
	return (y + x % y) % y;
}
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

#ifdef ONLINE_JUDGE
	//freopen("crosses.in", "r", stdin);

	//freopen("crosses.out", "w", stdout);
#endif
#ifndef ONLINE_JUDGE
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
}
int main()
{
	Mohammed_Atef_Hassan
		int n;
	cin >> n;
	vector<pair<string, ll>>v(n);
	for (int i = 0; i < n; i++)cin >> v[i].first >> v[i].second;
	string x;
	cin >> x;
	ll sum = 0;
	for (int i = 0; i < n; i++)
	{
		if (v[i].first == x)
		{
			for (int j = i + 1; j < n; j++)
				sum += v[j].second;
		}
	}
	ex(sum);
}

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

vector<int>E[5000],G[5000];
int c[5000],r[5000];
int d[5000];
int main(){
	int n,k;scanf("%d%d",&n,&k);
	rep(i,n)scanf("%d%d",&c[i],&r[i]);
	rep(i,k){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);E[b].push_back(a);
	}
	rep(i,n){
		queue<int>que;
		memset(d,-1,sizeof(d));
		d[i]=0;que.push(i);
		while(!que.empty()){
			int p=que.front();que.pop();
			if(d[p]==r[i])continue;
			for(int v:E[p]){
				if(d[v]==-1){
					d[v]=d[p]+1;que.push(v);
				}
			}
		}
		rep(j,n){
			if(i!=j&&d[j]!=-1)G[i].push_back(j);
		}
	}
	priority_queue<P,vector<P>,greater<P>>que;
	memset(d,0x3f,sizeof(d));
	d[0]=0;que.push(P(0,0));
	while(!que.empty()){
		P p=que.top();que.pop();
		if(d[p.second]!=p.first)continue;
		for(int v:G[p.second]){
			if(d[v]>p.first+c[p.second]){
				d[v]=p.first+c[p.second];
				que.push(P(d[v],v));
			}
		}
	}
	printf("%d\n",d[n-1]);
}

Measured memory_bytes: 70820
{-# LANGUAGE BangPatterns #-}

import           Control.Monad
import           Data.Function
import qualified Data.List     as L
import           Debug.Trace

main :: IO ()
main = do
  [d, g] <- map read.words <$> getLine
  pcs <- replicateM d $ do
    [p, c] <- map read.words <$> getLine
    return (p, c)
  print $ solve d g pcs

solve :: Int -> Int -> [(Int, Int)] -> Int
solve d g pcs = minimum $ do
    complete <- L.subsequences [1..d]
    Just num <- return $ greedy complete
    return num
  where
    !sorted = reverse $ zip [1..d] pcs
    greedy complete = go0 0 0 sorted
      where
        go0 !count !score ((i, (p, c)):rest)
          | i `elem` complete = go0 (count + p) (score + 100 * i * p + c) rest
          | otherwise = go0 count score rest
        go0 count score [] = go count score sorted
        go !count !score ((i, (p, c)):rest)
          | i `elem` complete = go count score rest
          | score < g, q <- min p $ (g - score + 100 * i - 1) `quot` (100 * i) =
              go (count + q) (score + 100 * i * q) rest
          | otherwise = go count score rest
        go count score []
          | score < g = Nothing
          | otherwise = Just count



Measured memory_bytes: 892
//-fexec-charset=CP932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100
#define THOU 1000
#define FIVEMAX 100000
#define NINEMAX 1000000000
#define TWEMAX 1000000000000
#define rep(i,n) for (int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define darep(i,a,n) for(int i=n,i>=a;i--)

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

ll gcd(ll x,ll y){
    if(x<y) swap(x,y);
 
    ll r;
    while(y>0){
        r=x%y;
        x=y;
        y=r;
    }
    return x;
}

int main(){
  ll a,b;
  vector<ll>v;
  cin>>a>>b;
  ll x=gcd(a,b);
  const auto &pmf=prime_factorize(x);
  cout<<pmf.size()+1<<endl;
  return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(){
  int n,x,i,j,k,total=0;
  while(1){
    scanf("%d %d",&n,&x);
    if(n==0 && x==0)break;
    total=0;
    for(i=1;i<=n;i++){
      for(j=i+1;j<=n;j++){
	for(k=j+1;k<=n;k++){
	  if(i+j+k == x)total++;
	}
      }
    }
    printf("%d\n",total);
  }
  return 0;
}

Measured memory_bytes: 600
#include<cstdio>
using namespace std;
int main(){
	int rec=0,dia=0;
	int a,b,c;
	while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
		if(a*a+b*b==c*c)rec++;
		else if(a==b)dia++;
	}
	printf("%d\n%d\n",rec,dia);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
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> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for(int i = a; i <= b; i++) {
        int n = i;
        V<> v;
        while(n) {
            v.push_back(n%10);
            n/=10;
        }
        if(v[0] == v[4] && v[1] == v[3]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3588
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        //long mod = (long)Math.pow(10,9) + 7;
        long n = sc.nextLong();
        int p = sc.nextInt();
        boolean isOdd = false;
        for(long i = 0; i < n; i++){
            if(sc.nextInt() % 2 != 0){
                isOdd = true;
            }
        }
        if(isOdd){
            System.out.println((long)rep2(2,n)/2L);
        }else{
            System.out.println(p == 0 ? (long)rep2(2,n) : 0);
        }
    }
    
    private static long rep2(long b, long n){
        if(n == 1) return b;
        if(n % 2 == 0){
            return (long)Math.pow(rep2(b,n/2), 2);
        }else{
            return (long)Math.pow(rep2(b,n/2), 2)*b;
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
struct node
{
    char city[15];
    int score;
    int num;
}s[105];
bool cmp(const node &a,const node &b)
{
    if(strcmp(a.city,b.city)!=0)
        return strcmp(a.city,b.city)<0;
    else
        return a.score>b.score;
}
int main()
{
    int n,i;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=0;i<n;i++)
        {
            scanf("%s%d",&s[i].city,&s[i].score);
            s[i].num=i+1;
        }
        sort(s,s+n,cmp);
        for(i=0;i<n;i++)
            printf("%d\n",s[i].num);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INF = 1LL << 60;

 int N, W;
 vector<vector<ll>> dp(101, vector<ll>(100001, -1));
 vector<ll> w(100), v(100);

 ll rec(int i, int j) {
   if (dp.at(i).at(j) >= 0) return dp.at(i).at(j);

   ll res;
   if (i == N) res = 0;
   else if (j < w.at(i)) res = rec(i + 1, j);
   else res = max(rec(i + 1, j), rec(i + 1, j - w.at(i)) + v.at(i));

   return dp.at(i).at(j) = res;
 }

 int main() {
   cin >> N >> W;
   rep(i, 0, N) cin >> w.at(i) >> v.at(i);

   cout << rec(0, W) << endl;
 }


Measured memory_bytes: 80256
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	static int n;
	static Long memo[][];
	static int[] w, val;
	static long OO = (long) (1e18);

	static long dp(int idx, int rem) {
		if (rem < 0) {
			return -OO;
		}
		if (idx == n) {
			return 0;
		}
		if (memo[idx][rem] != null)
			return memo[idx][rem];

		long take = val[idx] + dp(idx + 1, rem - w[idx]);
		long leave = dp(idx + 1, rem);

		return memo[idx][rem] = Math.max(take, leave);
	}

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		n = sc.nextInt();
		int r = sc.nextInt();
		w = new int[n];
		val = new int[n];
		for (int i = 0; i < n; i++) {
			w[i] = sc.nextInt();
			val[i] = sc.nextInt();
		}
	
		memo = new Long[n + 1][r + 1];
		pw.print(dp(0, r));

		pw.close();
	}

	static class Pair {

		long total;
		int diff;

		public Pair(long total, int diff) {
			this.total = total;
			this.diff = diff;
		}

		public String toString() {
			return total + " " + diff;
		}

	}

	static class Pair2 implements Comparable<Pair2> {

		int x, y;

		public Pair2(int x, int y) {
			this.x = x;
			this.y = y;

		}

		public int compareTo(Pair2 o) {
			if (x == o.x)
				return y - o.y;
			return x - o.x;
		}

		public String toString() {
			return x + " " + y;
		}

	}

	static class Edge implements Comparable<Edge> {
		int node, cost;

		Edge(int a, int b) {
			node = a;
			cost = b;
		}

		public int compareTo(Edge e) {
			return cost - e.cost;
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}

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

using namespace std;

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

int main() {
  long a, b;
  cin >> a >> b;
  cout << a * b / gcd(a, b) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

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

    string s;
    cin >> s;
    int cnt=0;
    rep(i,3){
        if(s[i]=='1'){
            cnt+=1;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,k;
    cin >> n >> k;
    vi h(n),sub(n, 100000000000);
    rep(i,n) cin >> h.at(i);
    sort(h.begin(), h.end());
    rep(i,n-k+1) {
        sub.at(i) = h.at(i+k-1) - h.at(i);
    }
    sort(sub.begin(), sub.end());
    cout << sub.at(0) << endl;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;

const int maxn = 100001;
const ll inf = 1e14;
int n, w, weight[101], value[101];
ll dp[2][maxn];

int main(){
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.precision(10);
   cout << fixed;
   cin >> n >> w;
   bool at = 0;
   int mx_value = 0;
   for (int i = 0; i < n; ++i){
      cin >> weight[i] >> value[i];
      mx_value += value[i];
   }
   for (int i = 1; i <= mx_value; ++i)
      dp[at][i] = inf;
   for (int i = 0; i < n; ++i){
      at ^= 1;
      for (int j = 0; j <= mx_value; ++j){
         dp[at][j] = dp[at ^ 1][j];
         if (j >= value[i])
            dp[at][j] = min(dp[at][j], dp[at ^ 1][j - value[i]] +weight[i]);
      }
   }
   int mx = -1;
   for (int i = 0; i <= mx_value; ++i){
      if (dp[at][i] <= w)
         mx = i;
   }
   cout << mx << '\n';
   return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main() {
    int cnt,u,d,l,r,f,b,N,g;char T[20];while (scanf("%d",&N)!=EOF && N) {
        cnt=1,u=1,f=2,r=3,d=6,l=4,b=5;while (N--) {
            scanf("%s",&T);
            if (T[0]=='N') g=u,u=f,f=d,d=b,b=g;
            else if (T[0]=='E') g=u,u=l,l=d,d=r,r=g;
            else if (T[0]=='S') g=u,u=b,b=d,d=f,f=g;
            else if (T[0]=='W') g=u,u=r,r=d,d=l,l=g;
            else if (T[0]=='L') g=f,f=l,l=b,b=r,r=g;
            else g=f,f=r,r=b,b=l,l=g;
            cnt+=u;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 1036
fun main(array: Array<String>) {
    val (n, a, b) = readLine()!!.split(" ").map { it.toInt() }
    var sum = 0
    var ans = 0
    for(i in 1..n) {
        var num = i
        while (num > 0) {
            sum += num % 10
            num /= 10
        }
        if(sum in a..b) ans += i
        sum = 0
    }
    print(ans)
}

Measured memory_bytes: 35984
a=int(input())

if a<=9:
  print(a)
elif 9<a<100:
  print(9)
elif 100<=a<=999:
  print(9+a-99)
elif 999<a<10000:
  print(9+900)
elif 10000<=a<=99999:
  print(9+900+a-9999)
else:
  print(90909)

Measured memory_bytes: 3060
import bisect

h, w = map(int, input().split())
figure_dic = {}
def add_dic(figure):
    if not figure in figure_dic:
        figure_dic[figure] = 0
    figure_dic[figure] += 1
for i in range(h):
    line = list(input())
    for j in line:
        add_dic(j)
figures = []
for key, items in figure_dic.items():
    figures.append(items)
figures.sort()
same_boxes = []
if h % 2 == 0:
    if w % 2 == 0:
        same_boxes += [4 for i in range(h*w//4)]
    else:
        same_boxes += [4 for i in range((w//2)*(h//2))]
        same_boxes += [2 for i in range(h//2)]
else:
    if w % 2 == 0:
        same_boxes += [4 for i in range((h//2)*(w//2))]
        same_boxes += [2 for i in range(w//2)]
    else:
        same_boxes += [4 for i in range((h//2)*(w//2))]
        same_boxes += [2 for i in range(h//2 + w//2)]
        same_boxes += [1]
same_boxes.sort(reverse=True)
l = len(figures)
flag = 0
for box in same_boxes:
    left = bisect.bisect_left(figures, box)
    if left == l:
        flag = 1
        break
    figures[left] -= box
    figures.sort()
if flag:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 42476
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <limits.h>
 
#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

ll gcd(ll l, ll r)
{
	if (l < r) swap(l, r);
	while(true)
	{
		ll m = l % r;
		if (m == 0) return r;
		l = r;
		r = m;
	}
}

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

    N = N % K;
    ll ans = min(K - N, N);

    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))
L.sort()
result = 0
for x in range(N):
    z = x + 2
    for y in range(x+1, N):
        while z < N and L[x] + L[y] > L[z]:
            z += 1
        result += z - y - 1
print(result)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int MAXN = 10000001;
#define ll long long 

class TaskD {
private:
	Debugger debugger;
	int get(int x){
		int ans = 0;
		while(x){
			x%= __builtin_popcount(x);
			ans++;
		}
		return ans;
	}

public:
	void solveOne(int it){
		int n;
		cin >> n;
		string s;
		cin >> s;
		int ones = 0;
		for(int i = 0; i < n; i++){
			if(s[i] == '1'){
				ones++;
			}
		}
		int mods[2] = {ones-1, ones+1};
		int val[2] = {0, 0};
		vector<int> pot2[2];
		for(int i = 0; i < 2; i++){
			pot2[i].assign(n+1, 0);
		}
		for(int where = 0; where < 2; where++){
			if(mods[where] <= 0){
				continue;
			}
			pot2[where][0] = 1 % mods[where];
			for(int i = 1; i <= n; i++){
				pot2[where][i] = 2 * pot2[where][i-1] % mods[where];
			}
			
			for(int i = 0; i < n; i++){
				val[where] = val[where] * 2 + s[i] - '0';
				val[where] %= mods[where];
			}
		}

		for(int i = 0; i < n; i++){
			if(s[i] == '1'){
				if(mods[0] <= 0){
					cout << 0 << endl;
				}else{
					int curr = val[0];
					curr -= pot2[0][n-i-1];
					curr = (curr + mods[0]) % mods[0];
					cout << 1 +  get(curr) << endl;
				}
			}else{
				int curr = val[1];
				curr += pot2[1][n-i-1];
				curr = (curr + mods[1]) % mods[1];
				cout << 1 +  get(curr) << endl;
			}
			
		}


	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskD solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 5200
#include <iostream>
#include <queue>
#include <string>

using namespace std;

int main() {
    priority_queue<int> S;
    string order; // 操作
    int n;
    
    while (true) {
        cin >> order;
        if (order == "insert") {
            cin >> n;
            S.push(n);
        }
        else if (order == "extract") {
            cout << S.top() << endl;
            S.pop();
        }
        else
            break;
    }
}


Measured memory_bytes: 6932
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int dp[2][100005],a[101];
int32_t main(){
    boost;
    //freopen(".in","r",stdin);
    int n,k;
    cin>>n>>k;
    for (int i = 0; i < n; ++i)
        cin>>a[i];
    dp[0][k]=1;
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= k; ++j)
            dp[(i-1)&1][j]=(dp[(i-1)&1][j]+dp[(i-1)&1][j-1])%MOD;
        for (int j = k; j >= 0; j--)
            dp[i&1][j]=(dp[(i-1)&1][min(k,a[i-1]+j)]-(j?dp[(i-1)&1][j-1]:0)+MOD)%MOD;
    }
    cout<<dp[n&1][0]<<"\n";
    return 0;
}

//do smth instead of nothing and stay organized
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 5124
from collections import deque
N = int(input())

y = deque()
for i in range(N):
    input_com = input()
    if input_com == 'deleteFirst':
        y.popleft()
    elif input_com == 'deleteLast':
        y.pop()
    else:
        order, num = input_com.split()
        if order == 'insert':
             y.appendleft(num)
        else:
            if num in y:
                y.remove(num)
            else:
                continue

print(" ".join(y))


Measured memory_bytes: 69852
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,k,ans=0;
  cin>>a>>b>>c>>k;
  if(k<=a){
    ans=k;
    cout<<ans;
    return 0;}    
  if(k>a&&k<=a+b){
    ans=a;
    cout<<ans;
    return 0;}  
   cout<<a+(k-a-b)*-1;

  
  return 0;
    
}
       
  

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> v(n), c(n);
  for (int i=0; i<n; i++){
    cin >> v[i];
  }
   for (int i=0; i<n; i++){
    cin >> c[i];
  }
  int count=0;
  for (int i=0; i<n; i++){
    if (v[i] - c[i] > 0) count += v[i] - c[i];
  }
  cout << count << endl;
}


Measured memory_bytes: 256
# include<bits/stdc++.h>
# define LL long long
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int minn=1e9;
	minn=min(minn,abs(b-a)+abs(b-c));
	minn=min(minn,abs(b-a)+abs(a-c));
	minn=min(minn,abs(c-a)+abs(c-b));
	cout<<minn<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int mod = 1e9+7;

int main() {

  string s;cin >> s;
  int ans = 700;
  if(s[0] == 'o') ans += 100;
  if(s[1] == 'o') ans += 100;
  if(s[2] == 'o') ans += 100;
  cout << ans << endl;
  return 0;
}





// EOF


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N, K;
string S;

void next(string &s) {
	if (s[0] == 'A') s[0] = 'B';
	else {
		REP(j, N - 1) {
			if (s[j + 1] == 'A') s[j] = 'B';
			else s[j] = 'A';
		}
		s[N - 1] = 'A';
	}
}

// --DEBUG-- //
string rev(string s) {
	REP(i, N) s[i] = s[i] == 'A' ? 'B' : 'A';
	return s;
}
void solveDEBUG(string s) {
	int t = K;
	while (t--) next(s);
	cout << s << endl;
}
////

int main() {
	cin >> N >> K >> S;
	
	if (debug) solveDEBUG(S);
	
	string ans = "", lev = "";
	
	for (int i = N - 2; i >= 0; i -= 2) {
		if (S[i] == 'B' && S[i + 1] == 'A') ans += "AB";
		else break;
	}
	for (int i = N - 1 - (int)ans.size(); i >= 0; i--) lev += S[i];
	
	for (int i = 0; i < N - 1; i += 2) {
		if (K <= 4 || ans.size() >= N - 2) break;
		
		if ((S[i] == 'A') ^ (i % 2 == 1)) K--; i++;
		if ((S[i] == 'A') ^ (i % 2 == 1)) K--; i--;
		
		K -= 2;
		ans += "AB";
	}
	
	for (int i = 0; ans.size() < N; i++) ans += lev[i];
	reverse(ALL(ans));
	
	REP(i, 4) if (K) next(ans), K--;
	if (K && N % 2 == 1) ans[0] = ( (ans[0]=='B')+K ) % 2 == 1 ? 'B' : 'A';
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,start,end) for(int i = start; i < end; i++)
#define ll long long
const ll N = 4e3 + 200;
const ll INF = 0x3f3f3f3f;


int main(){
  ll n;
  cin>>n;
  std::vector<string> v;
  map<string,ll> mp;
  rep(i,n){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    // cout<<s<<endl;
    if(mp[s] == 0){
      v.push_back(s);
    }
    mp[s]++;
  }
  int len = v.size();
  ll sum = 0;
  rep(i,len){
    ll k = mp[v[i]];
    if(k >= 2)
    sum += (k*(k-1))/2;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 16628
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;
const int oo = 1e9+7;
const int mod = 1e9+7;
const int MAXN = 1e3+7;

vector<vector<int>> dp(MAXN, vector<int>(MAXN, 0));
char grid[MAXN][MAXN];

void add(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}

int main() {
    
    int h, w;
    string line;
    scanf("%d%d",&h,&w);
    getline(cin, line);
    
    for(int r = 1; r <= h; ++r) {
        getline(cin, line);
        for(int c = 1; c <= w; ++c) {
            grid[r][c] = line[c-1];
            dp[r][c] = 0;
        }
    }
    
    dp[1][1] = 1;
    
    for(int r = 1; r <= h; ++r) {
        for(int c = 1; c <= w; ++c) {
            if(grid[r][c] == '#') continue;
            add(dp[r+1][c], dp[r][c]);
            add(dp[r][c+1], dp[r][c]);
        }
    }
    
    printf("%d\n", dp[h][w]);
    
    return 0;
}




Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll gcd(ll x,ll y){
    if(x<y) swap(x,y);
    //xの方が常に大きい
    ll r;
    while(y>0){
        r=x%y;
        x=y;
        y=r;
    }
    return x;
}

int main(){
    int x;cin>>x;
    if(x==0){
        cout<<1<<endl;
    }
    else{
        cout<<0<<endl;
    }
}

Measured memory_bytes: 3632
[n,m] = [int(i) for i in input().split()]
dic = {}
checker2 = 1
checker3 = 1
if m != 0:
    for i in range(m):
        [s,c] = [int(i) for i in input().split()]
        if s-1 in dic.keys() and dic[s-1] != str(c):
            checker2 = 0
        else:
            dic[s-1] = str(c)
    if checker2:
        for i in range(10 ** (n-1)-1,10 ** n):
            checker = 1
            num = str(i)
            for key in dic.keys():
                if key >= len(num):
                    checker = 0
                else:
                    if dic[key] != num[key]:
                        checker = 0

            if checker:
                checker3 = 0
                print(i)
                break
        if checker3:
            print(-1)

    else:
        print(-1)
else:
    if n == 1:
        print(0)
    else:
        print(10**(n-1))

Measured memory_bytes: 39280
#include<iostream>
using namespace std;
int main(){
  int m,n,i,j,k,s;
  cin >> n >> m;
  int a[m];
  for(i=0;i<m;i++)a[i]=0;
  for(i=0;i<n;i++){
    cin >> k;
    for(j=0;j<k;j++){cin >> s;a[s-1]++;}
  }
  s=0;
  for(i=0;i<m;i++){if(a[i]==n)s++;}
  cout << s;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static double eye_right, eye_left;
	static int a, b, c, d, A, B, C, D;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
		System.out.println(a + " " + A);
		System.out.println(b + " " + B);
		System.out.println(c + " " + C);
		System.out.println(d + " " + D);
	}
	static boolean read(){
		if(!sc.hasNext())return false;
		eye_left = sc.nextDouble();
		eye_right = sc.nextDouble();
		return true;
	}
	static void solve(){
		if(eye_left >= 1.1){
			a++;
		}else if(eye_left >= 0.6){
			b++;
		}else if(eye_left >= 0.2){
			c++;
		}else if(eye_left < 0.2){
			d++;
		}
		
		if(eye_right >= 1.1){
			A++;
		}else if(eye_right >= 0.6){
			B++;
		}else if(eye_right >= 0.2){
			C++;
		}else if(eye_right < 0.2){
			D++;
		}
	}

}

Measured memory_bytes: 12000
/*
 * Author:  mybestwishes
 * Created Time:  2011/8/31 13:04:56
 * File Name: A.cpp
 */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <time.h>
using namespace std;
#define Abs(x) (((x) > 0)?(x):(-(x)))
#define N 1000000
typedef long long lint;
int num[N] ;

int main() {
    int n , k ;
    while(scanf("%d%d" , &n ,&k) != EOF){
        //cout<<n<<k<<endl;
        if(n == 0 && k == 0 ) break ;
        for(int i = 0 ; i < k ; i++)
            scanf("%d" , &num[i]);
        bool tag = true ;
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < k ; j++){
                int tmp ; 
                scanf("%d" , &tmp);
                num[j] -= tmp ;
                if(num[j] < 0){
                    tag = false ;
                }
            }
        }
        if(tag)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}

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

def main():
    n, k = input_list()
    # R = グー, S = チョキ, P = パー
    R, S, P = input_list()
    t = input()
    tt = list(t)
    for i in range(n - k):
        if tt[i] == t[i+k]:
            tt[i+k] = "x"
    r = tt.count("r") * P
    s = tt.count("s") * R
    p = tt.count("p") * S
    print(r + s + p)


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 76952