akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,k;cin >> n >> m >> k;
    vector<ll> a(n),b(m),sa(n+1),sb(m+1);
    REP(i,n){
        cin >> a[i];
        sa[i+1]=sa[i]+a[i];
    }
    REP(i,m){
        cin >> b[i];
        sb[i+1]=sb[i]+b[i];
    }
    ll ans=0;
    REP(i,n+1){
        if(sa[i]>k){
            continue;
        }
        ll u=upper_bound(ALL(sb),k-sa[i])-sb.begin();
        chmax(ans,i+u-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9496
#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5;
int a[N],b[N],c[N],d[N],fa[N],sz[N],vis[N];
inline int find(ri x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main(){
	ri n,m,i,sa,sb,edge,cnt,x,y;
	gi(n);
	sa=0;
	for(i=1;i<=n;++i) gi(a[i]),sa^=a[i],c[i]=a[i];
	c[n+1]=sa;
	sb=0;
	for(i=1;i<=n;++i) gi(b[i]),sb^=b[i],d[i]=b[i];
	d[n+1]=sb;
	sort(c+1,c+1+n+1);
	sort(d+1,d+1+n+1);
//	for(i=1;i<=n+1;++i) printf("%d ",c[i]); puts("");
//	for(i=1;i<=n+1;++i) printf("%d ",d[i]); puts("");
	for(i=1;i<=n+1;++i)
		if(c[i]!=d[i])
			return puts("-1"),0;
	a[n+1]=sa;
	b[n+1]=sb;
	m=unique(c+1,c+1+n+1)-c-1;
	for(i=1;i<=n+1;++i)
		a[i]=lower_bound(c+1,c+1+m,a[i])-c,
		b[i]=lower_bound(c+1,c+1+m,b[i])-c;
//	for(i=1;i<=n+1;++i) printf("%d ",a[i]); puts("");
//	for(i=1;i<=n+1;++i) printf("%d ",b[i]); puts("");
	for(i=1;i<=m;++i) fa[i]=i,sz[i]=1,d[i]=0;
	edge=0;
	for(i=1;i<=n;++i)
		if(a[i]!=b[i]){
			++edge;
			x=find(a[i]);
			y=find(b[i]);
			if(x==y) continue;
			if(d[x]<d[y]) swap(x,y);
			if(d[x]==d[y]) ++d[x];
			fa[y]=x;
			sz[x]+=sz[y];
		}
	cnt=0;
	for(i=1;i<=n+1;++i){
		x=find(a[i]);
		if(!vis[x]){
			vis[x]=1;
			if(sz[x]>1)
				++cnt;
		}
	}
	cnt+=sz[find(a[n+1])]==1;
//	printf("edge = %d cnt = %d\n",edge,cnt);
	printf("%d\n",edge+cnt-1);
	return 0;
}

Measured memory_bytes: 6656
H,W = map(int,input().split())
s = [input() for i in range(H)]
dx=[0,-1,1,0]
dy=[1,0,0,-1]
flag = True
for i in range(H):
    for j in range(W):
        if s[i][j]=='#':
            cnt = 0
            for k in range(4):
                if 0<=j+dx[k] and j+dx[k]<W and 0<=i+dy[k] and i+dy[k]<H:
                    if s[i+dy[k]][j+dx[k]]=='#':
                        cnt += 1
            if cnt==0:
                flag=False
print('Yes' if flag else 'No')


Measured memory_bytes: 40944
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define P pair<ll, ll>
using ll = int64_t;
using namespace std;
#define ketasuu(n) fixed << setprecision(n)
#define btoe(p) p.begin(), p.end()
#define etob(p) p.rbegin(), p.rend()

//define gcd and lcm (using 64bit)
ll gcd(ll a, ll b)
{
    if (a < b)
    {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

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

int main(){
    ll n, m;
    cin >> n >> m;
    bool ok=true;
    vector<ll> p(n);
    ll l=1;
    rep(i,n) cin>>p[i];
    rep(i,n){
        if(p[i]%2==1){
            cout<<0<<endl;
            return 0;
        }
    }
    rep(i,n){
        p[i]/=2;
        l=lcm(l,p[i]);
        if(l>m){
            ok=false;
            l=1;
        }
    }
    rep(i,n){
        if((l/p[i])%2==0) ok=false;
    }
    if(!ok){
        cout<<0<<endl;
        return 0;
    }
    ll ans=(m+l)/(2*l);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
from math import ceil
n = int(input())
a = list(map(int, input().split()))
a.reverse()
b = [0] * n
for i in range(n):
    if i % 2 == 0:
        b[i//2] = a[i]
    else:
        b[-(ceil(i/2))] = a[i]

#print(b)
for i in range(n):
    print(b[i])


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

int main() {
  int n,count=0;
  cin >> n;
  
  vector<int> data(n);
  
  for(int i =0;i<n;i++){
    cin >> data.at(i);
  }
  
  for(int i=0;i<n;i+=2){
    if(data.at(i)%2 == 1){
      count++;
    }
  }
  cout << count << endl;
  
  return 0;
    
  
  
}

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

int main(){
	int N, M;
	char A[50][50], B[50][50];
	int count;
	
	cin >> N >> M;
	for(int j=0; j<N; ++j)
		for(int i=0; i<N; ++i)
			cin >> A[j][i];
	for(int j=0; j<M; ++j)
		for(int i=0; i<M; ++i)
			cin >> B[j][i];
	
	for(int j=0; j+M<=N; ++j){
		for(int i=0; i+M<=N; ++i){
			count = 0;
			
			for(int y=0; y<M; ++y){
				for(int x=0; x<M; ++x){
					if(A[j+y][i+x] == B[y][x]) ++count;
				}
			}
			if(count == (M*M)){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int d[6], n, i, j, blank, ue, mae;
	for (i = 0; i < 6; i++) {
		scanf("%d", &d[i]);
	}

	scanf("%d", &n);

	for (j = 0; j < n; j++) {
		scanf("%d %d", &ue, &mae);
		for (i = 0; d[1] != mae && i < 3; i++) {
			//3S
			blank = d[0];
			d[0] = d[4];
			d[4] = d[5];
			d[5] = d[1];
			d[1] = blank;
		}

		if (d[1] != mae) {
			//1E
			blank = d[0];
			d[0] = d[3];
			d[3] = d[5];
			d[5] = d[2];
			d[2] = blank;
			for (i = 0; d[1] != mae; i++) {
				//3S
				blank = d[0];
				d[0] = d[4];
				d[4] = d[5];
				d[5] = d[1];
				d[1] = blank;
			}
		}

		for (i = 0; d[0] != ue; i++) {
			//3E
			blank = d[0];
			d[0] = d[3];
			d[3] = d[5];
			d[5] = d[2];
			d[2] = blank;
		}

		printf("%d\n", d[2]);
	}
	return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int x;
    cin >> x;
    while(1){
        if(IsPrime(x)==true){
            cout << x <<endl;
            return 0;
        }
        x++;
    }
    return 0;
}

Measured memory_bytes: 256
def getval():
    n = int(input())
    x = [list(map(int,input().split())) for i in range(n)]
    return n,x

def main(n,x):
    x.sort()
    xmax = [0,x[0][1]+x[0][0]]
    xmin = [0,x[0][1]+x[0][0]]
    for i in range(1,n):
        idx = x[i]
        s = idx[1]+idx[0]
        if s>xmax[1]:
            xmax = [i,s]
        elif s<xmin[1]:
            xmin = [i,s]
    m1 = abs(x[xmax[0]][0]-x[xmin[0]][0])+abs(x[xmax[0]][1]-x[xmin[0]][1])
    ymax = [0,x[0][1]-x[0][0]]
    ymin = [0,x[0][1]-x[0][0]]
    for i in range(1,n):
        idx = x[i]
        s = idx[1]-idx[0]
        if s>ymax[1]:
            ymax = [i,s]
        elif s<ymin[1]:
            ymin = [i,s]
    m2 = abs(x[ymax[0]][0]-x[ymin[0]][0])+abs(x[ymax[0]][1]-x[ymin[0]][1])
    print(max(m1,m2))
    

if __name__=="__main__":
    n,x = getval()
    main(n,x)

Measured memory_bytes: 103956
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	string s;
	cin >> n >> s;
	string t(s,n/2);
	cout << (t + t == s ? "Yes\n" : "No\n");
	return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] NX = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int N = NX[0];
            int X = NX[1];
            int[] XX = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            List<int> iList = new List<int>();
            List<int> jList = new List<int>();
            for(int i = 0; i < N; i++)
            {
                int A = Math.Abs(X - XX[i]);
                iList.Add(A);
            }
            if (iList.Count == 1)
            {
                Console.WriteLine(iList[0]);
                return;
            }
            for (int j = 0; j < iList.Count -1; j++)
            {
                jList.Add(Gcd(iList[j], iList[j + 1]));
            }
            Console.WriteLine(jList.Min());

        }
        public static int Gcd(int a, int b)
        {
            var x = 0;
            while (true)
            {
                // 割り切れたら
                if (a % b == 0)
                {
                    return b;
                }
                else
                {
                    x = a % b;
                    a = b;
                    b = x;
                }
            }
        }
    }
}

Measured memory_bytes: 23776
#include <iostream>

using namespace std;

int main(void)
{
  int N, L;
  int sum = 0;
  cin >> N >> L;

  if(L >= 0){
    for(int i = 2; i <= N; i++)
      sum += (L+i-1);
  }
  else if((L+N-1) > 0){
    for(int i = 1; i <= N; i++)
      if((L+i-1) != 0)
        sum += (L+i-1);
    }
  else{
    for(int i = 1; i < N; i++)
      sum += (L+i-1);
    }
    
  cout << sum;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<int> even, odd, a;
    i64 maxi = 0, es = 0, os = 0;
    for (int i = 0; i < n; i++) {
        i64 in;
        std::cin >> in;
        a.push_back(in);
        if (a[maxi] < a[i]) maxi = i;
        if (in <= 0) continue;
        if (i % 2) { os += in; odd.push_back(i + 1); }
        else { es += in; even.push_back(i + 1); }
    }

    if (a[maxi] <= 0) {
        printf("%d\n%d\n", a[maxi], n - 1);
        for (int i = n; i > maxi + 1; i--) printf("%d\n", i);
        for (int i = 0; i < maxi; i++) printf("%d\n", 1);
        return 0;
    }

    std::deque<int> r;
    auto &q = es > os ? even : odd;

    std::reverse(q.begin(), q.end());
    for (int i = n; i > q.front(); i--) r.push_back(i);
    for (int i = 0; i < q.size() - 1; i++) {
        for (int j = 0; j < (q[i] - q[i + 1]) / 2; j++) r.push_back((q[i] + q[i + 1]) / 2 - j);
    }
    for (int i = 1; i < q.back(); i++) r.push_back(1);

    printf("%lld\n%ld\n", std::max(es, os), r.size());
    for (int i : r) printf("%d\n", i);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
int R, C;
int sy, sx, gy, gx;
char maze[50][50];
int dis[50][50];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

/*int bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (int i = 0; i < 4; i++) {
			int ny = p.first + dy[i];
			int nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] != '#' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}*/

int main() {
	cin >> n >> m;
	vector<pair<ll, string>> v(m);
	vector<ll> flg(n);
	vector<ll> wa(n);
	ll ac = 0;
	ll wan = 0;
	rep(i, n) {
		flg[i] = false;
	}
	rep(i, m) {
		cin >> v[i].first >> v[i].second;
	}
	rep(i, m) {
		if (!flg[v[i].first-1]) {//正解していない
			if (v[i].second == "WA") {
				wa[v[i].first-1]++;
			}
			else if (v[i].second == "AC") {
				ac++;
				wan += wa[v[i].first-1];
				flg[v[i].first - 1] = true;
			}
		}
	}
	cout << ac << " " << wan << endl;
}



Measured memory_bytes: 8064
#include <iostream>
using namespace std;
int a[200005],n;
bool b[200005];
inline bool pd(int x)
{
	for(int i=1;i<=n*2-1;i++)
	{
		if(a[i]>=x)
			b[i]=1;
		else
			b[i]=0;
	}
	b[0]=b[1];
	if(b[n]==b[n+1]||b[n]==b[n-1])
		return b[n];
	for(int i=n+1;i<=n+n-1;i++)
	{
		if(b[i]==b[i+1])
			return b[i];
		if(b[n+n-i]==b[n+n-i-1])
			return b[n+n-i];
	}
	return b[1];
}
int main(int argc, char** argv) {
	cin >> n;
	for(int i=1;i<=n*2-1;i++)
		cin >> a[i];
	int l=1,r=n*2,ans=0;
	while(l<=r)
	{
		int md=(l+r)/2;
		if(pd(md))
		{
			l=md+1;
			ans=max(ans,md);
		}
		else
			r=md-1;
	}
	cout << ans << endl;
	return 0;
}

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

void wa() { 
    cout << "WA\n"; 
    exit(0);
}

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

    if(!(s[0] == 'A')) wa();
    auto cnt = 0;
    auto index = 0;
    for(int i = 2; i < s.length() - 1; ++i){
        cnt += s[i]== 'C';
        if(s[i] == 'C') {
            index = i;
        }
    }
    if(cnt != 1) wa();
    for(int i = 0; i < s.length(); ++i){
        if(i  == 0 || i == index) continue;
        if(!('a' <= s[i] && s[i] <= 'z')) wa();
    }

    cout << "AC\n";
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    f = [1]
    N = 1000000
    for i in range(1,N+1):
        f.append(f[-1]*i%mod)
    inv = [None]*(N+1)
    inv[N] = pow(f[N],mod-2,mod)
    for i in range(N)[::-1]:
        inv[i] = inv[i+1]*(i+1)%mod
    def comb(a,b):
        return f[a]*inv[b]*inv[a-b]%mod
    h,w,a,b = LI()
    ans = 0
    y = h-a
    x = b+1
    while x <= w and y:
        ans += comb(x+y-2,x-1)*comb(h-y+w-x,w-x)%mod
        y -= 1
        x += 1
    print(ans%mod)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 115568
import java.util.Scanner;

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

		int[][] A = new int[3][10];
		for(int i = 0; i < 3; i++)
			for(int j = 0; j < 10; j++)
				A[i][j] = 0;
		
		int[][] B = new int[3][10];
		for(int i = 0; i < 3; i++)
			for(int j = 0; j < 10; j++)
				B[i][j] = 0;
		
		int[][] C = new int[3][10];
		for(int i = 0; i < 3; i++)
			for(int j = 0; j < 10; j++)
				C[i][j] = 0;
		
		int[][] D = new int[3][10];
		for(int i = 0; i < 3; i++)
			for(int j = 0; j < 10; j++)
				D[i][j] = 0;

		int n = sc.nextInt();

		String[][] N = new String[n][2];
		for (int i = 0; i < n; i++) {
			int b = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			int v = sc.nextInt();
			
			f--;
			r--;
			
			if(b == 1)
				A[f][r] = A[f][r] + v;
			else if(b == 2)
				B[f][r] = B[f][r] + v;
			else if(b == 3)
				C[f][r] = C[f][r] + v;
			else
				D[f][r] = D[f][r] + v;
		}

		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 10; j++) 
				System.out.printf(" %d", A[i][j]);
			System.out.println();
		}
		System.out.println("####################");
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 10; j++) 
				System.out.printf(" %d", B[i][j]);
			System.out.println();
		}
		System.out.println("####################");
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 10; j++) 
				System.out.printf(" %d", C[i][j]);
			System.out.println();
		}
		System.out.println("####################");
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 10; j++) 
				System.out.printf(" %d", D[i][j]);
			System.out.println();
		}
	}
}	


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

int getDigit(int i)
{
    int ans = 0;

    while(i != 0)
    {
        i /= 10;
        ++ans;
    }
    return ans;
}

int main(void)
{
    int N, K;

    cin >> N >> K;

    vector<int> D(K, 0);
    for(int i = 0; i < K; ++i)
    {
        cin >> D[i];
    }
    std::sort(D.begin(), D.end());

    int s;
    for(s = N; ; ++s)
    {
        int st = s;
        bool ok = true;
        for(int i = 0; st != 0; ++i)
        {
            if(std::binary_search(D.begin(), D.end(), st%10))
            {
                ok = false;
                break;
            } 
            st /= 10;
        }
        if(ok) break;
    }


    cout << s << endl;

    return 0;
}



Measured memory_bytes: 3588
#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;

const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int c[12];
int a[12][12];

int main(){
	int n,m,x;cin>>n>>m>>x;
	rep(i,n){
		scanf("%d",&c[i]);
		rep(j,m)scanf("%d",&a[i][j]);
	}
	int Min=INT_MAX;
	rep(i,1<<n){
		int cnt[12]{};
		int sum=0;
		rep(j,n){
			if(i>>j&1){
				sum+=c[j];
				rep(k,m)cnt[k]+=a[j][k];
			}
		}
		bool ok=true;
		rep(j,m){
			if(cnt[j]<x)ok=false;
		}
		if(ok)Min=min(Min,sum);
	}
	if(Min==INT_MAX)puts("-1");
	else cout<<Min<<endl;
}

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

int main() {
	// your code goes here
	int n;cin >> n;
	vector<vector<int>> arr(n,vector<int>(3,0));
	
	for(int i = 0;i<n;i++){
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
	}
	int dp0 = arr[n-1][0],dp1 = arr[n-1][1],dp2 = arr[n-1][2];
	for(int i = n-2;i>=0;i--){
		int t0 = arr[i][0]+max(dp1,dp2);
		int t1 = arr[i][1]+max(dp0,dp2);
		int t2 = arr[i][2]+max(dp0,dp1);
		
		dp0 = t0;
		dp1 = t1;
		dp2 = t2;
	}
	cout << max(dp0,max(dp1,dp2)) << endl;
	return 0;
}

Measured memory_bytes: 5760
from collections import deque

def cal():
    h, w = map(int, input().split())
    q = deque()
    counts = [[True for _ in range(w+2)]]+[[True]+[False]*w+[True] for _ in range(h)]+[[True for _ in range(w+2)]]
    for i in range(h):
        a = input()
        for j in range(w):
            if a[j] == '#':
                q.append([i+1, j+1, 0])
                counts[i+1][j+1] = True

    while q:
        x, y, z = q.popleft()    
        if not counts[x+1][y]:
            counts[x+1][y] = True
            q.append([x+1, y, z+1])
        if not counts[x-1][y]:
            counts[x-1][y] = True
            q.append([x-1, y, z+1])
        if not counts[x][y+1]:
            counts[x][y+1] = True
            q.append([x, y+1, z+1])
        if not counts[x][y-1]:
            counts[x][y-1] = True
            q.append([x, y-1, z+1])
    print(z)
    

cal()


Measured memory_bytes: 168532
#include <stdio.h>

int main()
{
    int n, flag;
    while(scanf("%d", &n) == 1)
    {
        flag = 0;
        while(n > 0)
        {
            int m = n % 10;
            if(m == 9)
            {
                flag = 1;
                break;
            }
            n /= 10;
        }
        printf("%s\n", flag == 1? "Yes":"No");
    }
    return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    C = [[0 for i in range(3)] for j in range(N+1)]
    for i in range(N-1,-1,-1):
        if S[i] == "R":
            C[i][0] = C[i+1][0]+1
            C[i][1] = C[i+1][1]
            C[i][2] = C[i + 1][2]
        elif S[i] == "G":
            C[i][0] = C[i + 1][0]
            C[i][1] = C[i + 1][1]+1
            C[i][2] = C[i + 1][2]
        else:
            C[i][0] = C[i + 1][0]
            C[i][1] = C[i + 1][1]
            C[i][2] = C[i + 1][2]+1
    sum = 0
    # print(S)
    for i in range(N):
        for j in range(i+1,N-1):
            if S[i] == S[j]:
                continue
            k = j - i + j
            # 残りがRである場合
            if S[i] != "R" and S[j] != "R":
                sum += C[j+1][0]
                if k < N and S[k] == "R":
                    sum -=1
                # print(f"GB:{i},{j},Rp:{C[j + 1][0]}")
            if S[i] != "G" and S[j] != "G":
                sum += C[j + 1][1]
                if k < N and S[k] == "G":
                    sum -= 1
                # print(f"RB:{i},{j},Gp:{C[j + 1][1]}")
            if S[i] != "B" and S[j] != "B":
                sum += C[j + 1][2]
                if k < N and S[k] == "B":
                    sum -= 1
                # print(f"RG:{i},{j},RB:{C[j + 1][2]}")
    print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 69584
//package Uniquenumber;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		boolean flag;
		int N = sc.nextInt();
		int[] point = new int[N];
		int[][] num = new int[N][3]; 
		for(int i = 0; i < N; i++) {
			num[i][0] = sc.nextInt();
			num[i][1] = sc.nextInt(); 
			num[i][2] = sc.nextInt();
		}
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < N; j++) {
				flag = true;
				for(int k = 0; k < N; k++) {
					if(num[j][i] == num[k][i] && j != k) flag = false;
				}
				if(flag) point[j] += num[j][i];
			}
		}
		for(int i = 0; i < N; i++) System.out.println(point[i]);
	}

}

Measured memory_bytes: 20848
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define All(v) (v).begin(),(v).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;

deque<char> a, b, c;
map<char, deque<char>> X;

char dfs(char x)
{
    if(X[x].size()==0){
        cout << char(x - 'a' + 'A') << endl;
        return 0;
    }
    char y = X[x].front();
    X[x].pop_front();
    dfs(y);
}

int main(){
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    rep(i, sa.length()) a.push_back(sa[i]);
    rep(i, sb.length()) b.push_back(sb[i]);
    rep(i, sc.length()) c.push_back(sc[i]);
    X.insert(make_pair('a', a));
    X.insert(make_pair('b', b));
    X.insert(make_pair('c', c));
    dfs('a');
}

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

int	main() {
	int H, W;
	cin >>H >>W;
	vector<int> C(26, 0);
	for (int i=0; i<H*W; i++) {
		char c;
		cin >>c;
		C.at(c-'a')++;
	}
	int HW=(H/2)*(W/2);
	for (int i=0; i<26; i++) {
		int a=min(HW, C.at(i)/4);
		HW -=a;
		C.at(i) -=a*4;
	}
	if (0!=HW) {
		cout <<"No" <<endl;
		return 0;
	}
	HW=(H%2)*(W/2)+(W%2)*(H/2);
	for (int i=0; i<26; i++) {
		int a=min(HW, C.at(i)/2);
		HW -=a;
		C.at(i) -=a*2;
	}
	if (0!=HW) {
		cout <<"No" <<endl;
		return 0;
	}
	cout <<"Yes" <<endl;
	return 0;
};


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <deque>
#include <stack>
using namespace std;
const int N=1e5+10;
int a[N];
int main()
{

   int a,b,c;
   int ans;
   scanf("%d %d %d",&a,&b,&c);
   if(a>b)
   {
       printf("0\n");
   }
   else
   {
       ans=b/a;
       if(ans>=c)
       {
           printf("%d\n",c);
       }
       else
        printf("%d\n",ans);
   }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int A,B;
    cin >> A >> B;
    int t = 1;
    int ans = 0;
    while(t < B){
        t += A - 1;
        ans ++;
    }
    pr(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> p2;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin>>s;
  if(s=="AAA"||s=="BBB")
     cout<<"No";
     else
     cout<<"Yes";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
using ulong = unsigned long;
using ll = long long;
const int M = 1e9 + 7;
#pragma unused(M)

int main(){
	string s;
	cin >> s;
	int idx = 0;
	while(idx < s.size() && s[idx] != 'C') idx++;
	while(idx < s.size() && s[idx] != 'F') idx++;
	cout << (idx == s.size() ? "No" : "Yes") << endl;
	return 0;
}



Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N, M;
	cin >> N;
	vector<long long> D( N );
	for( int i = 0; i < N; i++ ) {
		cin >> D[i];
	}
	cin >> M;
	vector<long long> T( M );
	for( int i = 0; i < M; i++ ) {
		cin >> T[i];
	}

	sort( D.begin(), D.end() );
	sort( T.begin(), T.end() );
	string ans = "YES";
	int j = 0;
	for( int i = 0; i < M; i++ ) {
		int flag = 0;
		while( j < N ) {
			if( D[j] == T[i] ) {
				flag = 1;
				j++;
				break;
			}
			if( D[j] > T[i] ) break;
			j++;
		}
		if( flag == 0 ) {
			ans = "NO";
			break;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 6392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }


int main() {
    int input;
    cin >> input;
    FOR(i,1,1000){
      if(i*100 <= input && i*105 >= input){
        cout << 1 << endl;
        return 0;
      }
    }

    cout << 0 << endl;
    return 0;


}



Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int ans = 0;
        for (int i = 0; i < 2; i++) {
            ans += Math.max(a,b);
            if (a == ans ) {
                a -= 1;
            } else {
                b -= 1;
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 21844
import bisect

N, M, K = map(int, input().split())
Alist = [0] + list(map(int, input().split()))
Blist = list(map(int, input().split()))

B = [Blist[0]]
for b in Blist[1:]:
    B.append(b + B[-1])


sums = 0
ans = 0
for idx, a in enumerate(Alist):
    sums += a
    if sums > K:
        break
    k = K - sums
    tmp = bisect.bisect_right(B, k)
    ans = max(ans, idx + tmp)

print(ans)

Measured memory_bytes: 40028
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
//const int MAX=;


void input(){
	string S;
	cin>>S;
	int l = sz(S);
	int ans = 0;
	rep(i, l/2){
		if(S[i]!=S[l-1-i])ans++;
	}
	cout<<ans;
}

void solve(){

}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >> N;
  vector<int> hito(110);
  for(int i = 0; i < N; i++){
   cin >> hito[i]; 
  }

  int ans = 10000000;
  for(int i = 1; i < 101; i++){
    int cost = 0;
   for(int j = 0; j < N; j++){
     cost += (hito[j] - i) * (hito[j] - i);
   }
    ans = min(ans, cost);
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  int n; cin>>n;
  vector<vector<bool>> f(n,vector<bool>(10,0));
  vector<vector<int>> p(n,vector<int>(11,0));
  rep(i,n){
    rep(j,10){
      int F; cin>>F;
      if(F==1) f[i][j]=1;
    }
  }
  rep(i,n){
    rep(j,11) cin>>p[i][j];
  }

  int ans=-INF;
  for(int bit=1;bit<(1<<10);bit++){
    int sum=0;
    rep(i,n){
      int c=0;
      rep(j,10){
        if(f[i][j]&&((bit&(1<<j))!=0)) c++;
      }
      sum+=p[i][c];
    }
    ans=max(sum,ans);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n), n)+[X%n]
  return [X%n]


#############
# Main Code #
#############

H,W = inputIL()
data = []
for _ in range(H):
  s = inputS()
  if s != "."*W:
    data.append(s)

memo = []
for i in range(W):
  flag = 1
  for j in range(len(data)):
    if data[j][i] == "#":
      flag = 0
  if flag == 0:
    memo.append(i)
    
ans = [[data[j][i] for i in memo] for j in range(len(data))]

for i in range(len(ans)):
  print(*ans[i],sep="")


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

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

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

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


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

  rep(i, N+1) {
    if (i * (i + 1) / 2 == N) {
      cout << "Yes" << endl;
      vector<vector<int>> S(i + 5);
      int Ncount = 0;
      int Scount = 0;
      for (int j = i; j > 0; j--) {
        rep(k, j) {
          S[Scount].pb(Ncount);
          S[Scount + k + 1].pb(Ncount);
          Ncount++;
        }
        Scount++;
      }
      cout << i+1 << endl;
      rep(j, i + 1) {
        cout << i;
        rep(k, i) { cout << " " << S[j][k] + 1; }
        cout << endl;
      }
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 2304
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,M = MI()
S = [0] + LI()
T = [0] + LI()
mod = 10**9+7

dp = [[0]*(M+1) for _ in range(N+1)]
# dp[i][j] = S[:i+1] と T[:j+1] に対する答え

for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i] == T[j]:
            dp[i][j] = dp[i-1][j]+dp[i][j-1]+1
        else:
            dp[i][j] = dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]
        dp[i][j] %= mod

print(dp[N][M]+1)  # 空列を追加


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

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

    int m = 0;
    for(int i = n-1; i >= 0; --i) {
        int sum = 0;
        for(int j = n/(i+1); j >= 1; --j) {
            if(j == 1) {
                b[i] = (sum%2 != a[i])?1:0;
                m += b[i];
            } else {
                sum += b[(i+1)*j-1];
            }
        }
    }

    cout << m << '\n';
    for(int i = 0; i < n; ++i) {
        if(b[i] == 1) cout << i+1 << ' ';
    }
    cout << '\n';

    return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main(){
	int m,k;
	scanf("%d%d",&m,&k);
	if(k==0){
		for(int i=0;i<(1<<m);i++)
			printf("%d %d ",i,i);
		printf("\n");
	}
	else if(m==1){
		if(k>=1)
			puts("-1");
		else puts("1 1 0 0");
	}
	else{
		if(k>=(1<<m))
			puts("-1");
		else{
			printf("%d ",k);
			for(int i=0;i<(1<<m);i++)
				if(i!=k)
				printf("%d ",i);
			printf("%d ",k);
			for(int i=(1<<m)-1;i>=0;i--)
				if(i!=k)
				printf("%d ",i);
		}
	}	
} 

Measured memory_bytes: 1792
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

ans = 0

for i in range(n):
    ans1 = 0
    ans2 = 0
    ok = -1
    ng = n
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        if a[mid] < b[i] :
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans1 += ok + 1
    ok = n
    ng = -1
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        if b[i] < c[mid]:
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans2 += n - ok
    ans += ans1 * ans2
print(ans)

Measured memory_bytes: 107108
#include <stdio.h>

int main() {
  int n, x, i,  cnt = 0;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    if (isPrime(x)) {
      cnt++;
    }
  }
  printf("%d\n", cnt);

  return 0;
}

int isPrime(int x) {
  int i;

  if (x == 2) {
    return 1;
  } else if (x < 2 || x % 2 == 0) {
    return 0;
  }

  for (i = 3; i * i <= x; i += 2) {
    if (x % i == 0) {
      return 0;
    }
  }

  return 1;
}



Measured memory_bytes: 1964
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    map <ll, ll> as;
    ll tot = 0;
    REP(i, n){
        ll a; cin >> a;
        as[a]++;
        tot += a;
    }
    ll q; cin >> q;
    REP(_, q){
        ll b; cin >> b;
        ll c; cin >> c;
        ll num = as[b];
        as[b] = 0;
        as[c] += num;
        ll diff = (c-b)*num;
        tot += diff;
        cout << tot << endl;
    }
    return 0;
}

Measured memory_bytes: 9484
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    ll h ,w;
    cin >> h >> w;

    ll ans = 0;
    if (h == 1 || w == 1){
        ans = 1;
    } else {
        ans  = w * (h/2);
        if (h % 2 == 1) ans += (w+1) / 2;
    }

    cout << ans << '\n';

    return 0;
}

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

bool checkAndPop(stack<char>& stk, char c) {
  if (stk.empty()) return false; 
  if ( (c == ')') && (stk.top() != '(') ) return false;
  if ( (c == ']') && (stk.top() != '[') ) return false;

  stk.pop();
  return true;
}

bool solve(const std::string& s) {
  stack<char> stk;
  for (auto c : s) {
    switch (c) {
    case '(':
    case '[':
      stk.push(c);
      break;
      
    case ')':
    case ']':
      if (!checkAndPop(stk, c)) return false;
      break;
    }
  }
  return stk.empty();
}

int main() {
  string s;
  while(getline(cin, s), s.size() > 1) {
    if (solve(s)) cout << "yes" << endl;
    else          cout << "no"  << endl;
  }
  return 0;
}


Measured memory_bytes: 3124
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			int n = sc.nextInt();
			for(int k=0;k<n;k++){
				String s = sc.next();
				int[] num = new int[8];

				for(int i=0;i<8;i++){
					num[i] = Integer.valueOf(s.substring(i,i+1));
				}
				Arrays.sort(num);
				int a = 0;
				int b = 0;
				int c = 1;
				for(int i=0;i<8;i++){
					a += num[i]*c;
					b += num[7-i]*c;
					c *= 10;
				}
				System.out.println(a-b);
				
			}
		}
	
	}	
}

Measured memory_bytes: 17176
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 1 << 30;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll k;cin >> k;
    ll num = 7;
    ll cnt = 1;
    repp(i,1,1e6+10){
        if(num%k == 0){
            cout << i << "\n";
            return 0;
        }
        num = num*10 + 7;
        num %= k;
    }
    cout << -1 << "\n";
    return 0;
}

Measured memory_bytes: 3660