akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long int64;
typedef vector<vector<int64> > matrix;
const int64 mod = 1000000009LL;

matrix mul_matrix(const matrix &a, const matrix &b)
{
	const int l = a[0].size();
	const int m = a.size();
	const int r = b.size();

	matrix ret;

	ret.resize(r);
	for(int i = 0; i < r; ++i)
		ret[i].resize(l);

	for(int i = 0; i < r; ++i) {
		for(int j = 0; j < l; ++j) {
			for(int k = 0; k < m; ++k)
				ret[i][j] = (ret[i][j] + a[k][j] * b[i][k] % mod) % mod;
		}
	}

	return ret;
}

void pow_matrix_b(matrix &a, int64 x)
{
	matrix ret;
	const int n = a.size();

	ret.resize(n);
	for(int i = 0; i < n; ++i) {
		ret[i].resize(n, 0);
		ret[i][i] = 1;
	}

	for(int64 i = 1; i <= x; i *= 2) {
		if(i & x)
			ret = mul_matrix(ret, a);
		a = mul_matrix(a, a);
	}

	a = ret;
}

void fall(vector<int64> &v, int64 len)
{
	const int w = v.size();
	matrix f;

	f.resize(w);
	for(int i = 0; i < w; ++i)
		f[i].resize(w, 0);
	for(int i = 0; i < w; ++i) {
		for(int d = -1; d <= 1; ++d) {
			if(0 <= i + d && i + d < w)
				f[i+d][i] = 1;
		}
	}

	pow_matrix_b(f, len);

	matrix m, ret;

	m.push_back(v);
	ret = mul_matrix(f, m);
	v = ret[0];
}

int main()
{
	int case_count = 1;

	while(true) {

		int64 w, h;
		int n;
		vector<pair<int64, int64> > objs;
		vector<int64> v;
		vector<int64> ys;

		scanf("%lld%lld%d", &w, &h, &n);
		if(w == 0)
			break;
		objs.resize(n);
		for(int i = 0; i < n; ++i) {
			scanf("%lld%lld", &objs[i].first, &objs[i].second);
			objs[i].first -= 1; objs[i].second -= 1;
			ys.push_back(objs[i].second);
		}
		ys.push_back(h - 1);
		sort(ys.begin(), ys.end());
		ys.erase(unique(ys.begin(), ys.end()), ys.end());
		v.resize(w, 0);
		v[0] = 1;

		for(int step = 0; step < ys.size(); ++step) {
			int64 y = ys[step];
			int64 len = step > 0 ? y - ys[step - 1] : y;
			fall(v, len);
			for(int i = 0; i < n; ++i) {
				if(objs[i].second == y)
					v[objs[i].first] = 0;
			}
		}

		int64 ans = v[w - 1];
		printf("Case %d: %lld\n", case_count++, ans);
	}

	return 0;
}

Measured memory_bytes: 1192
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int q,cnt=0;
  cin >> s >> q;
  while(q--) {
    int t;
    cin >> t;
    if(t==1) {
      cnt++;
    }
    else if(t==2) {
      int f;
      string c;
      cin >> f >> c;
      if(f==1) {
        if(cnt%2) {
          s.push_back(c[0]);
        }
        else {
          s.insert(0,c);
        }
      }
      else {
        if(cnt%2) {
          s.insert(0,c);
        }
        else {
          s.push_back(c[0]);
        }
      }
    }
  }
  if(cnt%2) {
    for(int i=s.size()-1; i>=0; i--) {
      cout << s[i];
    }
    cout << "\n";
    return 0;
  }
  cout << s << "\n";
}

Measured memory_bytes: 1040
#include<iostream>
#include<algorithm>

using namespace std;
int N, S;
int main() {
  while (cin >> N && N > 0) {
    int sum = 0;
    int m = 1001;
    int M = -1;
    for (int i = 0; i < N; ++i) {
      cin >> S;
      sum += S;
      m = min(m, S);
      M = max(M, S);
    }
    sum = sum - m - M;
    int ans = sum / (N-2);
     cout << ans << endl;
  }
  return 0;
}

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

typedef long long ll;
typedef pair<ll, int> P;
typedef pair<pair<int, int>, int> PP;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

const int MAX = 1100000;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	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;
	}
}

ll COM(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;
}


int main(void) { 
    int X, Y;
    cin >> X >> Y;
    COMinit();
    ll ans = 0;
    for (int a = 0; 2 * a <= X; a++) {
        int b = X - 2 * a;
        if(a + 2 * b == Y){
            ans += COM(a + b, a) % MOD;
            ans %= MOD;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 25984
n, m = map(int, input().split())
ab = sorted([tuple(map(int, input().split())) for i in range(n)])
ans = 0
for i in range(n):
    if m == 0:
        break
    if m - ab[i][1] >= 0:
        m -= ab[i][1]
        ans += ab[i][0] * ab[i][1]
    else:
        ans += ab[i][0] * m
        m = 0
print(ans)

Measured memory_bytes: 17764
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N=1e5;
ll a[N+10],t[N+10],c[N+10];

int main()
{
	int n,Q;scanf("%d %d",&n,&Q);
	int cnt=1;a[1]=n;
	for(int i=1;i<=Q;++i) 
	{
		ll x;scanf("%lld",&x);
		while(cnt&&a[cnt]>=x) --cnt;
		a[++cnt]=x;
	};
	t[cnt]=1;
	for(int i=cnt;i>=1;--i)
	{
		ll k=a[i];int lim=i-1,j;
		while(true)
		{
			j=upper_bound(a+1,a+lim+1,k)-a-1;
			if(!j) break;
			t[j]+=k/a[j]*t[i];k%=a[j];
			lim=j-1;
		};
		c[1]+=t[i];c[k+1]-=t[i];
	};
	for(int i=1;i<=n;++i) c[i]+=c[i-1],printf("%lld\n",c[i]);
	return 0;
}

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

ll N, K;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K;
  if (K == 0) {
    cout << N * N << endl;
    return 0;
  }
  ll ans = 0;
  for (int i = K + 1; i <= N; i++) {
    ans += N / i * (i - K) + max(0LL, N % i - K + 1);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
     
    public class Main {
      public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int X = sc.nextInt();
        int []a = new int[N];
        
        int all = 0;
        for(int i=0; i<N; i++) {
        	 a[i] = sc.nextInt();
        	 for(int j=0; j<D; j++) {
        		 if(D>=j*a[i]+1) {
        			 all++;
        		 }
        	 }
        }
             System.out.println(all+X);
      }
    }

Measured memory_bytes: 35972
use std::io::Read;

fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();

    // 行ごとのiterが取れる
    let mut iter = buf.split_whitespace();
    let problem_counts: usize = iter.next().unwrap().parse().unwrap();
    let target_score: usize = iter.next().unwrap().parse().unwrap();
    let bornases: Vec<(usize, usize, usize)> = (0..problem_counts)
        .enumerate()
        .map(|(i, _)| {
            (
                (i + 1) * 100,
                iter.next().unwrap().parse::<usize>().unwrap(),
                iter.next().unwrap().parse::<usize>().unwrap(),
            )
        })
        .map(|x| (x.0, x.1, x.0 * x.1 + x.2))
        .collect();

    #[derive(Clone, Debug)]
    struct Pattern {
        attempts: usize,
        score: usize,
        another_list: Vec<(usize, usize)>,
    }

    // 各行を選ぶ選ばないパターンを作る
    let mut patterns = Vec::new();
    // 2の3乗の組み合わせを作成
    for i in 0..2usize.pow(problem_counts as u32) {
        let mut row = Pattern {
            attempts: 0,
            score: 0,
            another_list: vec![(
                bornases[problem_counts - 1].0,
                bornases[problem_counts - 1].1,
            )],
        };
        // ビット演算する際の最大桁が1桁目に来るとこで
        // シフトできれば良いので、number.len()-1までloop
        let anothers: Vec<(usize, usize)> = (0..problem_counts)
            .filter(|j| ((i >> j) & 1) != 1)
            .map(|j| (bornases[j].0, bornases[j].1))
            .collect();
        for j in 0..problem_counts {
            // j桁右シフトして最初のbitが1かチェック
            if ((i >> j) & 1) == 1 {
                row = Pattern {
                    attempts: row.attempts + bornases[j].1,
                    score: row.score + bornases[j].2,
                    another_list: anothers.clone(),
                };
            }
        }
        patterns.push(row);
    }

    let mut result = 10000000;
    for pattern in &patterns {
        let mut tmp_count = 0;
        if pattern.score >= target_score {
            tmp_count = pattern.attempts;
        } else {
            let mut current_score = pattern.score;
            tmp_count = pattern.attempts;
            'outer: for anothers in pattern.another_list.iter().rev() {
                for _ in 0..anothers.1 {
                    if current_score < target_score {
                        tmp_count += 1;
                        current_score += anothers.0;
                    } else {
                        break 'outer;
                    }
                }
            }
            if current_score < target_score {
                continue;
            }
        }
        if result > tmp_count && tmp_count != 0 {
            result = tmp_count;
        }
    }

    println!("{}", result);
}


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

const int maxn = 100010;
int n, ans, mask[maxn];
vector<int> G[maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1, u, v; i < n; i++) {
        scanf("%d %d", &u, &v);
        G[u].push_back(v), G[v].push_back(u);
    }
    function<void(int, int)> dfs = [&](int v, int fa) {
        vector<int> cnt(20);
        for (int u : G[v]) if (u ^ fa) {
            dfs(u, v), mask[v] |= mask[u];
            for (int i = 0; i < 20; i++) {
                if (mask[u] >> i & 1) cnt[i]++;
            }
        }
        int cur = 0;
        for (int i = 19; ~i; i--) {
            if (cnt[i] > 1) { cur = i + 1; break; }
        }
        while (mask[v] >> cur & 1) cur++;
        mask[v] |= (1 << cur), ans = max(ans, cur);
        mask[v] = mask[v] >> cur << cur;
    };
    dfs(1, 0), printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 24348
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  long long h,w;
  cin>>h>>w;
  long long ans;
  if(h%3==0){
    cout<<0<<endl;
    return 0;
  }else{
    ans = w;
  }
  if(w%3==0){
    cout<<0<<endl;
    return 0;
  }else{
    ans = min(ans,h);
  }
  long long left;
  long long r1,r2;
  long long m,M;
  REP(i,w){
    if(i==0){
      continue;
    }else{
      left = h*i;
      if(h%2==0){
        r1=(w-i)*h/2;
        ans = min(ans,abs(r1-left));
      }else{
        r1=(w-i)*(h/2);
        r2=(w-i)*((h+1)/2);
        m = min(left,min(r1,r2));
        M = max(left,max(r1,r2));
        ans = min(ans,M-m);
      }
    }
  }
  
  long long u1,u2;
  long long d;
  REP(i,h){
    if(i==0){
      continue;
    }else{
      d = w*i;
      if(w%2==0){
        u1=(h-i)*w/2;
        ans = min(ans,abs(u1-d));
      }else{
        u1=(h-i)*(w/2);
        u2=(h-i)*((w+1)/2);
        m = min(d,min(u1,u2));
        M = max(d,max(u1,u2));
        ans = min(ans,M-m);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}


int main()
{
    int N;
    string s;
    cin >> N >> s;
   
    // RGB
    vector<vector<ll> > dp(N+1, vector<ll>(3, 0));
    
    rep(i,N)
    {
        if( s[i] == 'R' ) dp[i+1][0] = dp[i][0]+1;
        else if( s[i] == 'G' ) dp[i+1][1] = dp[i][1]+1;
        else dp[i+1][2] = dp[i][2]+1;
        rep(j, 3) chmax(dp[i+1][j], dp[i][j]);
    }
    /*
    rep(i,dp.size())
    {
        cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
    }
    */

    ll ans = 0;
    rep(i, N-2)
    {
        REP(j, i+1, N-1)
        {
            ll yet_r = dp[N][0] - dp[j+1][0];
            ll yet_g = dp[N][1] - dp[j+1][1];
            ll yet_b = dp[N][2] - dp[j+1][2];

            if( s[i] == s[j] ) continue;
            else
            {
                if( (s[i] == 'R' || s[i] == 'G')&& (s[j] == 'R' || s[j] == 'G') ) ans += yet_b;
                else if( (s[i] == 'R' || s[i] == 'B')&& (s[j] == 'R' || s[j] == 'B') )ans += yet_g;
                else if( (s[i] == 'G' || s[i] == 'B')&& (s[j] == 'G' || s[j] == 'B') )ans += yet_r;
            }
            
            // j - i == k - j のチェック
            ll k = j + (j - i);
            if( k < N && s[j] != s[k] && s[i] != s[k] ) ans--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>

using namespace std;

// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);

void solve()
{
    long long n, d;
    cin >> n >> d;
    int points = 0;
    long long px, py;
    while (n--)
    {
        cin >> px >> py;
        if (sqrt(px*px + py*py) <= d)
            points++;
    }
    cout << points << '\n';

}

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

    int nCases = 1;
    // cin >> nCases;

    while(nCases--)
        solve();

    return 0;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
pair<int,int> x[505];
int ans[250005],c[505];
int main()
{
	int n,cur=1;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&x[i].first);
		x[i].second=i;
		ans[x[i].first]=i;
	}
	sort(x+1,x+n+1);
	for (int i=1;i<=n;i++)
	{
		int cnt=x[i].second-1;
		while (cnt--)
		{
			while (ans[cur])
			cur++;
			ans[cur]=x[i].second;
		}
	}
	for (int i=1;i<=n;i++)
	{
		int cnt=n-x[i].second;
		while (cnt--)
		{
			while (ans[cur])
			cur++;
			ans[cur]=x[i].second;
		}
	}
	for (int i=1;i<=n*n;i++)
	{
		c[ans[i]]++;
		if (c[ans[i]]==ans[i])
		{
			for (int j=1;j<=n;j++)
			{
				if (x[j].second==ans[i] && x[j].first!=i)
				{
					printf("No");
					return 0;
				}
			}
		}
	}
	printf("Yes\n");
	for (int i=1;i<=n*n;i++)
	printf("%d ",ans[i]);
}

Measured memory_bytes: 2176
#pragma GCC optimize("O3")
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 200000

int main() {
	long long x, y, z;
	long long s, ans;
	scanf("%lld %lld %lld", &x, &y, &z);
	scanf("%lld", &s);
	ans = 0;
	while (x >= y) {
		ans++;
		y *= 2;
	}
	while (y >= z) {
		ans++;
		z *= 2;
	}
	if(ans<=s)printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 1612
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N);
  
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> B.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> C.at(i);
  }
  
  int ans=B.at(A.at(0)-1);
  
  for(int i=1;i<N;i++){
    ans = ans + B.at(A.at(i)-1);
    if(A.at(i-1) == A.at(i)-1){
      ans = ans + C.at(A.at(i-1)-1);
    }
  }
  
  cout << ans << endl;
}

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

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

	double S = a * b * sin(c/180.0 * M_PI) / 2.0;
	double L = a + b + sqrt((a-b*cos(c/180.0*M_PI))*(a-b*cos(c/180.0*M_PI)) + b*sin(c/180.0*M_PI)*b*sin(c/180.0*M_PI));
	double h = b*sin(c/180.0*M_PI);

	printf("%.8f\n%.8f\n%.8f\n", S, L, h);

	return 0;
}

Measured memory_bytes: 1220
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a[3];
    //rep(i, 3) a[i].push_back(-inf);
    rep(i, 3) rep(j, n) {int tmp; cin >> tmp; a[i].push_back(tmp);}
    //rep(i, 3) a[i].push_back(inf);
    rep(i, 3) sort(a[i].begin(), a[i].end());
    ll ans = 0;
    rep(i, n) {
        int bo = lower_bound(a[0].begin(), a[0].end(), a[1][i]) - a[0].begin();
        int up = a[2].end() - upper_bound(a[2].begin(), a[2].end(), a[1][i]);
        //cout << bo << " " << up << endl;
        ans += (ll)up * bo;
    }
    cout << ans << endl;
}



Measured memory_bytes: 1784
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

public class Program
{
    public static void Main(string[] args)
    {
        new Program().Solve(new ConsoleInput(Console.In, ' '));
    }

    public void Solve(ConsoleInput cin)
    {
        var s = cin.ReadLine;
        var result = 0;
        for (int i = 0; i < s.Length/2; i++)
        {
            if (s[i] != s[s.Length - i-1])
                result++;
        }
        WriteLine(result);
        ReadKey();
    }
}

public class ConsoleInput
{
    private readonly System.IO.TextReader _stream;
    private char _separator = ' ';
    private Queue<string> inputStream;
    public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
    {
        this._separator = separator;
        this._stream = stream;
        inputStream = new Queue<string>();
    }
    public string Read
    {
        get
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(_separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
    }
    public string ReadLine { get { return _stream.ReadLine(); } }
    public int ReadInt { get { return int.Parse(Read); } }
    public long ReadLong { get { return long.Parse(Read); } }
    public double ReadDouble { get { return double.Parse(Read); } }
    public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
    public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
    public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
}

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

signed main(){
  string s,u;cin>>s;bool f=1;
  int q;cin>>q;
  while(q--){
    int t;cin>>t;
    if(t==1)f^=1;
    else{
      int a;char c;cin>>a>>c;
      if((a==1)^f)s+=c;
      else u+=c;
    }
  }
  reverse(u.begin(),u.end());
  u+=s;
  if(!f)reverse(u.begin(),u.end());
  cout<<u<<endl;
}


Measured memory_bytes: 1128
#include<iostream>
#include<vector>
#include<string>
#include<cmath>

using ll = long long;
const ll MAX = 1e15 + 5;

int main(){
    ll x, k, d;
    std::cin >> x >> k >> d;

    ll ans = MAX;
    if(x == 0LL){
        if(k % 2 == 0) ans = 0;
        else ans = std::abs(d);
    }else{
        ll i;
        long double tmp = (long double)(x) / (long double)(2 * d) + (long double)(k) / 2.0;
        i = std::ceil(tmp);
        if(i >= 0 && i <= k) ans = std::min(ans, std::abs(x + d * (k - 2 * i)));
        i = std::floor(tmp);
        if(i >= 0 && i <= k) ans = std::min(ans, std::abs(x + d * (k - 2 * i)));
        if(ans == MAX){
            ans = std::min(ans, std::abs(x + d * k));
            ans = std::min(ans, std::abs(x - d * k));
        }
    }

    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3676
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int m = Integer.parseInt(in[1]);

        String[] a[] = new String[n][n];
        for(int i=0; i<n; i++){
            a[i] = br.readLine().split("");
        }

        String[] b[] = new String[m][m];
        for(int i=0; i<m; i++){
            b[i] = br.readLine().split("");
        }


        for(int i=0; i<n-m+1; i++){
            for(int j=0; j<n-m+1; j++){

                boolean match = true;
                for(int k=0; k<m; k++){
                    for(int l=0; l<m; l++){
                        if(!a[i+k][j+l].equals(b[k][l])) match = false;
                        if(!match) break;
                    }
                    if(!match) break;

                }

                if(match){
                    System.out.println("Yes");
                    System.exit(0);
                }
            }
        }

        System.out.println("No");
    }
}



Measured memory_bytes: 21588
import java.io.*;
import java.util.StringTokenizer;
import static java.lang.Math.*;

public class Main {
  public static void main(String[] args) {
    new Main().solve();
  }

  private void solve() {
    try(InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out)) {

      int n = Integer.parseInt(in.nextLine().replace(" ", ""));
      String ans = n % 4 == 0 ? "YES" : "NO";
      out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  int atoi(String s) { return Integer.parseInt(s); }
  long atol(String s) { return Long.parseLong(s); }

  static class InputReader implements AutoCloseable {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream), 32768);
      st = null;
    }

    public String nextLine() throws IOException {
      return br.readLine();
    }
    public String next() {
      if (st == null || !st.hasMoreTokens()) {
        try { st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          throw new UncheckedIOException(e);
        }
      }
      return st.nextToken();
    }
    public int nextInt() { return Integer.parseInt(next()); }
    public long nextLong() { return Long.parseLong(next()); }
    int[] mapInt(int len) {
      int[] ret = new int[len];
      for (int i = 0; i < len; i++) ret[i] = Integer.parseInt(next());
      return ret;
    }
    long[] mapLong(int len) {
      long[] ret = new long[len];
      for (int i = 0; i < len; i++) ret[i] = Long.parseLong(next());
      return ret;
    }
    @Override public void close() throws IOException { br.close(); }
  }
}

Measured memory_bytes: 20692
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  scanf("%d", &n);

  int c[1000], s[1000], f[1000];
  REP(i,n - 1){
    scanf("%d %d %d", &c[i], &s[i], &f[i]);
  }

  REP(i,n){
    int t = 0;
    FOR(j,i,n - 1){
      if(i == j){
        t += s[i] + c[i];
      }else{
        if(t <= s[j]){
          t = s[j] + c[j];
        }else{
          if(t % f[j] == 0){
            t += c[j];
          }else{
            t += f[j] - (t % f[j]) + c[j];
          }
        }
      }
    }
    printf("%d\n", t);
  }

  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int n, x, i, j;
	while (1) {
		scanf("%d %d", &n, &x);
		if(n == 0 && x == 0) break;

		int cnt = 0;
		for (i = 1; i < x / 3 ; i++) {
			for (j = n; j > (x - i)/ 2 ; j--) {
				if(i < x-i-j && x -i-j < j) cnt++;
			}
		}
		printf("%d\n", cnt);
	}

    return 0;
}


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


//TEMPLATE
#define pb              push_back
#define mp              make_pair
#define ll              long long
#define ld              long double
//#define pi              3.1415926536
#define pi              acos(-1)
#define newline         printf("\n")
#define printminusone   printf("-1\n")
#define scl1(n)         scanf("%lld", &n)
#define scl2(a, b)      scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)   scanf("%lld %lld %lld", &a, &b, &c)
#define printl(n)       printf("%lld\n", n)
#define ssl1(str)       scanf(" %[^\n]", str)
#define scd1(n)         scanf("%lf", &n)
#define scd2(a, b)      scanf("%lf %lf", &a, &b)
#define printd(n)       printf("%lf\n", n)
#define printld(n)      printf("%Lf\n", n)
#define printcase       printf("Case %lld: ", i)
#define reversed(s)     reverse(s.begin(), s.end())
#define asort(s)        sort(s.begin(), s.end())
#define dsort(s)        sort(s.rbegin(), s.rend())
#define for0(i, n)      for (i = 0; i < n; i++)
#define for1(i, n)      for (i = 1; i <= n; i++)
#define fori(itt, stt)  for(auto itt = stt.begin(); itt != stt.end(); itt++)
#define pii             pair <ll, ll>
#define piii            pair <ll, pii>
#define F               first
#define S               second
#define FR              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(arr, x)      memset(arr, x, sizeof arr)
#define bitcount(n)     __builtin_popcountll(n)
#define all(s)          s.begin(), s.end()

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;




int main() {
    ll t = 0, n, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0;
    string s, s1, s2;

    cin >> x >> y;
    cout << x*y << "\n";

    return 0;
}



Measured memory_bytes: 3588
n, m, k = map(int, input().split())

if k == 0:
    print('Yes')
    exit()
if k % n == 0 or k % m == 0:
    print('Yes')
    exit()
for i in range(n+1):
    for j in range(m+1):
        area = i*j + (n-i) * (m-j)
        if k == area:
            print('Yes')
            exit()
print('No')

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

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

    int cnt = 1;
    int m = p[0];
    for (int i = 1; i < n; i++) {

        if(m>p[i]){
            cnt++;
            m = p[i];
        }
    }

        cout << cnt << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

#include<bits/stdc++.h>
#include<iomanip>
#define inf  (int)1e18
#define EPS   1e-9
#define mod 1000000007
#define all(k) sort(k.begin(),k.end())
#define Pi 3.14159
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define repk(i,a,n) for(int i=a;i<=(n);i++)
#define ll long long
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define vc vector<char>
#define vl vector<ll>
#define mi map<int,int>
#define ml map<ll,ll>
#define umap unordered_map<ll,int>
using namespace std;

ll int togglebit(ll int n)
{
	if (n == 0)
		return 1;


	ll int i = n;

	n |= n >> 1;


	n |= n >> 2;
	n |= n >> 4;
	n |= n >> 8;
	n |= n >> 16;

	return i ^ n;
}

void sol() {
	ll n; cin >> n;

	vpl v;
	ll x, y;
	rep(i, 0, n) {

		cin >> x >> y;
		v.pb(pl(x, y));
	}

	double sum = 0.0;
	rep(i, 0, n - 1 ) {
		rep(j, i + 1, n) {
			sum += sqrt((double)pow((v[i].F - v[j].F), 2) + (double)pow((v[i].S - v[j].S), 2));
		}
	}


	cout << fixed;
	cout << setprecision(10) << sum * 2.0 / n;

}
int main() {


	int t = 1;
	// cin >> t;

	for (int i = 0; i < t; ++i)
		sol();


	return 0;
}



Measured memory_bytes: 3720
#include <cstdio>
#include <string>

int check(const std::string& str) {
  std::string s = str;
  while (!s.empty()) {
    s.pop_back();
    size_t size = s.size();
    if (size % 2 != 0) {
      continue;
    }
    std::string s1 = s.substr(0, size / 2);
    std::string s2 = s.substr(size / 2, size / 2);
    if (s1 == s2) {
      return size;
    }
  }
  return 0;
}

int main() {
  char tmp[256];
  std::scanf("%s", tmp);
  std::string str(tmp);
  std::printf("%d\n", check(str));

  return 0;
}


Measured memory_bytes: 256
/* blog : https://misteer.hatenablog.com/entry/AGC036-A */

#include <iostream>
#include <vector>
#include <cassert>

using namespace std;
using lint = long long;

// Z * Z < Sを満たす最小のZを求める
lint sqrti(lint S) {
    lint ok = 0, ng = 1e9 + 1;
    while (ng - ok > 1) {
        lint mid = (ok + ng) / 2;
        (mid * mid < S ? ok : ng) = mid;
    }
    return ok;
}

int main() {
    lint S;
    cin >> S;
    lint Z = sqrti(S);

    vector<lint> X(3), Y(3);
    X[0] = Y[0] = 0, X[2] = 1;

    if (S <= Z * (Z + 1)) {
        Y[1] = Z * (Z + 1) - S;
        X[1] = Z, Y[2] = Z + 1;
    } else {
        Y[1] = (Z + 1) * (Z + 1) - S;
        X[1] = Y[2] = Z + 1;
    }

    assert(X[1] * Y[2] - X[2] * Y[1] == S);
    for (int i = 0; i < 3; ++i) {
        assert(X[i] <= 1e9);
        assert(Y[i] <= 1e9);
        cout << X[i] << " " << Y[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 384
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
   
    int N;
    cin>>N;
    
    if(N<1000){
        cout<<"ABC"<<endl;
    }else{
        cout<<"ABD"<<endl;
    }
    
        

    return 0;
   
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin>>s;
    if(s.back()!='s'){
        cout<<s+'s'<<endl;
    }
    else{
        cout<<s+"es"<<endl;
    }

    return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using mat = vector<vector<ll>>;
using arr = vector<ll>;
constexpr ll MOD = 1000000007;

ll n, k;

mat mul(mat& a, mat& b) {
  mat c(n, arr(n));
  REP(i, n) REP(j, n) REP(k, n) {
    c[i][j] += a[i][k] * b[k][j] % MOD;
    c[i][j] %= MOD;
  }
  return c;
}

mat pow(mat& a, ll e) {
  mat res(n, arr(n));
  REP(i, n) res[i][i] = 1;
  while(e){
    if (e&1) res = mul(res, a);
    a = mul(a, a);
    e >>= 1;
  }
  return res;
}

int main()
{
  cin >> n >> k;
  mat a(n, arr(n));
  REP(i, n) REP(j, n) cin >> a[i][j];
  auto res = pow(a, k);

  ll ans = 0;
  REP(i, n) REP(j, n) ans = (ans + res[i][j]) % MOD;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <string>
#define mod 1000000007
#define INF LLONG_MAX
#define loop(i,x,n) for(int i = x; i < n; i++)
#define pb push_back
#define mp make_pair
#define ll long long 
#define vpl vector< pair<ll,ll> >
#define vpi vector< pair<int,int> >
#define vi vector<int>
#define vl vector<ll>
#define vch vector<char>
#define se second
#define fi first
using namespace std;
 
ll solve(ll wts[],int pro[],int N,ll W,int sum){
	
	ll dp[N+1][sum+1];
	
	for(int i=0;i<=N;i++){
		for(int j=0;j<=sum;j++){
			dp[i][j] = W+1;
		}
	}
	
	dp[0][0] = 0;
	for(int n=1;n<=N;n++){
		for(int p=0;p<=sum;p++){
			ll inc = W+1, exc = W+1;
			if(pro[n-1] <= p){
				inc = wts[n-1] + dp[n-1][p - pro[n-1]];
			}
			exc = dp[n-1][p];
			
			dp[n][p] = min(inc,exc);
		}
	}
	
	ll ans = 0;
	for(int j=1;j<=sum;j++){
		if(dp[N][j] <= W){
			ans = j;
		}
	}
	
	
	
	return ans;
}
 
 
int main() 
{ 
 	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	ll w;
	
	cin >> n >> w;
	
	ll wts[n];
	int pro[n];
	
	//int sum = 0;
	
	for(int i=0;i<n;i++){
		cin >> wts[i] >> pro[i];
		//sum += pro[i];
	}
	
	cout << solve(wts,pro,n,w,100000) << "\n";
	
	
	return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N; cin >> N;
    string S; cin >> S;
    int ans = 0;
    int pos = -1;
    while(true)
    {
        pos = S.find("ABC", pos+1);
        if(pos == -1) break;
        ans++;
    }
    cout << ans << endl;
} 
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int a,b;
  string s;
  cin>>a>>s>>b;
  if(s=="+")cout<<(a+b)<<endl;
  else cout<<(a-b)<<endl;
  return 0;
}


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

const int MAX_N = 3010;

int N, T, S;
int A[MAX_N], B[MAX_N];

int dp[MAX_N][MAX_N];

int solve() {
  fill(dp[0],dp[MAX_N],0);
  for(int i = 1; i <= N; ++i) {
    for(int j = 1; j <= T; ++j) {
      dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      if(j-B[i] < 0) continue;
      int begin, end;
      begin = j-B[i];
      end = j;
      if(begin < S && S < end) continue;
      dp[i][j] = max(dp[i][j], dp[i-1][j-B[i]] + A[i]);
    }
  }

  /*  for(int i = 1; i <= N; ++i) {
    for(int j = 0; j <= T; ++j) {
      if(j) cout << " ";
      cout << dp[i][j];
    }
    cout << endl;
  }
  */
  return dp[N][T];
}

int main() {
  while(cin >> N >> T >> S) {
    for(int i = 1; i <= N; ++i)
      cin >> A[i] >> B[i];
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 35000
//bismillah
//created by anaksoleh
//24 Nov 2019
#include <bits/stdc++.h>
using namespace std;

#define INF 100000000
#define SIZE 100009
int N;
int arr[SIZE];
bool computed[SIZE];
int val[SIZE];

int solve(int num)
{
    // Solve using top - bottom
    if(num < 1)return INF;
    if(num == 1)return 0;
    if(computed[num])return val[num];
    int best = min(solve(num - 1) + abs(arr[num] - arr[num - 1]) ,solve(num - 2) + abs(arr[num] - arr[num - 2]));
    computed[num] = true;
    val[num] = best;
    return best;
}


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

    cin >> N;
    for(int i = 1 ; i <= N ; i++){
        cin >> arr[i];
    }
    cout << solve(N) << '\n';
    return 0;
}


Measured memory_bytes: 2688
#include<cstdio>
#include<iostream>
using namespace std;
int f[110][110][2];
int n,m;
char s[110][110]; 
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for (int i=0;i<=n;i++)for (int j=0;j<=m;j++) f[i][j][0]=f[i][j][1]=1e9;
	if (s[1][1]=='.') f[1][1][0]=0;
	else f[1][1][1]=1;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		{
			if (i==j&&i==1) continue;
			if (s[i][j]=='.') f[i][j][0]=min(min(f[i-1][j][0],f[i][j-1][0]),min(f[i-1][j][1],f[i][j-1][1]));
			else f[i][j][1]=min(min(f[i-1][j][0],f[i][j-1][0])+1,min(f[i-1][j][1],f[i][j-1][1]));
		}
	printf("%d",min(f[n][m][0],f[n][m][1]));
}


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

int main(){
	string a;
	cin>>a;
	if(a[0]==a[1]&&a[1]==a[2]||a[1]==a[2]&&a[2]==a[3]) cout<<"Yes";
	else cout<<"No";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;
#define ll long long

int d = 365;
//int k = 0;
vector<vector<int>> s(d, vector<int>(26, 0));
vector<ll> c(26);

void init() {
    cin >> d;
    for(int i = 0; i < 26; i++) cin >> c[i];
    for(int i = 0; i < d; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    return;
}

ll calc(vector<int> out) {
    ll score = 0;
    vector<ll> last(26, 0);
    for(int i = 0; i < out.size(); i++) {
        last[out[i]] = i+1; // タイプ番号
        for(int j = 0; j < 26; j++) {
            score -= c[j]*((i+1)-last[j]);
        }
        score += s[i][out[i]];
        //cout << "score : " << score << endl;
    }
    
    //cout << p << endl;
    //if(out.size() >= d) return score;
    //cout << k << endl;
    //cout << out.size() << " " << d << endl;
    //int p = min(int(out.size()+k), d);
    //int k = 13;
    //int p = min(int(out.size()+k), d);
    /*
    ll q = LLONG_MIN;
    for(int k = 0; k < 26; k++) {
        int p = min(int(out.size()+k), int(d));
        ll tmp = 0;
        for(int i = out.size(); i < p; i++) {
            for(int j = 0; j < 26; j++) {
                //score -= c[j]*((i)-last[j]);
                tmp -= c[j]*((i)-last[j]);
            }
        }
        if(tmp > q) {
            q = tmp;
        }
    }
    */

    int k = 10;
    int p = min(int(out.size()+k), int(d));
    for(int i = out.size(); i < p; i++) {
        for(int j = 0; j < 26; j++) {
            score -= c[j]*((i)-last[j]);
            //tmp -= c[j]*((i)-last[j]);
        }
    }
    return score;
}

/*
vector<int> proc(int k) {
    vector<int> out;
    ll ans = 0;
    //ll tmp = 0;
    ll max_v = -1;
    //for(int k = 0; k < 26; k++) {
    //cout << "k: " << k << endl;
    //vector<int> out;
    for(int i = 0; i < d; i++) {
        //max_v = -100000000000;
        max_v = LLONG_MIN;
        int best = 0;
        for(int j = 0; j < 26; j++) {
            out.push_back(j);
            ll tmp = calc(out);
            if(max_v < tmp) {
                max_v = tmp;
                best = j;
            }
            out.pop_back();
        }
        out.push_back(best);
    }
    //}
    return out;
}
*/

int main() {
    init();
    
    vector<int> out;
    ll ans = 0;
    ll max_v = -1;
    //for(int k = 0; k < 26; k++) {
        //cout << "k: " << k << endl;
        //vector<int> out;
    for(int i = 0; i < d; i++) {
        //max_v = -100000000000;
        max_v = LLONG_MIN;
        int best = 0;
        for(int j = 0; j < 26; j++) {
            out.push_back(j);
            //for(int k = 0; k < 26; k++) {
            ll tmp = calc(out);
            if(max_v < tmp) {
                max_v = tmp;
                best = j;
            }
            //}
            out.pop_back();
        }
        out.push_back(best);
    }
    //}
    
    for(int i = 0; i < d; i++) {
        cout << out[i]+1 << endl;
    }
    //cout << max_v << endl;
    return 0;
}

Measured memory_bytes: 3704
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr> () -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut vec: Vec<usize> = Vec::new();
    for _ in 0..n {
        vec.push(read::<usize>());
    }

    let mut count: usize = 0;
    for i in 1..(n-1) {
        if ((vec[i-1] < vec[i]) && (vec[i] < vec[i+1])) || 
            ((vec[i-1] > vec[i]) && (vec[i] > vec[i+1])) {
            count += 1;
        }
    }
    println!("{}", count);
}



Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; 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;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x /gcd(x, y) * y );
}

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}


ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
char c[2010][2010];
ll a[20][20];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>a(n), res(n);
	rep(i, n) {
		cin >> a[i];
		res[i] = i + 1;
	}
	ll res2 = 0;
	rep(i, n) {
		if (a[i] != res[i])res2++;
	}
	if (res2 <= 2)puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 
  int64_t n;
  cin>>n;

 
  int64_t max_wk=0;
  for(int64_t i=1;i*i<=n;i++){
      max_wk=max(i*i,max_wk);
  }

  cout<<max_wk<<endl;

	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    int a, b; cin >> a >> b;
    int n_l = 0, n_m = 0, n_u = 0;
    rep(i,n) {
        int x; cin >> x;
        if (x <= a) n_l++;
        if (a < x && x <= b) n_m++;
        if (b < x) n_u++;
    }
    int ans = min({n_l,n_m,n_u});
    cout << ans << endl;
}

Measured memory_bytes: 3560