akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}

// 割り算の切り上げ処理
template<typename T>
T round_up(T a, T b) {
  return (a + b - 1) / b;
}

// 約数列挙
template<typename T>
vector<T> calc_divisor(T n) {
   vector<T> res;
   for (T i = 1LL; i*i <= n; ++i) {
       if (n % i == 0) {
           res.push_back(i);
           T j = n / i;
           if (j != i) res.push_back(j);
       }
   }
   sort(res.begin(), res.end());
   return res;
}

// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;

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




int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int a, b;
    cin >> a >> b;
    for(ll i=min(a,b);i<=max(a,b);i++){
        if(abs(a - i) == abs(b - i)){
            print(i);
            return 0;
        }
    }
    print("IMPOSSIBLE");

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
int a,b,c,i,n,j,t;
int g,h,o;
    map<int,int> ma;
    map<int,int> :: iterator it;
vector<int> v;
    h=0;
cin>>a>>b;
if((b*2)<a)cout<<(a-(b*2))<<endl;
else cout<<0<<endl;
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val S = sc.next()
  val dayOfTheWeek = List("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT")
  val x :: xs = (dayOfTheWeek ++ dayOfTheWeek).dropWhile(_ != S)
  println(xs.takeWhile(_ != "SUN").length + 1)
}


Measured memory_bytes: 55264
#include<iostream>
#include<algorithm>
using namespace std;
int n,k,ans;
int a[60];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	    cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=n;k;k--){
		ans+=a[i];
		i--;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)n;i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;


string x;
int cntT=0;
int cntS=0;


int main(){
    cin>>x;
    Rep(i,x.size()){
        if(x[i]=='T'){
            if(cntS==0){
                cntT++;
            }
            else{
                cntS--;
            }
        }
        if(x[i]=='S'){
            cntS++;
        }
    }
    cout<<cntT+cntS<<endl;

    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void){
  int n,count=0,ans=1;
  scanf("%d",&n);
  while(n>0){
    n=n/2;
    count++;
  }
  while(count>1){
    ans=ans*2;
    count--;
  }
  printf("%d",ans);
  return 0;
}

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

// GCD, LCM
// https://youtu.be/8lm8o8L9Bmw?t=2285
// https://youtu.be/XI8exXVxZ-Q?t=3595
// https://youtu.be/F2p_e6iKxnk?t=843
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
    ll N,K;
    cin >>N >> K;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    if(A.back()<K){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    ll g = A[0];
    
    for(int i=1;i<N;i++){
        g = gcd(g,A[i]);
    }
    if(K%g ==0){
        cout <<"POSSIBLE" << endl;
    }else{
        cout <<"IMPOSSIBLE" << endl;
    }
    return 0;
}

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

int main() {
	// your code goes here
	long long A, B, C = 0;
	cin >> A;
	cin >> B;
	cin >> C;
	long long a = A;
	long long b = B;
	long long c = C;
	int res = 0;
	if (A == B && B == C && A == C)
	{
	    if(A%2 == 0)
	    {
	        res = -1;
	    }
	    else
	    {
	        res = 0;
	    }
	}
	else
	{
		while (A % 2 != 1 && B % 2 != 1 && C % 2 != 1)
		{
			a = (B + C) / 2;
			b = (A + C) / 2;
			c = (A + B) / 2;
			A = a;
			B = b;
			C = c;
			res++;
		}
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}

vector<ll> fact, factinv, inv;
ll mod = 998244353;
void prenCkModp(ll n) {
	fact.resize(n + 5);
	factinv.resize(n + 5);
	inv.resize(n + 5);
	fact.at(0) = fact.at(1) = 1;
	factinv.at(0) = factinv.at(1) = 1;
	inv.at(1) = 1;
	for (ll i = 2; i < n + 5; i++) {
		fact.at(i) = (fact.at(i - 1) * i) % mod;
		inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
		factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
	}

}
ll nCk(ll n, ll k) {
	return (fact.at(n) * ((factinv.at(k) * factinv.at(n - k)) % mod)) % mod;
}
int modPow(long long a, long long n, long long p) {
	if (n == 0) return 1; // 0乗にも対応する場合
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

int main() {
	ll N;
	cin >> N;
	vector<ll> A(1000001);
	rep(i, 1000001) {
		A.at(i) = 0;
	}
	rep(i, N) {
		ll a;
		cin >> a;
		A.at(a)++;
		
		if (A.at(a) == 1) {
			
			for (ll g = a * 2; g < 1000001; g += a) {
				A.at(g) += 2;
				
			}
		}
	}
	ll an = 0;
	rep(i, 1000001) {
		if (A.at(i) == 1) {
			an++;
		
		}
	}
	
	cout << an << endl;

}

Measured memory_bytes: 11180
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int X, Y; cin >> X >> Y;
	for (int i = 0; i <= X; ++i) {
		if (2 * (X - i) + 4 * (i) == Y) {
			cout << "Yes" << endl;
			return;
		}
	}
	cout << "No" << endl;
	return;
}
int main() {
	solve();
	return 0;
}

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

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            char[] s = ReadLine().ToArray();
            int ans = 0;

            int right = 0;
            int left = n-1;
            while (right < left)
            {
                if (s[right] == 'W' && s[left] == 'R')
                {
                    Swap(ref s[right], ref s[left]);
                    ans++;
                }
                if (s[right] == 'R') right++;
                if (s[left] == 'W') left--;
            }
            /*


            int changeLimit = 0;
            for (int i = 0; i < n; i++)
            {
                if (s[i] == 'R')break;
                changeLimit++;
            }

            int changeIndex = 0;
            for (int i = n - 1; i >= Divide(n); i--)//Rを右に移動させない
            {
                if (changeLimit <= 0) break;//入れ替え終わり
                if(s[i] == 'R')
                {
                    Swap(ref s[i], ref s[changeIndex++]);
                    changeLimit--;
                    ans++;
                }
            }
*/
            WriteLine(ans);
        }

        static int Divide(int n)
        {
            if (n % 2 == 0) return n / 2;
            else return (n / 2) + 1;
        }
        static void Swap<T>(ref T a, ref T b)
        {
            var tmp = a;
            a = b;
            b = tmp;
        }
    }
}


Measured memory_bytes: 29480
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling, digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl flag, D; vpll path;
//***********//
int main() { 
	cin >> X >> N;
	vl A(102);
	ll ans = INF;
	for (i = 0; i < N; i++) {
		ll p;
		cin >> p;
		A[p] = 1;
	}
	ll ans2 = 0;
	for (i = 0; i <= 101; i++) {
		if (!A[i]) {
			if (abs(X - i) < ans) {
				ans = abs(X - i);
				ans2 = i;
			}
		}
	}
	cout << ans2;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

//string HOGE(".!\"#&%&'()*+,-/:;<=>?@[\\]^_`{|}~"); // ok
//string HOGE(".!\"#&%&'()*+,-/:"); // bad
//string HOGE(";<=>?@[\\]^_`{|}~"); // bad

//string HOGE(".!\"#&%&'"); // bad
//string HOGE("()*+,-/:;<=>?@[\\"); // bad
//string HOGE("]^_`{|}~"); // bad

//string HOGE(".!\"#&%&'()*+,-/:;<=>?@[\\"); // bad
//string HOGE("()*+,-/:;<=>?@[\\]^_`{|}~"); // bad

//string HOGE(".!\"#&%&'()*,-/:;<=>?@[\\]^_`{|}~"); // ok (no +)

//string HOGE(".!\"#&%&'()*+,-/:;<=>?@[\\]^_"); // ok -5


// included '_'

//string HOGE("_.!\"#&%&'()*+,-/:;<=>?"); // ok more -5
//string HOGE("_.!\"#&%&'()*+,-/:"); // ok more -5 
//string HOGE("_.!\"#&%"); // ok more -5 
//string HOGE("_.!"); // bad 
//string HOGE("_.!\"#&%"); // bad 
//string HOGE("_.!\"#&%&'()"); // ok
//string HOGE("_.!\"#&%&'("); // ok
//string HOGE("_.!\"#&%&'"); // ok

//string HOGE("_'"); // ok!!!

// included '_' and '''


int main(void) {
	string s;

	int total = 0;

	while (cin >> s) {
		replace_if(s.begin(), s.end(), [](char c){ return isalpha(c) || c == '.' || c == '_' || c == '\''; }, ' ');
		
		istringstream iss(s);
		int num;
		while (iss >> num) {
			total += num;
		}
	}

	cout << total << endl;

	return 0;}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
using namespace boost::range;
using boost::irange;
using boost::math::gcd;
using boost::math::lcm;

using ll = int64_t;
constexpr char LN = '\n';
template<class T> bool chmax(T& a, const T& b) {if(a<b){a=b;return true;}else{return false;}}
template<class T> bool chmin(T& a, const T& b) {if(b<a){a=b;return true;}else{return false;}}

#ifdef LOCAL
template<class H> void dump_(const char* s, H h) {cout<<s<<"="<<h<<LN; }
template<class H, class... T> void dump_(const char* s, H h, T... t) {for(;*s!=',';++s){cout<<*s;}cout<<"="<<h<<",";dump_(++s,t...);}
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__)
#else
#define dump(...)
#endif

struct init_ {init_(){cin.tie(nullptr);ios::sync_with_stdio(false);}} init_;

template<class C> C scan(size_t n) {C c(n);for(auto& v:c){cin>>v;}return c;}
template<class C> C scan(size_t n, size_t m) {C vss(n);for(auto& vs:vss){vs.resize(m);for(auto& v:vs){cin>>v;}}return vss;}

template<class R> struct Joined { const R& r; const char* s; };
template<class R> Joined<R> joined(const R& r, const char* s = " ") {return{r,s};}
template<class R> ostream& operator<<(ostream& out, Joined<R> j) {bool f=true;for(const auto& v:j.r){if(f){f=false;}else{out<<j.s;}out<<v;}return out;}

template<class T> using matrix = vector<vector<T>>;
template<class T> matrix<T> make_matrix(size_t n, size_t m, const T& init = T()) {matrix<T> vss(n);for(auto& vs:vss){vs.resize(m,init);}return vss;}
template<class T> ostream& operator<<(ostream& out, Joined<matrix<T>> j) {bool a=true;for(const auto& vs:j.r){if(a){a=false;}else{out<<LN;}bool f=true;for(const auto& v:vs){if(f){f=false;}else{out<<j.s;}out << v;}}return out;}

template<class T> void show_(const T& t) {cout<<t;}
template<class T> void show_(const vector<T>& v) {cout<<joined(v);}
void show_(bool b) {cout<<(b?"Yes":"No");}
void show_(double d) {cout<<fixed<<setprecision(12)<<d;}
template<class T, class... TS> void show_(const T& t, TS... ts) {show_(t);cout<<' ';show_(ts...);}
template<class T> void show(const T& t) {show_(t);cout<<LN;}
template<class T, class... TS> void show(const T& t, TS... ts) {show_(t, ts...);cout<<LN;}

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    string h = s.substr(0, s.size() / 2);
    show(s == h + h);
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
q = int(input())
query = [list(map(int,input().split())) for _ in range(q)]

all_sum  = sum(a)

cnt = {}
for i in a:
    if i not in cnt:
        cnt[i] = 0
    cnt[i] += 1

for (b, c) in query:
    if b in cnt:
        all_sum -= b * cnt[b]
        all_sum += c * cnt[b]
        if c not in cnt:
            cnt[c]=0 
        cnt[c] += cnt[b]
        cnt[b] = 0
    print(all_sum)

Measured memory_bytes: 35928
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;
#define x first
#define y second
p a[300010],c;
priority_queue<p,vector<p>,greater<p> >q;
int main(){int n,r=0,i;cin>>n;for(i=0;i<n;i++)scanf("%d%d",&a[i].x,&a[i].y);sort(a,a+n);long long s=0;for(i=0;i<n;i++){s+=a[i].x,c.x=a[i].y,c.y=a[i].x;q.push(c);while(!q.empty()){if(s<=q.size()*q.top().x)break;s-=q.top().y,q.pop();}if(r<q.size())r=q.size();}cout<<r<<endl;return 0;}

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

int main() {
  int k,n;
  cin>>k>>n;
  int house[n];
  for(int i=0; i<n; i++) cin>>house[i];

  int max = k-(house[n-1]-house[0]);
  for(int i=0; i<n-1; i++) {
    if(max<house[i+1]-house[i]) max=house[i+1]-house[i];
  }

  cout<<k-max<<endl;

  return 0;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

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

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

int main(void)
{
    int c[3][3];
    int a[3], b[3];
    REP(i, 3) REP(j, 3) cin >> c[i][j];
    REP(i, 3) REP(j, 3) {
        c[i][j] -= c[2][j];
    }
    REP(j, 3) REP(i, 3) {
        c[i][j] -= c[i][2];
    }
    REP(i, 3) REP(j, 3) {
        if (c[i][j] != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque
h,w=map(int,input().split())
p=['-'*(w+2)]
for i in range(h):
    p.append('-'+input()+'-')
p.append('-'*(w+2))

isl=[]
v=[[0 for i in range(w+2)] for j in range(h+2)]
d=[[0,1],[1,0],[-1,0],[0,-1]]

def bfs(x,y):
    if v[x][y]!=0:
        return
    q=deque()
    q.append((x,y))
    v[x][y]=1
    br,wh=0,0
    cnt=0
    while len(q)>0:
        ch,cw=q.popleft()
        #v[ch][cw]=1
        if p[ch][cw]=='#':
            br+=1
            for dh,dw in d:
                if p[ch+dh][cw+dw]=='.' and v[ch+dh][cw+dw]==0:
                    q.append((ch+dh,cw+dw))
                    v[ch+dh][cw+dw]=1
        elif p[ch][cw]=='.':
            wh+=1
            for dh,dw in d:
                if p[ch+dh][cw+dw]=='#' and v[ch+dh][cw+dw]==0:
                    q.append((ch+dh,cw+dw))
                    v[ch+dh][cw+dw]=1
        #print('xy=',x,y,'chw=',ch,cw,'bw=',br,wh,q)
    isl.append((br,wh))

for i in range(1,h+1):
    for j in range(1,w+1):
        bfs(i,j)

ans=0
for br,wh in isl:
    ans+=br*wh

print(ans)

Measured memory_bytes: 55516
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N), data(N);
  int ans = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i) >> data.at(i);
    ans += data.at(i) - vec.at(i) + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) throws ArrayIndexOutOfBoundsException{


        Scanner sc = new Scanner(System.in);


        int n = sc.nextInt();

//        int b[] = new int[n];
        List<Integer> b = new ArrayList<>();
        for (int i=0; i<n; i++) b.add(sc.nextInt());

        List<Integer> ans = new ArrayList<>();

        while(!(b.isEmpty())){

            int tmp = -1;
            for (int i=0; i<b.size(); i++) {
                if (b.get(i) == i + 1) {
                    tmp = i;
                }
            }
                if (tmp==-1){
                    System.out.println("-1");
                    break;
                }
                b.remove(tmp);
                ans.add(tmp+1);
            }
//            for (int i=n-1; i>=0; i--){
//                if (b.get(i)==i+1){
//                    ans.add(b.get(i));
//                    b.remove(i);
//                    n = b.size();
//                }
//            }

        Collections.reverse(ans);
        if (n==ans.size()) {
            for (int i : ans) {
                System.out.println(i);
            }
        }

//        for (int i=ans.size()-1; i>=0; i--){
//            System.out.println(ans.get(i));
//        }


//        int output[] = new int[n];



    }

}



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

#define ll long long int
#define vi vector<int>
using namespace std;

int main(){
    long long int n;
    cin >> n;
    map<long long int ,long long int> mp;
    vector<long long int> v(n);
    for(long long int i=0;i<n;i++)
    {
    cin >> v[i];
    mp[i+1LL-v[i]]++;    
    }
    long long int ans=0;
    for(long long int i=0;i<n;i++){
        mp[i+1LL-v[i]]--;
        ans+=mp[v[i]+i+1LL];
    }
    cout << ans;
}

Measured memory_bytes: 27392
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)

int lo, mid, hi, n, cnt[3];
string s;
bool check(int L){
    drain(cnt);
    fox(l, n){
        if (s[l]=='J') cnt[0]++;
        if (s[l]=='O' && cnt[0]>0){cnt[1]++; cnt[0]--;}
        if (s[l]=='I'){
            if (L>0){cnt[0]++; L--;}
            else if (cnt[1]){cnt[1]--; cnt[2]++;}
            else return 0;
        }
    }
    return 1;
}
int main(){
    cin >> n >> s;
    hi=n;
    while(lo<hi){
        mid=(lo+hi)/2;
        //cout << mid << endl;
        if (check(mid)) hi=mid;
        else lo=mid+1;
    }
    //cout << lo << endl;
    check(lo);
    cout << cnt[2] << endl;
    return 0;
}

Measured memory_bytes: 3916
N,M=map(int, input().split())

ans1=min(N, M//2)
resN=N-ans1
resM=M-ans1*2
if resM<2:
    print(ans1)
else:
    #Nもうない
    ans2=resM//4
    print(ans1+ans2)
#print(resN, resM)

Measured memory_bytes: 9172
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	scan_init()
	n := scanInt()
	m := scanInt()
	a:= make([]int, n)
	b:= make([]int, n)
	c:= make([]int, m)
	d:=make([]int, m)
	for i:=0; i<n; i++ {
		a[i] = scanInt()
		b[i] = scanInt()
	}
	for i:=0; i<m; i++ {
		c[i] = scanInt()
		d[i] = scanInt()
	}
	for i:=0; i<n; i++ {
		take := 10*int(math.Pow(10,8))
		check := 0
		for j:= 0; j<m; j++ {
			get := a[i] - c[j]
			if get<0 {
				get = -get
			}
			more := b[i] -d[j]
			if more<0 {
				more = -more
			}
		// 	fmt.Println(check, get+more, take, i, j, m, a, b,c,d)
			if take> get+more {
				take = get+more
				check = j+1
			}
		}
		fmt.Println(check)
	}
}

var sc = bufio.NewScanner(os.Stdin)

func scan_init() {
	sc.Split(bufio.ScanWords)
}
func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func scan() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 200000)

func readLine() string {
	buf := make([]byte, 0, 200000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
func readLineToNumber() int {
	S := readLine()
	number, _ := strconv.Atoi(S)
	return number
}
func readLineToSlice() []string {
	S := readLine()
	list := strings.Split(S, "")
	return list
}
func readLineToNumberSlice(memo map[string]int) []int {
	// err時は-1を代入
	S := readLine()
	intList := make([]int, len(S))
	for i := 0; i < len(S); i++ {
		if val, ok := memo[string(S[i])]; ok {
			intList[i] = val
		} else {
			intList[i] = -1
		}
	}
	return intList
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  rep(i,K){
    if(A>=B) B *=2;
    else if (B>=C) C*=2;
  }
  if (A < B && B < C) cout << "Yes" << endl;
  else cout << "No" << endl;
  
return 0;
}


Measured memory_bytes: 3624
using System;

namespace _001_ListOfTop3Hills
{
	class Program
	{
		static void Main ( string[] args )
		{
			int[] inputData = new int[10];

			for (int lp = 0; lp < inputData.Length; lp++)
			{
				inputData[lp] = int.Parse (Console.ReadLine ());
			}

			Array.Sort (inputData);

			Console.WriteLine (inputData[9]);
			Console.WriteLine (inputData[8]);
			Console.WriteLine (inputData[7]);
		}
	}
}

Measured memory_bytes: 9332
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(long long i=0; i<x;i++)
#define mod 1000000007
#define INF 10000000000
typedef long long ll;


int main(){
  ll N,K;
  cin>>N>>K;
  ll h[N];
  rep(i,N) cin>>h[i];
  
  ll DP[N];
  rep(i,N) DP[i] = INF;
  
  DP[0]=0;  
  
  
  for(ll i=1;i<N;i++){
    for(ll j=1;j<=K;j++){
      if(i-j >= 0)  DP[i]=min(DP[i],DP[i-j]+abs(h[i]-h[i-j]));
  	}
  }
  
  cout<<DP[N-1];
}

Measured memory_bytes: 1792
import sys

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))


s=input()

for i in range(len(s)):
    if i%2==0:
        if s[i] == 'L':
            print('No')
            exit()
    else:
        if s[i] == 'R':
            print('No')
            exit()
print('Yes')



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n ;
    cin >> n;
    string s;
    cin >> s;
    int num = 0;
    for(int i = 0;i<n;i++){
        if(s[i] == 'W'){
            num++;
        }
    }
    int m = n - num;
    int ans = 0;
    for(int i = 0;i < m;i++){
        if(s[i] == 'W'){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3728
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    long long n,m;
    cin>>n>>m;
    long long ans=0;
	long long sum=m/n;
	while(sum!=1){
		ans++;
		sum=sum/2;
	}
	cout<<ans+1;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() { //1a
 
  string str1;
  cin >> str1;
   int sum = 0;
    if( "str1"s.size() % 2 == 0) { //2a
    //"string1".at(0) = "string1".at(S - 1)//真⇒0偽⇒１
    //"string1".at(1) = "string1".at(S - 2)
	//"string1".at(2) = "string1".at(S - 3)
    //"string1".at(3) = "string1".at(S - 4)
  
      for (int i = 0; i < str1.size() / 2 ; i++) {//3a
  if( str1.at(i) != str1.at( str1.size()- i-1 ) ){//4a
    sum += 1;
  }//4b
                   //}       
      if( i == str1.size() / 2 ){//5a
   // cout << sum << endl;//"iranaikamo
    break;
  }//5b
    //真⇒0偽⇒１
}//3b
    }//2b    
 	else{//6a
       for (int i = 0; i < (  str1.size() - 1 ) / 2 ; i++) {//7a
     if( str1.at(i) != str1.at( str1.size() - i-1 ) ) {//8a
       sum += 1;
     }//8b
     if( i == ( str1.size()- 1) / 2 ){//9a
   // cout << sum << endl;//"iranaikamo
    break;
     }//9b 
       }//7b
    }//6b
  cout << sum << endl;
}//1b
 

Measured memory_bytes: 256
n = int(input())
g = [[0] * n for _ in range(n)]

while n:
    l = list(map(int, input().split()))
    column_g = g[l[0] - 1]
    for i in l[2:]:
        column_g[i-1] = 1
    n -= 1
for v in g:
    print(*v)

Measured memory_bytes: 8392
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  if (N == 1 && K == 1) {
    cout << "YES" << endl;
  } else if (N <= K) {
    cout << "NO" << endl;
  } else {
    if (N % 2 == 0) {
      if (N / 2 >= K) cout << "YES" << endl;
      else cout << "NO" << endl;
    } else {
      if (N / 2 + 1 >= K) cout << "YES" << endl;
      else cout << "NO" << endl;
    }
  }
 
  return 0;
}

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

int main(void) {
    int N, K;
    cin >> N >> K;
    int d[110], A[110][110];
    vector<bool> flg(110, false);
    for (int i = 0; i < K; i++) {
        cin >> d[i];
        for (int j = 0; j < d[i]; j++) {
            cin >> A[i][j];
            flg[A[i][j]] = true;
        }
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (!flg[i]) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define INFTY 10000000000
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
using ipair = pair<ll,ll>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
  int n;
  cin>>n;
  int cnt=0;
  vector<int> a(n+1);
  for(int i=1;i<=n;i++)cin>>a[i];
  vector<int> ball(n+1,0);
  for(int i = n;i>0;i--){
    int num = n/i;
    int balls=0;
    for (int j = 1; j <= num; j++)
    {
      if(ball[i*j]==1)balls++;
    }
    if(balls%2==a[i])ball[i]=0;
    else{ ball[i] = 1; cnt++;}
  }
  cout<<cnt<<endl;
  for(int i=1;i<=n;i++){
    if(ball[i]==1)cout<<i<<" ";
  }

  return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x, y;
    cin >> x >> y;
    if (x % y == 0)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << x * (y + 1) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
  int n,m; cin>>n>>m;
  vi a(m),b(m);
  vll avail(m);
  int dp[(1<<n)];
  rep(i,(1<<n)) dp[i]=INF;
  dp[0]=0;
  rep(i,m){
    cin>>a[i]>>b[i];
    rep(j,b[i]){
      int x; cin>>x; x--;
      avail[i]+=(1<<x);
    }
  }
  rep(i,m){
    rep(j,(1<<n)){
      int x=(j|avail[i]);
      dp[x]=min(dp[j]+a[i],dp[x]);
    }
  }
  ll ans=0;
  rep(i,n) ans+=(1<<i);
  //rep(i,n) cout<<avail[i]<<" ";
  //cout<<endl;
  /*rep(j,(1<<n)){
    if(dp[j]==INF) cout<<"INF"<<" ";
    else cout<<dp[j]<<" ";
  }*/
  //cout<<ans<<endl;
  if(dp[ans]==INF) cout<<-1<<endl;
  else cout<<dp[ans]<<endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define L length()
using namespace std;
signed main()
{
	string a,b;getline(cin,a),getline(cin,b);
	puts(((a.L<b.L)?("LESS"):(((a.L>b.L)?("GREATER"):(((a<b)?("LESS"):(((a>b)?("GREATER"):("EQUAL")))))))));
	return 0;
}

Measured memory_bytes: 256
num = int(input())
if 400 <= num < 600:
    print('8')
if 600 <= num < 800:
    print('7')
if 800 <= num < 1000:
    print('6')
if 1000 <= num < 1200:
    print('5')
if 1200 <= num < 1400:
    print('4')
if 1400 <= num < 1600:
    print('3')
if 1600 <= num < 1800:
    print('2')
if 1800 <= num < 2000:
    print('1')


Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,sta,end) for(ll i=sta;i<end;i++)
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define vvl vector<vector<ll>>
#define vl  vector<ll>
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||

signed main(){
//	cin.tie(0);
  //	ios::sync_with_stdio(false);
	ll N,W;
	cin>>N>>W;
	ll dp[N+1][W+1];
	ll weight[N],value[N];
	rep(i,0,N) cin>>weight[i]>>value[i];

	rep(w,0,W+1) dp[0][w]=0;
	rep(i,0,N){
		rep(w,0,W+1){
			if(w>=weight[i]){
				dp[i+1][w]=dp[i][w-weight[i]]+value[i];
              	if(dp[i][w]>dp[i+1][w])dp[i+1][w]=dp[i][w];
			}
			else{
				dp[i+1][w]=dp[i][w];
			}
		}
	}
	cout<<dp[N][W]<<endl;
	return 0;
}


Measured memory_bytes: 79104
n,k=map(int,input().split())
x=sorted(list(map(int,input().split())))
print(min((min(abs(x[i])+abs(x[i+k-1]-x[i]),abs(x[i+k-1])+abs(x[i]-x[i+k-1]))) for i in range(n-k+1)))

Measured memory_bytes: 14388
//https://atcoder.jp/contests/abc132/tasks/abc132_a
//A - Fifty-Fifty
#include <bits/stdc++.h>
using namespace std;

string s;

int main() {
    cin >> s;
    map<char,int> flags;
    for (int i = 0; i < s.size(); i++) {
        flags[s[i]]++;
    }
    int ansflag = 1;
    for (auto ele: flags) {
        if (ele.second != 2) ansflag = 0;
    }
    cout << (ansflag ? "Yes" : "No") << endl;
    return 0;
}

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

using namespace std;

static const int INF = 1e9 + 7;

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

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

Vec<string> infos;

enum struct info {
  add,
  mul
};

stack<info> s;
int now;
int dfs()
{
  if(now == infos.size()){
    switch (s.top()) {
    case info::add:
      return 0;
    case info::mul:
      return 1;
    }
  }
  int res = (s.top() == info::mul);
  auto d = s.top();
  while (now < infos.size() && s.size() <= infos[now].size()) {
    auto c = infos[now].back();
    switch (c) {
    case '+':
      s.push(info::add);
      switch (d) {
      case info::add:
        now++;
        res += dfs();
        break;
      default:
        now++;
        res *= dfs();
      }
      break;
    case '*':
      s.push(info::mul);
      now++;
      switch (d) {
      case info::add:
        res += dfs();
        break;
      default:
        res *= dfs();
      }
      break;
    default:
      now++;
      switch (d) {
      case info::add:
        res += c - '0';
        break;
      default:
        res *= c - '0';
      }
    }
  }
  s.pop();
  return res;
}

void hawawa()
{
  int n;
  while (cin >> n && n) {
    infos.resize(n);
    for (auto&& i : infos) {
      cin >> i;
    }
    s.push(info::add);
    now = 0;
    cout << dfs() << "\n";
    while (s.size()) s.pop();
  }
}

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



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
const static string t="0357";
string aa(int x){
    string ret="";

    while(x){
        ret+=t[x%4];
        x/=4;
    }
    return ret;
}
bool isvalid(string s){
    if(s.find('0')!=string::npos)return false;
    REP(i,1,4)if(s.find(t[i])==string::npos)return false;
    return true;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    string n;
    cin>n;
    int a=1;
    int ans=0;
    REP(i,n.size())a*=4;
    REP(i,1,a){
        string x=aa(i);
        if(!isvalid(x))continue;
        cerr<x<endl;
        if(x.size()<n.size())ans++;
        else if(x<=n)ans++;
    }
    cout<ans<endl;
    return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Sequence as Sq
import Data.Sequence (ViewL(..),ViewR(..),(><),(<|),(|>),Seq)

bsreadInt :: BC.ByteString -> Int
bsreadInt = fst . fromJust . BC.readInt
strToInt s = (read :: String -> Int) s

main = do

    [h,w]<- map bsreadInt . BC.words <$> BC.getLine
    ss <- replicateM h BC.getLine
    let s = BC.filter(/='\r') $ BC.concat ss
    let grid = array ((1,1),(h,w)) [((i,j), BC.index s ((i-1) * w + (j-1))) | i<-[1..h],j<-[1..w]]
    
    let chk = Set.singleton (1,1)
    let q0 = Sq.fromList [(1,1)]
    let q =  q0 <| Sq.empty
    let white = BC.length $ BC.filter(=='.') s
   
    if (Sq.length (move q h w grid chk)) == 0 then print (-1)
                                          else print $ white -  Sq.length (move q h w grid chk) 
    
adjblock :: (Int,Int) -> Int -> Int -> [(Int,Int)]
adjblock (m,n) h w
   | m==1 && n==1 = [(2,1),(1,2)]
   | m==h && n==w = []
   | m==h && n==1 = [(m-1,n),(m,n+1)]
   | m==1 && n==w = [(m+1,n),(m,n-1)]
   | m==1 = [(m+1,n),(m,n-1),(m,n+1)]
   | n==1 = [(m-1,n),(m+1,n),(m,n+1)]
   | m==h = [(m-1,n),(m,n-1),(m,n+1)]
   | n==w = [(m-1,n),(m+1,n),(m,n-1)]
   | otherwise = [(m-1,n),(m+1,n),(m,n-1),(m,n+1)]

sqleft :: Seq a -> a
sqleft q = sqleft_(Sq.viewl q)
sqleft_ :: ViewL a -> a
sqleft_ (x :< xs) = x
sqright :: Seq a -> a
sqright q = sqright_(Sq.viewr q)
sqright_ :: ViewR a -> a
sqright_ (xs :> x) = x

--movestep :: [(Int,Int)] -> Int -> Int -> (array (Int,Int)) -> [[(Int,Int)]]
movestep qa h w grid chk = [(i,j) | (i,j) <- (adjblock (sqright qa) h w ) , (grid ! (i,j)) == '.' , Set.member (i,j) chk == False]

--move :: (Seq [[(Int,Int)]]) -> Int -> Int -> (Array (Int,Int)) -> [(Int,Int)]
move q h w grid chk = if Sq.length q == 0
                      then Sq.empty
                      else if sqright (sqleft q) == (h,w)
                           then sqleft q
                           else move q2 h w grid chk2
                                where qa = sqleft q
                                      q2 = (Sq.drop 1 q) >< (Sq.fromList add)
                                      add = [qa |> x |x <- (movestep qa h w grid chk)]
                                      chk2 = Set.union chk (Set.fromList (movestep qa h w grid chk))

Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    BufferedReader rd;

    Main() throws IOException {
        rd = new BufferedReader(new InputStreamReader(System.in));
        compute();
    }

    private void compute() throws IOException {
        int n = pint();
        long[] a = new long[n];
        for(int i=0;i<n;i++) {
            a[i] = plong();
        }

        long res = 1;
        for(int i=0;i<n;i++) {
            res *= a[i] / gcd(res,a[i]);
        }
        out(res);
    }

    public static long gcd(long a, long b) {
        while (b > 0) {
            long c = a % b;
            a = b;
            b = c;
        }
        return a;
    }

    private int pint() throws IOException {
        return pint(rd.readLine());
    }

    private int pint(String s) {
        return Integer.parseInt(s);
    }

    private long plong() throws IOException {
        return plong(rd.readLine());
    }

    private long plong(String s) {
        return Long.parseLong(s);
    }

    private static void out(Object x) {
        System.out.println(x);
    }

    public static void main(String[] args) throws IOException {
        new Main();
    }
}


Measured memory_bytes: 21204
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DMultipleOf2019 solver = new DMultipleOf2019();
        solver.solve(1, in, out);
        out.close();
    }

    static class DMultipleOf2019 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            String s = in.next();
            int n = s.length();
            int[] mod = new int[n + 1];
            long res = 0;
            for (int i = s.length() - 1; i >= 0; i--) {
                long p = Arith.pow(10, s.length() - 1 - i, 2019);
                mod[i] = (mod[i + 1] + (s.charAt(i) - '0') * (int) p) % 2019;
            }

            HashMap<Integer, Integer> hm = new HashMap<>();
            for (int i = 0; i <= n; i++) {
                hm.merge(mod[i], 1, Integer::sum);
            }

            for (long x : hm.values()) {
                res += x * (x - 1) / 2;
            }

            out.println(res);


        }

    }

    static class Arith {
        public static long pow(long a, long n, long MOD) {
            return n == 0 ? 1 : (pow(a * a % MOD, n / 2, MOD) * (n % 2 == 1 ? a : 1)) % MOD;
        }

    }
}



Measured memory_bytes: 47064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    for(int i = 0; i < n; ++i)  cin >> b[i];
    
    ll res = 0;
    // a_i + b_j で、d 桁目の bit が立っている個数を調べる。
    for(int d = 0; d < 30; ++d){
        vector<ll> amod(n), bmod(n);
        int m = 1 << (d + 1);
        // 2^(d+1) で割った余りの数列 (bmod はソートしておく)
        for(int i = 0; i < n; ++i){
            amod[i] = a[i] % m;
            bmod[i] = b[i] % m;
        }
        sort(bmod.begin(), bmod.end());
        ll cnt = 0; // d 桁目の bit が立つ個数
        ll T = 1 << d;
        for(int i = 0; i < n; ++i){
            // amod_i + bmod_j は 4T 未満 (T = 2^d)
            // d 桁目の bit が立つのは、amod_i + bmod_j が [T, 2T) または [3T, 4T) の範囲にあるとき
            cnt += lower_bound(bmod.begin(), bmod.end(), T * 2 - amod[i]) - lower_bound(bmod.begin(), bmod.end(), T - amod[i]);
            cnt += lower_bound(bmod.begin(), bmod.end(), T * 4 - amod[i]) - lower_bound(bmod.begin(), bmod.end(), T * 3 - amod[i]);
        }
        res += (1 << d) * (cnt % 2);
    }
    cout << res << endl;
}

Measured memory_bytes: 6572
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

	inputs := scanNums(N)

	topRecord := 0
	currentRecord := 0
	for i := 0; i < N-1; i++ {
		if inputs[i] >= inputs[i+1] {
			currentRecord++
		} else {
			currentRecord = 0
		}
		if currentRecord > topRecord {
			topRecord = currentRecord
		}
	}
	fmt.Println(topRecord)
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 7684
#include "bits/stdc++.h"

using namespace std;

int main() {
	int N;
	cin >> N;
	map<int, int>mp;
	for (int i = 0; i < N; ++i) {
		int n;
		cin >> n;
		mp[n]++;
	}
	int ans = 0;
	for (auto p : mp) {
		if (p.first <= p.second) {
			ans += p.second - p.first;
		}
		else {
			ans += p.second;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8068