akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
#define MAX 200100
//#define NIL -1
//#define INFTY 1000000000000000000

vector<LL> parent(MAX);
vector<LL> length(MAX);

void init(LL n){
    for(LL i=0; i<n; i++){
        parent[i]=i;
        length[i]=1;
    }
}

int find(LL x){
    while(parent[x]!=x){
        x=parent[x];
    }
    return x;
}

bool same(LL x, LL y){
    return find(x)==find(y);
}

bool unite(LL x, LL y){
    x=find(x);
    y=find(y);
    if(x==y){
        return false;
    }
    if(length[x]<length[y]){
        swap(x,y);
    }
    parent[y]=x;
    length[x]+=length[y];
    return true;
}

int main(){
    LL n;
    LL m;
    cin >> n >> m;
    vector<LL> num(n, 0);
    LL a;
    LL b;

    init(n);
    for(LL i=0; i<m; i++){
        cin >> a >> b;
        a--;
        b--;
        unite(a,b);
    }

    for(LL i=0; i<n; i++){
        LL tmp=find(i);
        num[tmp]++;
    }
    LL ans=0;
    for(LL i=0; i<n; i++){
        ans=max(ans,num[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8012
public class Main
{
  public static void main(String[]args)
  {
    for(int i = 1;i<10;i++)
    {
      for(int j = 1;j<10;j++)
      {
        int temp = i*j;
        System.out.println(i+"x"+j+"="+temp);
      }
    }
  }
}

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

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

const ll INF = 1LL << 60;

int N, W;
ll dp[110][100010];
ll w[100], v[100];

int main(){
    cin >> N >> W;
    rep(i, N){
        cin >> w[i] >> v[i];
    }

    for(int i = 0; i<N; ++i){
        for(int sum_w = 0; sum_w<=W; ++sum_w){
            if(sum_w - w[i] >= 0){
                chmax(dp[i+1][sum_w], dp[i][sum_w-w[i]] + v[i]);
            }
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    cout << dp[N][W] << endl;
}


Measured memory_bytes: 81668
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

ll modpow(ll x, ll n){
	ll res = 1;
	while(n > 0){
		if(n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

vector<ll> fac(MAX), finv(MAX), inv(MAX);

void comInit(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(ll i=2; i<MAX; i++){
		fac[i] = fac[i-1]*i % mod;
		inv[i] = mod - inv[mod%i] * (mod/i) % mod;
		finv[i] = finv[i-1] * inv[i] % mod;
	}
}


ll com(ll n, ll k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main(){
	ll n; cin >> n;
	comInit();
	vl c(n); rep(i,n) cin >> c[i];
	ll dec = 0;
	REP(i,2,n+1){
		dec += com(n-2,i-2);
		dec %= mod;
	}
	sort(all(c));
	vl t(n,0);
	REP(i,1,n+1){
		t[0] += i * com(n-1,i-1) % mod;
		t[0] %= mod;
	}
	REP(i,1,n){
		t[i] = t[i-1] - dec;
		if(t[i]<0) t[i] += mod;
	}
	ll sum = 0;
	rep(i,n) sum += t[i]*c[i], sum %= mod;
	cout << sum * modpow(2,n) % mod << endl;
}

Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 59; //MAX 9223372036854775807

int main()
{
ll n;
cin >> n;
ll ans[n+1] = {};
ll t[n+1] = {};
rep(i, n){
    cin >> t[i+1];
}
for (ll i = n; i > 0; i--)
{
    ll ch=i;
    ll now=ch*2;
    ll sum=0;
    while(now<=n){
        sum+=ans[now];
        now+=ch;
    }
    if((sum%2)^t[i])ans[i]=1;
    else ans[i]=0;
}
ll m=0;
rep(i,n+1){
if(ans[i])m++;
}
cout << m << endl;
bool aaa=0; 
rep(i,n){
    if(ans[i+1]){
        if(aaa){cout << " ";}
        cout  <<i+1;
        aaa=1;
    }
}
if(aaa)cout <<  endl;
return 0;
}



Measured memory_bytes: 3968
N = int(input())
N3 = N//3
N5 = N//5
N15 = N//15

S = N * (N+1) // 2
S3 = N3 * (N3+1) // 2 *3
S5 = N5 * (N5+1) // 2 *5
S15 = N15 * (N15+1) // 2 *15

sum = S - (S3 + S5 -S15)
print(sum)

Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

// KMP
template <class T>
std::vector<int> KMP(T& S)
{
    std::vector<int> A(S.size()+1);
    A[0] = -1;
    int j = -1;

    for(int i=0; i<S.size(); i++){
        while(j > -1 && S[j] != S[i]) j = A[j];
        j++;
        A[i+1] = j;
    }

    return A;
}

// detect T from S
template <class Type>
std::vector<int> matchedIndex(Type& S, Type& T)
{
    std::vector<int> ret;
    std::vector<int> A = KMP(T);

    for(int m = 0, i = 0; m + T.size() <= S.size();){
        while(m+i < S.size() && i < T.size() && S[m+i] == T[i]) i++;
        if(i == T.size()) ret.push_back(m);
        m += std::max(i - A[i], 1);
        i = std::max(A[i], 0);
    }

    return ret;
}

int main()
{
    int N;
    cin >> N;
    vector<int> a(N), b(N);
    for(auto& x: a) cin >> x;
    for(auto& x: b) cin >> x;
    a.push_back(a[0]);
    b.push_back(b[0]);
    
    vector<int> c(N), d(2*N);
    for(int i=0; i<N; i++){
        c[i] = a[i] ^ a[i+1];
        d[i] = b[i] ^ b[i+1];
        d[N+i] = d[i];
    }
    d.pop_back();

    vector<int> index = matchedIndex(d, c);
    for(auto& k: index){
        k = (N-k)%N;
    }
    sort(index.begin(), index.end());

    for(auto& k: index){
        cout << k << " " << (a[k] ^ b[0]) << endl;
    }
}

Measured memory_bytes: 8276
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) {}
	ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
};
typedef ModInt<1000000007> mint;

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<int> as(N);
		for(int i = 0; i < N; ++ i)
			scanf("%d", &as[i]);
		vector<int> bs(N);
		for(int i = 0; i < N; ++ i)
			scanf("%d", &bs[i]);
		vector<int> events(N * 2);
		rep(i, N) {
			events[i * 2 + 0] = as[i] * 2 + 0;
			events[i * 2 + 1] = bs[i] * 2 + 1;
		}
		sort(events.begin(), events.end());
		mint ans = 1;
		int cnt[2] = {};
		for(int x : events) {
			if(cnt[1 - x % 2] > 0) {
				ans *= cnt[1 - x % 2];
				-- cnt[1 - x % 2];
			} else {
				++ cnt[x % 2];
			}
		}
		printf("%d\n", ans.get());
	}
	return 0;
}


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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  rep(i, M){
    cin >> A.at(i);
  }
  
  int days = 0;
  rep(i, M){
  	days += A.at(i);
  }
  
  if (days > N) cout << -1 << endl;
  else cout << N - days << endl;
  
  return 0;
}

Measured memory_bytes: 3664
#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 rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(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

bool iGN(ll x, vl d){
    while(x > 0){
        ll temp = x%10;
        x /=10;
        rp(i,sz(d)) if(temp == d[i]) return false;
    }
    return true;
}

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

    vl d;
    ll n,k;
    cin >> n >> k;
    for (ll i = 0,x; i < k; i++) {
        cin >>x;
        d.pb(x);
    }
    while(!iGN(n,d)) ++n;

    cout << n;
    cout << endl;
    return 0;
}

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


Measured memory_bytes: 256
N,K=map(int,input().split())
sum=0
count=1
if N>=K:
	sum+=(N-K+1)/N
	for i in range(K-1,0,-1):
		if i*count < K: count=count*2
		sum+=(1/N)*(1/count)
else:
	while N*count < K: count=count*2
	for i in range(N,0,-1):
		if i*count < K: count=count*2
		sum+=(1/N)*(1/count)
print(sum)

Measured memory_bytes: 3064
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
count=0
for i in range(N):
    count+=min(A[i],B[i])
    if A[i]<B[i]:
        if A[i+1]<B[i]-A[i]:
            count+=A[i+1]
            A[i+1]=0
        else:
            count+=B[i]-A[i]
            A[i+1]-=B[i]-A[i]
print(count)

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

using namespace std;

inline int read(){
	char ch=getchar();int x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

int main(){
	int x=read(),y=read();
	int ans=x+y;
	ans=max(ans,x-y);
	ans=max(ans,x*y);
	cout<<ans;
	return 0;
}


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

using namespace std;

int main() {
	int n, h[101], res = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> h[i];
	while (true) {
		bool canContinue = false;
		for (int i = 1; i <= n; ++i)
			if (h[i])
				canContinue = true;
		if (!canContinue) break;
		for (int i = 1; i <= n;) {
			if (h[i] == 0) { ++i; continue; }
			int j = i + 1;
			while (j <= n && h[j] > 0) ++j;
			///seg[i, j - 1]
			int amin = 1e9 + 7;
			for (int z = i; z <= j - 1; ++z)
				amin = min(amin, h[z]);
			res += amin;
			for (int z = i; z <= j - 1; ++z)
				h[z] -= amin;
			i = j;
		}
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	int kq=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		kq=(kq^a[i]);
	}
	for(int i=0;i<n;i++) cout<<(kq^a[i])<<" ";
}

Measured memory_bytes: 4328
def dfs(a, xs)
  return [true, xs] if a.size == 0

  is = []
  a.size.times{|i| is.push(i) if a[i] == i }
  return [false, []] if is.size == 0

  a.delete_at(is[is.size - 1])
  xs.push(is[is.size - 1])

  ret = dfs(a, xs)
  if ret[0] then
    return ret
  else
    return [false, nil]
  end
end

def main(argv)
  n = gets.chomp.to_i
  b = gets.chomp.split(' ').map(&:to_i)
  
  b.map!{|x| x - 1}
  ret = dfs(b, [])
  if ret[0] then
    ret[1].reverse.map{|x| x + 1}.each do |x|
      puts x.to_s
    end
  else
    puts (-1).to_s
  end
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
#define MAX 500000+2
#define SENTINEL 2000000000
int L[MAX/2+2], R[MAX/2+2], A[MAX];
int cnt;
void merge(int A[], int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	for ( int i = 0; i < n1; i++ ) L[i] = A[left + i];
	for ( int i = 0; i < n2; i++ ) R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	int i = 0, j = 0;
	for ( int k = left; k < right; k++ ) {
		cnt++;
		if ( L[i] <= R[j] ) {
			A[k] = L[i++];
		} else {
			A[k] = R[j++];
		}
	}
}
void mergeSort(int A[], int left, int right) {
	if( left+1 < right ) {
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}
int main(){
	int n, i;
	cnt = 0;
	cin >> n;
	for ( int i = 0; i < n; i++ ) cin >> A[i];
	mergeSort(A, 0, n);
	for ( int i = 0; i < n; i++ ) {
		if ( i ) cout << " ";
		cout << A[i];
	} 
	cout << endl;
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 6980
#include <stdio.h>

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

	int i, t[101], sum = 0;
	for(i = 0; i < n; i++) {
		scanf("%d", &t[i]);
		sum += t[i];
	}

	int j, m, p, x;
	scanf("%d", &m);
	for(i = 0; i < m; i++) {
		scanf("%d %d", &p, &x);
		printf("%d\n", sum + (x - t[p - 1]));
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,C;
  cin>>N>>C;
  vector<vector<int>> D(C,vector<int>(C,0)), c(N,vector<int>(N,0));
  for(int i=0;i<C;i++){
    for(int j=0;j<C;j++){
      cin>>D[i][j];
    }
  }

  vector<vector<int>> count(3,vector<int>(C,0));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      int tmp;
      cin>>tmp;tmp--;
      c[i][j]=tmp;
      count[(i+j)%3][c[i][j]]++;
    }
  }
  int ans=INF;
  for(int i=0;i<C;i++){
    for(int j=0;j<C;j++){
      for(int k=0;k<C;k++){
        if(i==j || j==k || k==i)continue;
        int tmp=0;
        for(int l=0;l<C;l++){
          tmp+=D[l][i]*count[0][l];
          tmp+=D[l][j]*count[1][l];
          tmp+=D[l][k]*count[2][l];
        }
        ans=min(tmp,ans);
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1280
#include"bits/stdc++.h"
using namespace std;

int main() {
	string s,out;
	cin >> s;
	if (s == "Sunny") {
		out = "Cloudy";
	}
	else if (s == "Cloudy") {
		out = "Rainy";
	}
	else {
		out = "Sunny";
	}
	cout << out << endl;
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<long long> h(n);
    for (auto i = 0; i < n; i++)
    {
        long long hi;
        cin >> hi;
        h[i] = hi;
    }

    int ans = 0;

    int p = 0;
    while(p < n){
        int tmp = 0;
        while(p < n-1 && h[p] >= h[p+1]){
            tmp += 1;
            p += 1;
        }

        if(tmp > ans){
            ans = tmp;
        }

        p += 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VL vector<LL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    /*
    int t,n;
    cin>>t;
    loop(t1,1,t+1)
    {
        int a[n];
        loop(i,0,n) cin>>a[i];
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }
    */

    int a,b;
    cin>>a>>b;
    int ans = a * b;
    cout<<ans<<'\n';

    /*
    if(f) cout<<"Yes"<<'\n';
    else cout<<"No"<<'\n';
    */

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

void Print_where_P_is_1(double* x, double* y, int n);
void Print_where_P_is_2(double* x, double* y, int n);
void Print_where_P_is_3(double* x, double* y, int n);
void Print_where_P_is_infin(double* x, double* y, int n);

int main()
{
	cout << fixed << setprecision(6);

	int n;
	cin >> n;

	double *x = new double[n];
	double *y = new double[n];

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

	Print_where_P_is_1(x, y, n);
	Print_where_P_is_2(x, y, n);
	Print_where_P_is_3(x, y, n);
	Print_where_P_is_infin(x, y, n);


	delete[] y;
	delete[] x;

	return 0;
}

void Print_where_P_is_1(double* x, double* y, int n)
{
	double sum = 0;
	for (int i = 0; i < n; i++){
		double d = x[i] - y[i];
		if (d < 0.0)
			d *= -1.0;
		sum += d;
	}
	cout << sum << endl;
}

void Print_where_P_is_2(double* x, double* y, int n)
{
	double sum = 0;
	for (int i = 0; i < n; i++) {
		double d = x[i] - y[i];
		d = d * d;
		sum += d;
	}
	sum = sqrt(sum);
	cout << sum << endl;
}

void Print_where_P_is_3(double* x, double* y, int n)
{
	double sum = 0;
	for (int i = 0; i < n; i++) {
		double d = x[i] - y[i];
		d = d * d * d;
		if (d < 0.0)
			d *= -1.0;
		sum += d;
	}
	sum = cbrt(sum);
	cout << sum << endl;
}

void Print_where_P_is_infin(double* x, double* y, int n)
{
	double max = 0;
	for (int i = 0; i < n; i++) {
		double d = x[i] - y[i];
		if (d < 0.0)
			d *= -1.0;
		if (max < d)
			max = d;
	}
	cout << max << endl;
}



Measured memory_bytes: 3472
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

int main(int argc, void **arg)
{
    long long n;
    long long p[20];
    long long i, j, k;

    scanf("%lld", &n);

    for (i = 0; i < n; i++)
    {
        scanf("%lld", &p[i]);
    }

    k = 0;
    for (i = 1; i < n - 1; i++)
    {
        long long min = p[i];
        long long max = p[i];

        if( min > p[i-1] ) min = p[i-1];
        if( min > p[i+1] ) min = p[i+1];
        if( max < p[i-1] ) max = p[i-1];
        if( max < p[i+1] ) max = p[i+1];

        if( min != p[i] && max != p[i] ) k++;
    }

    printf("%lld\n", k);

    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
using namespace std;
 
int main(){
  int N, K, p[1000];
  cin >> N >> K;
  for (int i=0; i < N; i++){
    cin >> p[i];
  }
  sort(p, p+N);
  int sum = 0;
  for (int i=0; i<K; i++){
  	sum += p[i];
  }
  cout << sum;
}

Measured memory_bytes: 3540
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

int gcd(int A, int B) {
    if(A == 0) return B;
    if(B == 0) return A;
    int tmp;
    if(B > A) {
        tmp = B;
        B = A;
        A = tmp;
    }
    int r;
    while(1) {
        r = A % B;
        A = B;
        if(r == 0) {
            return B;
        }
        B = r;
        
    }
}

int main(void) {
    int N;
    cin >> N;
    vector<long long>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }

    vector<vector<long>> ans_vec(N+2, vector<long>(2));
    ans_vec[1][0] = A[0];
    ans_vec[N][1] = A[N-1];
    ans_vec[0][0] = 0; 
    ans_vec[N+1][1] = 0;
    for(int i = 1; i < N; i++) {
        ans_vec[i][0] = gcd(A[i-1], ans_vec[i-1][0]);
        ans_vec[N-i+1][1] = gcd(A[N-i], ans_vec[N-i+2][1]);
    }
    long long ans = 0;
    for(int i = 0; i < N; i++) {
        long long gcd_i = gcd(ans_vec[i][0], ans_vec[i+2][1]);
        if(ans < gcd_i) ans = gcd_i;
    }
    cout << ans << endl;
    //cout << gcd(12,18) << endl;
    return 0;
}

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

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

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

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



int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll N, M; cin >> N >> M;
	vector<ll> a(N), b(N), c(M), d(M);
	REP(i, N) cin >> a[i] >> b[i];
	REP(i, M) cin >> c[i] >> d[i];

	auto f = [](ll a, ll b, ll c, ll d)
			 {
				 return abs(a - c) + abs(b - d);
			 };
		

	REP(i, N)
	{
		ll res{0};
		ll mi{INF};

		REP(j, M)
		{
			ll tmp = f(a[i], b[i], c[j], d[j]);
			if (mi > tmp)
			{
				mi = tmp;
				res = j;
			}
		}

		std::cout << res + 1 << std::endl;
	}
	
	return 0;
}


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

#define int long long

using namespace std;

const int N = 305;
int dp[N][N], pref[N][N], C[N][N], n, k, m;

signed main(){
    scanf("%lld %lld %lld", &n, &k, &m);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= i; j++) {
            if (i == 0 || j == 0 || i == j) C[i][j] = 1;
            else C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % m;
        }
    }

    memset(dp, 0, sizeof(dp));

    for (int i = 1; i <= k + 1; i++) {
        dp[1][i] = 1;
        if (i == 1) pref[1][i] = dp[1][i];
        else pref[1][i] = (pref[1][i - 1] + dp[1][i]) % m;
    }

    for (int i = 2; i <= n + 1; i++) {
        for (int j = 1; j <= k + 1; j++) {
            for (int p = 1; p <= i - 1; p++) {
                int res = C[i - 2][p - 1];
                res *= dp[p][j]; res %= m;
                res *= pref[i - p][j - 1]; res %= m;

                dp[i][j] = (dp[i][j] + res) % m;
            }

            if (j == 1) pref[i][j] = dp[i][j];
            else pref[i][j] = (pref[i][j - 1] + dp[i][j]) % m;
        }
    }

    printf("%lld", dp[n + 1][k + 1]);
    return 0;
}

Measured memory_bytes: 2432
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

double dfs(const vector<vector<int>> &G, int v, vector<double> &E){
  if(E[v] >= 0) return E[v];
  double ret = 0;
  size_t d = G[v].size();
  for(size_t i = 0; i < d; ++i){
    int v_ = G[v][i];
    double p = dfs(G,v_,E);
    ret += (p+1)/d;
  }
  E[v] = ret;
  return E[v];
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  vector<int> D(N);
  for(int i = 0; i < M; ++i){
    int s, t;
    cin >> s >> t;
    --s,--t;
    G[s].push_back(t);
    ++D[t];
  }
  vector<double> P(N,0);
  P[0] = 1;
  for(int i = 0; i < N; ++i){
    for(auto v : G[i]){
      P[v] += P[i]/G[i].size();
    }
  }
  vector<double> E(N,-1);
  dfs(G,0,E);
  double ans = E[0];
  for(int i = 0; i < N; ++i){
    int d = G[i].size();
    if(d == 1) continue;
    for(auto v : G[i]){
      double t = E[0] - (E[i] - (E[i]*d-(E[v]+1))/(d-1))*P[i];
      //cerr << i << " " << v << " " << t << endl;
      ans = min(ans,t);
    }
  }
  printf("%.12f\n",ans);
}


Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <string>
#include <cstring>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <memory>

//#pragma comment(linker, "/STACK:16777216")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx,avx2,popcnt,tune=native")

using namespace std;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define ull unsigned long long
//#define double long double
//#define int ll
//#define int ull
//#define int short
//#define int unsigned short
//#define int unsigned int
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define hash hash228
const int SZ = 1e2 + 4;
const double EPS = 1e-7;
const int mod = 1e9 + 7;
const int hashpow = 2;
const int inf = 2e9;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int n, k;
int x[SZ];

inline void read() {
    cin >> n >> k;
    for (int i = 0; i < k; ++i) {
        int d;
        cin >> d;
        for (int j = 0; j < d; ++j) {
            int a;
            cin >> a;
            --a;
            ++x[a];
        }
    }
}

inline void solve() {
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (!x[i]) {
            ++ans;
        }
    }
    cout << ans << "\n";
}

signed main() {

#ifdef __LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

//    int t;
//    cin >> t;
//    for (int i = 0; i < t; ++i) {
    read();
    solve();
//    }

    return 0;
}

Measured memory_bytes: 3656
def main():
    N, T = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    A = [a[0] for a in AB]
    B = [b[1] for b in AB]
    dp1 = [[0]*(T+1) for i in range(N+2)]
    for i in range(1, N+1):
        for j in range(T):
            dp1[i][j] = max(dp1[i][j], dp1[i-1][j])
            if j + A[i-1] < T:
                dp1[i][j + A[i-1]] = \
                    max(dp1[i][j + A[i-1]], dp1[i-1][j] + B[i-1])

    dp2 = [[0]*(T+1) for i in range(N+2)]
    for i in range(1, N+1)[::-1]:
        for j in range(T):
            dp2[i][j] = max(dp2[i][j], dp2[i+1][j])
            if j + A[i-1] < T:
                dp2[i][j + A[i-1]] = \
                    max(dp2[i][j + A[i-1]], dp2[i+1][j] + B[i-1])

    ans = 0
    for i in range(1, N+1):
        for j in range(T):
            ans = max(ans, dp1[i-1][j] + dp2[i+1][T-1-j] + B[i-1])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 179332
// AtCoder Beginner Contest 119 - Problem B: Still TBD (https://atcoder.jp/contests/abc119/tasks/abc119_b) 
#include <bits/stdc++.h>

using namespace std;

double solve(int N, const vector<double>& xs, const vector<string>& us)
{
    double ans = 0.0;

    for (int i = 0; i < N; ++i)
        ans += (us[i] == "JPY" ? xs[i] : 380000.0 * xs[i]);

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<double> xs(N);
    vector<string> us(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i] >> us[i];

    auto ans = solve(N, xs, us);

    cout.precision(15);
    cout << fixed << ans << '\n';

    return 0;
}


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

int n, m=20000, mi;
double cx, cy, d, mx, p=1.0, x[55], y[55];
double f(double p, double q) {return p*p + q*q;}

int main() {
	int i;
	cin >> n;
	for(i=0; i<n; i++) {
		cin >> x[i] >> y[i];
		cx += x[i]; cy += y[i];
	}
	cx /= n; cy /= n;
	while(m--) {
		mx = f(cx - x[0], cy - y[0]);
		mi = 0;
		for(i=1; i<n; i++) {
			d = f(cx - x[i], cy - y[i]);
			if(d > mx) mx = d, mi = i;
		}
		cx += (x[mi] - cx) * p;
		cy += (y[mi] - cy) * p;
		p *= 0.999;
	}
	printf("%.9f", sqrt(mx));
	return 0;
}

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

int main(){
	int n;
	cin >> n;
    vector<int> dp(1);
    cin >> dp[0];
    for(int i=1; i<n; i++){
        int tmp;
        cin >> tmp;
        auto itr=lower_bound(dp.begin(),dp.end(),tmp);
        if(itr!=dp.end()) *itr=tmp;
        else dp.push_back(tmp);
    }
    
    cout << dp.size() << endl;
}


Measured memory_bytes: 3508
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		System.out.println(c+" "+a+" "+b);
	}
}


Measured memory_bytes: 21588
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#define MAXN 100000
#define MAXV 20000
using namespace std;
typedef long long LL;
vector<int> prime;
LL seq[MAXN+5],a[MAXN+5],b[MAXN+5];
bool vis[MAXV+5];
map<LL,int> mp;
void prepare()
{
	for(int i=2;i<=MAXV;i++)
	{
		if(vis[i]==false)
			prime.push_back(i);
		for(int j=0;1LL*prime[j]*i<=MAXV;j++)
		{
			vis[i*prime[j]]=true;
			if(i%prime[j]==0)
				break;
		}
	}
}
void Work(int i,LL x)
{
	a[i]=b[i]=1;
	for(int j=0;1LL*prime[j]*prime[j]*prime[j]<=x;j++)
	{
		LL t1=prime[j],t2=1LL*prime[j]*prime[j],t3=1LL*prime[j]*prime[j]*prime[j];
		while(x%t3==0)	x/=t3;
		if(x%t2==0)			a[i]*=t2,b[i]*=t1;
		else if(x%t1==0)	a[i]*=t1,b[i]*=t2;
		while(x%t1==0)	x/=t1;
	}
	if(x!=1LL)
	{
		LL t=(LL)sqrt(x);
		if(t*t==x)	a[i]*=x,b[i]*=t;
		else		a[i]*=x,b[i]*=x*x;
	}
}
int main()
{
//	freopen("anticube.in","r",stdin);
//	freopen("anticube.out","w",stdout);
	prepare();
	int N;
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
	{
		scanf("%lld",&seq[i]);
		Work(i,seq[i]);
		mp[a[i]]++;
	}
	int ans=0;
	for(int i=1;i<=N;i++)
		if(mp.find(a[i])!=mp.end())
		{
			if(a[i]==b[i])
			{
				ans++;
				mp.erase(mp.find(a[i]));
			}
			else
			{
				int ansn=mp[a[i]];
				mp.erase(mp.find(a[i]));
				if(mp.find(b[i])!=mp.end())
				{
					ansn=max(ansn,mp[b[i]]);
					mp.erase(mp.find(b[i]));
				}
				ans+=ansn;
			}
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8832
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    said = [[]] * n
    for i in range(n):
        said[i] = [list(map(int, input().split())) for _ in range(int(input()))]

    ans = 0
    n_bit = '0' + str(n) + 'b'
    for i in range(2 ** n):
        i_bin = format(i, n_bit)
        i_bin_c = i_bin.count('1')
        if i_bin_c <= ans:
            continue

        isTrue = True
        for j in range(n):
            if i_bin[j] == '0':
                continue
            for k in said[j]:
                if int(i_bin[k[0]-1]) != k[1]:
                    isTrue = False
                    break
            if not isTrue:
                break
        if isTrue:
            ans = i_bin_c
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
S = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
A = [c for c in S.split(', ')]
N = int(input())
print(A[N - 1])


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
#include <string.h>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define INF (1LL<<60)
#define int long long
#define ll long long
#define mod 1000000007


int dp[401][401];
int N, a[401];

int solve(int l, int r){
	if (dp[l][r] != 0) return dp[l][r];

	if (r - l == 1){
		dp[l][r] = 0;
		return 0;
	}

	int m = INF;
	for (int k = l + 1; k < r; k++){
		m = min(m, solve(l, k) + solve(k, r));
	}
	for (int i = l; i<r; i++)
		m += a[i];
	dp[l][r] = m;
	return m;
}

signed main(){
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> a[i];

	cout << solve(0, N) << endl;

	return 0;
}


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

Alice=0
Bob=0
a.sort()
#print(a)
h=len(a)
for i in range(h):
    if len(a)>0:
        Alice+=a[-1]
        del a[-1]
        h-=1
    if len(a)>0:
        Bob+=a[-1]
        del a[-1]
        h-=1
print(Alice-Bob)

Measured memory_bytes: 3064
#include <cstdio>
#include <utility>
#include <vector>
#include <functional>
#include <set>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n';)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;if((c=gcu())=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
struct range{
	int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

struct L { int o, p, l, v; };

int main() {
	int V {in}, E {in};
	vector<vector<int>> g(V);
	vector<L> l(V);
	times(i, E) {
		int s {in}, t {in};
		g[s].push_back(t);
		g[t].push_back(s);
	}
	int t {};
	vector<int> v(V);
	function<void(int, int)> f = [&](int c, int p) {
		l[c] = {t++, p ,t, 1};
		for (int i : g[c])
			if (!l[i].v) {
				f(i, c);
				l[c].l = min(l[c].l, l[i].l);
			} else if (i != p)
				l[c].l = min(l[c].l, l[i].o);
	};
	f(0, -1);
	set<int> ap;
	int np {};
	for (int i: range(1, V)) {
		int p = l[i].p;
		if (!p)
			np++;
		else if (l[p].o <= l[i].l)
			ap.insert(p);
	}
	if (np > 1)
		ap.insert(0);
	for (int i: ap)
		outl(i);
}


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

int main() {
  int n;cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  int cnt=0,ans=1e9;
  rep(i,n){
    ans=min(ans,a[i]);
    if(ans==a[i])cnt++;
  }
  cout<<cnt<<endl;
}

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

ll gcd(ll a, ll b){
    if(a < b) return gcd(b,a);
    ll m;
    while((m = a%b)){
        a = b;
        b = m;
    }
    return b;
}

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

int main(){
    int n;
    ll ans;
    cin >> n >> ans;
    rep(i,n-1){
        ll t;
        cin >> t;
        if(ans == t) continue;
        ans = lcm(ans, t);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
i = 1
ans = A[0]
N -= 2
while N>0:
    if N>1:
        ans += 2*A[i]
        N -= 2
        i += 1
    else:
        ans += A[i]
        break
print(ans)

Measured memory_bytes: 31612
H,W = map(int,input().split())
maze = []
for _ in range(H):
    l = list(input())
    maze.append(l)
import collections as col
q = col.deque()
q.append((0,0))
maze[0][0] = 0
def bfs(maze):
    while True:
        if len(q) == 0:
            print("-1")
            quit()
        else: nowx,nowy = q.popleft()
        if nowx == (H - 1) and nowy == (W - 1): return
        for x in [1,-1]: 
            if nowx + x == H or nowy == W or \
             maze[nowx + x][nowy] != '.' : continue
            if 0 <= nowx + x and nowx + x <= H - 1:
                q.append((nowx+x,nowy))
                maze[nowx + x][nowy] = maze[nowx][nowy] + 1
        for y in [1,-1]: 
            if nowx == H or nowy + y== W or \
             maze[nowx][nowy + y] != '.' : continue
            if 0 <= nowy + y and nowy + y <= W - 1:
                q.append((nowx,nowy+y))
                maze[nowx][nowy + y] = maze[nowx][nowy] + 1
bfs(maze)
cnt = 0
for x in maze:
    for y in x:
        if y == '#':
            cnt += 1
print(H*W - maze[H-1][W-1] - cnt - 1)




Measured memory_bytes: 3316
N = int(input())
H = [int(_) for _ in input().split()]

count = 0
while True:
    for n in range(N):
        if H[n] == 0:
            continue
        elif n == N-1:
            count += 1
        elif H[n+1] == 0:
            count += 1
        H[n] -= 1
    if sum(H) == 0:
        break
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long 
#define inf 0x3f
#define INF 0x3f3f3f3f
#define fi first
#define se second 
#define mp make_pair
#define pa pair<int,int>

using namespace std;

inline ll read()
{
	ll sum=0,f=1;char c=getchar();
	while (!isdigit(c)) {if (c=='-') f=-1;c=getchar();}
	while (isdigit(c)) {sum=sum*10+c-'0';c=getchar();}
	return sum*f;
}

int main()
{
	int k=read(),a=read(),b=read();
	if (a+1>k) {cout<<k+1;return 0;}
	if (a+2>b)
	{
		cout<<k+1;
		return 0;
	} 
	else
	{
		ll ans=0;
		k-=(a-1);k-=2;ans+=b;
		if (k&1) k--,ans++; 
		int d=k/2;
		ans+=1ll*d*(b-a);
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << '\n'
#define SORT(V) sort((V).begin(),(V).end())
#define HSORT(V,n) sort(V,V+n)
#define RSORT(V) sort((V).rbegin(), (V).rend())
#define INF 1e+9
#define MININF -INF
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int main(){
    int x;
    cin >> x;
    if (x == 3||x == 5||x == 7) PRINT("YES");
    else PRINT("NO");
}


Measured memory_bytes: 256
import sys
from collections import deque

input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)

deq = deque([A[0]])
ans = 0

for x in A[1:]:
    ans += deq.popleft()
    deq.append(x)
    deq.append(x)

print(ans)


Measured memory_bytes: 32608
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;
int r[55555];
int ri;
bool t[55556];
void FiveEverywhere() {
	int N;
	cin >> N;
	int p[55556];
	p[0] = 2;
	for (size_t i = 0; i < 55555; i++)
	{
		t[i] = (i % 2 == 0) ? false : true;
	}
	int i = 3;
	int ind = 1;
	ri = 0;
	while (i <= 55555)
	{
		if (!t[i]) {
			i += 2;
			continue;
		}
		p[ind++] = i;
		if (i % 5 == 1) {
			r[ri++] = i;
			if (ri == N) break;
		}
		int ii = i;
		while ((ii + i) <= 55555)
		{
			ii += i;
			t[ii] = false;
		}
		i += 2;
	}
	ind = 2;
	//while (ri < N)
	//{
	//	if (ri < 5 || (ri >= 5 && check(p[ind]))) {
	//		r[ri++] = p[ind];
	//	}
	//	ind++;
	//}

	for (size_t i = 0; i < N; i++)
	{
		if (i > 0) cout << " ";
		cout << r[i];
	}
}
int main() {
	FiveEverywhere();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  long long int a,b,c;
  cin>>a>>b>>c;
  if(c<a)
    cout<<a-c<<" "<<b;
  else if(c==a)
    cout<<0<<" " <<b;
  else
  {
    if(c-a>=b)
      cout<<0<<" "<<0;
    else
      cout<<0<<" "<<b-(c-a);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const DSZ=6;
int const MAXN=220000;
int N;
ll K;
int pr[MAXN],nx[MAXN],len[MAXN];
ll last[MAXN];
int s[MAXN];
int ss;

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

	cin>>N>>K;
	vector<int> a(N);
	rep(i,0,N) cin>>a[i];
	
	rep(i,0,N) pr[a[i]]=-1;
	rep(i,0,2*N) {
		int cur=a[i%N];
		if (pr[cur]!=-1 && pr[cur]<N) {
			nx[pr[cur]]=(i+1)%N;
			len[pr[cur]]=i+1-pr[cur];
		}
		pr[cur]=i;
	}
	
	K*=N;
	rep(i,0,N) last[i]=-1;
	int cur=0;
	while (K>len[cur]) {
		if (last[cur]!=-1) {
			K%=last[cur]-K;
			if (K<len[cur]) break;
		}
		
		last[cur]=K;
		K-=len[cur];
		cur=nx[cur];
	}
	
	map<int,int> pos;
	ss=0;
	while (K>0) {
		int p=pos[a[cur]];
		if (p<ss && s[p]==a[cur]) {
			ss=p;
		} else {
			s[ss++]=a[cur];
			pos[a[cur]]=ss-1;
		}
		cur=(cur+1)%N;
		K--;
	}
	
	rep(i,0,ss) cout<<s[i]<<" \n"[i+1==ss];
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define int long long int
using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    //cout<<"I must do it...Yeahhh";
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n+1]={};
        int b[n+1];
        for(int i=1;i<=n;i++)
            cin>>b[i],a[b[i]]++;
        /*for(int i=1;i<=n;i++)
            cout<<b[i]<<' ';
        cout<<'\n';
        for(int i=1;i<=n;i++)
            cout<<a[i]<<' ';
        cout<<'\n';*/
        int ans=0;
        for(int i=1;i<=n;i++)
            ans+=(a[i]*(a[i]-1))/2;
        //cout<<ans<<'\n';
        for(int i=1;i<=n;i++)
        {
            int x=a[b[i]];
            cout<<ans-((x*(x-1))/2 -((x-1)*(x-2))/2)<<'\n';
        }
    }
    return 0;
}

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

struct Card{char suit,value;};

void bubble(struct Card A[],int N){
    for(int i=0;i<N;i++){
        for(int j=N-1;j>=i+1;j--){
            if(A[j].value<A[j-1].value){
                Card t=A[j];A[j]=A[j-1];A[j-1]=t;
            }
        }
    }

}

void selection(struct Card A[],int N){
    for(int  i=0;i<N;i++){
        int minj=i;
        for(int j=i;j<N;j++){
            if(A[j].value<A[minj].value)minj=j;
        }
        Card t=A[i];A[i]=A[minj];A[minj]=t;
    }
}

void print(struct Card A[],int N){
    for(int i=0;i<N;i++){
        if(i>0)cout<<" ";
        cout <<A[i].suit<<A[i].value;
    }
    cout <<endl;
}

bool isStable(struct Card C1[],struct Card C2[],int N){
    for(int i=0;i<N;i++){
        if(C1[i].suit!=C2[i].suit)return false;
    }
    return true;
}

int main(){
    Card C1[100],C2[100];
    int N;
    char ch;

    cin>>N;
    for(int  i=0;i<N;i++){
        cin>>C1[i].suit>>C1[i].value;
    }
    for(int i=0;i<N;i++)C2[i]=C1[i];

    bubble(C1,N);
    selection(C2,N);

    print(C1,N);
    cout<<"Stable"<<endl;
    print(C2,N);
    if(isStable(C1,C2,N)){
    cout<<"Stable"<<endl;}
  else {
    cout<<"Not stable"<<endl;
  }
return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
#include <string>
using namespace std;
int main() {
    int M, D;
    cin >> M >> D;
    int  d1, d10;
    int count; count=0;
    for (int a = 1; a <= M; a++) {
        for (int i = 1; i <= D; i++) {
            d10=i/10;d1=i-d10*10;

            if ((d1 >= 2 && d10 >= 2)&&(a == d1 * d10) ) {
                count = count+1;
            }

        }
    }



    cout<<count;
    return 0;
}

Measured memory_bytes: 256
#coding:utf-8
from collections import defaultdict
from Queue import Queue
import sys
N,M=map(int,sys.stdin.readline().split())
L=[None]*200001
R=[None]*200001
D=[None]*200001
C=defaultdict(list)
done=[False]*200001
if M==0:
    print("Yes")
    sys.exit(0)

class UnionFind(object):
    #https://www.kumilog.net/entry/union-find
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]

uf=UnionFind(n=N+1)
for i in xrange(M):
    l,r,d=map(int,sys.stdin.readline().split())
    L[i]=l
    R[i]=r
    D[i]=d
    C[l].append(i);C[r].append(i)
    uf.union(l,r)
groups={}
for i in range(1,N+1):
    groups[uf.find(i)]=i

X=[None]*200001
for group in groups:
    Q=Queue()
    X[group]=0
    for c in C[group]:
        Q.put(c)
        done[c]=True
    while not Q.empty():
        q=Q.get()
        #print(q)
        l=L[q];r=R[q];d=D[q]
        ll=rr=False
        if X[l]!=None:
            if X[r] is None:
                rr=True
                X[r]=X[l]+d
            else:
                if X[r]!=X[l]+d: 
                    print("No")
                    sys.exit(0)
        elif X[r]!=None:
            if X[l] is None:
                ll=True
                X[l]=X[r]-d
            else:
                if X[r]!=X[l]+d:
                    print("No")
                    sys.exit(0)
        else:
            sys.exit(1)
        if ll:            
            for c in C[l]:
                if not done[c]:
                    Q.put(c); done[c]=True
        if rr:
            for c in C[r]:
                if not done[c]:
                    Q.put(c); done[c]=True
        #print(X[:11])




print("Yes")            




   



Measured memory_bytes: 94744
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li_re = sorted(li)

point = 0

for i in range(len(li)):
    if li_re[i] != li[i]:
        point += 1

if point > 2:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3064