akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
	int N, M;
	std::cin >> N >> M;

	int sum{};
  
	std::vector<int> data(N);
	for(int i = 0; i < N; ++i) {
    	std::cin >> data[i];
		sum += data[i];
    }

	double line = sum / (4.0*M);
  
	std::cout << ((std::count_if(data.begin(), data.end(), [=](int n){return n>=line;}) >= M) ? "Yes" : "No") << std::endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
int const MOD = 1000000007;
#define END {cout<<END<<'\n'; return 0;}
#define ALL(vec) vec.begin(),vec.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,s,n) for(int i=s; i<n; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n';
template<class T> inline bool cmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool cmax(T& a, T b) { if (a < b) { return a = b; } return false; }

int n,m,q,_,x,y;
string s,t;
bool ok;
char ch;
struct c{
  char k; int id,v;
};

int main(){
  cin.tie(0); ios::sync_with_stdio(false);
    
  cin>>n; V(c)a(n),b;
  rep(i,n){
    cin>>ch; a[i].k=ch;
    cin>>ch; a[i].v=ch-'0';
    a[i].id=i;
  }
  b=a;
  rep(i,n)gnr(j,i+1,n-1){
    if(a[j].v<a[j-1].v)swap(a[j],a[j-1]);
  }
  rep(i,n){
    m=i;
    rer(j,i+1,n)if(b[j].v<b[m].v)m=j;
    swap(b[i],b[m]);
  }
  s="Stable";
  rep(i,n-1)if(b[i].v==b[i+1].v&&b[i].id>b[i+1].id)s="Not stable";
  rep(i,n)cout<<a[i].k<<a[i].v<<(i==n-1?'\n':' ');
  pri1("Stable");
  rep(i,n)cout<<b[i].k<<b[i].v<<(i==n-1?'\n':' ');
  pri1(s);
}


Measured memory_bytes: 3204
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e6+3)
#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 ALL(x) (x).begin(),(x).end()
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

ll modpow(ll x, ll n) {
    if(n==0){
        return 1;
    }else if(n%2==0){
        ll h = modpow(x,n/2);
        return h * h % MOD;
    } else {
        return x * modpow(x,n-1) % MOD;
    }
}

int main() {
  int Q; cin >> Q;
  ll x, d, n;
  vector<ll> X, D, N;
  rep(i,Q){
    cin >> x >> d >> n;
    X.push_back(x);
    D.push_back(d);
    N.push_back(n);
  }
  vector<ll> kaijo;
  kaijo.push_back(1);
  reps(i,MOD){
    kaijo.push_back((kaijo[i-1]*i)%MOD);
  }

  rep(i,Q){
    x = X[i]; d = D[i]; n = N[i];
    if(d==0){
      cout << modpow(x,n)%MOD << endl;
    }else{

      ll a = (x * modpow(d,MOD-2))%MOD;
      ll b = (x * modpow(d,MOD-2) + n - 1)%MOD;
      if((a > b)||(n>=MOD)||(a == 0)){
        cout << 0 << endl;
      }else{
        cout << kaijo[b] * modpow(kaijo[a-1],MOD-2) % MOD * modpow(d,n) % MOD << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 12888
#include<iostream>
 
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int dem = 0;
	int x = a;
	while (x <= b)
	{
		if (c % x == 0)
			dem++;
		x++;
	}
	cout<<dem<<endl;
	return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    unsigned int A,B;
    cin >> A >> B;

    if((A+B)%2==0)
    {
        cout << (A+B)/2 << endl;
        return 0;
    }

    cout <<  "IMPOSSIBLE" << endl;
   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

int main(){
    ll ans = 0;
    int n, m; cin >> n >> m;
    vector<pair<int,int>> a(n);
    rep(i,n) cin >> a[i].first >> a[i].second;

    sort(a.begin(),a.end());

    for(int i = 0, cnt = 0; cnt < m; i++){
        for(int j = 0; j < a[i].second; j++){
            if(cnt >= m){ break; }
            ans += a[i].first;
            cnt++;
        }
    }

    put(ans);
}

Measured memory_bytes: 1024
n = int(input())
ac, wa, tle, re = 0, 0, 0, 0
i = 0
while i < n:
    c = input()
    if c == "AC":
        ac += 1
    elif c == "WA":
        wa += 1
    elif c == "TLE":
        tle += 1
    elif c == "RE":
        re += 1
    i += 1

print("AC x ", ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)


Measured memory_bytes: 9196
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      abs: [(usize, usize); 3],
    }

    let mut s = vec![0; 4];
    for &(a, b) in abs.iter() {
        s[a-1] += 1;
        s[b-1] += 1;
    }
    for i in 0..4 {
        if s[i] > 2 {
            return println!("{}", "NO");
        }
    }
    println!("{}", "YES");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    int x, a, ans=0; cin >> x >> a;
    if(x>=a) ans = 10;
    cout << ans << endl;

}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  int btn = 1, ans = 0;

  for (int i = 0; i < N; i++) {
    btn = A.at(btn - 1), ans++;
    if (btn == 2) {
      cout << ans << "\n";
      return 0;
    }
  }

  cout << -1 << "\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	string S,T; cin >> S >> T;
	int ans = 0;
	for (int i = 0; i < S.size(); ++i) {
		if (S[i] != T[i]) ans++;
	}
	cout << ans << endl;
	return;
}
int main() {
	solve();
	return 0;
}

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

int main() {
  long long x;
  cin >> x;
  
  long long account = 100;
  int count = 0;
  while (1) {
    if (account >= x) break;
    
    account += account * 0.01;
    count++;
  }
  
  cout << count << endl;
}


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

int main(){
  int N;
  cin>>N;
  vector<int> d(N);
  for(int i=0;i<N;i++){
    cin>>d.at(i);
  }
  sort(d.begin(),d.end());
  if(N%2==1){
    cout<<0<<endl;
  }else if(d.at(N/2-1)==d.at(N/2)){
    cout<<0<<endl;
  }else{
    cout<<d.at(N/2)-d.at(N/2-1)<<endl;
  }
}

Measured memory_bytes: 640
class Stack():
    def __init__(self, max_size = 10):
        self.top = 0
        self.max = max_size
        self.s = [None for _ in range(self.max)]
    def is_empty(self):
        return self.top == 0

    def is_full(self):
        return self.top >= self.max - 1

    def push(self, x):
        if self.is_full():
            print('Error: Stack Overflow')
        self.top += 1
        self.s[self.top] = x

    def pop(self):
        if self.is_empty():
            print('Error: Stack Underflow')
        self.top -= 1
        return self.s[self.top + 1]


line = input().split()
stack = Stack(len(line))

for i in line:
    try:
        i = int(i)
    except:
        i = str(i)

    if type(i) == int:
        stack.push(i)
    else:
        num2 = stack.pop()
        num1 = stack.pop()
        if i == '+':
            stack.push(num1 + num2)
        elif i == '-':
            stack.push(num1 - num2)
        elif i == '*':
            stack.push(num1 * num2)

print(stack.pop())


Measured memory_bytes: 5608
using System;
using System.IO;
using System.Text;
using static Scanner;
using static System.Math;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Solve();
        Console.Out.Flush();
    }
    static void Solve() {
        var S = Scan().AsSpan();
        var dp = new long[S.Length + 1];
        for (int i = 0; i < S.Length; i++) {
            if (S[i] == '<') dp[i + 1] = dp[i] + 1;
        }
        for (int i = S.Length - 1; i >= 0; i--) {
            if (S[i] == '>') dp[i] = Max(dp[i], dp[i + 1] + 1);
        }
        long answer = 0;
        foreach (var v in dp) answer += v;
        Console.WriteLine(answer);
    }
}

public static class Scanner
{
    static readonly Stream stdin = Console.OpenStandardInput();
    static readonly byte[] buffer = new byte[1024];
    static int length, p;
    static bool isEof;
    private static byte StdIn() {
        if (isEof) return 0;
        if (p < length) return buffer[p++];
        p = 0;
        if ((length = stdin.Read(buffer, 0, 1024)) > 0) return buffer[p++];
        isEof = true;
        return 0;
    }
    public static char GetChar() {
        var by = StdIn();
        while ((by < '!' || '~' < by) && !isEof) by = StdIn();
        return (char) by;
    }
    public static string Scan() {
        var sb = new StringBuilder();
        for (var ch = GetChar(); '!' <= ch && ch <= '~'; ch = (char) StdIn()) {
            sb.Append(ch);
        }
        return sb.ToString();
    }
}

Measured memory_bytes: 29684
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc111_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().ToCharArray();
            for (int i = 0; i < str.Length; i++)
            {
                if(str[i] == '1') str[i] = '9';
                else if(str[i] == '9') str[i] = '1';
            }

            WriteLine(str);
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n=1001;
  ll d[n];
  d[0]=0;
  REP(i,1,n) d[i]=d[i-1]+i;
  ll a,b;
  cin >> a >> b;
  ll x=b-a;
  pr(d[x]-b);
}

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


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

int main() {
int N;
  int count = 0;
  cin >> N;
  vector<int> p(N);
  for(int a = 0;a < N;a++){
   cin >> p[a];
    if(p[a] != a + 1)count++;
  }
  if(count <= 2){
    cout << "YES" << endl;
  }else{
   cout << "NO" << endl; 
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i; i<(n); i++)
using namespace std;

  
int main() {

  string a;
  cin >> a;
  
  int ans = a.size();
  
  for(int j=0; j<2; j++)
  {
    int cnt = 0;

    for(int i=0; i<a.size(); i++)
    {
      // 奇数番目
      if(i%2==0)
      {
        if(a[i]==char('0'+j)) cnt++;
      }
      // 偶数番目
      if(i%2!=0)
      {
        if(a[i]!=char('0'+j)) cnt++;
      }
    }
    
    ans = min(ans,cnt);
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 512
use input::{Input, ReadMode};

fn main() {
    let mut input = Input::new(ReadMode::Line);

    let s = input.parse::<String>();
    let t = input.parse::<String>();

    if &s == &t[..t.len() - 1] {
        println!("Yes");
    } else {
        println!("No");
    }
}

#[allow(dead_code)]
pub mod input {
    use std::io::{BufRead, Read};

    pub enum ReadMode {
        Full,
        Line,
    }

    pub struct Input<'a> {
        lock: std::io::StdinLock<'static>,
        iter: Option<std::str::SplitAsciiWhitespace<'a>>,
        mode: ReadMode,
    }

    impl<'a> Input<'a> {
        fn naive_read(&mut self) -> Option<std::str::SplitAsciiWhitespace<'a>> {
            let mut s = Box::leak(Box::new(String::new()));
            let res = match self.mode {
                ReadMode::Full => self.lock.read_to_string(&mut s),
                ReadMode::Line => self.lock.read_line(&mut s),
            };
            res.ok().expect("failed to read");
            Some(s.split_ascii_whitespace())
        }
        pub fn new(mode: ReadMode) -> Self {
            let lock = Box::leak(Box::new(std::io::stdin())).lock();
            let iter = None;
            Self { lock, iter, mode }
        }
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            self.lock.read_line(&mut s).ok().expect("failed to read");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            match &mut self.iter {
                Some(iter) => {
                    let x = if let Some(x) = iter.next() {
                        x
                    } else {
                        self.iter = self.naive_read();
                        self.iter.as_mut().unwrap().next().expect("reached EOF")
                    };
                    x.parse().ok().expect("failed to parse")
                }
                None => {
                    self.iter = self.naive_read();
                    self.parse()
                }
            }
        }
    }
}


Measured memory_bytes: 2120
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;
typedef pair<int, int> P;   //cost, to
static const int INF = 1e9;
static const int SIZE = 101;
int par[SIZE];
int rk[SIZE];
int d[SIZE];
int n;

struct edge
{
	int u, v, cost;
};

struct edge2
{
	int to, cost;
};

bool comp(const edge& e1, const edge& e2)
{
	return(e1.cost < e2.cost);
}

void init()
{
	for (int i = 0; i < SIZE; ++i)
	{
		par[i] = i;
		rk[i] = 0;
	}
}

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

void unite(int a, int b)
{
	int x = find(a);
	int y = find(b);
	if (x == y)
	{
		return;
	}
	if (rk[x] < rk[y])
	{
		par[x] = y;
	}
	else
	{
		par[y] = x;
		if (rk[x] == rk[y])
		{
			++rk[x];
		}
	}
}

bool same(int a, int b)
{
	return(find(a) == find(b));
}

int kruskal(vector<edge>& es)
{
	init();
	int res = 0;
	sort(es.begin(), es.end(), comp);
	for (int i = 0; i < es.size(); ++i)
	{
		edge e = es[i];
		if (!same(e.u, e.v))
		{
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return(res);
}

int prim(vector<edge2>* G)
{
	vector<bool> isUsed(n);
	for (int i = 0; i < n; ++i)
	{
		isUsed[i] = false;
	}
	priority_queue<P, vector<P>, greater<P> > pque;
	P p = make_pair(0, 0);
	pque.push(p);
	int res = 0;
	while (!pque.empty())
	{
		P p = pque.top();
		pque.pop();
		int v = p.second;
		if (isUsed[v])
		{
			continue;
		}
		isUsed[v] = true;
		res += p.first;
		for (int i = 0; i < G[v].size(); ++i)
		{
			edge2 e = G[v][i];
			pque.push(P(e.cost, e.to));
		}
	}
	return(res);
}


void solve()
{
	cin >> n;

// For Kruskal
	vector<edge> es;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			int cost;
			cin >> cost;
			if (cost != -1)
			{
				edge e;
				e.u = i;
				e.v = j;
				e.cost = cost;
				es.push_back(e);
			}
		}
	}
	cout << kruskal(es) << endl;

// For Prim
	//vector<edge2> G[SIZE];
	//for (int i = 0; i < n; ++i)
	//{
	//	for (int j = 0; j < n; ++j)
	//	{
	//		int cost;
	//		cin >> cost;
	//		if (j >= i && cost != -1)
	//		{
	//			edge2 e1, e2;
	//			e1.to = j;
	//			e1.cost = cost;
	//			e2.to = i;
	//			e2.cost = cost;
	//			G[i].push_back(e1);
	//			G[j].push_back(e2);
	//		}
	//	}
	//}
	//cout << prim(G) << endl;
}

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

Measured memory_bytes: 1344
#include <cmath>
#include <iostream>

using namespace std;
using ll = long long;

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

int main() {
  int n, k;
  cin >> n >> k;

  // double ans = 0;
  // for (int i = 1; i <= n; ++i) {
  //   if (i >= k) {
  //     ans += (double)(n - i + 1) / n;
  //     break;
  //   }
  //   int r = log2(k / i) + 1;
  //   ans += 1.0 / (n * pow(2, r));
  // }

  double ans = 0;
  for (int i = 1; i <= n; ++i) {
    int now = i;
    double tmp = 1.0;
    while (now < k) {
      now *= 2;
      tmp /= 2.0;
    }
    ans += tmp;
  }

  printf("%.12f\n", ans / n);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    std::vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    for(int i=0;i<n;i++)
    {
        if(v[i]%2==0)
        {
            if(v[i]%3!=0&&v[i]%5!=0)
            {
                cout<<"DENIED\n";
                return 0;
            }
            
        }
    }
    cout<<"APPROVED\n";
        // your code goes here
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;



int N, M;  //N頂点M辺
vector<int> visited;
vector<vector<int>> G;



int main() {
    cin >> N;
    M=N-1;
    pair<int,int>p[M];
    G = vector<vector<int>>(N); // サイズを確保する
    visited = vector<int>(N, 0); // 全頂点を「未訪問」に初期化
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        // 頂点番号を 0-indexed とする
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
        p[i]=make_pair(a,b);
    }
    
    int qq[N];
    qq[0]=0;
    map<int,int> ans[N+1];

    queue<int> que;
    int ft=0; //大体 0 なのでft=0としてカットしても良い

    que.push(ft); // ft を橙色頂点にする
    visited[ft]=1; // 初期条件 (頂点 ft を初期ノードとする)

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();
        int d=1;

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (visited[nv] != 0) continue; // すでに発見済みの頂点は探索しない
            if(qq[v]==d){d++;qq[nv]=d;ans[v][nv]=d;}else{qq[nv]=d;ans[v][nv]=d;}
            d++;

            // 新たな白色頂点 nv についてキューに追加する（距離情報を更新する場合はvisited[v]+1）
            visited[nv] = 1;
            que.push(nv);
        }
    }

  int q=0;
  rep(i,N)chmax(q,qq[i]);
  cout << q << endl;
  for(int i=0;i<M;i++){
    cout << ans[p[i].first][p[i].second] << endl;
  }

    
}

Measured memory_bytes: 19780
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;

	vector<bool> l1(n, false), l2(n, false);

	for(int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		if (a == 1) l1[b] = true;
		if (b == n) l2[a] = true;
	}

	for(int i = 2; i < n; i++)
	{
		if(l1[i] && l2[i])
		{
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}

	cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    x, y = list(map(lambda x: int(x)-1, input().split()))
    edges[x].append(y)


def memoize(f):
    memo = dict()

    def memoized(*args):
        if args in memo.keys():
            return memo[args]
        else:
            memo[args] = f(*args)
            return memo[args]
    return memoized

@memoize
def longest_path(v):
    retval = 0
    for v2 in edges[v]:
        retval = max(retval, longest_path(v2)+1)
    return retval


ans = 0
for i in range(n):
    ans = max(ans, longest_path(i))
print(ans)

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

using namespace std;
using ll = long long;

int main(){
  ll N;
  cin >> N;
  
  vector<ll> B(N-1);
  for(int i=0; i<(N-1); i++) cin >> B[i];
  vector<ll> A(N);
  
  A[0] = B[0];
  A[1] = B[0];
  
  for(int i=1; i<(N-1); i++){
    A[i+1] = B[i];
    if(A[i]>B[i]) A[i] = B[i];
  }
  
  cout << accumulate(A.begin(), A.end(), 0) << endl;
  
  return 0;
}

Measured memory_bytes: 3628
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int t;(t=s.nextInt())>0;){Double m=999.,d,h,w;String b="",i;for(;t-->0;){i=s.next();h=s.nextDouble()/100;w=s.nextDouble();if(m.compareTo(d=Math.abs(w/(h*h)-22))>=0){b=m.equals(d)&&b.compareTo(i)<0?b:i;m=d;}}System.out.println(b);}}}

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

int main(){
    int n;
    cin >> n;
    char word;
    for (int i = 0; i < n; i++){
        cin >> word;
        if (word == 'Y'){
            cout << "Four" << '\n';
            return 0;
        }
    }
    cout << "Three" << '\n';
}

Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,d=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(n)]

ans=0
for i in range(n):
    x,y=xy[i]
    if d**2>=x**2+y**2:
        ans+=1
print(ans)

Measured memory_bytes: 101760
#include <iostream>
// #include <string>
// #include <unordered_set>

using namespace std;

// int s[100];

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

  int s, sum = 0, m = 1000;

  for ( int i = 0; i < n; i++ ) {
    cin >> s;
    if ( s % 10 != 0 ) {
      m = min( s, m );
    }
    sum += s;
  }

  int a;

  if ( sum % 10 == 0 ) {
    if ( m == 1000 ) {
      a = 0;
    } else {
      a = sum - m;
    }
  } else {
    a = sum;
  }

  cout << a << endl;

  return 0;
}


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

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> dot(H, vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> dot.at(i).at(j);
    }
  }
  bool possible = true;
  
  for(int k=0; k<H; k++){
    for(int l=0; l<W; l++){
      if(dot.at(k).at(l) == '#'){
        bool check = false;
       if(k>0){
        if(dot.at(k-1).at(l) == '#'){
         check = true;
        }
       }
       if(l>0){
        if(dot.at(k).at(l-1) == '#'){
         check = true;
        }
       }
       if(k<H-1){
        if(dot.at(k+1).at(l) == '#'){
         check = true;
        }
       }
       if(l<W-1){
        if(dot.at(k).at(l+1) == '#'){
         check = true;
        }
       }
       if(check == false){
        possible = false;
       }
      }
    }
  }
  
  if(possible){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
    
        
}

Measured memory_bytes: 256
import numpy as np
MAXX = 10**5 + 5

isprime = np.ones(MAXX, dtype=bool)
count = np.zeros(MAXX, dtype=int)

#eratosen no furui
isprime[0] = isprime[1] = False
for i in range(2, MAXX):
    if isprime[i]:
        isprime[2*i::i] = False

for i in range(1, MAXX):
    if isprime[i] and isprime[(i+1)>>1]:
        count[i] = 1

#累積和
for i in range(1, MAXX):
    count[i] += count[i-1]

#read query
Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(count[r] - count[l-1])





Measured memory_bytes: 27612
#include <iostream>

using namespace std;

int main(void){
    int num;
    cin >> num;
    char words[num];
    cin >> words;
    int oxcount = 0;
    
    for(int i = 0; i < num - 1; i++){
        if(words[i] != words[i + 1]){
            oxcount += 1;
            i += 1;
        }
    }
    cout << oxcount << '\n';
}


Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>

int main(){
   int n,a,b;
   char s[100000];
   int as,bs;
   int i,flag;

   scanf("%d %d %d",&n,&a,&b);
   scanf("%s",s);

   as=bs=0;
   for(i=0;i<n;++i){
      flag=0;
      switch(s[i]){
         case 'a':
            if((as+bs)<(a+b)){
               ++as;
               flag=1;
            }
            break;
         case 'b':
            if(((as+bs)<(a+b))&&(bs<b)){
               ++bs;
               flag=1;
            }
            break;
      }
      puts((flag)?"Yes":"No");
   }

   return 0;
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N;
  cin >> N;
  vector< int > ord(N);
  iota(begin(ord), end(ord), 1);
  vector< int > P(N), Q(N);
  cin >> P >> Q;
  int a, b;
  int add = 0;
  do {
    if(P == ord) a = add;
    if(Q == ord) b = add;
    ++add;
  } while(next_permutation(begin(ord), end(ord)));
  cout << abs(a - b) << endl;
}

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

using namespace std;

int main() {
    int N; cin >> N;
    vector<pair<int, int>> v;
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }
    sort(v.begin(), v.end(), [](auto a, auto b) {
        return a.second < b.second;
    });
    int res = 0;
    for (int t = 0, i = 0; i < N; i++) {
        if (t < v[i].first) {
            res++;
            t = v[i].second;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3864
import sys
input = sys.stdin.readline

from math import ceil

n = int(input())
a = list(map(int,input().split()))
b = ['0'] * (n+1)
    
for i in reversed(range(0, n)):
    d = n // (i+1)
    cn = 0
    for j in range(2, d+1):
        if b[j*(i+1)] == '1':
            cn += 1
    if cn % 2 == a[i]:
        b[i+1] = '0'
    else:
        b[i+1] = '1'
print(b.count('1'))
ee = []
for i,v in enumerate(b):
    if i == 0:
        continue
    if v == '1':
        ee.append(str(i))
print(' '.join(ee))

Measured memory_bytes: 72568
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	if((a+b)%2!=0)
		cout << (a+b)/2+1 << endl;
	else
		cout << (a+b)/2 << endl;

	return 0;
}


Measured memory_bytes: 256
N,Y=map(int,input().split())
answer=-1,-1,-1
for x in range(N+1):
    for y in range(N-x+1):
        z=N-x-y
        if 0<=z<=2000 and 10000*x+5000*y+1000*z==Y:
            answer=x,y,z
            break
    else:
        continue
    break
print(*answer)

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif


struct edge {
    int from, to;
    ll cost;
};

class BellmanFord {
    int V;
    int E;
    vector<edge> edges;
    vector<ll> dist;
    vector<bool> negative;

public:
    BellmanFord(int v, int e) : V(v), E(e), negative(v) {
        dist.resize(V, INF);
    }

    void add_edge(int from, int to, ll cost) {
        edges.push_back({from, to, cost});
    }

    ll get_total_cost(int v) {
        return dist[v];
    }

    // v に到達するまでに負ループがあるかを検出する
    bool is_negative(int v) {
        return negative[v];
    }

    // ベルマンフォード法の実行・全辺の負閉路を検出 trueを返す時に負閉路を含む
    bool exec() {
        bool updated = false;
        dist[0] = 0;
        for (int i = 0; i < V; ++i) {
            for (int j = 0; j < E; ++j) {
                edge edge = edges[j];
                if (dist[edge.from] != INF && dist[edge.to] > dist[edge.from] + edge.cost) {
                    dist[edge.to] = dist[edge.from] + edge.cost;
                    if (i == V - 1) updated = true;
                }
            }
        }

        for (int i = 0; i < V; ++i) {
            for (int j = 0; j < E; ++j) {
                edge edge = edges[j];
                if (dist[edge.from] != INF && dist[edge.to] > dist[edge.from] + edge.cost) {
                    negative[edge.to] = true;
                }
                if (negative[edge.from]) {
                    negative[edge.to] = true;
                }
            }
        }
        return updated;
    }
};

void Main() {
    int N, M, p;
    cin >> N >> M >> p;
    BellmanFord bellmanFord(N, M);
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        bellmanFord.add_edge(a, b, -c + p);
    }
    bellmanFord.exec();

    if (bellmanFord.is_negative(N - 1)) {
        cout << "-1" << '\n';
    } else {
        cout << max(0ll, -bellmanFord.get_total_cost(N - 1)) << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**7)

class CombByFermat:
    def __init__(self, size, mod):
        self.size = size
        self.mod = mod
        self.factrial = [1]
        self.inverse = [1]
        pre_f = 1
        for i in range(1, self.size+1):
            pre_f = (pre_f * i) % self.mod
            self.factrial.append(pre_f)
            self.inverse.append(pow(pre_f, self.mod-2, self.mod))
    def comb(self, n, r):
        if n < r:
            return 0
        return (self.factrial[n] * self.inverse[r] * self.inverse[n-r]) % self.mod

mod = 10**9 + 7
n,k = map(int, input().split())
cmb = CombByFermat(n+k, mod)
print(cmb.comb(n+k-1, n))


Measured memory_bytes: 5632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		int k = Integer.parseInt(str[1]);

		long num[] = new long[k];

		for (int i = 1; i <= n; i++) {
			num[i % k]++;
		}

		long res = 0;
		for (int a = 0; a < k; ++a) {
			int b = (k - a) % k;
			int c = (k - a) % k;
			if ((b + c) % k != 0)
				continue;
			res += num[a] * num[b] * num[c];
		}

		System.out.println(res);
	}
}


Measured memory_bytes: 34472
n,m = gets.chomp.split(" ").map(&:to_i)
vote = gets.chomp.split(" ").map(&:to_i)
minVote = vote.inject(:+) * 1 / (4 * m).to_f
count = 0
(0..n-1).each do |i|
    # puts vote[i]
    if vote[i] >= minVote
        count += 1
    end
end

if count >= m
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788
n = int(input())
w1 = input()
used = [w1]

for _ in range(n-1):
    w2 = input()
    if w2 in used:
        print("No")
        quit()
    if w1[-1] != w2[0]:
        print("No")
        quit()
    used.append(w2)
    w1 = w2
print("Yes")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define int long long

int n,m,L,R,s[200009],t[200009];
int a[200009],x[200009];
int query[200009];

bool ch1(int mid){
  int A=a[mid];
  r(i,m){
    if(query[i]==1 && A>=x[i]) A=(A+s[i])*t[i];
    if(query[i]==2 && A<=x[i]) A=(A-s[i])/t[i];
  }
  return R<A;
}

bool ch2(int mid){
  int A=a[mid];
  r(i,m){
    if(query[i]==1 && A>=x[i]) A=(A+s[i])*t[i];
    if(query[i]==2 && A<=x[i]) A=(A-s[i])/t[i];
  }
  return L<=A;
}

void ch3(int mid){
  int A=a[mid];
  r(i,m){
    if(query[i]==1 && A>=x[i]) A=(A+s[i])*t[i];
    if(query[i]==2 && A<=x[i]) A=(A-s[i])/t[i];
  }
  cout<<A<<endl;
}

signed main(){
  cin>>n>>m>>L>>R;
  r(i,n)cin>>a[i];
  r(i,m){
    cin>>query[i]>>x[i]>>s[i]>>t[i];
  }
  //cout<<endl;
  sort(a,a+n);

  //r(i,n)ch3(i);

  int l=-1,r=n;
  while(r-l>1){
    int mid=(r+l)/2;
    if(ch1(mid))r=mid;
    else l=mid;
  }

  int l2=-1,r2=n;
  while(r2-l2>1){
    int mid=(r2+l2)/2;
    //cout<<r2<<l2<<mid<<endl;
    if(ch2(mid))r2=mid;
    else l2=mid;
    //cout<<r2<<l2<<mid<<endl;
  }
  //cout<<r<<' '<<r2<<endl;

  cout<<r-r2<<endl;
}


Measured memory_bytes: 10784
/* Coached by Dukkha and rainboy */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 100000
#define M 100000

int dsu[M], ll[M];

int find(int i) {
	return dsu[i] < 0 ? i : (dsu[i] = find(dsu[i]));
}

void join(int i, int j) {
	i = find(i);
	j = find(j);
	if (i == j)
		return;
	if (dsu[i] > dsu[j]) {
		dsu[i] = j;
		if (ll[j] > ll[i])
			ll[j] = ll[i];
	} else {
		if (dsu[i] == dsu[j])
			dsu[i]--;
		dsu[j] = i;
		if (ll[i] > ll[j])
			ll[i] = ll[j];
	}
}

int aa[N], bb[N];

int compare(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;

	return bb[j] - bb[i];
}

int main() {
	static int ii[N];
	static char used[M];
	int n, m, i, j, ans;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &aa[i], &bb[i]);
		ii[i] = i;
	}
	qsort(ii, n, sizeof *ii, compare);
	memset(dsu, -1, m * sizeof *dsu);
	for (j = 0; j < m; j++)
		ll[j] = j;
	ans = 0;
	for (i = 0; i < n; i++) {
		j = m - aa[ii[i]];
		if (j < 0 || (used[j] && (j = ll[find(j)] - 1) < 0))
			continue;
		used[j] = 1;
		ans += bb[ii[i]];
		if (j - 1 >= 0 && used[j - 1])
			join(j - 1, j);
		if (j + 1 < m && used[j + 1])
			join(j, j + 1);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2164
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int,int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;
int dx[4] = { 0,0,-1,1 }, dy[4] = { 1,-1,0,0 };

int H, W;
int dp[303][303];
vector<int>v[2][303];
int calc(string S,string T) {
	REP(i, 2)REP(j, H)v[i][j].clear();
	REP(i, H) {
		FOR(j, i, H) {
			if (S[i] == T[j]) {
				v[0][j-i].push_back(H - i-1);
			}
		}
	}
	REP(j, H) {
		FOR(i, j, H) {
			if (T[j] == S[i]) {
				v[1][i-j].push_back(H - j-1);
			}
		}
	}
	REP(i, H) {
		VSORT(v[0][i]);
		VSORT(v[1][i]);
	}
	REP(i, H + 1) {
		REP(j, H + 1)dp[i][j] = INF;
	}
	dp[0][0] = 0;
	REP(i, H+1)REP(j, H+1) {
		if (i >= j) {
			int cnt = 0;
			int M = v[0][i - j].size();
			cnt = v[0][i - j].end() - lb(v[0][i - j], i);
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cnt);
			dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cnt);
		}
		else {
			int cnt = 0;
			cnt = v[1][j - i].end() - lb(v[1][j - i], j);
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cnt);
			dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cnt);
		}
	}
	return dp[H][H];
}
char C[303][303];
string S[303];
void solve() {
	cin >> H >> W;
	REP(i, H)REP(j, W) {
		cin >> C[i][j];
		S[j] += C[i][j];
	}
	ll ans = 0;
	REP(j, W - 1) {
		//print(calc(S[j], S[j + 1]));
		ans += calc(S[j], S[j + 1]);
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




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

typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const int BIG = 1e9 + 555;
const int maxN = 100 * 1000 + 9;

ll memo[maxN][15];
int n;
bool calc[maxN][15];
string s;

ll dp(int i, int rem){
	if(i >= n){
		if(rem == 5){
			return 1;
		}
		return 0;
	}

	if(calc[i][rem]){
		return memo[i][rem];
	}
	
	ll ans = 0;
	if(s[i] == '?'){
		for(int dig = 0; dig < 10; dig++){
			ans = (ans + dp(i + 1, (rem * 10 + dig) % 13)) % MOD;
		}
	} else {
		ans = (ans + dp(i + 1, (rem * 10 + (s[i] - '0')) % 13)) % MOD;
	}

	calc[i][rem] = true;
	return (memo[i][rem] = ans);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> s;

	n = (int)s.size();
	
	cout << dp(0, 0) << '\n';

	return 0;
}

Measured memory_bytes: 21456
import heapq

def main():
    x,y,a,b,c = tuple([int(t)for t in input().split()])
    p = [int(t)for t in input().split()]
    q = [int(t)for t in input().split()]
    r = [int(t)for t in input().split()]

    p = sorted(p)[a-x:]
    q = sorted(q)[b-y:]

    r = sorted(r)

    while(len(r)>0):
        r_ = heapq.heappop(r)
        if r_-p[0]>=0 or r_-q[0]>=0:
            if r_-p[0]>r_-q[0]:
                heapq.heappop(p)
                heapq.heappush(p,r_)
            else:
                heapq.heappop(q)
                heapq.heappush(q,r_)

    print(sum(p)+sum(q))

if __name__ == "__main__":
    main()

Measured memory_bytes: 23232
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          pb push_back
#define          N (int)2e5+5
#define          PI acos(-1.0)
#define          int long long 
#define          vi vector<int>
#define          mod 1000000007
#define          ld long double
#define          eb emplace_back
#define          mii map<int,int>
#define          vpii vector<pii>
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

void go()
{
	cin >> s;
	n = s.size();
	bool ok = 0;
	fo(i,0,n) 
	{
		if( s[i] == '7' ) ok = 1;
	}

	if( ok ) cout << "Yes\n";
	else cout << "No\n";
}

int32_t main()
{
	FAST;     
	int t=1; 
	// cin>>t;
	test(t) go();
}

 

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

using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>(b);--i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a))
#define mp make_pair
#define All(a) (a).begin(), (a).end()
template <typename T=long long>
inline T IN(){T x; cin>>x; return(x);}
inline void CIN(){}
template <class Head,class... Tail>
inline void CIN(Head&& head,Tail&&... tail){
    cin>>head;
    CIN(move(tail)...);
}
#define CINT(...) int __VA_ARGS__;CIN(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CIN(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CIN(__VA_ARGS__)
 
typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int,V,greater<int>> PQG;

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

ll K,N;
const ll Nmax=1e5; 
struct sushi{ll kind; ll deli;};
vector<sushi> sslist;
map<ll,ll> kcount;
priority_queue<sushi,vector<sushi>,greater<sushi>> gq;
priority_queue<sushi> q;

bool comp(sushi a, sushi b){
	return a.deli>b.deli;
}

bool operator<(const sushi& a, const sushi& b){
	return a.deli<b.deli;
};

bool operator>(const sushi& a, const sushi& b){
	return a.deli>b.deli;
};
int main(){
	cin>>N>>K;
	sslist.resize(N);
	REP(i,N){
		CINT(t,d);
		sslist[i]=sushi{t,d};
	}
	sort(All(sslist),comp);
	ll fund=0;
	ll num=0;
	REP(i,K){
		fund+=sslist[i].deli;
		if(kcount[sslist[i].kind]>0){
			gq.emplace(sslist[i]);
			num--;
		}
		kcount[sslist[i].kind]++;
		num++;
	}
	FOR(i,K,N)if(kcount[sslist[i].kind]==0){
		q.emplace(sslist[i]);
		kcount[sslist[i].kind]++;
	}
	ll sum=fund+num*num;
	while((!gq.empty())&&(!q.empty())){
		fund-=gq.top().deli; gq.pop();
		fund+=q.top().deli; q.pop();
		num++;
		sum=max(sum,fund+num*num);
	}
	cout<<sum<<"\n";
	return 0;
}

Measured memory_bytes: 8820
import itertools
a = []
for _ in range(5):
  a.append(int(input()))
k = int(input())
combs = itertools.combinations(a, 2)
l = [(n,m) for (n, m) in combs if m - n > k]
if len(l) == 0:
  print('Yay!')
else:
  print(':(')

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	string s, t;
	cin >> s >> t;
	int l1 = s.length(), l2 = t.length();
	vector<vector<int>> dp(l1 + 1, vector<int> (l2 + 1, 0));
	for (int i = 0; i <= l1; i++) {
		for (int j = 0; j <= l2; j++) {
			if (i == 0 || j == 0) {
				continue;
			}
			if (s[i - 1] == t[j - 1]) {
				dp[i][j] = 1 + dp[i - 1][j - 1];
			} else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	string ans;
	int p1 = l1, p2 = l2;
	while (p1 > 0 && p2 > 0) {
		if (s[p1 - 1] == t[p2 - 1]) {
			ans += s[p1 - 1];
			p1--;
			p2--;
		} else if (dp[p1 - 1][p2] > dp[p1][p2 - 1]) {
			p1--;
		} else {
			p2--;
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
	
	return 0;
}


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

int main() {
  int N, A = 0;
  string x;
  cin >> N;
  for(int i = 0; i < N; i++){
  	cin >> x;
    if(x == "Y"){
      cout << "Four";
      A = 1;
      break;
    }
  }
  if(A != 1){
  cout << "Three";
  }
}

Measured memory_bytes: 256