akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
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<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;

void solve() {
	int n;
	cin >> n;
	int a[n];
	F0R(i,n) cin >> a[i];

	vector<bitset<32>> bs(n);
	F0R(i,32) {
		int cnt = 0;
		map<int,int> mp;
		F0R(j,n) {
			if(a[j] & (1<<i)) cnt++, mp[j]++;
		}

		if(cnt%2==1) {
			F0R(j,n) {
				if(mp.count(j)==0) bs[j][i]=1;
			}
		}
		else {
			F0R(j,n) if(mp.count(j)==1) bs[j][i]=1;
		}
	}

	F0R(i,n) cout << (bs[i].to_ulong()) << ' ';
}

int32_t main() {_
	
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif

	// tc(t)
		solve();
	cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}



Measured memory_bytes: 15056
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int a,b,c;
  cin>>a>>b>>c;
  int ans = min(b/a,c);
  cout<<ans<<endl;
  return 0;
}

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

int sum(vector<int> scores, int g) {
  int x = 0;
  rep(i, g)
    x += scores.at(i);
  return x;
}

int resum(vector<int> scores, int h) {
  int x = 0;
  rep2(i, scores.size()-h,h)
    x += scores.at(i);
  return x;
}

int minm(vector<int> scores, int from, int to) {
  int x = 0;
  rep2(i,from, to){
    if(x > scores.at(i))
      x = scores.at(i);
  }
  return x;
}

int main() {
int p, q, r, ans;
  cin >> p >> q >> r;
  ans = min(p+q, q+r);
  ans = min(p+r, ans);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

#define MP make_pair
#define F first
#define S second

int main(){
	ll x,y;
    cin >> x >> y;
    char m[x+1][y+1];
    int dp[x+1][y+1];
  	fill((int*)dp,(int*)(dp+x+1),1000);
    for(int i=1;i<=x;i++){
    	for(int j=1;j<=y;j++){
        	cin >> m[i][j];
        }
    }
    if(m[1][1]=='.'){
    dp[1][1]=0;
    }else{
    	dp[1][1]=1;
    }
    
    for(int i=1;i<=x;i++){
    	for(int j=1;j<=y;j++){
            ll hcost=0,wcost=0;
            if(i==1&&j==1) continue;
            if(m[i-1][j]=='.'&&m[i][j]=='#') hcost=1;
            if(m[i][j-1]=='.'&&m[i][j]=='#') wcost=1;
        	dp[i][j]=min(dp[i-1][j]+hcost, dp[i][j-1]+wcost);
        }
    }

    cout << dp[x][y] << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
string S,T;
vector<vector<int>> c(3,vector<int>(3,0));
//=============================
void input()
{
    rep(i,3){
        rep(j,3){
            cin>>c[i][j];
        }
    }
}
//=============================
void func(){}
//=============================
void solve()
{
    bool ans=true;;

    for (int i=0; i<2; ++i){
        for (int j=0; j<2; ++j){
            if (c[i][j+1]-c[i][j] != c[i+1][j+1]-c[i+1][j]) {
                ans = false;
            }
            if (c[j+1][i]-c[j][i] != c[j+1][i+1]-c[j][i+1]) {
                ans=false;
            }
        if (c[i][2]-c[i][0] != c[i+1][2]-c[i+1][0]){
            ans=false;
        }
        if (c[2][i]-c[0][i] != c[2][i+1]-c[0][i+1]){
            ans=false;
        }
        
        }
    }


    cout<<(ans ? "Yes" : "No")<<endl;
}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define MOD 1000000007LL
using namespace std;
typedef long long ll;

ll N, A[100000], B[100000];

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> A[i];
  REP(i, 0, N) cin >> B[i];

  ll ma = *max_element(A, A + N);
  ll mb = *max_element(B, B + N);

  ll cnt = 0;
  REP(i, 0, N) if(A[i] == ma && B[i] == mb) cnt++;

  if(ma != mb || cnt == 0) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1;
  REP(i, 0, N) {
    if(i >= 1 && A[i - 1] == A[i]) ans *= A[i], ans %= MOD;
    if(A[i] == ma) break;
  }
  REP(i, 0, N) {
    if(i >= 1 && B[N - i] == B[N - i - 1]) ans *= B[N - i - 1], ans %= MOD;
    if(B[N - i - 1] == mb) break;
  }
  REP(i, 0, cnt - 2) ans *= ma, ans %= MOD;

  cout << ans << endl;
}


Measured memory_bytes: 1792
//ALDS1_10B Matrix Chain Multiplication
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

static const int N=100;
vector<int> p(N+1);
vector< vector<int> > m(N+1,vector<int>(N+1));

int main(){
 int n;
 cin >> n;
 for(int i=1;i<=n;i++){
 cin>>p[i-1]>>p[i];
 }
 for(int l=2;l<=n;l++){
  for(int i=1;i<=n-l+1;i++){
   int j=i+l-1;
   m[i][j]=(1<<21);
   for(int k=i;k<=j-1;k++){
    m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
   }
  }
 }

 cout<<m[1][n]<< endl;

 return 0;
}

Measured memory_bytes: 1264
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,m,a[200005];
char s[200005];
void solve(){
	char G='A'+'B';int pos=1,op=0;
	for(int i=1,o=m;i<=o&&pos<=n;i++){
		if(!(a[pos]^op)) a[pos]^=1;
		else pos++,op^=1;
		m--;
	}
	if(pos<=n){
		for(int i=1;i<=n-pos+1;i++) a[i]=a[i+pos-1]^op;
		for(int i=n,now=0;i>n-pos+1;i--,now^=1) a[i]=now;
		return; 
	}
	for(int i=n,now=0;i;i--,now^=1) a[i]=now;
	if(m&1) a[1]=1;
}
int main(){
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) a[i]=s[i]-'A';
	solve();
	for(int i=1;i<=n;i++) putchar(a[i]+'A');
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<string>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<string> str(n);

    cin >> str[0];

    bool flag = true;
    for(int i = 1; i < n ; i++){
        string tmp; 
        cin >> tmp;
        if(flag){
            if(str[i - 1][str[i - 1].size() - 1] != tmp[0]){
                flag = false;
            }
            for(int j = 0; j <= i; j++){
                if(str[j] == tmp){
                    flag = false;
                }
            }
            str[i] = tmp;
            //cout << "tmp:" << tmp << endl;
        }
    }

    if(flag){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;   
    }

    return 0;
}

Measured memory_bytes: 256
h, w, k = map(int, input().split())
board = [str(input()) for _ in range(h)]
ans = 0
for i in range(2 ** h):
    for j in range(2 ** w):
        w_of_h = [] #white of h
        for m in range(h):
            if ((i >> m) & 1):
                w_of_h.append(m)
        w_of_w = [] #white of w
        for n in range(w):
            if ((j >> n) & 1):
                w_of_w.append(n)
        cnt = 0
        for H in w_of_h:
            for W in w_of_w:
                if board[H][W] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1       
print(ans)

Measured memory_bytes: 9036
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define range(i,l,h) for(int i=l;i<h;i++)
#define endl '\n'
#define I INT_MAX
#define L INT_MIN
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vt vector
using namespace std;
using std::ios;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;
const int mxn=200005;

map<ll,ll> f;

void fact(ll a)
{
  for(int i=2;i*i<=a;i++)
  {
    if(a%i==0)
    {
      while(a%i==0)
      {
        a/=i;
      }
      f[i]++;
    }
  }
  if(a!=1)f[a]++;
}


int main()
{
  fastio;
  
  int n;
  cin>>n;
  vt<ll> a(n);
  range(i,0,n)
  {
    cin>>a[i];
  }

  bool ok=1;

  range(i,0,n)
  {
    fact(a[i]);
  }

  for(auto i:f)
  {
    if(i.second>1)
    {
      ok=0;
      break;
    }
  }

  int pc=0;
  
  if(ok)
  {
    cout<<"pairwise coprime";
  }
  else 
  {
    ll hcf=a[0];
    range(i,1,n)
      hcf=__gcd(a[i],hcf);
    if(hcf==1)
    cout<<"setwise coprime";
    else 
      cout<<"not coprime";
  } 

}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n, m, ina, inb;
  cin >> n >> m;
  vector<vector<int>> a(n + 1, vector<int>());
  for(int i = 0; i < m; ++i)
  {
    cin >> ina >> inb;
    a[ina].emplace_back(inb);
  }

  const int INF = 1 << 30;

  int border = INF;
  int ans = 0;
  for(int i = 0; i < n; ++i)
  {
    if (border <= i)
    {
      ans++;
      border = INF;
    }
    if (a[i].size() == 0) continue;
    border = min(border, *min_element(a[i].begin(), a[i].end()) );
  }
  ans += (border != INF);
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

int main() {
    int A,B,K;
    cin >> A >> B >> K;
    vector<int> P(0);
    for(int i=1; i<=100; ++i) {
        if(A % i == 0 && B % i == 0) P.push_back(i);
    }
    sort(P.begin(), P.end(), greater<int>());
    cout << P[K-1] << endl;
}

Measured memory_bytes: 256
H, W= map(int, input().split())
S = ["K"*(W+2)]
for k in range(H):
    S.append("K"+input()+"K")
S.append("K"*(W+2))
A = [[0 for k in range(W)] for l in range(H)]

for y in range(1,W+1):
    for x in range(1,H+1):
        if S[x][y] == "#":
            A[x-1][y-1] = "#"
        else:
            c = 0
            for dy in range(-1,2):
                for dx in range(-1,2):
                    if S[x+dx][y+dy] == "#":
                        c += 1
            A[x-1][y-1] = c
for x in A:
    for y in x:
        print(str(y), end="")
    print()

Measured memory_bytes: 3444
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        t: [i64; n],
        m: usize,
        px: [(usize1, i64); m],
    }
    let sum = t.iter().sum::<i64>();
    for i in 0..px.len() {
        println!("{}", sum - t[px[i].0] + px[i].1);
    }
}

Measured memory_bytes: 4352
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

lo n,m,b,a[li],k,flag,x,dp[li];
lo cev;
string s;
vector<lo> v;

void YES(int xxxxxxx){
	if(xxxxxxx==1){cout<<"YES\n";exit(0);}
	printf("YES\n");
	exit(0);
}

void NO(int xxxxxxx){
	if(xxxxxxx==1){cout<<"NO\n";exit(0);}
	printf("NO\n");
	exit(0);
}

inline lo add(lo x,lo y){
	if(x+y>=mod) return x+y-mod;
	return x+y;
}

inline lo f(lo sira){
	lo cevv=0;
	if(a[sira]==1) return 0;
	if(sira==n) return 1;
	if(sira>n) return 0;
	if(~dp[sira]) return dp[sira];
	cevv=add(cevv,f(sira+1));
	cevv=add(cevv,f(sira+2));
	return dp[sira]=cevv;
}

inline lo solve(){
	memset(dp,-1,sizeof(dp));
	scanf("%lld %lld",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%lld",&x);
		a[x]=1;
	}
	printf("%lld\n",f(0));
	return 0;
}

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


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

using namespace std;

/** Interface */

inline int readChar();
template <class T = int> inline T readInt();
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x );
inline void writeWord( const char *s );

/** Read */

static const int buf_size = 4096;

inline int getChar() {
	static char buf[buf_size];
	static int len = 0, pos = 0;
	if (pos == len)
		pos = 0, len = fread(buf, 1, buf_size, stdin);
	if (pos == len)
		return -1;
	return buf[pos++];
}

inline int readChar() {
	int c = getChar();
	while (c <= 32)
		c = getChar();
	return c;
}

template <class T>
inline T readInt() {
	int s = 1, c = readChar();
	T x = 0;
	if (c == '-')
		s = -1, c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return s == 1 ? x : -x;
}

/** Write */

static int write_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
	if (write_pos == buf_size)
		fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
	write_buf[write_pos++] = x;
}

template <class T>
inline void writeInt( T x, char end ) {
	if (x < 0)
		writeChar('-'), x = -x;

	char s[24];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n--)
		writeChar(s[n]);
	if (end)
		writeChar(end);
}

inline void writeWord( const char *s ) {
	while (*s)
		writeChar(*s++);
}

struct Flusher {
	~Flusher() {
		if (write_pos)
			fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
	}
} flusher;

typedef long long ll;
typedef unsigned long long ull;

int main() {
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    ll s = 0;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        s -= a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
        s += b[i];
    }
    ll add2 = s, add1 = s;
    for (int i = 0; i < n; ++i) {
        if (a[i] > b[i]) {
            add1 -= a[i] - b[i];
        }
        if (a[i] < b[i]) {
            add2 -= (b[i] - a[i]) / 2;
            add1 -= (b[i] - a[i]) % 2;
        }
    }
    if (add1 < 0 || add2 < 0) {
        cout << "No";
    } else {
        cout << "Yes";
    }
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(){
  int k,s;
  scanf("%d %d",&k,&s);
  int co = 0;

  rep(a,k+1){
    REP(b,a,k+1){
      REP(c,b,k+1){
        if(a+b+c==s){
          if(a==b&&b==c){
            co++;
          }
          else if(a==b||b==c){
            co+=3;
          }
          else {
            co+=6;
          }
        }
      }
    }
  }
  printf("%d\n",co);

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] $){
		//System.err.println();
		Scanner s=new Scanner(System.in);
		char[]a=s.next().toCharArray();
		for(int i=0;i<a.length;++i) {
			int t=i%2+a[i];
			if(t=='L'||t=='S') {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> use(10,0);
    rep(i,k){
        int a;
        cin >> a;
        use[a] = 1;
    }
    auto can = [&](int a){
        while(a > 0){
            if(use[a%10] == 1) return false;
            else a /= 10;
        }
        return true;
    };
    while(1){
        if(can(n)) break;
        else ++n;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
int f(int n){for(int i=3;i<n;i+=2)if(n%i == 0)return 0;return 1;}int main(){int N;std::cin>>N;int c=0,i=0;while(c<N){int n=11+i*10;if(f(n)){std::cout<<n<<" ";c++;}i++;}}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;
int H,W;
char S[1000][1000];

using namespace std;
struct djk{
  djk(int n):n(n),c(n),d(n,inf){
  }
  void add(int s,int t,lint v){
    c[s].push_back(make_pair(v,t));
  }
  void solve(int start){
    q.push(make_pair(0,start));
    d[start]=0;
    while(!q.empty()){
      auto p=q.top();
      q.pop();
      lint pv=p.first;
      int pt=p.second;
      if(d[pt]>pv)continue;
      for(auto e:c[pt]){
        lint ev=e.first;
        int et=e.second;
        if(d[et]>d[pt]+ev){
          d[et]=d[pt]+ev;
          q.push(make_pair(d[et],et));
        }
      }
    }
  }
  const lint inf =1e15;
  int n;
  using edge=pair<lint,int>;
  vector<vector<edge> > c;
  vector<lint> d;
  priority_queue<edge,vector<edge>,greater<edge> > q;
};

int num(int h,int w){
  return h*W+w;
}

bool isload(int h,int w){
  return h>=0 and h<H and w>=0 and w<W and S[h][w]=='.';
}

int main(){

  cin>>H>>W;
  int N=H*W;
  djk djk(N);
  int ch,cw;
  cin>>ch>>cw;
  ch--;cw--;
  int dh,dw;
  cin>>dh>>dw;
  dh--;dw--;
  REP(h,H)REP(w,W)cin>>S[h][w];
  REP(h,H)REP(w,W){
    FOR(hi,h-2,h+3)FOR(wi,w-2,w+3)if(isload(hi,wi)){
      if(hi==h and wi==w)continue;
      else if(wi==w and max(hi-h,h-hi)==1)djk.add(num(h,w),num(hi,wi),0);
      else if(hi==h and max(wi-w,w-wi)==1)djk.add(num(h,w),num(hi,wi),0);
      else djk.add(num(h,w),num(hi,wi),1);
    }
  }
  djk.solve(num(ch,cw));
  // REP(h,H){
  //   REP(w,W){
  //     cerr<<(djk.d[num(h,w)]!=djk.inf?djk.d[num(h,w)]:-1);
  //   }
  //   cerr<<endl;
  // }
  cout<<(djk.d[num(dh,dw)]!=djk.inf?djk.d[num(dh,dw)]:-1)<<endl;
  return 0;
}


Measured memory_bytes: 299296
/*
This code By @1353055672(Ligen)
[Warning]You're not excepted to understand this code!
RP++
*/
#pragma GCC optimize(3)
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#define ll long long
#define ull unsigned long long
#define mn 5000020
#define mod (int)(1e9+7)
#define FOR(a,b,c) for (register ll a=b;a<=c;a++)
#define FORD(a,b,c) for (register ll a=b;a>=c;a--)
using namespace std;
inline ll read(){
    ll x=0,f=1;
    char c=getchar();
    while (c<'0'||c>'9'){
        if (c=='-')f=-1;
        c=getchar();
    }
    while (c>='0'&&c<='9'){
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}
inline ll Max(ll a,ll b){return (a>b)?a:b;}
inline ll Min(ll a,ll b){return (a<b)?a:b;}
inline ll Abs(ll x){return (x<0)?-x:x;}
ll base=131,x;
map<int,bool>mp;
char s[120],fa;
int main(){
	int n=read();
	FOR(i,1,n){
		scanf("%s",s+1);
		if(i>1&&s[1]!=fa){
			puts("No");return 0;
		}
		int len=strlen(s+1); 
		fa=s[len];x=0;
		FOR(j,1,len)x=(x*base+s[j])%mod;
		if(mp[x]) {
			puts("No");return 0;
		}
		mp[x]=1;
	}
	puts("Yes" );
	return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

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

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

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


void Main() {
	int A, B;
	cin >> A >> B;
	cout << max(0, A - 2*B) << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import Data.Maybe

main = do
  n <- readLn  :: IO Integer
  putStrLn $ solve n

solve n = map (chr .(+ ord '`') . fromIntegral) $ go n []
  where
    go n ns
      | n == 0 = ns
      | otherwise =
          let (p, q) = divMod n 26
          in if q == 0
            then go (p-1) (26:ns)
            else go p (q:ns)
  
getInt :: IO Int
getInt = readLn

second :: (b -> c) -> (a, b) -> (a, c)
second f (a, b) = (a, f b)

readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = fmap (second BS.tail) . BS.readInt

readIntVec :: Int -> IO (V.Vector Int)
readIntVec n = V.unfoldrN n readInt <$> BS.getLine

readIntList :: IO [Int]
readIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntPair :: IO (Int, Int)
readIntPair = do
  v <- readIntVec 2
  return (v V.! 0, v V.! 1)


Measured memory_bytes: 3924
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;

int main()
{
	double r;
	double s,l;
	double pi = 3.141592653589;
	
	cin >> r;
	
	cout << fixed << pi*r*r << ' ' << 2*pi*r << endl;
	
	return 0;
}



Measured memory_bytes: 3276
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
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; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 
 
void solve(){
    ll n,m;
    vll G[100];
    cin>>n>>m;
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        a--,b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    rep(i,n){
        cout<<G[i].size()<<endl;
    }
}
 
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    ll Q=1;
    // cin>>Q;
    rep(_,Q){
 
        solve();
 
    }
   
 
 
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9+5;
#define debug(y) cout<<#y<<y<<endl;
int main()
{
    const int INF=1e9+5;
    long long int n;
    cin>>n;
    vector<int>h(n);
    for(auto &x:h)
    {
        cin>>x;
    }

    vector<int>cost(n+1,INF);
    cost[0]=0;
    for(long long int i=1;i<n;i++)
    {    
         if(i-2<0)
         {
             cost[i]=cost[i-1]+abs(h[i]-h[i-1]);
         }
         else
        cost[i]=min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2]));
      
    }
    cout<<cost[n-1];

}


Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll A, B, C, D;
ll DP[3005][3005];

int main(){
  cin >> A >> B >> C >> D;
  DP[A][B] = 1;

  for (ll i = A + 1; i <= C; i++){
    DP[i][B] = DP[i - 1][B] * B;
    DP[i][B] %= MOD2;
  }
  for (ll j = B + 1; j <= D; j++){
    DP[A][j] = DP[A][j - 1] * A;
    DP[A][j] %= MOD2;
  }

  for (ll i = A + 1; i <= C; i++){
    for (ll j = B + 1; j <= D; j++){
      DP[i][j] = DP[i - 1][j] * j + DP[i][j - 1] * i;
      DP[i][j] %= MOD2;

      DP[i][j] -= DP[i - 1][j - 1] * (i - 1) * (j - 1);
      DP[i][j] %= MOD2;
      if (DP[i][j] < 0) DP[i][j] += MOD2;
    }
  }

  cout << DP[C][D] << endl;

  return 0;
}


Measured memory_bytes: 74000
#include<stdio.h>
#define MAX 101

void print(int n,int *A){
  int i;
  for(i=0;i<n-1;i++)
    printf("%d ",A[i]);
  printf("%d\n",A[i]);
}
/*
void insertion_sort(int n,int *A){
  int i,j,v;
  for(i=0;i<n;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    print(n,A);
  } 
}
*/

void insertion_sort(int n,int *A){
  int i,j,v;
  for(i=0;i<n;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    print(n,A);
  } 
}
int main(){
  int n,i;
  int a[MAX];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  insertion_sort(n,a);
  return 0;
}



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

int main(void) {
  string input;
  cin >> input;
  int ans;
  for (int i = 0; i < 1 << 3; i++) {
    ans = input[0] - '0';
    string s = input.substr(0, 1);
    for (int j = 0; j < 3; j++) {
      if ((i >> j) & 1) {
        ans += input[j + 1] - '0';
        s += "+";
      } else {
        ans -= input[j + 1] - '0';
        s += "-";
      }
      s += input[j + 1];
    }
    if (ans == 7) {
      cout << s + "=7" << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.{readInt,readLine}

object Main {

  def main(args: Array[String]) = {
    val n = readInt
    val read:Map[String,Int] = (1 to n).map(_=> readLine.trim -> 1).toMap

    for(x <- List("S","H","C","D"); y<-1 to 13) {
      if(!read.contains(x+" "+y))
        println(x+" "+y)
    }
  }
}

Measured memory_bytes: 43832
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
 
typedef long long ll;


int main(){
	int a;
	string s;
	cin >>a;
	cin >> s;
	
	if(a >= 3200){
		cout << s << endl;
	}else{
		cout << "red" <<endl;
	}
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if (a > 0 || (abs(a - b)+1) % 2 == 0)  {
        cout << "Positive" << endl;
    }
    else if (a < 0 && b >= 0) {
        cout << "Zero" << endl;
    }
    else {
        cout << "Negative" << endl;
    }

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    ll n,z,w;
    cin>>n>>z>>w;
    vl a(n);
    rep(i,n)cin>>a[i];
    if(n==1)cout<<abs(a[n-1]-w)<<endl;
    else cout<<max(abs(a[n-1]-w),abs(a[n-1]-a[n-2]))<<endl;
}

Measured memory_bytes: 3648
S = input()

d = ["dream", "dreamer", "erase", "eraser"]
rs = S[::-1]
ls = len(S)
rd = [(s[::-1], len(s)) for s in d]
i = 0
while True:
    if i == ls:
        print("YES")
        break
    for s, l in rd:
        if rs[i:i+l] == s:
            i += l
            break
    else:
        print("NO")
        break


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

int main(){
  string s;
  cin >> s;
  bool a[26];
  for(int i = 0; i < 26; i++){
    a[i] = false;
  }
  for(int i = 0; i < s.size(); i++){
    a[s[i] - 'a'] = true;
  }
  for(int i = 0; i < 26; i++){
    if(a[i] == false){
      cout << (char)(i+'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}

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

using namespace std;

int main() {
	vector<int> v(5);
	vector<int> d(5);
	int m = 0;
	for (int i = 0; i < 5; i++) {
		cin >> v[i];
		d[i] = v[i] % 10;
	}
	sort(d.begin(), d.end());
	for (int i = 0; i < 5; i++) {
		if (d[i] == 0)continue;
		m = d[i];
		m = abs(10 - m);
		break;
	}
	int ans = 0;
	for (int i = 0; i < 5; i++) {
		if (v[i] % 10 != 0)ans += 10-(v[i] % 10);
		ans += v[i];
	}

	cout << ans-m << endl;

	return 0;
}


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

int main() {
  int n, k; cin >> n >> k;
  vector<int> h(n);
  for(int i = 0; i < n; i++) cin >> h.at(i);
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(h.at(i) >= k)
      ans++;
  }
    cout << ans << endl;
}


Measured memory_bytes: 640
# ABC069C - 4-adjacent (ARC080C)
def main():
    N, *A = map(int, open(0).read().split())
    f, t, m = 0, 0, 0  # two, four, misc
    for i in A:
        if i % 4 == 0:
            f += 1
        elif i % 2 == 0:
            t += 1
        else:
            m += 1
    m += t % 2
    flg = f + 1 >= m
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 14052
import java.util.Scanner;
import java.util.Arrays;

class Main{
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String a = sc.nextLine();
      String[] max = a.split(" ");
     
      String b1 = max[0];
      String b2 = max[1];
      int a1 = Integer.parseInt(max[0]);
      int a2 = Integer.parseInt(max[1]);
      if (a1 == a2){
          System.out.println("a == b");
      }else if (a1 < a2){
          System.out.println("a < b");
      }else if (a1 > a2){
          System.out.println("a > b");
    }
  }
}

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

vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  // Nの入力
  int N;
  vector<int> A;
  cin >> N;
  A = input(N);

  string result = "YES";
  sort(A.begin(), A.end());

  for(int i=0; i<N-1; i++){
    if(A.at(i)==A.at(i+1)){
      result = "NO";
      break;
    }
  }
  
  cout << result << endl;

}

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

int main(){
  int n;
  cin>>n;
  ll ans=0;
  for(int a=1; a<=n; a++){
    if(n%a==0) ans+=n/a-1;
    else ans+=n/a;
  }
  cout<<ans<<endl;
}

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

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

    long long cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0) cnt += i;
    }

    cout << cnt << endl;
}

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

using namespace std;

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

    if(b == "A"){
        cout << 'T' << endl;        
    }else if(b == "C"){
        cout << 'G' << endl;        
    }else if(b == "G"){
        cout << 'C' << endl;        
    }else if(b == "T"){
        cout << 'A' << endl;        
    }

}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
   int n,i,j,k,x[8],y[8];
   double d;
 
   scanf("%d",&n);
   for (i=0;i<n;i++)
      scanf("%d %d",&x[i],&y[i]);
   d=0;
   for (i=0;i<n;i++)
      for (j=0;j<n;j++)
         d+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
   printf("%f\n",d/n);
   return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;



int main()
{

    int s, w;
    cin >> s >> w;
    if (s <= w)cout << "unsafe" << endl;
    else cout << "safe" << endl;


    return 0;

}


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

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

    for(int i=0;i<c-a;i++){
        cout << "R";
    }
    for(int i=0;i<d-b;i++){
        cout << "U";
    }
    for(int i=0;i<c-a;i++){
        cout << "L";
    }
    for(int i=0;i<d-b;i++){
        cout << "D";
    }
    cout << "D";
    for(int i=0;i<c-a+1;i++){
        cout << "R";
    }
    for(int i=0;i<d-b+1;i++){
        cout << "U";
    }
    cout << "L";
    cout << "U";
    for(int i=0;i<c-a+1;i++){
        cout << "L";
    }
    for(int i=0;i<d-b+1;i++){
        cout << "D";
    }
    cout << "R" << endl;


}

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

const int N = 100000 + 5;
int n, k;
char s[N];
int main() {
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	cin >> n >> k;
	cin >> (s + 1);
	vector < pair < int , int > > v;
	int l = 1;
	for(int i = 2; i <= n + 1; i++) {
		if(s[i] != s[i - 1] || i == n + 1) {
			v.push_back({s[i - 1], l});
			l = 1;
		}
		else ++l; 
	}
	
	cout << min(n - 1, n - (int) v.size() + 2 * k);
	return 0;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
//#pragma GCC target("avx,avx2,sse4.2")
#define re register
#define rep(q, a, b) for (re int q = a, q##_end_ = b; q <= q##_end_; ++q)
#define dep(q, a, b) for (re int q = a, q##_end_ = b; q >= q##_end_; --q)
#define mem(a, b) memset(a, b, sizeof a)
#define debug(a) cerr << #a << ' ' << a << "___" << endl
using namespace std;
//char buf[10000000], *p1 = buf, *p2 = buf;
#define Getchar() getchar()//p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 10000000, stdin), p1 == p2) ? EOF : *p1++
template<typename T>
void in(T &r) {
    static char c;
    r = 0;
    while (c = Getchar(), c < 48)
        ;
    do
        r = (r << 1) + (r << 3) + (c ^ 48);
    while (c = Getchar(), c > 47);
}
int main(){
	int a,b,c;
	in(a),in(b),in(c);
	printf("%d\n",min(a*b,c));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int N, T; 
long long ans = 0;
vector<int> vec;

void solve(){
    long long cnt = 0;
    for(int i = 1; i < N; i++){
        cnt += min(T, vec[i]-vec[i-1]);
    }
    cnt += T;
    cout << cnt << endl;
}

int main(){
    cin >> N >> T;
    int buff;
    for(int i = 0; i < N; i++) {
        cin >> buff;
        vec.push_back(buff);
    }
    solve();
}


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

int main(){
  int n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d;
  a--; b--; c--; d--;
  cin >> s;

  bool psb = true;
  for (int i = min(a, b); i < max(c, d); i++){
    if (s.at(i) == '#'){
      if (s.at(i + 1) == '#') psb = false;
    }
  }

  if (!psb){
    cout << "No" << endl;
    return 0;
  }

  if ((a < b && d < c) || (b < a && c < d)){
    int x = max(a, b);
    int y = min(c, d);
    psb = false;
    for (int i = x; i <= y; i++){
      if (s.at(i - 1) == '.' && s.at(i) == '.' && s.at(i + 1) == '.'){
        psb = true;
        break;
      }
    }
  }

  cout << (psb ? "Yes" : "No") << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const int N = 2e5 + 5;

int n, c[N];
int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> c[i];
  sort(c + 1, c + 1 + n, greater<int>());

  ll res = 0;
  for (int i = 1; i <= n; ++i) {
    (res += 1LL * c[i] * (i + 1)) %= MOD;
  }
  for (int i = 1; i < n; ++i) {
    (res *= 4LL) %= MOD;
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 1024
import sys


sys.setrecursionlimit(100000)
MOD = 10**9 + 7
n = int(input())
tree = [[] for i in range(n)]
for i in range(n-1):
    tmp1, tmp2 = map(int, input().split())
    tree[tmp1 - 1].append(tmp2 - 1) 
    tree[tmp2 - 1].append(tmp1 - 1)
visited = [False]*n

def dfs(i):
    visited[i] = True
    if all([visited[j] for j in tree[i]]):
        return 1, 1  #黒の通り数, 白の通り数
    else:
        ans1 = 1
        ans2 = 1
        for j in tree[i]:
            if not visited[j]:
                tmp1, tmp2 = dfs(j)
                ans1 *= tmp2
                ans2 *= (tmp1 + tmp2)
                ans1 %= MOD
                ans2 %= MOD
        return ans1, ans2  #黒の通り数, 白の通り数

print(sum(dfs(0)) % MOD)


Measured memory_bytes: 100520
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL)x=x->right;
  return x;
}

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

Node treeSuccessor(Node x){
  if(x->right!=NIL)return treeMinimum(x->right);

  Node y = x->parent;
  while(y!=NIL && x==y->right){
	x=y;
	y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL)y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL)x=y->left;
  else x=y->right;

  if(x!=NIL)x->parent=y->parent;

  if(y->parent==NIL)root=x;
  else if(y==y->parent->left) y->parent->left=x;
  else y->parent->right=x;

  if(y!=z) z->key=y->key;
  free(y);


}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
	y=x;
	if(z->key<x->key)x=x->left;
	else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;

}

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


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
	scanf("%s", com);
	if ( com[0] == 'f' ){
  	scanf("%d", &x);
  	Node t = treeSearch(root, x);
  	if ( t != NIL ) printf("yes\n");
  	else printf("no\n");
	} else if ( com[0] == 'i' ){
  	scanf("%d", &x);
  	insert(x);
	} else if ( com[0] == 'p' ){
  	inorder(root);
  	printf("\n");
  	preorder(root);
  	printf("\n");
	} else if ( com[0] == 'd' ){
  	scanf("%d", &x);
  	treeDelete(treeSearch(root, x));
	}
  }

  return 0;
}



Measured memory_bytes: 20468
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n; ll k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];
    sort(all(a));
    sort(rall(f));
    auto check = [&](ll x) {
                     ll cost = 0;
                     rep(i, n) {
                         if (a[i] * f[i] > x) {
                             cost += a[i] - x / f[i];
                         }
                     }
                     return cost <= k;
                 };
    ll ng = -1, ok = 1e12;
    while (ok - ng > 1) {
        ll mid = (ok + ng) >> 1;
        if (check(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}


Measured memory_bytes: 6376
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

//関数定義
//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main() {
  // ========================================================
  int a, b, c;
  cin >> a >> b >> c;
  if (((a == b) && (b == c)) || ((a != b) && (b != c) && (c != a))) {
    nOUT;
  } else {
    yOUT;
  }
}

//最大公約数
ll gcd(ll a, ll b) {
  if (!b) return a;
  return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

Measured memory_bytes: 256