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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

class UnionFind {
public:
  UnionFind(int n) {
    r.resize(n, 0);
    p.resize(n);
    for (int i = 0; i < n; ++i) {
      p[i] = -1;
    }
  }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return ;
    if (r[a] > r[b]) {
      p[a] += p[b];
      p[b] = a;
    } else {
      p[b] += p[a];
      p[a] = b;
      if(r[a] == r[b]) r[b]++;
    }
    return ;
  }
  int find(int a) {
    return (p[a] < 0) ? a : p[a] = find(p[a]);
  }
  bool same(int a, int b) {
    return find(a) == find(b);
  }
  size_t size(int n) {
    return -p[find(n)];
  }
private:
  vector<int> r, p;
};

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli n, m;
  while (cin >> n >> m) {
    vector<pair<int, int>> v(m);
    cin >> v;
    reverse(v.begin(), v.end());

    UnionFind uf(n + 1);

    vector<lli> u;
    lli x = (n - 1) * n / 2;
    each (e, v) {
      u.push_back(x);
      if (uf.same(e.first, e.second)) {
        continue;
      }

      x += (uf.size(e.first) - 1LL) * uf.size(e.first) / 2;
      x += (uf.size(e.second) - 1LL) * uf.size(e.second) / 2;

      uf.unite(e.first, e.second);

      x -= (uf.size(e.first) - 1LL) * uf.size(e.first) / 2;
    }
    reverse(u.begin(), u.end());
    each (i, u) cout << i << endl;
  }

  return 0;
}


Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    REP(i, N)cin >> A[i];
    sort(ALL(A));
    int n = A[N - 1];

    auto rIt = lower_bound(ALL(A), n / 2);
    int r1 = *rIt;
    int r2 = *(rIt - 1);

    if (n == r1)cout << n << " " << r2 << endl;
    else if (n == r2)cout << n << " " << r1 << endl;
    else if (r1 - (n / 2) > (n / 2) - r2) {
        cout << n << " " << r2 << endl;
    }
    else {
        cout << n << " " << r1 << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main (){
	
	int a,b;
	scanf("%d %d", &a, &b);
	int i = a;
	a = 0;
	for(int j = 0; j < i; j++){
		a = a+j;
	}
	int x = b;
	b = 0;
	for(int j = 0; j < x;j++){
	b = b+j;
	}
	printf("%d", a + b);
	return 0;
}

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

int a[12][12];
int main(){
  int n,m,x;
  cin>>n>>m>>x;
  vector<int>c(n);
  rep(i,n){
    cin>>c[i];
    rep(j,m)cin>>a[i][j];
  }
  long long kotae=INT_MAX;
  rep(s,1<<n){
    long long sum=0;
    vector<int>d(m,0);
    rep(i,n){
      if(s>>i&1){
        sum+=c[i];
        rep(j,m){
          d[j]+=a[i][j];
        }
      }
    }
    bool ok=true;
    rep(j,m){
      if(d[j]<x){
        ok=false;
        break;
      }
    }
    if(ok)kotae=min(kotae,sum);
  }
  if(kotae==INT_MAX)cout<<-1<<endl;
  else cout<<kotae<<endl;
  return 0;
}
  

Measured memory_bytes: 3632
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

void main() {
    int n;
    scan(n);
    auto ans = (n + 999) / 1000 * 1000 - n;
    writeln(ans);
}

void scan(T...)(ref T args) {
    auto line = readln.split; // @suppress(dscanner.suspicious.unmodified)
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 2748
#include <iostream>

using namespace std;

const int64_t R = 1'000'000'007LL;

int64_t x[100'000];
int64_t y[100'000];

int main()
{
    int n, m;
    cin >> n >> m;

    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    for (int i = 0; i < m; i++)
    {
        cin >> y[i];
    }

    int64_t resultX = 0;
    for (int64_t i = 1; i <= n - 1; i++)
    {
        int64_t a = x[i - 1] * (n - i) % R;
        int64_t b = x[i] * i % R;
        int64_t c = (R + a - b) % R;
        resultX = (resultX + c) % R;
    }

    int64_t resultY = 0;
    for (int64_t i = 1; i <= m - 1; i++)
    {
        int64_t a = y[i - 1] * (m - i) % R;
        int64_t b = y[i] * i % R;
        int64_t c = (R + a - b) % R;
        resultY = (resultY + c) % R;
    }

    int64_t result = resultX * resultY % R;
    cout << result << endl;

    return 0;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t x, y;
    cin >> x >> y;

    // a + b = x
    // 2a + 4b = y
    // => b = y/2 - x
    //    a = 2x - y/2
    if (y % 2 != 0 || y / 2 - x < 0 || 2 * x - y / 2 < 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

using matrix = vector<vector<long long>>;

const int mod = 1000000007;

int N;
long long K;
matrix A; // 行列の宣言

// 行列の掛け算
matrix mul(matrix &a, matrix &b) {
    matrix res(N, vector<long long>(N, 0));
    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
            for(int k = 0; k < N; k++)
                (res[i][j] += a[i][k] * b[k][j]) %= mod;
    return res;
}

// 行列累乗
matrix pow(matrix m, long long k) {
    matrix res(N, vector<long long>(N, 0));
    for(int i = 0; i < N; i++)
        res[i][i] = 1; // 単位行列にする
    // 繰り返し自乗法
    while(k > 0) {
        if(k & 1) res = mul(res, m);
        m = mul(m, m);
        k >>= 1;
    }
    return res;
}


int main() {
    ll k;
    cin>>N>>k;
    A.assign(N, vector<long long>(N)); // 初期化子リストを代入
    rep(i,N)rep(j,N) cin>>A[i][j];

    A = pow(A, k);

    long long res = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            res += A[i][j];
            res %= mod;
        }
    }

    cout << res << endl;

}

Measured memory_bytes: 3720
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>

auto& in = std::cin;
auto& out = std::cout;

int32_t N;
int32_t min= 10001000, max=-10001000;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N;
	for (int32_t i = 0; i < N; ++i)
	{
		int a;
		in >> a;
		min = std::min(min, a);
		max = std::max(max, a);
	}
	out << (max - min) << endl;

	return 0;
}
#endif


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
double pi = 3.1415926535897932384646433;
typedef long long ll;
typedef pair<ll, ll>pii;
ll ccw(pii a, pii b, pii c)
{
	return (b.first - a.first)*(c.second - b.second) - (b.second - a.second)*(c.first - b.first);
}
double dist(pii a, pii b)
{
	return sqrt(double((b.first - a.first)*(b.first - a.first) + (b.second - a.second)*(b.second - a.second)));
}
double dot(pii a, pii b)
{
	return double(a.first*b.first + a.second*b.second);
}
double ans[111];
int main()
{
	fill(ans, ans + 111, 0);
	int num;
	scanf("%d", &num);
	vector<pii>v;
	map<pii, int>ma;
	for (int i = 0; i < num; i++)
	{
		ll a, b;
		scanf("%lld%lld", &a, &b);
		v.push_back(make_pair(a, b));
		ma[make_pair(a, b)] = i;
	}
	sort(v.begin(), v.end());
	vector<pii>v1, v2;
	for (int i = 0; i < num; i++)
	{
		for (;;)
		{
			if (v1.size() <= 1)break;
			pii a = v1[v1.size() - 2], b = v1[v1.size() - 1];
			if (ccw(a, b, v[i])<0)v1.pop_back();
			else break;
		}
		v1.push_back(v[i]);
	}
	for (int i = 0; i < num; i++)
	{
		for (;;)
		{
			if (v2.size() <= 1)break;
			pii a = v2[v2.size() - 2], b = v2[v2.size() - 1];
			if (ccw(a, b, v[i])>0)v2.pop_back();
			else break;
		}
		v2.push_back(v[i]);
	}
	for (int i = int(v2.size()) - 2; i >= 1; i--)v1.push_back(v2[i]);
	for (int i = 0; i < v1.size(); i++)
	{
		pii s = v1[(i + v1.size() - 1) % v1.size()];
		pii t = v1[i];
		pii u = v1[(i + 1) % v1.size()];
		//printf("%lld %lld  %lld %lld  %lld %lld\n", s.first, s.second, t.first, t.second, u.first, u.second);
		double x = acos(dot(make_pair(u.first - t.first, u.second - t.second), make_pair(s.first - t.first, s.second - t.second)) / dist(s, t) / dist(t, u));
		ans[ma[v1[i]]] = (pi - x) / (2 * pi);
	}
	for (int i = 0; i < num; i++)printf("%.6lf\n", ans[i]);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define vll vector<ll>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n, k, a;
    cin >> n >> k;
    vll x;
    
    for(ll i=0; i<n; i++){
        cin >> a;
        x.push_back(a);
    }
    
    sort(x.begin(), x.end());
    ll ans = 0;
    for(ll i=0; i<k; i++){
        ans += x[i];
    }
    
    cout << ans << endl;
    return 0;
}

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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 2e5 + 5;
ll a[N], n;
vector<ll> node[N];
multiset<ll> s[N];
ll dp[N];
void dfs(ll u, ll p){
        ll l = 1, h = n;
        while (l <= h){
                ll mid = (l + h) >> 1;
                if ((*s[mid].begin()) >= a[u]) h = mid - 1;
                else l = mid + 1;
        }
        dp[u] = max(dp[p], h + 1);
        s[h + 1].insert(a[u]);
        for (auto j : node[u]){
                if (j != p) {
                        dfs(j, u);
                }
        }
        auto it = s[h + 1].lower_bound(a[u]);
        s[h + 1].erase(it);
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (fopen("WALKING.INP", "r")){
                freopen("WALKING.INP", "r", stdin);
                freopen("WALKING.OUT", "w", stdout);
        }
        cin >> n;
        for (int i = 1; i <= n; i++){
                cin >> a[i];
        }
        s[0].insert(0);
        for (int i = 1; i <= n; i++){
                s[i].insert(1e18);
        }
        for (int i = 1; i < n; i++){
                ll u, v;
                cin >> u >> v;
                node[u].push_back(v);
                node[v].push_back(u);
        }
        dfs(1, 0);
        for (int i = 1; i <= n; i++) cout << dp[i] << endl;
}


Measured memory_bytes: 62128
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int a[5], k;
    for(int i=0; i<5; i++) cin>>a[i];
    cin>>k;
    if(a[4]-a[0]>k) cout<<":("<<endl;
    else cout<<"Yay!"<<endl;

    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define ll long long 
using namespace std;
int main(){
  ll n,max=0,a,s=0,i;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>a;
    if(a>=max)
      	max=a;
   	else
      s+=max-a; 
  }
  cout<<s;
}


Measured memory_bytes: 3624
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N, M;

void init()
{
}

ll factorial(int n)
{
    ll ans = 1;
    FOR(i, 1, n+1){
        ans *= i;
        ans %= MOD;
    }
    return ans;
}

void solve()
{
    if(N > M) swap(N, M);
    if(N+1 < M) cout << 0 << endl;
    else{
        ll ans = factorial(N) * factorial(M);
        ans %= MOD;
        if((N+M) % 2 == 0){
            ans *= 2;
            ans %= MOD;
        }
        cout << ans << endl;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
static const int MAX = 20;
int main()
{
    int N, M, C;
    int A[MAX][MAX], B[MAX];
    scanf("%d %d %d", &N, &M, &C);
    for (int i = 0; i < M; ++i) scanf("%d", &B[i]);
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j){
            scanf("%d", &A[i][j]);
        }
    }
    int ans = 0;
    for (int i = 0; i < N; ++i){
        int sum = C;
        for (int j = 0; j < M; ++j){
            sum += A[i][j] * B[j];
        }
        if (sum > 0) ++ans;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)  	
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f;
const int maxn = 1e6+5;
const double pi = acos(-1.0);
using namespace std;
ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1; }return s; }
ll read()     //输入外挂
{
    ll res = 0, ch, flag = 0;
    if ((ch = getchar()) == '-')
        flag = 1;
    else if (ch >= '0' && ch <= '9')
        res = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9')
        res = res * 10 + ch - '0';
    return flag ? -res : res;
}
int main() {
    ll n, m;
    cin >> n >> m;
    if (n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include<iomanip>
#include<sstream>
#include <fstream>
#define ll long long
#define pb push_back
#define clr(a, b) memset((a), (b), sizeof(a))
#define debugs(x) cout << "Line" << __LINE__ << "	" << #x << "=" << x << endl
#define break break
#define continue continue
#define itn int
#define endl '\n'
#define Endl endl
#define vint vector<int>
#define pii pair<int, int> 
using namespace std;

int n, k, m;
string s[50000], ss[50000];

void solve(int T)
{

	cin >> n >> m >> k;
	int q = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
		for (int j = 0; j < s[i].size(); j++)
			if (s[i][j] == '#')q++;
	}
	int tot = (1 << (n+m)) - 1;
	int ans = 0;
	for (int i = 0; i <= tot; i++)
	{
		int x = i, num = 0, now = 0;
		for (int i = 0; i < n; i++)ss[i] = s[i];
		while (x)
		{
			if (x & 1)
			{
				if (now < n)
				{
					for (int i = 0; i < ss[now].size(); i++)
						if (ss[now][i] == '#')
						{
							num++;
							ss[now][i] = '.';
						}
				}
				else
				{
					int N = now - n;
					for (int i = 0; i < n; i++)
						if (ss[i][N] == '#')
						{
							num++;
							ss[i][N] = '.';
						}
				}

			}
			now++;
			x /= 2;
		}
		if (q-num == k)ans++;
	}
	cout << ans << endl;
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	int numoftest = 1;

	//cin >> numoftest;


	for (int siven = 1; siven <= numoftest; ++siven)
		solve(siven);
	return 0;
}

/*


*/

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

using namespace std;


void solve() {
    map<string,int> mp;
    {
        mp["MON"] = 1;
        mp["TUE"] = 2;
        mp["WED"] = 3;
        mp["THU"] = 4;
        mp["FRI"] = 5;
        mp["SAT"] = 6;
        mp["SUN"] = 0;
    }
    string s; cin >> s;

    int res = 7 - mp[s];
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,counter=0,a[100000]={0};
    cin>>n;
        for(int j=1;j*j<=n;j++)
        {
            for(int k=1;k*k<=n;k++)
            {
                for(int l=1;l*l<=n;l++)
                {
                        a[j*j+k*k+l*l+j*k+k*l+l*j]++;
                }
            }
        }
        for(int i=1;i<=n;i++)
        {
            cout<<a[i]<<'\n';
        }
    return 0;
}

Measured memory_bytes: 4304
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[4] = {1, 0, -1, 0};
int dj[4] = {0, -1, 0, 1};

int x, y;

void dfs(int i, int j, char cur, char next, vector<vector<char>> &vec){
    
    vec[i][j] = next;
    for(int h = 0; h < 4; h++){
        int ni = i + di[h];
        int nj = j + dj[h];
        if(ni < 0 || y <= ni || nj < 0 || x <= nj) continue;

        if(vec[ni][nj] == cur) dfs(ni, nj, cur, next, vec);
    }
}



signed main(){
    
    while(1){
    cin >> x >> y;
    if(x == 0) break;
    vector<vector<char>> g(y, vector<char> (x));
    for(int i = 0; i < y; i++){
        for(int j = 0; j < x; j++){
            cin >> g[i][j];
       }
    }
    
    set<vector<vector<char>>> st;
    queue<pair<int, vector<vector<char>>>> que;
    que.push({0, g});
    st.insert(g);
    
    while(1){
        
        auto tmp = que.front();
        auto vec = tmp.second;
        int cost = tmp.first;
        que.pop();
            
        /*cout << endl;
        for(int i = 0; i < y; i++){
            for(int j = 0; j < x; j++){
                cout << vec[i][j] << " ";
            }
            cout << endl;
        }
        cout << endl;
        */

        bool flag = true;
        char cur = vec[0][0];
        for(int i = 0; i < y; i++){
            for(int j = 0; j < x; j++){
                if(vec[i][j] != cur) flag = false;
            }
        }

        if(flag){
            cout << cost << endl;
            break;
        }
        
        if(cur != 'R'){
            auto vec2 = vec;
            dfs(0, 0, cur, 'R', vec2);

            if(st.find(vec2) == st.end()){
                que.push({cost + 1, vec2});
                st.insert(vec2);
            }
        }
        
        if(cur != 'B'){
            auto vec2 = vec;
            dfs(0, 0, cur, 'B', vec2);
            if(st.find(vec2) == st.end()){

                que.push({cost + 1, vec2});
                st.insert(vec2);
            }
        }
        
        if(cur != 'G'){
            auto vec2 = vec;
            dfs(0, 0, cur, 'G', vec2);
            if(st.find(vec2) == st.end()){

                que.push({cost + 1, vec2});
                st.insert(vec2);
            }
        }
        
    }
    }
    return 0;
}



Measured memory_bytes: 7784
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
  vector<int> a(n+1);
  for (int i = 0; i < n+1; i++)
  {
    cin>>a.at(i);
  }
  vector<long long int> b(n);
  for(long long int i=0; i<n; i++){
    cin>>b.at(i);
  } 
  long long int ans=0;
  for(int i=0; i<n; i++){
    if(b.at(i)<a.at(i)){
      ans+=b.at(i);
      a.at(i)-=b.at(i);
    }else{
      b.at(i)-=a.at(i);
      ans+=a.at(i);
      if(a.at(i+1)<b.at(i)){
        ans+=a.at(i+1);
        a.at(i+1)=0;
      }else{
        a.at(i+1)-=b.at(i);
        ans+=b.at(i);
      }
    }
  }
  cout<<ans<<endl;
}

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

int main(void){
	char a,b;
	cin >> a >> b;
	
	if((a=='H'&& b=='H') ||(a=='D' && b=='D'))
		cout << 'H' << endl;
	else
		cout << 'D' << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
long long r,n,a[500000],b[500000],c[500000],i;
using namespace std;
#define f for(i = 0; i < n; i++)
signed main()
{
    cin >> n;
    f cin >> a[i];
    f cin >> b[i];
    f cin >> c[i];
    sort(a, a + n);
    sort(b, b + n);
    sort(c, c + n);
    f r += (lower_bound(a, a + n, b[i]) - a) * (c + n - upper_bound(c, c + n, b[i]));
    cout << r;
}


Measured memory_bytes: 9216
import sys



index = {}
for line in sys.stdin:
    word, page_num = tuple(line.rstrip('\n').split(' '))
    if word in index:
        index[word].append(int(page_num))
    else:
        index[word] = [int(page_num)]
for k in sorted(index.keys()):
    print k
    pages = index[k]
    pages.sort()
    print ' '.join(map(str, pages))

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	int i;
	if(a>=b)
	{
		for(i=0;i<a;i++)
		printf("%d",b);
	}
	else
	{
		for(i=0;i<b;i++)
		printf("%d",a);
	}
} 

Measured memory_bytes: 256
N=int(input())
H=list(map(int,input().split()))
S=[]
ans=[]
count=0

if N==1:
    print(0)

else:
    for i in range(N-1):
        if H[i]>=H[i+1]:
            S.append("o")
        else:
            S.append("x")

    for i in range(N-1):
        if S[i]=="o":
            count+=1
        else:
            ans.append(count)
            count=0
    ans.append(count)
    print(max(ans))

Measured memory_bytes: 14224
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
using vll = vector<long long>;

template<typename T1>
T1 gcd(T1 a, T1 b) { return b ? gcd(b, a % b) : a; }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)

int main() {
	ll a, b, c, d,s,e;
	in(a);
	in(b);
	in(c);
	in(d);

	vll denom(3),ans(3,0);

	denom[0] = c;
	denom[1] = d;
	denom[2] = c * d / gcd(c,d);

	rep(i, 0, 3) {
		if (b >= denom[i]) {
			if (a <= denom[i]) {
				s = 0;
			}
			else {
				s = (a - (a % denom[i])) / denom[i];
				if (a % denom[i] == 0) {
					s--;
				}
			}
			e = (b - (b % denom[i])) / denom[i];

			ans[i] += e - s;
		}
	}
	
	outn(b-a+1 - ans[0]-ans[1]+ans[2]);

	return 0;

}



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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

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

  int size = s.size();
  REP(i, size) {
    s.pop_back();
    if(s.size() % 2 == 1) continue;
    string sub1 = s.substr(0, s.size()/2);
    string sub2 = s.substr(s.size()/2, s.size()/2);
    if(sub1 == sub2) {
      cout << s.size() << endl;
      return 0;
    }
  }
  cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(s,t):
        if s == t:
            return 'IDENTICAL'
        sa = s.split('"')
        ta = t.split('"')
        if len(sa) != len(ta):
            return 'DIFFERENT'
        ef = False
        for i in range(len(sa)):
            si = sa[i]
            ti = ta[i]
            if si == ti:
                continue
            if i % 2 == 0 or ef:
                return 'DIFFERENT'
            ef = True
        return 'CLOSE'

    while 1:
        n = S()
        if n == '.':
            break
        rr.append(f(n,S()))

    return '\n'.join(map(str,rr))


print(main())



Measured memory_bytes: 9048
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int a,b;
    cin >> a >> b;

    srep(i,1,1000000){
        double c = (double)i * 0.08;
        double d = (double)i * 0.1;
        int cc = c;
        int dd = d;
        if(a == cc && b == dd){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}
 
 


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

int main(){
    string S;
    int count0=0, count1=0, ans;
    cin >> S;
    for(int i=0;i<S.length();i++){
        if(S[i]=='0'){
            count0++;
        }else{
            count1++;
        }
    }
    ans = 2*min(count0,count1);
    cout << ans << endl;
}



Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	while(true){
		long n,m;
		cin>>n>>m;
		if(n==0&&m==0)break;
		long sum=0;
		vector<pair<long,long>> d(n);
		for(int i=0;i<n;i++){
			cin>>d[i].second>>d[i].first;
			sum+=d[i].first*d[i].second;;
		}
		sort(d.begin(),d.end());
		reverse(d.begin(),d.end());
		for(int i=0;i<n;i++){
			sum-=min(m,d[i].second)*d[i].first;
			m-=min(m,d[i].second);
		}
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 3156
#include <iostream>
using namespace std;
typedef long long l;
l n,k,r=0;l h[400005]={0};l L[12][2]={0};l M=998244353;
int main(){
  cin>>n>>k;h[1]=1;h[2]=-1;
  for(int i=0;i<k;i++)cin>>L[i][0]>>L[i][1];
  for(int i=1;i<n;i++){r=(r+h[i]+100*M)%M;
    for(int j=0;j<k;j++){h[L[j][0]+i]+=r;h[L[j][1]+i+1]-=r;}
  }  cout<<((r+h[n])+100*M)%M<<endl;}

Measured memory_bytes: 6712
X, K, D = map(int, input().split())
if X < 0:
  X = -X
if K*D <= X:
  print(abs(X-K*D))
else:
  if K%2 != (X//D)%2:
    print(abs(X%D - D))
  else:
    print(abs(X%D))


Measured memory_bytes: 9164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {

            string input = Console.ReadLine();
            int N = int.Parse(input);
            int[] ary = new int[N];


            ary[0] = int.Parse(Console.ReadLine());
            ary[1] = int.Parse(Console.ReadLine());

            int max1 = ary[0] < ary[1] ? ary[1] : ary[0];
            int max2 = ary[0] < ary[1] ? ary[0] : ary[1];

            for (int i = 2; i < N; i ++ )
            {
                input = Console.ReadLine();
                ary[i] = int.Parse(input);

                if(max1 < ary[i] ) {
                    max2 = max1;
                    max1 = ary[i];
                } else if ( max2 < ary[i])
                {
                    max2 = ary[i];
                }
            }


            for(int i = 0; i < N; i++ )
            {
                if (max1 == max2)
                {
                    Console.WriteLine(max1);
                }
                else
                {
                    if(ary[i] != max1)
                    {
                        Console.WriteLine(max1);
                    } else
                    {
                        Console.WriteLine(max2);
                    }
                }
            }


            return;
        }



    }
}


Measured memory_bytes: 18480
#include<stdio.h>
int main(){
int s,i,j,k;
scanf("%d",&s);
s++;
for(i=-1;i<24&&s;i++){
for(j=-1;j<59&&s;j++){
for(k=-1;k<59&&s;k++)s--;
}
}
printf("%d:%d:%d\n",i,j,k);
return 0;
}

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

int main(){
  int In[3];
  int c_5 = 0,c_7 = 0;
  for(int i=0;i < 3;i++){
    cin >> In[i];
    if(In[i] == 5){
      c_5++;
    }else if(In[i] == 7){
      c_7++;
    }
  }
  if(c_5 == 2 && c_7 == 1){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  } 
} 
  



Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 31.03.2018 20:28:06       
**/
#include <bits/stdc++.h>

using namespace std;

int a[51] = {0,1,2,12,84,770,8340,106400,1546888,25343766,461133960,232367169,627905865,632459808,928262728,919805769,382796331,887217496,639768068,869694124,205875097,205589953,487772376,239955313,998339621,31622834,902930073,146839084,449786840,982224660,865803735,21834818,721531716,26008837,471774471,69010090,700009308,776938882,645550477,526939604,142728157,654489641,128201240,185493259,789721045,977049419,589149550,700648836,25087729,874433491,352791804};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  cout << a[n] << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int a,b;
int main(){
	scanf("%d%d",&a,&b);
	if(a==1)  a=14;
	if(b==1)  b=14;
	if(a>b)  printf("Alice");
	if(a==b)  printf("Draw");
	if(a<b)  printf("Bob");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e5+1)
#define INFL LLONG_MAX
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;


int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;

	// Write your code here


	int t = 1;
	//cin >> t;
	while (t--) {
		ll n;
		cin >> n;
		ll cnt = 0;
		ll x = 100;
		while (n > x) {
			x += x / 100;
			cnt++;
		}
		cout << cnt << "\n";
	}


	return 0;
}

Measured memory_bytes: 3660
n,m = map(int,input().split())
AB = [[] for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    AB[a-1].append(b-1)
    AB[b-1].append(a-1)

visited = set()
ans = [0]*n
stack = [0]
for i in stack:
    # このへんあやしい
    for j in AB[i]:
        if j in visited:
            continue
        visited.add(j)
        ans[j] = i+1
        stack.append(j)
    # このへんまで
for i in ans[1:]:
    if i==0:
        print('No')
        exit()
print('Yes')
for i in ans[1:]:
    print(i)

Measured memory_bytes: 42400
N, X = map(int, input().split())
L = [int(i) for i in input().split()]

sum = 0
count = 1

for i in range(N):
  sum = sum + L[i]
  count += 1
  if sum > X:
    count -= 1
    break
  if sum >= X:
    break
print(count)

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = (int) 1e5 + 10;
const int MOD = (int) 1e9 + 7;

map<int, int> mp;

int n;
ll c2, c4, c14, c24, c74;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int t = i;
        for (int j = 2; j <= i; ++j) {
            while (t % j == 0) {
                t /= j;
                mp[j]++;
            }
        }
        if (t != 1) mp[t]++;
    }

    for (auto &m : mp) {
        if (m.second >= 74) c74++;
        if (m.second >= 24) c24++;
        if (m.second >= 14) c14++;
        if (m.second >= 4) c4++;
        if (m.second >= 2) c2++;
    }

    cout << c74 + (c2 - 1) * c24 + (c4 - 1) * c14 + (c2 - 2) * (c4 - 1) * c4 / 2 << endl;
}


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

template<typename T>
struct BinaryIndexedTree {
private:
  std::vector<T> node;

public:
  BinaryIndexedTree(int n_) { node.resize(n_, 0); }
  void add(int k, T x) {
    for (int j = k + 1; j <= node.size(); j += j & -j) node[j-1] += x;
  }
  T sum(int k) { // [0, k)
    T acc = 0;
    for (int j = k; j > 0; j -= j & -j) acc += node[j-1];
    return acc;
  }
};

int main() {
  int n, q;
  cin>>n>>q;
  BinaryIndexedTree<int> bit(n);
  for (int i = 0; i < q; ++i) {
    int com, x, y;
    cin>>com>>x>>y;
    if (com == 0) bit.add(x-1, y);
    else cout << bit.sum(y)-bit.sum(x-1) << endl;
  }
}


Measured memory_bytes: 3160
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //ATTENTION: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/
string s;
/**********************************/

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

    cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
}


Measured memory_bytes: 256
import collections

n = int(input())
v = list(map(int, input().split()))

O = collections.Counter(v[0::2])
E = collections.Counter(v[1::2])

def get_candidate(F):
    c = [[0, 0], [0, 0]]
    for i, j in F.items():
        if j >= c[0][1]:
            c[1] = c[0]
            c[0] = [i, j]
        elif j >= c[1][1]:
            c[1] = [i, j]
    return c

o = get_candidate(O)
e = get_candidate(E)

if o[0][0] != e[0][0]:
    ans = n - o[0][1] - e[0][1]
else:
    ans = min(n - o[0][1] - e[1][1], n - o[1][1] - e[0][1])

print(ans)

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

int main(){
  int N;
  cin >> N;
  vector<ll> S(N),a(N);
  rep(i,N) cin >> a[i];
  S[0] = a[0];
  for(int i = 1; i < N ; i++) {
    S[i] = S[i-1] + a[i];
  }
  ll res = 0;
  map<ll,int> mp;
  for(int i = N-1; i >= 0; i--) {
    res += mp[S[i]];
    mp[S[i]]++;
  }
  cout << res + mp[0] << endl;
  return 0;
}

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

int main(){
    ll a,b,c; cin >> a >> b >> c;
    ll tmp=c-(a+b);
    if (tmp>=0 && 4*a*b<tmp*tmp) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) int(x.size())

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; }

const double PI=3.14159265358979323846;

int mod = 1e9+7;
int INF = 1e9+7;
// const long long INF = 1LL<<60;

int dp[3001][3001];

int main(){
  int N, T;
  cin >> N >> T;
  vector<P> item(N); 
  rep(i, N){
    cin >> item[i].first >> item[i].second;
  }

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

  int ans = 0;
  rep(i, N){
    rep(j, T+1){
      // 使わない
      chmax(dp[i+1][j], dp[i][j]);
      // 使う
      int nj = j + item[i].first;
      if(nj > T) continue;
      dp[i+1][nj] = max(dp[i+1][nj], dp[i][j] + item[i].second);
    }
    int tmp_ans = dp[i][T-1] + item[i].second;
    chmax(ans, tmp_ans);
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;
int main(){
  int r;
  cin >> r;
  if(r<1200){
    cout << "ABC" << endl;
  }
  else if(r<2800){
    cout << "ARC" << endl;
  }
  else {
    cout << "AGC" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<ll,ll> ;
const ll INF = 1e18;
const int MOD = 1000000007;
int n = 10005;
vector<vector<int>> tree(n,vector<int>());
vector<int> c(n);
vector<int> ans(n);
int cnt = 0;
int M = 0;

void dfs(int i,int p=-1){
    for(int child:tree[i]){
        if(child==p) continue;
        dfs(child,i);
    }

    ans[i] = c[cnt];
    if(cnt != n-1) M += ans[i];
    ++cnt;
    return;
}

int main(){
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        --a;--b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    c.resize(n);
    rep(i,n) cin >> c[i];
    sort(c.begin(),c.end());
    dfs(0);
    cout << M << endl;
    rep(i,n){
        cout << ans[i] << (i==n-1 ? '\n' : ' ');
    } 
    return 0;
}

Measured memory_bytes: 1408
import sys
fin = sys.stdin.readline


H, W = [int(elem) for elem in fin().split()]
grid = [[int(elem) for elem in fin().split()] for _ in range(H)]
assert len(grid[0]) == W

directions = ((0, 1), (1, 0))

operations = []
for y in range(H):
    for x in range(W):
        if grid[y][x] % 2 == 0:
            continue
        for dy, dx in directions:
            next_y, next_x = y + dy, x + dx
            if next_y >= H or next_x >= W:
                continue
            elif grid[next_y][next_x] % 2 == 1:
                grid[y][x] -= 1
                grid[next_y][next_x] += 1
                operations.append((y + 1, x + 1, next_y + 1, next_x + 1))
                break
        else:
            if y == H - 1 and x == W - 1:
                break
            elif x == W - 1:
                next_y, next_x = y + 1, x
            else:
                next_y, next_x = y, x + 1
            grid[y][x] -= 1
            grid[next_y][next_x] += 1
            operations.append((y + 1, x + 1, next_y + 1, next_x + 1))  

print(len(operations))
for y, x, next_y, next_x in operations:
    print(y, x, next_y, next_x)


Measured memory_bytes: 26484
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 998244353;

int main(){
	int H, W, A, B;
	cin >> H >> W >> A >> B;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cout << ((i < B) ^ (j < A));
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,a[10000];
  vector<long long> v;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  for(int i=0;i<n;i++)
    for(int j=0;j<=3&&j<n;j++){
      if(i==j)continue;
      long long s=a[i];
      for(int k=0;k<=(int)log10(a[j]);k++)s*=10;
      v.push_back(s+a[j]);
    }
  sort(v.begin(),v.end());
  cout<<v[2]<<endl;
  return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] nums = new int[n];
		int count = 0;
		for(int i=0; i<nums.length; i++) {
			nums[i] = sc.nextInt();
			if(nums[i]%2==0) {
				while(nums[i]%2==0) {
					nums[i] = nums[i]/2;
					count++;
				}
			}else {
				continue;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 34460
#include<bits/stdc++.h>
#define fr(i,x,y) for(int i=x;i<=y;++i)
#define rf(i,x,y) for(int i=x;i>=y;--i)
#define LL long long 
using namespace std;
const int N=2e5+10,mod=1e9+7;
LL jc[N]={1},ny[N]={1};

LL add(LL x,LL y){
	return (x+y)%mod;
}

LL mul(LL x,LL y){
	return x*y%mod;
}

void Add(LL &x,LL y){
	x=(x+y)%mod;
}

void Mul(LL &x,LL y){
	x=(x*y)%mod;
}

LL q_pow(LL x,int y=mod-2){
	LL ans=1;
	for(;y;y>>=1){
		if(y&1) Mul(ans,x);
		Mul(x,x);
	}
	return ans;
}

LL C(int x,int y){
	return mul(jc[x],mul(ny[y],ny[x-y]));
}

LL Get(int x,int y){
	return C(x+y,y);
}

int main(){
	fr(i,1,N) jc[i]=mul(jc[i-1],i),ny[i]=q_pow(jc[i]);
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	LL ans=Get(w-1,h-1),res=0;
	fr(i,1,b) Add(res,mul(Get(h-a-1,i-1),Get(a-1,w-i))); 
	Add(ans,add(mod,-res));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
using namespace std;
int main(){
  int a;
  cin>>a;
if(a%10==7)
{cout<<"Yes"<<endl;
 return 0;}
  a=a/10;
if(a%10==7)
{cout<<"Yes"<<endl;
 return 0;}
  a=a/10;
  if(a%10==7)
{cout<<"Yes"<<endl;
 return 0;}
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3644
import itertools
import math
import fractions
import functools

import math
import itertools

# -1 no ans
# 1 syoziki
# 0 hu sinsetu

N = int(input())
ans = [[-1] * N for i in range(N)]


for person in range(N):
    A = int(input())
    for _ in range(A):
        x, y = map(int, input().split())
        x -= 1
        ans[person][x] = y


def is_ok(num):
    # -1 not decided
    # 1 syoziki
    # 0 husinsetu
    people = []
    for i in range(N):
        if (num >> i) & 1:
            people.append(1)
        else:
            people.append(0)


    for i in range(N):
        if people[i] == 1:
            for j in range(N):
                if ans[i][j] == 1 and people[j] != 1:
                    return False
                if ans[i][j] == 0 and people[j] != 0:
                    return False
    return True


    # people = [-1] * N
    # for i in range(N):
    #     # i is syoziki
    #     if((num >> i) & 1):
    #         if(people[i] == 0):
    #             return False
    #         people[i] = 1
    #         for j in range(N):
    #             if(ans[i][j] == 1):
    #                 if(people[j] == 0):
    #                     return False
    #                 people[j] = 1
    #             if(ans[i][j] == 0):
    #                 if(people[j] == 1):
    #                     return False
    #                 people[j] = 0
    #     else:
    #         if(people[i] == 1):
    #             return False
    #         people[i] = 0

    # return True


def countBit(num):
    ori = num
    count = 0
    while(num > 0):
        if(num & 1):
            count += 1
        num = num >> 1
    return count


out = 0

for i in range(1 << N):
    if(is_ok(i)):
        out = max(out, countBit(i))

print(out)


Measured memory_bytes: 72024
function Scanner(input) {
	var self = this;
	self.itemNo = 0;
	self.orgStr = input;
	self.splitedStrs = (function(target) {
		var result = [];
		var target = target.replace(/[\n \t]+/g, " ");
		var strs = target.split(" ");
		for (var i = 0, len = strs.length; i < len; i++) {
			result.push(strs[i]);
		}
		return result;
	}(input));

	self.next = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? result : null;
	}

	self.nextInt = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? parseInt(result) : null;
	}

	self.nextBigDecimal = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? parseFloat(result) : null;
	}
	
	self.nextByte = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? new Int8Array(result) : null;
	}

}

function Main(sc) {

	var K = sc.nextInt();
	var A = sc.nextInt();
	var B = sc.nextInt();
	var ans = "NG";
	
	for (var i = 0; i < 10000000; i++) {
		if (A <= K * i && K * i <= B) {
			ans = "OK";
		}
		if (K * i > B) break;
	}
	
	console.log(ans);
}
Main(new Scanner(require("fs").readFileSync("/dev/stdin", "utf8")));
// Main(new Scanner("33"));

// var str1 = sc.next(); // Stringで取得
// var int1 = sc.nextInt(); // intで取得
// var bd1 = sc.nextBigDecimal(); // BigDecimalで取得
// var byte1 = sc.nextByte(); // byteで取得


Measured memory_bytes: 29584