akhauriyash/Code-Regression huggingface dataset:
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int N; cin >> N;
	string str; cin >> str;
	stack<int> st;
	rep(i, N){
		if(str[i] == '('){
			st.push(0);
		}
		else {
			if(!st.empty() && st.top() == 0){
				st.pop();
			}
			else
				st.push(1);
		}
	}
	string ans = str;
	while(!st.empty()){
		int a = st.top(); st.pop();
		if(a == 0){
			ans.insert(ans.end(), ')');
		}
		else{
			ans.insert(ans.begin(), '(');
		}
	}
	cout<< ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#if ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define foreach(i, vec) for(auto &&i : vec)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) cerr << #x << ": " << (x) << endl
using namespace std;
typedef long long LL;
typedef long long int64;
typedef std::vector<int> VI;
typedef std::vector<VI> VVI;
typedef std::vector<LL> VL;
typedef std::vector<VL> VVL;
typedef std::vector<string> VS;
typedef std::pair<int, int> PII;
typedef std::pair<int64, int64> PLL;
typedef std::queue<int> QI;
typedef std::priority_queue<int> PQI;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>inline void vcin(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;
// M_PI 3.1415...

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(n);
    LL h[101000];
    rep(i, n){
        cin >> h[i];
    }
    LL dp[100100];
    dp[0]=0;
    REP(i, 1, n){
        if(i!=1)
            dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
        else
            dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
    }
    LL ans = dp[n-1];
    co(ans);
    return 0;
}

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

int main() {
  bool x = false;
  int a;
  cin >> a;
  
  for(int i = 0; i < 9; i++) {
    for(int j = 0; j < 9; j++) {
      if((i + 1) * (j + 1) == a) {
        x = true;
        break;
      } else {
        continue;
      }
    }
  }
  
  if(x) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


template<typename T>
struct Segtree{
    int n;
    T op;
    vector<T> elm;
    function<T(T, T)> f;

    Segtree(int n, T init, function<T(T, T)> f, T op = T()) :
        n(n),
        op(op),
        elm(2 * n, init),
        f(f)
    {
    }

    void set(int x, T val){
        x += n;
        elm[x] = val;
        while(x >>= 1)
            elm[x] = f(elm[2 * x], elm[2 * x + 1]);
    }

    void update(int x, T val){
        x += n;
        elm[x] = f(val, elm[x]);
        while(x >>= 1)
            elm[x] = f(elm[2 * x], elm[2 * x + 1]);
    }

    T get(int x, int y) const{
        T val = op;
        for(x += n, y += n - 1; x <= y; x >>= 1, y >>= 1){
            if(x & 1)
                val = f(val, elm[x++]);
            if(!(y & 1))
                val = f(val, elm[y--]);
        }
        return val;
    }
};


signed main(){
    int n;
    cin >> n;
    vector<pair<int,int>> a;
    vector<vector<int>> t(2, vector<int>(n));
    for(int i = 0; i < 2 * n; ++i){
        string s;
        int x;
        cin >> s >> x;
        a.emplace_back(s == "B", --x);
        t[s == "B"][x] = i;
    }
    // v[i][j]: dp[i][j]で遷移に必要な値
    vector<vector<vector<int>>> v(n + 1, vector<vector<int>>(n + 1, vector<int>(2, MOD)));
    for(int i = 0; i <= n; ++i){
        Segtree<int> seg(2 * n, 0, [](int x, int y){return x + y;});
        for(int j = 0; j < i; ++j)
            seg.set(t[0][j], 1);
        for(int j = 0; j <= n; ++j){

            int pos_i = t[0][i];
            int pos_j = t[1][j];
            v[i][j][0] = pos_i - seg.get(0, pos_i);
            v[i][j][1] = pos_j - seg.get(0, pos_j);

            if(j != n)
                seg.set(t[1][j], 1);
        }
    }


    vector<vector<int>> dp(n + 1, vector<int>(n + 1, MOD));
    dp[0][0] = 0;

    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= n; ++j){
            if(i != n)
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + v[i][j][0]);
            if(j != n)
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + v[i][j][1]);
        }
    }

    cout << dp[n][n] << endl;
}


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

set<int> st;
int main() {
  int n;
  cin >> n;

  int cnt = 0;
  while (st.count(n) == 0) {
    st.insert(n);
    if (n % 2 == 0) {
      n = n / 2;
    } else {
      n = 3 * n + 1;
    }
    ++cnt;
  }
  cout << cnt + 1 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        int []a = IntStream.range(0, n).map(x -> in.nextInt()).toArray();
        long [][]dp = new long[n][n];

        for(int i = 0; i < n; i++) {
            dp[i][i] = a[i];
        }
        for (int i = 0; i < n - 1; i++) {
            dp[i][i + 1] = Math.max(a[i], a[i + 1]) - Math.min(a[i], a[i + 1]);
        }

        for(int len = 2; len < n; len++) {
            for(int start = 0; start + len < n; start++) {
                int end = start + len;
                dp[start][end] = Math.max(
                        // take the first
                        a[start] + Math.min(dp[start + 2][end] - a[start + 1], dp[start + 1][end - 1] - a[end]),


                        //take the end
                        a[end] + Math.min(dp[start + 1][end - 1] - a[start], dp[start][end - 2] - a[end - 1])

                );
            }
        }
        System.out.println(dp[0][n - 1]);
    }
}


Measured memory_bytes: 109904
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"
const int mxN = 1e5+5;
int arr[mxN];
vi G[mxN];
int d[mxN];
int dfs(int u, int par=-1)
{
	if(par!=-1 and d[u]==1)
		return arr[u];
	int total=arr[u]<<1;
	for(auto v:G[u])
	{
		if(v==par)
			continue;
		int temp=dfs(v,u);
		if(temp>arr[u])
		{
			cout<<"NO";
			exit(0);		
		}
		total-=temp;
	}
	if(total<0 or total>arr[u])
	{
		cout<<"NO";
		exit(0);
	}
	return total;
}
signed main()
{
    //freopen(file".inp","r",stdin);
    //freopen(file".out","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    	cin>>arr[i];
    if(n==2)
    	return cout<<((arr[1]==arr[2]) ? "YES":"NO"),0;
    for(int i=1,u,v;i<n;i++)
    {
    	cin>>u>>v;
    	G[u].eb(v);
    	G[v].eb(u);
    	++d[u], ++d[v];
	}
	int temp=dfs(1);
	if(d[1]==1 and temp!=arr[1])
		return cout<<"NO",0;
	if(d[1]!=1 and temp!=0)
		return cout<<"NO",0;
	cout<<"YES";
}


Measured memory_bytes: 15884
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var Ai = Sarray().Select((a, i) => a - i - 1).ToArray();
            Array.Sort(Ai);
            var b = Ai[(N - 1) / 2];
            var ans = Ai.Sum(a => Abs(a - b));
            WriteLine(ans);
        }
 
        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 49036
// AOJ 2803 Overflow of Furo
// 2018.4.19 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*******************************************/
/* Dinic's Max Flow Algorithm 
/*******************************************/

#define INF  0x01010101
#define VMAX 110
typedef struct { int to; int cap; int rev; } EDGE;
EDGE edge[VMAX][VMAX]; int hi[VMAX];
int V;				// 頂点数
int level[VMAX], iter[VMAX];
int queue[3*VMAX], qtop;

void add_edge(int from, int to, int cap)
{
	int f, t;
	EDGE *e;

	f = hi[from]++, t = hi[to]++;
	e = &edge[from][f], e->to = to, e->cap = cap, e->rev = t; 
	e = &edge[to][t], e->to = from, e->cap = cap, e->rev = f;
}

void bfs(int s)
{
	int i, v;
	EDGE *e;
	
	memset(level, -1, V << 2);
	level[s] = 0;
	queue[0] = s, qtop =1;
	while (qtop) {
		v = queue[--qtop];
		for (i = 0; i < hi[v]; i++) {
			e = &edge[v][i];
			if (e->cap > 0 && level[e->to] < 0) {
				level[e->to] = level[v] + 1;
				queue[qtop++] = e->to;
			}
		}
	}
}
 
int dfs(int v, int t, int f)
{
	int *i, d;
	EDGE *e;
	
	if (v == t) return f;
	for (i = &iter[v]; *i < hi[v]; (*i)++) {
		e = &edge[v][*i];
		if (e->cap > 0 && level[v] < level[e->to]) {
			d = dfs(e->to, t, f <= e->cap? f: e->cap);
			if (d > 0) {
				e->cap -= d;
				edge[e->to][e->rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
 
int maxFlow(int s, int t)
{
	int f, flow = 0;
	while (1) {
		bfs(s);
		if (level[t] < 0) break;
		memset(iter, 0, V << 2);
		while ((f = dfs(s, t, INF)) > 0) flow += f;
	}
	return flow;
}

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

EDGE edge2[VMAX][VMAX]; int hi2[VMAX];
int a[5100], b[5100];
int fr[VMAX], to[VMAX];

int main()
{
	int K, N, M, i, f, t, flow, ans;
	int source, sink;

	K = in(), N = in(), M = in();
	source = K+N+1, sink = 0, V = source+1;
	for (i = 1; i <= K; i++) add_edge(source, i, INF);
	f = 0;
	for (i = 0; i < M; i++) {
		a[i] = in(), b[i] = in();
		if (a[i] > b[i]) t = a[i], a[i] = b[i], b[i] = t;
		add_edge(a[i], b[i], in());
		f |= !a[i] && b[i] >= 1 && b[i] <= K; 
	}
	if (f) { puts("overfuro"); return 0; }

	flow = maxFlow(source, sink);
	memcpy(edge2, edge, sizeof(edge2)), memcpy(hi2, hi, sizeof(hi2));

	fr[source] = INF, to[sink] = INF;
	for (i = 0; i < source; i++) {
		memcpy(edge, edge2, sizeof(edge2)), memcpy(hi, hi2, sizeof(hi2));
		fr[i] = maxFlow(source, i);
	}
	for (i = 1; i <= source; i++) {
		memcpy(edge, edge2, sizeof(edge2)), memcpy(hi, hi2, sizeof(hi2));
		to[i] = maxFlow(i, sink);
	}

	ans = -1;
	for (i = 0; i < M; i++) {
		t = fr[a[i]]; if (t > to[b[i]]) t = to[b[i]]; if (t > ans) ans = t;
		t = fr[b[i]]; if (t > to[a[i]]) t = to[a[i]]; if (t > ans) ans = t;
	}
	printf("%d\n", ans+flow);
	return 0;
}


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

int main(){
  int a,b;
  cin >>a>>b;
  if(a>b){
    for(int i=0;i<a;i++){
      cout<<b;
    }
  }
        else{
        for(int i=0;i<b;i++){
          cout<<a;
        }
        }
    
    cout<<endl;
           return 0;

}

Measured memory_bytes: 256
using System;

namespace _0521
{
    class Program
    {
        static void Main(string[] args)
        {
            int zankin = 0;
            int coin = 0;
            while (true)
            {
                int now = int.Parse(Console.ReadLine());
                if (now == 0)
                {
                    break;
                }
                zankin = 1000 - now;
                if(zankin>=500)
                {
                    coin++;
                    zankin -= 500;
                }
                while(true)
                {
                    if (zankin / 100 == 0)
                    {
                        break;
                    }
                    else
                    {
                        coin++;
                        zankin -= 100;
                    }
                }
                if(zankin>=50)
                {
                    coin++;
                    zankin -= 50;
                }
                while (true)
                {
                    if (zankin / 10 == 0)
                    {
                        break;
                    }
                    else
                    {
                        coin++;
                        zankin -= 10;
                    }
                }
                if (zankin >= 5)
                {
                    coin++;
                    zankin -= 5;
                }
                if(!(zankin==0))
                {
                    coin += zankin;
                }
                zankin = 0;
                Console.WriteLine(coin);
                coin = 0;
            }
        }
    }
}

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

using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;

void solve(){
	string s;
	cin >> s;

	int ans = 0, cnt = 0;
	for(auto ch : s){
		if(ch == 'R') ++cnt;
		else{
			ans = max(ans, cnt);
			cnt = 0;
		}
	}

	cout << max(ans, cnt) << "\n";
}

signed main (void){
	// Fast_IO
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// Set Fixed Notation (default sucks), High Precision for Floating-Point Output
	cout << fixed << setprecision(20);

	// Multiple TCs
	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


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

using namespace std;
typedef long long ll;

int n;
double p[3030];
double dp[3030][3030];
double f(int idx, int heads)
{
    if (idx == n) return heads > n - heads;
    double &ret = dp[idx][heads];
    if (ret == ret) return ret;
    return ret = f(idx+1, heads + 1) * p[idx] + f(idx+1, heads) * (1.0 - p[idx]);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    memset(dp, -1, sizeof dp);
    cin >> n;
    for (int i =0 ; i < n; ++i) cin >> p[i];
    cout << fixed << setprecision(10) << f(0, 0) << "\n";

    return 0;
}


Measured memory_bytes: 72320
#include <bits/stdc++.h>
using namespace std;
#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 repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define loop(i,a,B) for (int i = a; i B; i++)
#define loopR(i,a,B) for (int i = a; i B; i--)
#define all(x) (x).begin(), (x).end()
#define allR(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", my_dmp(#__VA_ARGS__, __VA_ARGS__)
void my_dmp(const char*) { cerr << endl; }
template <class T, class... U> void my_dmp(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; my_dmp(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
using ld = long double;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, vector<T>, greater<T> >;
template <class T, class = typename T::iterator, class = typename enable_if<!is_same<T, string>::value>::type>
ostream& operator<<(ostream& os, T const& v) { os << "{"; for (auto const& x : v) os << " " << x; return os << " }"; }
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S>& p) { return is >> p.first >> p.second; }
struct my_Init { my_Init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } my_init;

template <class T, size_t d, class = typename enable_if<(d == 0)>::type> constexpr auto make_v(T const& x = {}) { return x; }
template <class T, size_t d, class... U, class = typename enable_if<(d > 0)>::type> constexpr auto make_v(size_t n, U... x) { auto val = make_v<T,d-1>(x...); return vector<decltype(val)>(n, move(val)); }
template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> constexpr bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> constexpr bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
template <class It> constexpr auto sumof(It b, It e) { return accumulate(b,e,typename iterator_traits<It>::value_type{}); }
const ll INF = (1LL<<62)-1; // ~ 4.6e18
////////////////////////////////

int32_t main() {
    string s; cin >> s;
    int n = s.size();
    vector<int> a(n+1);
    rep1 (i,n) if (s[i-1] == '<') chmax(a[i],a[i-1]+1);
    repR (i,n) if (s[i] == '>') chmax(a[i], a[i+1]+1);
    cout << sumof(all(a)) << endl;
    //
    dump(a);
}


Measured memory_bytes: 4764
M=10**9+7
r=tuple(tuple((j-k)*9%13for j in range(10))for k in range(13))
d=[1]+[0]*12
for c in input():
    if c>'9':
        d=[sum(d[j]for j in k)%M for k in r]
    else:
        d=[d[(int(c)-k)*9%13]for k in range(13)]
print(d[5])

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

long num[100010]; long a[100010];

int main(){long N; long cnt = 0;//cntは10e5以下の個数
cin >> N;
erep(i, N) cin >> a[i];
erep(i, N){
    if(a[i] <= 100000){
      num[a[i]]++;
      cnt++;
    }
    }
long ans = N - cnt;
erep(i, 100000){
    if(num[i] < i) ans += num[i];
    else ans += num[i] - i;
}

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

Measured memory_bytes: 1024
n, m, x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
l, r = 0, 0
(1..x).each do |i|
  if a.include?(i)
    l += 1
  end
end
(x..n).each do |i|
  if a.include?(i)
    r += 1
  end
end
puts [l,r].min

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;

int main(){  
	int n, a, b, c, x, y[108000];
	while(cin >> n >> a >> b >> c >> x, n){	
		int res = -1;
		for(int i = 0;i < n;i++){
			cin >> y[i];
		}
		int ys = 0;
		for(int i = 0;i <= 10000;i++){
			if(y[ys] == x)ys++;
			if(ys == n){
				res = i;
				break;
			}
			x = (a * x + b) % c;
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 800000000
#define MAX 1000

int main(){
  string S;
  int K;
  cin>>S>>K;
  int n=S.size();

  int i=0;
  int j=0;
    while(i<K){
    int x=S.at(j)-'a';
    if(j==n-1){
      int y=(x+K-i)%26;
      S.at(j)=(char)('a'+y);
      break;
    }
    if((26-x)%26<=K-i){
      i+=(26-x)%26;
      S.at(j)='a';
      j++;
    }else{
      j++;
    }
  }
  cout<<S<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define N 3005
#define M 998244353
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
ll n,s;
ll a[N];
ll dp[N][N];
ll run(int idx,int now)
{
    if(now==s)
    {
        return n-idx+1;
    }
    if(idx==n)
    {
        return 0;
    }
    if(dp[idx][now]!=-1)
        return dp[idx][now];
    //not taking
    ll ans=0;
    ans+=run(idx+1,now);
    ans%=M;
    // taking
    ll age=idx+1;
    if(now+a[idx]<=s&&now==0)
        ans+=(age*run(idx+1,now+a[idx]))%M;
    else if(now+a[idx]<=s&&now!=0)
        ans+=(run(idx+1,now+a[idx]))%M;
    ans%=M;
    return dp[idx][now]=ans;
}

main()
{
    memset(dp,-1,sizeof dp);
    cin>>n>>s;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    cout<<run(0,0);

}


Measured memory_bytes: 71040
/// In The Name Of God

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

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

const int N = (int)(1 << 18) + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

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

using namespace std;

void upd(int &x, int y) {
	if (x < y) x = y;
}

int m, n;
int a[N], dp[N][2];
int main() {
	#ifdef wws
		freopen ("in.txt", "r", stdin);
	#endif
	Kazakhstan
	cin >> m;
	int n = (1 << m);
	memset(dp, -0x3f, sizeof(dp));
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		dp[i][0] = a[i];
	}
	for (int i = 0; i < m; i++) {
		for (int mask = 0; mask < n; mask++) {
			if (mask & (1 << i)) continue;
			upd(dp[mask | (1 << i)][1], dp[mask][0] + dp[mask | (1 << i)][0]);
			upd(dp[mask | (1 << i)][0], dp[mask][0]);
		}
	}
	for (int k = 1; k < n; k++) {
		upd(dp[k][1], dp[k - 1][1]);
		cout << dp[k][1] << nl;
	}
	ioi
}


Measured memory_bytes: 6144
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;
#define MAXN 2000
#define MOD 1000000007
#define ll long long
#define rint register int
#define gc() getchar()
inline ll read(ll r=0,int s=0,int c=gc()){for(;c<48||c>57;s=c,c=gc());for(;c>=48&&c<=57;(r*=10)+=c-48,c=gc());return s^'-'?r:-r;}
inline int fxp(int s, int n=MOD-2){int a=1; for(; n; n&1 ? a = 1ll*a*s%MOD : 0, s = 1ll*s*s%MOD, n >>= 1); return a;}
struct Edge{int u,v,w;}e[MAXN+5]; inline bool operator < (Edge a, Edge b){return a.w<b.w;}
int fa[MAXN+5], n, m, L, M, R; ll X, W, C, del[MAXN+5];
inline int getf(int x){return x^fa[x]?fa[x]=getf(fa[x]):x;} inline bool Union(int x, int y){return (x=getf(x))^(y=getf(y))?fa[x]=y,true:false;}
ll Kruskal(int c=n-1){for(rint i = 1; i <= m && Union(e[i].u,e[i].v)?C+=e[i].w,--c:true; i++); return C;}


int main()
{
	n = read(), m = read(), X = read(); for(rint i = 1; i <= m; e[i].u = read(), e[i].v = read(), e[i].w = read(), i++); sort(e+1,e+m+1);
	for(rint i = 1; i <= n; fa[i] = i, i++); W = Kruskal(); if(W>X) return puts("0"),0;
	for(rint i = 1, j; i <= m; Union(e[i].u,e[i].v), C = e[i].w, Kruskal(n-2), del[i] = C-W, i++) for(j = 1; j <= n; fa[j] = j, j++);
	for(rint i = 1; i <= m; L += del[i]<X-W, M += del[i]==X-W, i++); R = m-L-M;
	printf("%d\n",(1ll+!!L)*fxp(2,R)*(fxp(2,M)+MOD-1-!L)%MOD); return 0;
}

Measured memory_bytes: 256
def main():
  h,w,k=map(int,input().split())
  si,sj,ti,tj=map(int,input().split())
  si-=1
  sj-=1
  ti-=1
  tj-=1
  b=[input()for _ in range(h)]
  ans=[[-1]*w for _ in range(h)]
  ans[si][sj]=0
  from collections import deque
  d=deque()
  d.append((si,sj))
  while d:
    x,y=d.popleft()
    if x==ti and y==tj:
      exit(print(ans[x][y]))
    for dx,dy in [[1,0],[-1,0],[0,-1],[0,1]]:
      for i in range(1,k+1):
        xx=x+dx*i
        yy=y+dy*i
        if not(0<=xx<h and 0<=yy<w) or b[xx][yy]=="@":break
        if 0<=ans[xx][yy]<=ans[x][y]:break
        if ans[xx][yy]==-1:d.append((xx,yy))
        ans[xx][yy]=ans[x][y]+1
  print(-1)
if __name__ == "__main__":
  main()

Measured memory_bytes: 93160
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int isPrime(int a) {
    for (int i = 2; i * i <= a; ++i) {
        if (a % i == 0) {
            return 0;
        }
    }
    return 1;
}





void oneCase () {
    int a, b, c;
    cin >> a >> b >> c;
    if (b - a == c - b) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    cout << "\n";

}





int main() {
    int t = 1;
//    cin >> t;
    while (t > 0) {
        oneCase();
        --t;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

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

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

class WarshallFloyd:
    def __init__(self,n):
        self.v = n
        self.d = [[1e100]*n for _ in range(n)]
        for i in range(n):
            self.d[i][i] = 0

    def path(self,x,y,c):
        if x == y:
            return False
        self.d[x][y] = c
        self.d[y][x] = c
        return True

    def build(self):
        for k in range(self.v):
            for i in range(self.v):
                for j in range(self.v):
                    self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])

n,m,l = map(int,input().split())
wf = WarshallFloyd(n)
for i in range(m):
    a,b,c = map(int,input().split())
    wf.path(a-1,b-1,c)
wf.build()
d = [[1e100]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            d[i][j] = 0
        elif wf.d[i][j] <= l:
            d[i][j] = 1

for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

q = int(input())
for i in range(q):
    s,t = map(int,input().split())
    ans = d[s-1][t-1]
    if ans == 1e100:
        print(-1)
    else:
        print(ans - 1)


Measured memory_bytes: 134944
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
  int x,y;
  int t,l;

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

  for(int c=0;c<=x;c++)
  {
    l=c*2;
    l+=(x-c)*4;
    if(l==y)
    {
      printf("Yes\n");
      return 0;
    }
  }

  printf("No\n");

  return 0;
}

Measured memory_bytes: 1656
N,D=map(int,input().split())
COUNT=0
DISTANCE=0

LIST=[[0]*D]*N
#print(LIST)
#print(LIST[0])

for i in range(N):  
  LIST[i]=list(map(int,input().split()))

#print(LIST)
  
  
for i in range(N):
  for j in range(N):
    for k in range(D):
      DISTANCE=DISTANCE+(LIST[i][k]-LIST[j][k])**2
    DISTANCE=DISTANCE**0.5
    if DISTANCE%1==0 and DISTANCE!=0:
      COUNT=COUNT+1
      #print(COUNT,DISTANCE)
    DISTANCE=0
    
print(int(COUNT/2))
      
      


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <chrono>
#include <utility>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

constexpr int cm = 1<<17;
char buff[cm], *ci = buff + cm, ct;

inline char readchar() {
  if (ci - buff == cm) {
    fread(buff, 1, cm, stdin);
    ci = buff;
  }
  return *ci++;
}

inline int readint() {
  int num = 0;
  if (ci - buff + 16 > cm) {
    while ((ct = readchar()) >= '0') {
      num = (num << 3) + (num << 1) + ct - '0';
    }
  } else {
    while ((ct = *ci++) >= '0') {
      num = (num << 3) + (num << 1) + ct - '0';
    }
  }
  return num;
}

int main(){
  auto start = chrono::system_clock::now();

  int n = readint();

  vector<queue<int>> v(1002, queue<int> ());
  rep(i, n) {
    rep(j, n - 1) {
      int a = readint();
      v[i + 1].emplace(a);
    }
  }

  for (int day = 1; day <= n * (n - 1) / 2; ++day) {
    bool done[1002] = {};
    for (int i = 1; i <= n; ++i) {
      if (done[i]) continue;
      if (v[i].empty()) continue;
      int next = v[i].front();
      if (done[next]) continue;
      if (v[next].front() == i) {
        v[i].pop(); v[next].pop();
        done[i] = done[next] = true;
      }
    }
    if (all_of(done, done + n, [](const bool& x){return x == false;})){
      printf("-1");
      return 0;
    }
    if (all_of(v.begin(), v.end(), [](const queue<int>& x){return x.empty();})) {
      printf("%d", day);
      return 0;
    }
    auto now = chrono::system_clock::now();
    auto dur = now - start;
    auto msec = chrono::duration_cast<chrono::microseconds>(dur).count();
    if (msec >= 26900) {
      printf("%d", n * (n - 1) / 2);
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 4864
# 組み合わせの計算は下記サイトから引用
# https://qiita.com/derodero24/items/91b6468e66923a87f39f#%E7%95%AA%E5%A4%96%E7%B7%A8
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N,K=map(int, input().split())
R=N-K

for i in range(1,K+1):
    if N-K+1<i or K-1<i-1:
        print(0)
    else:
        print(cmb(R+1,i,mod) * cmb(K-1,i-1,mod) % mod)


Measured memory_bytes: 4596
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

struct Card {
    char suit;
    int value;

    bool operator<(const Card& c) const {
        return this->value < c.value;
    }
    bool operator<=(const Card& c) const {
        return this->value <= c.value;
    }
    Card& operator=(int val) {
        this->value = val;
    }
};
#define MAX 100000
#define SENTINEL 2000000000
Card L[MAX/2+2],R[MAX/2+2];
void merge(Card *a,int n, int l,int mid,int r) {
    int n1=mid-l;
    int n2=r-mid;
    rep(i,n1) L[i]=a[l+i];
    rep(i,n2) R[i]=a[mid+i];
    L[n1]=SENTINEL;
    R[n2]=SENTINEL;
    int i,j;
    i=j=0;
    for(int k=l;k<r;k++) {
        if(L[i]<=R[j]) a[k]=L[i++];
        else a[k]=R[j++];
    }
}
void merge_sort(Card *a,int n,int l,int r) {
    if(l+1<r) {
        int mid=(l+r)/2;
        merge_sort(a,n,l,mid);
        merge_sort(a,n,mid,r);
        merge(a,n,l,mid,r);
    }
}
int partition(Card *a,int p,int r) {
    int i,j;
    Card x;
    x=a[r];
    i=p-1;
    for(int j=p;j<r;j++) {
        if(a[j]<=x) {
            i++;
            swap(a[i],a[j]);
        }
    }
    swap(a[i+1],a[r]);
    return i+1;
}

void quick_sort(Card *a,int n,int p,int r) {
    int q;
    if(p < r) {
        q = partition(a,p,r);
        quick_sort(a,n,p,q-1);
        quick_sort(a,n,q+1,r);
    }
}

Card A[MAX],B[MAX];
int main() {
    int n;
    cin>>n;
    rep(i,n) {
        cin>>A[i].suit>>A[i].value;
        B[i]=A[i];

    }

    merge_sort(A,n,0,n);
    quick_sort(B,n,0,n-1);
    bool is_stable = true;

    rep(i,n) is_stable &= A[i].suit == B[i].suit;

    if(is_stable) cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
    rep(i,n) cout<<B[i].suit<<" "<<B[i].value<<endl;

    return 0;
}

Measured memory_bytes: 3512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

string s;

int main() {
    cin >> s;

    ll ans = 0;

    for (int i = 0; i < s.size(); ++i) {
        for (int j = 1; i + j <= s.size(); ++j) {
            ll n = stoll(s.substr(i, j));
            ll l = (i == 0 ? 1LL : (1LL << (i - 1)));
            ll r = (i + j == s.size() ? 1LL : 1LL << (s.size() - (i + j + 1)));
            ans += l * r * n;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
A=[0]*(M+1)
cnt=0
for i in range(N):
  S=list(map(int,input().split()))
  for j in range(1,S[0]+1):
    A[S[j]]+=1
    #print(A)
#print(A)
for i in range(len(A)):
  if A[i]>=N:
    cnt+=1
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c,n) for(int i=c;i<n;i++)

int main(){
  int h,w;
  cin>>h>>w;
  
  char lis[h+2][w+2];
  memset(lis,'0',sizeof(lis));
  
  rep(i,1,h+1){
    rep(j,1,w+1){
      cin>>lis[i][j];
    }
  }
  
  rep(i,1,h+1){
    rep(j,1,w+1){
      if(lis[i][j]=='#'){
        if(lis[i-1][j]=='#'){continue;}
        else if(lis[i+1][j]=='#'){continue;}
        else if(lis[i][j-1]=='#'){continue;}
        else if(lis[i][j+1]=='#'){continue;}
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  
  cout<<"Yes"<<endl;
  
  return 0;
}


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

int main(){
	int a = 0;
	string n;
	cin >> n;
	for (int i = 0; i < 3; i++)
		if (n[i] == '7')
			a++;
	if (a > 0)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 3576
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,dy[]={0,1},dx[]={1,0};
string s[10],state[10];
// 0
//1 3
// 2

string rot90(string s){
    return s[3]+s.substr(0,3);
}

int enc(char c){
    if(c=='R')return 0;
    if(c=='r')return 1;
    if(c=='G')return 2;
    if(c=='g')return 3;
    if(c=='B')return 4;
    if(c=='b')return 5;
    if(c=='W')return 6;
    if(c=='w')return 7;
}

#define id(y,x) ((y)*3+(x))

int f(int y,int x,int mask){
    if(y==3)return 1;
    if(x==3)return f(y+1,0,mask);
    int res=0;
    rep(i,9)if(!(mask>>i&1)){
        string t=s[i];
        rep(j,4){
            t=rot90(t);
            if(y>0){
                int a=enc(t[0]),b=enc(state[id(y-1,x)][2]);
                if((a+b)%2==0 || a/2!=b/2)continue;
            }
            if(x>0){
                int a=enc(t[1]),b=enc(state[id(y,x-1)][3]);
                if((a+b)%2==0 || a/2!=b/2)continue;
            }
            state[id(y,x)]=t;
            res+=f(y,x+1,mask|1<<i);
        }
    }
    return res;
}

int main(){
	cin>>n;
    rep(tc,n){
        rep(i,9)cin>>s[i];
        int used[10]={};
        string state[10];
        cout<<f(0,0,0)<<endl;
    }
}

Measured memory_bytes: 928
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    string s,t;
    cin >> s >> t;
    bool ans=false;
    int slen = s.length();
    int tlen = t.length();
    for(int i=slen-tlen; i>=0; i--){
        for(int j=0; j<tlen; j++){
            if(s[i+j]!='?'){
                if(s[i+j]==t[j]){
                    ans = true;
                }else{
                    ans = false;
                    break;
                }
            }else{
                ans = true;
            }
        }
        //cout << ans << endl;
        if(ans){
            for(int j=0; j<tlen; j++){
                s[i+j]=t[j];
            }
            for(int j=0; j<slen; j++){
                if(s[j]=='?'){
                    s[j]='a';
                }
            }
            break;
        }
    }
    if(ans){
        cout << s << endl;
    }else{
        cout << "UNRESTORABLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from heapq import heappop,heappush

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

h=[]
for l in a:
    heappush(h,-l) 
    
for i in range(m):
    amax=heappop(h)
    l=(-amax)//2
    heappush(h,-l)
    
print(-sum(h))


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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  std::vector<int> v(n), v1;
  for(int i=0;i<n;i++){
    cin>>v[i];
    v1.push_back(v[i]);
  }
  sort(v.begin(), v.end());
  for(int i=0;i<n;i++){
    if(v1[i]<v[n/2]) cout<<v[n/2]<<endl;
    else cout<<v[n/2-1]<<endl;
  }

  return 0;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

ll dp[1001][1001];

int main(int argc, char const *argv[]) {
    input_init();
    rep(i,1001) rep(j,1001) dp[i][j] = LINF;
    int h,w; cin>>h>>w;
    int sy,sx,gy,gx; cin>>sy>>sx>>gy>>gx;
    --sy; --sx;
    --gy; --gx;
    vector<string> g(h);
    rep(i,h) cin>>g[i];
    deque<P> q;
    q.emplace_back(sy,sx);
    dp[sy][sx] = 0;
    while (!q.empty()) {
        P cur = q.front(); q.pop_front();
        int cy = cur.first; int cx = cur.second;
        if (cy == gy && cx == gx) {
            continue;
        }
        for (int dy = -2; dy <= 2; ++dy) {
            for (int dx = -2; dx <= 2; ++dx) {
                if (dy == 0 && dx == 0) continue;
                int cost = 1;
                if ((dy == 1 && dx == 0) || (dy == 0 && dx == 1) || (dy==-1 && dx==0) || (dy==0 && dx==-1)) {
                    cost = 0;
                }
                int ny = cy+dy; int nx = cx+dx;
                if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
                if (g[ny][nx] == '#') continue;
                if (chmin(dp[ny][nx], dp[cy][cx]+cost)) {
                    if (cost) q.emplace_back(ny,nx);
                    else q.emplace_front(ny,nx);
                }
            }
        }
    }

    if (dp[gy][gx] != LINF) cout << dp[gy][gx] << '\n';
    else cout << -1 << '\n';
    return 0;
}

Measured memory_bytes: 12688
#ifndef ___Class_RangeTree
#define ___Class_RangeTree

// ------ Includes ------ //
#include <limits>
#include <vector>
#include <algorithm>

template<typename Type> class RangeTree {
private:
	int size_;
	std::vector<std::vector<Type> > dat;
	std::vector<std::vector<int> > vl;
	inline int query_(int a, int b, Type x, int k, int l, int r, int e) {
		// Find range [a, b) : value < x : Now k-th node and the range is [l, r) and e integers below x in the range
		if (r <= a || b <= l || e == 0) return 0;
		if (a <= l && r <= b) return e;
		int lc = query_(a, b, x, k << 1, l, (l + r) >> 1, vl[k][e - 1]);
		int rc = query_(a, b, x, k << 1 | 1, (l + r) >> 1, r, e - vl[k][e - 1]);
		return lc + rc;
	}
public:
	RangeTree() : size_(0), dat(std::vector<Type>()) {};
	template<class T>
	RangeTree(T begin_, T end_) {
		int n = (end_ - begin_);
		for (size_ = 1; size_ < n; size_ <<= 1);
		dat.resize(size_ << 1);
		vl.resize(size_);
		for (int i = 0; i < n; i++) dat[i + size_].push_back(*(begin_ + i));
		for (int i = size_ - 1; i > 0; i--) {
			dat[i].resize(dat[i << 1].size() + dat[i << 1 | 1].size());
			vl[i].resize(dat[i].size());
			int cl = 0;
			for (int j = 0; j < dat[i].size(); j++) {
				if (j - cl == dat[i << 1 | 1].size() || (cl != dat[i << 1].size() && dat[i << 1][cl] < dat[i << 1 | 1][j - cl])) dat[i][j] = dat[i << 1][cl++];
				else dat[i][j] = dat[i << 1 | 1][j - cl];
				vl[i][j] = cl;
			}
		}
	}
	inline int size() { return size_; }
	inline int query(int l, int r, Type x) {
		// Find range [a, b) : value < x
		int ptr = lower_bound(dat[1].begin(), dat[1].end(), x) - dat[1].begin();
		return query_(l, r, x, 1, 0, size_, ptr);
	}
};

#endif

#include <cstdio>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
int N, Q, xl, yl, xr, yr;
int main() {
	scanf("%d%d", &N, &Q);
	vector<pair<int, int> > p(N);
	for (int i = 0; i < N; i++) scanf("%d%d", &p[i].first, &p[i].second);
	sort(p.begin(), p.end());
	vector<int> z1(N), z2(N);
	for (int i = 0; i < N; i++) {
		z1[i] = p[i].first;
		z2[i] = p[i].second;
	}
	RangeTree<int> seg(z2.begin(), z2.end());
	while (Q--) {
		scanf("%d%d%d%d", &xl, &yl, &xr, &yr);
		int ptr1 = lower_bound(z1.begin(), z1.end(), xl) - z1.begin();
		int ptr2 = lower_bound(z1.begin(), z1.end(), xr + 1) - z1.begin();
		int res1 = seg.query(ptr1, ptr2, yl);
		int res2 = seg.query(ptr1, ptr2, yr + 1);
		printf("%d\n", res2 - res1);
	}
	return 0;
}

Measured memory_bytes: 4100
M=998244353
S=input()
N=len(S)
d=[[0]*4001 for _ in range(4001)]
d[0][0]=1
x=0
for i in range(2*N):
	if i<N:
		x+=int(S[i])
		y=2*i+2-x
	for j in range(i+1):
		for k in range(2):
			if i-y<=j-k<x:d[j+1-k][i-j+k]+=d[j][i-j]%M
print(d[x][y]%M)

Measured memory_bytes: 165852