akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
#pragma GCC optimize("-O3")
#define endl "\n"
#define mp make_pair
#define st first
#define nd second
#define pii pair<int, int>
#define pb push_back
#define _upgrade ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(10), cin.tie(0), cout.tie(0);
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FWD(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fwd(i, a, b) for (int i = (a); i < (b); ++i)
#define all(c) (c).begin(), (c).end()
#define sz(X) (int)((X).size())
#define what(x) cerr << #x << " is " << x << endl;
#define int long long

const int inf = 2e18;

int getPot(int x)
{
    return x > 60 ? inf : 1ll << x;
}

int32_t main()
{
    int n;
    cin >> n;
    vector<int> A(n + 1);
    vector<int> X(n + 1); //ile_wolnych

    rep(i, n + 1) cin >> A[i];

    int x = 1;
    rep(i, n + 1)
    {
        x -= A[i];
        X[i] = x;

        x *= 2;
        x = min(x, inf);
        if (x < 0)
            break;
    }

    if (x < 0)
    {
        cout << -1 << endl;
        exit(0);
    }

    int res = 0;
    int sum = 0;
    for (int i = n; i >= 0; i--)
    {
        res += min(sum, X[i]);
        res += A[i];
        sum += A[i];
    }
    cout << res << endl;
}

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

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

	int dp[n];
	for(int i=0; i<n; i++)	dp[i] = INT_MAX;
	dp[0] = 0;
	for(int i=0; i<n-1; i++)
	{
		if(i+1 < n)
			dp[i+1] = min( dp[i+1], dp[i] + abs(h[i] - h[i+1]));

		if(i+2 < n)
			dp[i+2] = min( dp[i+2], dp[i] + abs(h[i] - h[i+2]));	
	}

	cout << dp[n-1];
}

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

int main(){
  int n, ans=0; cin>>n;
  string s; cin>>s;
  
  for(int i=0;i<n;i++){
    if(i<n-1){
      if(s[i]==s[i+1]){
        ans++;
        while(s[i]==s[i+1])i++;
      }else{
        ans++;
      }
    }else{
      ans++;
    }
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import collections
import math


def main():
    N = int(input())
    S = ["".join(sorted(input())) for i in range(N)]
    cnt = collections.Counter(S)
    ans = 0
    for v in cnt.values():
        if v != 1:
            ans += math.factorial(v) // (math.factorial(v - 2) * 2)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24084
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e4;
const int mod=998244353;
int n,m,len,ans;
char S1[maxn+8],S2[maxn+8];
int fac[maxn+8],fact[maxn+8],f[maxn+8][maxn+8];

int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

int C(int n,int m){return 1ll*fac[n]*fact[m]%mod*fact[n-m]%mod;}
int power(int a,int k)
{
    int sum=1;
    for (;k;k>>=1,a=1ll*a*a%mod)
	if (k&1)
	    sum=1ll*sum*a%mod;
    return sum;
}

int main()
{
    scanf("%s",S1+1);
    scanf("%s",S2+1);
    len=strlen(S1+1);
    fac[0]=fact[0]=1;
    for (int i=1;i<=len;i++) fac[i]=1ll*fac[i-1]*i%mod;
    fact[len]=power(fac[len],mod-2);
    for (int i=len-1;i;i--) fact[i]=1ll*fact[i+1]*(i+1)%mod;
    for (int i=1;i<=len;i++) {if (S1[i]==S2[i]&&S1[i]=='1') n++;if (S1[i]=='1'&&S2[i]=='0') m++;}
    f[0][0]=1;//for (int i=1;i<=m;i++) f[0][i]=1ll*f[0][i-1]*(m-i+1)%mod*(m-i+1)%mod;
    for (int i=0;i<=n;i++)
	for (int j=0;j<=m;j++)
	    {
		if (i) f[i][j]=(f[i][j]+1ll*f[i-1][j]*(n-i+1)%mod*(m-j)%mod)%mod;
		if (j) f[i][j]=(f[i][j]+1ll*f[i][j-1]*(m-j+1)%mod*(m-j+1)%mod)%mod;
	    }
    for (int i=0;i<=n;i++)
	{
	    //printf("%d\n",f[i][m]);
	    ans=(ans+1ll*f[i][m]*fac[n-i]%mod*fac[n-i]%mod*C(n+m,n-i)%mod)%mod;
	}
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 380160
#![allow(non_snake_case)]
use std::collections::HashMap;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let N:usize = sc.read();
    let K:usize = sc.read();
    let A:Vec<usize> = sc.vec(N);
    let mut ans:usize = 0;
    let mut Acc:Vec<usize> = vec![0;N+1];
    Acc.push(0);
    for i in 0..N{
        Acc[i+1] = (Acc[i]+A[i]-1)%K
    }
    let mut S = HashMap::new();
    for i in 0..(N+1){
        *S.entry(Acc[i]).or_insert(0) += 1;

        if K <= i{
            *S.entry(Acc[i-K]).or_insert(0) -= 1;
        }
        ans += S[&Acc[i]]-1;
    }
    
    
    
    println!("{}", ans);



}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
        .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}




Measured memory_bytes: 17304
S = input()
N = len(S)
n = N // 2
A = 0

if N % 2 == 0:
  T = S[:n]
  U = S[:n-1:-1]
else:
  T = S[:n]
  U = S[:n:-1]
for i in range(n):
  if T[i] != U[i]:
    A += 1
print(A)
    
	

Measured memory_bytes: 3060
import sys
x,n = map(int,input().split())
    
p,f = x-1,x+1
bans = set(map(int,input().split()))

if n == 0 or x not in bans:
    print(x)
    sys.exit()

while True:
    if p not in bans:
        print(p)
        break 
    p -= 1
    
    if f not in bans:
        print(f)
        break 
    f += 1

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

int main(void) {
	int a, b;
	stack<int> S;
	string c;
	while (cin >> c) {
		if (c[0] == '+') {
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			S.push(a + b);
		}
		else if (c[0] == '*') {
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			S.push(a*b);
		}
		else if (c[0] == '-') {
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			S.push(b - a);
		}
		else {
			S.push(atoi(c.c_str()));
		}
	}
	cout << S.top() << endl;
	return 0;
}

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

#define b_month 20	//大の月
#define s_month 19	//小の月
#define yeardate	((5*b_month)+(5*s_month))	//1年の日数を求める
#define three_yeardate	(10*b_month)			//3の倍数の場合の1年の日数を求める

unsigned int datecount(unsigned int y,unsigned int m,unsigned int d);

int main()
{
	unsigned int n;			//入力するデータセット数
	unsigned int y,m,d;		//入力するyear, month, date
	unsigned int m_date=0;	//1年1月1日から記念日までの日数
	unsigned int date=0;	//入力したデータから記念日までの日数

	cin>>n;

	m_date = datecount(1000,1,1);

	for(unsigned int i=0;i<n;i++)
	{
		cin>>y>>m>>d;
		
		date = datecount(y,m,d);

		cout<<m_date-date<<endl;
	}
	return 0;
}

//入力されたデータから記念日までの日数を出力する関数
unsigned int datecount(unsigned int y,unsigned int m,unsigned int d)
{
		unsigned int s_count=0;	//合計日数
		unsigned int y_count=0;	//年を日数に変換した値
		unsigned int m_count=0;	//月を日数に変換した値
		unsigned int d_count=0;	//日を日数に変換した値

		//年を日数に変換
		y_count = (((y-1)/3)*three_yeardate)+(((y-1)-((y-1)/3))*yeardate);

		//月を日数に変換
		if(y%3==0)	//現在の年が3の倍数の場合
		{
			m_count = (m-1)*b_month;
		}
		else if(m%2==0)	//現在の月が偶数の場合
		{
			m_count = (((m-1)/2)*s_month) + ((m-1-((m-1)/2))*b_month);
		}
		else	//現在の月が奇数の場合
		{
			m_count = (((m-1)/2)*s_month) + (((m-1)/2)*b_month);
		}

		//日を日数に変換
		d_count = d;

		//合計値を計算
		s_count = y_count + m_count + d_count;

		return s_count;
}

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

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

template <typename T>
inline void read(T &x)
{
    T data = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        data = (data << 3) + (data << 1) + ch - '0';
        ch = getchar();
    }
    x = f * data;
}

const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e5 + 9;
int m[109];
signed main()
{
    //freopen("in.txt","r",stdin);
    //freopen("data.txt","w",stdout);
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    //std::cout.tie(0);
    string s, t;
    cin >> s >> t;
    int ans = inf;
    int a = s.length(), b = t.length();
    for (int i = 0; i < a; ++i)
    {
        int cnt = 0;
        if (i + b - 1 >= a)
            break;
        for (int j = 0; j < b; ++j)
        {
            if (s[i + j] != t[j])
                cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

Measured memory_bytes: 3596
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void) {

    int N; cin>>N;
    vector<int> a(N+1,0);

    for (int i = 2; i <= N; ++i) { //階上の2~Nまでの全ての素因数を出したい
        int tmp = i;
        ll cnt = 0;
        for (int j = 2; j <= tmp; ++j) {//tmp(i)を素因数分解する
            while(tmp%j==0){//割り切れるまでjで割って、素因数をa[]でカウント
                tmp /= j;
                a[j]++;
            }
        }
    }

    ll ans = 1;
    for (int i = 0; i <= N; ++i) {
        //もしa[i]>0なら+1したものをansにかけて、a[i]が0なら1をかける
        ans *= (a[i]>0)?++a[i]:1;
        ans %= MOD;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

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

int main(){
    string S;
    cin >> S;
    int ans=700;
    REP(i,3){
        if(S[i]=='o'){
            ans += 100;
        }
    }
   cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int main(){
	long long a,b,x,cnt;
	cin>>a>>b>>x;
	if(a==0){
        cnt=(b/x)+1;
    }
    else
    {
    	cnt=(b/x)-((a-1)/x);
	}
	cout<<cnt;}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
char g[22][22];
int dy[]={0,0,1,-1};
int dx[]={1,-1,0,0};
void bfs(int y,int x);
int main(){
  while(cin >> g[0]){
    for(int i=1;i<12;i++){
      cin >> g[i];
    }
    int ret = 0;
    for(int i=0;i<12;i++){
      for(int j=0;j<12;j++){
	if(g[i][j] == '1'){
	  bfs( i , j );
	  ret++;
	}
      }
    }
    cout << ret << endl;
  }
}
void bfs(int y,int x){
  g[y][x] = '0';
  for(int i=0;i<4;i++){
    int ty = y + dy[i];
    int tx = x + dx[i];
    if(g[ty][tx] == '1')bfs( ty , tx );
  }
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4040, maxm = 200200, mod = 1'000'000'007;
int mul(long long a, long long b){
	return a * b % mod;
}
int add(int a, int b){
	a += b;
	if(a >= mod) a -= mod;
	return a;
}
int pwr(int a, long long b){
	int r = 1;
	for(; b; b >>= 1, a = mul(a, a)) if(b&1) r = mul(r, a);
	return r;
}
int fat[maxm], ifat[maxm];
void init(){
	fat[0] = 1;
	for(int i = 1; i < maxm; i++) fat[i] = mul(i, fat[i - 1]);
	ifat[maxm - 1] = pwr(fat[maxm - 1], mod - 2);
	for(int i = maxm - 2; i >= 0; i--) ifat[i] = mul(ifat[i + 1], i + 1);
}
int coef(int n, int k){
	if(n < k) return 0;
	return mul(fat[n], mul(ifat[k], ifat[n - k]));
}
int cnt[maxn][maxn], f[maxn][maxn], x[maxm], y[maxm];
int main(){
	init();
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
	for(int i = 0; i < n; i++){
		cnt[2001-x[i]][2001-y[i]] += 1;
		cnt[x[i]+2001][y[i]+2001] += 1;
	}
	int ans = 0;
	for(int i = 1; i < maxn; i++){
		for(int j = 1; j < maxn; j++){
			f[i][j] = add(f[i - 1][j], f[i][j - 1]);
			if(i > 2000 && j > 2000) ans = add(ans, mul(cnt[i][j], f[i][j]));
			else f[i][j] = add(f[i][j], cnt[i][j]);
		}
	}
	for(int i = 0; i < n; i++) ans = add(ans, mod - coef(2 * x[i] + 2 * y[i], 2 * x[i]));
	cout << mul(ans, (mod + 1) / 2) << endl;
	return 0;
}


Measured memory_bytes: 130816
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

struct NumberTheory
{
	vector<ll> primes;
	vector<bool> prime;
	vector<ll> totient;
	vector<ll> sumdiv;
	vector<ll> bigdiv;
	void Sieve(ll n)
	{
		prime.assign(n+1, 1);
		prime[1] = false;
		for(ll i = 2; i <= n; i++)
		{
			if(prime[i])
			{
				primes.pb(i);
				for(ll j = i*2; j <= n; j += i)
				{
					prime[j] = false;
				}
			}
		}
	}
	
	ll phi(ll x)
	{
		map<ll,ll> pf;
		ll num = 1; ll num2 = x;
		for(ll i = 0; primes[i]*primes[i] <= x; i++)
		{
			if(x%primes[i]==0)
			{
				num2/=primes[i];
				num*=(primes[i]-1);
			}
			while(x%primes[i]==0)
			{
				x/=primes[i];
				pf[primes[i]]++;
			}
		}
		if(x>1)
		{
			pf[x]++; num2/=x; num*=(x-1);
		}
		x = 1;
		num*=num2;
		return num;
	}
	
	bool isprime(ll x)
	{
		if(x==1) return false;
		for(ll i = 0; primes[i]*primes[i] <= x; i++)
		{
			if(x%primes[i]==0) return false;
		}
		return true;
	}

	void SievePhi(ll n)
	{
		totient.resize(n+1);
		for (int i = 1; i <= n; ++i) totient[i] = i;
		for (int i = 2; i <= n; ++i)
		{
			if (totient[i] == i)
			{
				for (int j = i; j <= n; j += i)
				{
					totient[j] -= totient[j] / i;
				}
			}
		}
	}
	
	void SieveSumDiv(ll n)
	{
		sumdiv.resize(n+1);
		for(int i = 1; i <= n; ++i)
		{
			for(int j = i; j <= n; j += i)
			{
				sumdiv[j] += i;
			}
		}
	}
	
	ll getPhi(ll n)
	{
		return totient[n];
	}
	
	ll getSumDiv(ll n)
	{
		return sumdiv[n];
	}
	
	ll modpow(ll a, ll b, ll mod)
	{
		ll r = 1;
		if(b < 0) b += mod*100000LL;
		while(b)
		{
			if(b&1) r = (r*a)%mod;
			a = (a*a)%mod;
			b>>=1;
		}
		return r;
	}
	
	ll inv(ll a, ll mod)
	{
		return modpow(a, mod - 2, mod);
	}
	
	ll invgeneral(ll a, ll mod)
	{
		ll ph = phi(mod);
		ph--;
		return modpow(a, ph, mod);
	}
	
	void getpf(vector<ii>& pf, ll n)
	{
		for(ll i = 0; primes[i]*primes[i] <= n; i++)
		{
			int cnt = 0;
			while(n%primes[i]==0)
			{
				n/=primes[i]; cnt++;
			}
			if(cnt>0) pf.pb(ii(primes[i], cnt));
		}
		if(n>1)
		{
			pf.pb(ii(n, 1));
		}
	}

	//ll op;
	void getDiv(vector<ll>& div, vector<ii>& pf, ll n, int i)
	{
		//op++;
		ll x, k;
		if(i >= pf.size()) return ;
		x = n;
		for(k = 0; k <= pf[i].se; k++)
		{
			if(i==int(pf.size())-1) div.pb(x);
			getDiv(div, pf, x, i + 1);
			x *= pf[i].fi;
		}
	}
};

NumberTheory nt;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n,p; cin>>n>>p;
	nt.Sieve(1011111);
	vector<ii> pf;
	nt.getpf(pf, p);
	ll ans = 1;
	for(ii x:pf)
	{
		ll pri = x.fi; ll cnt = x.se;
		for(ll j = 0; j < cnt/n; j++)
		{
			ans*=pri;
		}
	}
	cout<<ans<<'\n';
	
}


Measured memory_bytes: 1528
#define _'			'
A[_];long P[_],M=1e9+7,F[_],I[_],X;i,j,k,t;c(a,b)long*a,*b;{t=*a<*b?-1:*a>*b;}p(a,b){return b?p(a%M*a%M,b/2)*(b%2?a:1L)%M:1;}f(a,b){return F[a+b]*I[a]%M*I[b]%M;}main(s){for(*I=1;++X<_;~scanf("%d",A+i)&&i++%2&&gets(P))I[X]=p(s=F[X]=X*s%M,M-2);for(qsort(A,i/2,8,c);j<i;P[j++-1]=X)for(X=f(t=--A[++j],s=--A[k=j]);k;X=s<A[k-=2]?X:(X-f(s-A[k],t-A[k+1])*P[k]%M+M)%M);printf("%d",X);}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);

int main() {
  ll n,X;
  cin>>n>>X;
  vector<ll> x(n);
  rep(i,n) cin>>x[i];
  sort(all(x));
  ll ans=abs(X-x[0]);
  rep(i,n-1){
    if(x[i+1]-x[i]!=ans){
      ans=gcd(x[i+1]-x[i],ans);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3832
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	long long a, b, x;
	cin >> a >> b >> x;

	int ans = 0;
	long long i = a / x;
	long long j = b / x;

	cout << j - i + (a % x == 0) << "\n";

	return 0;

}

Measured memory_bytes: 256
from itertools import chain
H, W = map(int, input().split())
S = [input() for _ in range(H)]
A = [[0]*(W) for _ in range(H)]

for i in range(H):
    tmp = 0
    stack = []
    for j in range(W):
        if S[i][j] == "." and j < W-1:
            tmp += 1
            stack.append(j)
        elif j == W-1:
            if S[i][j] == ".":
                tmp += 1
                stack.append(j)
            
            while stack:
                tmp_j = stack.pop()
                A[i][tmp_j] += tmp
            tmp = 0
        else:
            while stack:
                tmp_j = stack.pop()
                A[i][tmp_j] += tmp
            tmp = 0
for j in range(W):
    tmp = 0
    stack = []
    for i in range(H):
        if S[i][j] == "." and i < H-1:
            tmp += 1
            stack.append(i)
        elif i == H-1:
            if S[i][j] == ".":
                tmp += 1
                stack.append(i)
            while stack:
                tmp_i = stack.pop()
                A[tmp_i][j] += tmp
            tmp = 0
        else:
            while stack:
                tmp_i = stack.pop()
                A[tmp_i][j] += tmp
            tmp = 0
ans = max(chain.from_iterable(A))-1
print(ans)

Measured memory_bytes: 111620
import heapq

v,e = map(int,input().split())
ans = 0
par = [i for i in range(v)]
rank = [0]*v
def find(x,par):
    if par[x] == x:
        return par[x]
    else:
        return find(par[x],par)
def unite(x,y,par,rank):
    x = find(x,par)
    y = find(y,par)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

L = []
for i in range(e):
    a,b,d = map(int,input().split())
    L.append([d,a,b])
L.sort()
for i in range(e):
    cur = heapq.heappop(L)
    if find(cur[1],par) != find(cur[2],par):
        ans += cur[0]
        unite(cur[1],cur[2],par,rank)
print(ans)


Measured memory_bytes: 25308
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<vector<int >  >adjlist;
vector<int >comp;
void dfs(int u,int compid){
    for(auto v: adjlist[u]){
        if(comp[v]==-1){
            comp[v] = compid;
            dfs(v,compid);
        }
    }
}
int main(){
    cin>>n>>m;
    adjlist.resize(n);
    comp.resize(n,-1);
    set<pair<int,int > >temp;
    for(int i=0,a,b;i<m;i++){
        cin>>a>>b;
        a-=1;
        b-=1;
        if(temp.find({a,b})!=temp.end())continue;
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
        temp.insert({a,b});
    }
    int nand = 0;
    for(int i=0;i<n;i++){
        if(comp[i]==-1){
            comp[i] = nand;
            dfs(i,nand);
        }
        nand++;
    }
    //get maxx
    vector<int >maxi(n,0);
    for(int i=0;i<n;i++)maxi[comp[i]]++;
    int finally = 0;
    for(int i=0;i<n;i++)finally = max(finally,maxi[i]);
    cout<<finally;
    
}

Measured memory_bytes: 34276
#include <stdio.h>
int main(void)
{
	int A,B,C,D;
	scanf("%d%d%d",&A,&B,&C);
	
	D=B/A;
	
	
	if(D>C)
	{
		printf("%d",C);
	}
	
	else
	{
		printf("%d",D);
	
	}
	return 0;
	













}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep( i, a, b ) for( int i = (a); i <= (b); ++i )
#define dep( i, a, b ) for( int i = (a); i >= (b); --i )
using namespace std;
typedef long long ll;
const int N = 1e6+9, INF = 0x3f3f3f3f;

int main( void ) {
    ios::sync_with_stdio( false );
    int n, m, num, ans = 0;
    cin >> n;
    vector<int> vt(n);
    for( int i = 0; i < n; ++i ) cin >> vt[i];
    cin >> m;
    for( int i = 0; i < m; ++i ) {
        cin >> num;
        if( *lower_bound( vt.begin(), vt.end(), num ) == num ) ++ans;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3220
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

queue<int> result;

void fac(long long n){
    long long s = floor(sqrt(n));
    long long r = 0;
    for(long long i = 2; i <= s; i++){
        if((n%i) == 0){
            r = 0;
            do{
                r++;
                n = n / i;
            }while((n%i) == 0);
            result.push(i);
            result.push(r);
        }
    }
    if(n > s){
        result.push(n);
        result.push(1);
    }
}

long long calc(long long n){
    long long i = 1;
    while(true){
        if((n - i) <= i){
            return i;
        }
        n = n - i;
        i++;
    }
}

int main()
{  
    long long n;
    cin >> n;
    fac(n);
    long long sum = 0;
    while(result.empty() == false){
        result.pop();
        long long i = result.front(); result.pop();
        sum += calc(i);
    }
    cout << sum << endl;
    
}

Measured memory_bytes: 3752
#include<stdio.h>

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

  if(N/100 == 7){
    printf("Yes");
  }
  else if((N%100)/10 == 7){
    printf("Yes");
  }
  else if(N%10 == 7){
    printf("Yes");
  }
  else{
    printf("No");
  }

  return 0;
}


Measured memory_bytes: 1732
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep_b(i,n) for(int i=1;i<=(n);++i)

using namespace std;

int main()
{
	int N, a, b, c, sum = 0;
	cin >> N;
	rep_b(a, N)
		rep_b(b, N)
		rep_b(c, N)
	{
		sum += gcd(c, gcd(a, b));
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <numeric>
#include <iomanip>
#include <climits>
#include <cstring>
#include <cmath>

using namespace std;

#define int long long
#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>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=(int)(r)-1;i>=l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using vpii=vector<pii>;
using ll=long long;

constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}
template<typename T>bool chmin(T&a,T b){return a>b?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return a<b?(a=b,1):0;}
int read(){int a;scanf("%lld",&a);return a;}

const long double pi = acos(-1);
constexpr int inf = 3*TEN(18) + 10;

constexpr int mod = TEN(9)+7;

int N;
vi A;

inline ll pow_mod(ll a, ll x, ll m)
{
	if (x == 0) return 1;

	ll res = pow_mod(a, x / 2, m);

	res *= res;
	res %= m;

	if (x % 2) {
		res *= a;
		res %= m;
	}

	return res;
}

int inv(int n) {
	return pow_mod(n, mod - 2, mod);
}

const int MAX = TEN(9);

signed main()
{
	int N; cin >> N;
	vi a(N);
	rep(i, N) cin >> a[i];

	int X = 0;
	rep(i, N) X ^= a[i];

	rep(i, N) {
		cout << (a[i] ^ X) << ' ';
	}
}



Measured memory_bytes: 4816
/*
 * a.cpp
 *
 *  Created on: 2019/06/08
 *      Author: MEIP-users
 */




#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <locale>
#include <queue>
#include <tuple>
#include <map>
#include <fstream>

using namespace std;


#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1e9+10)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))




int main() {
	int n;
	cin >> n;
	vector<ll>as(n);
	vector<ll>bs(n);
	rep(i, n){
		ll a,b;
		cin >> a >> b;
		as[i] = a;
		bs[i] = b;
	}
	sort(as.begin(),as.end());
	sort(bs.begin(),bs.end());
	if(n%2 == 1){
		ll s = as[(n+1)/2-1];
		ll f = bs[(n+1)/2-1];
		cout << f-s+1<<endl;
	}else{
		cout << bs[n/2-1]-as[n/2-1] + bs[n/2]-as[n/2]+1 << endl;
	}
	return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define ll long long
#define EPS 1.0e-8
#define MAX_N 100
typedef pair<int,int> P;

int main(){
	int n;
	double h;
	int cnt[6] = {};

	cin >> n;
	rep(i, n){
		cin >> h;
		if(h < 165.0) cnt[0]++;
		else if(h >= 165.0 && h < 170.0) cnt[1]++;
		else if(h >= 170.0 && h < 175.0) cnt[2]++;
		else if(h >= 175.0 && h < 180.0) cnt[3]++;
		else if(h >= 180.0 && h < 185.0) cnt[4]++;
		else if(h >= 185.0) cnt[5]++;

	}


	rep(i,6){
		printf("%d:",i+1);
		rep(j,cnt[i]) cout << "*";
		cout << endl;
	}
}

Measured memory_bytes: 1248
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int num[200005];
int main()
{
    int b[200005];
    int n,k;
    int ans=0;
    scanf("%d%d",&n,&k);
    memset(num,0,sizeof num);
    memset(b,0,sizeof b);
    memset(a,0,sizeof a);
    int fl=1;
    for(int i=1;i<=n;i++){scanf("%d",&a[i]);num[a[i]]++;}
    for(int i=1;i<=n;i++){if(num[i]!=0) b[fl++]=num[i];}
    sort(b+1,b+n+1);
    for(int i=n-k;i>0;i--) ans+=b[i];
    cout<<ans;
    return 0;
}



Measured memory_bytes: 2560
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args)throws IOException {
		 Scanner scanner = new Scanner(System.in);
	        long a = scanner.nextLong();
	        long b = a / 500;
	        long c = (a - b * 500) / 5;
	        System.out.println(b * 1000 + c * 5);
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

    int alp[26] = {};
    for (int i=0; i<s.length(); i++) {
        alp[s[i] - 'a']++;
    }

    int i = 0, cnt = 0;
    while (i <= ceil(s.length() / 2.0)) {
        // cout << "deb1" << endl;
        int t = s.length() - i - 1;
        if (s[i] == s[t]) {
            i++;
            continue;
        }
        // cout << "deb2" << endl;
        if (s[i] != 'x' and s[t] != 'x') return cout << -1 << endl, 0;
        // cout << "deb3" << endl;
        if (s[i] == 'x') s.insert(t+1, "x");
        else s.insert(i, "x");
        cnt++; i++;
        // cout << s << endl;
    }
    cout << cnt << endl;

    return 0;
}


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

using namespace std;

int main()
{
    long long n , k ,sum=0 ;
    cin>>n>>k;
    long long arr[n];



    for (long long i=0 ;i<n ;i++)
    {
        cin>>arr[i];
    }
     if (k>=n){cout<<"0";}
     else{
    sort(arr,arr+n);
    for (long long i=0 ;i<n-k ;i++)
    {
        sum+=arr[i];
    }
cout<<sum;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
    char s[4];
    scanf("%s", s);
    for(int i = 0; i < 4; i++){
        s[i] -= 48;
    }
    int left = s[0]*10 + s[1];
    int right = s[2]*10 + s[3];
    int left_monthable, right_monthable;

    if(left >= 1 && left <= 12){
        left_monthable = 1;
    }else{
        left_monthable = 0;
    }

    if(right >= 1 && right <= 12){
        right_monthable = 1;
    }else{
        right_monthable = 0;
    }

    if(left_monthable == 1){
        if(right_monthable == 1){
            printf("AMBIGUOUS");
        }else{
            printf("MMYY");
        }
    }else{
        if(right_monthable == 1){
            printf("YYMM");
        }else{
            printf("NA");
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
 long a,b,c,d;
  cin>>a>>b>>c>>d;
  
  long ma=b*d;
  ma=max(ma,b*c);
  ma=max(ma,a*c);
  ma=max(ma,a*d);
  
  cout<<ma;
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(long long A, long long B, long long C, long long K){
    if (K > A + B + C) cout << A - (K - A - B) << '\n';
    else if (K > A + B) cout << A - (K - A - B) << '\n';
    else if (K > A) cout << A << '\n';
    else cout << K << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    solve(A, B, C, K);
    return 0;
}


Measured memory_bytes: 3772
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

const MOD = 10^^9 + 7;

int calc(string s) {

    auto dp = new int[][](s.length + 1, 13);
    // dp[i][j]
    // i : i 桁目までみた
    // j : 13 で割った余

    // dp[0][0] = 1;

    if (s[0] == '?') {
        foreach (i; 0..10) {
            dp[1][i % 13]++;
        }
    }
    else {
        int d = s[0] - '0';
        dp[1][d]++;
    }

    for (int i = 1; i < s.length; i++) { // i 桁目
        for (int j = 0; j < 13; j++) { // 余り
            if (s[i] == '?') { // 0..9
                foreach (k; 0..10) {
                    dp[i + 1][(10 * j + k) % 13] += dp[i][j];
                    dp[i + 1][(10 * j + k) % 13] %= MOD;
                }
            }
            else {
                int d = s[i] - '0';
                dp[i + 1][(10 * j + d) % 13] += dp[i][j];
                dp[i + 1][(10 * j + d) % 13] %= MOD;
            }
        }
    }

    // foreach (a; dp) writeln(a);
    return dp[s.length][5];
}

void main() {
    string s = read!string;
    writeln(calc(s));
}


Measured memory_bytes: 11544
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm> 
using namespace std;
typedef long long ll;
int main()
{
	map<int,int> m;
	int N,M;
	scanf("%d%d",&N,&M);
	int a[N];
	for(int i=0;i<N;++i) scanf("%d",&a[i]);
	sort(a,a+N);
	int x,y;
	for(int i=0;i<M;++i){
		scanf("%d%d",&x,&y);
		m[y]+=x;
	}
	ll ans=0;
	for(int i=0;i<N;++i){
		if(m.size()&&m.rbegin()->first>a[i]){
			a[i]=m.rbegin()->first;
			m.rbegin()->second--;
			if(m.rbegin()->second==0){
				m.erase(m.rbegin()->first);
			}
		}
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
	
typedef long long int ll;
ll n,m,l,r,k;

ll chk(ll x)
{
	ll ans=0;
	for (int i = 1; i <= n; ++i)
	{
		ans+=min(m,x/i);
	}
	return ans;
}
int main()
{
	string s;
	cin>>s;
	ll ans=0;
	for (int i = 0; i < s.length()/2; ++i)
	{
		if(s[i]!=s[s.length()-1-i])
		{
			ans+=1;
		}
	}
	cout<<ans<<endl;	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long int n, wt;
  cin>>n>>wt;
  long long int w[n+1], v[n+1], dp[wt+1];
  for(int i=1;i<=n;i++) cin>>w[i]>>v[i];
  for(int i=0;i<=wt;i++) dp[i]=0;
  for(int j=1;j<=n;j++) for(int i=wt;i>=0;i--) if(w[j]<=i) dp[i]=max(dp[i],dp[i-w[j]]+v[j]);
  cout<<dp[wt];
}

Measured memory_bytes: 4248
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

string s;
vector<string> st;
void dfs(string t, vector<bool> use){
	if(s.size() == t.size()){
		if(t.find("{") == string::npos) st.emplace_back(t);
		return;
	}

	char c = s[t.size()];
	if(c == 'a'){
		t += c;
		dfs(t, use);
		t.pop_back();
	}
	if(not use[c - 'a' + 1]){
		t += c + 1;
		use[c - 'a' + 1] = true;
		dfs(t, use);
		use[c - 'a' + 1] = false;
		t.pop_back();
	}
	if(use[c - 'a']){
		t += c;
		use[c - 'a'] = true;
		dfs(t, use);
		use[c - 'a'] = false;
		t.pop_back();
	}
}

int main(){
	while(cin >> s, s[0] != '#'){
		st.clear();
		dfs("", vector<bool>(27,0));
		sort(all(st));

		cout << st.size() << endl;

		if(st.size() <= 10){
			for(auto t : st){
				cout << t << endl;
			}
		}else{
			rep(i,5){
				cout << st[i] << endl;
			}
			rep(i,5){
				cout << st[st.size() - 5 + i] << endl;
			}
		}
	}
}



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

int main() {
  long long q,h,s,d,n;
  cin>>q>>h>>s>>d>>n;
  long long ans=0;
  long long two=min({q*8,h*4,s*2,d});
  long long x=n/2;
  n%=2;
  ans+=two*x;
  if(n%2==0) cout<<ans<<endl;
  else cout<<min({ans+q*4,ans+h*2,ans+s})<<endl;
}


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

using namespace std;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;
    vector <int> v(n);
    for(int i = 0; i < n; i++)
    	cin >> v[i];
    sort(v.begin(), v.end());
    int sol = 1e9;
    for(int i = 0; i < n - k + 1; i++){
    	sol = min(sol, abs(v[i] - v[i + k - 1]));
	}
	cout << sol;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int N;
  int MAX=0;
  int result=0;
  scanf("%d", &N);
  int H[N], i;
 
  for(i=0; i<N; i++){
    scanf("%d", &H[i]);

    if(H[i] < (MAX-1)){
      result = 1;
      break;
    }
    else if(H[i] > MAX) MAX=H[i];
    else continue;
  }

  switch(result){
    case 0:
      printf("Yes\n");
      break;
    case 1:
      printf("No\n");
      break;
  }
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if ((a + b) % 2==0) {
		cout << (a + b) / 2 << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>    
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()]
#define endl "\n"
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N 	     = 1000*100+5;
const ll N2     = 1000*1000;
const double PI  = 3.14159265;
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
ll calc(int n)
{
	ll res = n;
	res*=(n-1);
	res/=2;
	return res;
}
void sortString(string &str) 
{ 
   sort(str.begin(), str.end()); 
}
int main()
{
	/*comment for all except cc/cf
	#ifndef ONLINE_JUDGE
    	freopen("input.txt","r",stdin);
    	freopen("out.txt","w",stdout);
   	 #endif*/
	fastio();
	int n;
	cin>>n;
	string s[n];
	std::map<string, int> m;
	for (int i = 0; i < n; ++i)
	{
		cin>>s[i];
		sortString(s[i]);
		m[s[i]]++;
	}
	ll ans=0;
	for(auto x : m)
		ans+=calc(x.ss);
	cout<<ans;
}


Measured memory_bytes: 16640
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let p: Vec<usize> = sc.vec(n);
    let mut cnt = 0;
    for i in (1..n - 1) {
        if p[i - 1] > p[i] && p[i] > p[i + 1] {
            cnt += 1;
        } else if p[i - 1] < p[i] && p[i] < p[i + 1] {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

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

  int w, h, x, y; cin >> w >> h >> x >> y;
  int ans = 0;
  if(w==2*x && h==2*y) ans = 1;
  cout << fixed << setprecision(6);
  cout << (double)h*w/2 << " " << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main {

  def factorize(p:Int,d:Int,l:List[Int]):List[Int] = {
    if(d >= Math.sqrt(p)+1) {
      if(p != 1) p::l else l
    } else {
      if(p%d == 0)
        factorize(p/d,d,d::l)
      else if(d==2)
        factorize(p,d+1,l)
      else
        factorize(p,d+2,l)
    }
  }

  def printList(l:List[Int]):Unit = l match {
    case List() => ()
    case h::tail =>
        printList(tail)
        print(" " + h)
  }

  def main(args: Array[String]) = {
    val n = readInt
    val list = factorize(n,2,List())
    print(n.toString + ":")
    printList(list)
    println()
  }
}

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

const int maks = 1e6;
vector<int> g[maks];
int odp = 0;
int wyn[maks];
int n,m;
int dfs(int x) {
    if(wyn[x])return wyn[x];
    for(int v: g[x]) {
        wyn[x] = max(wyn[x],dfs(v)+1);
    }
    odp = max(odp,wyn[x]);
    return wyn[x];
    
}
void input() {
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int x,y; cin >> x >> y;
        g[x].push_back(y);
    }
}
int main() {
   input();
   for(int i = 1; i<= n; i++)
    if(!wyn[i])dfs(i);
    cout << odp;
}


Measured memory_bytes: 30464
#include <stdio.h>
#define N 25

typedef struct {
  int parent;
  int left;
  int right;
} Node;

Node Tree[N];

void printPreorder(int x) {
  printf(" %d", x);
  if(Tree[x].left != -1)printPreorder(Tree[x].left);
  if(Tree[x].right != -1)printPreorder(Tree[x].right);
}

void printInorder(int x) {
  if(Tree[x].left != -1)printInorder(Tree[x].left);
  printf(" %d", x);
  if(Tree[x].right != -1)printInorder(Tree[x].right);
}

void printPostorder(int x) {
    if(Tree[x].left != -1)printPostorder(Tree[x].left);
    if(Tree[x].right != -1)printPostorder(Tree[x].right);
    printf(" %d", x);
}

int main() {
  int n, i;
  int id, root;

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    Tree[i].parent = -1;
    Tree[i].left = -1;
    Tree[i].right = -1;
  }
  for(i = 0; i < n; i++) {
    scanf("%d", &id);
    scanf("%d", &Tree[id].left);
    if(Tree[id].left != -1) Tree[Tree[id].left].parent = id;
    scanf("%d", &Tree[id].right);
    if(Tree[id].right != -1)Tree[Tree[id].right].parent = id;
  }

  for (i = 0; i < n; i++) {
    if( Tree[i].parent == -1) {
      root = i;
      break;
    }
  }

  printf("Preorder\n");
  printPreorder(i);
  printf("\n");
  printf("Inorder\n");
  printInorder(i);
  printf("\n");
  printf("Postorder\n");
  printPostorder(i);
  printf("\n");

  return 0;
}

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

int main() {
	int n; cin >> n;
	vector<int>p(n); for (int i = 0; i < n; i++)cin >> p[i];
	vector<int>p_sorted = p; sort(p_sorted.begin(), p_sorted.end());
	
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (p[i] != p_sorted[i])cnt++;
	}
	if (cnt > 2)cout << "NO" << endl;
	else cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
    int n; cin >> n;
    int perm[n], p[n], q[n];
    for (int i = 0; i < n; i++) perm[i] = i + 1;
    for (int i = 0; i < n; i++) cin >> p[i];
    for (int i = 0; i < n; i++) cin >> q[i];

    int a = 1;
    do {
        int flag = 1;
        for (int i = 0; i < n; i++) {
            if (perm[i] != p[i]) flag = 0;
        }
        if (flag) break;
        a++;
    } while (next_permutation(perm, perm + n));
    
    sort(perm, perm + n);
    int b = 1;
    do {
        int flag = 1;
        for (int i = 0; i < n; i++) {
            if (perm[i] != q[i]) flag = 0;
        }
        if (flag) break;
        b++;
    } while (next_permutation(perm, perm + n));
    int ans = abs(a - b);
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
W = list(map(int, input().split()))

ans = 10 ** 5
for t in range(1, n):
    S1, S2 = 0, 0
    for i in range(n):
        S1 = sum(W[0:t])
        S2 = sum(W[t:n])
    ans = min(ans, abs(S1 - S2))
print(ans)

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

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

    static class DXorSum2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 尺取りしていけばいい
            int n = in.nextInt();
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
            }

            long cnt = 0;
            long xor = 0;
            long sum = 0;
            int l = 0;
            for (int i = 0; i < n; i++) {
                xor = xor ^ a[i];
                sum = sum + a[i];
                while (xor != sum) {
                    xor = xor ^ a[l];
                    sum = sum - a[l];
                    l++;
                }
                cnt += i - l + 1;
            }
            out.println(cnt);

        }

    }
}



Measured memory_bytes: 84616
class Matrix < Array
  attr_reader :n, :m
  def initialize(arr, row = false, cul = false)
    if (row and cul) or !(Array === arr[0])
      arr.flatten!
      super()
      for i in 0...row ||= arr.length
        self << [*arr[i * cul, cul]]
      end
      @n, @m = row, cul
    elsif Array === arr[0]
      super(arr)
      @n, @m = arr.length, arr[0].length
    else
      raise
    end
  end
  
  def self.e(row = 0)
    result = []
    for i in 0...row
      result << (0...row).map{|num|num == i ? 1: 0}
    end
    return Matrix.new(result)
  end
  
  def *(other)
    if Matrix === other
      return mmul(other)
    elsif Numeric === other
      return self.map{|item|item.map{|i|i * other}}
    end
  end
  
  def dup
    return Matrix.new(self.map(&:dup), @n, @m)
  end
  
  def **(num)
    if num == 0
      return 1
    else
      result = Matrix.e(@n)
      num.to_s(2).each_char{|c|result = result * result * self ** (c.to_i)}
      return result
    end
  end
  
  def to_s
    result = []
    for i in 0...@n
      result << self[i].join(" ")
    end
    return result
  end
  
  def to_ary
    self
  end
  
  private
  def mmul(other)
    result = []
    for i in 0... self.n
      for j in 0... other.m
        temp = 0
        for k in 0... self.m
          temp += self[i][k] * other[k][j]
        end
        result << temp
      end
    end
    return Matrix.new(result, self.n, other.m)
  end
end
class Dice
  def initialize(i, ii, iii, iv, v, vi, ichi = [0, 1, 0], ni = [0, 0, 1], san = [1, 0, 0], posx = 0, posy = 0)
    @att = Matrix.new([ichi, ni, san], 3, 3)
    @num = Array.new([nil, i, ii, iii, iv, v, vi])
    @x, @y = posx, posy
  end
  
  def dup
    return Dice.new(*@num[1..6].dup, *@att.dup, @x, @y)
  end
  
  def getx(i = 1)
    return @num[i * (@att.index{|item|item[0] != 0} + 1) * @att.find{|item|item[0] != 0}[0]]
  end
  
  def gety(i = 1)
    return @num[i * (@att.index{|item|item[1] != 0} + 1) * @att.find{|item|item[1] != 0}[1]]
  end
  
  def getz(i = 1)
    return @num[i * (@att.index{|item|item[2] != 0} + 1) * @att.find{|item|item[2] != 0}[2]]
  end
  
  def rotx(i = 1)
    return self.dup.rotx!(i)
  end
  
  def roty(i = 1)
    return self.dup.roty!(i)
  end
  
  def rotz(i = 1)
    return self.dup.rotz!(i)
  end
  
  def rotx!(i = 1)
    @att *= Matrix.new([[1, 0, 0], [0, 0, -i], [0, i, 0]], 3, 3)
    return self
  end
  
  def roty!(i = 1)
    @att *= Matrix.new([[0, 0, i], [0, 1, 0], [-i, 0, 0]], 3, 3)
    return self
  end
  
  def rotz!(i = 1)
    @att *= Matrix.new([[0, -i, 0], [i, 0, 0], [0, 0, 1]], 3, 3)
    return self
  end
end
order = { "N" => [:rotx!, 1], "E" => [:rotz!, 1], "S" => [:rotx!, -1], "W" => [:rotz!, -1]}
dice = Dice.new(*gets.split(" ").map(&:to_i))
gets.chomp.split(//).each{|com|dice.send(order[com][0], order[com][1])}
puts dice.gety

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int k;
  cin >> k;

  vector<int> a(k);
  for (int i = 0; i < k; ++i)
    cin >> a[i];

  bool poss = 1;
  long long l = 2, r = 2;

  for (int i = k-1; i >= 0; --i) {
    if (((l + a[i] - 1) / a[i]) * a[i] > r) poss = 0;
    else {
      l = ((l + a[i] - 1) / a[i]) * a[i];
      r = (r / a[i]) * a[i] + a[i] - 1;
    } 
  }

  if(poss) cout << l << " " << r << '\n';
  else cout << -1 << '\n';
}


Measured memory_bytes: 640
#!/usr/bin/env ruby
n = gets.chomp.to_i

if n > 81
  puts 'No'
else
  ok = false
  1.upto(9) do |i|
    1.upto(9) do |j|
      if i * j == n
        ok = true
        break
      end
    end
  end

  puts ok ? 'Yes' : 'No'
end


Measured memory_bytes: 14424