akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

const int N=100005;
const int P=998244353;
const long long INFll=0x3f3f3f3f3f3f3f3fll;

int n,m;
int a[N],b[N],c[N],id[N];
int top=-1;
int p[N],fa[N];
long long f[N],size[N];

vector<int> son[N];

struct edge{
	int u,v;
	inline edge(){}
	inline edge(int _u,int _v){
		u=_u;
		v=_v;
		if(c[u]<c[v]) swap(u,v);
	}
	inline bool operator<(const edge &w)const{
		if(c[u]==c[w.u]) return c[v]>c[w.v];
		return c[u]<c[w.u];
	}
}d[N];

int find(int x){
	if(p[x]==0) return x;
	return p[x]=find(p[x]);
}

inline void onion(int x,int y){
	x=find(x),y=find(y);
	if(x==y) return ;
	p[y]=x;
	fa[y]=x;
}

inline bool cmp(int x,int y){
	return c[x]<c[y];
}

#define min(x,y) ((x<y)?x:y)
#define max(x,y) ((x>y)?x:y)

void init(){
	int x1,x2;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]),c[i]=max(a[i]-b[i],0),id[i]=i;
	sort(id+1,id+n+1,cmp);
	for(int i=1;i<=n;i++) c[id[i]]=i;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x1,&x2);
		d[i]=edge(x1,x2);
	}
	//printf("id : ");	for(int i=1;i<=n;i++) printf("%d ",id[i]); printf("\n");
	sort(d+1,d+m+1);
	for(int i=1,j=0;i<=n;i++){
		//int u=id[i];
		while(c[d[j+1].u]==i && j<=m){
			j++;
			onion(d[j].u,d[j].v);
			//printf("edge: %d %d\n",d[j].u,d[j].v);
		}
	}
	for(int i=1;i<=n;i++) c[i]=max(a[i]-b[i],0);
	for(int i=1;i<=n;i++) son[fa[i]].push_back(i);
	for(int i=1;i<=n;i++){
		int u=id[i],len=son[u].size();
		if(len==0) f[u]=c[u]+b[u],size[u]=b[u];
		else{
			f[u]=INFll;
			size[u]=b[u];
			for(int j=0;j<len;j++) size[u]+=size[son[u][j]];
			for(int j=0;j<len;j++){
				int v=son[u][j];
				f[u]=min(f[u],size[u]-size[v]+max(c[u],f[v]));
			}
		}
	}
	/*
	printf("a : ");		for(int i=1;i<=n;i++) printf("%d ",a[i]); printf("\n");
	printf("b : ");		for(int i=1;i<=n;i++) printf("%d ",b[i]); printf("\n");
	printf("id : ");	for(int i=1;i<=n;i++) printf("%d ",id[i]); printf("\n");
	printf("fa : ");	for(int i=1;i<=n;i++) printf("%d ",fa[i]); printf("\n");
	printf("size : ");	for(int i=1;i<=n;i++) printf("%lld ",size[i]); printf("\n");
	printf("f : ");		for(int i=1;i<=n;i++) printf("%lld ",f[i]); printf("\n");
	*/
	printf("%lld\n",f[id[n]]);
}

int main(){
	init();
	return 0;
}

Measured memory_bytes: 9728
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	K := sc.nextInt()

	sum := 0
	for a := 1; a <= K; a++ {
		for b := 1; b <= K; b++ {
			ab := gcd(a, b)
			for c := 1; c <= K; c++ {
				sum += gcd(ab, c)
			}
		}
	}

	fmt.Println(sum)
	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
long long h[1000005]={0};
string Multiply(string x,string y){
	memset(h,0,sizeof(h));
	for(int i=x.size()-1;i>=0;i--){
		for(int j=y.size()-1;j>=0;j--){
			h[i+j]+=(int)((x[i]-'0')*(y[j]-'0'));
		}
	}
	int g=0;
	for(int i=x.size()+y.size()-2;i>=0;i--){
		int k=h[i]+g;
		h[i]=(h[i]+g)%10;
		g=k/10;
		h[i]+=48;
	}
	string ss;
	for(int i=0;i<x.size()+y.size()-1;i++){
		ss+=h[i];
	}
	if(g){
		ss=char(g+'0')+ss;
	}
	int j=0;
	while(ss[j]==48&&j<ss.size()-1){
		j++;
	}
	return ss.substr(j);
}
int main(){
	string s1,s2;
	cin>>s1>>s2;
	int n=0;
	for(int i=s2.size()-1;i>=0;i--){
		if(s2[i]=='0'){
			n++;
		}else{
			break;
		}
	}
	int k=0;
	for(int i=0;i<s2.size();i++){
		if(s2[i]=='.'){
			break;
		}
		k++;
	}
	s2=s2.substr(0,s2.size()-n);
	string kk=Multiply(s1,s2.substr(0,k)+s2.substr(k+1));
	if(kk.size()<=(s2.size()-k-1)){
		cout<<0<<endl;
		return 0;
	}
	cout<<kk.substr(0,kk.size()-(s2.size()-k-1))<<endl;
}


Measured memory_bytes: 11452
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX (1<<17)
vii g[MX];
int N,M,Y[MX],P[MX];
char O[MX][16];
int main(void){
    scanf("%d%d",&N,&M);
    F(M)scanf("%d%d",P+i,Y+i),g[P[i]-1].PB({Y[i],i});
    F(N){
        int I=1;
        sort(g[i].begin(),g[i].end());
        for(auto&h:g[i])sprintf(O[h.bb],"%06d%06d",i+1,I++);
    }
    F(M)puts(O[i]);
    return 0;
}


Measured memory_bytes: 10240
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;

int main(){
	string S;
	cin >> S;
	vector<int> A(4);
	for(int i=0;i<4;i++){
		A[i] = S[i] - '0';
	}
	int sum = A[0];
	int bit;

	for(bit=0;bit<8;bit++){
		for(int shift=0;shift<3;shift++){
			if(bit & (1<<shift)){
				sum += A[shift+1];
			}else{
				sum -= A[shift+1];
			}
		}
		if(sum == 7){
			break;
		}
		sum = A[0];
	}
	for(int i=0;i<3;i++){
		cout << A[i];
		if(bit & (1<<i)){
			cout << "+";
		}else{
			cout << "-";
		}
	}
	cout << A[3] << "=7" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << "/n"
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
	string s;
	cin >> s;
	reverse(s.begin(),s.end());
	string divide[4] = {"maerd","remaerd","esare","resare"};
	rep(i,s.size()){
		bool ok = false;
		rep(j,4){
			if(s.substr(i, divide[j].size()) == divide[j]){
				ok = true;
				i += divide[j].size() - 1;
			}
		}
		if(!ok){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 512
import collections as co

n, k = map(int,input().split())
a = list(map(int,input().split()))
cnt = co.Counter(a)
ans = 0
initial = len(cnt)
if initial <= k:
    print(0)
    exit()
else:
    cnt = sorted(cnt.values())
    for i in range(initial-k):
        ans += cnt[i]
    print(ans)

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


int main(){
  string S, T;
  cin >> S;
  cin >> T;
  int count = 0;
  for (int i = 0; i < 3; i++){
    if (S.at(i) == T.at(i)){
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int digit(int,long long);
void ABC060(int,int,int);
int main(){
	string o,e;
	cin>>o>>e;
	for(int i=0;i<o.size()+e.size();i++){
		if(i%2==0){
			cout<<o[i/2];
		}
		else{
			cout<<e[(i+1)/2-1];
		}
	}
	cout<<endl;
}
void ABC060(int a,int b,int c){
	
	for(int u=1;u<100;u++){
		if(a*u%b==c){
			cout<<"YES"<<endl;
			break;
			}
		else if(a*u%b==0){
			cout<<"NO"<<endl;
			break;
		}
	}
}
int digit(int n,long long dig){
	return n%(dig*10)/dig;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// const ll INF = 1e18;
// const ll MOD = 1e9+7;
//const double pi = 3.14159265358979;
using vl = vector<ll>;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()

ll N,M;

int Main() {
    cin >> N >> M;
    vl a(N);
    rep(i,N) cin >> a[i];
    
    rep(i,M) {
        N -= a[i];
    }
    
    if (N < 0) {
        cout << "-1" << endl;
    } else {
        cout << N << endl;
    }
    return 0;
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 11084
def lcm(x,y):
    return x*y//gcd(x,y)

def cnt(x):
    return B//x - A//x + (A%x==0)

from math import gcd

A, B, C, D = map(int, input().split())
l = lcm(C,D)

print((B-A+1)-cnt(C)-cnt(D)+cnt(l))

Measured memory_bytes: 61324
package main

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

func main() {
	n := getInt()
	ts := make([]int, n)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		ts[i] = getInt()
		as[i] = getInt()
	}

	T := 1
	A := 1

	for i := 0; i < n; i++ {
		t := ts[i]
		a := as[i]

		d := max((T+t-1)/t, (A+a-1)/a)
		T = d * t
		A = d * a
	}

	fmt.Println(T + A)
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

//vector<int> v = sieve_of_eratosthenes(p);
//for(auto &e: v) cout << e << endl;
vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes;
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i*i < n; ++i)
    if (primes[i])
      for (int j = i*i; j < n; j+=i)
        primes[j] = 0;
  return primes;
}

map<int, int> mp;

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

  ll n, p;
  cin >> n >> p;
  if(n == 1){ cout << p << endl; return 0; }
  ll lim = p;
  FOR(i,2,sqrt(lim)+1){
    while(p%i==0){
      p/=i;
      mp[i]++;
    }
  }
  //for(auto &e: mp) cout << e.first << " " << e.second << endl;

  ll ans = 1LL;
  for(auto &e: mp){
    ll num = e.second/n;
    REP(i, num){
      ans *= e.first;
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#-swank
(unless (member :child-sbcl *features*)
  (quit
	:unix-status
	(process-exit-code
	  (run-program *runtime-pathname*
				   `("--control-stack-size" "128MB"
					 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
					 "--eval" "(push :child-sbcl *features*)"
					 "--script" ,(namestring *load-pathname*))
				   :output t :error t :input t))))

(defparameter al (concatenate 'list "abcdefghijklmnopqrstuvwxyz"))

(let ((s (read-line)))
  (let ((a (append (mapcan (lambda (x)
								(unless (find x s)
								  (list x)))
						   al)
				   (list "None"))))
	(princ (car a))))


Measured memory_bytes: 11704
#include <stdio.h>

int main(void) {

	int h, w;

	while (1) {

		scanf("%d %d", &h, &w);
		if (h == 0 && w == 0) {
			break;
		}

		for (int h_i = 0; h_i < h; h_i++) {
			for (int w_i = 0; w_i < w; w_i++) {
				if (w_i == w - 1) {
					puts("#");
				}
				else if(h_i == 0 || h_i == h -1 || w_i == 0){
					printf("#");
				}
				else {
					printf(".");
				}
			}
		}

		puts("");
	}

	return 0;
}



Measured memory_bytes: 2028
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n;
cin>>n;
ll q;
ll a1=0;
ll o=0;
ll p=0;
for(ll i=0; i<n; i++){
cin>>q;
if(q%2==0){
p++;}
else if(q==1){
a1++;}
else{
o++;}}
ll ca=0;
ca=pow(3,n)-pow(2,p);
cout << ca << endl;}


Measured memory_bytes: 3948
#include<bits/stdc++.h>
using namespace std ; 
int max(int a,int b){
	if(a>b)return a;
	return b;
} 
int check(int a,int b,int c){
	if(a<b+c && b<a+c && c<a+b){
		return 1; 

	} 
	return 0;
}
int main(){
	int  n ; 
	cin>>n; 
	int ans=0;
	vector<int> v(n); 
	for(int i=0;i<n;i++){
		cin>>v[i];
	}  
	if(n<3){cout<<0;return 0;}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int x=j+1;x<n;x++){ 
				if(v[i]==v[j] || v[j]== v[x] || v[x]== v[i])continue ;
				ans+=check(v[i],v[j],v[x]);
			}
		}
	} 
	cout<<ans; 

}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define int int64_t

signed main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n,d,i,ans;
    cin>>n>>d;
    ans=0;

    for(int i=0;i<n;i++)    
    {
        int a,b;
        cin>>a>>b;

        int val=a*a + b*b;
        if(val <= d*d)
            ans++;
    }
    
    cout<<ans<<endl;
    

    return 0;
}




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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

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

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T){
    REP(i, S.size()) {
        bool check = true;
        REP(j, S.size()) {
            if(S[(i+j)%S.size()] != T[j]) {
                check = false;
                break;
            }
        }

        if(check) {
            cout << YES << endl;
            return;
        }
    }

    cout << NO << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}



Measured memory_bytes: 256
n = [int(i) for i in input().split() ]


rgb =  n[0:3]
rgb.sort(reverse=True)
#rgb = list(filter(lambda x:x >= n[3],rgb))

rm = int(n[3]/rgb[0] ) + 1
c = 0
for i in range(rm):
    if i * rgb[0] == n[3]:
            c += 1
            break
        
    for j in range(int((n[3] - i * rgb[0])/rgb[1]) + 1):
        

        if (n[3] - i * rgb[0] - j * rgb[1]) % rgb[2] == 0:
            c += 1

print (c)
    

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  unsigned long N;
  std::cin >> N;

  std::vector<long> x(N), y(N), h(N);
  for (unsigned long i = 0; i < N; i++) {
    std::cin >> x.at(i) >> y.at(i) >> h.at(i);
  }

  for (long cx = 0; cx <= 100; cx++) {
    for (long cy = 0; cy <= 100; cy++) {
      long H = -1;
      for (unsigned long i = 0; i < N; i++) {
        if (h.at(i) >= 1) {
          H = h.at(i) + std::abs(x.at(i) - cx) + std::abs(y.at(i) - cy);
          break;
        }
      }

      for (unsigned long i = 0; i < N; i++) {
        long h_ =
            std::max(0L, H - std::abs(x.at(i) - cx) - std::abs(y.at(i) - cy));
        if (h_ != h.at(i)) {
          H = -1;
        }
      }
      if (H > 0) {
        std::cout << cx << ' ' << cy << ' ' << H << std::endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

using int64 = long long;

constexpr int MOD = 1e9 + 7;

class Combination {
 public:
  constexpr Combination() {
    Build();
  }
  static constexpr int MOD = 1000000007;
  static constexpr int n_ = 2020;
  struct LookupTable {
    int64 factorial_[n_];
    int64 inverse_[n_];
    int64 finverse_[n_];
  };
  LookupTable lt {};
  constexpr int64 Get(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0) return 0;
    return lt.factorial_[n] * (lt.finverse_[k] * lt.finverse_[n - k] % MOD) % MOD;
  }
 private:
  constexpr void Build() noexcept {
    lt.factorial_[0] = 1; lt.factorial_[1] = 1;
    lt.finverse_[0] = 1; lt.finverse_[1] = 1;
    lt.inverse_[1] = 1;
    for (int i = 2; i < n_; ++i) {
      lt.factorial_[i] = lt.factorial_[i - 1] * i % MOD;
      lt.inverse_[i] = MOD - lt.inverse_[MOD % i] * (MOD / i) % MOD;
      lt.finverse_[i] = lt.finverse_[i - 1] * lt.inverse_[i] % MOD;
    }
  }
};

template<typename T> void fastin(T &num) {
  T c;
  num = 0;
  c = getchar_unlocked();
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
}

template<typename T> void fastout(T &n) {
  T N = n, rev, count = 0;
  rev = N;
  if (N == 0) {
    putchar_unlocked('0');
    putchar_unlocked('\n');
    return;
  }
  while ((rev % 10) == 0) { 
    ++count; rev /= 10;
  }
  rev = 0;
  while (N != 0) { 
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  }
  while (rev != 0) { 
    putchar_unlocked(rev % 10 + '0');
    rev /= 10;
  }
  while (count--) putchar_unlocked('0');
  putchar_unlocked('\n');
}

Combination com;

int main() {
  int n, k; fastin(n); fastin(k);
  for (int i = 1; i <= k; ++i) {
    int64 ans = 0;
    (ans += com.Get(n - k + 1, i) * com.Get(k - 1, i - 1)) %= MOD;
    fastout(ans);
  }

  return 0;
}


Measured memory_bytes: 128
// ABC081C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<algorithm>
using namespace std;
int main()
{
	int N, K;
	cin >> N >> K;

	int a[200001];
	for (int i = 1; i <= N; i++) cin >> a[i];
	//for (int i = 0; i < N; i++) cout << a[i] << endl;
	int count[200001] = {};
	
	for(int i=1;i<=N;i++)
	{
		count[a[i]]++;
	}

	//for (int i = 1; i <= N; i++) cout << count[i];
	sort(count+1, count + N+1, greater<int>());

	//for (int i = 1; i <= N; i++) cout << count[i];
	//for (int i = 0; i < N; i++) cout << a[i] << endl;
	
	int vari = 0;
	for (int i = 1; i <= N; i++)
	{
		if (count[i]!=0 ) vari++;
	}
	//cout << vari << endl;

	int e = 0;
	e = vari - K;
	if (e < 0)e = 0;
//	cout << e << endl;
	
	int ans=0;
	for(int i=0;i<=K;i++)
	{
		ans += count[i];
	}
	ans = N - ans;
	cout << ans << endl;

	return 0;


}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


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

#define ABS(x, y) (x > y ? x - y : y - x)

bool DP[80][80][(80 + 79) * 80 + 1];
int A[80][80];
int B[80][80];

int main() {
    int H, W;
    cin >> H >> W;

    int D = (H + W - 1) * 80;

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> A[i][j];
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> B[i][j];
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            for (int k = 0; k <= D; ++k) {
                DP[i][j][k] = false;
            }
        }
    }

    DP[0][0][ABS(A[0][0], B[0][0])] = true;

    for (int i = 1; i < H; ++i) {
        for (int k = 0; k <= D; ++k) {
            if (DP[i - 1][0][k]) {
                int d = ABS(A[i][0], B[i][0]);
                DP[i][0][k + d] = true;
                DP[i][0][ABS(k, d)] = true;
            }
        }
    }

    for (int j = 1; j < W; ++j) {
        for (int k = 0; k <= D; ++k) {
            if (DP[0][j - 1][k]) {
                int d = ABS(A[0][j], B[0][j]);
                DP[0][j][k + d] = true;
                DP[0][j][ABS(k, d)] = true;
            }
        }
    }

    for (int i = 1; i < H; ++i) {
        for (int j = 1; j < W; ++j) {
            for (int k = 0; k <= D; ++k) {
                if (DP[i - 1][j][k] || DP[i][j - 1][k]) {
                    int d = ABS(A[i][j], B[i][j]);
                    DP[i][j][k + d] = true;
                    DP[i][j][ABS(k, d)] = true;
                }
            }
        }
    }

    int ans;

    for (ans = 0; ans <= D; ++ans) {
        if (DP[H - 1][W - 1][ans]) break;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 79744
//  main.cpp
//  20191220homework
//
//  Created by Priscilla Leang on 12/27/19.
//  Copyright  2019 Priscilla Leang. All rights reserved.
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    //takoyaki;
    int a, b, m, n;
    m = 0;
    cin>> a;
    int takoyaki[a];

    for (int i = 0; i< a; i++){
        cin>> takoyaki[i];
    }

    for (int i = 0; i< a; i++){
        for (int j = i+1; j< a; j++){
            int x = takoyaki[i]*takoyaki[j];
            m+=x;
        }
    }
    cout<< m;
    //shell game
    cin>> a>> b;
    //a is number of times, b is where is is found
//    int shells[3];
//    for (int i = 0; i< 3; i++){
//        shells[i] = i;
//    }
//    for (int i = 0; i< a; i++){
//        if (i% 2 == 0){//odd move
//            int h = shells [0];
//            shells[0] = shells[1];
//            shells[1] = h;
//        }
//        else if (i%2==1){
//            int h = shells[1];
//            shells[1] = shells[2];
//            shells[2] = h;
//        }
//    }
//    cout<< shells[b];
    //parade
//    cin>> a;
//    int soldiers[a][2];
//    for (int i =0; i< a; i++){
//        for(int j = 0; j< 2; j++){
//            cin>> soldiers[i][j];
//        }
//    }
//    //calculate original beauty
//    //see which side has less people
//    //find the set where teh less side value> greater side value
//    //
    
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())

matrix = [[0 for _ in range(10)] for _ in range(10)]

for i in range(1, n+1):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    matrix[a][b] += 1

ans = 0
for i in range(0, 10):
    for j in range(0, i+1):
        if i == j:
            ans += matrix[i][i] ** 2
        else:
            ans += matrix[i][j] * matrix[j][i] * 2

print(ans)

Measured memory_bytes: 3064
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable long mod = 10^^9 + 7;
immutable int inf = mod;

void main(){
    int n = readln.chomp.to!int;
    auto a = new int[](n + 1);

    foreach(i ; 1 .. n + 1){
        readVars(a[i]);
    }

    auto ma = new int[](n + 1);
    ma[1 .. $] = inf;
    ma[0] = -1;

    auto mb = assumeSorted(ma);

    int ans;

    foreach(i ; 1 .. n + 1){
        int j = mb.lowerBound(a[i]).length.to!int;
        ans = max(ans, j);
        mb[j] = a[i];
    }

    writeln(ans);
}

void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        throw new Exception("args num < input num");
    }
}

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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "YES"
#define FALSE__ "NO"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007
#define PI 3.141592653589793238462643383

signed main()
{
	init();
	solve();
}

void init()
{
	int N;
	cin >> N;
	int res = 0;
	rep(i, N) {
		int a;
		cin >> a;
		res += a % 2;
	}
	PRINT(res % 2 == 0);
}

void solve()
{
}


Measured memory_bytes: 256
import math

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
M = math.ceil(N/K)

H = [T[i::K] for i in range(K)]
res = 0
for h in H:
    dp = [[0]*3 for _ in range(len(h))]
    if h[0] == "r":
        dp[0][2] = P
    elif h[0] == "s":
        dp[0][0] = R
    else:
        dp[0][1] = S

    for i in range(1, len(h)):
        dp[i][0] = max(dp[i-1][1], dp[i-1][2])
        dp[i][1] = max(dp[i-1][0], dp[i-1][2])
        dp[i][2] = max(dp[i-1][0], dp[i-1][1])

        if h[i] == "r":
            dp[i][2] += P
        elif h[i] == "s":
            dp[i][0] += R
        else:
            dp[i][1] += S

    res += max(dp[-1])

print(res)


Measured memory_bytes: 16372
n = int(input())
a = list(map(int, input().split()))
count = 0
# list a[i]が偶数かどうかをチェック。ループはとりあえず省略する

exist_odd = False
while exist_odd == False:
    for i in range(n):
        if a[i] % 2 != 0:
            exist_odd = True
            if n != i:
                count -= 1
            break
        else:
            a[i] = a[i] / 2
    count += 1
    # print(count)
print(count)

Measured memory_bytes: 9184
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let a = v[0];
	let b = v[1];
	if a <= 9 && b <= 9 {
		println!("{}", a*b);
	}else{
		println!("-1");
	}
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

const long long mod = 1000000007;
int N,K; long long D[100100],S[100100];

int main()
{
	scanf ("%d %d",&N,&K); D[0] = 1;
	for (int i=0;i<N;i++){
		int a; scanf ("%d",&a);
		S[0] = D[0];
		for (int j=1;j<=K;j++) S[j] = (S[j-1] + D[j]) % mod;
		for (int j=0;j<=K;j++){
			D[j] = S[j];
			if (j > a) D[j] = (D[j] + mod - S[j-a-1]) % mod;
		}
	}

	printf ("%lld\n",D[K]);

	return 0;
}

Measured memory_bytes: 1664
# kが奇数のとき、n//k**3となる
# kが偶数の時、a≡b≡c mod(k//2)となり、上述プラス.
n,k = map(int,input().split())
ans=0
if k%2==1:
    ans+=(n//k)**3
    print(ans)
else:
    ans+=(((n-k//2)//k + 1)**3)
    ans+=(n//k)**3
    print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
//typedef int64_t int;
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise cout.precision(10); cout << fixed;
#define pb push_back
#define mk make_pair
#define endl "\n"
#define int int64_t
#define ll long long
#define in(num,n) std::vector<int> num(n); for (int i = 0; i < n; i++)cin >> num[i]
const ll Inf = 1e9 + 7;
void solve() {
    string str;
    cin >> str;
    std::map<char, int> mp;
    bool eq = true;
    for (int i = 0; i < str.size(); i++)mp[str[i]]++;
    for (auto x : mp) {
        if (x.second % 2 != 0)eq = false;
    }
    if (eq)cout << "Yes" << endl;
    else cout << "No" << endl;
}


int32_t main()
{
    fastio;
    precise;

    //int test; cin >> test; while (test--)
    solve();
    return 0;
}

Measured memory_bytes: 3644
using System;

class ITP1_1_B
{
    public static void Main()
    {
        const int iPowerOfValue = 3;    //???????????????

        /* Input */
        int iValue = int.Parse(Console.ReadLine()); //??\???????????´??°???

        /* Output */
        Console.WriteLine(System.Math.Pow(iValue, iPowerOfValue));
    }
}

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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] a1 = Console.ReadLine().Split(' ');
            string[] a2 = Console.ReadLine().Split(' ');
            string[] a3 = Console.ReadLine().Split(' ');
            int[,] a = new int[3, 3];
            for (int i = 0; i < 3; i++)
            {
                a[0, i] = int.Parse(a1[i]);
                a[1, i] = int.Parse(a2[i]);
                a[2, i] = int.Parse(a3[i]);
            }
            int n = int.Parse(Console.ReadLine());
            bool[,] b = new bool[3, 3];
            for (int i = 0; i < n; i++)
            {
                int kazu = int.Parse(Console.ReadLine());
                for (int k = 0; k < 3; k++)
                {
                    for (int l = 0; l < 3; l++)
                    {
                        if (a[k, l] == kazu)
                            b[k, l] = true;
                    }
                }
            }

            for (int i = 0; i < 3; i++)
            {
                if (b[i, 0] && b[i, 1] && b[i, 2]) { Console.WriteLine("Yes"); return; }
                if (b[0, i] && b[1, i] && b[2, i]) { Console.WriteLine("Yes"); return; }
            }
            if(b[0,0]&&b[1,1]&&b[2,2]) { Console.WriteLine("Yes"); return; }
            if(b[0,2]&&b[1,1]&&b[2,0]) { Console.WriteLine("Yes"); return; }
            Console.WriteLine("No");
        }
    }
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=0,a,b,c,cmp,data,m,h,x,y,xcmp=0,ycmp=0,sum=0;

string s,w;

vector<int> z;

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
       cin >> s;
       rrrep(i,s.size()-1,-1){
           if(s[i]=='m' &&s[i-1]=='a' &&s[i-2]=='e' &&s[i-3]=='r' &&s[i-4]=='d'){
               //Cout("a");
               i-=4;
           }
           else if(s[i]=='r' &&s[i-1]=='e' &&s[i-2]=='m' &&s[i-3]=='a' &&s[i-4]=='e' && s[i-5]=='r' && s[i-6]=='d'){
               i-=6;
           }
           else if(s[i]=='e' &&s[i-1]=='s' &&s[i-2]=='a' &&s[i-3]=='r' &&s[i-4]=='e'){
               i-=4;
           }
           else if(s[i]=='r' &&s[i-1]=='e' &&s[i-2]=='s' &&s[i-3]=='a' &&s[i-4]=='r' && s[i-5]=='e'){
               i-=5;
           }
           else{
               Cout("NO");
               return 0;
           }
           
       }
       Cout("YES");
return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<cstdlib>
using namespace std;

int main(){
   string a;
   cin >> a;
   int n = 753;
   int min = n;
   
   for(int i = 0; i < a.length()-2; i++){
        string p = a.substr(i,3);
        int t = abs(stoi(p) - n);
        if(t < min){
            min = t;
        }    
   }
   
   cout << min << endl;
}

Measured memory_bytes: 256
def bubbleSort(number, array)
  flag = 1
  count_num = 0

  while flag == 1
    flag = 0
    for i in 1..number-1 do
      next_array = array[i]      
      if array[i-1].to_i > array[i].to_i
        array[i] = array[i-1]
        array[i-1] = next_array
        count_num += 1
        flag = 1
      end
    end    
  end
  puts array.join(" ").strip
  puts count_num
end

number = gets.to_i
array = gets.to_s.split(" ")

bubbleSort(number,array)



Measured memory_bytes: 6868
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
#define ll long long int
#define pi 3.141592653589793238

int main(){
	ll n;
    cin>>n;
    if(n<2)
    {
        cout<<0;
        return 0;
    }
    else
    {
        ll ans=1,v1=1,v2=1,v3=1;
        for(ll i=0;i<n;i++)
            v1=(v1*10)%mod,v2=(v2*9)%mod,v3=(v3*8)%mod;
        v2=(v2*2)%mod;
        cout<< (v1 + (-v2 + v3 + mod)%mod + mod )%mod <<endl;
    }
    return 0;
}




Measured memory_bytes: 3648
n = int(input())
h = list(map(int, input().split()))

memo = 0
for i in range(n-1):
  if h[i] > h[i+1]:
    memo = max(memo, h[i] - 1)
    if h[i] - h[i+1] > 2 or h[i+1] < memo:
      print("No")
      exit()
print("Yes")

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

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var cmb = new Combination(2 * 100000, Mod);
            var dct = primefactorize(M);
            var ans = 1L;
            foreach (var d in dct)
                ans = ans * cmb.nCk((int)(N - 1 + d.Value), (int)d.Value) % Mod;
            WriteLine(ans);
        }
        static Dictionary<long, long> primefactorize(long n)
        {
            var primes = new Dictionary<long, long>();
            for (long i = 2; i * i <= n; ++i)
            {
                while (n % i == 0)
                {
                    if (!primes.ContainsKey(i)) primes[i] = 0;
                    ++primes[i];
                    n /= i;
                }
            }
            if (n != 1) primes[n] = 1;
            return primes;
        }
        public class Combination
        {
            readonly long mod;
            readonly long[] fac, finv, inv;
            public Combination(long n, long mod = 1000000007)
            {
                long max = n + 1;
                this.mod = mod;
                fac = new long[max];
                finv = new long[max];
                inv = new long[max];
                fac[0] = fac[1] = 1;
                finv[0] = finv[1] = 1;
                inv[1] = 1;
                for (int i = 2; i < max; ++i)
                {
                    fac[i] = fac[i - 1] * i % mod;
                    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
                    finv[i] = finv[i - 1] * inv[i] % mod;
                }
            }
            public long nCk(int n, int k)
            {
                if (n < k) return 0;
                if (n < 0 | k < 0) return 0;
                return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
            }
        }
    }
}

Measured memory_bytes: 18016
using System;
using System.Linq;

    class Program
    {
        static void Main(string[] args)
        {
            var abc=Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray();
            Console.WriteLine(abc[1]-abc[0]== abc[2] - abc[1]?"YES":"NO");
        }
    }

Measured memory_bytes: 13268
n, m, x = map(int, input().split())
ca = []
for _ in range(n):
    ca.append(list(map(int, input().split())))


cost_max = 12 * (10 ** 5)
book_list = []
flag = 0
for i in range(2**n):
    book_num = 0
    book_list = []
    if i == 0:
        continue
    for j in range(n):
        if (i >> j) & 1:
            book_list.append(ca[j])
            book_num += 1
    for j in range(m):
        skill_revel = 0
        for k in range(book_num):
            skill_revel += book_list[k][j+1]
        if skill_revel >= x:
            if j == (m-1) and k == (book_num-1):
                cost = 0
                for l in range(book_num):
                    cost += book_list[l][0]
                if cost <= cost_max:
                    flag = 1 
                    cost_max = cost
            continue
        else:
            break

if flag == 0:
    print(-1)
else:
    print(cost_max)

Measured memory_bytes: 9152
while true
    @w,@h=gets.split(" ").map(&:to_i)
    if @w==0
        break
    end
    a=(0...@h).map{gets}
    @flag=Array.new(@h).map{Array.new(@w,0)}
    @h.times do |i|
        @w.times do |j|
            if a[i][j]=='W'
                @flag[i][j]|=1
            elsif a[i][j]=='B'
                @flag[i][j]|=2
            end
        end
    end
    def solve(x,y,c)
        dx=[0,1,0,-1]
        dy=[1,0,-1,0]
        4.times do |i|
            if x+dx[i]<0||x+dx[i]>=@w||y+dy[i]<0||y+dy[i]>=@h
                next
            end
            if @flag[y+dy[i]][x+dx[i]]&3>0
                next
            end
            if @flag[y+dy[i]][x+dx[i]]&c>0
                next
            end
            @flag[y+dy[i]][x+dx[i]]|=c
            solve(x+dx[i],y+dy[i],c)
        end
    end
    @h.times do |i|
        @w.times do |j|
            if @flag[i][j]==1
                solve(j,i,4)
            elsif @flag[i][j]==2
                solve(j,i,8)
            end
        end
    end
    bcnt=0
    wcnt=0
    @h.times do |i|
        @w.times do |j|
            if @flag[i][j]&15==4
                wcnt+=1
            elsif @flag[i][j]&15==8
                bcnt+=1
            end
        end
    end
    print("#{bcnt} #{wcnt}\n")
end

Measured memory_bytes: 11748
from math import gcd
from collections import defaultdict

N, P = map(int, input().split())
S = list(map(int, input()))

answer = 0
if P == 2 or P == 5: # Case when only last digit matters
    for j in range(N - 1, -1, -1): # Enumerate right endpoint
        if S[j] % P == 0:
            answer += j + 1
else: 
    # Enuerate left endpoint from right to left
    # Find number of right endpoints that make the substr % P == 0
    cnts = defaultdict(int)
    suffix = 0
    base = 1
    for i in range(N - 1, -1, -1):
        suffix = (suffix + S[i] * base) % P
        answer += cnts[suffix]  # Substr with length >= 2
        answer += 1 if suffix == 0 else 0 # Substr with length = 1
        cnts[suffix] += 1
        base = base * 10 % P

print(answer)

Measured memory_bytes: 11732
#include<bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(b);i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(d);j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRvl(c) for (vl::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvll(c) for (vll::iterator it = (c).begin(); it != (c).end(); it++)
#define gc getchar_unlocked
#define pc putchar_unlocked3
#define pb(a) push_back((a))
 
 
void solve()
{
    string str;
    cin>>str;
    int ans=  0;
    int n = str.length();
    for(int i=0;i<n/2;i++)
    {
        if(str[i]!=str[n-1-i])ans++;
    }
    cout<<ans<<endl;

}
 
int main()
{
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif 
    */
        ll t;
    //cin>>t;
    //while(t--)
        solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

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

Node *root, *NIL;

Node* find(Node *u, int k) {
    while(u != NIL && k != u->key) {
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    while(x != NIL) {
        y = x;
        if(z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    z->parent = y;   
    if(y == NIL) {
        root = z;
    } else if(z->key < y->key) {
        y->left = z;
    } else {
        y->right = z;
    }
}

void inorder(Node *u) {
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if(u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, x;
    string com;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> com;
        if(com == "insert") {
            cin >> x;
            insert(x);
        } else if(com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } else if(com == "find") {
            cin >> x;
            Node*t = find(root, x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        }
    }
    return 0;
}


Measured memory_bytes: 21944
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
	    long nlen = String.valueOf(n).length(); 
	    for (long i = 1; i * i <= n; i++) {    
	        if (n % i == 0) {      
                if (String.valueOf(n/i).length() < nlen ){
                	nlen = String.valueOf(n/i).length();
	            }
	        }
	    }
	    System.out.println(nlen);
	    
	    
	}

}

Measured memory_bytes: 23636
s = gets.chomp
n = s.length
cnt = {}
ans = 0

2019.times do |i|
  cnt[i] = 0
end

cnt[0]+=1
pow = 1
now = 0

s.reverse.each_char do |i|
  now += i.to_i*pow
  # p now
  cnt[now%2019]+=1 
  pow=pow*10%2019
end

2019.times do |i|
  ans += cnt[i]*(cnt[i]-1)/2
end

# p cnt
puts ans


Measured memory_bytes: 15020
N, M= (int(x) for x in input().split())
height=[int(x) for x in input().split()]
nlist=[1]*N

for _ in range(M):
    a, b =(int(x) for x in input().split())
    a-=1
    b-=1
    if height[a]<=height[b]:
        nlist[a]=0

    if height[b]<=height[a]:
        nlist[b]=0

print(sum(nlist))

Measured memory_bytes: 20092
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;

LL N;
LL A, B, C;

int main()
{
	while(scanf("%lld", &N) != EOF)
	{
		for(LL h = 1; h <= 3500; h++) {
			for(LL n = 1; n <= 3500; n++) {
				LL x = N * h * n;
				LL y = 4 * h * n - N * n - N * h;
				if(y > 0 && x % y == 0) {
					A = h;
					B = n;
					C = x / y;
				}
			}
		}
		printf("%lld %lld %lld\n", A, B, C);
	}
	return 0;
}

Measured memory_bytes: 128
res=[[[0 for r in range(10)]for f in range(3)]for b in range(4)]
for i in range(int(input())):
    b,f,r,v=map(int,input().split())
#    print(b,f,r,v)
    res[b-1][f-1][r-1]+=v
for b in range(4):
    for f in range(3):
        for r in range(10):
            print(' ',res[b][f][r],sep='',end='')
        print()
    if b < 3:
        print('#'*20)


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

#define int long long
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const unsigned int mod = 1e9 + 7;

using namespace std;

int32_t main() {
	fastio;

	int n;
	cin >> n;
	int a[n + 1], freq[n + 1];
	memset(freq, 0, sizeof(freq));
	for(int i = 2; i <= n; ++i) cin >> a[i];
	for(int i = 2; i <= n; ++i) ++freq[a[i]];
	for(int i = 1; i <= n; ++i) cout << freq[i] << '\n';

	return 0;
}


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

long long mod = 1000000007;

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

    long long sum = 0;
    long long acc = 0;
    for (int i = 0; i < n; ++i) {
        sum = (sum + (a[i] * acc)) % mod;
        /* acc += (a[i] % mod); */
        acc = (acc + a[i]) % mod;
    }
    cout << sum % mod << "\n";
    return 0;
}


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

int main(){
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    vector<int> sum(N + 1, 0);
    for(int i = 0; i < N; i++){
        cin >> L[i];
        sum[i + 1] = sum[i] + L[i];
    }
    int ans = N + 1;
    for(int i = 0; i <= N; i++){
        if(sum[i] > X){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
(defun month-p (x)
  (<= 1 (parse-integer x) 12))


(defun solve (s)
  (let* ((s1 (subseq s 0 2))
         (s2 (subseq s 2)))
    (cond
      ((and (month-p s1) (month-p s2)) "AMBIGUOUS")
      ((and (month-p s1) (not (month-p s2))) "MMYY")
      ((and (not (month-p s1)) (month-p s2)) "YYMM")
      (t  "NA"))))

(defun main ()
  (let ((s (read-line)))
    (princ (solve s))
    (fresh-line)))

(main)


Measured memory_bytes: 23636
import Control.Monad

mymin :: [Int] -> Int
mymin (x:[]) = x
mymin (x:xs) =
  min x $ mymin xs


dfs :: [Int] -> [Int] -> [Int] -> Int
dfs [as, bs ,cs] [a, b, c] (l:ls) =
  let 
    r0 = dfs [as, bs, cs] [a, b, c] ls
    r1 = dfs [as + l, bs, cs] [a, b, c] ls + 10
    r2 = dfs [as, bs + l, cs] [a, b, c] ls + 10
    r3 = dfs [as, bs, cs + l] [a, b, c] ls + 10
  in 
    mymin [r0, r1, r2, r3]

dfs [as, bs, cs] [a, b, c] [] =
  if mymin [as, bs, cs] > 0 then
    abs(as - a) + abs(b - bs) + abs(c - cs) - 30
  else
    100000000


main = do
  [n, a, b, c] <- (map read) . words <$> getLine
  ls <- replicateM n (read <$> getLine)
  putStrLn $ show $ dfs (replicate 3 0) [a, b, c] ls


Measured memory_bytes: 1020