akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define int ll
#define BUF 1e5
#define INF 1LL << 30
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
constexpr ll mod = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

template <typename Monoid>
class SegmentTree {
public:
    using F = function<Monoid(Monoid, Monoid)>;

    vector<int> node;
    int size;
    int n;
    F f;
    Monoid ie;

    SegmentTree(vector<int> &in, F f, Monoid ie) : f(f), ie(ie) {
        int in_sz = in.size();
        n = 1;
        while (n < in_sz) {
            n *= 2;
        }
        size = n * 2 - 1;
        node.resize(size, 0);
        for (int i = 0; i < in_sz; i++) {
            node[n - 1 + i] = in[i];
        }
        init_dfs(0);
    }

    int init_dfs(int now) {
        if (2 * now + 1 >= size)
            return node[now];
        node[now] = f(init_dfs(2 * now + 1), init_dfs(2 * now + 2));
        return node[now];
    }

    void add(int index, int val) {
        index += n - 1;
        node[index] += val;
        while (index > 0) {
            index = (index - 1) / 2;
            node[index] = f(node[2 * index + 1], node[2 * index + 2]);
        }
    }

    void update(int index, int val) {
        index += n - 1;
        node[index] = val;
        while (index > 0) {
            index = (index - 1) / 2;
            node[index] = f(node[2 * index + 1], node[2 * index + 2]);
        }
    }

    int query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    int _query(int a, int b, int now, int l, int r) {
        if (r <= a || b <= l)
            return ie;
        if (a <= l && r <= b)
            return node[now];
        int val_l = _query(a, b, 2 * now + 1, l, (l + r) / 2);
        int val_r = _query(a, b, 2 * now + 2, (l + r) / 2, r);
        return f(val_l, val_r);
    }
};

signed main() {
    cin >> N >> Q;
    int ie = 0;
    vector<int> v(N, ie);
    SegmentTree<int> sg(v, [](int x, int y) { return x + y; }, ie);
    for (int q = 0; q < Q; q++) {
        int c, x, y;
        cin >> c >> x >> y;
        if (c == 0) {
            sg.add(x - 1, y);
        } else {
            cout << sg.query(x - 1, y) << endl;
        }
    }
}


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

int main(){
    int a,b,ans=-1;
    cin>>a>>b;
    for(int i=1;i<=1010;i++){
        int A,B;
        A=i*8/100;
        B=i/10;
        if(a==A&&b==B){ans=i;
            break;
            }
        }
    cout<<ans<<endl;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  string S; cin >> S;
  int N = S.size();
  vector<vector<ll>> num(N+1, vector<ll>(13,0));
  num[0][0] = 1;
  
  reverse(S.begin(),S.end());
  vector<ll> d = {1,10,9,12,3,4};
  for(int i = 1; i <= N; i++) {
    int m = (i-1) % 6;
    if (S[i-1] == '?') {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 13; k++) {
          int l = (j * d[m] + k) % 13;
          num[i][l] += num[i-1][k];
          num[i][l] %= MOD; 
        }
      }
    } else {
      int j = S[i-1] - '0';
      for (int k = 0;k < 13; k++) {
        int l = (j * d[m] + k) % 13;
        num[i][l] += num[i-1][k];
        num[i][l] %= MOD; 
      }
    }
  }

  cout << num[N][5] << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

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

  int i = 1;
  while (1) {
    i++;
    int ins;
    if (n % 2 == 0) {
      ins = n / 2;
    } else {
      ins = n * 3 + 1;
    }
    if (s.find(ins) == s.end())
      s.insert(ins);
    else {
      cout << i << endl;
      return 0;
    }
    n = ins;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a,b,x;
int main(){
	scanf("%lld%lld%lld",&a,&b,&x);
	rep(i,0,10)printf("%lld\n",x=x*a-b);
}



Measured memory_bytes: 128
#include <stdlib.h>
#include <stdio.h>

#define MAXN 100000

struct list {
	int n, c;
	int *edges;
} verts[MAXN];

void add_list(struct list *l, int v) {
	if (l->n+1 > l->c) {
		if (!l->c)
			l->c = 1;
		l->c *= 2;
		l->edges = realloc(l->edges, (size_t)l->c * sizeof *l->edges);
	}
	l->edges[l->n++] = v;
}
void del_list(struct list *l, int v) {
	int tail = 0;
	for (int head = 0; head < l->n; head++) {
		if (l->edges[head] == v)
			continue;
		l->edges[tail++] = l->edges[head];
	}
	l->n--;
}

void add_edge(int a, int b) {
	add_list(&verts[a], b);
	add_list(&verts[b], a);
}

int calc_dists_rec(int c, int dists[MAXN], int dist) {
	if (dists[c] != -1)
		return -1;
	dists[c] = dist;

	int best = dist;
	for (int i = 0; i < verts[c].n; i++) {
		int d = calc_dists_rec(verts[c].edges[i], dists, dist+1);
		if (d > best)
			best = d;
	}
	return best;
}

int calc_dists(int s, int dists[MAXN]) {
	for (int i = 0; i < MAXN; i++)
		dists[i] = -1;
	return calc_dists_rec(s, dists, 0);
}

int udist[MAXN], vdist[MAXN], cdist[MAXN];

int crit_point(int s) {
	if (udist[s] >= vdist[s])
		return s;

	int bestv = -1, bestd = MAXN;
	for (int i = 0; i < verts[s].n; i++) {
		int n = verts[s].edges[i];
		if (vdist[n] < bestd) {
			bestv = n;
			bestd = vdist[n];
		}
	}

	return crit_point(bestv);
}

int main(void) {
	int n, u, v;
	scanf("%d%d%d", &n, &u, &v);
	u--; v--;

	for (int i = 0; i < n-1; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		add_edge(a-1, b-1);
	}

	calc_dists(u, udist);
	calc_dists(v, vdist);
	int crit = crit_point(u);

	int before;
	for (before = 0; before < verts[crit].n-1; before++) {
		int da = udist[verts[crit].edges[before]];
		int db = udist[verts[crit].edges[before+1]];
		if (da < db)
			break;
	}
	int befv = verts[crit].edges[before];
	del_list(&verts[befv], crit);
	int max = calc_dists(befv, cdist);

	printf("%d\n", udist[befv] + max + (udist[crit] == vdist[crit]));

	for (int i = 0; i < n; i++)
		free(verts[i].edges);
}


Measured memory_bytes: 9856
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<endl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<endl
#define trii(x) cerr<<#x<<": ("<<x.F<<","<<x.S<<")\n";
#define trvii(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<"("<<a[zz].F<<","<<a[zz].S<<") ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<"\n"
#define trsetii(s) cerr<<#s<<": ";for(auto &i:s) trii(i);
#define epsilon 0.000000001L
#define mod 1000000007ll
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define modulo 998244353ll

int main()
{
    fast();
    ll n;
    cin>>n;
    vi a(n);
    for(ll i=0;i<n;i++)
        cin>>a[i];
    sort(a.begin(),a.end());
    __int128 pro =1 ;
    for(int i=0;i<n;i++)
    {
        pro*=(__int128)a[i];
        if(pro>1000000000000000000ll)
        {
            cout<<-1<<nl;
            return 0;
        }
    }
    ll ans=pro;
    cout<<ans<<nl;
}


Measured memory_bytes: 3936
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct point
{
	long long name; long long dist;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
ll const MOD = 1e9 + 7;

ll const MAX = 200005;
ll dist[MAX] = {};
ll n, m;
struct edge {
	ll to; ll dist;
};

ll const INF = 1e18;
priority_queue<point> pq;
vector<edge> G[MAX];
vector<edge> S[MAX];
vector<edge> T[MAX];

ll dp_s[MAX] = {};
ll dp_t[MAX] = {};

bool ord(ll x, ll y) {
	return dist[x] < dist[y];
}

ll num[MAX];

ll dijkstra(ll start, ll goal) {
	REP(i, 1, n) {
		dist[i] = INF;
	}
	ll cnt = n;
	pq.push({ start,0 });
	while (!pq.empty() && cnt > 0) {
		point curp = pq.top();
		pq.pop();
		ll cur = curp.name; ll curd = curp.dist;
		if (dist[cur] == INF) {
			cnt--;
			dist[cur] = curd;
			REP(i, 0, SIZE(G[cur]) - 1) {
				edge next_e = G[cur][i];
				if (dist[next_e.to] != INF) continue;
				pq.push({ next_e.to, curd + next_e.dist });
			}
		}
	}
	return dist[goal];
}


void filldp(ll dp[], vector<edge> X[], ll start) {
	dp[start] = 1;
	REP(i, 1, n) {
		ll cur = num[i];
		REP(j, 0, SIZE(X[cur]) - 1) {
			ll next = X[cur][j].to;
			dp[next] = (dp[next] + dp[cur]) % MOD;
		}
	}
}

int main() {
	cin >> n >> m;
	ll s, t;
	cin >> s >> t;
	REP(i, 1, m) {
		ll u, v, d;
		cin >> u >> v >> d;
		G[u].push_back({ v,d*2 });
		G[v].push_back({ u,d*2 });
	}
	ll d;
	d = dijkstra(s,t);
	d /= 2;
	REP(i, 1, n) {
		num[i] = i;
	}
	SORT_O(num, n, ord);
	REP(i, 1, n) {
		REP(j, 0, SIZE(G[i]) - 1) {
			ll f = i;
			ll to = G[i][j].to;
			ll dis = G[i][j].dist;
			if (dis + dist[f] == dist[to]) {
				S[f].push_back({ to,dis });
				T[to].push_back({ f,dis });
			}
		}
	}


	filldp(dp_s, S, s);
	reverse(num + 1, num + 1 + n);
	filldp(dp_t, T, t);
	ll ans = 0;
	REP(i, 1, n) {
		if (dist[i] == d) {
			
			ll cur = dp_s[i] * dp_t[i] % MOD;
			ans = (ans + cur * cur%MOD) % MOD;
			//cout << i << " _ " << cur << endl;
		}
		else {
			REP(j, 0, SIZE(S[i]) - 1) {
				ll next = S[i][j].to;
				if (dist[i] < d && dist[next] > d) {
					ll cur = dp_s[i] * dp_t[next] % MOD;
					ans = (ans + cur * cur % MOD) % MOD;
					//cout << i << " " << next << " ! " << cur << endl;
				}
			}
		}
	}
	/*
	REP(i, 1, n) {
		cout << dist[i] << " ";
	}
	cout << endl;
	REP(i, 1, n) {
		cout << dp_s[i] << " ";
	}cout << endl;
	REP(i, 1, n) {
		cout << dp_t[i] << " ";
	}
	cout << endl;
	*/
	cout << (dp_s[t]*dp_s[t]%MOD-ans+MOD)%MOD << endl;
}

Measured memory_bytes: 39544
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-6;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int n;

int main(){
	while(1){
		cin>>n;
		if(!n) break;
		vi a(n);
		for(int i=0;i<n;i++) cin>>a[i];
		sort(a.begin(),a.end());
		int sum=0;
		for(int i=1;i<n-1;i++) sum+=a[i];
		cout<<sum/(n-2)<<endl;
	}
}

Measured memory_bytes: 2972
#include <iostream>

using namespace std;

int preorder[40],inorder[40];

void print_postorder(int lp,int rp,int li,int ri);

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;++i)
    cin >> preorder[i];
  for(int i=0;i<n;++i)
    cin >> inorder[i];

  print_postorder(0,n,0,n);

  return 0;
}


// lp<= i&&i<rp
void print_postorder(int lp,int rp,int li,int ri){
  if(lp==rp) return;
  //cout << "[" << lp << "," << rp << "] [" << li << "," << ri << "]" << endl;
  int root = preorder[lp];
  int num = 0;
  for(int i=li;i<ri&&inorder[i]!=root;++i){
    num++;
  }
  print_postorder(lp+1,lp+1+num,li,li+num);
  print_postorder(lp+1+num,rp,li+num+1,ri);

  cout << preorder[lp];
  if(lp == 0){
    cout << endl;
  }else{
    cout << " ";
  }
}

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

using namespace std;

int main()
{
  string S[3];
  cin >> S[0] >> S[1] >> S[2];
  for(int i = 0; i < 3; i++) {
    reverse(begin(S[i]), end(S[i]));
  }
  int now = 0;
  while(!S[now].empty()) {
    int nxt = (S[now].back() - 'a') % 3;
    S[now].pop_back();
    now = nxt;
  }
  cout << (char) (now + 'A') << endl;
}

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

int main(){
  int N;
  string S;
  cin>>N>>S;
  int ans=0;
  int count=0;
  for(int i=1;i<N;i++){
    count=0;
    int k=N;
    for(int j=0;j<k&&i+j<N;j++){
      if(S.at(j)==S.at(i+j)){
        if(k==N){
          k=i+j;
        }
        count++;
      }else{
        ans=max(ans,count);
        count=0;
        k=N;
      }
    }
    ans=max(ans,count);
  }
  cout<<ans<<endl;
}


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

using namespace std;
const double EPS = 1e-8;

typedef complex<double> Point;
Point input(){
    double x, y;
    cin >> x >> y;
    return Point(x, y);
}
struct Circle{
    Point p;
    double r;
    Circle(Point p_, double r_) : p(p_), r(r_) {}
    bool operator < (const Circle & c) const {
        return r < c.r;
    }
    bool contain(const Circle& c) const {
        double d = abs(p - c.p);
        return r > c.r && r - c.r > d;
    }
    bool contain(const Point& pt) const {
        double d = abs(p - pt);
        return d < r;
    }
    bool cross(const Circle & c) const {
        double d = abs(p - c.p);
        return !contain(c) && r + c.r > d - EPS;
    }
};

vector<int> calc_dp(int n, vector<Circle> c, Circle d = Circle(Point(1e8, 1e8), 0)){
    assert(n == c.size());
    if(n == 0) return vector<int>(1, 0);
    vector<int> dp(n);
    for(int i = 0; i < n; i++){
        if(d.r > 0 && c[i].cross(d)) continue;
        dp[i] = 1;
        for(int j = 0; j < i; j++){
            if(c[i].contain(c[j])){
                dp[i] = max(dp[i], dp[j] + 1);
            }
        }
    }
    return dp;
}
int main(){
    int n;
    while(cin >> n && n){
        Point sp = input();
        Point tp = input();
        vector<Circle> sc, tc;
        REP(i, n){
            Point p = input();
            double r;
            cin >> r;
            Circle c(p, r);
            bool sb = c.contain(sp);
            bool tb = c.contain(tp);
            if(sb && tb) continue;
            if(sb) sc.push_back(c);
            if(tb) tc.push_back(c);
        }
        sort(sc.begin(), sc.end());
        sort(tc.begin(), tc.end());
        int sn = sc.size();
        int tn = tc.size();
        vector<int> sdp = calc_dp(sn, sc);
        vector<int> tdp = calc_dp(tn, tc);
        int ans = 0;
        ans = max(ans, *max_element(sdp.begin(), sdp.end()));
        ans = max(ans, *max_element(tdp.begin(), tdp.end()));
        for(int i = 0; i < sn; i++){
            for(int j = 0; j < tn; j++){
                if(!sc[i].cross(tc[j])){
                    ans = max(ans, sdp[i] + tdp[j]);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1336
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
	int n = 1;
	cin >> n;
	//vector<double>a(n);
	double a[105];
	double s1 = 0, s2 = 1;
	for (int i = 0; i < n; i++) {
		cin >> a[n];
		s1 += 1 / a[n];
		
	}
	cout << 1 / s1 << endl;
	return 0;
}

Measured memory_bytes: 256
import bisect
a, b, q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(a)] + [INF]
t = [-INF] + [int(input()) for i in range(b)] + [INF]
for question in range(q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for shrine in [s[b - 1], s[b]]:
        for temple in [t[d - 1], t[d]]:
            d1, d2 = abs(shrine - x) + abs(temple - shrine), abs(temple - x) + abs(shrine - temple)
            res = min(res, d1, d2)
    print(res)


Measured memory_bytes: 13864
#include <bits/stdc++.h>
using namespace std;
char amap[1005][1005];
int allb = 0;
struct Node{
    int x;
    int y;
    Node(int xi, int yi){
        x = xi; y = yi;
    }
};
queue<Node> man;
const int arr[2][4] = {{-1, 1, 0, 0}, {0, 0, -1, 1}};
int main(){
    int H, W;
    scanf("%d %d", &H, &W);
    getchar();
    for (size_t i = 0; i < (size_t)H; i++) {
        for (size_t j = 0; j < (size_t)W; j++) {
            amap[i][j] = getchar();
            if(amap[i][j] == '#'){
                allb++;
                Node node(i, j);
                man.push(node);
            }
        }
        getchar();
    }
    // for (size_t i = 0; i < (size_t)H; i++) {
    //     for (size_t j = 0; j < (size_t)W; j++) {
    //         printf("%c", amap[i][j]);
    //     }
    //     printf("\n");
    // }
    int ans = 0;
    while(allb < H * W){
        int l = man.size();
        for (size_t i = 0; i < (size_t)l; i++) {
            Node node = man.front();
            man.pop();
            for (size_t j = 0; j < 4; j++) {
                if(node.x + arr[0][j] < H && node.x + arr[0][j] >= 0 && node.y + arr[1][j] >= 0 && node.y + arr[1][j] < W && amap[node.x + arr[0][j]][node.y + arr[1][j]] == '.'){
                    amap[node.x + arr[0][j]][node.y + arr[1][j]] = '#';
                    allb++;
                    Node newnode(node.x + arr[0][j],node.y + arr[1][j]);
                    man.push(newnode);
                }
            }
        }
        ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 9360
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <utility>
#include <cctype>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#define LL long long
#define LB long double
#define x first
#define y second
#define Pair pair<int,int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const LL LINF=2e16;
const int INF=2e9;
const int magic=348;
const double eps=1e-10;
const double pi=3.14159265;

inline int getint()
{
    char ch;int res;bool f;
    while (!isdigit(ch=getchar()) && ch!='-') {}
    if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
    while (isdigit(ch=getchar())) res=res*10+ch-'0';
    return f?res:-res;
}

int n;
int a[58],b[58];
bool dp[58][58][58];int DP[58][58];
bool Dp[58][58];
int valid[58],vtot;
int anslist[58],tot;

inline void init_dp()
{
	memset(dp,false,sizeof(dp));
	int i,j,k;
	for (i=0;i<=50;i++) dp[i][i][0]=dp[i][i][1]=true;
	for (i=0;i<=50;i++) dp[i][0][1]=true;
	for (k=2;k<=50;k++)
		for (i=0;i<=50;i++)
			for (j=0;j<=50;j++)
			{
				if (dp[i][j][k-1]) {dp[i][j][k]=true;continue;}
				if (dp[i%k][j][k-1]) {dp[i][j][k]=true;continue;}
				dp[i][j][k]=false;
			}
	for (i=0;i<=50;i++)
		for (j=0;j<=50;j++)
		{
			for (k=0;!dp[i][j][k] && k<=50;k++) {}
			DP[i][j]=k;
		}
}

inline bool judge()
{
	int res=-1;
	int i,j,k,cc;
	for (i=1;i<=n;i++)
	{
		memset(Dp,false,sizeof(Dp));
		Dp[0][a[i]]=true;
		for (j=0;j<=vtot-1;j++)
			for (k=0;k<=50;k++)
				if (Dp[j][k])
				{
					Dp[j+1][k]=true;
					Dp[j+1][k%valid[j+1]]=true;
				}
		if (!Dp[vtot][b[i]]) return false;
	}
	return true;
}

int main ()
{
	n=getint();int i;
	for (i=1;i<=n;i++) a[i]=getint();
	for (i=1;i<=n;i++) b[i]=getint();
	init_dp();int lim=-1,calc;
	for (i=1;i<=n;i++) lim=max(lim,DP[a[i]][b[i]]);
	if (lim>50) {printf("-1\n");return 0;}
	if (lim==0) {printf("0\n");return 0;}
	anslist[1]=lim;++tot;
	for (calc=lim-1;calc>0;calc--)
	{
		vtot=0;for (i=1;i<=tot;i++) valid[++vtot]=anslist[i];
		for (i=calc-1;i;i--) valid[++vtot]=i;
		if (judge()) continue;
		anslist[++tot]=calc;
	}
	LL ans=0;for (i=1;i<=tot;i++) ans+=(1ll<<anslist[i]);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 512
//Author : Nishit Patel
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef double db;
typedef long long ll;
#define pb push_back
#define FAST cin.sync_with_stdio(0); cin.tie(0);
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define arep(i, a, n)  for(int i = a; i <= (n); ++i)
#define drep(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x)     for(auto& a : x)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef map<ll, ll> ml;
typedef unordered_map<ll, ll> hash;
#define deb_1(A)                     {cerr << "[" << #A << "] : " << A << endl;}
#define deb_2(A,B)                   {cerr << "[" << #A << "] : " << A << endl<< "[" << #B << "] : " << B << endl;}
#define deb_3(A,B,C)                 {cerr << "[" << #A << "] : " << A << endl<< "[" << #B << "] : " << B << endl\
									   << "[" << #C << "] : " << C << endl;}
#define deb_4(A,B,C,D)               {cerr << "[" << #A << "] : " << A << endl<< "[" << #B << "] : " << B << endl\
									   << "[" << #C << "] : " << C << endl<< "[" << #D << "] : " << D << endl;}
#define deb_X(x,A,B,C,D,FUNC, ...)  FUNC  
#define deb(...)                    deb_X(,##__VA_ARGS__,\
                                          deb_4(__VA_ARGS__),\
                                          deb_3(__VA_ARGS__),\
                                          deb_2(__VA_ARGS__),\
                                          deb_1(__VA_ARGS__),\
                                         )
                                         
                                         
#define L 1000005
bitset<L> bt;
ll memo[1000005];
map<ll, list<ll>> v;
ll dfs(ll curr,ll depth)
{
	 if(bt[curr] == 1)
	 {
		 return memo[curr]+1;
	 }
	 bt[curr] = 1;
	 ll logest_depth =0;
	 for(auto i: v[curr])
	 {
		 if(memo[i] == 0)
		 {
			 logest_depth = max(logest_depth,dfs(i,depth));
		 }
		 else{
			 logest_depth = max(logest_depth,memo[i]+1);
		 }
	 }
	 memo[curr] = logest_depth;
	 return 1+logest_depth;
}
int main() {
	FAST
	ll n,m,x,y;
	cin>>n>>m;
	rep(i,m)
	{
		cin>>x>>y;
		v[x].pb(y);
	}
	ll depth = INT_MIN;
	arep(i,1,n)
	{
		if(bt[i] == 0)
		{
			depth = max(depth,dfs(i,0));
		}
			
	}
	cout<<depth-1<<endl;
}


Measured memory_bytes: 19416
# ABC051 D - Candidates of No Shortest Paths
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def WF():
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])

n,m=nm()
aa=[]
bb=[]
cc=[]
d=[[0]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    aa.append(a)
    bb.append(b)
    cc.append(c)
for i in range(n):
    for j in range(n):
        if i==j:
            d[i][j]=0
        else:
            d[i][j]=10**5

for i in range(m):
    d[aa[i]][bb[i]]=min(d[aa[i]][bb[i]],cc[i])
    d[bb[i]][aa[i]]=min(d[bb[i]][aa[i]],cc[i])
WF()

ans=m
for i in range(m):
    short=False
    for j in range(n):
        if d[j][aa[i]]+cc[i]==d[j][bb[i]]:
            short=True
    if short:
        ans-=1
print(ans)


Measured memory_bytes: 3444
//   PIGMEISTER™   //

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

#define ll long long
#define ull unsigned long long
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);i++)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);i--)
#define mi map<ll,ll>
#define vi vector<ll>
#define si set<ll>
#define pi pair<ll,ll>
#define vp vector<pair<ll,ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define modinv(x) powah(x,mod-2)
#define ncr(n,r) (((fact[n]*modinv(fact[n-r]))%mod*modinv(fact[r]))%mod)
#define factorial fact.pb(1);sidha(i,1,MAX)fact.pb((fact[i-1]*i)%mod)
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod (ll)1000000007
//#define mod (ll)998244353
#define MAX 200005
ll powah(ll, ll);

int main()
{
    jaldi;
    
    ll n, k;
    cin >> n >> k;
    cout << min(n%k, k - n%k);

    return 0;
}

ll powah(ll x, ll y) { 
    ll res = 1; x = x % mod;
    while (y > 0) { 
        if (y & 1) res = (res*x) % mod; 
        y = y>>1; x = (x*x) % mod; 
    } 
    return res; 
}

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

typedef struct node{
	int key;
	struct node *parent;
	struct node *left;
	struct node *right;
} Node, Tree;

void insert(Tree **T, int key)
{
	Node *pre = NULL;
	Node *curr = *T;
	Node *newNode = NULL;
	
	newNode = (Node*)malloc(sizeof(Node));
	newNode->key = key;
	newNode->left = NULL;
	newNode->right = NULL;
	
	while (curr != NULL) {
		pre = curr;
		if (key > curr->key) {
			curr = curr->right;
		} else {
			curr = curr->left;
		}
	}
	
	newNode->parent = pre;
	
	//如果根结点存在，则pre一定不为空，反之pre为空 
	if (pre == NULL) {
		*T = newNode;
	} else {
		if (key > pre->key) {
			pre->right = newNode;
		} else {
			pre->left = newNode;
		}
	}
}

void Inorder(Tree *T)
{
	if (T == NULL)
		return;
		
	Inorder(T->left);
	cout << " " << T->key;
	Inorder(T->right);
}

void Preorder(Tree *T)
{
	if (T == NULL)
		return;
		
	cout << " " << T->key;	
	Preorder(T->left);
	Preorder(T->right);
}

void print(Tree *T)
{
	Inorder(T);
	cout << '\n';
	Preorder(T);
	cout << '\n';
}

int main(void)
{
	Tree *T = NULL;
	int n;
	int key;
	string cmd;
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> cmd;
		if (cmd == "insert") {
			cin >> key;
			insert(&T, key);
		} else {
			print(T);
		}
	}
	
	
	return 0;
}


Measured memory_bytes: 26652
#include<stdio.h>

int N;
int a[100001];
int b[100001];
int c[100001];
int happy[100001][3];

void action(int);

int main(void){
    scanf("%d",&N);

    int i;
    for(i=1;i<N+1;i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
    }

    happy[1][0]=a[1];
    happy[1][1]=b[1];
    happy[1][2]=c[1];

    for(i=2;i<N+1;i++){
        action(i);
    }
    
    if(happy[N][0]>happy[N][1]&&happy[N][0]>happy[N][2]){
        printf("%d\n",happy[N][0]);
    }else if(happy[N][1]>happy[N][2]){
        printf("%d\n",happy[N][1]);
    }else{
        printf("%d\n",happy[N][2]);
    }

    return 0;

}

void action(int i){
    int dpa=happy[i-1][0];
    int dpb=happy[i-1][1];
    int dpc=happy[i-1][2];
    if(dpb>dpc){
        happy[i][0]=dpb+a[i];
    }else{
        happy[i][0]=dpc+a[i];
    }
    if(dpa>dpc){
        happy[i][1]=dpa+b[i];
    }else{
        happy[i][1]=dpc+b[i];
    }
    if(dpb>dpa){
        happy[i][2]=dpb+c[i];
    }else{
        happy[i][2]=dpa+c[i];
    }

}

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

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

int MOD = 1e9 + 7;
ll INF = 1e18;

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

int n;
int match[2010];
bool used[2010];
vector<vector<int>> g(2000);

bool dfs(int v){
    used[v]=true;
    for(int i=0; i<g[v].size(); i++){
        int u=g[v][i], w=match[u];

        if(w < 0 || (!used[w] && dfs(w))){
            match[v]=u;
            match[u]=v;
            return true;
        }
    }
    return false;
}

int bipartite_matching(){
    int res=0;
    memset(match, -1, sizeof(match));

    for(int v=0; v<n; v++){
        if(match[v] < 0){
            memset(used, false, sizeof(used));
            if(dfs(v)){
                res++;
            }
        }
    }
    return res;
}

int main(){
    cin>>n;
    vector<int> a(n), b(n), c(n), d(n);
    for(int i=0; i<n; i++) cin>>a[i]>>b[i];
    for(int i=0; i<n; i++) cin>>c[i]>>d[i];

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(a[i] < c[j] && b[i] < d[j]){
                g[i].push_back(j+1000);
                g[j+1000].push_back(i);
            }
        }
    }

    cout << bipartite_matching() << endl;;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()
 
int GCD(int a,int b){ return b ? GCD(b,a%b) : a ;}
int LCM(int a,int b){ return a*b / GCD(a,b) ;}
 
typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;

int main(){
      int n,m;
      cin >> n >> m;
      vector<tuple<int,int,int>> py(m);
      rep(i,m){
            int p,y;
            cin >> p >> y;
            py[i] = make_tuple(p,y,i);
      }
      sort(ALL(py));
      int rank = 1;
      for(int i=0;i<m;i++){
            get<1>(py[i]) = rank;
            rank++;
            if(i<m-1 && get<0>(py[i])!=get<0>(py[i+1]))rank = 1;
      }
      sort(ALL(py),
      [](const auto &A,const auto &B)
      {return get<2>(A) < get<2>(B);});
      rep(i,m){
            printf("%06d%06d\n",get<0>(py[i]),get<1>(py[i]));
      }
      return 0;
}

Measured memory_bytes: 2688
#include <stdio.h>
#include <ctype.h>

int main(int argc, char** argv){
	int c;
	for(;;){
		// Input
		c = getchar();
		// Finish Check
		if( c == EOF ){
			break;
		}
		// Convert
		if( isupper(c) ){
			c = tolower(c);
		} else if( islower(c) ){
			c = toupper(c);
		}	
		// Output
		putchar(c);
		
	}
	return 0;
}

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

int main () {
  int N, A;
  cin >> N;
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> A;
    int x = 0;
    
    if (A % 2 == 1) {
      sum = 0;
      break;
    }
    
    while (A % 2 == 0){
      A /= 2;
      x++;
    }
    
    
    if (i == 0) {
      sum += x;
    }
    
    if (i != 0 && x <= sum){
      sum = x;
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
N = int(input())
l_list = list(map(int, input().split()))
l_list.sort()
from bisect import *
ans = 0
for i in range(N):
    for j in range(i + 1, N - 1):
        a = l_list[i]
        b = l_list[j]
        high = a + b
        id1 = bisect_right(l_list, high - 1)
        ans += max(0, id1 - (j + 1))
print(ans)


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

#define fr(i,b,e) for(int i=(b); i!=(e); ++i)
#define rep(i,e) for(int i=0; i!=(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long int ll;
using graph = vector<vector<int>>;
using edgedp = vector<vector<pair<int,ll>>>;
//constexpr int INF=1000000;
constexpr ll INF=1e18;
//constexpr int MOD=998244353;
constexpr int MOD=1e9+7;




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

    int n,m,x;
    cin >> n >> m >> x;
    
    // 全bit探索なるものを行ってみる。

    vector<int> c(n);
    vector<vector<int>> a(n,vector<int> (m));
    ll min=INF;
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];
        }
    }

    bool can=false;
    for(int cmb=(1<<n)-1; cmb>=0; --cmb){
        ll cost=0;
        vector<int> tmp(m,0);
        for(int i=0; i!=n; ++i){
            if(cmb & (1<<i)){
                cost+=c[i];
                rep(j,m) tmp[j]+=a[i][j];
            }
        }
        bool clear=true;
        fr(i,0,m){
            if(tmp[i]<x){
                clear=false;
                break;
            }
        }
        if(clear && (cost < min)) min=cost , can=true;
    }
    
    if(can){
        cout << min << "\n";
    }else{
        cout << -1 << "\n";
    }
}   




Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  int n; cin >> n;
  V a(n);
  rep(i, n) cin >> a[i];

  ll y = 0;
  rep(i, n) {
    y += (i % 2 == 0) ? (a[i]) : (-a[i]);
  }
  cout << y << " ";

  rep(i, n-1) {
    y = 2*a[i] - y;
    cout << y << " "; 
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N; cin >> N;
    ll R = ceil(sqrt((double)N));
    for (ll L = R; L >= 0; L--) {
        if (N % L == 0) {
            cout << L + N / L - 2 << endl;
            return 0;
        }
    }
}


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

int main() {
  int a,b,x;
  cin >> a >> b;
  x=a*b;
  if(x%2)
    cout << "Odd" << endl;
  else 
    cout << "Even" << endl;
  // ここにプログラムを追記
}

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

typedef long long ll;
typedef pair<int,int> P;
ll mod = 1e9+7;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0;i < n;++i) cin >> a[i];
    ll ans = 1;
    int x[3] = {0,0,0};
    for (int i = 0;i < n;++i) {
        int cnt = 0;
        for (int j = 0;j < 3;++j) if (a[i] == x[j]) cnt++;
        (ans *= cnt) %= mod;
        for (int j = 0;j < 3;++j) if (a[i] == x[j]) {
            x[j]++;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using namespace atcoder;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
  
    int N,Q; cin >> N >> Q;
    dsu uf(N);
    rep(i,Q) {
        int t,a,b; cin >> t >> a >> b;
        if (t == 0) {
            uf.merge(a,b);
        } else {
            if (uf.same(a,b)) cout << 1 << '\n';
            else cout << 0 << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 3936
import re
s = input()
s_without_x = s.replace("x", "")
if s_without_x[::-1] != s_without_x:
    print(-1)
else:
    length = len(s_without_x)
    idx = 0
    where = [0 for _ in range(length + 1)]
    for i in range(len(s)):
        now = s[i]
        if now == "x":
            where[idx] += 1
        else:
            idx += 1
    res = 0
    rev = where[::-1]
    for i in range(len(rev)):
        res += abs(where[i] - rev[i])
    print(int(res / 2))


Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << "\n";}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int v[510][510];
int ans[100000][4];
void solve() {
	var(int, h, w);
	rep(i, 1, h + 1) {
		rep(j, 1, w + 1) {
			cin >> v[i][j];
		}
	}
	int c = 0;
	rep(i, 1, h) {
		rep(j, 1, w + 1) {
			if (v[i][j] & 1) {
				ans[c][0] = i;
				ans[c][1] = j;
				ans[c][2] = i + 1;
				ans[c][3] = j;
				++c;
				++v[i + 1][j];
			}
		}
	}
	rep(j, 1, w) {
		if (v[h][j] & 1) {
			ans[c][0] = h;
			ans[c][1] = j;
			ans[c][2] = h;
			ans[c][3] = j + 1;
			++c;
			++v[h][j + 1];
		}
	}
	print(c);
	rep(i, 0, c) {
		print(ans[i][0], ans[i][1], ans[i][2], ans[i][3]);
	}
}
int main() {
	solve();
	return 0;
}


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

using namespace std;

const int N = 50;

int main() {
  long long k;
  cin >> k;
  long long a[N + 1];
  long long r = k / N;
  k %= N;
  for (int i = 1; i <= N; ++i) {
    a[i] = N - 1;
  }
  for (int i = 1; i <= N; ++i) {
    a[i] = N - 1 + r;
  }
  for (int i = 1; i <= N; ++i) {
    if (i <= k) {
      a[i] += N - k + 1;
    }
    else {
      a[i] -= k;
    }
  }
  cout << N << endl;
  for (int i = 1; i <= N; ++i) {
    cout << a[i] << (i == N ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=110000;
const double pi=acos(-1);
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 n;
  cin >> n;
  vector<ll>a(n);
  rep(i,n-1){
    ll x;
    cin >> x;
    x--;
    a[x]++;
  }
  rep(i,n) cout << a[i] << endl;
}


Measured memory_bytes: 4752
#include <stdio.h>
#include <stdlib.h>

int binarySearch(int *,int,int);

int main(){
  int n,q,i,count=0,*S,*T,found;

  scanf("%d",&n);

  S=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  T=(int *)malloc(q*sizeof(int));
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++){
    found=binarySearch(S,T[i], n);
  if(found==1)
    count++;
  }
  printf("%d\n",count);
  free(S);

  return 0;
}

int binarySearch(int *S,int x,int n){
  int left,right,mid;

  left=0;
  right=n;

  while(left<right){
    mid=(left+right)/2;
    if(S[mid]==x){
      return 1;
    }
    else if(S[mid]<x){
      left=mid+1;
    }else
      right=mid;
  }
  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <time.h>
#include <list>

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define chk(a) rep(i, a.size()) cout << a[i] << " "
#define SORT(c) sort((c).begin(),(c).end())
#define ll long long
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)


using namespace std;
typedef pair<int, int> pii;
#define WARU 1000000007;

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

int main(void) {
	string str;

	cin >> str;
	bool c = false;
	bool ok = false;

	rep(i, str.length()) {
		if (str[i] == 'C') {
			c = true;
		}
		if (c && str[i] == 'F') {
			ok = true;
		}

	}
	if (ok) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 4005
using namespace std;
int mp[2][N][N];
int n,k,Ans;
int sum(int tg,int i,int j,int k){
	return mp[tg][i][j]-mp[tg][i-k][j]
		  -mp[tg][i][j-k]+mp[tg][i-k][j-k];
}
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++){
		int x,y,tg;
		char ch[5];
		scanf("%d%d%s",&x,&y,ch);
		x%=2*k; y%=2*k;
		tg=(ch[0]=='B'?0:1);
		mp[tg][x][y]++;
		mp[tg][x+2*k][y+2*k]++;
		mp[tg][x+2*k][y]++;
		mp[tg][x][y+2*k]++;
	}
	for (int tg=0;tg<2;tg++)
		for (int x=0;x<4*k;x++)
			for (int y=1;y<4*k;y++)
				mp[tg][x][y]+=mp[tg][x][y-1]; 
	for (int tg=0;tg<2;tg++)
		for (int x=1;x<4*k;x++)
			for (int y=0;y<4*k;y++)
				mp[tg][x][y]+=mp[tg][x-1][y];
	for (int i=2*k;i<4*k;i++)
		for (int j=2*k;j<4*k;j++){
			int ans=sum(0,i,j,k);
			ans+=sum(0,i-k,j-k,k);
			ans+=sum(1,i,j-k,k);
			ans+=sum(1,i-k,j,k);
			Ans=max(Ans,ans);
		}
	printf("%d",Ans);
}

Measured memory_bytes: 125568
M=input()
N=len(M)
S=[]
B=[]
for i in range(0,N):
    S.append(M[i])
    B.append(M[i])
T=2**(N-1)
A=0
if N!=1:
    for i in range(0,T):
        t=[]
        k=i
        for j in range(0,N-1):
            if k>=2**(N-2-j):
                t.append(1)
                k=k-2**(N-2-j)
            else:
                t.append(0)
        n=0
        for j in range(0,N):
            S[j]=B[j]
        for j in range(0,N-1):
            if j<N-2:
                if t[j]==1:
                    n=n+int(S[j])
                else:
                    S[j+1]=S[j]+S[j+1]
            else:
                if t[j]==1:
                    n=n+int(S[j])+int(S[j+1])
                else:
                    S[j+1]=S[j]+S[j+1]
                    n=n+int(S[j+1])
        A=A+n
else:
    A=int(M)
print(A)

Measured memory_bytes: 3064
#include<iostream>
int main(){
	int w,h,x,y,r;
	std::cin>>w>>h>>x>>y>>r;
	if(x >= r && x <= w - r && y >= r && y <= h - r )
		std::cout<<"Yes"<<std::endl;
	else
		std::cout<<"No"<<std::endl;
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#define DIV LLONG_MAX

long long mypow(long long k, long long n) {
	long long temp = 1;

	k = k % DIV;
	while (n) {
		if (n % 2) temp = temp * k % DIV;
		k = k * k % DIV;
		n = n / 2;
	}
	return temp % DIV;
}

long long cmb(long long n, long long r) {
	long long x = 1, y = 1, y_inv;
	long long min;

	if (n - r > r) min = r;
	else min = n - r;
	for (long long i = 0; i < min; i++) {
		x = x * (n - i) % DIV;
		y = y * (i + 1) % DIV;
	}
	return x / y % DIV;
}

int main(void){
	int	n,p;
	int a;
	long long zero_cnt = 0, one_cnt = 0;
	long long ans = 0;

	scanf("%d %d", &n, &p);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		if (a % 2)one_cnt++;
		else zero_cnt++;
	}
	if (p) {
		for (long long i = 0; 2 * i + 1 <= one_cnt; i++) {
			//printf("cmb(%lld, 2 * %lld + 1)=%lld\n",
				//one_cnt,i,cmb(one_cnt, 2 * i + 1));
			ans += cmb(one_cnt, 2 * i + 1);
		}
	}
	else {
		for (long long i = 0; 2 * i <= one_cnt; i++) {
			//printf("%lld\n", cmb(one_cnt, 2 * i ));
			ans += cmb(one_cnt, 2 * i);
		}
	}
	//printf("ans=%lld\n", ans);
	//printf("pow(2,%lld)=%lld\n", zero_cnt, (long long)mypow(2, zero_cnt));
	ans = ans * (long long)mypow(2, zero_cnt);
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll n;
    cin >> n;

    vector<ll> pos(n+1,0);
    for(int i = 0; i < n; i++){
        ll a;
        cin >> a;
        pos[a] = i+1;
    }

    set<ll> used;
    used.insert(0);
    used.insert(n+1);

    ll ans = 0;
    for(int i = 1; i <= n; i++){
        auto itr = used.lower_bound(pos[i]);
        ll r = *itr;
        ll l = *(--itr);
        ans += (pos[i] - l)*(r - pos[i])*i;
        used.insert(pos[i]);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 11136
class Amida
  def initialize n
    @vlines = Array.new(n+1).map{Array.new(1000, nil)}
  end

  def set_hline h, v1, v2
    @vlines[v1][h] = v2
    @vlines[v2][h] = v1
  end

  def solve a
    now = a
    start = @vlines[now].size
    start.downto(0) do |i|
      next if @vlines[now][i].nil?
      now = @vlines[now][i]
    end
    puts now
  end
end

def main
  loop do
    n,m,a = gets.chomp.split.map(&:to_i)
    break if (n|m|a) == 0
    amida = Amida.new(n)
    m.times do
      h,p,q = gets.chomp.split.map(&:to_i)
      amida.set_hline(h, p, q)
    end
    amida.solve(a)
  end
end

main

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

long long d, n;

long long int lpow(long long int x, long long int y)
{
    long long int res = 1;
    for (int i = 0; i < y; i++)
    {
        res *= x;
    }
    return res;
}

int main(){
    cin >> d >> n;
    if(n == 100) n++;
    cout << lpow(100, d) * n << endl;
    return 0;
}

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

bool ok(vector<bool> check) {
  int temp=n;
  if(check[temp%10]) {
    n++;
    return false;
  }
  while(temp/10) {
    temp/=10;
    if(check[temp%10]) {
      n++;
      return false;
    }
  }
  return true;
}

int main() {
  int k;
  cin >> n >> k;
  vector<bool> check(10,false);
  for(int i=0;i<k;i++) {
    int temp;
    cin >> temp;
    check[temp]=true;
  }
  while(!ok(check)){}
  cout << n << endl;
}

Measured memory_bytes: 256