akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

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

    vector<int> ans(N);
    bool flag=true;
    for(int i=0; i<N; ++i){
        flag=false;
        for(int j=N-1-i; j>=0; --j){
            if(b[j] == j+1){
                ans[i]=b[j];
                b.erase(b.begin() + j);
                flag=true;
                break;
            }
        }
        if(flag==false){
            cout<<-1<<endl;
            return 0;
        }
    }

    for(int i=N-1; i>=0; --i){
        cout<<ans[i]<<endl;
    }
    return 0;
}

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

constexpr double pi = 3.14159265358979;

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

    double shrt = 5.0*h + m/12.0;
    double lng = (double)m;
    double x = abs(lng - shrt)*pi/30;
    
    double ans = sqrt(a*a + b*b - 2*a*b*cos(x));
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 4148
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
 int n,m;
  cin>>n>>m;
  vin a(n);
  rep(i,0,n) cin>>a[i];
  priority_queue<int> pq;
  rep(i,0,n) pq.push(a[i]);
  rep(i,0,m){
    int b=pq.top();  //最高価格
    b/=2;
    pq.pop();
    pq.push(b);
  }
  ll ans=0;
  rep(i,0,n){
   ans+=pq.top(); 
    pq.pop();
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4300
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, 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; }
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; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

ll n;
vl a;

ll solve(int x) {
	ll ans = 0, now = 0;
	rep(i, n) {
		now += a[i];

		if (i % 2 == x && now >= 0) {
			ans += now + 1;
			now = -1;
		}
		else if (i % 2 != x && now <= 0) {
			ans -= now - 1;
			now = 1;
		}
	}
	return ans;
}

int main() {
	cin >> n;
	a.resize(n);
	rep(i, n) cin >> a[i];

	cout << min(solve(0), solve(1)) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (long long i = l; i < r; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
map<pair<int, int>, int> gmemo;
int gcd(int a, int b) {
	if (gmemo[{a, b}] != 0) return gmemo[{a, b}];
	if (gmemo[{b, a}] != 0) return gmemo[{b, a}];
	if (a % b == 0)
		return gmemo[{a, b}] = b;
	else
		return gmemo[{a, b}] = gcd(b, a % b);
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
bool prime(int a) {
	if (a == 1) return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0) return false;
	}
	return true;
}
signed main() {
	int n,ans=0,cntab=0,cntb=0,cnta=0;
	string s[10000];
	cin>>n;
	rep(i,n){
		cin>>s[i];
		if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A')cntab++;
		else if(s[i][0]=='B')cntb++;
		else if(s[i][s[i].size()-1]=='A')cnta++;
		rep(j,s[i].size()-1){
			if(s[i][j]=='A'&&s[i][j+1]=='B')ans++;
		}
	}
	ans+=(max(0ll,cntab-1)+min(cnta,cntb));
	if(max(cnta,cntb)>0&&cntab>0)ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }


template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) {}
	ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while(b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if(u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}

	bool operator==(ModInt that) const { return x == that.x; }
	bool operator!=(ModInt that) const { return x != that.x; }
	ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
	ModInt<MOD> r = 1;
	while(k) {
		if(k & 1) r *= a;
		a *= a;
		k >>= 1;
	}
	return r;
}
typedef ModInt<924844033> mint;

int main() {
	int N; int K;
	while(~scanf("%d%d", &N, &K)) {
		vector<mint> dp, ndp((N + 1) * 4);
		ndp[0 * 4 + 0] = 1;
		rep(i, K) for(int j = i; j < N; j += K) {
			dp.swap(ndp);
			ndp.assign((N + 1) * 4, mint());
			rep(k, N + 1) rep(p, 4) {
				mint x = dp[k * 4 + p];
				if(x.x == 0) continue;
				int np = j + K < N ? ((p & 1) << 1) : 0;
				//左に置く
				if(j - K >= 0 && (p & 2) == 0)
					ndp[(k + 1) * 4 + (np | 0)] -= x;
				//右に置く
				if(j + K < N)
					ndp[(k + 1) * 4 + (np | 1)] -= x;
				//置かない
				ndp[k * 4 + np] += x;
			}
		}
		mint ans;
		vector<mint> fact(N + 1);
		fact[0] = 1;
		rep(i, N)
			fact[i + 1] = fact[i] * (i + 1);
		rep(k, N + 1)
			ans += ndp[k * 4 + 0] * fact[N - k];
		printf("%d\n", ans.get());
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}

signed main(){
  int h,w; cin>>h>>w;
	int n; cin>>n;
	VI a(n); rep(i,n) cin>>a[i];
	int c[h][w];
	int cnt = 0;
	rep(i,h){
		rep(j,w){
			if(i%2==0){
				c[i][j] = cnt+1;
			}else{
				c[i][w-j-1] = cnt+1;
			}
			a[cnt]--;
			if(a[cnt]==0) cnt++;
		}
	}
	rep(i,h){
		rep(j,w){
			cout << c[i][j] << ' ';
		}
		cout << endl;
	}
  return 0;
}


Measured memory_bytes: 384
N = int(input())
p = list(map(float, input().split()))
dp = [[float(0)] * (N+1) for _ in range(N)]
ans = float(0)
s = N//2+1

dp[0][1] = float(p[0])
dp[0][0] = float(1-p[0])

for i in range(1,N):
    for j in range(i+2):
        if j>0:
            dp[i][j] += dp[i-1][j-1]*p[i]
        if i>0:
            dp[i][j] += dp[i-1][j]*(1-p[i])

for i in range(s,N+1):
    ans += dp[N-1][i]

print(ans)

Measured memory_bytes: 111836
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) (vec).begin(),(vec).end()
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n,m,k,wu,wv;
long long dp[3300][3300],ww,vis[3300][3300],best[3],fff;
vector<pair<int,long long> > item[3300];
void upd(long long x){
	if(x>=best[0]){
		best[2]=best[1];
		best[1]=best[0];
		best[0]=x;
		return;
	}
	if(x>=best[1]){
		best[2]=best[1];
		best[1]=x;
		return;
	}
	if(x>=best[2]){
		best[2]=x;
		return;
	}
}
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m>>k;
	while(k--){
		cin>>wu>>wv>>ww;
		vis[wu][wv]=ww;
		item[wu].push_back(make_pair(wv,ww));
	}
	for(int i=1;i<=n;i++) sort(item[i].begin(),item[i].end());
	dp[0][1]=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
			if(!vis[i][j]) continue;
			best[0]=best[1]=best[2]=0;
			for(int k=item[i].size()-1;k>=0;k--){
				if(item[i][k].first>j) continue;
				upd(vis[i][item[i][k].first]);
				fff=best[0]+best[1]+best[2];
				dp[i][j]=max(dp[i][j],dp[i-1][item[i][k].first]+fff);
			}
		}
	}
	cout<<dp[n][m]<<endl;
	return 0;
}


Measured memory_bytes: 163656
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #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<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; }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

template<typename T>
struct CumulativeSum {
    vector<T> s;
    CumulativeSum(const vector<T> &nums) {
        int n = nums.size();
        s.resize(n + 1, 0);
        for (int i = 0; i < n; ++i) {
            s[i + 1] = s[i] + nums[i];
        }
    }
    // [l, r), l and r is 0-indexed.
    T sum(int l, int r) {
        return s[r] - s[l];
    }
};

void Main() {
	int N; cin >> N;
	vl a(N);
	REP(i,N) cin >> a[i];
	CumulativeSum<ll> cs(a);

	// vvl dp(N, vl(N, 0));
	vvl memo(N, vl(N + 1));
	vector<vector<bool>> done(N, vector<bool>(N + 1));
	auto dp = [&](auto dp, int l, int r) {
		if (done[l][r]) return memo[l][r];
		ll sum = cs.sum(l, r);
		ll ans = numeric_limits<ll>::max();
		FOR(i, l + 1, r) {
			chmin(ans, dp(dp, l, i) + dp(dp, i, r) + sum);
		}
		if (ans == numeric_limits<ll>::max()) {
			ans = 0;
		}
		done[l][r] = true;
		memo[l][r] = ans;
		return ans;
	};
	cout << dp(dp, 0, N) << endl;
}

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


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }

const int maxn = 1e6 + 7;

int main() {

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

    int x; cin >> x;
    int ans = x^1;
    out(ans);
    
    
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int INF = 1e15+23432;
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;cin>>n;
    vector<int> a(n), b(n);
    int fact[n+1];
    fact[0] = 1;
    for(int i=1;i<=n;i++)
        fact[i] = i*fact[i-1];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    set<int> used;
    int ans = 0;
    for(int i=0;i<n;i++){
        int temp = a[i]-1;
        for(int j: used)
            if(j<= a[i]-1)
                temp--;
        ans += fact[n-i-1]*temp;
        used.insert(a[i]);
    }
    used.clear();
    for(int i=0;i<n;i++){
        int temp = b[i]-1;
        for(int j: used)
            if(j<= b[i]-1)
                temp--;
        ans -= fact[n-i-1]*temp;
        used.insert(b[i]);
    }
    cout<<abs(ans)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<pll> arb(n);
    vector<set<int>> idx(m+1);

    REP(i, n){
        ll a, b;
        cin >> a >> b;
        arb[i] = make_pair(a, b);
        if(a > m)
            continue;
        // insert a index
        idx[a].insert(i);
    }

    ll ans = 0;
    priority_queue<ll> pq;
    for(int i=m-1;i>=0;i--){
        // arb[i]を決める
        int after = m - i; // 1-m
        for(auto j: idx[after]){
            pq.push(arb[j].second);
        }
        if(pq.empty())
            continue;
        ll top = pq.top();
        pq.pop();
        ans += top;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12280
x, y, a, b, c = map(int, input().split())

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort()
q.sort()
r.sort()

z = []

for i in range(x):
    z.append(p[a - i - 1])
    
for i in range(y):
    z.append(q[b - i - 1])

for i in list(r):
    z.append(i)

z.sort(reverse=True)

ans = 0

for i in range(x + y):
    ans += z[i]
    
print(ans)

Measured memory_bytes: 23328
#include <stdio.h>

int sum;

int main()
{
    int n,a[200010];
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum^=a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(i!=1)
            printf(" ");
        printf("%d",sum^a[i]);
    }
    printf("\n");
    return 0;
}

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

typedef pair<string, int> pp;
const int N = 110;

int n, dex[N];
pp a[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
		dex[i] = i;
	}
	sort(dex, dex + n, [](int x, int y) {
		if(a[x].first != a[y].first)
			return a[x].first < a[y].first;
		return a[x].second > a[y].second;
	});
	for (int i = 0; i < n; i++)
		cout << ++dex[i] << '\n';
	return 0;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())
graph = [[] for _ in range(N)]
dist = [-1] * N
for _ in range(N-1):
  u, v, w = map(int, input().split())
  graph[u-1].append((v-1, w))
  graph[v-1].append((u-1, w))
q = deque()

dist[0] = 0
q.append(0)

while len(q) != 0:
  v = q.popleft()
  for next_v, next_w in graph[v]:
    if dist[next_v] != -1:
      continue
    dist[next_v] = dist[v] + next_w
    q.append(next_v)

for d in dist:
  if d%2 == 0:
    print(0)
  else:
    print(1)

Measured memory_bytes: 47772
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

int main() {
  long long n,m;
  cin >> n >> m;
  long long ans = 0;
  if(m <= 2*n) {
    ans = m/2;
  }else {
    ans = n + (m-2*n)/4;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    const ll MOD = 1e9+7;
    ll n,k;
    cin >> n >> k;

    // x^y % m
    auto mpow = [](ll x, ll y, ll m)
    {
        ll ret = 1;
        while(y!=0)
        {
            if(y&1) ret = (ret*x) % m;
            x = (x*x) % m;
            y = y >> 1;
        }
        return ret;
    };

    vector<ll> fac(2*n+1, 1); // n! % MOD
    vector<ll> finv(2*n+1, 1); // 1/k! % MOD = k!^(MOD-2) % MOD
    for(int i=0;i<2*n;++i)
    {
        fac[i+1] = (fac[i]*(i+1)) % MOD;
        finv[i+1] = (finv[i]*mpow(i+1, MOD-2, MOD)) % MOD;
    }

    auto mcomb = [&](ll x, ll y, ll m) {
        if(x == 0 && y == 0) return ll(1);
        if(x < y || x < 0) return ll(0);

        ll kf_inv = (finv[x-y]*finv[y]) % m; // 1/{(x-y)!*y!} % m
        return (fac[x]*kf_inv) % m; // nCk = x!/{(x-y)!*y!}
    };

    if(k >= n-1) {
        cout << mcomb(2*n-1, n-1, MOD) << endl;
        return 0;
    }

    ll ans = 0;
    rep(i,k+1) {
        ans += (mcomb(n,i,MOD) * mcomb(n-1,i,MOD)) % MOD;
        ans %= MOD;
    }

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

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 998244353
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n, k;
	cin >> n >> k;
	
	vi l(k), r(k);
	for(int i = 0; i < k; i++) {
		cin >> l[i] >> r[i];
	}
	
	vector<ll> dp(n + 1, 0);
	dp[0] = 1;
	dp[1] = -1;
	for(int i = 0; i < n; i++) {
		if(i > 0) (dp[i] += dp[i - 1]) %= P;
		for(int j = 0; j < k; j++) {
			if(i + l[j] < n) (dp[i + l[j]] += dp[i]) %= P;
			if(i + r[j] + 1 < n) (dp[i + r[j] + 1] -= dp[i] - P) %= P;
		}
	}
	
	cout << dp[n - 1] << endl; 
}

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

Measured memory_bytes: 4832
using System;
using System.IO;
using System.Linq;

namespace ABC127B
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var temp = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            var r = temp[0];
            var D =temp[1];
            var xprev = temp[2];

            for (int i = 0; i < 10; i++)
            {
                var xnext = r * xprev - D;
                Console.WriteLine(xnext);
                xprev = xnext;
            }
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
 
#define pb push_back
#define mp make_pair
 
#define all(x) (x).begin(), (x).end()
 
#define fi first
#define se second
 
using namespace std;
 
typedef long long ll;
 
const int MAXN = (int)2e5 + 5;
 
int arr[MAXN];
 
int n, ans;
 
void solve() {
    scanf("%d", &n);
 
    for (int i = 1, x; i <= n; ++i) {
        scanf("%d", &x);
        arr[x] = i;
    }
 
    for (int i = 1, x = 0; i <= n; ++i) {
        if (arr[i] > arr[i - 1]) {
            ++x;
        }
        else {
            x = 1;
        }
 
        ans = max(ans, x);
    }
 
    printf("%d\n", n - ans);
}
 
int main() {
    int tt = 1;
 
    while (tt--) {
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 1152
import queue
import time

N=3
N2=9
diry=[0,1,0,-1]
dirx=[1,0,-1,0]
pos=[[2,2],[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1]]
move=[[1,3],[0,2,4],[1,5],[0,4,6],[1,3,5,7],[2,4,8],[3,7],[4,6,8],[5,7]]

class Puzzle:
    board=""
    space=0

    def __init__(self,board,space):
        self.board=board
        self.space=space

    #盤面を表示
    def showBoard(self):
        for i in range(N2):
            if self.board[i]!=0:
                print(self.board[i],end=' ')
            else:
                print('  ',end='')
            if i%3==2:
                print()
        print()

class State:
    pz=None
    g=0
    h=0
    f=0
    pr=None

    def __init__(self,pz,g,h=0,pr=None):
        self.pz=pz
        self.g=g
        self.h=h
        self.f=g+h
        self.pr=pr

    #初期盤面から1手ずつ表示
    def showRoot(self):
        if self.pr!=None:
            self.pr.showRoot()
        self.pz.showBoard()

    def __lt__(self,other):
        if self.f==other.f:
            return self.g>other.g
        return self.f<other.f

#正解とのマンハッタン距離
def h2(p):
    count=0
    for i in range(N2):
        n=int(p.board[i])
        count+=abs(pos[n][0]-i//N)+abs(pos[n][1]-i%N)
    return count

#h1を用いたヒューリスティック探索
def heuristic(pz,h):
    closedList=set()
    s=State(pz,0,h(pz),None)
    q=queue.PriorityQueue()
    q.put(s)
    while not q.empty():
        s=q.get()
        if s.pz.board in closedList:
            continue
        if s.pz.board=='123456780':
            return s.g
        space=s.pz.space
        for next in move[space]:
            nb=list(s.pz.board)
            nb[space],nb[next]=nb[next],nb[space]
            newb=''.join(nb)
            if not newb in closedList:
                np=Puzzle(newb,next)
                ns=State(np,s.g+1,h(np),s)
                q.put(ns)
        closedList.add(s.pz.board)
    return -1

#初期盤面の読み込み
s=''
for i in range(3):
    s+=input()
initialBoard=s.replace(' ','')

#空白の設定
space=initialBoard.find('0')

#Puzzleオブジェクトの作成
initialPuzzle=Puzzle(initialBoard,space)

if initialBoard=='123456780':
    print(0)
else:
    print(heuristic(initialPuzzle,h2))



Measured memory_bytes: 14912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll suma = accumulate(all(a), 0LL);
    vector<ll> plus(n, 0);
    reps(i, 1, n) plus[i] = a[i] * 2 - plus[i - 1];
    ll sump = accumulate(all(plus), 0LL);
    vector<ll> ans(n);
    ans[0] = suma - sump;
    reps(i, 1, n) ans[i] = a[i] * 2 - ans[i - 1];
    rep(i, n) printf("%lld%s", ans[(i - 1 + n) % n], (i == (n - 1)) ? "\n" : " ");
    return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
void quicksort(long long int number[],long long int n,int first,int last){
   int i, j, pivot, temp;

   if(first<last){
      pivot=first;
      i=first;
      j=last;

      while(i<j){
         while(number[i]<=number[pivot]&&i<last)
            i++;
         while(number[j]>number[pivot])
            j--;
         if(i<j){
            temp=number[i];
            number[i]=number[j];
            number[j]=temp;
         }
      }

      temp=number[pivot];
      number[pivot]=number[j];
      number[j]=temp;
      quicksort(number,n,first,j-1);
      quicksort(number,n,j+1,last);

   }
}

int main()
{
    long long int n;
    scanf("%lli", &n);
    long long int a[n];

    for(int i=0; i<n; i++) scanf("%lli", &a[i]);

    quicksort(a,n,0,n-1);
    for(int i=1; i<n; i++)
    {
       if(a[i]==a[i-1])
       {
           printf("NO\n");
           return 0;
       }
    }
    printf("YES\n");

    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
const ll INFLL = 1e18;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;}
//------------------------------------------------------------------------------

signed main() {
    int N;
    cin>>N;
    vector<pii> a(N);
    vector<pii> b(N);
    REP(i,N) cin>>a[i].first, a[i].second=i;
    b=a;
    sort(ALL(b));
    vector<int> c(N);
    REP(i,N) {
        c[b[i].second]=i;
    }
    int ans=0;
    REP(i,N) {
        if(abs(i-c[i])%2!=0) ans++;
    }
    cout<<ans/2<<endl;
    return 0;
}


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

int main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  int count=0;
  if(n==1){
    cout<<0<<endl;
    return 0;
  }
  if (s.at(0)=='R'){
    if(s.at(1)=='R'){
      count++;
    }
  }
  if(s.at(n-1)=='L'){
    if(s.at(n-2)=='L'){
      count++;
    }
  }
  for(int i=1;i<n-1;i++){
    if(s.at(i)=='R'){
      if(s.at(i+1)=='R'){
        count++;
      }
    }
    else{
      if(s.at(i-1)=='L'){
        count++;
      }
    }
  }
  int ans=1;
  for(int i=1;i<n;i++){
    if(s.at(i)!=s.at(i-1)){
      ans++;
    }
  }
  if(ans==1){
    cout<<count<<endl;
    return 0;
  }
  if(ans==2){
    cout<<count+1<<endl;
    return 0;
  }
  else{
    if(ans/2<=k){
      cout<<count+ans-1<<endl;
    }
    else{
      cout<<count+2*k<<endl;
    }
  }
  

  return 0;
}


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


int main(){
  int64_t h,w;
  cin >> h >> w;
  if(h == 1 || w == 1)cout <<1;
  else cout << (h*w+1)/2;

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
#define MAXN 1000000007
 
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n;
	cin>>n;
	ll arr[n+1];
	ll brr[n];

	for (ll i=0;i<n+1;i++) {
		cin>>arr[i];
	}
	for (ll i=0;i<n;i++) {
		cin>>brr[i];
	}
	ll counter=0;
	for (ll i=0;i<n;i++) {
		counter+=min(brr[i],(arr[i]+arr[i+1]));
		if (min(brr[i],(arr[i]+arr[i+1]))==brr[i]) {
			if (arr[i]<brr[i]) {
				arr[i+1]-=(brr[i]-arr[i]);
			}
		}
		else {
			arr[i+1]=0;
		}
	}
	cout<<counter;
}


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

void err()
{
	std::cout << "No"<< std::endl;
	exit(0);
}

int main(int argc, char **argv)
{
	ll H, W; cin >> H >> W;
	vector<ll> cnt(26, 0);

	REP(_, H)
	{
		string s; cin >> s;
		for (char c : s)
		{
			cnt[c-'a']++;
		}
	}


	if ((H*W)&1)
	{
		REP(i, 26)
		{
			if (cnt[i]&1)
			{
				cnt[i]--;
				break;
			}
		}
	}

	REP(i, 26)
	{
		if (cnt[i]&1)
		{
			err();
		}
	}

	ll n2{0};
	if (H&1) n2 += W/2;
	if (W&1) n2 += H/2;

	ll ex2{0};
	REP(i, 26)
	{
		if (cnt[i] % 4 == 2)
			++ex2;
	}

	if (ex2 > n2) err();
	std::cout << "Yes" << std::endl;
}


Measured memory_bytes: 256
tmp = list(map(int, input().split('/')))
y, m, d= tmp[0], tmp[1], tmp[2]

out = 'TBD'
if y < 2019:
  out = 'Heisei'
elif y == 2019:
  if m < 5:
    out = 'Heisei'

print(out)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> ar(n);
	ll ans = 0LL;

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

	sort(ar.begin(), ar.end());
	n -= 2;
	ans += (ll)ar.back();
	//printf("%+d", ar.back());
	ar.pop_back();
	bool flag = false;
	int tmp;
	for (int i = 0; i < n; i++) {
		if (flag) {
			ans += (ll)tmp;
			flag = false;
		}else{
			tmp = ar.back();
			ar.pop_back();
			flag = true;
			ans += (ll)tmp;
		}
		//printf("%+d", tmp);
	}

	//printf("\n");
	printf("%lld", ans);

	return 0;
}


Measured memory_bytes: 4040
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(NM[0]*(NM[0] - 1) / 2 + NM[1] * (NM[1] - 1) / 2);
        }
    }
}

Measured memory_bytes: 13268
/*
 * 2516.cc: Amidakuji
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 8;
const int MAX_M = 8;

/* typedef */

typedef unsigned int uint;

/* global variables */

int n, m;
int minh = MAX_M;
uint gl;

/* subroutines */

inline uint getn(uint n, int i) {
  return (n >> (4 * i)) & 0xf;
}

inline uint resetn(uint n, int i) {
  return n & ~(0xfU << (4 * i));
}

inline uint setn(uint n, int i, int v) {
  return resetn(n, i) | ((v & 0xf) << (4 * i));
}

inline uint swapn(uint n, int i, int j) {
  uint vi = getn(n, i);
  uint vj = getn(n, j);
  return setn(setn(n, i, vj), j, vi);
}

void rec(uint cs, uint an, uint hs, int h) {
  if (an == 0) {
    if (cs == gl && minh > h) minh = h;
    return;
  }
  if (h >= minh) return;

  for (int i = 0; i < n - 1; i++) {
    int ai = getn(an, i);
    if (ai > 0) {
      int h0 = max(getn(hs, i), getn(hs, i + 1)) + 1;
      uint hs0 = setn(setn(hs, i, h0), i + 1, h0);
      uint an0 = setn(an, i, ai - 1);
      uint cs0 = swapn(cs, i, i + 1);
      rec(cs0, an0, hs0, (h0 > h) ? h0 : h);
    }
  }
}

/* main */

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

  uint st = 0, an = 0;
  for (int i = 0; i < n; i++) st = setn(st, i, i);
  gl = st;
  
  for (int i = 0; i < m; i++) {
    int ai;
    cin >> ai;
    ai--;

    an = setn(an, ai, getn(an, ai) + 1);
    gl = swapn(gl, ai, ai + 1);
  }
  //printf("st=%x, gl=%x, an=%x\n", st, gl, an);

  rec(st, an, 0, 0);
  printf("%d\n", minh);
  return 0;
}

Measured memory_bytes: 1148
s = input().split()

A = int(s[0])
B = int(s[1])
N = int(s[2])

result = 0

n = (N // B) * B - 1
if (n < 0):
  n = 0

a = (A*N)//B - A*(N//B)
b = (A*n)//B - A*(n//B)
"""
for x in range(N+1):
  y = (A*x)//B - A*(x//B)
  if y > result:
    result = y
"""
    
if (a > b):
  result = a
else:
  result = b
print(result)   

Measured memory_bytes: 9140
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define MOD 1000000007

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

    int n;
    cin>>n;

    int a[n+1][4];
    int dp[n+1][4];
    for(int i = 1; i<=n; i++){
        for(int j = 1; j<=3; j++){
            cin>>a[i][j];
        }
    }
    for(int i = 1; i<=n; i++){
        for(int j = 1; j<=3; j++){
            dp[i][j] = 0;
        }
    }
    
    dp[1][1] = a[1][1];
    dp[1][2] = a[1][2];
    dp[1][3] = a[1][3];


    for(int i = 2; i<=n; i++){
        for(int j = 1; j<=3; j++){
            for(int k = 1; k<=3; k++){
            if(j == k){
                continue;
            }
            dp[i][j] = max(dp[i][j],a[i][j] + dp[i-1][k]);
            }
        }
    }
    int ans = 0;
    for(int i = 1; i<=3; i++){
        ans = max(ans,dp[n][i]);
    }
    cout<<ans;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

	int N; cin >> N;
	int F[N] = {0};
	rep (i, N){
		rep (j, 10){
			int f; cin >> f;
			F[i] *= 2;
			F[i] += f;
		} // end rep
	} // end rep

	int P[N][11] = {0};
	rep (i, N){
		rep (j, 11) cin >> P[i][j];
	} // end rep
	

	int res = -2*(int)1e9;
	for (int i = 1; i < 1<<10; ++i){
		int curr = 0;
		for (int j = 0; j < N; ++j){
			int k = __builtin_popcount(i & F[j]);
			curr += P[j][k];
		} // end for
		res = max(res, curr);
	} // end for

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

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
h = [0 for i in range(N + 1)]

ans = 0

for a in A:
    h[a] += 1

B = sorted(A)

cnt = 1
for i in range(len(B)-1):
    if(B[i] == B[i+1]):
        cnt += 1
    else:
        ans += cnt * (cnt - 1) // 2
        cnt = 1
ans += cnt * (cnt - 1) // 2


for a in A:
    ansi = ans
    num = h[a]
    ansi -= num * (num - 1) // 2
    num -= 1
    ansi += num * (num - 1) // 2
    print(ansi)



Measured memory_bytes: 26140
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int N = 1e5 + 7;
const int INF = 1e9;

int used[N];

namespace DSU {
    int p[N];
    int rank[N];

    int get(int v) {
        if (p[v] != v) {
            p[v] = get(p[v]);
        }
        return p[v];
    }

    void merge(int a, int b) {
        a = get(a);
        b = get(b);
        assert(a != b);
        if (rank[a] < rank[b]) swap(a, b);
        p[b] = a;
        if (rank[a] == rank[b]) rank[a]++;
    }

    void init() {
        for (int i = 0; i < N; i++) {
            p[i] = i;
        }
    }
}

struct Edge {
    int u, v, ind;

    Edge() {}

    Edge(int u_, int v_, int ind_) {
        u = u_;
        v = v_;
        ind = ind_;
    }
};

int d[N];
int cl[N];
int ans[2 * N];

void run(int cd, vector<Edge> in, vector<Edge> out) {
    // cerr << "run " << cd << endl;
    
    for (auto t : in) {
        if (DSU::get(t.u) != DSU::get(t.v)) {
            if (used[t.u] && used[t.v]) continue;
            if (!used[t.u] && !used[t.v]) {
                cl[t.u] = 0;
                cl[t.v] = 1;
            } else if (!used[t.u]) {
                cl[t.u] = 1 ^ cl[t.v];
            } else {
                cl[t.v] = 1 ^ cl[t.u];
            }
            ans[t.ind] = cd;
            DSU::merge(t.u, t.v);
            used[t.u] = 1;
            used[t.v] = 1;
        }
    }
    for (auto t : out) {
        if (used[t.v]) continue;
        if (!used[t.u]) continue;
        cl[t.v] = cl[t.u];
        ans[t.ind] = d[t.v] - d[t.u];
        used[t.v] = 1;
    }
}

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

    DSU::init();

    int n, m;
    cin >> n >> m;
    map<int, vector<int>> ind;
    for (int i = 0; i < n; i++) {
        cin >> d[i];
        ind[d[i]].push_back(i);
    }
    map<int, vector<Edge>> in;
    map<int, vector<Edge>> out;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        assert(u != v);
        if (d[u] > d[v]) swap(u, v);
        if (d[u] == d[v]) {
            in[d[u]].push_back(Edge(u, v, i));
        }  else {
            out[d[v]].push_back(Edge(u, v, i));
        }
    }
    fill(ans, ans + m, INF);
    fill(cl, cl + N, -1);
    for (auto t : ind) {
        run(t.first, in[t.first], out[t.first]);
    }
    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            cout << -1 << endl;
            exit(0);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << (cl[i] ? 'B' : 'W');
    }
    cout << endl;
    for (int i = 0; i < m; i++) {
        cout << ans[i] << '\n';
    }
}   


Measured memory_bytes: 33616
def dfs(s)
  
  return 0 if s.to_i > N
  
  ans = 0
  ans = 1 if s.include?(?7) && s.include?(?5) && s.include?(?3) 
  
  "753".chars do |c|
    ans += dfs( s + c )
  end
  
  ans
end

N = gets.to_i

p dfs('0')

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

#define MAX 200000

int N;
vector<int> G[MAX];
bool visited[MAX];
int prenum[MAX],parent[MAX],lowest[MAX],timer;
vector<P> bridge;

void dfs(int v,int prev){
	prenum[v]=lowest[v]=timer;
	timer++;
	visited[v]=true;

	int next;
	for(int i=0;i<G[v].size();i++){
		next=G[v][i];
		if(!visited[next]){
			parent[next]=v;
			dfs(next,v);
			lowest[v]=min(lowest[v],lowest[next]);
			if(prenum[v]<lowest[G[v][i]])bridge.push_back(P(min(v,G[v][i]),max(v,G[v][i])));
		}else if(next!=prev){
			lowest[v]=min(lowest[v],prenum[next]);
		}
	}
}


set<int> art_points(){
	for(int i=0;i<N;i++){
		visited[i]=false;
	}
	timer=1;
	dfs(0,-1);
	set<int> ap;
	int np=0;
	for(int i=1;i<N;i++){
		int p=parent[i];
		if(p==0)np++;
		else if(prenum[p]<lowest[i])ap.insert(p);
	}
	if(np>1)ap.insert(0);
	return ap;
}

int n,m;

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	art_points();
	printf("%d\n",bridge.size());
	return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int k;
  string s;
  cin >> k >> s;
  if (s.size() <= k) {
    cout << s << '\n';
  } else {
    for (int i = 0; i < k; ++i) {
      cout << s[i];
    }

    cout << "..." << '\n';
  }
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define all(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };

int main() {
	int n;
	cin >> n;
	int a[100];
	rep(i, n) {
		cin >> a[i];
	}
	int cnt = 0;
	rep(i, n - 1) {
		if (a[i] == a[i + 1]) {
			a[i + 1] = 10001 + i;
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

const long long MIN = 0;
const int MAX_NUM = 100000;

int N;
int h[MAX_NUM][3];

// dp[i][j] := i日目での満足度最大値(最後の活動をjとする)
//             j = 0) A
//               = 1) B
//               = 2) C
long long dp[MAX_NUM + 1][3];
//dp[i + 1][j] = ::max( d[i][k] + h[i][j] ) ( j != k )

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

	dp[0][0] = dp[0][1] = dp[0][2] = 0;

	for ( int i = 0; i < N; ++i ) {
		for ( int j = 0; j < 3; ++j ) {
			long long res = MIN;
			for ( int k = 0; k < 3; ++k ) {
				if ( j == k ) continue;
				res = ::max( res,
							 dp[i][k] + h[i][j] );
			}
			dp[i + 1][j] = res;
		}
	}

	cout << ::max( ::max( dp[N][0], dp[N][1] ), dp[N][2] ) << endl;
	return 0;
}

Measured memory_bytes: 3712
from collections import Counter
n = int(input())
ct_ls = []
for i in range(n):
    ct_ls.append("".join(sorted(input())))
ct = Counter(ct_ls)
_ct = 0
for n in ct.values():
    if n >= 2:
        _ct += n * (n - 1) / 2
print(int(_ct))

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

#define ll long long int
#define ld long double
#define mod 1000000007
#define big 1e18+10
#define small -big
#define endl "\n"
#define pb push_back




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


    ll t=1;
    //cin >> t;

    while(t--)
    {
        ll n;
        
        cin >> n;
        
        ll A[n+1][4];
        
        memset(A, 0, sizeof(A));
        
        for(ll i = 1; i <= n; i++)
        {
             
            
            for(ll j = 1; j <= 3; j++)
            { 
                
                ll a;
                cin >> a;
                
                for(ll k = 1; k <= 3; k++)
                {
                    if(j!=k)
                    {
                        A[i][j] = max(A[i][j], A[i-1][k]+a);
                    }
                }
            }
            
            
        }
        
        
        cout << max({A[n][1], A[n][2], A[n][3]}) << endl;

         
    }


    return 0;
        
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define mt make_tuple
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define forn(i, a) for(int i=0; i<a; i++)
#define Forn(i, a) for(int i=1; i<=a; i++)
#define read(x) ((scanf("%s", &_), (x) = _))
#define INF 1e9
#define memINF 127
#define inf 1e18
#define all(x) x.begin(), x.end()
#define MOD 1e9+7 
#define HASH 1543 

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;

using namespace std;

inline int in() 
{
    int x=0, c;
    for(; (uint)((c=getchar())-'0')>=10;) 
	{ 
		if(c=='-') 
			return -in(); 
		if(!~c)
			throw ~0; 
	}
    do 
	{ 
		x=(x<<3)+(x<<1)+(c^48); 
	} 
	while((uint)((c=getchar())^48)<10);
    return x;
}
inline int gcd(int a, int b){if(a>b) swap(a, b); return a==0?b:gcd(b%a, a);}
inline int lcm(int a, int b){return a*b/gcd(a, b);}

struct E
{
	int ed, c, nex;
}e[400005];

int N, M, dist[200010], a, b, c, t, ru[200010];
bool vis[200010];
unordered_set<int> inr[200010], m;

inline void INS(int st, int ed, int c)
{
	e[++t].ed=ed,
	e[t].c=c,
	e[t].nex=ru[st],
	ru[st]=t;
}

int main()
{
	while(~scanf("%d %d",&N,&M))
	{
		memset(vis, false, sizeof(vis));
		memset(dist, 63, sizeof(dist));
		memset(e, 0, sizeof(e));
		memset(ru, 0, sizeof(ru));
		t=0;
		Forn(i, 200001)
			inr[i].clear();
		while(M--)
		{
			a=in(), b=in(), c=in();
			INS(a, b, c);
			INS(b, a, c);
		}
		priority_queue<pi> q;
		dist[1]=0;
		vis[1]=true;
		q.push(mp(0, 1));
		while(!q.empty())
		{
			int st=q.top().s, cost=-q.top().f;
			q.pop();
			vis[st]=true;
			if(cost>dist[st])
				continue;
			for(int i=ru[st]; i>0; i=e[i].nex)
			{
				int ed=e[i].ed, c=e[i].c, d=dist[st]+(!inr[st].count(c));
				if(vis[ed]||dist[ed]<d)
					continue;
				if(dist[ed]>d)
				{
					dist[ed]=d;
					q.push(mp(-d, ed));
					inr[ed].clear();
				}
				inr[ed].insert(c);
			}
		}
		if(dist[N]>INF)
			puts("-1");
		else
			printf("%d\n", dist[N]);
	}
	return 0;
}


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

using namespace std;

#define int long long

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

  map<string,int> mp;
  while (n--) {
    string s;
    cin >> s;
    mp[move(s)];
  }

  cout << mp.size() << '\n';

  return 0;
}

Measured memory_bytes: 19248
#include <stdio.h>

int main() {

    int i,s;
    i = s = 0;
    int x[10000];

    while(1){
    	scanf("%d", &x[i]);
    	i++;
    	if(x[i-1]==0){
    		break;
    	}
    }

    for(s=0;s<i-1;s++){
    	printf("Case %d: %d\n",s+1, x[s]);
    }

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  string s;
  cin>>s;

  ll sum=0;

  for(ll i=0;i<=3;i++)
  {
      if(s[i]=='+')
      {
          sum=sum+1;
      }
      else
      {
          sum=sum-1;
      }
  }

  cout<<sum<<endl;
}


Measured memory_bytes: 256