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

using ll = unsigned long long;

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

    // 左にある黒
    vector<int> black(s.size() + 2, 0);
    // 右にある白
    vector<int> white(s.size() + 2, 0);

    for (int i = 1; i <= s.size(); i++) {
        if (s[i - 1] == '#') {
            black[i] = black[i - 1] + 1;
        } else {
            black[i] = black[i - 1];
        }
    }

    for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] != '#') {
            white[i] = white[i + 1] + 1;
        } else {
            white[i] = white[i + 1];
        }
    }

    int result = 9999999;
    for (int i = 0; i <= s.size(); i++) {
        int tmp = black[i] + white[i];
        result = min(tmp, result);
    }

    cout << result << endl;
}


Measured memory_bytes: 2180
#include<bits/stdc++.h>
using namespace std;
int n, f[100001], a[100001], res;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    f[0]=1e9;
    for(int i=2;i<=n;i++)
    {
        f[i]=min(f[i-1]+abs(a[i]-a[i-1]), f[i-2]+abs(a[i]-a[i-2]));
        //res=min(res, f[i]);
    }
    cout<<f[n];
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <list>
#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str="";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}

int main() {
	Int n, m; cin >> n >> m;
	Int cnt = 0;
	if (m - 2 > 0) {
		if (n - 2 > 0) {
			cnt += (n - 2) * (m - 2);
		}
		if (n == 1) cnt += m - 2;
	}
	else if(m==1&&n-2>0){
		cnt += n - 2;
	}
	else if (n == 1 && m == 1) cnt = 1;
	cout << cnt;

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int k =1;
  for(int i=0; i<n; i++){
    int t;
    cin>>t;
    if(t == k) k++;
  }
  if(k == 1){
    cout<<-1<<endl;
    return 0;
  }
  cout<<n - k + 1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   //75=5*5*3 15*5  25*3  75
           //2 4 4    14 4  24 2  74
           //cout<<5*10*3*6*9*4<<endl;
           int n;
           cin>>n;
           map<int,int> cnt;
           rep(i,1,n+1){//iを素因数分解
             int v=i;
             for(int j=2;j*j<=v;j++){
               while(v%j==0){
                 cnt[j]++;
                 v/=j;
               }
             }
             if(v!=1){
              cnt[v]++; 
             }
           }
           /////////////
           vin num(100,0);
           for(auto v:cnt){
             rep(i,0,100){
               if(v.second>=i) num[i]++;
             }
           }
           int ans=0;
           ans+=num[4]*(num[4]-1)/2*(num[2]-2);
           //cout<<num[4]<<endl;
           ans+=num[14]*(num[4]-1);
           ans+=num[24]*(num[2]-1);
           ans+=num[74];
           cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll n;
vl g[2*MAX];
ll sub[2*MAX];
ll tictac[2*MAX];
ll fact[2*MAX],ans[2*MAX];

void dfs(ll u,ll p){
  sub[u] = 1;
  for(auto v:g[u]){
    if(v!=p){
      dfs(v,u);
      sub[u]+=sub[v];
    }
  }
}

void pre(ll u,ll p){
  tictac[u] = 1;
  for(auto v:g[u]){
    if(v!=p){
      pre(v,u);
      tictac[u]=tictac[u]*tictac[v]%MOD;
    }
  }
  ll sum = 0;
  ll den = 1;
  for(auto v:g[u]){
    if(v == p)continue;
    sum+=sub[v];
    den=den*fact[sub[v]]%MOD;
  }
  tictac[u]=tictac[u]*fact[sum]%MOD*minv(den,MOD)%MOD;
}

void solve(ll u,ll p){
  
  ans[u] = tictac[u];

  for(auto v:g[u]){
    if(v!=p){
      ll temp[4];
      
      temp[0] = tictac[u];
      temp[1] = sub[u];
      temp[2] = sub[v];
      temp[3] = tictac[v];

      tictac[u] = tictac[u]*minv(tictac[v],MOD)%MOD*minv(fact[n-1],MOD)%MOD*fact[sub[v]]%MOD;
      tictac[u] = tictac[u]*fact[n-1-sub[v]]%MOD;
      
      sub[u]-=sub[v];
      sub[v]+=sub[u];

      tictac[v] = fact[n-1];
      for(auto vv:g[v]){
        tictac[v]=tictac[v]*tictac[vv]%MOD;
        tictac[v]=tictac[v]*minv(fact[sub[vv]],MOD)%MOD;
      }

      solve(v,u);

      sub[u] = temp[1];
      sub[v] = temp[2];
      tictac[u] = temp[0];
      tictac[v] = temp[3];

    }
  }
}

int main(){FAST;
  
fact[0] = 1;
for(ll i=1;i<=200000;++i)fact[i] = fact[i-1]*i%MOD;

cin>>n;

for(ll i=1;i<=n-1;++i){
  ll u,v;cin>>u>>v;
  g[u].pb(v);
  g[v].pb(u);
}
dfs(1,0);
pre(1,0);
solve(1,0);
for(ll i=1;i<=n;++i)cout<<ans[i]<<'\n';
return 0;
}

Measured memory_bytes: 20976
x = int(input())
exp = [1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 125, 128, 144, 169, 196, 216, 225, 243, 256, 289, 324, 343, 361, 400, 441, 484, 512, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1000]

if x in exp:
    print(x)
else:
    exp.append(x)
    exp.sort()
    print(exp[exp.index(x)-1])

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <sstream>
#include <cstring>
#include <cctype>
#include <set>
#include <queue>
#include <algorithm>

typedef long long ll;

using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 15;
const int MOD = 10000;

struct BOOK{
    int price;
    int a[MAXN];
}book[MAXN];
int b[MAXN];

int main()
{
    int n, m, x, price, level, ans = INF, res = 0;
    bool flag;
    scanf("%d %d %d", &n, &m, &x);

    for (int i = 0; i < n; i ++ ) {
        scanf("%d", &book[i].price);
        for (int j = 0; j < m; j ++ ) {
            scanf("%d", &book[i].a[j]);
        }
    }

    for (int i = 1; i < (1 << n); i ++ ) {
        res = 0;//统计每种情况所有书的总价格
        memset(b, 0, sizeof(b));
        for (int j = 0; j < n; j ++ ) {
            if ( i >> j & 1 ) {
                res += book[j].price;
                for (int k = 0; k < m; k ++ ) {
                    b[k] += book[j].a[k];
                }
            }
        }
        flag = true;
        for (int k = 0; k < m; k ++ ) {
            if ( b[k] < x ) {
                flag = false;
                break;
            }
        }

        if ( flag ) ans = min(ans, res);
    } 

    printf("%d", ans == INF?-1:ans);
    return 0;
}

Measured memory_bytes: 3784
object Main extends App {
  def is_yes(str: String): Boolean = {
    val len = str.length
    return len <= 1 || (str.head == str.last && is_yes(str.slice(1, len - 1)))
  }
  val sc = new java.util.Scanner(System.in)
  val s = sc.next
  val n = s.length

  val no_num = Array(
    s,
    s.slice(0, (n - 1) / 2),
    s.substring((n + 3) / 2 - 1)
  ).filter(!is_yes(_)).length

  println(if (no_num > 0) "No" else "Yes")
}


Measured memory_bytes: 25500
import Control.Applicative
import Numeric

main = do
    ss <- words <$>getLine
    let a = read $ ss!!0
    let b = read $ ss!!2
    let op = ss!!1
    let o = case op of
              "+" -> show(a+b)
              "-" -> show(a-b)
              "*" -> show(a*b)
              "/" -> show(a`div`b)

    if op /= "?" then do
        _ <- putStrLn $ o
        main
    else return()

Measured memory_bytes: 3956
program main
	implicit none
    integer(8)::x,i,j,ans
    
    read(*,*)x
    ans=1
    
    do i=1,x
    	do j=2,x
        	if(i**j<=x .and. i**j>ans)then
            	ans=i**j
            end if
        end do
    end do
    write(*,*) ans
    stop
end program main




Measured memory_bytes: 2924
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"

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

    long long n, k;
    cin >> n >> k;
    long long m = n % k;
    if(m > k / 2)
        m = k - m;
    cout << m << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto e : s) os << e; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += b % mod) %= mod; if (a < 0) a += mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  cin >> a;
  rep(i, n) a[i] = (a[i] >= k ? 1 : 0);
  cout << accumulate(all(a), 0) << endl;
}


Measured memory_bytes: 3608
N = int(input())
A=input().split()
B=input().split()
C=input().split()

A = [int(s) for s in A]
B = [int(s) for s in B]
C = [int(s) for s in C]

manzoku = 0
pre_a = 100

for a in A:
    manzoku += B[a-1]
    if(pre_a == a-1):
        manzoku += C[a-2]
    pre_a = a

print(manzoku)

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

typedef long long ll;
using namespace std;

ll Mod = 1e9 + 7;
int main()
{
    ll N, a, b, c, d, e;
    cin >> N >> a >> b >> c >> d >> e;
    ll m = min(a, min(b, min(c,min(d, e))));
    cout << (N-1) / m  + 5 << endl;


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define pai 3.141592653589
   
int main(void)
{
double r, s, l;
   
scanf("%lf", &r);
   
s = pai * r * r;
l = 2 * pai * r;
   
printf("%.6f %.6f\n", s, l);
return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include<cstdio>

using namespace std;

int n,s;
int cnt;
 
void solve(int a,int b,int c){
    if(b==n && s==c){
        cnt++;
    }
    if(b<n){
        for(int i=a+1;i<=9;i++)solve(i,b+1,c+i);
    }
}

int main(void){
    while(1){
        scanf("%d%d",&n,&s);
        cnt=0;
        if(n==0)break;
        solve(-1,0,0);
        printf("%d\n",cnt);
    }
    return 0;
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    ll N;

    Scll(N);

    ll q = N;
    ll r = 1;
    ll s;
    ll t;
    ll ans = 0;
    while( r <= N ){
        s = q/r;
        t = q%r;
        // printf ("%llu,%llu,%llu,%llu\n", q, r, s, t);
        if( t >= s ){
            if( t % s == 0 ) {
                ans+= t/s + r - 1;
                // printf ("%llu\n", t/s + r - 1 );
            }
        }

        if( t < s ){
            r++;
        }else{
            r += (s+t-1) / s;
        }
    }

    printf ("%llu\n", ans);

    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2e5+5;
int n,m,x,y,tot;
char a[N],b[N];
int main()
{
  scanf("%d%d%d%d%d",&n,&m,&tot,&x,&y);
  scanf("%s",a+1); scanf("%s",b+1);
  int cr=y;
  for(int i=1;i<=tot;i++)
    {
      if(a[i]=='L')cr--;
      if(!cr){puts("NO");return 0;}
      if(b[i]=='R'&&cr<m)cr++;
    }
  cr=y;
  for(int i=1;i<=tot;i++)
    {
      if(a[i]=='R')cr++;
      if(cr>m){puts("NO");return 0;}
      if(b[i]=='L'&&cr>1)cr--;
    }
  cr=x;
  for(int i=1;i<=tot;i++)
    {
      if(a[i]=='U')cr--;
      if(!cr){puts("NO");return 0;}
      if(b[i]=='D'&&cr<n)cr++;
    }
  cr=x;
  for(int i=1;i<=tot;i++)
    {
      if(a[i]=='D')cr++;
      if(cr>n){puts("NO");return 0;}
      if(b[i]=='U'&&cr>1)cr--;
    }
  puts("YES");
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n + 1], b[n + 1];
    for(int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
    for(int i = 3; i <= n; ++i) {
        if(a[i] == b[i] && a[i - 1] == b[i - 1] && a[i - 2] == b[i - 2]) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

Measured memory_bytes: 3612
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	int X,Y,Z,W;
	cin >>X>>Y >>Z;
	W = Y;
	if (X == Y) {
		W = Z;
	}
	else if (Y == Z) {
		W = X;
	}
	cout <<W<< endl;
}


Measured memory_bytes: 256
float c[8];j;
float f(int i){
	return c[i]*(c[(i+3)%6]-c[7])+c[(i+2)%6]*(c[7]-c[i+1])+c[6]*(c[i+1]-c[(i+3)%6]);
}
int main(){for(;~scanf("%f",c+j++);j%8||puts(f(j=0)*f(2)>0&&f(2)*f(4)>0?"YES":"NO"));
	return 0;
}

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

int main(){
    int d,n;
    cin >> d >> n;
    int ans = 0;
    if (n == 100){
        n = 101;
    }
    ans = n * pow(100,d);
    cout << ans << endl;
}

Measured memory_bytes: 256
//I love Nanami Chiaki
#include<bits/stdc++.h>
using namespace std;
const int maxn=2007;
const int mod=924844033;
int n,K,dp[maxn][maxn],f[2][maxn][2],fac[maxn];
inline void add(int &x,int y){
	x+=y;if (x>=mod) x-=mod;
}
int main(){
	scanf("%d%d",&n,&K);
	fac[0]=1;for (int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
	int zz=0,pre=0,cnt,nw;
	bool hve;
	dp[zz][0]=1;
	for (int i=0;i<2*K;i++){
		cnt=0;nw=0;
		memset(f,0,sizeof(f));
		for (int j=i;j<n;j+=2*K){
			cnt++;
			if (j+K<n) hve=true;
			else hve=false;
		}
		if (i>=K) f[nw][0][0]=1;
		else f[nw][0][1]=1;
		for (int j=0;j<cnt;j++){
			memset(f[nw^1],0,sizeof(f[nw^1]));
			for (int k=0;k<=j;k++){
				for (int c=0;c<2;c++){
					if (!f[nw][k][c]) continue;
					add(f[nw^1][k][0],f[nw][k][c]);
					if (j!=cnt-1 || hve) add(f[nw^1][k+1][1],f[nw][k][c]);
					if (!c) add(f[nw^1][k+1][0],f[nw][k][c]);
				}
			}
			nw^=1;
		}
//		cout<<i<<':'<<cnt<<endl;
//		for (int j=0;j<=cnt;j++) cout<<f[nw][j][0]<<' '<<f[nw][j][1]<<endl;
//		puts("");
		memset(dp[zz^1],0,sizeof(dp[zz^1]));
		for (int j=0;j<=pre;j++){
			for (int k=0;k<=cnt;k++){
				add(dp[zz^1][j+k],1ll*dp[zz][j]*(1ll*f[nw][k][0]+f[nw][k][1])%mod);
			} 
		}
		pre+=cnt;
		zz^=1;
	}
	int ans=0;
	for (int i=0;i<=n;i++){
		if (i&1) add(ans,mod-1ll*dp[zz][i]*fac[n-i]%mod);
		else add(ans,1ll*dp[zz][i]*fac[n-i]%mod);
	}
	printf("%d\n",ans);
	return 0;
}

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


int main(){
	int n ;
	cin >>n;
	int x;
	char s[n];
	int y[52] ;
	for(int w =0 ; w<52;w++){
		y[w]=0;
	}
	for(int j=0;j<n;j++){
		cin>> s[j];
		cin >> x;
		
		if(s[j] =='S'){
			 y[x-1] =x;
		}
		else if(s[j] == 'H'){
			y[x+12] =x;
		}
		else if(s[j] =='C'){
			y[x+25] =x;
		}
		else if(s[j] =='D'){
			y[x +38] =x;
		}
	} 
	for(int r =0;r <52;r++){
		if(y[r] == 0){
			if(r <13){
				cout <<'S'<<" "<<r +1 <<"\n";
			}
			else if (r>12 &&r <26){
				cout <<'H'<<" "<<r -12 <<"\n";
			}
			else if (r >25 && r <39){
				cout <<'C'<<" "<<r -25<<"\n";
			}
			else if (r>38){
				cout <<'D'<<" "<<r -38<<"\n";
			}
		}
	}

return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#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 ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

struct BIT{
    int n;
    VL bit;

    BIT(){}
    BIT(int x){
        n = x;
        bit.assign(n+1, 0);
    }

    void init(int x){
        n = x;
        bit.assign(n+1, 0);
    }

    void add(int i, ll x){
        i++;
        while (i <= n){
            bit[i] += x;
            i += i & -i;
        }
    }

    // [0, i]
    ll sum(int i){
        i++;
        ll ret = 0;
        while (i > 0){
            ret += bit[i];
            i -= i & -i;
        }
        return ret;
    }

    // [l, r)
    ll sum(int l, int r){
        if (l >= r) return 0;
        return sum(r-1) - sum(l-1);
    }
};

int main() {
    int n;
    string s;
    cin >> n >> s;
    VI d, c(n);
    REP(i,n) if (s[i] == 'D') d.push_back(i);
    int cnt = 0;
    REP(i,n){
        if (s[i] == 'D') cnt++;
        c[i] = cnt;
    }
    int m = d.size();
    int q;
    cin >> q;
    while (q--){
        int k = in();
        ll ans = 0, sum = 0;
        BIT bit(m + 1);
        int j = 0;
        REP(i,n){
            if (s[i] == 'M'){
                bit.add(0, 1);
                bit.add(c[i], -1);
                sum += c[i] - j;
            }else if (s[i] == 'C'){
                while (j < m && i - d[j] >= k){
                    sum -= bit.sum(j);
                    j++;
                }
                ans += sum;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 17528
#include <bits/stdc++.h>
#include <vector>
#include <string>
using namespace std;
#define FL(i,a,b) for(int i = a;i<b;i++)
typedef vector<int> vi;
typedef long long int lli;
const int inf = numeric_limits<int>::max();




int main(){
    lli a,b,c,k;
    cin>>a>>b>>c>>k;
    lli ans = 0;
    if(k<=a){
        ans = k;
        cout<<ans;
        return  0;
    }
    else{
        ans = a;
        k = k - a;
    }
    if(k<=b){
        cout<<ans;
        return 0;
    }
    else{
        k = k - b;
    }
    ans = ans-k;
    cout<<ans;
    
}




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


int main(){
    int n,k;cin>>n>>k;
    vector<int> a(n), b(n,0);
    rep(i,n)cin>>a[i];
    
    rep(l,k){
        swap(b,a);
        a.assign(n,0);
        
        rep(i,n){
            int s=max(0, i-b[i]);
            int g=min(n, i+b[i]+1);
            //cout << s <<" "<< g << endl;
            a[s]++;
            if(g<n)a[g]--;
        }
        for(int i=1; i<n; i++){
            a[i]+=a[i-1];
        }
        if(a[0]==n && a[n-1]==n)break;
    }
    rep(i,n){
        cout<<a[i];
        if(i!=n-1)cout<<" ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4844
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)

p1 = p[:x]
q1 = q[:y]

s = p1 + q1 + r
s.sort(reverse= True)

print(sum(s[:x+y]))


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

using namespace std;

int main(){
  long long x;
  cin >> x;
  long long k;
  k = x / 11;
  if(x - 11*k == 0){
    cout << 2*k;
  }else if(x - 11*k > 6) {
    cout << 2*k + 2 << endl;
  }else cout << 2*k + 1 << endl;

 return 0;

}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int n,i;
ll ans,nr;
string s;
int main()
{
    //freopen("sol.in","r",stdin);
    //freopen("sol.out","w",stdout);
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>s;
    n=(int)s.size();
    for(i=n-1;i>=0;i--)
    {
    	if(s[i]=='W')nr++;
    	else ans+=nr;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 720
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		
		if(A.charAt(A.length() - 1) == B.charAt(0) && B.charAt(B.length() - 1) == C.charAt(0)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		
	}
}


Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#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 INF 1e9+7
#define LLINF 1e18
// #define int ll
using namespace std;
const int MOD = 1e9 +7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,p[100010],cnt=0,ans=0;
    cin>>n;
    rep(i,n){
        cin>>p[i];
        if(p[i]==i+1){
            cnt++;
        }
        else{
            ans +=(cnt+1)/2;
            cnt=0;
        }
        if(i==n-1){
            ans +=(cnt+1)/2;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <map>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <algorithm> 
#include <ctime>

#define MaxN 1005
#define INF 2140000000
 
using namespace std;

string S;
int ans;
bool found[256];
int main()
{
	cin>>S;
	for(int i=0;i<S.size();i++)
		for(char j='a';j<='z';j++)
		{
			string P=S;
			for(int k=0;k<S.size();k++)
				if(P[k]==j)
					for(int l=1;k-l>=0&&l<=i;l++)
						P[k-l]=j;
			ans=0;
			memset(found,0,sizeof found);
			for(int k=0;k<S.size()-i;k++)
				if(!found[P[k]])
					ans++,found[P[k]]=true;
			if(ans==1)
			{
				cout<<i;
				return 0;
			}
		}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define THE using
#define DARK namespace
#define ONE std
#define dbg(x) cout << #x << " = " << x << endl

THE DARK ONE;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    freopen("out.txt", "w", stdout);
//    freopen("input.txt", "r", stdin);
    string str1, str2;
    cin >> str1 >> str2;
    vector<int> v1(30), v2(30);
    for(int c: str1){
        v1[c - 'a']++;
    }
    for(int c: str2){
        v2[c - 'a']++;
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    for(int i = 0; i < 30; i++){
        if(v1[i] != v2[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 916
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){



    ll n;
    cin>>n;


    map<ll,ll> m;
    vector<ll> a;

    rep(i,n){
        ll k;
        cin>>k;
        m[k]++;
    }

    vector<bool> f(1000001,false);

    if(n==1){
        cout<<1<<endl;
        return 0;
    }


    for(auto &m2:m){
        if(m2.second>=2){
            ll ii = 1;
            ll a1 =  m2.first;
            while(ii*a1<=1000000){
                f[ii*a1]=true;
                ii++;
            }
            
        }else if(m2.second==1){
            a.push_back(m2.first);
        }
    }

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

    ll ans = 0;

    rep(i,a.size()){
        ll a1 = a[i];
        if(!f[a1]){
            ans++;
            ll ii = 1;
            while(ii*a1<=1000000){
                f[ii*a1]=true;
                ii++;
            }
        }else{
            ll ii = 1;
            while(ii*a1<=1000000){
                f[ii*a1]=true;
                ii++;
            }

        }
    }
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 17892
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
N=int(input())
T=[int(input()) for i in range(N)]
def lcm(a,b):
    return a*b//gcd(a,b)
ans=1
for i in T:
    ans=lcm(ans,i)
print(ans)

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

int N;
const int NMAX = 100000;

int T[NMAX], X[NMAX], Y[NMAX];

int main(){
    scanf("%d",&N);
    for(int i=0;i<N;i++) scanf("%d%d%d",T+i,X+i,Y+i);

    int t=0,x=0,y=0;
    for(int i=0;i<N;i++){
        int d = abs(x-X[i]) + abs(y-Y[i]);
        int dt = T[i] - t;
        if(dt < d) return !printf("No");
        if(d%2 != dt%2) return !printf("No");
    }
    return !printf("Yes");
}


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

const int64_t MOD = 1e9+7;

void add(int64_t& a, int64_t b){
    a = (a+b)%MOD;
}
int nth_bit(int64_t num , int n) {
    return (num >> n) & 1;
}

int main() {
    int64_t N;
    cin >> N;

    int64_t dp[61][3] = {0};
    dp[60][0] = 1;

    for(int d = 59; d >= 0; d--) {
        for(int s = 0; s <= 2; s++) {
            for (int k = 0; k <= 2; k++) {
                int s2 = min(2, 2*s+nth_bit(N, d) - k);
                if (s2 >= 0) add(dp[d][s2], dp[d+1][s]);
            }

        }
    }


    int64_t ans = (dp[0][0] + dp[0][1] + dp[0][2]) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
nodes = []
par_kid = {}
depthnot0 = []
for i in range(n):
    node = list(map(int, input().split()))
    nodes.append(node)
    if (node[1] != 0):
        par_kid[node[0]] = node[2:]
        depthnot0 += node[2:]
for i in range(n):
    if (i not in depthnot0):
        first_node = i
        break
#print(first_node)
##depth만 계산 가능하다면 다 print가능.
par_dep = {first_node:(-1,0)}
def pd(f):
    if (len(par_kid) == 0):
        return 0
    A = par_kid[f]
    c = 0
    for a in A:
        par_dep[a] = (f,par_dep[f][1]+1)
        if (a not in par_kid.keys()):
            c += 1
            continue
        pd(a)
    if (c == len(A)):
        return 0
s = pd(first_node)
    
for i in range(n):
    parent = par_dep[i][0]
    depth = par_dep[i][1]
    if (n == 1):
        print('node 0: parent = -1, depth = 0, root, []')
    elif (i == first_node):
        print('node {}: parent = {}, depth = {}, root,'.format(i,parent,depth), par_kid[i])
    elif (i in par_kid.keys()):
        print('node {}: parent = {}, depth = {}, internal node,'.format(i,parent,depth), par_kid[i])
    else:
        print('node {}: parent = {}, depth = {}, leaf, []'.format(i,parent,depth))


Measured memory_bytes: 39704
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin>>a;
    a%=10;
    if(a==3)cout<<"bon"<<endl;
    else if(a==0||a==1||a==6||a==8)cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define	pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigboi        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(all(v), RNG);
// Use mt19937_64 for 64 bit random numbers. 


void solve(){
	string s;
	cin>>s;
	if(s[2]==s[3] && s[4]==s[5]){
		cout<<"Yes";
	}
	else cout<<"No";
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0); 	
	int t=1;
	//cin>>t;
	FOR(i, 1, t+1){	
	//	cout<<"Case #"<<i<<":"<<endl;
		solve();
	}
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
 
}


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

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;};

const Int INF = 1e15;
Int dp[1<<4][111][111];

signed main(){
  Int n,m,e,s,t,r;
  cin>>n>>m>>e>>s>>t>>r;
  vector<vector<Int>> G(n),H(n);
  for(Int i=0;i<m;i++){
    Int a,b;
    cin>>a>>b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }

  vector<Int> as(e),bs(e),cs(e);
  for(Int i=0;i<e;i++) cin>>as[i]>>bs[i]>>cs[i];

  for(Int b=0;b<16;b++)
    for(Int i=0;i<111;i++)
      for(Int j=0;j<111;j++)
        dp[b][i][j]=INF;

  using T = tuple<Int, Int, Int>;
  deque<T> que;
  dp[0][s][0]=0;
  que.emplace_back(0,s,0);

  while(!que.empty()){
    Int b,v,d;
    tie(b,v,d)=que.front();que.pop_front();


    // event
    for(Int i=0;i<e;i++){
      if(v==cs[i]){
        Int nb=b|(1<<i);
        Int nv=v;
        Int nd=d;	
        if(dp[nb][nv][nd]>dp[b][v][d]+0){
          dp[nb][nv][nd]=dp[b][v][d]+0;
          que.emplace_front(nb,nv,nd);
        }
      }
    }

    // okarina
    {
      Int nb=b;
      Int nv=s;
      Int nd=0;      
      if(dp[nb][nv][nd]>dp[b][v][d]+1){
        dp[nb][nv][nd]=dp[b][v][d]+1;
        que.emplace_back(nb,nv,nd);
      }
    }
    
    if(d==r) continue;
    
    // normal route
    for(Int u:G[v]){
      Int nb=b;
      Int nv=u;
      Int nd=d+1;      
      if(dp[nb][nv][nd]>dp[b][v][d]+1){
        dp[nb][nv][nd]=dp[b][v][d]+1;
        que.emplace_back(nb,nv,nd);
      }
    }

    // event route
    for(Int i=0;i<e;i++){
      if((~b>>i)&1) continue;
      if(bs[i]==v) swap(as[i],bs[i]);
      if(as[i]!=v) continue;
      // a -> b
      Int nb=b;
      Int nv=bs[i];
      Int nd=d+1;      
      if(dp[nb][nv][nd]>dp[b][v][d]+1){
        dp[nb][nv][nd]=dp[b][v][d]+1;
        que.emplace_back(nb,nv,nd);
      }
    }
  }  
  
  Int ans=INF;  
  for(Int b=0;b<16;b++)
    for(Int j=0;j<=r;j++)
      chmin(ans,dp[b][t][j]);
  if(ans==INF) ans=-1;
  
  cout<<ans<<endl;
  return 0;
}




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

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    for(auto &e : S) cin >> e;
    int ans = H + W;
    for(int bit = 0; bit < (1 << (H - 1)); ++bit) [&]() {
        int res = __builtin_popcount(bit);
        int N = res + 1;
        vector<int> cnt(N);
        for(int j = 0; j < W; ++j) {
            int now = 0, tmp = 0;
            for(int i = 0; i < H; ++i) {
                cnt[now] += S[i][j] == '1';
                tmp += S[i][j] == '1';
                if(tmp > K) return;
                if(bit & (1 << i)) now++, tmp = 0;
            }
            if(*max_element(cnt.begin(), cnt.end()) > K) {
                cnt.assign(N, 0);
                res++, j--;
            }
        }
        ans = min(ans, res);
    }();
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
import * as fs from 'fs';

//in
// 2 3 3
//out
// 0 2

function main(inp: string) {
    let [a, b, k]: number[] = inp.split(' ').map(Number)
    if (k >= a) {
        k = k - a;
        a = 0;
    } else {
        a = a - k;
        k = 0;
    }

    if (k > 0) {
        if (k >= b) {
            b = 0;
        } else {
            b = b - k;
        }
    }

    // Too　late
    // for (let i = 0; i < k; i++) {
    //     if (a > 0) {
    //         a--;
    //         continue
    //     }
    //     if (b > 0) {
    //         b--
    //     }
    // }
    console.log(`${a} ${b}`);
}

main(fs.readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 7372
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

typedef pair<ll, ll> P;

int main() {
  string s; cin >> s;
  set<char> S;
  for (auto c: s) {
    if (S.count(c)) {
      cout << "no" << endl;
      return 0;
    }
    
    S.insert(c);
  }
  cout << "yes" << endl;
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{

int a,m;
cin>>a>>m;
std::vector<double> v(a);double y=0;
for (int i = 0; i < a; ++i)
{
	cin>>v[i];
	y+=v[i];
}
float c=(0.25/m)*y;
sort(v.begin(), v.end());
if(lower_bound(v.begin(), v.end(),c)!=v.end())
{
int ind=v.end()-lower_bound(v.begin(), v.end(),c);

if (ind>=m)
{
	cout<<"Yes";
}
else
cout<<"No";}
else
cout<<"No";

return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int h, w, a,b,c,d;
string s[3030];
int m[3030][3030];
void solve(){
	cin >> h >> w;
	cin >> a >> b >> c >> d;
	a--; b--; c--; d--;
	for(int i = 0; i < h; i++){
		cin >> s[i];
	}
	
	int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
	int dd[5] = {-2,-1,0,1,2};
	priority_queue<pair<int, P>, vector<pair<int, P>>, greater<pair<int, P>>> q;
	q.push({1,{a,b}});
	while(!q.empty()){
		auto p = q.top(); q.pop();
		int cnt = p.first;
		int x = p.second.first, y = p.second.second;
		for(int k = 0; k < 4; k++){
			int nx = x+dx[k];
			int ny = y+dy[k];
			if(nx<0 || ny<0 || nx>=h || ny>=w) continue;
			if(s[nx][ny] == '#') continue;
			if(m[nx][ny] != 0 && m[nx][ny] <= cnt) continue;
			m[nx][ny] = cnt;
			q.push({cnt,{nx,ny}});
		}
		for(int i = 0; i < 5; i++){
			int nx = x+dd[i];
			if(nx<0 || nx>=h) continue;
			for(int j = 0; j < 5; j++){
				int ny = y+dd[j];
				if(ny<0 || ny>= w) continue;
				if(s[nx][ny] == '#') continue;
				if(m[nx][ny] != 0 && m[nx][ny] <= cnt+1) continue;
				m[nx][ny] = cnt+1;
				q.push({cnt+1,{nx,ny}});
			}
		}
	}
	cout << m[c][d]-1 << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 12700
S = input()[::-1]
N = len(S)
amari = [0 for i in range(2019)]
before = int(S[0])
amari[before] += 1
S = S[1::]
keta = 1
for i in S:
    i = int(i)
    keta = (keta * 10) % 2019
    x = (keta * i + before) % 2019
    amari[x] += 1
    before = x
ans = amari[0]
for i in amari:
    ans += i * (i - 1) // 2
print(ans)


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

int main(){
  int H, W;
  char b[52][52];
  cin >> H >> W;
  for(int i=0; i<=W+1; i++){
    b[0][i]=b[H+1][i]='.';
  }
  for(int i=0; i<=H+1; i++){
    b[i][0]=b[i][W+1]='.';
  }
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      cin >> b[i][j];
    }
  }
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      if(b[i][j]=='#'){
        if(b[i][j-1]=='.'&& b[i][j+1]=='.' && b[i-1][j] =='.' && b[i+1][j]=='.'){
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<ll> T(N);
    for (auto &it : T)
        cin >> it;
    ll ans = T[0];
    for (int i = 0; i < N; i++)
        ans = lcm(ans, T[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

ll f(ll M)
{
  M--;

  ll cnt = 0;
  while (M > 1)
  {
    M /= 2;
    cnt++;
  }
  for (ll i = 0; i < cnt; i++)
  {
    M *= 2;
  }
  return M + 1;
}

string g(string T)
{
  ll M = T.size();
  ll K = f(M);

  ll cnt = 0;
  for (ll i = 0; i < K; i++)
  {
    if (T.at(i) == '1')
      cnt++;
  }

  string ret;
  ret.resize(M - K + 1);
  for (ll i = 0; i < M - K + 1; i++)
  {
    ll a = T.at(i) - '0', b = T.at(i + K - 1) - '0';
    if (cnt > 0 && ((a == 0 && b == 2) || (a == 2 && b == 0)))
      ret.at(i) = '0';
    else
    {
      ret.at(i) = abs(a - b) + '0';
    }

    if (T.at(i) == '1')
      cnt--;
  }

  return ret;
}

int main()
{
  ll N;
  cin >> N;
  string A;
  cin >> A;
  for (ll i = 0; i < N - 1; i++)
  {
    A.at(i) = abs(A.at(i) - A.at(i + 1)) + '0';
  }
  A.pop_back();

  while (A.size() > 1)
  {
    A = g(A);
  }
  cout << A << endl;
}

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

void dfs(int i,int pre,vector<vector<int>> &G,vector<int> &ans){
    for(auto v : G[i]){
        // preは一つ前に探索済み、iは現在の頂点、vはこれから訪問する頂点
        if(v == pre) continue;
        ans[v] += ans[i];
        dfs(v,i,G,ans);
    }
    return;
}

int main(){
    int n,q;
    cin >> n >> q;
    vector<vector<int>> G(n,vector<int>());
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<pair<int,int>> ope(q);
    vector<int> ans(n);
    rep(i,q){
        int p,x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    dfs(0,0,G,ans);
    rep(i,n) printf("%d%c",ans[i],(i==n-1)?'\n':' ');
}

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

int main() {
    int n;
    cin >> n;
    vector<int> E(100001);
    vector<int> O(100001);

    for(int i = 0; i < n; i++) {
        int t;
        cin >> t;
        if (i % 2 == 0) {
            E[t]++;
        } else {
            O[t]++;
        }
    }
    int emax, omax;
    vector<int>::iterator iter = max_element(E.begin(), E.end());
    emax = distance(E.begin(), iter);
    iter = max_element(O.begin(), O.end());
    omax = distance(O.begin(), iter);
    sort(E.begin(), E.end(), std::greater<int>() );
    sort(O.begin(), O.end(), std::greater<int>() );
    if (emax == omax) {
        int m = max(E[0] + O[1], E[1] + O[0]);
        cout << n - m << endl;
    } else {
        cout << n - (E[0] + O[0]) << endl;
    }
}


Measured memory_bytes: 1024
N = int(input())
A_list = list(map(int, input().split()))
total = sum(A_list)
half = total // 2
l = 0
r = len(A_list) - 1
l_len = 0
r_len = 0
while True:
	new_len = l_len + A_list[l]
	if new_len <= half:
		l_len = new_len
		l += 1
	else:
		break

while True:
	new_len = r_len + A_list[r]
	if new_len <= half:
		r_len = new_len
		r -= 1
	else:
		break

if l == r:
	cut_l = r_len + A_list[r] - l_len
	cut_r = l_len + A_list[l] - r_len
	print(min(cut_l, cut_r))
else:
	print(0)


Measured memory_bytes: 26220
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int n, k;
	cin >> n>>k;
	vector<vector<int> > pr(10, vector<int>(n+1,0));
	vector<int> ko(10, 0);
	for (int i = 0; i < n; i++) {
		int c, g; cin >> c >> g;
		g--;
		pr[g][ko[g]] = c;
		ko[g]++;
	}
	for (int i = 0; i < 10; i++) {
		sort(pr[i].begin(), pr[i].end());
		reverse(pr[i].begin(), pr[i].end());
	}
	vector<vector<int> > sum(10,vector<int> (n+1,0));
	for (int i = 0; i <10; i++) {
		int su = 0;
		for (int j = 1; j <= ko[i]; j++) {
			su += pr[i][j-1];
			sum[i][j] = su + j * (j - 1);
		}
	}
	vector<vector<int> > dp(10, vector<int>(n + 1, 0));
	dp[0] = sum[0];
	for (int i = 1; i < 10; i++) {
		for (int j = 0; j <= k; j++) {
			for (int kk = j; kk <= k; kk++) {
				dp[i][kk] = max(dp[i][kk], dp[i - 1][j] + sum[i][kk - j]);
			}
		}
	}
	cout << dp[9][k] << endl;
	return 0;
}


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

using namespace std;

int main(){
        string s;
        string ans;
        cin>>s;
        for(int i=0;i<(int)s.length();i++){
                if(s[i]=='0'){
                        ans+='0';
                }
                else if(s[i]=='1'){
                        ans+='1';
                }
                else{
                        if(!ans.empty()){
                                ans.erase(ans.end()-1);
                        }
                }
        }
        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<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;


int main(){
  string a,b,c;
  cin >> a >> b >> c;
  cout << (char)toupper(a[0]) << (char)toupper(b[0]) << (char)toupper(c[0]) << endl;
}


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

class A
{
	static void Main()
	{
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int m = a[0], d = a[1];

		var c = 0;
		for (int i = 4; i <= m; i++)
			for (int j = 1; j <= d; j++)
			{
				int d1 = j % 10, d2 = j / 10;
				if (d1 >= 2 && d2 >= 2 && i == d1 * d2) c++;
			}
		Console.WriteLine(c);
	}
}


Measured memory_bytes: 13268