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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 30;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

map<ll, int>  prime_factorization_map(ll x) {
  map<ll, int> res;
  for(ll i = 2; i*i <= x; ++i) {
    while(x % i == 0) {
      if(res.find(i) == res.end()) res[i] = 0;
      ++res[i];
      x /= i;
    }
  }
  if(x != 1) res[x] = 1;

  return res;
}

int main()
{
  ll a, b; cin >> a >> b;
  ll x = __gcd(a, b);
  auto mp = prime_factorization_map(x);
  cout << mp.size() + 1 << endl;
}

Measured memory_bytes: 256
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 10, M = 1e3 + 10;
const int INF = INT_MAX;
const db PI = acos(-1);

void test();

int main() {
    fast_io();
    test();
    return 0;
}

void test() {
    int n, m;
    cin >> n >> m;
    int mn = INF, mx = 0;
    for (int i = 0, x, y; i < m; ++i) {
        cin >> x >> y;
        mn = min(mn, y);
        mx = max(mx, x);
    }
    cout << max(0, mn - mx + 1) << "\n"; 
}


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

using namespace std;

bool isPos(vector<long long> &a,long long p,long long k) {

    long long cuts=0;

    for(long long i = 0 ; i < a.size() ; i++) {

        long long cur=ceil(a[i]/(long double)p);

        cuts+=(cur-1);

    }

    return cuts<=k;

}

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long long n;

    cin >> n;

    long long k;

    cin >> k;

    vector<long long> a(n);

    for(long long i = 0 ; i < n ; i++) {

        cin >> a[i];

    }

    long long l=1;

    long long r=LLONG_MAX/100;

    long long res=LLONG_MAX/100;

    while(l<=r) {

        if(l==r) {

            if(isPos(a,l,k)) {

                res=min(res,l);

            }

            break;

        }

        long long m = (l+r)/2;

        if(isPos(a,m,k)) {

            res=min(res,m);

            r=m-1;

        } else {

            l=m+1;

        }

    }

    cout << res << '\n';

    return 0;

}



Measured memory_bytes: 4764
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########

def resolve():
    x,y = mi()
    minval = x * 2
    maxval = x * 4
    invalid  = 1
    if minval<= y and y <= maxval and y%2 == 0:
        invalid = 0
    print("No" if invalid else "Yes")

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    ll x,k,d;cin>>x>>k>>d;
    x=abs(x);
    ll th=x/d;
    if(k<th){
        cout<<abs(x-k*d);
    }
    else {
        if((k-th)%2==0){
            cout<<abs(x%d);
        }
        else cout<<abs((x%d)-d);
    }
 
return 0;
}

Measured memory_bytes: 3648
while True:
    r = list(map(int, input().split()))

    if r[0] == -1 and r[1] == -1 and r[2] == -1:
        break
    elif r[0] == -1 or r[1] == -1:
        print("F")
    elif r[0] + r[1] >= 80:
        print("A")
    elif r[0] + r[1] >= 65 and r[0] + r[1] < 80:
        print("B")
    elif r[0] + r[1] >= 50 and r[0] + r[1] < 65:
        print("C")
    elif r[0] + r[1] >= 30 and r[0] + r[1] < 50:
        if r[2] >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")

Measured memory_bytes: 7684
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

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

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



ll calc(ll n) {
  if (n == 1) {
    return 1LL;
  } else {
    return 1LL + 2 * calc(n/2);
  }
}

ll H;

int main () {
  cin >> H;
  cout << calc(H) << "\n";
}

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

using namespace std;

string colors[8] = {
  "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"
};

int c(char ch) {
  if(isdigit(ch)) return ch-'0';
  return ch-'a'+10;
}

int d(string s) {
  return c(s[0])*16 + c(s[1]);
}

int main() {
  
  int colR[8];
  int colG[8];
  int colB[8];
  
  colR[0] = d("00"); colG[0] = d("00"); colB[0] = d("00");
  colR[1] = d("00"); colG[1] = d("00"); colB[1] = d("ff");
  colR[2] = d("00"); colG[2] = d("ff"); colB[2] = d("00");
  colR[3] = d("00"); colG[3] = d("ff"); colB[3] = d("ff");
  colR[4] = d("ff"); colG[4] = d("00"); colB[4] = d("00");
  colR[5] = d("ff"); colG[5] = d("00"); colB[5] = d("ff");
  colR[6] = d("ff"); colG[6] = d("ff"); colB[6] = d("00");
  colR[7] = d("ff"); colG[7] = d("ff"); colB[7] = d("ff");
  
  /*
  for(int i=0; i<8; i++) {
    colR[i] = i & 1 ? 255 : 0;
    colG[i] = i & 2 ? 255 : 0;
    colB[i] = i & 4 ? 255 : 0;
  }
  */
  
  string s;
  
  while(cin >> s) {
    if(s == "0") break;
    
    s = s.substr(1);
    
    int R = d(s.substr(0, 2));
    int G = d(s.substr(2, 2));
    int B = d(s.substr(4, 2));
    
    int minD = (int)1e9;
    int id = -1;
    for(int i=0; i<8; i++) {
      if( minD > pow(R-colR[i],2.0) + pow(G-colG[i],2.0) + pow(B-colB[i],2.0) ) {
	id = i;
	minD = pow(R-colR[i],2.0) + pow(G-colG[i],2.0) + pow(B-colB[i],2.0);
      }
    }
    
    cout << colors[id] << endl;
  }
  
  return 0;
}

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

int main() {
  int N,t=0,s;
  cin>>N;
  for(int i=0;i<N;i++){
    int c=0,x=i+1;
    while(x%2==0){
      x/=2;
      c++;
    }
    if(c>=t){
      t=c;
      s=i+1;
    }
  }
  cout<<s<<endl;
}


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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

template<typename T> inline constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const int MOD = 1000000007;
const int INF = INT_MAX;

signed main()
{
	int N;
	cin >> N;

	vector<queue<int>> A(N);
	rbf(a, A) {
		rep(i, N - 1) {
			int tmp;
			cin >> tmp;
			a.push(tmp);
		}
	}

	vector<bool> yet(N, true);

	int day = 0, dcnt = 0;

	bool can = true, can2 = false;

	while (1) {
		if (dcnt == N * (N - 1)) break;
		can = true;

		rep(i, N) {
			if ((!A[i].empty()) && (!A[A[i].front() - 1].empty())) {
				int idx = A[i].front() - 1;

				if (((A[idx].front() - 1) == i) && yet[i] && yet[idx]) {
					A[i].pop();
					A[idx].pop();
					dcnt += 2;

					yet[i] = false;
					yet[idx] = false;

					can = false;
				}
			}
		}
		
		if (can) {
			can2 = true;
			break;
		}

		fill(All(yet), true);
		day++;
	}

	if (can2) COL(-1);
	else COL(day);

	return 0;
}

Measured memory_bytes: 6784
#include <iostream>
#include <vector>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

int n;
vector< pair<int, int> > input;

int dfs(int p) {
  int t = input[p].first + 1;
  char e = (char) input[p].second;
  int ans;

  if(e == '+') ans = 0;
  if(e == '*') ans = 1;
  if(e != '+' && e != '*') return e;

  for(int i = p + 1; input[i].first >= t && i < input.size(); i++) {
    if(input[i].first > t) continue;

    int v;
    if(input[i].second == '+' || input[i].second == '*') v = dfs(i);
    else v = input[i].second;

    if(e == '+') ans += v;
    if(e == '*') ans *= v;
  }

  return ans;
}

int main(void) {
  while(1) {
    cin >> n;
    if(n == 0) break;

    input.clear();
    REP(i, 0, n) {
      string line; cin >> line;
      int level = 0;
      for(; line[level] == '.'; level++);
      char c = line[level];
      input.push_back(pair<int, int>(level, c == '+' || c == '*' ? c : c - '0'));
    }

    cout << dfs(0) << endl;
  }

  return 0;
}

Measured memory_bytes: 3140
import bisect
def I(): return int(input())
def LI(): return list(map(int,input().split()))
n=I()
a=sorted(LI())
b=sorted(LI())
c=sorted(LI())
ans=0
for bd in b:
    oka=bisect.bisect_left(a,bd)
    okc=bisect.bisect_right(c,bd)
    ans+=oka*(n-okc)
print(ans)

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename T>
ll nCr(T n, T r) {
ll ans = 1;
    for (int i = n; i > n - r; --i) {
            ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans/i;
    }
    return ans;
}

int main() {
    int n;
    string s;
    cin >> n >> s;
    int r = 0;
    int g = 0;
    int b = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') ++r;
        if (s[i] == 'G') ++g;
        if (s[i] == 'B') ++b;
    }
    ll rll = nCr(r, 1);
    ll gll = nCr(g, 1);
    ll bll = nCr(b, 1);
    ll res = rll * gll * bll;
    for (int i = 0; i < n; ++i) {
        for (int j = 1; i+j+j < n; ++j) {
            if (s[i] != s[i+j] && s[i+j] != s[i+j+j] && s[i+j+j] != s[i]) --res;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	while (true){
		int N;
		cin >> N;
		if (N == 0) return 0;

		char c[100];
		int point[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
		int cnt;
		int stage = 0;
		for (int i = 0; i < 100; i++){
			cin >> c[i];
			cnt = i%N;
			if (cnt == 0) cnt = N-1;
			else cnt -= 1;
			if (c[i] == 'M'){
				point[cnt]++;
			}
			else if (c[i] == 'S'){
				stage += point[cnt]+1;
				point[cnt] = 0;
			}
			else {
				point[cnt] += stage+1;
				stage = 0;
			}
		}
		sort(point, point + N);
		for (int i = 0; i < N; i++){
			cout << point[i] << ' ';
		}
		cout << stage << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int count = 0;
for(int i = 0; i < n; i++){
	int a, b;
	cin >> a >> b;
	if(count == 3){
		break;
	} if(a == b){
		count++;
	} if (a != b){
		count = 0;
	}

	}
if(count == 3){
	cout << "Yes" << endl;
} else {
	cout << "No" << endl;
}

}



Measured memory_bytes: 3632
//AND BAND KA TOLA JO MERA CODE DEKHRA WO BHEN KA ....
//------------------------------------------Template------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define lp(i,a,b) for(ll i=a;i<b;i++)
#define rlp(i,a,b) for(ll i=b;i>=a;i--)
#define TEZI_BOLTEY ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INF 1e9
#define pb push_back 
#define mp make_pair 
#define endl "\n"
ll nCr(ll n, ll k) {double res = 1;lp(i,1,k+1){res = res * (n - k + i) / i;}return (int)(res + 0.01);}
//---------------------------------------------------------------------------------------------------
//---------------------------------<<< DRAGON SIN MELIODAS >>>---------------------------------------
//---------------------------------------------------------------------------------------------------
int32_t main()
{
	TEZI_BOLTEY
	ll a,b,c,d;
	cin >> a >> b>> c >> d;
	ll m1,m2;
	ll ans;
	if(a>=0)
	{
		if(c>=0)
		{
			m1=b,m2=d;
			ans=m1*m2;
		}
		else
		{
			if(d>=0)
			{
				m1=b,m2=d;
			ans=m1*m2;

			}
			else
			{
				m1=a;m2=d;
			ans=m1*m2;
			}
		}
	}
	else
	{
		if(b>=0)
		{
			if(c>=0)
			{
				m1=b,m2=d;
			ans=m1*m2;
			
			}
			else
			{
				if(d>=0)
				{
					ans=max(b*d,c*a);				
				}
				else
				{
					ans=a*c;
				}
			}
		}
		else
		{
			if(c>=0)
			{
				ans=b*c;
			}
			else
			{
				if(d>=0)
				{
					ans=a*c;
				}
				else
				{
					ans=a*c;
				}
			}
		}
	}
		cout << ans;
}


Measured memory_bytes: 3640
// Try M-SOLUTIONS プロコンオープン
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let mut tree = vec![vec![]; n];
    for _ in 1..n {
    	let a = get!(usize)-1;
        let b = get!(usize)-1;
        tree[a].push(b);
        tree[b].push(a);
    }
    let mut cs = vec![];
    for _ in 0..n {
    	cs.push(get!());
    }
    cs.sort();
    use std::collections::BinaryHeap;
    let mut pq = BinaryHeap::new();
    let mut ds = vec![1; n];
    for i in 0..n {
    	if tree[i].len() == 1 {
        	pq.push((0, i));
            ds[i] = 0;
        }
    }
    while let Some((d, i)) = pq.pop() {
    	let d = d - 1;
        for &j in tree[i].iter() {
        	if ds[j] < 1 {
            	continue;
            }
            ds[j] = d;
            pq.push((d, j));
        }
    }
    let mut mi = 0;
    for i in 0..n {
    	if ds[i] < ds[mi] {
        	mi = i;
        }
    }
    pq.push((ds[mi], mi));
    let mut vs = vec![0; n];
    while let Some(v) = cs.pop() {
    	if let Some((_, i)) = pq.pop() {
        	vs[i] = v;
            for &j in tree[i].iter() {
            	if vs[j] == 0 {
                	pq.push((v, j));
                }
            }
        }
    }
    let mut tmp = vec![];
    tmp.push(0);
    ds[0] = 1;
    let mut score = 0;
    while let Some(i) = tmp.pop() {
    	for &j in tree[i].iter() {
        	if ds[j] == 1 {
            	continue;
            }
            ds[j] = 1;
            score += std::cmp::min(vs[i], vs[j]);
            tmp.push(j);
        }
    }
    println!("{}", score);
    for i in 0..n {
    	if i > 0 {
        	print!(" ");
        }
        print!("{}", vs[i]);
    }
    println!();
}

Measured memory_bytes: 6396
import numpy as np
import sys
sys.setrecursionlimit(100000)


class UnionFind:
    def __init__(self, size):
        # -nが木のroot
        #親ノードの位置を格納
        self.table = [-1 for i in range(size)]

    def _find(self, x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def find(self, x):
        if self.table[x] < 0:
            return x
        self.table[x] = self.find(self.table[x])
        return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] >= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

    def get_ntree(self):
        res = 0
        for c in self.table:
            if c < 0:
                res += 1
        return res

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_nclass(self):
        done = []
        for x in range(len(self.table)):
            if x in done:
                continue
            while self.table[x] >= 0:
                done.append(x)
                x = self.table[x]

    def get_nodenum(self):
        res = []
        for t in self.table:
            if t < 0:
                res.append(-t)

        return res



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



directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count


N,M=acinput()

uf = UnionFind(N)

for i in range(M):
    tmp = acinput()
    uf.union(tmp[0]-1,tmp[1]-1)


print(uf.get_ntree())



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

int main(){
    int N;
    cin >> N;
    double ans = (double)(N/2 + N%2)/N;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int max = Math.max(Math.max(a, b), c);
        
        int dif = max * 3 - a - b - c;
        if (dif % 2 == 0) {
            System.out.println(dif / 2);
        } else {
            System.out.println(dif / 2 + 2);
        }
    }
}


Measured memory_bytes: 23764
use std::io::Read;
fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();

    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();

    let mut N: i32 = iter.next().unwrap().parse().unwrap();
    let ps: Vec<(i32)> = (0..N)
        .map(|_| { iter.next().unwrap().parse().unwrap() })
        .collect();

    let n = ps.iter().enumerate().map(|(i, e)| i + 1 != (*e as usize)).filter(|n| *n == true).count();
    println!("{}", if n == 2 || n == 0 {"YES"} else {"NO"})
}



Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int n,ans=1000000,m;
    cin>>n;
    vector<int>x(n);
    rep(i,n)cin>>x[i];
    for(int j=1;j<=100;j++){
        m=0;
        rep(i,n)m+=(j-x[i])*(j-x[i]);
        ans=min(ans,m);
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
string s, t;
map<char, int> ds, dt;
int main(void){
	cin >> s >> t;
	int n = s.length();

	vector<int> ns(n), nt(n);
	int k = 0;
	rep(i, n){
		if(ds.find(s[i]) == ds.end()) ds[s[i]] = ++k;
		ns[i] = ds[s[i]];
	}

	k = 0;
	rep(i, n){
		if(dt.find(t[i]) == dt.end()) dt[t[i]] = ++k;
		nt[i] = dt[t[i]];
	}

	if(ns == nt) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 2312
import java.util.*;

public class Main{

     public static void main(String []args){
        Scanner in = new Scanner(System.in);
        int number = 5;
        int max = 0, min = 123;
        while(number-- > 0){
            int k = in.nextInt();
            max = Math.max(k, max);
            min = Math.min(k, min);
        }
        int j = in.nextInt();
        if(max-min > j) System.out.println(":(");
        else System.out.println("Yay!");
     }
}

Measured memory_bytes: 21844
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    x = int(readline())

    for i in range(1, 361):
        if (x * i) % 360 == 0:
            return print(i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61868
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define mod 998244353
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=10001 ;
int main()
{
   fast ;
   ll n ;
   cin>>n ;
   vector<pll>r,g ;
   for(ll i=0;i<n;i++)
   {
       ll x,y ;
       cin>>x>>y ;
       r.pb({x,y}) ;
   }

   for(ll i=0;i<n;i++)
   {
       ll x,y ;
       cin>>x>>y ;
       g.pb({x,y}) ;
   }
   sort(all(r)) ;
   sort(all(g)) ;

   ll f[n] ;
   memset(f,0,sizeof(f)) ;
   ll ans=0 ;
   for(ll i=0;i<n;i++)
   {
       ll x=g[i].ff ;
       ll y=g[i].ss ;

       ll in=-1 ;
       ll mx=-1 ;
       for(ll j=0;j<n;j++)
       {
           if(f[j]==0&&r[j].ff<x&&r[j].ss<y)
           {
                if(in==-1)
                    in=j ;
                else
                {
                    if(r[j].ss>r[in].ss)
                    {
                        in=j ;
                    }
                }
           }
       }
       if(in!=-1)
       {
           ans++ ;
           f[in]=1 ;
       }
   }

   cout<<ans ;


}



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

int main() {
	int N,M;
	cin>>N>>M;
	vector<string> A(N),B(M);
	rep(i,N)cin>>A[i];
	rep(j,M)cin>>B[j];
	string ans = "No";
	rep(i,N)rep(j,N){
		int cnt = 0;
		rep(dx,M)rep(dy,M){
			int nx = i+dx,ny=j+dy;
			if(nx>=0&&nx<N&&ny>=0&&ny<N)
			if(A[nx][ny]==B[dx][dy])cnt++;
		}
		if(cnt == M*M)ans = "Yes";
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
    int A, B, C;
    int X;
    scanf("%d", &A);
    scanf("%d", &B);
    scanf("%d", &C);
    scanf("%d", &X);
    int count = 0;
    for(int a = 0; a <= A; a++) {
        for(int b = 0; b <= B; b++) {
            for(int c = 0; c <= C; c++) {
                int total = 500 * a + 100 * b + 50 * c;
                if(total == X) {
                    count++;
                }
            }
        }
    }
    printf("%d\n", count);
}

Measured memory_bytes: 2116
#include<cstdio>
#include<cstdlib>

using namespace std;

int main(){
	for(int a,b,c;scanf("%d%d%d",&a,&b,&c),a||b||c;){
		if(c==0){
			if(a==1 && b<0)	printf("%d %d %d %d\n",1,0,a,b);
			else		printf("%d %d %d %d\n",a,b,1,0);
			goto END;
		}

		int p,q,r,s;
		for(p=a;p>=1;p--){
			if(a%p==0){
				r=a/p;
				for(q=abs(c);q>=-abs(c);q--){
					if(q!=0 && c%q==0){
						s=c/q;
						if(b==p*s+q*r){
							printf("%d %d %d %d\n",p,q,r,s);
							goto END;
						}
					}
				}
			}
		}

		puts("Impossible");
		END:;
	}

	return 0;
}

Measured memory_bytes: 764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int redEat=fs.nextInt(), greenEat=fs.nextInt();
		int redHave=fs.nextInt();
		int greenHave=fs.nextInt();
		int blankHave=fs.nextInt();
		int[] red=fs.readArray(redHave), green=fs.readArray(greenHave), blank=fs.readArray(blankHave);
		Arrays.sort(red); Arrays.sort(green); Arrays.sort(blank);
		PriorityQueue<Integer> pq=new PriorityQueue<>();
		long ans=0;
		for (int i=0; i<redEat; i++) {
			ans+=red[redHave-1-i];
			pq.add(red[redHave-1-i]);
		}
		for (int i=0; i<greenEat; i++) {
			ans+=green[greenHave-1-i];
			pq.add(green[greenHave-1-i]);
		}
		for (int i:blank) {
			if (i>pq.peek()) {
				ans-=pq.remove();
				ans+=i;
				pq.add(i);
			}
		}
		System.out.println(ans);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");

		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

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

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

		public int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) {
				a[i]=nextInt();
			}
			return a;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

	}

}



Measured memory_bytes: 52680
#include "bits/stdc++.h"
#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pl pair<ll,ll>
#define rep(i,b) for(ll i=0;i<b;i++)

using namespace std;
ll n,t,ans=0;
int main(){
    cin>>n>>t;
    vl a(n);
    rep(i,n)cin>>a[i];
    rep(i,n-1)ans+=min(a[i+1]-a[i],t);
    cout<<ans+t<<endl;
}



Measured memory_bytes: 1792
import sys

N , M = [int(n) for n in input().split()]

A=[]
B=[]
for i in range(N):
    A.append(input())
for i in range(M):
    B.append(input())

for i in range(N-M+1):
    for j in range(N-M+1):
        corres = True
        for k in range(M):
            if A[i+k][j:j+M] != B[k]:
                corres = False
                break
        if corres == True:
            print('Yes')
            sys.exit()

print('No')


Measured memory_bytes: 3064
import sys
readline=sys.stdin.buffer.readline

S=readline().rstrip().decode("utf-8")
T=readline().rstrip().decode("utf-8")

S2T=[[0 for i in range(26)] for j in range(26)]
T2S=[[0 for i in range(26)] for j in range(26)]

for i in range(len(S)):
  s,t=ord(S[i])-97,ord(T[i])-97
  S2T[s][t]+=1
  T2S[t][s]+=1
#print("S2T:",S2T)

for i in range(26):
  cnt=0
  for j in range(26):
    if S2T[i][j]>0:
      cnt+=1
      if cnt>1:
        print("No")
        exit()
  cnt=0
  for j in range(26):
    if T2S[i][j]>0:
      cnt+=1
      if cnt>1:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 44912
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=3005;
const int mod=1e9+7;
const int inv=(mod+1)/2;
int n,q;
int a[maxn],dp[maxn][maxn];

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d%d",&n,&q);
	REP(i,n)scanf("%d",&a[i]);
	REP(i,n)REP(j,n)if(a[i]>a[j])dp[i][j]=1;
	REP(i,q){
		int x,y;
		scanf("%d%d",&x,&y);
		REP(j,n){
			if(j==x||j==y)continue;
			int sum=1LL*(dp[j][x]+dp[j][y])*inv%mod;
			dp[j][x]=dp[j][y]=sum;
			sum=1LL*(dp[x][j]+dp[y][j])*inv%mod;
			dp[x][j]=dp[y][j]=sum;
		}
		int sum=1LL*(dp[x][y]+dp[y][x])*inv%mod;
		dp[x][y]=dp[y][x]=sum;
	}
	int ans=0;
	REP(j,n)for(int k=j+1;k<=n;k++)ans=(ans+dp[j][k])%mod;
	REP(i,q)ans=2LL*ans%mod;
	printf("%d\n",ans);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 35456
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

bool cmp(pair<LL, LL> &x, pair<LL, LL> &y)
{
    return x.first > y.first;
}


int main(){
    LL h;
    LL w;
    LL m;
    cin >> h >> w >> m;
    LL tmp_h;
    LL tmp_w;
    vector<pair<LL, LL>> hw(m);
    vector<LL> sum_h(h,0);
    vector<LL> sum_w(w,0);

    for(LL i=0; i<m; i++){
        cin >> tmp_h >> tmp_w;
        tmp_h--;
        tmp_w--;
        hw[i].first=tmp_h;
        hw[i].second=tmp_w;
        sum_h[tmp_h]++;
        sum_w[tmp_w]++;
    }

    LL max_h=0;
    LL max_w=0;
    LL h_cnt=0;
    LL w_cnt=0;

    for(LL i=0; i<h; i++){
        max_h=max(max_h,sum_h[i]);
    }
    for(LL i=0; i<h; i++){
        if(max_h==sum_h[i]){
            h_cnt++;
        }
    }

    for(LL i=0; i<w; i++){
        max_w=max(max_w,sum_w[i]);
    }
    for(LL i=0; i<w; i++){
        if(max_w==sum_w[i]){
            w_cnt++;
        }
    }
    LL hw_cnt=0;
    for(LL i=0; i<m; i++){
        if(sum_h[hw[i].first]==max_h && sum_w[hw[i].second]==max_w){
            hw_cnt++;
        }
    }
    LL sum_hw=max_h+max_w;
    if(hw_cnt==h_cnt*w_cnt){
        cout << sum_hw-1 << endl;
    }else{
        cout << sum_hw << endl;
    }

    return 0;
}


Measured memory_bytes: 12732
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
typedef long long int ll;
typedef unsigned long long int ull;;
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
ll desc_cmp(const void* X,const void* Y){ll x=*(ll*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}

int main(){
    int a[3];scanf("%d %d %d",&a[0],&a[1],&a[2]);
    qsort(a,3,sizeof(int),asc_cmp);

    int cnt=0;
    for(int i=0;i<2;i++){
        if(a[i]==a[i+1])cnt++;
    }
    if(cnt==1)printf("Yes\n");
    else printf("No\n");

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define debug(a,b,c) cout << a << " " << b << " " << c << endl;
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define inl(x,n) for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower); 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code
	int n;
	cin >> n;
	map<string, int> m;
	while(n--){
		string s;
		cin >> s;
		m[s]++;
	}
	cout << "AC x " << m["AC"] << endl;
	cout << "WA x " << m["WA"] << endl;
	cout << "TLE x " << m["TLE"] << endl;
	cout << "RE x " << m["RE"] << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, Q;
ll D, M, C, DM, MC, DMC;

string S;

void solve() {
	cin >> N;
	cin >> S;
	cin >> Q;
	while(Q--) {
		ll res = 0;
		D = 0; M = 0; C = 0; DM = 0; MC = 0;;
		int K;
		cin >> K;
		rep(i, 0, K) {
			if(S[i] == 'D') D++;
			else if(S[i] == 'M') {
				M++; DM += D;
			}
			else if(S[i] == 'C') {
				C++;
				MC += M;
				res += DM;
			}
		}
		rep(i, 0, N - K) {
			// debug(D, M, C, DM, MC, DMC);
			if(S[i] == 'D') {
				D--;
				DM -= M;
			}
			else if(S[i] == 'M') {
				M--; MC -= C;
			}
			else if(S[i] == 'C') {
				C--;
			}
			
			int j = i + K;
			if(S[j] == 'D') D++;
			else if(S[j] == 'M') {
				M++; DM += D;
			}
			else if(S[j] == 'C') {
				C++;
				MC += M;
				res += DM;
			}
		}
		cout << res << "\n";
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

int main(int argc, char const *argv[]) {
  string s;
  cin>>s;
  int count=0;
  for(int i=0;i<3;i++){
    if(s[i]=='1') count++;
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;
int main(){
	int n,r;
	cin>>n>>r;
	if(n>10)cout<<r;
	else cout<<r+100*(10-n); 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    while (n != 0)
    {
        string s[n];
        int dots[n];
        int last[1000000];
        rep(i, n) last[i] = 0;
        rep(i, n)
        {
            cin >> s[i];
            dots[i] = 0;
            rep(j, s[i].size())
            {
                if (s[i][j] == '.')
                    dots[i]++;
                else
                    break;
            }
            if (dots[i] != 0)
                last[dots[i] - 1] = i;
        }
        //cerr << last[0] << endl;
        rep(i, n)
        {
          //  cerr << i << endl;
            rep(j, dots[i] - 1)
            {

                s[i][j] = ' ';
                bool cont = false;
                rep(k, i + 1, n)
                {
                    if (dots[k] < j + 1)
                    {
                        break;
                    }
                    if (dots[k] == j + 1)
                    {
                        cont = true;
                        break;
                    }
                }
                if (cont)
                {
                    //   cerr << s[i] << "," << j << "," << last[j] << endl;
                    s[i][j] = '|';
                }
            }
            if (dots[i] > 0)
            {
                s[i][dots[i] - 1] = '+';
            }
            cout << s[i] << endl;
        }
        cin >> n;
    }
    return 0;
}



Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main(){    
    int H, W;
    cin >> H >> W;
    vector<vector<int>> a;
    a = vector<vector<int>>(H, vector<int>(W,0));
    for(int h=0; h<H; h++) for(int w=0; w<W; w++) cin >> a[h][w];

    vector<P> horizontal, vertival;
    for(int h=0; h<H; h++){
        for(int w=0; w<W-1; w++){
            if(a[h][w]%2==1){
                horizontal.push_back(P(h,w));
                a[h][w]--;  a[h][w+1]++;
            }
        }
    }

    for(int h=0; h<H-1; h++){
        if(a[h][W-1]%2==1){
            vertival.push_back(P(h,W-1));
            a[h][W-1]--;  a[h+1][W-1]++;
        }
    }

    int nH = horizontal.size(), nV = vertival.size();
    cout << nH + nV << endl;
    for(int i=0; i<nH; i++){
        int y = horizontal[i].first;
        int x = horizontal[i].second;
        y++;  x++;
        cout << y << " " << x << " " << y << " " << x+1 << endl;
    }
    for(int i=0; i<nV; i++){
        int y = vertival[i].first;
        int x = vertival[i].second;
        y++;  x++;
        cout << y << " " << x << " " << y+1 << " " << x << endl;
    }
}


Measured memory_bytes: 4212
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = INF

    cost = 0
    total = 0
    for i, a in enumerate(A):
        total += a
        if i % 2 == 0 and total <= 0:
            cost += abs(total) + 1
            total = 1
        elif i % 2 == 1 and total >= 0:
            cost += abs(total) + 1
            total = -1
    ans = min(ans, cost)

    cost = 0
    total = 0
    for i, a in enumerate(A):
        total += a
        if i % 2 == 1 and total <= 0:
            cost += abs(total) + 1
            total = 1
        elif i % 2 == 0 and total >= 0:
            cost += abs(total) + 1
            total = -1

    ans = min(ans, cost)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 15092
using System;
using System.Globalization;
using System.IO;
using System.Text;

public class Program
{
    public static void Main(string[] args)
    {
        var stdin = Console.OpenStandardInput();
        var ss = new StreamScanner(stdin);
        var p = new Program();
        p.solve(ss);
        stdin.Close();
    }

    private void solve(StreamScanner ss)
    {
        var x = ss.Int;
        var y = ss.Int;

        for (var t = 0; t <= x; ++t)
        {
            var k = x - t;
            if (calcLegs(t, k) == y)
            {
                Console.WriteLine("Yes");
                return;
            }
        }
        Console.WriteLine("No");
    }

    private int calcLegs(int tsuru, int kame) => 2 * tsuru + 4 * kame;


    class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        private readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) throw new EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        public char Char
        {
            get
            {
                byte b = 0;
                do b = read();
                while (b < 33 || 126 < b);
                return (char)b;
            }
        }

        public string Scan
        {
            get
            {
                var sb = new StringBuilder();
                for (var b = Char; b >= 33 && b <= 126; b = (char)read())
                    sb.Append(b);
                return sb.ToString();
            }
        }

        public long Long
        {
            get
            {
                long ret = 0; byte b = 0; var ng = false;
                do b = read();
                while (b != '-' && (b < '0' || '9' < b));
                if (b == '-') { ng = true; b = read(); }
                for (; true; b = read())
                {
                    if (b < '0' || '9' < b)
                        return ng ? -ret : ret;
                    else ret = ret * 10 + b - '0';
                }
            }
        }

        public int Int => (int)Long;

        public int[] IntArray(int n)
        {
            var arr = new int[n];
            for (var i = 0; i < n; ++i)
            {
                arr[i] = Int;
            }
            return arr;
        }

        public double Double => double.Parse(Scan, CultureInfo.InvariantCulture);
    }
}

Measured memory_bytes: 25748
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,M;
  cin >> N >> M;
  vvi task(100010);
  rep(i,N) {
    int a,b;
    cin >> a >> b;
    task[a].push_back(b);
  }
  int ans = 0;
  priority_queue<int> que;
  srep(i,1,M+1) {
    for(int k:task[i]) {
      que.push(k);
    }
    if(que.empty()) continue;
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8428