akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
typedef long long ll;
const long long llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=2e3+5;
const int mod=1e9+7;
using namespace std;
int n,m,q,dp1[nmax][nmax],dp2[nmax][nmax],dp3[nmax][nmax],i,j;
char a[nmax][nmax];
int main()
{
	//freopen("sol.in","r",stdin);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>m>>q;
    for(i=1;i<=n;i++)
     for(j=1;j<=m;j++)
	 {
        cin>>a[i][j];
        dp1[i][j]=dp1[i-1][j]+dp1[i][j-1]-dp1[i-1][j-1]+(int)(a[i][j]=='1');
        dp2[i][j]=dp2[i-1][j]+dp2[i][j-1]-dp2[i-1][j-1]+(int)(a[i][j]=='1' && a[i][j-1]=='1');
        dp3[i][j]=dp3[i-1][j]+dp3[i][j-1]-dp3[i-1][j-1]+(int)(a[i][j]=='1' && a[i-1][j]=='1');
     }
    while(q--)
    {
    	int x1,x2,y1,y2;
        cin>>x1>>y1>>x2>>y2;
        cout<<dp1[x2][y2]-dp1[x1-1][y2]-dp1[x2][y1-1]+dp1[x1-1][y1-1]-(dp2[x2][y2]-dp2[x1-1][y2]-dp2[x2][y1]+dp2[x1-1][y1])-(dp3[x2][y2]-dp3[x1][y2]-dp3[x2][y1-1]+dp3[x1][y1-1])<<endl;
    }
	return 0;
}

Measured memory_bytes: 52864
#include<bits/stdc++.h>
using namespace std;
#define ioS            ios::sync_with_stdio(false);cin.tie(0);
#define li             long int
#define ll            long li
#define ull            unsigned ll
#define pi             pair<int,int>
#define vi             vector<int>
#define vli            vector<li>
#define vll           vector<ll>
#define vvi            vector<vector<int>>
#define pb             push_back
#define mp             make_pair
#define forn(i,s,n)    for(auto i=s;i<n;++i)               
#define forr(i,s,n)    for(auto i=s;i>=n;--i) 
const ll MOD = 1e9+7;
const li mx = 1e6+1; 
void solve()
{
    int n,a,b;
    cin>>n>>a>>b;
    vi p(n);
    forn(i,0,n)
        cin>>p[i];
    int prob[3]={0};
    forn(i,0,n)
        prob[(p[i]>a)+(p[i]>b)]++;
    cout<<min(prob[0],min(prob[1],prob[2]))<<endl;
}
int32_t main()
{
    ioS
    int t;
    // cin>>t;
    // while(t--)
        solve();
}


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


int A,B,K;

int main(){
    cin>>A>>B>>K;

    for (size_t i = min(A,B); i > 0; i--)
    {
        if (A % i == 0 && B % i == 0) {
            K--;
        }
        if (K == 0) {
            cout<<i<<endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int N;

class Circle{
public:
    D x, y, z, r;
    Circle(D x, D y, D z, D r): x(x), y(y), z(z), r(r){};
};

class Edge{
public:
    int to;
    double cost;
    Edge(int to, double cost): to(to), cost(cost){};
    
    bool operator > (const Edge& right) const{
        return cost > right.cost;
    }
};

D prim(vector<vector<Edge>>& G, int root){
    int V = G.size();
    D res = 0;
    vector<bool> visited(V, false);
    priority_queue<Edge, vector<Edge>, greater<Edge>> queue;
    queue.push(Edge(root, 0));
    
    while(!queue.empty()){
        auto edge = queue.top(); queue.pop();
        if(visited[edge.to])
            continue;
        res += edge.cost;
        visited[edge.to] = true;
        for(int i=0; i<G[edge.to].size(); i++){
            if(!visited[G[edge.to][i].to])
                queue.push(G[edge.to][i]);
        }
    }
    return res;
}

D dist(Circle& c1, Circle& c2){
    //???????????????????????????0?????????
    D d1 = sqrt((c1.x-c2.x)*(c1.x-c2.x) + (c1.y-c2.y)*(c1.y-c2.y) + (c1.z-c2.z)*(c1.z-c2.z));
    D d2 = abs(c1.r-c2.r);
    
    return GE(d1, d2) ? max(d1-c1.r-c2.r, 0.0) : 0;
}

void solve(){
    vector<Circle> circles;
    for(int i=0; i<N; i++){
        D x, y, z, r; cin >> x >> y >> z >> r;
        circles.push_back(Circle(x, y, z, r));
    }
    vector<vector<Edge>> G(N);
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            double d = dist(circles[i], circles[j]);
            G[i].push_back(Edge(j, d));
        }
    }
    printf("%.3lf\n", prim(G, 0));
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    cout.precision(16);
    
    while(cin>>N, N)
        solve();
    
    return 0;
}

Measured memory_bytes: 1640
from collections import deque

K = int(input())

Q = deque([1,2,3,4,5,6,7,8,9])

for i in range(K-1):
    x = Q.popleft()
    if x % 10 != 0:
        Q.append(10*x+x%10-1)
    Q.append(10*x+x%10)
    if x % 10 != 9:
        Q.append(10*x+x%10+1)

print(Q.popleft())

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

long long prime[100001];
bool is_prime[100002];

long long sieve(long long n){
    long long p = 0;
    for(long long i = 0; i <= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(long long i = 2; i <= n; i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(long long j = 2*i; j <= n; j+= i)
                is_prime[j] = false;
        }
    }
    return p;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, cnt, tmp, i;
    cin >> N;
    tmp = sieve(100001);
    cnt = 0, i = 0;
    while(cnt < N && i < tmp){
        if(prime[i++]%5 == 1){
            cout << prime[i-1] << " ";
            cnt++;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 384
var
	s:array[1..100]of String[100];
	h,w,i,j:Longint;
	f:Boolean;
	b:array[1..100]of Boolean;
begin
	readln(h,w);
	for i:=1 to h do readln(s[i]);
	for j:=1 to w do begin
		b[j]:=false;
		for i:=1 to h do
			if s[i][j]='#' then begin
				b[j]:=true;
				break;
			end;
	end;
	for i:=1 to h do begin
		f:=false;
		for j:=1 to w do
			if s[i][j]='#' then begin
				f:=true;
				break;
			end;
		if f then begin
			for j:=1 to w do
				if b[j] then write(s[i][j]);
			writeln('');
		end;
	end;
end.


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long n,a,b;
int main()
{
    cin>>n>>a>>b;
    if(a==b)cout<<1;
    else if(a>b)cout<<0;
    else
    {
        if(n==1)cout<<0;
        else{
            long long s=(n-2)*(b-a)+1;
            cout<<s;
        }
    }
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        //int N = str.length();
        //char[] c = str.toCharArray();
        int count = 0;
        int count0 = 0;
        int count1 = 0;
        boolean test = true;
        
        //while(test && str.length()>1){
        for(int i=0; i<str.length(); i++){
            if(str.charAt(i)=='0'){
                count0++;
                //System.out.println(0+":"+count0);
            }else{
                count1++;
                //System.out.println(1+":"+count1);
            }
        }
        if(count0<count1){
            count = count0;
        }else{
            count = count1;
        }
        //}
        System.out.println(count*2);
    }
}

Measured memory_bytes: 39660
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a, T b) { a = min(a, b); }
template<class T> void umax(T &a, T b) { a = max(a, b); }

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

const int mod = 1e9+7;
const int N = 2e5+5;

void solve(){
	//int x1,y1,x2,y2;
	//cin>>x1>>y1>>x2>>y2;
	int n;
	cin>>n;
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			if(i*4+j*7==n){
				cout<<"Yes";
				return;
			}
		}
	}
	cout<<"No";

}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

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

using namespace std;

int main() {
  int n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;

  string m = "";
  for (int i = 0; i < n; i++) {
    int j = i - k;
    if (j < 0) {
      if (t[i] == 'r') m += 'p';
      if (t[i] == 's') m += 'r';
      if (t[i] == 'p') m += 's';
      continue;
    }
    if (t[i] == t[j]) {
      if (t[i] == 'r') {
        if (m[j] == 'p')
          m += 'r';
        else
          m += 'p';
      }
      if (t[i] == 's') {
        if (m[j] == 'r')
          m += 's';
        else
          m += 'r';
      }
      if (t[i] == 'p') {
        if (m[j] == 's')
          m += 'p';
        else
          m += 's';
      }
    } else {
      if (t[i] == 'r') m += 'p';
      if (t[i] == 's') m += 'r';
      if (t[i] == 'p') m += 's';
    }
  }

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (t[i] != m[i]) {
      if (t[i] == 'r') ans += p;
      if (t[i] == 's') ans += r;
      if (t[i] == 'p') ans += s;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(){

  int x,y,t,gcd;

  scanf("%d %d",&x,&y);

  if(x < y){
    t = x;
    x = y;
    y = t;
  }

  while(y >0){
    gcd = x % y;
    x = y;
    y = gcd;
  }
  printf("%d\n",x);
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll k, q;
    cin >> k >> q;
    vector<ll> d(k);
    REP(i, k){
        cin >> d.at(i);
    }

    REP(i, q){
        ll n, x, m;
        cin >> n >> x >> m;
        ll ans = n - 1;
        ll last = x;
        REP(j, k){
            const ll dj = d.at(j) % m;
            const ll num = max(0LL, (n - 1 - j + k - 1) / k);
            last += dj * num;
            if(dj == 0){
                ans -= num;
            }
        }
        ans -= last / m - x / m;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 384
N = gets.to_i
S = gets.chomp.split(//)

cnt = 0
ary = [0]
S.each_with_index do |c, ix|
  cnt += 1 if c == '#'
  ary << cnt
end
# p ary

min = N
(N + 1).times do |x|
  left_b = ary[x]
  right_b = ary[N] - left_b
  right_w = N - x - right_b

  cost = left_b + right_w
  min = [min, cost].min
end
puts min


Measured memory_bytes: 18428
N,K  = map(int,input().split())
nums = list(map(int,input().split()))
# preprocess
#
for i in range(len(nums)):
    nums[i] =  (nums[i] + 1)/2

ans = -1
ans = cand =  sum(nums[:K])
for i in range(K,len(nums)):
    cand = cand - nums[i - K] +  nums[i]
    ans = max(cand,ans)

print(ans)

Measured memory_bytes: 71792
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define inf 100000000000000000
#define ll long long 
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define test ll t ; cin>>t; while(t--)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	
	ll n ;
	cin>> n ;
	ll ans = ceil(n/2.0);
	cout<<ans<<endl;
	return 0;
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define ford(i, n) for (int i = int(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define endl '\n'
#define de(x) cout<<#x<<" = "<<(x)<<endl
#define de2(x,y) cout<<#x<<" = "<<(x) <<' '<< #y<<" = "<<y<<endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N=1e5+5;
ll dp[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int N,W;
	cin>>N>>W;
	forn(i,N){
		int w,v;
		cin>>w>>v;
		for(int j=W;j>=w;j--){
			dp[j]=max(dp[j],dp[j-w]+v);
		}
	}
	cout<<dp[W];
    return 0;
}



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

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

int main(){
    int n,count=0;
    cin >> n;
    char s[n];
    rep(i,n) cin >> s[i];

    rep(i,n-2){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') count++;
    }
    cout << count <<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int n; cin >> n;
  int sum = 0, a;
  REP(i, n) {
    cin >> a;
    sum += a - 1;
  }
  cout << sum << endl;
}


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

using namespace std;

#define REP(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";

template <typename T>
using V = vector<T>;

typedef long double ld;


int N;

int64_t solve(V<int64_t> A) {
	int64_t sum = A[0], ans = 0;
	for (int i = 1; i < N; ++i) {
		int64_t next = sum + A[i];
		// cout << next << endl;
		if (next == 0) {
			++ans;
			if (sum < 0)
				next = 1;
			else
				next = -1;
		} else if (sum < 0) {
			if (next < 0) {
				ans += abs(next)+1;
				next = 1;
			}
		} else {
			if (next > 0) {
				ans += next+1;
				next = -1;
			}
		}
		sum = next;
	}
	return ans;
}

int64_t solve_fast(V<int64_t> A) {
	int64_t ans, tmp = A[0];
	if (A[0] <= 0)
		A[0] = 1;
	ans = abs(A[0]-tmp)+solve(A);
	A[0] = tmp;
	if (A[0] >= 0)
		A[0] = -1;
	ans = min(ans, abs(A[0]-tmp)+solve(A));
	return ans;
}

V<int64_t> A;

V<V<int64_t>> DP(50000, V<int64_t>(10, -1));

int64_t f(int psum, int i) {
	if (i == A.size())
		return 0;

	if (DP[psum+10000][i] != -1)
		return DP[psum+10000][i];
	int64_t ans = 1e18, sum = psum + A[i];

	for (int v = -100; v <= 100; ++v) {
		if (psum < 0 && psum + v > 0) {
			ans = min(ans, f(psum+v, i+1)+abs(A[i]-v));
		} else if (psum > 0 && psum + v < 0) {
			ans = min(ans, f(psum+v, i+1)+abs(A[i]-v));
		}
	}
	return DP[psum+10000][i] = ans;
}


int solve_kek() {
	int64_t ans = 1e9;
	for (int v = -100; v <= 100; ++v) if (v != 0) {
		ans = min(ans, f(v, 1)+abs(A[0]-v));
	}
	return ans;
}

void test() {
	default_random_engine re;
	for (int tc = 0; tc < 1000; ++tc) {
		N = re()%4+1;
		A.resize(N);
		for (int64_t& e : A) {
			e = re()%6 - 3;
		}
		cout << N << endl;
		for (auto e : A) {
			cout << e << " ";
		}
		cout << endl;
		cout << solve_kek()<< " " << solve_fast(A) << endl;
		assert(solve_kek() == solve_fast(A));
	}
}


int main() {
	// test();
	// return 0;
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> N;

	A.resize(N);

	READALL(A);


	cout << solve_fast(A) << endl;

	// cout << solve_kek() << endl;
	
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);    
	int n;
	cin >> n;
	bool check = true;
	while (n--) {
		int a;
		cin >> a;
		if (a & 1) {
			check = false;
			break;
		}
	}         
	if (check) {
		cout << "second\n";
	} else {
		cout << "first\n";
	}           
	return 0;
}




Measured memory_bytes: 256
n, m, c = map(int, input().split())
bm = list(map(int, input().split()))
anm = [list(map(int, input().split())) for _ in range(n)]

res = 0
count = 0
for i in range(n):
    res = 0
    for j in range(m):
        res += anm[i][j]*bm[j]

    res += c
    if res > 0:
        count += 1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>
#include <cassert>

using namespace std;

const int mod = 1e9 + 7;

long long modpow(long long a, long long n, long long mod) {
	long long ret = 1;

	while (n > 0) {
		if (n & 1) {
			ret = ret * a % mod;
		}

		a = a * a % mod;
		n >>= 1;
	}

	return ret;
}

// aの逆元
long long modinv(long long a, long long mod) {
	assert(gcd(a, mod) == 1);
	// TODO assert(modが素数)
	return modpow(a, mod - 2, mod);
}

class Combination {
public:
	vector<long long> fact, ifact;
	long long mod;
public:
	Combination(int n, int mod) : fact(n+1), ifact(n+1), mod(mod) {
		fact[0] = 1;
		for (int i = 1; i <= n; i++) {
			fact[i] = fact[i-1] * i % mod;
		}
		ifact[n] = modinv(fact[n], mod);
		for (int i = n; i > 0; i--) {
			ifact[i-1] = ifact[i] * i % mod;
		}
	};
	// ~Combination();

	// nCk
	long long comb(int n, int k) {
		assert(n >= 0);
		assert(0 <= k && k <= n);
		return fact[n] * ifact[k] % mod * ifact[n-k] % mod;
	}

	// nPk
	long long perm(int n, int k) {
		assert(n >= 0);
		assert(0 <= k && k <= n);
		return fact[n] * ifact[n - k] % mod;
	}

	// nHk n種類から重複を許してk個
	long long h(int n, int k) {
		return comb(n - k + 1, k);
	}
};

int main() {
	int s;
	cin >> s;

	Combination com(1e6, mod);

	long long ans = 0;
	for (int n_part = 1; n_part <= s / 3; n_part++) {
		int rest = s - n_part * 3;

// fprintf(stderr, "n_part %d\n", n_part);
// fprintf(stderr, "rest   %d\n", rest);
// fprintf(stderr, "comb   %lld\n", com.comb(n_part - 1 + rest, rest));

		ans += com.comb(n_part - 1 + rest, rest);
		ans %= mod;
	}

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


Measured memory_bytes: 18412
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	ll N=0;
	string S;
	cin>>N>>S;
	ll t=0;
	t=N;
	vector<ll> ruiseki(t);
	FDS(i,t-1){
		if(S.at(i)=='E'){
			ruiseki[i]++;
		}
		ruiseki[i+1]=ruiseki[i];
	}
	if(S.at(t-1)=='E'){
			ruiseki[t-1]++;
	}
	ll sum=0;
	ll aaa=ruiseki[t-1]-ruiseki[1];
	ll bbb=t-1-ruiseki[t-2];
	sum=min(aaa,bbb);
	for(ll i=1;i<t-1;i++){
		ll sub=0;
		sub=(i-ruiseki[i-1])+(ruiseki[t-1]-ruiseki[i]);
		sum=min(sum,sub);
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 3076
# https://atcoder.jp/contests/abc106/tasks/abc106_d
# 何も見ずにやり直してみる

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


class cumsum2d:  # 二次元累積和クラス pypyでも使えるよ
    def __init__(self, ls: list):
        '''
        2次元のリストを受け取る
        '''
        from itertools import product
        H = len(ls)
        W = len(ls[0])
        self.ls_accum = [[0] * (W + 1)]
        for l in ls:
            self.ls_accum.append([0] + l)

        # 縦に累積
        for i, j in product(range(1, H + 1), range(1, W + 1)):
            self.ls_accum[i][j] += self.ls_accum[i - 1][j]
        # 横に累積
        for i, j in product(range(1, H + 1), range(1, W + 1)):
            self.ls_accum[i][j] += self.ls_accum[i][j - 1]

    def total(self, i1, j1, i2, j2):
        '''
        点(i1,j1),(i1,j2),(i2,j1),(i2,j2)の4点が成す四角の中の合計を取り出す
        ただし i1<=i2, j1<=j2
        ただし、i軸に関しては[i1,i2),j軸に関しては[j1,j2)の半開区間である
        '''
        return self.ls_accum[i2][j2] - self.ls_accum[i1][j2] \
            - self.ls_accum[i2][j1] + self.ls_accum[i1][j1]


N, M, Q = read_ints()

# 列車を二次元座標に代入
table = [[0] * N for _ in range(N)]  # 都市はそれぞれ-1扱い
for _ in range(M):
    L, R = read_ints()
    table[L - 1][R - 1] += 1

# 二次元累積和を取る
table = cumsum2d(table)

# クエリに答える
for _ in range(Q):
    p, q = read_ints()
    p -= 1
    q -= 1
    print(table.total(p, p, q + 1, q + 1))


Measured memory_bytes: 59356
#include <bits/stdc++.h>
using namespace std;
long long int dp[3001][3001][4];
long long int sc[3001][3001];
int main(){
    int R,C,k;
    cin >> R >> C >> k;
    int r,c;
    long long int v;
    for(int i=0;i<k;i++){
        cin >> r >> c >> v;
        r --; c--;
        sc[r][c]=v;
    }
    for(int i=0;i<R;i++){
        for(int j=0;j<C;j++){
            for(int m=0;m<4;m++){
                 if(sc[i][j]>0 && m<3){
                    dp[i][j+1][m+1]=max(dp[i][j][m]+sc[i][j],dp[i][j+1][m+1]);
                    dp[i+1][j][0]=max(dp[i][j][m]+sc[i][j],dp[i+1][j][0]);
                 }
                dp[i][j+1][m]=max(dp[i][j][m],dp[i][j+1][m]);
                dp[i+1][j][0]=max(dp[i][j][m],dp[i+1][j][0]);            
            }
        }
    }
    cout << dp[R][C-1][0];
}

Measured memory_bytes: 355272
#include <stdio.h>
int main(){   
 int a, b;    
char op;    
while(1){        
scanf("%d %c %d", &a, &op, &b);        
if(op=='?'){            
break;        
}
else if(op=='+'){            
printf("%d\n", a+b);        
}
else if(op=='-')
{           
 printf("%d\n", a-b);        
}
else if(op=='*'){            
printf("%d\n", a*b);        
}
else if(op=='/'){            
printf("%d\n", a/b);        
}    
}    
return 0;
}


Measured memory_bytes: 2072
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define INPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.in"
#define OUTPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.out"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

void solve()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d);
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
    //freopen(INPUT, "r", stdin);freopen(OUTPUT, "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20;
int n, f[maxn + 1][(1 << maxn) + 10], K;
int g[maxn + 1][(1 << maxn) + 10];
char s[(1 << maxn) + 10];
int sum[(1 << maxn) + 10], h[(1 << maxn) + 10];
int ansl, ans;

int ctz(int x) {
	return x ? h[x] : 32;
}

int main() {
	for (int i = 1; i < 1 << maxn; ++i) h[i] = i & 1 ? 0 : h[i >> 1] + 1;
	scanf("%d%d", &n, &K);
	for (int i = 0; i <= n; ++i) {
		scanf("%s", s);
		for (int j = 0; j < 1 << i; ++j)
			if (s[j] == '1') ++f[i][j];
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= n; ++j)
			for (int k = 0; k < 1 << j; ++k) g[j][k] = 0;
		for (int j = i + 1; j <= n; ++j)
			for (int k = 0; k < 1 << j; ++k) {
				int d = ctz(k >> i);
				if (d < j - i)
					g[j - d][((k >> (i + d)) << i) | (k & ((1 << i) - 1))] += f[j][k];
				d = ctz((k >> i) ^ ((1 << (j - i)) - 1));
				if (d < j - i)
					g[j - d][((k >> (i + d)) << i) | (k & ((1 << i) - 1))] += f[j][k];
			}
		for (int j = 0; j <= n; ++j)
			for (int k = 0; k < 1 << j; ++k) f[j][k] = g[j][k];
		for (int j = 0; j < (1 << (i + 1)); ++j) sum[j] = 0;
		for (int j = i + 1; j <= n; ++j)
			for (int k = 0; k < (1 << j); ++k)
				sum[k & ((1 << (i + 1)) - 1)] += f[j][k];
		for (int j = (1 << (i + 1)) - 1; j >= 0; --j)
			if (sum[j] >= K) {
				ansl = i + 1; ans = j;
			}
	}
	for (int i = ansl - 1; i >= 0; --i)
		printf("%d", ans >> i & 1);
}

Measured memory_bytes: 107904
use std::io::*;
use std::str::FromStr;

const MOD: usize = 1_000_000_007;

fn check(v: [char; 4]) -> bool {
    let po = ['A', 'G', 'C'];
    for i in 0..4 {
        for j in i..4 {
            if i == 0 && j > 1 {
                continue;
            }
            if i == 1 && j > 2 {
                continue;
            }
            let mut ok = true;
            for k in 0..3 {
                if k == i {
                    if v[j] != po[k] {
                        ok = false;
                    }
                } else if k == j {
                    if v[i] != po[k] {
                        ok = false;
                    }
                } else {
                    if v[k] != po[k] {
                        ok = false;
                    }
                }
            }
            if ok {
                return true;
            }
            ok = true;
            for k in 1..4 {
                if k == i {
                    if v[j] != po[k-1] {
                        ok = false;
                    }
                } else if k == j {
                    if v[i] != po[k-1] {
                        ok = false;
                    }
                } else {
                    if v[k] != po[k-1] {
                        ok = false;
                    }
                }
            }
            if ok {
                return true;
            }
        }
    }
    return false;
}

fn main() {
    let n: usize = read();
    
    let po = ['A', 'C', 'G', 'T'];
    let mut dp = vec![[[[0; 4]; 4]; 4]; n];
    for i in 0..4 {
        for j in 0..4 {
            for k in 0..4 {
                let nya = [['A','G','C'], ['A','C','G'], ['G','A','C']];
                let mut ok = true;
                for l in 0..3 {
                    if po[i] == nya[l][0] && po[j] == nya[l][1] && po[k] == nya[l][2] {
                        ok = false;
                    }
                }
                dp[0][i][j][k] = if ok {1} else {0};
            }
        }
    }
    for i in 0..n-3 {
        for j in 0..4 {
            for k in 0..4 {
                for l in 0..4 {
                    for m in 0..4 {
                        if !check([po[j], po[k], po[l], po[m]]) {
                            dp[i+1][k][l][m] += dp[i][j][k][l];
                            dp[i+1][k][l][m] %= MOD;
                        }
                    }
                }
            }
        }
    }
    let mut ans = 0;
    for j in 0..4 {
        for k in 0..4 {
            for l in 0..4 {
                ans += dp[n-3][j][k][l];
                ans %= MOD;
            }
        }
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		ArrayList<Integer> list = new ArrayList<>();
		int[] d = new int[K];
		Set<Integer> set = new HashSet<>();
		for(int i = 0; i < K; i++) {
			d[i] = Integer.parseInt(sc.next());
			for(int j = 0; j < d[i]; j++) {
				set.add(Integer.parseInt(sc.next()));
			}
		}
		for(int i = 0; i < N; i++) {
			list.add(i + 1);
		}
		//リストから抜く
		System.out.println(list.size() - set.size());
		sc.close();

	}

}

Measured memory_bytes: 41552
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int N;
  cin >> N;
  
  vector<int>A(N);
  vector<int>B(N,0);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (i >= N/2){
      B.at(i) = A.at(i);
    }
  }
  
  for (int i = N/2; i > 0; i--) {
    int judge = 0;
    for (int j = 1; j <= N/i; j++) {
      if (B.at(i*j-1) == 1){
        judge++;
      }
    }
    if (judge % 2 != A.at(i-1)){
      B.at(i-1) = 1;
    }
  }
  
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (B.at(i) == 1){
      count++;
    }
  }
  cout << count << endl;
  for (int i = 0; i < N; i++) {
    if (B.at(i) == 1){
      cout << i+1;
      count--;
      if (count != 0){
        cout << ' ';
      }
    }
  }
  cout << endl;
}
      
    
      
  
  
  
 

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

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n, m, len;
  scanf("%d%d%d", &n, &m, &len);
  vector<int> a(n), b(m);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < m; ++i) scanf("%d", &b[i]);
  int u = *min_element(a.begin(), a.end());
  int v = *min_element(b.begin(), b.end());
  int ret = u + v;
  for (int i = 0; i < len; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    --x; --y;
    int cur = a[x] + b[y] - z;
    ret = min(ret, cur);
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main{
public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    String a = scan.nextLine();
    String line = scan.nextLine();
    String[] array = line.split(" ");
    for(int i = array.length-1;i>=0;i--){
        if(i!=0){
            System.out.print(array[i]+" ");
        }else{
            System.out.print(array[i]);
        }
    }
    System.out.println();
}
}


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {

    int n, a, b;
    cin >> n >> a >> b;

    cout << min(n * a, b) << endl;
    return 0;
}

Measured memory_bytes: 3616
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	for true {
		N, M := sc.nextInt(), sc.nextInt()
		if N == 0 && M == 0 {
			break
		}
		C := sc.nextIntSlice(M)
		X := sc.nextIntSlice(N)
		dp := make([][256]int, N+1)
		for i := 0; i < N+1; i++ {
			for j := 0; j < 256; j++ {
				dp[i][j] = INF
			}
		}
		dp[0][128] = 0
		for i := 0; i < N; i++ {
			for j := 0; j < 256; j++ {
				if dp[i][j] == INF {
					continue
				}
				for k := 0; k < M; k++ {
					nex := j + C[k]
					if nex < 0 {
						nex = 0
					}
					if nex > 255 {
						nex = 255
					}
					dp[i+1][nex] = min(dp[i+1][nex], dp[i][j]+pow(X[i]-nex, 2))
				}
			}
		}
		ans := INF
		for i := 0; i < 256; i++ {
			ans = min(ans, dp[N][i])
		}
		fmt.Fprintln(wtr, ans)
	}
}



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

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int n, d; cin >> n >> d;
    int a[n][d];
    for(int i = 0; i < n; i++)
        for(int j = 0; j < d; j++)
            cin >> a[i][j];

    int cnt = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            int res = 0;
            for(int k = 0; k < d; k++) res += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
            if(ceil(sqrt(res)) == floor(sqrt(res))) cnt++; 
        }
    }
    cout << cnt;
}

Measured memory_bytes: 3692
H, W = gets.chomp.split.map(&:to_i)
s = []
H.times do |i|
  s[i] = gets.chomp.split('')
end

ans = 0

H.times do |i|
  W.times do |t|
    next if s[i][t] == '#'
    arrived = []
    H.times do |u|
      arrived[u] = Array.new(W, nil)
    end
    queue = [[i, t, 0]]
    while !queue.empty?
      y, x, index = queue.shift
      next if y < 0 || x < 0 || y >= H || x >= W
      next if s[y][x] == '#'
      next if arrived[y][x]
      arrived[y][x] = index
      index += 1
      queue.push([y+1, x, index], [y, x+1, index], [y-1, x, index], [y, x-1, index])
    end
    max = arrived.flatten.compact.max
    ans = [ans, max].max
  end
end

p ans


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

int main() {
    int x;
    cin >> x;

    if (x < 600) cout << 8 << endl;
    else if (x < 800) cout << 7 << endl;
    else if (x < 1000) cout << 6 << endl;
    else if (x < 1200) cout << 5 << endl;
    else if (x < 1400) cout << 4 << endl;
    else if (x < 1600) cout << 3 << endl;
    else if (x < 1800) cout << 2 << endl;
    else if (x < 2000) cout << 1 << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

int main() {
    int n; cin >> n;
    map<char,int> mp;
    rep(i,n) {
        string s; cin >> s;
        char c = s[0];
        if (c == 'M' || c == 'A' || c == 'R' || c == 'C' || c == 'H') {
            mp[c]++;
        }
    }
    vint x;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        x.push_back(itr->second);
    }
    ll ans = 0;
    for (int i = 0; i < x.size(); i++) {
        for (int j = i+1; j < x.size(); j++) {
            for (int l = j+1; l < x.size(); l++) {
                ans += (ll)x[i]*x[j]*x[l];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
 
const int N = int(2e5) + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e18; 
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int n, a[N], b[N];
int main (){
    scanf ("%d", &n);
    for (int i = 1; i <= n + 1; ++i) scanf ("%d", a + i);
    for (int i = 1; i <= n; ++i) scanf ("%d", b + i);
    ll ans = 0;
    for (int i = 1; i <= n; ++i){
        int cur = min(b[i], a[i]);
        b[i] -= cur;
        a[i] -= cur;
        ans += 1ll * cur;
        cur = min(b[i], a[i + 1]);
        b[i] -= cur;
        a[i + 1] -= cur;
        ans += 1ll * cur;
    }
    return !printf ("%lld\n", ans);
}

Measured memory_bytes: 1024
n,m = gets.split.map(&:to_i)
class UnionFind
  def initialize(size)
    @rank = Array.new(size,0)
    @parent = Array.new(size,&:itself)
  end
  def getRoot(x)
    @parent[x] == x ? x : (@parent[x] = getRoot(@parent[x]))
  end
  def unite(x,y)
    xp = getRoot(x)
    yp = getRoot(y)
    if xp == yp
      return
    elsif @rank[xp] > @rank[yp]
      @parent[yp] = xp
    else
      @parent[xp] = yp
      @rank[yp] += 1 if @rank[xp] = @rank[yp]
    end
  end
  def same?(x,y)
    getRoot(x) == getRoot(y)
  end
  def size
    @parent.map{|x| getRoot(x)}.uniq.size
  end
end
g = UnionFind.new(n)
m.times do
  x,y,z = gets.split.map(&:to_i)
  g.unite(x-1,y-1) if not g.same?(x-1,y-1)
end
puts g.size

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

const int limit = 100010;

int total = 1;
int nxt[limit][2];
int len[limit];
bool leaf[limit];


ll calc(ll level) {
	int cur = 0;
	while (level % 2 == 0){
		level /=2;
		cur++;
	}
	ll val = 1LL;
	rep(loop, cur) val *= 2LL;
	return val;
}

int main(void) {
	ll n, l;
	cin >> n >> l;


	rep(i, limit) {
		rep(j, 2) nxt[i][j] = -1;
		len[i] = 0;
	}

	rep(i, n) {
		string s;
		cin >> s;
		const ll m = s.size();

		int cur = 0;
		rep(j, m) {
			const int idx = s[j] - '0';
			if (nxt[cur][idx] == -1) {
				nxt[cur][idx] = total++;
				len[nxt[cur][idx]] = len[cur] + 1;
			}
			cur = nxt[cur][idx];
		}
		leaf[cur] = true;
	}


	ll grundy = 0LL;

	rep(i, total) {
		if(leaf[i]) continue;
		if (nxt[i][0] == -1) {
		//	cerr << i << " " << 0 << " " << len[i] << endl;
			grundy ^= calc(l  - len[i]);
		}
		if (nxt[i][1] == -1) {
		//	cerr << i << " " << 1 << " " << len[i] << endl;
			grundy ^= calc(l - len[i]);
		}
	}

	//cerr << grundy << endl;

	if (grundy)
		puts("Alice");
	else
		puts("Bob");


	return 0;
}

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

#define debug(n) cerr << #n << ':' << n << endl;

using namespace std;

using  ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using  vi = vector<int>;
using  vl = vector<ll>;
using  vd = vector<double>;
template<class T,class U>
using umap = unordered_map<T,U>;
template<class T>
using uset = unordered_set<T>;

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

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

template<class T>
inline void putv(const vector<T>&v,char c = '\n'){
  for(auto&&e:v){
    cout << e << c;
  }
}

template<class T>
inline void readv(vector<T>&v){
  if(v.empty()){
    cerr << "void readv(vector<T>&v) v.empty()\n";
  }
  for(auto&&e:v){
    cin >> e;
  }
}

int main(){
  string s;cin >> s;
  const int size = static_cast<int>(s.size());
  vector<int> v;
  char pre = 'R';
  int cnt = 0;
  for(int i = 0; i < size; ++i){
    if(s[i] == pre){
      cnt++;
    } else {
      v.push_back(cnt);
      pre = s[i];
      cnt = 1;
    }
  }
  vector<int> ans(size, 0);
  v.push_back(cnt);
  int sum = -1;  
  for(int i = 0; i < v.size(); i+=2){
    sum += v[i];
    if(v[i] % 2 == 0){
      ans[sum] += v[i]/2;
      ans[sum + 1] += v[i]/2;
    } else {
      ans[sum] += 1 + v[i] / 2;
      ans[sum + 1] += v[i]/2;
    }
    if(v[i + 1] % 2 == 0){
      ans[sum] += v[i + 1]/2;
      ans[sum + 1] += v[i + 1]/2;
    } else {
      ans[sum] += v[i + 1] / 2;
      ans[sum + 1] += 1 + v[i + 1]/2;
    }
    sum += v[i + 1];
  }
  for(int i = 0; i < size; ++i){
    if(i) cout << ' ';
    cout << ans[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1528
// 2020-06-28 21:34:59
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

const ll C = 26;
ll D;
vector<ll> cs(C), ts;
void answer() {
  cin >> D;
  rep(i, C) cin >> cs[i];
  vector<vector<ll> > ss(D, vector<ll>(C, 0));
  rep(i, D) rep(j, C) cin >> ss[i][j];
  ts.assign(D, 0);
  ts[0] = 1;
  ts[1] = 17;
  ts[2] = 13;
  ts[3] = 14;
  ts[4] = 13;
  rep(i, D) ts[i]--;
  map<ll, ll> last;
  rep(i, C) last[i] = 0;
  ll score = 0;
  rep(i, D) {
    ll now = 0, nowc = 0, d = i + 1;
    rep(j, C) {
      ll cur = ss[i][j];
      ll pastd = last[j];
      last[j] = d;
      rep(k, C) if(j != k) cur -= cs[j] * (d - last[k]);
      last[j] = pastd;
      if(chmax(now, cur)) {
        nowc = j;
      }
    }
    score += now;
    cout << nowc+1 << '\n';
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3752
import scala.io.Source.stdin

object Main extends App {
  stdin.getLines.foreach { s =>
    val n = s.split(" ").map(_.toInt)
    if((1 to 10).filter( i => i!=n(0) && i!=n(1) && i!=n(2) ).count( _ <= 20-(n(0)+n(1)) ) >= 4)
      println("YES")
    else
      println("NO")
  }
}

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

using namespace std;

#define all(a) a.begin(), a.end()
#define pi acos(-1)
#define eps 1e-6
#define inf 1e14

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[8] = {-1, 0, 1, -1, 1, 0, 1, -1};
const int maxn = 100;
const int mod = 1e9 + 7;
const int maxa = 1e5 + 1;

int mul(int a, int b) { return a * 1LL * b % mod;}
int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b;}
int sub(int a, int b) { return a >= b ? a - b : a - b + mod;}
int pow(int a, int k)
{
    int res = 1;
    while (k)
    {
        if (k % 2) res = mul(res, a);
        a = mul(a, a);
        k /= 2;
    }

    return res;
}

int inv(int a)
{
    return pow(a, mod - 2);
}

int W, n;
ll dp[maxa], cost[maxn], val[maxn], sum;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> W;
    fill(dp, dp + maxa, 1e9);
    for (int i = 0; i < n; ++i)
        cin >> cost[i] >> val[i], sum += val[i];

    dp[0] = 0;
    for (int i = 0; i < n; ++i)
        for (int v = sum - val[i]; v >= 0; --v)
            dp[v + val[i]] = min(dp[v + val[i]], dp[v] + cost[i]);
        
    for (int v = sum; v >= 0; --v)
        if (dp[v] <= W)
            return cout << v, 0;
}


Measured memory_bytes: 1024