akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  cin >>N;
  if(N%2==0) {
cout << N << endl;
  }
  else {
cout << N*2 << endl;
  }
  }

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = Counter(list(map(int, input().split())))
A = sorted([(k, v) for k, v in A.items() if v >= 2], key=lambda x: x[0], reverse=True)
if len(A) == 0:
    print(0)
    exit()
if len(A) == 1:
    if A[0][1] >= 4:
        print(A[0][0] ** 2)
    else:
        print(0)
    exit()
if A[0][1] >= 4:
    print(A[0][0] ** 2)
else:
    print(A[0][0] * A[1][0])


Measured memory_bytes: 18600
#include<stdio.h>
#include<math.h>
 
using namespace std;
 
 
int main(){
    double x,y,s;
    int n,k;
     
     
    x=y=s=0;
    while((scanf("%d,%d",&n,&k)),n!=0){
        x=x+n*cos(M_PI*s/180);
        y=y+n*sin(M_PI*s/180);
        s=s+k;
    }
    printf("%d\n%d\n",int(y),int(x));
}

Measured memory_bytes: 1032
n, m, x = map(int, input().split())
k = [list(map(int, input().split())) for i in range(n)]
c = []
for i in range(n):
    c.append(k[i][0])
for i in range(n):
    del k[i][0]

INF = 10**18

ans = INF
for a in range(1<<n):
    cost = 0
    d = [0 for i in range(m)]
    for b in range(n):
        if(a>>b&1):
            cost += c[b]
            for i in range(m):
                d[i] += k[b][i]
    ok = True
    for b in range(m):
        if (d[b] < x):
            ok = False
    if (ok):
        ans = min(ans, cost)
if (ans == INF):
    print (-1)
else:
    print(ans)

Measured memory_bytes: 8988
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in(),K=in();
	string S=in<string>();
	
	S[K-1] = S[K-1]+32;
	cout << S << endl;
	return 0;
}


Measured memory_bytes: 892
from collections import defaultdict

class UnionFind:
  def __init__(self, n):
    self.parents = list(range(n))
    self.ranks = [0] * n

  def root(self, x):
    if self.parents[x] == x:
      return x
    else:
      y = self.root(self.parents[x])
      self.parents[x] = y
      return y

  def same(self, x, y):
    return self.root(x) == self.root(y)

  def unite(self, x, y):
    x = self.root(x)
    y = self.root(y)
    if x == y:
      return
    if self.ranks[x] < self.ranks[y]:
      self.parents[x] = y
    else:
      self.parents[y] = x
      if self.ranks[x] == self.ranks[y]:
        self.ranks[x] += 1

n, m, k = map(int, input().split())
u = UnionFind(n)
counts = [1 for _ in range(n)]
for _ in range(m):
  a, b = map(int, input().split())
  u.unite(a - 1, b - 1)
  counts[a - 1] += 1
  counts[b - 1] += 1

for _ in range(k):
  a, b = map(int, input().split())
  if u.same(a - 1, b - 1):
    counts[a - 1] += 1
    counts[b - 1] += 1

groups = defaultdict(int)
for i in range(n):
  groups[u.root(i)] += 1

print(*[groups[u.root(i)] - counts[i] for i in range(n)])


Measured memory_bytes: 20996
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int MAXN = (1 << 14) + 5;
const int MOD = 998244353;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

namespace ModCalculator {
	inline void Inc(int &x, int y) {
		x += y; if (x >= MOD) x -= MOD;
	}
	inline void Dec(int &x, int y) {
		x -= y; if (x < 0) x += MOD;
	}
	inline int Add(int x, int y) {
		Inc(x, y); return x;
	}
	inline int Sub(int x, int y) {
		Dec(x, y); return x;
	}
	inline int Mul(int x, int y) {
		return 1LL * x * y % MOD;
	}
}
using namespace ModCalculator;

inline int ksm(int x, int k) {
	int ret = 1;
	for (; k; k >>= 1) {
		if (k & 1) ret = Mul(ret, x);
		x = Mul(x, x);
	}
	return ret;
}

int n, m;
int fac[MAXN], finv[MAXN];
int len, lenv, rev[MAXN], w1[MAXN], w2[MAXN];
int dp[2][MAXN], F[MAXN], G[MAXN];

inline int C(int x, int y) {
	if (x < y) return 0;
	return Mul(fac[x], Mul(finv[y], finv[x - y]));
}

void NTT_init(int m) {
	int bit = -1;
	for (len = 1; len <= m; len <<= 1, ++bit);
	lenv = ksm(len, MOD - 2);
	for (int i = 0; i < len; ++i) {
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << bit);
	}
	int Gi = 3, Gv = ksm(Gi, MOD - 2);
	for (int i = 1; i < len; i <<= 1) {
		int wn1 = ksm(Gi, (MOD - 1) / (i << 1)), wk1 = 1;
		int wn2 = ksm(Gv, (MOD - 1) / (i << 1)), wk2 = 1;
		for (int k = 0; k < i; ++k) {
			w1[i + k] = wk1;
			wk1 = Mul(wk1, wn1);
			w2[i + k] = wk2;
			wk2 = Mul(wk2, wn2);
		}
	}
}

void NTT(int *a, int type) {
	int *w = (type == 1? w1 : w2);
	for (int i = 0; i < len; ++i) {
		if (i < rev[i]) {
			swap(a[i], a[rev[i]]);
		}
	}
	for (int i = 1; i < len; i <<= 1) {
		for (int j = 0; j < len; j += (i << 1)) {
			for (int k = 0; k < i; ++k) {
				int x = a[j + k], y = Mul(w[i + k], a[j + k + i]);
				a[j + k] = Add(x, y);
				a[j + k + i] = Sub(x, y);
			}
		}
	}
	if (type == 1) return;
	for (int i = 0; i < len; ++i) {
		a[i] = Mul(a[i], lenv);
	}
}

void init() {
	read(n); read(m);
	fac[0] = 1;
	for (int i = 1; i <= n + 2; ++i) {
		fac[i] = Mul(fac[i - 1], i);
	}
	finv[n + 2] = ksm(fac[n + 2], MOD - 2);
	for (int i = n + 2; i >= 1; --i) {
		finv[i - 1] = Mul(finv[i], i);
	}
	NTT_init(n + n);
}

void solve() {
	G[0] = 0;
	for (int i = 1; i <= n; ++i) {
		G[i] = finv[i + 2];
	}
	NTT(G, 1);
	int pre = 0, cur = 1;
	dp[pre][0] = 1;
	for (int j = 1; j <= m; ++j) {
		for (int i = 0; i <= n; ++i) {
			dp[cur][i] = Mul(dp[pre][i], C(i + 1, 2) + 1);
			F[i] = Mul(dp[pre][i], finv[i]);
		}
		for (int i = n + 1; i < len; ++i) {
			F[i] = 0;
		}
		NTT(F, 1);
		for (int i = 0; i < len; ++i) {
			F[i] = Mul(F[i], G[i]);
		}
		NTT(F, -1);
		for (int i = 1; i <= n; ++i) {
			Inc(dp[cur][i], Mul(F[i], fac[i + 2]));
		}
		swap(pre, cur);
	}
	int ans = 0;
	for (int i = 0; i <= n; ++i) {
		Inc(ans, Mul(C(n, i), dp[pre][i]));
	}
	printf("%d\n", ans);
}

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



Measured memory_bytes: 640
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(long[]);
    foreach (a; AS) if (a == 0) {
        writeln(0);
        return;
    }
    long r = 1;
    foreach (a; AS) {
        if (r * a < r || r * a > 10L^^18) {
            writeln(-1);
            return;
        }
        r *= a;
    }
    writeln(r);
}

Measured memory_bytes: 7156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N; cin >> N;
    vector < ll > X(N);
    loop(i,0,N) cin >> X[i];
    vector < vector < pair<ll, ll> > > dp(N, vector <pair<ll,ll>> (N));
    loop(i,0,N) dp[i][i]={0,X[i]};
    loop(i,0,N-1) dp[i][i+1] = {X[i]+X[i+1], X[i]+X[i+1]};
    loop(k, 2, N) {
        loop(i,0,N-k) {
            ll mincost = dp[i][i].first + dp[i][i].second + dp[i+1][i+k].first + dp[i+1][i+k].second;
            int split = i;
            loop(j,1,k) {
                if (dp[i][i+j].first + dp[i][i+j].second + dp[i+j+1][i+k].first + dp[i+j+1][i+k].second < mincost) {
                    mincost = dp[i][i+j].first + dp[i][i+j].second + dp[i+j+1][i+k].first + dp[i+j+1][i+k].second;
                    split=i+j;
                }
            }
            dp[i][i+k] = {mincost, dp[i][split].second + dp[split+1][i+k].second };
        }
    }
    cout << dp[0][N-1].first << "\n";
    return 0;
}

Measured memory_bytes: 2816
# Problem C - Energy Drink Collector
# input
N, M = map(int, input().split())
ab_list = []
for i in range(N):
    a, b = map(int, input().split())
    ab_list.append([a, b])

# initialization
nokori = M
ab_list = sorted(ab_list, key= lambda x: x[0])
ans = 0

# count
i = 0
while nokori>0:
    ab = ab_list[i]
    a = ab[0]
    b = ab[1]
    if b<=nokori:
        ans += a * b
        nokori -= b
    else:
        ans += a * nokori
        break
    i += 1

# output
print(ans)


Measured memory_bytes: 25952
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

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

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int x; cin >> x;
  bool dp[100010] = {false};
  dp[0] = true;
  vector<int> items = {100, 101, 102, 103, 104, 105};

  for (int item : items) {
    for (int i = 0; i <= x - item; i++) {
      if (dp[i]) dp[i + item] = true;
    }
  }

  outl(dp[x]);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 384
def main():
    N = int(input())
    if N % 2 == 0:
        pair = N + 1
    else:
        pair = N
    ans = set()
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i+j != pair:
                ans.add((i, j))
    print(len(ans))
    for a in ans:
        print(a[0], a[1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 43888
//Be Name Khoda
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma optimize O3
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
const ll M=1e5+5,LG=32,SM=600+5,inf=1e18+5;
ll mod=1e9+7;

ll n;

ll jad[3][M];
ll z[2];
ll p[2][M];
ll ip[M];

bool calc(ll a[M])
{
    For(i,0,n)
    {
        //cout << a[i] << ' ';
        ip[a[i]]=i;
    }
    //cout << '\n';
    bool res=0;
    For(i,0,n)
    {
        if (ip[i]!=i)
        {
            ip[a[i]]=ip[i];
            swap(a[i],a[ip[i]]);
            ip[i]=i;
            res^=1;
        }
    }
    return res;
}

int main()
{
    cin >> n;
    For(rep,0,3)
    For(i,0,n)
        cin >> jad[rep][i];
    For(i,0,n)
    {
        ll x=jad[1][i];
        if (x%3!=2) RET("No");
        if (jad[0][i]==x+1 && jad[2][i]==x-1)
            z[i&1]^=1;
        else if ( jad[0][i] != x-1 ||
            jad[2][i] != x+1)
            RET("No");
        x/=3;
        if (x%2!=i%2) RET("No");
        x/=2;
        p[i%2][i/2]=x; 
    }
    ll x=n%2;
    n/=2;
    if (z[0]!=calc(p[1])) RET("No");
    n+=x;
    if (z[1]!=calc(p[0])) RET("No");
    RET("Yes");
}    


Measured memory_bytes: 4096
n,k=map(int,input().split())
lista = [int(i) for i in input().split()]
import functools
#from functools import reduce
import fractions
#from fractions import gcd

gcda=functools.reduce(fractions.gcd, lista)

if k>max(lista):
    print("IMPOSSIBLE")
else:
    if k%gcda==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Measured memory_bytes: 81684
n, m = map(int, input().split())
a = list(map(int, input().split()))

sum_v = sum(a)
border = sum_v / (4*m)
count = 0
for i in a:
    if i >= border:
        count += 1
if count >= m:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,D,X;
  cin >> N >> D >> X;
  vector<int> A(110);
  for(int i=0;i<N;i++){cin >> A[i];}
  int sum=0;
  for(int i=0;i<N;i++){
    if(D%A[i]==0){sum+=D/A[i];}
    else{sum+=D/A[i]+1;}
  }
  cout << X+sum << endl;
}

Measured memory_bytes: 256
N,A,B,C = map(int, input().split())
S = [input() for _ in range(N)]


L = []
ans = "Yes"

if A == 0 and B == 0 and C == 0:
    ans = "No"
    
for i in range(N):
    s = S[i]
    if s == "AB":
        if A < B:
            A += 1
            B -= 1
            L.append("A")
        elif A > B:
            A -= 1
            B += 1
            L.append("B")
        else:
            if i < N-1 and S[i+1] == "BC":
                B += 1
                A -= 1
                L.append("B")
            else:
                A += 1
                B -= 1
                L.append("A")
    elif s == "BC":
        if B < C:
            B += 1
            C -= 1
            L.append("B")
        elif B > C:
            B -= 1
            C += 1
            L.append("C")
        else:
            if i < N-1 and S[i+1] == "AB":
                B += 1
                C -= 1
                L.append("B")
            else:
                C += 1
                B -= 1
                L.append("C")
    else:
        if A < C:
            A += 1
            C -= 1
            L.append("A")
        elif A > C:
            A -= 1
            C += 1
            L.append("C")
        else:
            if i < N-1 and S[i+1] == "BC":
                C += 1
                A -= 1
                L.append("C")
            else:
                A += 1
                C -= 1
                L.append("A")
    if A*B*C < 0:
        ans = "No"

        
print(ans)
if ans == "Yes":
    for l in L:
        print(l)

Measured memory_bytes: 85412
#include<stdio.h>
int main(void)
{
  int a,b;
  scanf("%d%d",&a,&b);
  if((a>0)||((b<0)&&((b-a)%2==1))){
    puts("Positive");
  } else if((a<0)&&(b>0)){
    puts("Zero");
  } else{
    puts("Negative");
  }
  return 0;
}


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

namespace ABC149
{
    class D
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = input[0];
            int K = input[1];

            input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int R = input[0];
            int S = input[1];
            int P = input[2];

            string T = Console.ReadLine();

            char[] k = new char[K];
            long res = 0;
            char next = ' ';
            for (int i = 0; i < N; i++)
            {

                if (i + K < N) next = T[i + K];
                else next = ' ';

                if (k[i % K] != 'p' && T[i] == 'r') { res += P; k[i % K] = 'p'; }
                else if (k[i % K] == 'p' && T[i] == 'r')
                {
                    if (next == 's') k[i % K] = 's';
                    else k[i % K] = 'r';
                }

                if (k[i % K] != 'r' && T[i] == 's') { res += R; k[i % K] = 'r'; }
                else if (k[i % K] == 'r' && T[i] == 's')
                {
                    if (next == 'p') k[i % K] = 'p';
                    else k[i % K] = 's';
                }


                if (k[i % K] != 's' && T[i] == 'p') { res += S; k[i % K] = 's'; }
                else if (k[i % K] == 's' && T[i] == 'p')
                {
                    if (next == 'r') k[i % K] = 'r';
                    else k[i % K] = 'p';
                }
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13536
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
using namespace std;

int main () {
	int n;
	cin >> n;
	string ans = "No";
	for(int i = 1; i <= 9; i++) {
		for(int j = i; j <= 9; j++) {
			if((i * j) == n) ans = "Yes";
		}
	}
	cout << ans;
	return 0;
}  

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

struct dist{
    int mg, wk;

    bool operator <=(const dist& r){
        if(this->mg != r.mg) return this->mg < r.mg;
        else return this->wk <= r.wk;
    }
};

struct P{
    int h, w;
};

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

int main()
{
    int h, w, sh, sw, th, tw;
    cin >> h >> w >> sh >> sw >> th >> tw;
    sh--; sw--; th--; tw--;
    string s[h];
    rep(i, h) cin >> s[i];

    arr<int> g(h, vector<int>(w));
    rep(i, h) rep(j, w) {
        g[i][j] = INF;
    }

    // pr(-1); return 0;
    g[sh][sw] = 0;
    // queue<P> que;
    deque<P> que;
    que.push_back({sh, sw});

    while(!que.empty()){
        // queue<P> next_q;
        // // if(cnt++ > h+w) break;
        // // pr(1);
        // while(!que.empty()){
            int x, y;
            x = que.front().h;
            y = que.front().w;
            que.pop_front();
            int d = g[x][y];

            rep(i, 4){
                int nx = x+dx[i], ny = y+dy[i];
                if(nx<0 || nx>=h || ny<0 || ny>=w) continue;
                if(s[nx][ny]=='#') continue;
                if(g[nx][ny] <= d) continue;
                g[nx][ny] = d;
                que.push_front({nx, ny});
            }

            FOR(i, -2, 3) FOR(j, -2, 3){
                int nx = x+i, ny = y+j;
                if(nx<0 || nx>=h || ny<0 || ny>=w) continue;
                if(s[nx][ny]=='#') continue;
                if(g[nx][ny] <= d+1) continue;
                g[nx][ny] = d+1;
                que.push_back({nx, ny});
            }
        // }
        // que = next_q;
    }

    int ans = g[th][tw];
    if(ans == INF) pr(-1);
    else pr(ans);
    return 0;}

Measured memory_bytes: 9552
#include<bits/stdc++.h>
#include<numeric>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i <= (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans;

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

	ll N, C, K;
	cin >> N >> C >> K;

	vector<ll> T(N);
	rep(i,N){
		cin >> T[i];
	}
	sort(T.begin(),T.end());

	rep(index,N){
		ll end = T[index] + K;
		ll cnt=1;
		while(1){
			if(cnt>=C || index==N-1) break;

			if(end >= T[index + 1]){
				cnt++;
				index++;
			}
			else break;
		}
		// cout << index << ": " <<  cnt << endl;
		ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
class comb():
  F = [1, 1]
  Fi = [1, 1]
  I = [0, 1]
  def __init__(self, num, mod):
    self.MOD = mod
    for i in range(2, num + 1):
      self.F.append((self.F[-1] * i) % mod)
      self.I.append(mod - self.I[mod % i] * (mod // i) % mod)
      self.Fi.append(self.Fi[-1] * self.I[i] % mod)
  def com(self, n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return self.F[n] * (self.Fi[k] * self.Fi[n - k] % self.MOD) % self.MOD


K = int(input())
S = input()
MOD = 10 ** 9 + 7

N = K + len(S)
M = len(S)
com = comb(N + 1, MOD)

p25 = [1]
for i in range(N + 1):
  p25.append(p25[-1] * 25 % MOD)

ans = 0

for i in range(K + 1):
  t = M + i
  ans = (ans + p25[N - t] * com.com(N, t)) % MOD

print(ans)


Measured memory_bytes: 242092
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
map<long long, int> freqs;
map<long long, int> allfreqs;
long long choose(long long n, long long k){
   if (k == 0) return 1;
   return (n * choose(n - 1, k - 1)) / k;
}
int main ()
{
  prep();

  int n, a, b;
  cin >> n >> a >>b;
  long long arr[n];
  for (int i=0; i<n; i++){
      cin >> arr[i];
      allfreqs[arr[i]]++;
  }
  sort(arr, arr+n);
  // if all one number, do all combos of that num, else do combos of x y's etc
  set<long long> all; 
  double avg = 0;
  for (int i=n-1; i>=n-a; i--){
      freqs[arr[i]]++;
      all.insert(arr[i]);
      avg += arr[i];
  }
  avg /= a;
  printf("%.6lf\n", avg);
  long long sum = 0;
  if (all.size() == 1){
      int many = allfreqs.find(arr[n-1])->second;
      for (int i=a; i<=b; i++){
         sum += choose(many, i);
      }
      
  }else{
      sum++;
      for (long long i : all){
          int freq = freqs.find(i)->second;
          sum *= choose(allfreqs.find(i)->second, freq);
      }
  }
  printf("%llu", sum);
  return 0; 
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int height[10];
  int i, j;
  int tmp;

  for(i=0;i<10;i++){
    scanf("%d", &height[i]);
  }
  
  for(i=0;i<9;i++){
    for(j=i;j<=9;j++){
      if(height[i] <= height[j]){
	tmp = height[i];
	height[i] = height[j];
	height[j] = tmp;
      }
    }
  }

  for(i=0;i<3;i++){
    printf("%d\n", height[i]);
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
#define GETINT(x) int (x); cin >> (x);
#define FOR(i, N) for(int i = 0; i < (N); (i)++)
#define RET cout << endl;
constexpr int _10e(int n) { return n == 0 ? 1 : 10 * _10e(n - 1); }

int main() {
    GETINT(X);
    GETINT(Y);
    cout << X + Y / 2 << endl;

    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
template <typename T>
using V = std::vector<T>;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  V<tuple<int, int, bool>> events;
  REP(i, n) {
    int a, b;
    cin >> a >> b;
    events.emplace_back(a, b, true);
  }
  REP(i, n) {
    int c, d;
    cin >> c >> d;
    events.emplace_back(c, d, false);
  }
  sort(events.begin(), events.end());
  set<int> s;
  int cnt = 0;
  for (auto [x, y, is_red] : events) {
    if (is_red) {
      s.insert(y);
    } else {
      auto it = s.lower_bound(y);
      if (it == s.begin()) continue;
      --it;
      ++cnt;
      s.erase(it);
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) a[i] = i + 1;
    for(int i = 0; i < n; i++) b[i] = i + 1;
    vector<int> p(n), q(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < n; i++) cin >> q[i];
    int f = 0;
    int A, B;
    int cnta = 0, cntb = 0;
    do {
        cnta++;
        bool ok = true;
        for(int i = 0; i < n; i++) {
            if(a[i] != p[i]) {
                ok = false;
                break;
            }
        }
        if(ok) {
            A = cnta;
        }
    }while(next_permutation(a.begin(), a.end()));
    do {
        cntb++;
        bool ok = true;
        for(int i = 0; i < n; i++) {
            if(b[i] != q[i]) {
                ok = false;
                break;
            }
        }
        if(ok) {
            B = cntb;
        }
    }while(next_permutation(b.begin(), b.end()));

    int ans = abs(A-B);
    cout << ans << endl;
}

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

int main (){
    ll a,b,k;   cin >> a >> b >> k;

    ll n;
    n = max(a,b);
    
    vector<int> j;
    
    for(int i=1;i<=n;i++){

        if( a % i == 0 && b % i == 0){
            
            j.push_back(i);
        }

    }


    
        cout << j.at(j.size()-k) << endl;
    


    
  
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int N=scan.nextInt();
        int N2=N;
        int[] order=new int[10];
        int i=0;
        int answer=0;
        while(N!=0){
            order[i]=N%10;
            answer+=order[i];
            N/=10;
        }
        if(N2%answer==0){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
#include<cstdio>
#include<cmath>
using namespace std;
#define N 3050
int n,l,v[N];
double pi=acos(-1),su[N][2],as1,as2;
int main()
{
	scanf("%d%d",&n,&l);l*=2;
	for(int i=1;i<=n;i++)scanf("%d",&v[i]),v[i]*=2,su[i][0]=su[i-1][0]+cos(pi*v[i]/l),su[i][1]=su[i-1][1]+sin(pi*v[i]/l);
	for(int i=1;i<=n;i++)
	for(int j=i+2;j<=n;j++)
	{
		long long su1=1ll*v[i]+v[j];
		if(su1<l)
		{
			int st=l-(l-su1)/2;
			double c1=cos(pi*st/l+1.5*pi),c2=sin(pi*st/l+1.5*pi);
			double v1=c1*(su[j-1][0]-su[i][0])-c2*(su[j-1][1]-su[i][1]),v2=c2*(su[j-1][0]-su[i][0])+c1*(su[j-1][1]-su[i][1]);
			double st1=cos(v[i]*pi*2/l)-cos(st*pi*2/l),st2=sin(v[i]*pi*2/l)-sin(st*pi*2/l);
			double le1=sqrt(st1*st1+st2*st2);
			v1*=le1,v2*=le1;
			v1+=cos(st*pi*2/l)*(j-i-1),v2+=sin(st*pi*2/l)*(j-i-1);
			as1+=v1,as2+=v2;
		}
		else
		{
			int st=(su1-l)/2;
			double c1=cos(pi*st/l+0.5*pi),c2=sin(pi*st/l+0.5*pi);
			double v1=c1*(su[j-1][0]-su[i][0])-c2*(su[j-1][1]-su[i][1]),v2=c2*(su[j-1][0]-su[i][0])+c1*(su[j-1][1]-su[i][1]);
			double st1=cos(v[i]*pi*2/l)-cos(st*pi*2/l),st2=sin(v[i]*pi*2/l)-sin(st*pi*2/l);
			double le1=sqrt(st1*st1+st2*st2);
			v1*=le1,v2*=le1;
			v1+=cos(st*pi*2/l)*(j-i-1),v2+=sin(st*pi*2/l)*(j-i-1);
			as1+=v1,as2+=v2;
		}
	}
	double st1=1.0*n*(n-1)*(n-2)/6;
	as1/=st1,as2/=st1;
	printf("%.15lf %.15lf\n",as1,as2);
}

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

int main() {

	char **c;     //?????????
	int W ,H;     //?????????????¨??????¨??????
	int i,j;      //???????????¨?????°
	int a=0;      //??????????´???¨??????????????°
	int count;    //??????
	int flag;     //??¢?´¢????¶?????????????????????????????????°
	int A[10000]; //??????????´???¨??????

	for(;;) {

	scanf("%d %d",&W,&H); //?¨??????¨???????????\???

	if(W==0&&H==0) break;

	c = malloc(sizeof(char *) * H);

	for(i=0;i<H;i++) {
		c[i] = malloc(sizeof(char)*W);
	}

	for(i=0;i<H;i++)
		scanf("%s",c[i]); //??????????????\???

	count=1;
	flag=1;

	while(flag) { //??¢?´¢????§?
		flag = 0;
		for(i=0;i<H;i++) {
			for(j=0;j<W;j++) {
				if(c[i][j]=='@') {
					if(i!=0&&c[i-1][j]=='.') { //???????§????
						count++;
						c[i-1][j]='@';
						flag=1;
					}
					if(j!=W-1&&c[i][j+1]=='.') { //???????§????
						count++;
						c[i][j+1]='@';
						flag=1;
					}
					if(i!=H-1&&c[i+1][j]=='.') { //???????§????
						count++;
						c[i+1][j]='@';
						flag=1;
					}
					if(j!=0&&c[i][j-1]=='.') { //???????§????
						count++;
						c[i][j-1]='@';
						flag=1;
					}
				}
			}
		}
	} //??¢?´¢????¶???????flag??????????¶???????

	A[a]=count;
	a++;

	free(c);
	}

	for(i=0;i<a;i++)
		printf("%d\n",A[i]);

	return 0;
}

Measured memory_bytes: 744
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(n)-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define mod 1000000007
#define INF 1000000000000000000
/****************************/
int n;
int a[100010];
vi v;
string s;
int main()
{
	double ans;
	int r;
	cin>>r;
	ans=double(r*2.0000000*pi);
	printf("%.6f",ans);
    return 0;
}

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

using namespace std;

int main()
{
	int A, B;

	scanf("%d", &A);
	scanf("%d", &B);

	vector<int> P(A);
	vector<int> Q(B);

	for (int i = 0; i < A; i++) { scanf("%d", &P[i]); }
	for (int i = 0; i < B; i++) { scanf("%d", &Q[i]); }

	int l = 1;
	int r = B;
	int m;

	while(r - l > 1)
	{
		m = (l + r) / 2;

		bool ok = false;

		for (int j = 0; j < (B - m); j++)
		{
			int ptr = j;

			for (int k = 0; k < A; k++)
			{
				if (P[k] == Q[ptr])
				{
					ptr++;
				}

				if (ptr == j + m)
				{
					break;
				}
			}

			if (ptr == j + m)
			{
				ok = true;
			}
		}

		if (ok)
		{
			l = m;
		}
		else
		{
			r = m;
		}
	}

	printf("%d\n", l);

	return 0;
}

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

#define INF 1e18
#define PI 3.141592653589793238
typedef long long ll;
#define N 200010

int main() {
    int a,b;cin>>a>>b;
    int ans=1;
    while(ans<1010){
        if(floor(ans*0.08)==a && floor(ans*0.1)==b) break;
        ans++;
    }
    if(ans==1010)cout<<-1<<endl;
    else cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 3564
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import           Control.Monad
import           Control.Monad.Primitive     (PrimMonad, PrimState)
import qualified Data.ByteString.Char8       as BS
import           Data.Char                   (isSpace)
import           Data.List                   (unfoldr)
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM

-- Union Find
newUnionFindTree :: PrimMonad m => Int -> m (UM.MVector (PrimState m) Int)
newUnionFindTree n = U.thaw $ U.enumFromN 0 n

getRoot :: PrimMonad m => UM.MVector (PrimState m) Int -> Int -> m Int
getRoot !v = go
  where
    go !i = do
      j <- UM.read v i
      if i == j then
        return i
      else do
        k <- go j
        UM.write v i k
        return k
{-# INLINE getRoot #-}

unify :: PrimMonad m => UM.MVector (PrimState m) Int -> Int -> Int -> m ()
unify !v !i !j = do
  i' <- getRoot v i
  j' <- getRoot v j
  unless (i' == j') $ do
    let !k = min i' j'
    UM.write v i' k
    UM.write v j' k
{-# INLINE unify #-}

main = do
  [n,q] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  uf <- newUnionFindTree n
  replicateM_ q $ do
    [t,u,v] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    if t == 0 then
      unify uf u v
    else do
      i <- getRoot uf u
      j <- getRoot uf v
      putStrLn $ if i == j then "1" else "0"


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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  long long int ans = 0;
  for(int i=0;i<n-1;i++) {
    if(a[i] + a[i+1] <= x) continue;
    else {
      ans += a[i+1] + a[i] - x;
      a[i+1] = max(0, x - a[i]);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
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; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n;
  cin >> n;
  ll a;
  bool fla = false;
  ll ans = 0;
  rep(i,n){
    cin >> a;
    if(a==i+1){
      if(fla){
        fla=false;
      }else{
        ans++;
        fla=true;
      }
    }else{
      fla=false;
    }
  }
  pri(ans);
  return 0;
}



Measured memory_bytes: 256
def data_input():
    a = input()
    b = input()
    c = input()
    d = input()
    return (int(a),b,c,d)
def answer():
    n,a,b,c = data_input()
    counta = 0
    for i in range(n):
        count = 0
        if a[i] != b[i]:
            count += 1
        if a[i] != c[i]:
            count += 1
        if b[i] != c[i]:
            count += 1
        if count != 0:
            count -= 1
        counta += count

    return counta

def output():
    res = answer()
    print(res)
output()

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

using namespace std;

int main() {
    int ar[8];
    ar[7] = 0;
    ar[5] = 0;
    int a;
    cin>>a;
    ar[a]++;
    cin>>a;
    ar[a]++;
    cin>>a;
    ar[a]++;
    if(ar[7]==1 && ar[5] == 2) cout<<"YES";
    else cout<<"NO";
}


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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int h, w;
vector<string> g;

int bfs() {
	vector<vector<int>> dist(h, vector<int>(w));
	queue<pair<int, int>> que;
	que.emplace(0, 0);

	g[0][0] = '#';
	while (!que.empty()) {
		int x = que.front().second;
		int y = que.front().first;
		que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];

			if (nx < 0 || nx >= w || ny < 0 || ny >= h) {
				continue;
			} else if (g[ny][nx] == '#') {
				continue;
			} else if (nx == w - 1 && ny == h - 1) {
				return dist[y][x] + 1;
			}

			dist[ny][nx] = dist[y][x] + 1;
			g[ny][nx] = '#';
			que.emplace(ny, nx);
		}
	}

	return dist[h - 1][w - 1];

}

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

	cin >> h >> w;

	g.resize(h);
	for (int i = 0; i < h; i++) {
		cin >> g[i];
	}

	int safe = 0;
	for (auto s : g) {
		for (auto c : s) {
			safe += c == '.';
		}
	}

	int cnt = bfs();
	cout << (cnt == 0 ? -1 : safe - (cnt + 1)) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		D(sc);
	}
	
	public static void A(Scanner sc) {
		int n = sc.nextInt();
		int k = sc.nextInt()-1;
		String s = sc.next();
		System.out.println(s.substring(0,k)+Character.toLowerCase(s.charAt(k))+s.substring(k+1,n));
	}
	
	public static void B(Scanner sc) {
		String s = sc.next();
		if((Integer.valueOf(s.substring(0,2))==0 || Integer.valueOf(s.substring(0,2))>=13) && Integer.valueOf(s.substring(2,4))<=12 && Integer.valueOf(s.substring(2,4))>=1) System.out.println("YYMM");
		else if((Integer.valueOf(s.substring(2,4))>=13 ||Integer.valueOf(s.substring(2,4))==0)&& Integer.valueOf(s.substring(0,2))<=12 && Integer.valueOf(s.substring(0,2))>=1) System.out.println("MMYY");
		else if(Integer.valueOf(s.substring(2,4))<=12 && Integer.valueOf(s.substring(0,2))<=12 && Integer.valueOf(s.substring(2,4))>=1 && Integer.valueOf(s.substring(0,2))>=1) System.out.println("AMBIGUOUS");
		else System.out.println("NA");
	}
	
	public static int findminl(int x, int k) {
		int ret = 1;
		int pro = x*2;
		while(pro<k) {
			ret++;
			pro*=2;
		}
		return ret;
	}
	
	public static void C(Scanner sc) {
		int n = sc.nextInt();
		int k = sc.nextInt();
		double ret = (n>=k)? (n-k+1)/(double)n:0.0;
		for(int i=1;i<=Math.min(k-1,n);i++) ret+=((1.0/Math.pow(2.0, findminl(i,k)))*(1.0/n));
		System.out.println(ret);
	}
	
	public static void colin(int root, ArrayList<ArrayList<int[]>> edge,  int[] col, boolean even) {
		if(col[root]!=0) return;
		if(even) col[root]=1;
		else col[root]=-1;
		for(int[] nw :edge.get(root)) {
			boolean ev;
			if(nw[1]%2==0) ev = even;
			else ev = !even;
			colin(nw[0],edge,col,ev);
		}
	}
	
	public static void D(Scanner sc) {
		int n = sc.nextInt();
		int[] col = new int[n+1];
		col[0] = 2;
		ArrayList<ArrayList<int[]>> edge = new ArrayList<ArrayList<int[]>>();
		for(int i=0;i<=n;i++) {
			edge.add(new ArrayList<int[]>());
		}
		for(int i=1;i<=n-1;i++) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			int w = sc.nextInt();
			edge.get(u).add(new int[] {v,w});
			edge.get(v).add(new int[] {u,w});
		}
		for(int i=1;i<=n;i++) {
			if(col[i]==0) colin(i,edge,col,true);
		}
		for(int i=1;i<=n;i++) {
			if(col[i]==1) System.out.println(1);
			else System.out.println(0);
		}
	}
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= i+1;
	}
	SORT(a);
	LL center;
	if (n % 2 == 1) {
		center = a[n/2];
	}
	else {
		center = (a[n/2] + a[n/2 - 1]) / 2;
	}
	LL ans = 0;
	for (int i = 0; i < n; i++) {
		ans += abs(a[i] - center);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;
const int MOD=1000000007;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }



int main(int argc, char**argv){
    int n;
    cin >> n;

    ll ans = 1;
    for (int i = 1;  i <= n; i++){
        ans *= i;
        ans %= MOD;
   }
    cout << ans << endl;


    return 0;
}


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

int compare(const void *a,const void *b){
	return *(int*)a-*(int*)b;
}

int minsiumai(int n, int a[n]){
    qsort(a,n,sizeof(a[n]),compare);
    return a[0];
}


int main(void){
    int n,i,k,j;
    scanf("%d",&n);
    scanf("%d",&k);

    int h[n],c[n],a[k];

    for(i=0;i<n;i++){
        scanf("%d",&h[i+1]);    
    }

/* kまでの最小　c[k] kの高さh[k]   */

    for(i=0;i<n+1;i++){
        c[i]=0;
    }

    for(i=0;i<n;i++){
        // if(i==0){
        //     c[i+2]=fabs(h[2]-h[1]);
        //     if(n==2){
        //         break;
        //     }else{
        //         continue;
        //     }
        // }


        if(i<k-1){
            for(j=0;j<i+1;j++){
                a[j] = c[ 1+j ] + fabs( h[ i+2 ] - h[ 1+j ] );
            }

            c[i+2] = minsiumai(i+1,a);
            // printf("%d\n",c[i+2]);
            continue;
        }







        if(i==n-1) break;
        
        for(j=0;j<k;j++){
            a[j] = c[i+j-k+2] + fabs( h[i+2] - h[i-k+2+j] );
        }





        c[i+2] = minsiumai(k,a);

        // printf("%d\n",c[i+2]);

        // a[0] = c[i + 1] + fabs(h[i + 2] - h[i + 1]) ;
        // a[1] =  c[i] + fabs(h[i + 2] - h[i]);



        // c[ i + k ] = minsiumai(k,a);

        // if(c[i + 1] + fabs(h[i + 2] - h[i + 1]) > c[i] + fabs(h[i + 2] - h[i])){
        //     c[i+2] =  c[i] + fabs(h[i + 2] - h[i]);
            
        // }else{
        //     c[i+2] = c[i+1] + fabs(h[i + 2] - h[i + 1]);
        // }

    }
    // for(i=0;i<n+1;i++){
    //     printf("%d\n",c[i]);
    // }
    printf("%d\n",c[n]);
    return 0;
}


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

#define LL long long
#define int long long
#define MIN LLONG_MIN
#define MAX LLONG_MAX
#define PB push_back
#define N 200001
#define MX 262144
#define LG 17
#define M 1000000007
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define LD long double
#define F first
#define S second
#define endl "\n"

int32_t main()
{
    LL i,j,lt,d,z,v,c,r,l,t1,k,h,u,q,ts,te,x,y,n,m;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    vector<LL> adj[n+1];
    for(i=1;i<=m;i++)
    {
        cin>>x>>y;
        adj[x].PB(y);
    }
    cin>>x>>y;
    LL ds[n+1][3];
    set<pair<LL,pair<LL,LL>>> di;
    for(i=0;i<=n;i++)
        for(j=0;j<3;j++)
            ds[i][j]=INT_MAX;
    ds[x][0]=0;
    di.insert({0,{x,0}});
    while(!di.empty())
    {
        auto tm=*di.begin();
        di.erase(di.begin());
        LL u=tm.S.F;
        z=tm.S.S;
        k=tm.F;
        // cout<<u<<" "<<k<<" "<<z<<endl;
        if(u==y&&z==0)
        {
            cout<<k/3<<endl;
            return 0;
        }
        k++;
        z=(z+1)%3;
        for(auto v:adj[u])
        {
            if(ds[v][z]>k)
            {
                di.erase({ds[v][z],{v,z}});
                ds[v][z]=k;
                di.insert({ds[v][z],{v,z}});
            }
        }
    }
    cout<<-1;
    return 0;
}   

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

int main(){
  string s;
  cin >> s;
  
  rep(i, s.size()) s.at(i) = 'x';
  
  cout << s << endl;
  
  
}

Measured memory_bytes: 256