akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 6060;
int n,l[N],r[N],a[N],res=1e9;char s[N],t[N];bool ok[N];
int dy(int x){x=(x+n*10000)%n;return x==0?n:x;}
void umax(int &x, int y){x=x>y?x:y;}
int solve(int t){
	int res=1e9;rep(i,0,n)a[i]=0;
	rep(i,1,n)if(ok[i]&&l[i])umax(a[l[i]-1],r[i]);
	for(int i=n,j=0;i>=0;i--){
		j=max(j,a[i]);
		if(t>0)res=min(res,(i+max(j,t))*2-t);
		else res=min(res,(max(i,-t)+j)*2+t);
	}
	return res;
}
int main() {
	scanf("%s%s",s+1,t+1);n=strlen(s+1);
	int c1=0,c2=0;rep(i,1,n)c1+=s[i]=='1',c2+=t[i]=='1';
	if(!c2){if(c1)puts("-1");else puts("0");return 0;}
	int lst=0;rep(i,-n+1,n){if(t[dy(i)]=='1')lst=i;if(i>=1)l[i]=i-lst;}
	per(i,2*n,1){if(t[dy(i)]=='1')lst=i;if(i<=n)r[i]=lst-i;}
	rep(q,-n,n){
		int tmp=0;rep(i,1,n)ok[i]=s[i]!=t[dy(i+q)],tmp+=ok[i];
		res=min(res,tmp+solve(q));
	}
	printf("%d",res);return 0;
}


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

using namespace std;

const int N = 2e4 + 5;

int n, m , A[N];

int main()
{
	cin >> n >> m;
	for(int i =0 ; i < m; ++i)
	{
		cin >> A[i];
		n -= A[i];
	}
	if(n < 0)
		puts("-1");
	else
		cout << n << endl;
	return 0;
}

Measured memory_bytes: 3644
//Littleboy123 Template 1.6
#include <bits/stdc++.h>
using namespace std;

//pragmas
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

const long double pi = acos(-1.0);

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define COUT(n) printf("%d\n", (n))
#define COUTLL(n) printf("%lld\n", (n))
#define CIN(n) scanf("%d", &(n))
#define CINLL(n) scanf("%lld", &(n))
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

void init(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

void infile(){
	freopen("input.in", "r", stdin);
}

void outfile(){
	freopen("output.out", "w", stdout);
}

ll modex(ll a, ll b, ll mod){
	if(b == 0)
		return 1;
	if(b == 1)
		return a;
	ll tmp = modex(a, b/2, mod);
	tmp = (tmp * tmp) % mod;
	if(b & 1)
		tmp = (tmp * a) % mod;
	return tmp;
}

//End of template

int main(){
	init();
	
	int n, k;
	cin >> n >> k;
	int arr[n];
	FOR(i, 0, n){
		cin >> arr[i];
	}
	int state[k+1];
	MEM(state, 0);
	FORE(i, 0, k){
		if(state[i] == 1)
			continue;
		FOR(j, 0, n){
			if(arr[j] + i <= k){
				state[arr[j]+i] = 1;
			}
		}
	}
	if(state[k] == 1){
		cout << "First\n";
	}
	else{
		cout << "Second\n";
	}
	return 0;	
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
const ll INF = 5e15;
int main(){
    ll N;
    cin >> N;
    ll T, A;
    cin >> T >> A;
    vector<pair<double, ll>> v;
    for(ll i = 0; i < N; i++){
        double H;
        cin >> H;
        v.push_back(pair<double, ll>(abs(T - H * 0.006 - A), i + 1));
    }
    sort(v.begin(), v.end());
    cout << v[0].second << endl;
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>

#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>

// namespace
using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

// constant
static const ll MOD = 998244353LL;
static const double PI = 3.14159265358979323846;

// conversion
inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// print
#define RET(x) return cout << x << endl, 0;

// for loop
#define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++)
#define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++)
#define REPI(v, vs) for (auto& v : vs)

//debug
#ifdef LOCAL_ENV
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define DUMP(x)
#define DEBUG(x)
#endif

#define MAX_VALUE 9223372036854775807LL

template <ull N, class T, class... Args, std::enable_if_t<N == 0, int> = 0>
auto make_multiple_vector(Args... args) {
    return T(args...);
}

template <ull N, class T, class... Args, std::enable_if_t<N != 0, int> = 0>
auto make_multiple_vector(ull size, Args... args) {
    using value_type = std::decay_t<decltype(make_multiple_vector<N - 1, T>(args...))>;
    return vector<value_type>(size, make_multiple_vector<N - 1, T>(args...));
}

int solve() {
	ll n;
	cin >> n;
	ll d1, d2;

	ll count = 0;
	REPD(i, 0, n) {
		cin >> d1 >> d2;
		if (d1 == d2) {
			++count;
			if (count >= 3) RET("Yes");
		}
		else {
			count = 0;
		}
	}

	RET("No");

	return 0;
}

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

	solve();
	// ll t;
	// cin >> t;
	// REPD(i, 0, t) solve();

	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<int> a(0);
    REP(i,n) {int v; cin>>v; a.emplace_back(v);}
    int ans=1;
    REP(i,n){
        ans= ans /__gcd(ans,a[i])* a[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3196
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

ans = 0
difmin = float("inf")

for i in range(N):
    ht = T - H[i] * 0.006
    dif = abs(ht - A)
    
    if dif < difmin:
        difmin = dif
        ans = i+1
        
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;//998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void A();

int main()
{
	A();
	fflush(stdout);
	return 0;
}

static void A()
{
	int L, R, d;
	get(L, R, d);
	int ans = 0;
	for (int i = L; i <= R; i++) {
		if (i % d == 0) ans++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define enter putchar('\n')
#define space putchar(' ')
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eps 1e-8
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 - '0' + c;
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
int L,N;
void add(int u,int v,int c) {
    out(u);space;out(v);space;out(c);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    read(L);
    int r;
    for(r = 20 ; r >= 0 ; --r) {
        if(L & (1 << r)) break;
    }
    N = r + 1;out(N);space;int M = r * 2 + __builtin_popcount(L) - 1;out(M);enter;
    for(int i = 1 ; i <= N - 1 ; ++i) {
        add(i,i + 1,(1 << i - 1));add(i,i + 1,0);
    }
    for(int i = 1 ; i <= N - 1 ; ++i) {
        if(L & (1 << i - 1)) {
            L ^= (1 << i - 1);
            add(i,N,L);
        }
    }
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    int n;
    cin >> n;
    vector<int> l;

    int sum;
    while(n--){
        int v;
        cin >> v;
        sum += v;
        l.push_back(v);
    }

    sort(l.begin(), l.end());

    cout << (l.back() < sum - l.back() ? "Yes" : "No") << endl;

    return 0;
}



Measured memory_bytes: 512
from collections import defaultdict


n = int(input())
div = defaultdict(int)

for i in range(2, n+1):
    num = i
    while num != 1:
        for d in range(2, num+1):
            if num % d == 0:
                num //= d
                div[d] += 1
                break
            else:
                continue

values = list(div.values())
over2 = 0
over4 = 0
over14 = 0
over24 = 0
over74 = 0
for value in values:
    if value >= 2:
        over2 += 1
    if value >= 4:
        over4 += 1
    if value >= 14:
        over14 += 1
    if value >= 24:
        over24 += 1
    if value >= 74:
        over74 += 1

ans1 = max(0, over4 * (over4-1) * (over2-2) // 2)
ans2 = max(0, over14 * (over4-1))
ans3 = max(0, over24 * (over2-1))
ans4 = over74
res = sum([ans1, ans2, ans3, ans4])
print(res)


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    vector<ll> cum(n + 1, 0);
    rep(i, n) cum[i + 1] = cum[i] + a[i];

    map<ll, ll> mp;
    rep(i, n + 1)
    {
        mp[cum[i]]++;
    }

    ll ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++)
    {
        ll nn = itr->second;
        ans += nn * (nn - 1) / 2;
    }

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

Measured memory_bytes: 15872
from collections import Counter

class UnionFind():
    def __init__(self, n=0):
        self.d = [-1]*n
        self.g = set()
    
    def find(self, x):
        if self.d[x] < 0: return x
        self.d[x] = self.find(self.d[x])
        return self.d[x]

    def unite(self, x, y):
        x,y=self.find(x),self.find(y)
        if x==y:return False
        if self.d[x] > self.d[y]: x,y=y,x
        self.d[x] += self.d[y]
        self.g.add(x)
        if y in self.g:self.g.remove(y)
        self.d[y] = x
        return True

    def same(self,x,y): return self.find(x)==self.find(y)
    def size(self,x): return -self.d[self.find(x)]
    
N,M=map(int,input().split())
edges=[tuple(map(int,input().split())) for _ in range(M)]
count=0
for m in range(M):
  uf = UnionFind(N+1)
  for i in range(M):
    if m==i:continue
    a,b=edges[i]
    uf.unite(a,b)
  if len(uf.g)+Counter(uf.d)[-1]-1==2:count+=1
print(count)

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

int selectionSort(int A[], const int N)
{
    int cnt = 0;

    for( int i = 0; i < N; ++i ){
        int min = i;

    //iより後でA[i]より最も小さい値の添字を求める
        for( int j = i; j < N; ++j )
            if( A[j] < A[min] )
                min = j;

    //iとminが異なれば交換
        if( i != min ){
       swap(A[i], A[min]);
       ++cnt;
    }
    }

    return cnt;
}

int main()
{
    int N;
    scanf("%d", &N);
    int A[N];
    for( int i = 0; i < N; ++i )
        scanf("%d", &A[i]);

    int cnt = selectionSort(A, N);

    for( int i = 0; i < N; ++i ){
        if( i ) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n%d\n", cnt);

    return 0;
}



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

typedef long long s64;
int val[200001 * 80], ls[200001 * 80], rs[200001 * 80], tot, root;
s64 a[200001];
int n, k;
s64 d = 1000000000000001ll;

void ins(s64 x, int& k = root, s64 l = -1000000000000000 + d, s64 r = 1000000000000000 + d)
{
    if (!k)
    {
        k = ++tot;
    }
    val[k]++;
    if (l == r)
    {
        return;
    }
    s64 mid = (l + r) / 2;
    if (x <= mid)
    {
        ins(x, ls[k], l, mid);
    }
    else
    {
        ins(x, rs[k], mid + 1, r);
    }
}

int qry(s64 le, s64 ri, int k = root, s64 l = -1000000000000000 + d, s64 r = 1000000000000000 + d)
{
    if (!k)
    {
        return 0;
    }
    if (le <= l && r <= ri)
    {
        return val[k];
    }
    s64 mid = (l + r) / 2;
    int ans = 0;
    if (le <= mid)
    {
        ans += qry(le, ri, ls[k], l, mid);
    }
    if (mid < ri)
    {
        ans += qry(le, ri, rs[k], mid + 1, r);
    }
    return ans;
}

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
    {
        a[i] -= k;
    }
    for (int i = 1; i <= n; i++)
    {
        a[i] += a[i - 1];
    }
    ins(0 + d);
    s64 ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int x = qry(-1000000000000000 + d, a[i] + d);
        ans += x;
        ins(a[i] + d);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 78080
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int lli;
const lli mod = 998244353;
 

int main(){
	string s;
	cin >> s;
	if(s[2] == s[3] and s[4] == s[5]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
let () =
  Scanf.scanf "%d" @@ fun n ->
  let p = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  Array.fold_left (fun (ans, u) v ->
    if u > v then (ans+1, v) else (ans, u)) (0, 200001) p
  |> fst |> Printf.printf "%d\n"


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;


void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


/* 注意 

    1LL<<60 * N とかのオーバーフローに気を付けろ
    制約がヒントになる、ちゃんと全ての制約を見ろ

*/

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

    int H, N; cin >> H >> N;
    vector<int> a(N), b(N);
    rep(i, N) cin >> a[i] >> b[i];

    int const inf = 1<<29;
    vector<vector<int>> dp(N+5, vector<int>(H+5, inf));
    // dp[i][j] := i 番目まで見て、体力を j 削るのに必要な最小 MP ただし、 j>=H は H と同一視する
    dp[0][0] = 0;
    rep(i, N) rep(j, H+1) {
        chmin(dp[i+1][j], dp[i][j]);
        chmin(dp[i+1][min(H, j+a[i])], dp[i+1][j]+b[i]);
    }
    cout << dp[N][H] << endl;
    
    return 0;
}


Measured memory_bytes: 39680
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


long long solution(vector<pair<long long, long long>>& M, long long D, long long A){
    int N = M.size();
    // 左から見ていくために、座標の昇順でソート
    sort(M.begin(), M.end());

    long long ans = 0, carry = 0;
    queue<pair<long long, long long>> q;
    REP(i, N){
        long long X = M[i].first;
        long long H = M[i].second;
        // これまでの操作の範囲に含まれないものの効果を取り除く
        while(!q.empty() and q.front().first < X){
            carry -= A*q.front().second;
            q.pop();
        }
        H -= carry;
        if(H > 0){
            long long num = (H+A-1)/A;
            ans += num;
            carry += A*num;
            q.emplace(X+2*D, num);
        }
    }
    return ans;
}


/* Binary Indexed Tree (Fenwick Tree)
 * 数列 {v_n} に対して、
 * ・ v[i] += w
 * ・ sum(l,r) = v[l+1]+...+v[r]
 * の操作を O(logN) でしたいって時に使える
 * cf. http://hos.ac/slides/20140319_bit.pdf
 * 1-index と 0-index を使い分けること！ (0-index の実装怪しい)
 */
template <typename T=long long>
class BIT  
{
    private:
        int sz;  // 1, 2, ..., sz の index を管理
        vector<T> bit;  // BIT を保存する vector; 区間の右端で番号付け

    public:
        BIT(int N): sz(N), bit(N+1, 0) {};

        // v[idx] に w を足す
        void add(int idx, T w){
            // x&(-x) で x の最も下の立っているbit (=各BITが管理する長さ) が取り出せる
            // 自分の番号に自分の長さを足していくと自分が含まれている領域を全て尽くせる
            for(int x = idx; x <= sz; x += x&(-x)) bit[x] += w;  // 1-index
            // for(int x = idx; x < sz; x |= x+1) bit[x] += w;  // 0-index
        }

        // v[1]+...+v[idx] を返す
        T sum(int idx){
            T ret = 0;
            // 区間和は、自分の番号から自分の区間の長さを引くと求まる
            for(int x = idx; x > 0; x -= x&(-x)) ret += bit[x];  // 1-index
            //for(int x = idx-1; x >= 0; x = (x&(x+1))-1) ret += bit[x];  // 0-index
            return ret;
        }
        
        // v[left+1]+...+v[right] を返す
        T sum(T left, T right){ return sum(right)-sum(left); }
};

long long solutionWithBIT(vector<pair<long long, long long>>& M, long long D, long long A){
    int N = M.size();
    sort(M.begin(), M.end());
    long long ans = 0;
    BIT<long long> bit(N+1);
    REP(i, N){
        long long X = M[i].first;
        long long H = M[i].second;

        H -= A*bit.sum(i+1);
        if(H <= 0) continue;
        long long num = (H+A-1)/A;
        ans += num;
        bit.add(i+1, num);
        int j = distance(M.begin(), upper_bound(M.begin(), M.end(), make_pair(X+2*D+1, (long long) -1)));
        bit.add(j+1, -num);
    }
    return ans;
}

int main()
{
    int N, D, A;
    cin >> N >> D >> A;
    vector<pair<long long, long long>> M(N);
    REP(i, N) cin >> M[i].first >> M[i].second;

    cout << solutionWithBIT(M, D, A) << endl;

    return 0;
}

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

int main() {
vector<vector<int>> A(3,vector<int>(3));
for(int i=0; i<3 ;i++)
{
for(int &x : A[i])
{
  cin >> x;
}
}
int N;
cin >> N;
for (int i = 0; i < N; i++)
{
  int x ;
  cin >> x;
  for (int j = 0; j < 3; j++)
  {
    for (int k = 0; k < 3 ; k++)
    {
      if(A[j][k]==x) A[j][k] = -1;
    }
    
  }
  
}
if(A[0][0]==-1 && A[0][1]==-1 && A[0][2]==-1)
{
  cout << "Yes" << endl;
  return 0;
}
if(A[1][0]==-1 && A[1][1]==-1 && A[1][2]==-1)
{
  cout << "Yes" << endl;
  return 0;
}
if(A[2][0]==-1 && A[2][1]==-1 && A[2][2]==-1)
{
  cout << "Yes" << endl;
  return 0;
}
if(A[0][0]==-1 && A[1][0]==-1 && A[2][0]==-1)
{
  cout << "Yes" << endl;
  return 0;
}
if(A[0][1]==-1 && A[1][1]==-1 && A[2][1]==-1)
{
  cout << "Yes" << endl;
  return 0;
}
if(A[0][2]==-1 && A[1][2]==-1 && A[2][2]==-1)
{
  cout << "Yes" << endl;
  return 0;
}
if(A[0][0]==-1 && A[1][1]==-1 && A[2][2]==-1)
{
  cout << "Yes" << endl;
  return 0;
}
if(A[2][0]==-1 && A[1][1]==-1 && A[0][2]==-1)
{
  cout << "Yes" << endl;
  return 0;
}
else cout << "No" << endl;
  return 0;
}

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

int main(void){
    int n;
    cin >> n;
    int num = 0;
    int ans = 0;
    for(int i=1;i<=n;i++){
        num = 0;
        if(i%2==1){
            for(int j=1;j<=i;j++){
                if(i%j==0){
                    num++;
                }
            }
        }
        if(num==8){
            ans++;
        }
    }
    cout << ans <<endl;
    return 0;
}
















































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

using namespace std;
typedef long long int lld;
#define INF 1000000000000000000
lld arr[200][2];
lld DP[1000000];
int n,w;

int main(){
	cin>>n>>w;
	for(int i=0;i<n;i++){
		for(int j=0;j<2;j++)cin>>arr[i][j];
	}
	
	for(int j=0;j<=w;j++)DP[j]=-INF;
	
	DP[0]=0;
	for(int i=0;i<n;i++){
		for(int j=w;j>=0;j--){
			if(j+arr[i][0]<=w)DP[j+arr[i][0]]=max(DP[j+arr[i][0]],DP[j]+arr[i][1]);
		}
		/*for(int j=0;j<=w;j++)cout<<DP[j]<<" ";
		cout<<endl;*/
	}
	lld ans=0;
	for(int i=0;i<=w;i++){
		ans=max(ans,DP[i]);
	}
	cout<<ans<<endl;
	
	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<pair<int, int>> e(n - 1);
  vector<int> G[n]; // G:頂点数がnのグラフを表す隣接リスト
  vector<int> x(n); // K判断用
  for(int i = 0; i < n - 1; i++){
    int a, b;
    cin >> a >> b;
    e.at(i) = make_pair(a - 1, b - 1);
    x.at(a - 1)++;
    x.at(b - 1)++;
    G[a - 1].emplace_back(b - 1);
    G[b - 1].emplace_back(a - 1); // 有向グラフではこの行をコメントアウト
  }
  
  int k = 0;
  for(int i = 0; i < n; i++) k = max(k, x.at(i));
  
  cout << k << '\n';
  
  map<pair<int, int>, int> mp;
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    int p = q.front();
    q.pop();
    int color = 1, ng = 1e9;
    for(int i = 0; i < G[p].size(); i++){
      if(mp[make_pair(p, G[p][i])] != 0 || mp[make_pair(G[p][i], p)] != 0){
        ng = mp[make_pair(p, G[p][i])] + mp[make_pair(G[p][i], p)];
        break;
      }
    }
    for(int i = 0; i < G[p].size(); i++){
      if(color == ng) color++;
      if(mp[make_pair(p, G[p][i])] != 0 || mp[make_pair(G[p][i], p)] != 0) continue;
      mp[make_pair(p, G[p][i])] = color;
      color++;
      q.push(G[p][i]);
    }
  }
  
  for(int i = 0; i < n - 1; i++){
    cout << mp[make_pair(e.at(i).first, e.at(i).second)] + mp[make_pair(e.at(i).second, e.at(i).first)] << '\n';
  }
}

Measured memory_bytes: 19712
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;i++)
const ll INF=1e18;
const int inf=2e9;
const ll MOD=1000000007;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};

int main(){
    ll H,W;cin>>H>>W;
    char info[H][W];
    rep(i,H)rep(j,W)cin>>info[i][j];
    ll ans=0;
    rep(i,H){
        rep(j,W){
            if(info[i][j]=='#')continue;
            ll now[H][W];
            rep(s,H)rep(t,W)now[s][t]=inf;
            now[i][j]=0;
            queue<pair<ll,ll>> que;
            que.emplace(i,j);
            while(!que.empty()){
                ll x=que.front().second,y=que.front().first;
                que.pop();
                rep(k,4){
                    ll ny=y+dy[k],nx=x+dx[k];
                    if(0>nx or nx>W-1 or 0>ny or ny>H-1)continue;
                    else{
                        if(info[ny][nx]=='#')continue;
                        if(now[ny][nx]>now[y][x]+1){
                            que.emplace(ny,nx);
                            now[ny][nx]=now[y][x]+1;
                        }
                    }
                }
            }
            ll nowcount=0;
            rep(s,H)rep(t,W){
                if(now[s][t]==inf)continue;
                else nowcount=max(nowcount,now[s][t]);
            }
            ans=max(nowcount,ans);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
x = gets.split.map(&:to_f)
y = gets.split.map(&:to_f)
max, p1, p2, p3 = 0, 0, 0, 0;
n.times do |i|
  q = (x[i] - y[i]).abs
  max = q if q > max
  p1 += q
  p2 += q ** 2
  p3 += q ** 3
end
puts p1
puts Math.sqrt(p2)
puts p3 ** Rational(1, 3)
puts max

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

int main(){
    int64_t n, d;
    cin >> n >> d;
    vector<int64_t> T(n);
    copy_n(istream_iterator<int64_t>(cin), n, T.begin());

    int64_t ans = d;
    for (int i = 1; i < n; i++){
        ans += min(d, T[i] - T[i - 1]);
    }

    cout << ans << endl;
}

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

#define debug(x) cout<<#x<<"="<<x<<endl
#define pii pair<int,int>
#define PQ priority_queue
#define ll long long
#define pb push_back
#define mp make_pair

int main(){
	string s;
	cin>>s;
	if (s.substr(0,4)=="YAKI") cout<<"Yes"; else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
const int MAX_C = 1000;
long long Com[MAX_C][MAX_C];

void calc_com() {
    memset(Com, 0, sizeof(Com));
    Com[0][0] = 1;
    for (int i = 1; i < MAX_C; ++i) {
        Com[i][0] = 1;
        for (int j = 1; j < MAX_C; ++j) {
            Com[i][j] = (Com[i-1][j-1] + Com[i-1][j]) ;
        }
    }
}
signed main(){
  calc_com();
  int N,A,B; cin>>N>>A>>B;
  vi C(N);
  rep(i,0,N) cin>>C[i];
  sort(ALL(C),greater<int>());
  int sum=0;
  rep(i,0,A) sum+=C[i];
  double ans=sum*1.0/A;
  printf("%.10lf\n",ans);
  int Ans=1;
  int E=0,D=0;
  rep(i,0,A){
    if(C[i]==C[A-1]) D++;
  }
  rep(i,A,N){
    if(C[i]==C[A-1]) E++;
  }
  Ans*=Com[D+E][D];
  if(C[0]==C[A-1]){
    REP(i,A+1,min(B,D+E)){
      Ans+=Com[D+E][i];
    }
  }
  cout<<Ans<<endl;
  }



Measured memory_bytes: 8064
import sys
input = sys.stdin.buffer.readline

n = int(input())
p = [int(input()) for _ in range(n)]

q = [0] * n
for i in range(n):
    q[p[i]-1] = i
mxk = 1
k = 1
for i in range(n-1):
    if q[i] < q[i+1]:
        k += 1
        if k > mxk:
            mxk = k
    else:
        k = 1
print(n-mxk)


Measured memory_bytes: 18948
// AUTHOR - RUTVIK KOTHARI
// DAIICT , GANDHINAGAR

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define ull unsigned long long
#define pll pair<ll,ll>
#define MS(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define INFL LLONG_MAX
#define pb push_back
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const ll N = 1e6 + 5;
const ll M = 3e5 + 5;
const ll mod = 1e9 + 7;
const ll m1 = 1e9 + 7;
const ll m2 = 1e9 + 9;
const ll p1 = 402653189;
const ll p2 = 1610612741;
const int LN = 20;

ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

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

ll pw[LN],fact[N],invfact[N];

void pre()
{
    fact[0]=1;
    for(int i=0;i<LN;i++)pw[i]=power(2,i);
    for(int i=1;i<N;i++)fact[i]=(i*fact[i-1])%mod;
    for(int i=0;i<N;i++)invfact[i]=powermodm(fact[i],mod-2,mod);
}


int main()
{
    FIO;
    //pre();

    ll i,j;

    ll n,k;
    cin>>n>>k;
    
    string s;
    cin>>s;
    
    ll ans = 0,len = s.length();
    
    for(i=0;i<len-1;i++)
    {
        if(s[i] == s[i+1])
            ans++;
    }
    
    ans = min(len-1,ans+2*k);
    
    cout<<ans;
    
    
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
using namespace std;
int main(){
   int S[13],H[13],C[13],D[13];
   for(int i=0;i<13;i++){
     S[i]=-1;
     H[i]=-1;
     C[i]=-1;
     D[i]=-1;
   }
   int num;
   scanf("%d",&num);
   int n;
   char m;
   for (int j=0;j<num;j++){
    scanf("%*c%c %d",&m,&n);
    if (m=='S'){
        S[n-1]=1;
    }
    else if (m=='H'){
        H[n-1]=1;
    }
    else if (m=='C'){
        C[n-1]=1;
    }
    else if (m=='D'){
        D[n-1]=1;
    }
   }




   for (int i=0;i<4;i++){
       for(int j=0;j<13;j++){
           if(i==0){
               if(S[j]==-1){
                   printf("S %d\n",j+1);
               }
           }
           else if(i==1){
               if(H[j]==-1){
                   printf("H %d\n",j+1);
               }
           }
           else if(i==2){
               if(C[j]==-1){
                   printf("C %d\n",j+1);
               }
           }
           else if(i==3){
               if(D[j]==-1){
                   printf("D %d\n",j+1);
               }
           }
       }
   }

}






Measured memory_bytes: 2668
#include<stdio.h>

int main()
{
	int a, b, sum;
	while(scanf("%d%d", &a, &b) == 2) {
		sum = a + b;
		if(sum % 3 == 0 || a % 3 == 0 || b % 3 == 0) {
			printf("Possible\n");
		}
		else {
			printf("Impossible\n");
		}
	}
	return 0;
}

Measured memory_bytes: 128
<?php
  fscanf(STDIN,"%d%d",$h,$w);
  for($i=0; $i<$h; $i++){
      $c[] = trim(fgets(STDIN));
  }
  for($i=0;$i<$h; $i++){
      echo $c[$i]."\n";
      echo $c[$i]."\n";
  }

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

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << "\n";
    return 0;
}


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

int main()
{
    int N, K;
    cin >> N >> K;
    int A[N+3];
    for(int i = 0; i < N; ++i) cin >> A[i];
    sort(A, A + N);
    int B[N+5];
    fill(B, B + N+3, 0);
    int cnt = 1, cur = 0;
    for(int i = 1; i <= N; ++i) {
        if(i == N) { B[cur++] = cnt; continue; }
        if(A[i-1] == A[i]) ++cnt;
        else { B[cur++] = cnt; cnt = 1; }
    }
    sort(B, B + cur);
    int res = 0;
    for(int i = 0; i < cur - K; ++i) {
        res += B[i];
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

bool pairCompare(const pair<string, int> & a, const pair<string, int> & b);

int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    vector<int> P(N), tent(N);
    vector<pair<string, int>> ans(N);
    for(int i = 0; i < N; i++){
        cin >> S[i] >> P[i];
        ans[i].first = S[i];
        ans[i].second = P[i];
    }
    
    sort(ans.begin(), ans.end(), pairCompare);
    
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(P[j] == ans[i].second){
                cout << j + 1 << endl;
                break;
            }
        }
    }
}

bool pairCompare(const pair<string, int> & a, const pair<string, int> & b){
    if(a.first == b.first){
        return a.second > b.second;
    }
    else{
        return a.first < b.first;
    }
}

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

int sumNum(string n){
	int sum=0;
	for(int i=0;i<=n.size();i++){
		sum+=atoi(n.substr(i,1).c_str());
	}
	return sum;
}
 
int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int i=0;
	while(true){
		string n;
		cin>>n;
		if(n=="0"){
			break;
		}
		cout<<sumNum(n)<<endl;
	}
    return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <cstdlib>

int main()
{
    int N, M, C;
    int a;
    int B[20];
    
    std::cin >> N >> M >> C;
    
    for(int k = 0; k < M; k++){
        std::cin >> B[k];
    }
    
    int buf = 0;
    
    int ans = 0;
    
    for(int i = 0; i < N ; i++){
        buf = C;
        for(int k = 0; k < M; k++)
        {
            std::cin >> a;
            buf += a * B[k];
        }
        if(buf > 0) ans+=1;
    }
    
    std::cout << ans;
}

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

int main(){
  int A, B, C, D; cin >> A >> B >> C >> D;
  bool isWinner = false;
  while(1){
    C -= B;
    if(C <= 0){
      isWinner = true;
      break;
    }
    A -= D;
    if(A <= 0){
      isWinner = false;
      break;
    }
  }
  if(isWinner) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_DATA (100)
#define LIMIT_LEN (40)
#define LIMIT_PAGE (1001)

struct word_t {
	char word[LIMIT_LEN];
	char pages[LIMIT_PAGE];
};
typedef struct word_t Word;

int compare_word(const void *a, const void *b) {
	return strcmp(((Word*)a)->word, ((Word*)b)->word);
}

int main(void) {
	Word ws[MAX_DATA] = {};
	char word[LIMIT_LEN];
	int num_word = 0, page, i, k;
	const char *sep;

	while (scanf("%s %d ", word, &page) != EOF) {
		for (i = 0; i < MAX_DATA; i++) {
			if (ws[i].word[0] == '\0') {
				strncpy(ws[i].word, word, LIMIT_LEN-1);
				ws[i].pages[page] = 1;
				num_word++;
				break;
			} else if (!strcmp(ws[i].word, word)) {
				ws[i].pages[page] = 1;
				break;
			}
		}
	}

	qsort(ws, num_word, sizeof(Word), compare_word);

	for (i = 0; i < num_word; i++) {
		puts(ws[i].word);
		sep = "";
		for (k = 0; k < LIMIT_PAGE; k++) {
			if (ws[i].pages[k]) {
				printf("%s%d", sep, k);
				sep = " ";
			}
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 784
fun main(args:Array<String>):Unit {
    val (n, _) = readLine()!!.trim().split(' ').map(String::toInt)
    val state = Array(n){readLine()!!.trim().toCharArray()}
    val notWhite = state.map{it.count{it != 'W'}}.toIntArray()
    val notBlue = state.map{it.count{it != 'B'}}.toIntArray()
    val notRed = state.map{it.count{it != 'R'}}.toIntArray()
    for (i in 1 until n){
        notWhite[i] += notWhite[i - 1]
        notBlue[i] += notBlue[i - 1]
        notRed[i] += notRed[i - 1]
    }
    var min = Int.MAX_VALUE
    for (w in 0 until n - 2){
        for (b in w + 1 until n - 1){
            if (notRed.last() - notRed[b] + notBlue[b] - notBlue[w] + notWhite[w] < min){
                min = notRed.last() - notRed[b] + notBlue[b] - notBlue[w] + notWhite[w]
            }
        }
    }
    println(min)
}


Measured memory_bytes: 32188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,i,j,k,ans=0;
  cin>>n>>k;
  for(i=2;i<7;i++){
    j=1;
    while((8*j+i*9-k)%11) j++;
    if(n-2<j) continue;
    ans+=(n-j-2)/11+1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
	int a,b;
	scanf("%d%d",&a,&b);
	if(b%2==1){printf("No");}
	else if(a*2>b){printf("No");}
	else if(a*4<b){printf("No");}
	else{printf("Yes");}
	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
using namespace std;
bool primes[1000001];vi prime; void seive(); int gcd(int a, int b); int power(int x, int y);

int32_t main(void){
	IOS;
	in1(n);
	map<string, int> m;
	rep(i, 0, n)
	{
		string s;
		cin>>s;
		m[s] += 1;
	}
	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"]<<endl;
}

void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}
int gcd(int a, int b){return b==0 ? a : gcd(b, a%b);}
int power(int x, int y){ int res = 1;x = x % mod; if (x == 0) return 0;
while (y > 0){ if(y & 1) res = (res*x) % mod; y = y>>1; x = (x*x) % mod;} return res;}


Measured memory_bytes: 3660
# -*- coding: utf-8 -*-

dx = [-1, -1, -1, 0, 1, 1,  1,  0]
dy = [-1,  0,  1, 1, 1, 0, -1, -1]

h, w = map(int, input().split())

grid = []
for i in range(h):
  grid.append(list(input()))

for i in range(h):
  for j in range(w):
    if grid[i][j]=='.':
      grid[i][j] = 0
      for k in range(8):
        x = j + dx[k]
        y = i + dy[k]
        if 0 <= x and x <= w-1 and 0 <= y and y <= h-1:
          if grid[y][x] == "#":
            grid[i][j] = grid[i][j] + 1

for i in range(h):
  print(''.join(map(str,grid[i])))


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

bool is_prime(ll n) {
  for(ll i=2;i*i<=n;i++) {
    if(n%i==0) {
      return false;
    }
  }
  return n!=1;
}

int main() {
  ll q;
  cin >> q;
  vector<bool> prime(1e5+1,false);
  for(int i=2;i<prime.size();i++) {
    prime[i]=is_prime(i);
  }
  vector<bool> like(1e5+1,false);
  for(int i=3; i<like.size();i+=2) {
    if(prime[i]&&prime[(i+1)/2]) {
      like[i]=true;
    }
  }
  vector<ll> pn(1e5+1,0);
  for(int i=1;i<pn.size();i++) {
    pn[i]=pn[i-1];
    if(like[i]) {
      pn[i]++;
    }
  }
  for(int i=0;i<q;i++) {
    ll l,h;
    cin >> l >> h;
    cout << pn[h]-pn[l-1] << endl;
  }
}

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> data(h, vector<char>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> data.at(i).at(j);
        }
    }

    vector<bool> line(h, false);
    vector<bool> row(w, false);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (data.at(i).at(j) == '#') {
                line.at(i) = true;
                row.at(j) = true;
            }
        }
    }

    for (int i = 0; i < h; i++) {
        if (line.at(i)) {
            for (int j = 0; j < w; j++) {
                if ( row.at(j)) {
                    cout << data.at(i).at(j);
                }
            }      
            cout << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int fac[2000005], ifac[2000005];

void gen_fac()
{
	fac[0] = 1;
	rep1(i, 2000000) fac[i] = 1LL * fac[i - 1] * i % MOD;
	ifac[1] = 1;
	for(int i = 2; i <= 2000000; i ++) ifac[i] = MOD - 1LL * ifac[MOD % i] * (MOD / i) % MOD;
	ifac[0] = 1;
	rep1(i, 2000000) ifac[i] = 1LL * ifac[i - 1] * ifac[i] % MOD;
}

int comb(int n, int m)
{
	if(n < m) return 0;
	return 1LL * fac[n] * ifac[n - m] % MOD * ifac[m] % MOD;
}

int solve(int n, int m, int k)
{
	int tot = comb((3 * m - k) / 2 + n - 1, n - 1);
	tot = (tot - 1LL * k * comb((m - k) / 2 + n - 1, n - 1) % MOD + MOD) % MOD;
	tot = (tot - 1LL * (n - k) * comb((m - k - 2) / 2 + n - 1, n - 1) % MOD + MOD) % MOD;
	return tot;
}

int main()
{
	gen_fac();
	int n, m;
	scanf("%d%d", &n, &m);
	int ans = 0;
	for(int i = 0; i <= m; i ++)
	if(!(m - i & 1)) ans = (ans + 1LL * comb(n, i) * solve(n, m, i)) % MOD;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 15872
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
	string X;

	cin >> X;
	
	cout << (X[0] == X[2] ? "Yes" : "No") << endl;
}


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

int main() {
	int n;
	cin >> n;
	int t[n],x[n],y[n];
	bool ans = true;
	for (int i = 0;i < n;i++) {
		cin >> t[i] >> x[i] >> y[i];
		if (t[i] < x[i] + y[i]) {
			ans = false;
		} else {
			if (t[i]%2!=(x[i]+y[i])%2){
				ans = false;
			}
		}
	}
	if (ans) {cout << "Yes" << endl;}
	else {cout << "No" << endl;}
}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

    ll a,b,c,ans;
    cin >> a >> b >> c;
    if(a%2==0 || b%2==0 || c%2==0) ans = 0;
    else{
        ans = min(a*b,a*c);
        ans = min(ans,b*c);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    int n, d, x;
    cin >> n >> d >> x;
    vector<int> arr(n, 0);
    int ans = x;
    for(int& val: arr) {
        cin >> val;
        ans += 1 + (d-1)/val;
    }
    cout << ans << endl;


    return 0;
}




Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int n,m,p[112345];
	string s[112345];

	cin>>n>>m;
	for(int i = 0;i<m;i++)
		cin>>p[i]>>s[i];

	bool a[112345];
	fill(a,a+n+1,false);
	bool AC[112345];
	fill(AC,AC+n+1,false);

	for(int i = 0;i<m;i++)
		AC[p[i]] |= s[i]=="AC";

	int ac = 0;
	int pe = 0;
	for(int i = 0;i<m;i++)
	{
		if(s[i]=="AC"){
			ac += !a[p[i]];
		       	a[p[i]] = true;
		}
		else{
			pe += AC[p[i]]&&!a[p[i]];
		}
		
	}

	cout<<ac<<" "<<pe<<endl;
}


Measured memory_bytes: 6400
import java.util.*;
import java.util.ArrayDeque;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);


        try{

            while (sc.hasNext()) {

                String str = sc.nextLine();
                Deque<Integer> deq = new ArrayDeque<Integer>();

                String[] s_array = str.split(" ");

                if (s_array.length > 2) {

                    for (int i = 0; i < s_array.length; i++) {

                        if (s_array[i].toString().equals("*")) {

                            deq.addFirst((deq.removeFirst() * deq.removeFirst()));

                        } else if (s_array[i].toString().equals("/")) {

                            int x = deq.removeFirst(), y = deq.removeFirst();
                            deq.addFirst(y/x);

                        } else if (s_array[i].toString().equals("+")) {

                            deq.addFirst((deq.removeFirst() + deq.removeFirst()));

                        } else if (s_array[i].toString().equals("-")) {

                            int x = deq.removeFirst(), y = deq.removeFirst();
                            deq.addFirst(y-x);

                        } else {

                            deq.addFirst(Integer.valueOf(s_array[i].toString()));

                        }
                    }

                    System.out.printf("%d\n", deq.removeFirst());

                }

            }

        } finally {

            sc.close();

        }

    }
}


Measured memory_bytes: 26260