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

using namespace std;


int main () {
	int r, g, b;
	cin >> r >> g >> b;

	int val;
	val = r * 100 + g * 10 + b;

	if (val % 4) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>

using namespace std;

int p;
string str;
int sx;

int ex();
int me();
int ee();

int inv(int n){
  if(n==0)throw 0;
  int r=1;
  int x=1;
  do{
    if(p-2&x){
      r=(r*n)%p;
    }
    x<<=1;
    n=(n*n)%p;
  }while(x<p-2);
  return r;
}

int ex(){
  int r=me();
  while(sx<str.size()&&(str[sx]=='+'||str[sx]=='-')){
    int f=(str[sx++]=='+')?1:-1;
    r=(r+me()*f+p)%p;
  }
  return r;
}

int me(){
  int r=ee();
  while(sx<str.size()&&(str[sx]=='*'||str[sx]=='/')){
    if(str[sx]=='*'){
      sx++;
      r=(r*ee())%p;
    }else if(str[sx]=='/'){
      sx++;
      r=(r*inv(ee()))%p;
    }
  }
  return r;
}

int ee(){
  if(str[sx]=='('){
    sx++;
    int r=ex();
    sx++;
    return r;
  }else{
    int r,n;
    sscanf(str.c_str()+sx,"%d%n",&r,&n);
    sx+=n;
    return r;
  }
}

int main(){
  for(;;){
    cin>>p;
    if(!p)break;
    char c;
    cin>>c;
    getline(cin,str);
    str.erase(remove(begin(str),end(str),' '),end(str));
    try{
      sx=0;
      int r=ex();
      cout<<str<<" = "<<r<<" (mod "<<p<<")"<<endl;
    }catch(...){
      cout<<"NG"<<endl;
    }
  }
}

Measured memory_bytes: 1524
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main(void){
  int X, quot500,r500, quot5;
  
  cin >> X;
  
  quot500 = X/500;
  r500 = X%500;
  quot5 = r500/5;
  
  printf("%d\n", 1000*quot500 + 5*quot5);
  
  return 0;
  
}
  



Measured memory_bytes: 256
/* AOJ 0050
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0050
 *
 */

#include <stdio.h>

#define DEBUG 0

void replace(char* where, char* with){
    while(*with){
        *where++ = *with++;
    }
}

char* match(char* where, char* s){
    int pos;
    int i;

    pos = 0;
    while(*(where+pos)){
        i = 0;
        while(*(where+pos+i)==*(s+i)){
            i++;
            if(*(s+i) == '\0'){
                return where+pos;
            }
        }
        pos++;
    }
    return NULL;
}


int main(){
    char buf[1001];
    char* p;

    while(fgets(buf, 1000, stdin)){

        if(DEBUG){
            printf("%s", buf);
            printf("0123456789");
            printf("0123456789");
            printf("0123456789");
            printf("0123456789");
            printf("0123456789");
            printf("0123456789\n");
            printf("%s\n", match(buf, "peach"));
            printf("%s\n", match(buf, "apple"));
        }

        for(p=buf; p&&*p;){
            p=match(p, "apple");
            if(p)
                replace(p, "XXXXX");
        }
            
        for(p=buf; p&&*p;){
            p=match(p, "peach");
            if(p)
                replace(p, "YYYYY");
        }

        for(p=buf; p&&*p; ){
            p=match(p, "YYYYY");
            if(p)
                replace(p, "apple");
        }

        for(p=buf; p&&*p; ){
            p=match(p, "XXXXX");
            if(p)
                replace(p, "peach");
        }
        
        printf("%s", buf);
        if(DEBUG){
            printf("0123456789");
            printf("0123456789");
            printf("0123456789");
            printf("0123456789");
            printf("0123456789");
            printf("0123456789\n");
        }
    }
    return 0;
}

Measured memory_bytes: 0
<?php
// 1桁の数→9
// 二桁の数→2*2 + 3*7
// ３桁の数→

$x = trim(fgets(STDIN));
$array = [1, 2, 3, 4, 5, 6, 7, 8, 9];
if($x<=9){
	echo $x . "\n";
	return;
}else{
	for($i=0; $i<$x; $i++){
		if($array[$i]%10!=0){
			$array[] = 10*$array[$i] + $array[$i]%10 -1;
		}
		$array[] = 10*$array[$i] + $array[$i]%10;
		if($array[$i]%10!=9){
			$array[] = 10*$array[$i] + $array[$i]%10 + 1;
		}
	}
}

echo $array[$x-1] . "\n" ;

Measured memory_bytes: 23028
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n,W;
	cin>>n>>W;
	ll v[n];
	ll w[n];
	for(int i=0;i<n;i++)
	{
		cin>>w[i]>>v[i];
	}
	ll dp[W+1][n+1];
	for(int i=0;i<=W;i++)
	{
		for(int j=0;j<=n;j++)
		{
			dp[i][j]=0;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=W;j++)
		{
			if(j>=w[i-1])
			{
				dp[j][i]=max(dp[j][i-1],max(dp[j-1][i],dp[j-w[i-1]][i-1]+v[i-1]));
			}
			else
			{
				dp[j][i]=max(dp[j-1][i],dp[j][i-1]);
			}
		}
	}
	cout<<dp[W][n];
}

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

using namespace std;

#define int long long

const int mod = 1e9 + 7;

int sum(int l, int r) {
    return (r + l) * (r - l + 1) / 2;
}

void solve() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int i = k; i <= n; ++i) {
        ans = ((ans + sum(n - i + 1, n) - sum(0, i - 1) + 1) % mod + mod) % mod;
    }
    cout << ans + 1;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define mp make_pair
#define F first
#define S second
using namespace std;

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<int> vi;

const int MAXN = 102;
int n;
double x[MAXN], y[MAXN], s1, s2, s3, s00;

int main(){
//	freopen(".in", "r", stdin);
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n;
	for(int i=0; i<n; i++)
		cin >> x[i];
	for(int i=0; i<n; i++)
		cin >> y[i];

	for(int i=0; i<n; i++){
		double d = abs(x[i] - y[i]);
		s1 += d;
		s2 += d*d;
		s3 += d*d*d;
		s00 = max(s00, d);
	}

	cout << setprecision(6) << fixed;

	cout << s1 << '\n' << pow(s2, 1.0/2) << '\n' << pow(s3, 1.0/3) << '\n' << s00 << '\n';

	return 0;
}


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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def sieve_optimized(limit):
    # Preprocessing step takes O(N log log N) time complexity.
    n = limit
    # Filimitd all primes upto n  (including n)
    sievebound = (n-1)//2
    sieve = [-1]*(sievebound + 1)
    # sieve[0] = True
    crosslimit = (int(sievebound**0.5) - 1)
    for i in range(1, crosslimit + 1):
        if sieve[i] == -1:
            for j in range(2*i*(i+1), sievebound + 1, 2*i+1):
                sieve[j] = 2*i + 1
    return sieve

def factorization(n, sieve):
    # Factorisaton query takes O(log N) time after preprocessing.
    divs = [1]
    while n!=1:
        if n&1:
            div = sieve[(n-1)//2]
            if div == -1:
                divs.append(n)
                break
            else:
                n //= div
                divs.append(div)
        else:
            n >>= 1
            divs.append(2)

    return divs

maxnum = 10**6 + 1
sieve = sieve_optimized(maxnum)

n = int(input())
nums = list(map(int, input().split()))

seen = dict()
maxval = 0
for i in nums:
    factors = factorization(i, sieve)
    if len(factors) <= 1: continue
    for f in set(factors[1:]):
        if f in seen:
            seen[f] += 1
            maxval = max(maxval, seen[f])
        else:
            seen[f] = 1


if maxval == n:
    print('not coprime')

elif 1 < maxval < n:
    print('setwise coprime')

else:
    print('pairwise coprime')

Measured memory_bytes: 188572
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment
const double EPS = 1e-8;

double dot(P a, P b){ return real(conj(a)*b); }
double cross(P a, P b){ return imag(conj(a)*b); }
int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;   // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(cross(b,c) < -EPS) return -1; // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

double area(vector<P> v){
  double sum = 0.0;
  int n = v.size();
  for(int i=0;i<n;i++) sum += (real(v[i]) - real(v[(i+1)%n])) * (imag(v[i]) + imag(v[(i+1)%n]));
  return fabs(sum) / 2;
}

P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}

vector<P> convex_cut(vector<P> G, L l){
  vector<P> ans;
  for(int i=0;i<G.size();i++){
    P A = G[i];
    P B = G[(i+1)%G.size()];
    if(ccw(l.first, l.second, A) != -1) ans.push_back(A);
    if(ccw(l.first, l.second, A) * ccw(l.first, l.second, B) < 0)
      ans.push_back(crossPoint(L(A,B), l));
  }
  return ans;
}

int n,m;
vector<P> mp;
double calc(int idx,vector<P>g){
  for(int i=0;i<m;i++){
    if(i==idx)continue;
    P t=mp[idx]-mp[i];
    P a=P(abs(t)/2,1)*t/abs(t)+mp[i];
    P b=P(abs(t)/2,-1)*t/abs(t)+mp[i];
    g=convex_cut(g,L(a,b));
  }
  return area(g);
}

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    vector<P> pl(n);
    mp.resize(m);
    for(int i=0,x,y;i<n;i++)cin>>x>>y,pl[i]=P(x,y);
    for(int i=0,x,y;i<m;i++)cin>>x>>y,mp[i]=P(x,y);
    for(int i=0;i<m;i++)printf("%.10f\n",calc(i,pl));
  }
  return 0;

}

Measured memory_bytes: 3168
sx, sy, tx, ty = map(int, input().split())

dx = tx - sx
dy = ty - sy

ans = "R"*dx + "U"*dy + "L"*dx + "D"*(dy + 1) + "R"*(dx+1) + "U"*(dy+1) + "L" + "U" + "L"*(dx+1) + "D"*(dy+1) + "R"

print(ans)

    

Measured memory_bytes: 3060
/*
   Push yourself, because no one else is going to do it for you.
*/
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define set_zero(a) memset(a,0,sizeof(a));
#define ll long long int
#define PI 2 * acos(0.0)
#define MAX 10000000000000000
#define in(a) scanf("%d",&a);
#define out(a) printf("%d",a);
#define INF 1000000 
#define M 1000000007
#define pi 3.14159265 
using namespace std; 
int main(){ 
   fast_io
   ll n;
   cin>>n;
   ll a[n];
   ll neg = 0;
   ll sum = 0;
   ll mini = MAX;
   vector<ll> v;
   for(ll i = 0;i<n;i++){
      cin>>a[i];
      if(a[i] < 0) neg++;
      sum += abs(a[i]);
      ll o = abs(a[i]);
      v.push_back(o);
   }
   if(neg % 2 == 0){
      cout<<sum<<endl;
   }
   else{
      sort(v.begin(),v.end());
      ll ans = 0;
      ans -= v[0];
      for(ll i = 1;i<v.size();i++){
          ans += v[i];
      }
      cout<<ans<<endl;
   }
   return 0; 
}  

Measured memory_bytes: 5028
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdio>
#include<utility>
#include<algorithm>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

int N,M;
int X[100],Y[100],h[100];


int main(){
    cin>>N;
    rep(i,0,N){
        cin>>X[i]>>Y[i]>>h[i];
    }
    rep(cx,0,101){
        rep(cy,0,101){
            bool flag=true;
            ll H;
            rep(i,0,N)if(h[i]!=0){
                H=h[i]+abs(X[i]-cx)+abs(Y[i]-cy);
            }
            rep(j,0,N){
                ll height=max(H-abs(X[j]-cx)-abs(Y[j]-cy),(ll)0);
                if(h[j]!=height){
                    flag=false;break;
                }
            }
            if(flag){
                cout<<cx<<' '<<cy<<' '<<H<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
import sys
from collections import defaultdict


def input():
    return sys.stdin.readline().rstrip()


def main():
    n = int(input())
    p = list(map(int,input().split()))
    ans = 0
    for i in range(1,n-1):
        if p[i-1]>p[i] and p[i] > p[i+1]:
            ans +=1
        if p[i-1]<p[i] and p[i] < p[i+1]:
            ans +=1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 64916
let () =
    let main () =
        let n = Scanf.scanf "%d" (fun n -> n) in
        let xy = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun x y -> x, y)) in
        let gx, gy = Array.fold_left (fun (ax, ay) (x, y) -> ax + x, ay + y) (0, 0) xy in
        let gx = float gx /. float n in
        let gy = float gy /. float n in

        let ax = Array.init n (fun i -> xy.(i) |> fst |> float) in
        let ay = Array.init n (fun i -> xy.(i) |> snd |> float) in

        let rec loop_i i p x y last_dist =
            if i = 0 then sqrt last_dist else
                let rec loop_j j fx fy max_dist =
                    if j = n then loop_i (i - 1) (p *. 0.999) (x +. (fx -. x) *. p) (y +. (fy -. y) *. p) max_dist else
                        let d = (ax.(j) -. x) *. (ax.(j) -. x) +. (ay.(j) -. y) *. (ay.(j) -. y) in
                        if max_dist < d then loop_j (j + 1) ax.(j) ay.(j) d else
                            loop_j (j + 1) fx fy max_dist
                in
                loop_j 0 0.0 0.0 0.0
        in
        loop_i 30000 0.1 gx gy 0.0 |> Printf.printf "%.10f\n"
    in
    main ()

Measured memory_bytes: 4608
X= int(input())
x=int(X/100)+1


for a in range(x):
    cost0 = 0
    cost0 += 100 * a
    if cost0 > X:
        break
    if cost0 == X:
        print(1)
        exit()

    for b in range(x):
        cost1 = cost0 + 101 * b
        if cost1 > X:
            break
        if cost1 == X:
            print(1)
            exit()

        for c in range(x):
            cost2 = cost1 + 102 * c
            if cost2 > X:
                break
            if cost2 == X:
                print(1)
                exit()

            for d in range(x):
                cost3 = cost2 + 103 * d
                if cost3 > X:
                    break
                if cost3 == X:
                    print(1)
                    exit()

                for e in range(x):
                    cost4 = cost3 + 104 * e
                    if cost4 > X:
                        break
                    if cost4 == X:
                        print(1)
                        exit()

                    for f in range(x):
                        cost5 = cost4 + 105 * f
                        if cost5 > X:
                            break
                        if cost5 == X:
                            print(1)
                            exit()
print(0)


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

int main() {
  int N;
  cin >> N;
  
  int a[N];
  for (int i = 0; i< N; i++) {
    cin >> a[i];
  }
  
  int j = 1;
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] == j) {
      j++;
      count++;
    }
  }
  if (j == 1) {
    cout << -1 << endl;
  } else {
    cout << N-count << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1e18;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
    //a^tを求める
    //例：d[i] = mint(k/i).pow(n);
    //mint(2).pow(n); 2^n
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll a[22][22];
mint dp[(1<<22)];
int main() {
  ll n;
  cin>>n;
  rep(j,(1<<22))dp[j]=0;
  dp[0]=1;
  rep(i,n)rep(j,n)cin>>a[i][j];
  for(ll i=0;i<(1<<n);i++){
    //cout<<i<<"i"<<endl;
    ll cnt=__builtin_popcountll(i);
    rep(j,n){
      if (1&(i>>j) and a[cnt-1][j]==1){
      //  cout<<i<<"I"<<j<<"J"<<endl;
        dp[i]+=dp[i^(1<<j)];
      //  cout<<dp[i]<<"cnt"<<cnt<<"i"<<i<<endl;

      }
    }
  }
  cout<<dp[(1<<n)-1];

}


Measured memory_bytes: 36328
//#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

//ifstream cin("x.in"); ofstream cout("x.out");

const int nmax = 1e5;

bool ok;
bool viz[nmax + 1];
long long v[nmax + 1];
vector<pair<int, int>> g[nmax + 1];

void dfs (int nod) {
    viz[ nod ] = 1;

    for (auto i : g[ nod ]) {
        if (viz[ i.first ] == 0) {
            v[ i.first ] = v[ nod ] + i.second;
            dfs( i.first );
        } else {
            if (v[ i.first ] != v[ nod ] + i.second)
                ok = 0;
        }
    }
}

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

    for (int i = 1; i <= m; ++ i) {
        int x, y, d;
        cin >> x >> y >> d;

        g[ x ].push_back(make_pair(y, d));
        g[ y ].push_back(make_pair(x, -d));
    }

    ok = 1;
    for (int i = 1; i <= n; ++ i) {
        if (viz[ i ] == 0) {
            dfs( i );
        }
    }

    cout << (ok == 1 ? "Yes" : "No");
    return 0;
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))


void solve(){
    int a[26]={0};
    string s;cin>>s;
    for(auto u:s){
        a[u-'a']++;
    }
    rep(i,0,26){
        if(a[i]==0){
            cout<<(char)('a'+i);
            return;
        }
    }
    cout<<"None";
}

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 305;
const lli INF = 1e18;
const lli MOD = 1e9+7;

vi m;
vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	m = vi(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

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

// ---- コーディングはここから！ ('-')7
ld dp[N][N][N];
void solve(){
	lli n; cin>>n; vl h(4,0);
	fore(i,0,n){int a; cin>>a; h[a]++;}
	ld tot=1.0*n;
	fore(i,0,N)fore(j,0,N)fore(k,0,N)dp[i][j][k]=-1;
	auto f=[&](auto f, int a, int b, int c)->ld{
			if(a<0 or b<0 or c<0)return 0;
			if(a+b+c==0)return 0;
			if(dp[a][b][c]>-.05)return dp[a][b][c];
			ld res = 1 + f(f,a-1,b,c) * a/tot +
			f(f,a+1,b-1,c) * b/tot +
			f(f,a,b+1,c-1) * c/tot;
			ld x = (tot-a-b-c)/tot;
			res/=(1-x);
			return dp[a][b][c]=res;
	};
	cout<<fixed<<setprecision(10)<<f(f,h[1],h[2],h[3])<<ENDL;
}

int main(){_
	//int t; cin>>t; while(t--)
	solve();
}


Measured memory_bytes: 447248
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char ch;
 
 
        try {
 
            String inputed = br.readLine();
 
            for(int i = 0; i < inputed.length(); i++){
                ch = inputed.charAt(i);
 
                if(ch >= 'a' && ch <= 'z'){
                    System.out.print((char)(ch-32));
                }else if(ch >= 'A' && ch <= 'Z'){
                    System.out.print((char)(ch+32));
                }else{
                    System.out.print((char)ch);
                }
            }
            System.out.printf("\n");
 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


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

template<class T>
class SegTree {
    int n;
    vector<T> dat;
    T id;
    function<T(T,T)> op;
    function<T(T,T)> update;

    T query_(int a, int b, int k, int l, int r) {
        if(r<=a || b<=l) return id;
        if(a<=l && r<=b) return dat[k];
        T c1 = query_(a,b,2*k+1,l,(l+r)/2);
        T c2 = query_(a,b,2*k+2,(l+r)/2,r);
        return op(c1,c2);
    }
public:
    SegTree(int n_, T id_, function<T(T,T)> op_, function<T(T,T)> update_)
        : id(id_), op(op_), update(update_) {
            n = 1;
            while(n<n_) n*=2;
            dat = vector<T>(2*n-1, id);
    }

    void change(int i, T x) {
        i += n - 1;
        dat[i] = update(dat[i], x);
        while(i>0) {
            i = (i-1)/2;
            dat[i] = op(dat[2*i+1], dat[2*i+2]);
        }
    }

    T query(int a, int b) {return query_(a,b,0,0,n);}

    T operator[](int i) {return dat[i+n-1];}
};

SegTree<int> STmin(200005,1<<29,
    [](int x, int y){return min(x,y);},[](int , int y){return y;}
);

SegTree<int> STmax(200005,-1,
    [](int x, int y){return max(x,y);},[](int , int y){return y;}
);

using P = pair<int,pair<int,int>>;
P op(P x, P y) {
    P res;
    res.first = x.first && y.first && (x.second.second<y.second.first);
    res.second.first = min(x.second.first,y.second.first);
    res.second.second = max(x.second.second,y.second.second);
    return res; 
}

SegTree<P> shoujun(200005,make_pair(1,make_pair(1<<29,-1)),op,[](P , P y){return y;});

int main(){
    int N, K; cin >> N >> K;
    vector<int> P(N);
    REP(i,N) cin >> P[i];
    REP(i,N) {
        STmin.change(i,P[i]);
        STmax.change(i,P[i]);
        shoujun.change(i,make_pair(1,make_pair(P[i],P[i])));
    }
    bool c = false;
    int ans = 0;
    REP(i,N-K+1) {
        if(c && shoujun.query(i,i+K).first) continue;
        else if(shoujun.query(i,i+K).first) {
            ans++;
            c = true;
            continue;
        }
        if((!i) || (P[i-1]!=STmin.query(i-1,i+K-1) || P[i+K-1]!=STmax.query(i,i+K))) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  int a,b,c,k;
  cin >> a >> b >>c >>k;
  int ma=max(max(a,b),c);
  int mb=a+b+c-ma;
  for(int i=0; i<k; i++){
  	ma*=2;
  }
  
  cout << ma+mb << endl;
  
}

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

using namespace std;

void solve() {
    int x;
    cin >> x;
    if(x == 7 || x == 5 || x == 3) 
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

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

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

#define int long long

int N, M;

signed main() {
    cin >> N >> M;
    int A = 100 * N + 1800 * M;
    cout << A * pow(2, M) << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >> n;
  vector<queue<ll>> q(n);
  for(int i=0;i<n;i++){
    for(int j=0;j<n-1;j++){
      ll a;
      cin >> a;
      q[i].push(a-1);
    }
  }

  ll k=0,c=0,b=0;
  bool muri=false;
  vector<bool> sumi(n,0);

  while(c<n*(n-1)/2){
    sumi=vector<bool>(n,0);
    k=0;
    for(int i=0;i<n;i++){
      if(q[i].empty())continue;
      if(q[q[i].front()].empty()){
        muri=true;
        break;
      }
      if(i==q[q[i].front()].front() && sumi[i]==false && sumi[q[i].front()]==false){
        sumi[i]=true;
        sumi[q[i].front()]=true;
        q[q[i].front()].pop();
        q[i].pop();
        k++;
        c++;
      }
    }
    //cout << k << endl;
    if(k==0)muri=true;
    if(muri)break;
    b++;
  }

  if(muri)cout << -1 << endl;
  else cout << b <<endl;

}

Measured memory_bytes: 12236
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Homework | diff Homework.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Homework.cpp && ./a.out

/*
 
 4/19/2020
 
 5:12-5:14
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N,M;

void solve() {
  LL sum=accumulate(A,A+M,0LL);
  LL res=max(N-sum,-1LL);
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>M;
  REP(i,M) cin>>A[i];
  solve();
  
  return 0;
}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

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

if(A > X || A + B < X) NO;
else YES;

}

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

using namespace std;
 
int main()
{
	long long n,cnt=0;
	cin>>n;
	int ar[n];
	for(int i=0;i<n;i++){
		cin>>ar[i];
	}
	for(int i=0;i<n;i++){
		if(ar[i]==i+1){
			cnt++;
			i++;
		}
	}
	cout<<cnt;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
    double n;
    int k;
    cin>>n>>k;
    double ans = 0.0;
    for(int i=1;i<=n;i++){
        int p = i;
        int count = 0;
        while(p<k){
            p *= 2;
            count++;
        }
        ans += pow(0.5,count)/n;
    }
    printf("%.12f\n",ans);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    double x,y,a,b,c,d,e,f;
    while(cin >> a >> b >> c >> d >> e >> f)
    {
        x=(f-e*c/b)/(d-e*a/b);
        y=c/b-a/b*x;
        x+=0.0001;
        y+=0.0001;
        cout<<fixed<<setprecision(3)<<x<<" ";
        cout<<y<<endl;
    }
    return 0;
}

Measured memory_bytes: 1284
function main()
	K=parse(Int,readline())
	P=Pair{Int,Int}[1=>1]
	D=Int[1145141919 for _=0:K]
	D[2]=1
	while !isempty(P)
		(u,d)=shift!(P)
		if D[(u+1)%K+1]>d+1
			D[(u+1)%K+1]=d+1
			push!(P,(u+1)%K=>d+1)
		end
		if D[u*10%K+1]>d
			D[u*10%K+1]=d
			unshift!(P,u*10%K=>d)
		end
	end
	println(D[1])
end
main()

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;

ll N,S;
ll root_N;

ll f(ll b,ll n)
{
	ll res = 0;
	while(n){
		res += n % b;
		n /= b;
	}

	return res;
}

int main()
{
	cin >> N >> S;
	root_N = sqrt(N);
	if(N < S){
		cout << -1 << endl;
		return 0;
	}
	else if(N == S){
		cout << N + 1 << endl;
		return 0;
	}

	for(ll i = 2;i <= root_N;i++){
		if(f(i,N) == S){
			cout << i << endl;
			return 0;
		}
	}

	ll x = N - S;
	for(ll i = sqrt(x);i >= 1;i--){
		if(x % i == 0){
			if(f(x / i + 1,N) == S){
				cout << x / i + 1 << endl;
				return 0;
			}
		}
	}
		
	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#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 sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


ll findCommon(set<char> X, set<char> Y){
  ll ans = 0;
  for (auto it = X.begin(); it != X.end(); it++) {
    if(Y.find(*it) != Y.end()) ans ++;
  }
  return ans;
}

set<char> getSet(string s){
  set<char> ans;
  F0R(i,s.length()) ans.insert(s[i]);
  return ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    string s;
    cin >> n;
    cin >> s;
    ll w[n];
    ll e[n];
    w[0] = 0;
    FOR(i,1,n){
      if(s[i-1] == 'W')
        w[i] = w[i-1] +1;
      else
        w[i] = w[i-1];
    }
    e[n-1] = 0;
    FORd(i,0,n-1){
      if(s[i+1] == 'E')
        e[i] = e[i+1] + 1;
      else
        e[i] = e[i+1];
    }
    ll ans = INF;
    F0R(i,n){
      if(ans > w[i] + e[i]) ans = w[i] + e[i];
    }

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

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 5396
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  string S;
  cin >> S;
  int numAB = 0;
  int numB = 0;
  bool ans;
  rep(i, N){
    switch(S[i]){
      case 'a':
        ans = (numAB < A + B);
        puts(ans ? "Yes" : "No");
        if(ans) numAB++;
        break;
      case 'b':
        ans = (numAB < A + B && numB < B);
        puts(ans ? "Yes" : "No");
        numB++;
        if(ans) numAB++;
        break;
      case 'c':
        puts("No");
        break;
    }
  }
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define newline putchar('\n')
#define SZ(x) (int((x).size()))
#define leave_space putchar(' ')
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 2e5 + 5;
vector<pii> vec;
int inl[MAXN];
struct Segment_tree {
	#define lson (root << 1)
	#define rson (root << 1 | 1)
	#define mid ((tree[root].l + tree[root].r) >> 1)
	struct Node {
		int l, r;
		pii val;
	}	tree[(1 << 19) + 10];
	inline void buildtree(int root, int l, int r) {
		tree[root].l = l;
		tree[root].r = r;
		tree[root].val = pii(2e9, l);
		if (l == r) return;
		buildtree(lson, l, mid);
		buildtree(rson, mid + 1, r);
	}
	inline pii query(int root, int l, int r) {
		if (l > r) return pii(2e9, 0);
		if (l <= tree[root].l && tree[root].r <= r) {
			return tree[root].val;
		}
		pii val = pii(2e9, 0);
		if (l <= mid) val = query(lson, l, r);
		if (r > mid) val = min(val, query(rson, l, r));
		return val;
	}
	inline void update(int root) {
		tree[root].val = min(tree[lson].val, tree[rson].val);
	}
	inline void replace(int root, int pos, int val) {
		if (tree[root].l == tree[root].r) {
			tree[root].val.fst = val; return;
		}
		if (pos <= mid) replace(lson, pos, val);
		else replace(rson, pos, val);
		update(root);
	}
}	Tree;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n, m;
	cin >> n >> m;
	vec.resize(n);
	Tree.buildtree(1, 1, m);
	rep (i, 1, n) {
		cin >> vec[i - 1].fst;
		cin >> vec[i - 1].sed;
	}
	sort(all(vec), [] (pii a, pii b) {
		if (a.fst != b.fst)
			return a.fst < b.fst;
		return a.sed > b.sed;
	} );
	int l = 1;
	vector<int> inf;
	rep (i, 0, n - 1) {
		if (vec[i].fst >= l) {
			Tree.replace(1, l, vec[i].sed);
			inl[l++] = i;
		} else {
			pii p = Tree.query(1, 1, l - 1);
			if (p.fst >= vec[i].sed) {
				inf.pb(vec[i].sed);
			} else {
				inf.pb(p.fst);
				Tree.replace(1, p.sed, vec[i].sed);
			}
		}
	}
	int ans = n - l + 1;
	sort(all(inf));
	reverse(all(inf));
	int r = m;
	for (auto v : inf) {
		if (v <= r && r >= l) {
			--r, --ans;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11384
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, K;
    cin >> N >> K;

    constexpr ll MOD = 1e9 + 7;

    //i = 1, 2, ..., NをN / iで分類
    //各要素の意味「first = N / iとなるiがsecond個ある」
    vector<pair<ll, ll>> elements;
    for (ll i = N; i > 0; ) {
        ll div = N / i;

        ll next = min(N / (div + 1), i - 1);
        ll num = i - next;
        elements.emplace_back(div, num);
        i = next;
    }

    //dp[i][j] := i個を設置して最後がj番目の割った数になる場合の数
    vector<vector<ll>> dp(K + 1, vector<ll>(elements.size(), 0));

    //1個設置する方法は1通り
    for (ll j = 0; j < elements.size(); j++) {
        dp[1][j] = 1;
    }

    for (ll i = 1; i < K; i++) {
        ll sum = 0, num = 0, index = elements.size() - 1;
        for (ll j = 0; j < elements.size(); j++) {
            while (num < elements[j].first) {
                (sum += dp[i][index] * elements[index].second) %= MOD;
                num += elements[index].second;
                index--;
            }
            dp[i + 1][j] = sum;
        }
    }

    ll ans = 0;
    for (ll j = 0; j < elements.size(); j++) {
        (ans += dp[K][j] * elements[j].second) %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 51700
#pragma GCC optimize("Ofast,fast-math,unroll-loops")

#include <bits/stdc++.h>

#define int ll
//#define double long double
//#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
#define PI 3.14159265358979

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;

/*
const ll MAX_MEM = 3e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/

template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}

template <class T>
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}

template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}

template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}

inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

signed main()
{
    Start();
    int n;
    string s;
    cin >> n >> s;
    string t(n / 2, ' ');
    copy(s.begin(), s.begin() + n / 2, t.begin());
    if (s == t + t)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}




Measured memory_bytes: 256
def check(y,x):
    if y-1 < 0:
        if x-1 < 0:
            move_x = [1,0]
            move_y = [0,1]
        if x+1 >= w:
            move_x = [-1,0]
            move_y = [0,1]
        else:
            move_x = [1,-1,0]
            move_y = [0,0,1]
    if y+1 >= h:
        if x-1 < 0:
            move_x = [1,0]
            move_y = [0,-1]
        if x+1 >= w:
            move_x = [-1,0]
            move_y = [0,-1]
        else:
            move_x = [1,-1,0]
            move_y = [0,0,-1]
    else:
        if x-1 < 0:
            move_x = [1,0,0]
            move_y = [0,1,-1]
        if x+1 >= w:
            move_x = [-1,0,0]
            move_y = [0,1,-1]
        else:
            move_x = [1,-1,0,0]
            move_y = [0,0,1,-1]
    for i in range(len(move_x)):
        if stage[y+move_y[i]][x+move_x[i]] == "#":
            return True
    return False
h,w = map(int, input().split())
stage = [input() for i in range(h)]
for i in range(h):
    for j in range(w):
        if stage[i][j] == "#":
            if not check(i,j):
                print("No")
                quit()
print("Yes")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int X = sc.nextInt();
    int T = sc.nextInt();
    
    if (N % X ==0) {
      System.out.println((N / X) * T);
    } else {
      System.out.println((N / X + 1) * T);
    }
  }
}

Measured memory_bytes: 35828
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

ll dp[110][5][2];

int main(){
  string s; cin >> s;
  int K; cin >> K;
  int n=s.size();
  dp[0][0][0]=1;
  rep(i,n)rep(j,4)rep(k,2){
    int nd=s[i]-'0';
    rep(d,10){
      int ni=i+1;
      int nj=j;
      int nk=k;
      if(k==0){
        if(d>nd) continue;
        if(d<nd) nk=1;
      }
      if(d!=0) nj++;
      dp[ni][nj][nk]+=dp[i][j][k];
    }
  }
  cout << dp[n][K][0]+dp[n][K][1] << endl;
}

Measured memory_bytes: 3632
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut mp = std::collections::HashMap::<i64, i64>::new();
    for a in sc.vec::<i64>(n) {
        *mp.entry(a).or_insert(0) += 1;
    }
    let ans: i64 = mp.iter().map(|(&k, &v)| if v >= k { v - k } else { v }).sum();
    println!("{}", ans);
}

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

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


Measured memory_bytes: 12540
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	map<int, int> cnt;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		++cnt[a[i]];
	}
	vector<int> p;
	for (auto x : cnt) {
		p.push_back(x.second);
	}
	sort(p.rbegin(), p.rend());
	int answer = 0;
	while ((int) p.size() > k) {
		answer += p.back();
		p.pop_back();
	}
	cout << answer << '\n';
	return 0;
}


Measured memory_bytes: 11640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
int i,j,k,n;
ll fact[10];
fact[0]=1;
for(i=1;i<10;i++)
    fact[i]=i*fact[i-1];

cin>>n;
double x[n],y[n],sum=0;
for(i=0;i<n;i++)
    cin>>x[i]>>y[i];
for(i=0;i<n;i++)
{
    for(j=i+1;j<n;j++)
        sum+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
double ans= sum*fact[n-1]*2/fact[n];
cout<<fixed<<setprecision(12)<<ans<<endl;

return 0;
}


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

vector<ll> g[100005];
ll u[3][100005];



int main() {
  ll n,m;
  cin >> n>>m;
  rep(i,m){
    ll u1,v1;
    cin>>u1>>v1;
    u1--;v1--;
    g[u1].push_back(v1);
  //  g[v1].push_back(u1);

  }
  rep(i,3)rep(j,100005)u[i][j]=-3;
  ll s1,t1;
  cin>>s1>>t1;
  s1--;t1--;
  queue <P> q;
  q.push(make_pair(s1,0));
  while(!q.empty()){
    P now=q.front();
    q.pop();
    ll t=now.first;
    ll dist=now.second;
    for(ll to:g[t]){
      if (u[(dist+1)%3][to]!=-3)continue;
  //    cout<<"to"<<to<<"d"<<(dist+1)<<endl;
      u[(dist+1)%3][to]=dist+1;
      q.push(make_pair(to,dist+1));
    }
  }

cout<<u[0][t1]/3;

}


Measured memory_bytes: 11340
#include<bits/stdc++.h>
using namespace std;
static const double INFTY = (1 << 20);
int main(){
    double N, T, A, h;
    cin >> N >> T >> A;
    vector<double> H(N);
    for(int i = 0; i < N; i++){
        cin >> h;
        H.at(i) = T - 0.006 * h;
    }
    double ans = 0, cc = INFTY;
    for(int i = 0; i < N; i++){
        if(abs(A - H.at(i)) < cc){
            ans = i;
            cc = abs(A - H.at(i));
        }
    }
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 3748
n = int(input())

s = input()
a = []
for i in range(n - 1):
    a.append(abs(int(s[i]) - int(s[i + 1])))

ans = []
for r in range(n - 1):
    if (n - 2)^ r ^ (n - 2 - r) == 0:
        ans.append(int(a[r]))
res = 0

for i in ans:
    res = abs(res - i)
if 1 in a:
    print(res % 2)
else:
    print(res)

Measured memory_bytes: 113488
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var K = one[1];
  var s = nextCharArray();
  s[K - 1] = s[K - 1].toLowerCase();
  myout(myconv(s,0));
}

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


void solve()
{
    string s;
    cin>>s;
    if(s[s.size()-1] == 's')
    {
        s = s+"es";
    }
    else
    {
        s = s + "s";
    }
    cout<<s<<endl;
    
}
int main() {
    int t=1;
    //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3604