akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
    long h, w, a, b, c, ans = LONG_MAX;
    cin >> h >> w;
    rep(i, h - 1) {
        a = (i + 1) * w;
        b = (h - i - 1) * (w / 2);
        c = ((h - i - 1) * (w - w / 2));
        ans = min(ans, max(a, c) - min(a, b));
        b = (h - i - 1) / 2 * w;
        c = ((h - i - 1) - (h - i - 1) / 2) * w;
        ans = min(ans, max(a, c) - min(a, b));
    }

    rep(i, w - 1) {
        a = h * (i + 1);
        b = (h / 2) * (w - i - 1);
        c = (h - h / 2) * (w - i - 1);
        ans = min(ans, max(a, c) - min(a, b));
        b = h * ((w - i - 1) / 2);
        c = h * ((w - i - 1) - (w - i - 1) / 2);
        ans = min(ans, max(a, c) - min(a, b));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  int odd = 0;
  for(int i = 1; i <= N; i+=2){
    odd++;
  }
  cout << fixed << setprecision(10);
  cout << (double) odd / (double) N << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14) <<double値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    int ans=0;
    rep(i,n){
        rep1(j,i+1,n){
            ans+=d[i]*d[j];
        }
    }
    cout << ans;



}

Measured memory_bytes: 256
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;


public class Main {

	public static void main(String [] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedOutputStream bos = new BufferedOutputStream(System.out);
		try {
			String str = br.readLine();
			int n = Integer.parseInt(str);
			String eol = System.getProperty("line.separator");
			byte [] eolb = eol.getBytes();
			for(int i = 0 ; i < n ; i++) {
				str = br.readLine();
				int blank = str.indexOf(" ");
				BigInteger a = new BigInteger(str.substring(0,blank));
				str =str.substring(blank+1);
				blank = str.indexOf( " ");
				BigInteger b = new BigInteger(str.substring(0,blank));
				BigInteger c = new BigInteger(str.substring(blank+1));
				boolean is = false;
				a = a.multiply(a);
				b = b.multiply(b);
				c = c.multiply(c);
				BigInteger zero = new BigInteger("0");
				if( (a.compareTo(b.add(c)) == 0 ) || (b.compareTo(a.add(c)) == 0 ) || (c.compareTo(a.add(b)) == 0 ) ) {
					if ( ( a.compareTo(zero) != 0 ) && (b.compareTo(zero) != 0) && (c.compareTo(zero) != 0)) {
						is = true;
					}
				}
				if(is) {
					bos.write("YES".getBytes());
					bos.write(eolb);
				} else {
					bos.write("NO".getBytes());
					bos.write(eolb);
				}
			}
			bos.flush();
		} catch(IOException ioe) {
			ioe.printStackTrace();
		}
	}
}

Measured memory_bytes: 9756
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,base[4],pt,now;
	cin>>n;
	string s;
	while(n-->0){
		pt=0;
		for(int i=0;i<3;i++)
			base[i]=0;
		for(now=3;now>0;){
			getline(cin,s);
			if(s=="HIT"){
				if(base[2]==1)
					pt++;
				for(int i=2;i>0;i--)
					base[i]=base[i-1];
				base[0]=1;
			}
			else if(s=="HOMERUN"){
				for(int i=0;i<3;i++){
					if(base[i]==1)
						pt++;
					base[i]=0;
				}
				pt++;
			}
			else if(s=="OUT"){
				now--;
			}
		}
		cout<<pt<<endl;
	}
	return 0;
}

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

double p[2999];
double dp[3000][3000];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> p[i];
	}

	dp[0][0] = 1;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			dp[i + 1][j + 1] += dp[i][j] * p[i];
			dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
		}
	}

	double ans = 0;
	for(int i = 0; i <= N; i++){
		if(i > N - i) ans += dp[N][i];
	}
	cout << fixed << setprecision(15) << ans << endl;
}


Measured memory_bytes: 70528
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll a, b, c, k;
    cin>>a>>b>>c>>k;
    if(abs(a-b)>(ll)1e18) return cout<<"Unfair\n", 0;
    if(k&1) return cout<<b-a<<endl, 0;
    else return cout<<a-b<<endl, 0;
    return 0;
}

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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF (1 << 29)

using namespace std;

int main(){
	long long a, b, n;
	cin >> a >> b >> n;

	long long c;
	if(b - 1 <= n){
		c = b - 1;
	}else{
		c = n;
	}
	cout << (long long)(a * c / b) << endl;

	return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int N = 301;

int cnt[N][N];
int dp[N][N];

int solve(int n, vector<int> a, vector<int> b) {
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			cnt[i][j] = -1;
			dp[i][j] = -1;
		}
	}
	function<int(int, int)> calc_cnt = [&](int i, int j) {
		if (i == 0 || j == 0) {
			return (int)0;
		}
		if (cnt[i][j] == -1) {
			cnt[i][j] = (a[i - 1] == b[j - 1]) + calc_cnt(i - 1, j - 1);
		}
		return cnt[i][j];
	};
	function<int(int, int)> calc_dp = [&](int i, int j) {
		if (i == 0 || j == 0) {
			return (int)0;
		}
		if (dp[i][j] == -1) {
			dp[i][j] = calc_cnt(i, j) + min(calc_dp(i - 1, j), calc_dp(i, j - 1));
		}
		return dp[i][j];
	};
	return calc_dp(n, n);
}

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

	int n, m;
	cin >> n >> m;
	vector<vector<int>> a(n, vector<int> (m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			a[i][j] = (c - 'a');
		}
	}
	int ans = 0;
	for (int j = 0; j + 1 < m; j++) {
		vector<int> f;
		vector<int> s;
		for (int i = 0; i < n; i++) {
			f.push_back(a[i][j]);
			s.push_back(a[i][j + 1]);	
		}
		ans += solve(n, f, s);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5892
#include<bits/stdc++.h>
using namespace std ;
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 1e6 + 5 ; 
int n, a[N], w[10], bk[10] ; 
char s[N] ; 
signed main()
{
	n = gi(), scanf("%s", s + 1 ) ;
	rep( i, 1, n ) a[i] = s[i] - '1', bk[a[i]] = 1 ; 
	rep( i, 1, n ) if( ( ( i - 1 ) & ( n - 1 ) ) == ( i - 1 ) ) w[a[i]] ^= 1 ; 
	if( w[1] ) { puts("1") ; exit(0) ; }
	if( w[2] && ( !bk[1] ) ) { puts("2") ; exit(0) ; }
	puts("0") ; 
	return 0 ;
} 

Measured memory_bytes: 8516
#include <stdio.h>

int main(void) {
	int c[4][13] = {0};
	int n, i;
	
	scanf("%d", &n);
	for(i = 0; n > i; i++){
		char bm;
		int bi;
		scanf("%*c%c%*c%d", &bm, &bi);
		switch(bm){
			case 'S':
			c[0][bi-1] = 1;
			break;
			case 'H':
			c[1][bi-1] = 1;
			break;
			case 'C':
			c[2][bi-1] = 1;
			break;
			case 'D':
			c[3][bi-1] = 1;
			break;
		}
	}
	
	for(i = 0; 52 > i; i++){
		if(c[i/13][i%13] == 0)
		printf("%c %d\n", i/13 == 0? 'S' : i/13 == 1 ? 'H' : i/13 == 2 ? 'C' : 'D', i%13+1);
	}
	
	return 0;
}

Measured memory_bytes: 596
#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>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

ll solve(ll n)
{
    if(n==1)return 0;
    return n*(n-1)/2;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);

ll n;
cin>>n;

cout<<solve(n)<<endl;
return 0;
}

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

using namespace std;

const int N = 3e3 + 2;

int n, a[N], u[2][N][N];
long long dp[2][N][N];

long long get(int l, int r, int player){
      if(l == r){
            if(player)
                  return a[l];
            else
                  return -a[l];
      }
      if(u[player][l][r])
            return dp[player][l][r];
      u[player][l][r] = 1;
      if(player){
            dp[player][l][r] = max(get(l + 1, r, player ^ 1) + a[l], get(l, r - 1, player ^ 1) + a[r]);
      } else {
            dp[player][l][r] = min(get(l + 1, r, player ^ 1) - a[l], get(l, r - 1, player ^ 1) - a[r]);
      }
      return dp[player][l][r];
}

int main(){
      cin >> n;

      for(int i = 1; i <= n; i ++){
            cin >> a[i];
      }

      cout << get(1, n, 1);
}


Measured memory_bytes: 211456
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll ans[110][110];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll k;
	cin >> k;
	ll res = 7 % k;
	ll ans = 1;
	bool flag = false;
	rep(i, 1000010) {
		if (res == 0) {
			flag = true;
			break;
		}
		res *= 10;
		res += 7;
		res %= k;
		ans++;
	}
	if (flag) {
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
    int count = 1;
    if(b != a) count++;
    if(c != b && c != a) count++;
    System.out.println(count);
  }
}

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

int main() {
  int A;
  int B;
  int C;
  int D;
  cin >> A >> B >> C >> D;
  for (int i = 0;;i++){
    C -= B;
    if(C <= 0){
      cout << "Yes" << endl;
      break;
    }
    A -= D;
    if(A <= 0){
      cout << "No" << endl;
      break;
    }
  }
  
}


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

#define int long long

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

int bit[200001], n;
int a[200000];
string S;

int sum(int i) {
    int s = 0;
    while (i > 0) {
        s += bit[i];
        i -= i & (-i);
    }
    return s;
}

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

signed main() {
    cin >> S;
    n = S.length();
    deque<int> appear_deq[26];
    for (int i = 0; i < n; i++) {
        appear_deq[S[i] - 'a'].push_back(i + 1);
    }
    int odd = 0;
    int odd_i;
    for (int i = 0; i < 26; i++) {
        if (appear_deq[i].size() % 2 == 1) {
            odd++;
            odd_i = i;
        }
    }
    if (odd >= 2) {
        cout << -1 << endl;
        return 0;
    }
    int used[26] = {};
    int ind = 0;
    for (int i = 0; i < n / 2; i++) {
        while (true) {
            int cur = S[ind] - 'a';
            if (used[cur] < appear_deq[cur].size() / 2) {
                a[i] = ind + 1;
                used[cur]++;
                ind++;
                break;
            }
            ind++;
        }
    }
    for (int i = 0; i < n / 2; i++) {
        int cur = S[a[i] - 1] - 'a';
        a[n - i - 1] = appear_deq[cur].back();
        appear_deq[cur].pop_back();
    }
    if (n % 2 == 1) {
        a[n / 2] = appear_deq[odd_i].back();
    }
    int ans = 0;
    for (int j = 0; j < n; j++) {
        ans += j - sum(a[j]);
        add(a[j], 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5252
import sys
input = sys.stdin.readline
import bisect

N = int(input())
# 逆順にする
A = [int(input()) for _ in range(N)][::-1]

dp = [float("inf")] * N

# 狭義単調増加列の長さの最大値を求める
for a in A:
    idx = bisect.bisect_right(dp, a)
    dp[idx] = a

answer = bisect.bisect_left(dp, float("inf"))
print(answer)

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

    long long a,b,c,d,e,f,g;
   cin>>a>>b;
   map<long long,long long>mp;



   for(long long i=0;i<b;i++)
   {
       cin>>c>>d;
       mp[c]++;
       mp[d]++;

   }

      for(long long i=1;i<=a;i++)
   {
       cout<<mp[i]<<endl;
   }



}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

bool isOne(LL a, LL b, LL p) {
	if(p == 1) {
		LL cnt = 0;
		if(a%2 == 1)	a++, cnt++;
		if(b%2 == 1)	b--, cnt++;
		cnt += (b-a)/2;
		return (cnt%2 == 1);
	}
	LL cntA = p - (a % p);
	LL cntB = (b % p) + 1;
	LL total = ((a & p) != 0 ? cntA : 0) + ((b & p) != 0 ? cntB : 0);
	return (total%2 == 1);
}

int main() {
	sll(A); sll(B);
	LL C = 0;
	rep(i, 0, 40) {
		if(isOne(A, B, (1ll<<i)))
			C |= (1ll<<i);
	}
	pll(C); nl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
//#define int long long
#define INF 10000000
using namespace std;
int main(){
    int N,M;
    while(1){
        cin >> N >> M;
        int a[1010]={};
        int record[M+10][1300]={};
        if(N == 0 && M== 0) break;
        int r;
        cin >> r;
        rep(i,r){
            int t,n,m,s;
            cin >> t >> n >> m >> s;
            if(a[n] == 0) a[n] = t;
            else {
                for(int j=a[n]; j<t; j++) record[m][j] = 1;
                a[n] = 0;
            }
        }
        int q;
        cin >> q;
        rep(i,q){
            int s,e,me;
            cin >> s >> e >> me;
            int cnt = 0;
            for(int j=s; j<e; j++) cnt += record[me][j];
            cout << cnt << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 52312
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 2010;
int dp1[N], dp2[N];

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    VI a(n+1);
    a[0] = y;
    REP(i,n) scanf("%d", &a[i+1]);

    dp1[n] = dp2[n] = abs(a[n] - a[n-1]);

    FORR(i,n-1,1){
        dp1[i] = dp2[i] = abs(a[i-1] - a[n]);
        FOR(j,i+1,n){
            dp1[i] = max(dp1[i], dp2[j]);
            dp2[i] = min(dp2[i], dp1[j]);
        }
    }

    cout << dp1[1] << endl;

    return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    string s;cin >>s;
    if(s[0]=='S'){
        puts("Cloudy");
    }
    else if(s[0]=='C'){
        puts("Rainy");
    }
    else puts("Sunny");
    return 0;
}



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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    map<ll,ll> mp;
    for(i = 1;i <= n;++i){
        mp[i] = 0;
    }
    for(i = 0;i < n-1;++i){
        ll a;
        cin >> a;
        ++mp[a];
    }
    for(auto x:mp){
        cout << x.second << endl;
    }

    return 0;
}

Measured memory_bytes: 16124
sx, sy, tx, ty = map(int, input().split())
up = "U" * (ty - sy)
right = "R" * (tx - sx)
down = up.replace("U", "D")
left = right.replace("R", "L")
first = up + right + down + left
second = "LU" + up + right + "RDRD" + down + left + "LU"
print(first+second)

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	
	for (char c : s)
	{
		if (count(s.begin(), s.end(), c) != 2)
		{
			cout << "No\n";
			return 0;
		}
	}
	
	cout << "Yes\n";
}


Measured memory_bytes: 256
#include<stdio.h>

long long cal(long long x , long long y) 
{
      long long ans = 1 ;
      for (int i = 0; i < y; i++) {
          ans = (ans*x)%1000000007 ;
      }
      return ans ;
}

int main(){
      long long n ;
      scanf("%lld", &n) ;
      long long a ;
      a = cal(10, n)-cal(9, n)-cal(9, n)+cal(8, n) ;
      a = a%1000000007 ;
      a = (a+1000000007)%1000000007 ;
      printf("%lld", a) ;
      return 0 ;
}

Measured memory_bytes: 1692
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto s = readln.chomp;
  int m;
  foreach (i; 1..n) {
    if (s[i] == 'E') {
      m++;
    }
  }

  auto lm = m;
  foreach (i; 1..n) {
    if (s[i-1] == 'W') {
      lm++;
    }
    if (s[i] == 'E') {
      lm--;
    }

    m = min(m, lm);
  }

  m.writeln;
}


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

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=1000002;

bitset<5005>prf[5005],suff[5005];

void solve(){
	int n,k;
	cin>>n>>k;
	vi a(n);
	cin>>a;
	prf[0].set(0);
	for(int i=0;i<n;i++){
		a[i]=min(a[i],k);
		prf[i+1]=prf[i]|(prf[i]<<a[i]);
	}
	suff[n].set(0);
	for(int i=n-1;i>=0;i--){
		suff[i]=suff[i+1]|(suff[i+1]<<a[i]);
	}
	int ans=0;
	for(int i=0;i<n;i++){
		vector<int>zz;
		for(int j=0;j<=5000;j++){
			if(prf[i][j]){
				zz.pb(j);
			}
		}
		int flag=0;
		for(int j=0;j<=5000;j++){
			if(suff[i+1][j]){
				int it=lower_bound(all(zz),k-j-a[i])-zz.begin();
				if(it==zz.size()){
					continue;
				}
				if(zz[it]+j+a[i]>=k&&zz[it]+j<k){
					flag++;
					break;
				}
			}
		}
		ans+=(flag!=0);
	}
	cout<<n-ans;
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


Measured memory_bytes: 6528
import java.util.Scanner;

class Main{
        public static void main(String[] args){
                Scanner scn=new Scanner(System.in);
                int N=scn.nextInt();
                int sum=0;
                for(int i=0;i<N;i++){
                        sum+=scn.nextInt()-scn.nextInt();
                }
                System.out.println(-sum+N);
        }
}

Measured memory_bytes: 25936
#include<stdio.h>
#include<string.h>
int main()
{
	char a[16],b[16],c[32];
	int n,s=0;
	scanf("%s%d",a,&n);
	while(n--)scanf("%s",b),strstr(strcat(strcpy(c,b),b),a)?++s:0;
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main() {
// Time Complexity: O(N+Q)
// Space Complexity: O(N+Q)
string s;
cin >> s;
deque<char> dq(s.begin(), s.end());
bool remained(true);
int q, t, f;
char c;
cin >> q;
while (q--) {
cin >> t;
if (t == 1) remained = !remained;
else {
cin >> f >> c;
remained ^ (f - 1) ? dq.push_front(c) : dq.push_back(c);
}
}
while (!dq.empty()) {
cout << (remained ? dq.front() : dq.back());
remained ? dq.pop_front() : dq.pop_back();
}
cout << '\n';
return 0;
}

Measured memory_bytes: 896
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);

		int n=in.nextInt(),A[]=new int[n];
		for(int i=0;i<n;i++)A[i]=in.nextInt();

		System.out.println(shellSort(A));
		for(int i=0;i<n;i++)System.out.println(A[i]);
	}

	static int shellSort(int[] A) {
		int cnt=0;
		
		List<Integer> H=setH(A.length);
		System.out.println(H.size());
		for(int i=0;i<H.size();i++) {
			if(i==H.size()-1)System.out.println(H.get(i));
			else System.out.print(H.get(i)+" ");
		}
		
		for(int i=0;i<H.size();i++) {
			cnt+=insertionSort(A,H.get(i));
		}
		
		return cnt;
	}

	static List<Integer> setH(int limit){
		List<Integer> H=new ArrayList<>();
		int h;
		for(h=1;h*3+1<limit;h=h*3+1);

		for(;h>0;h/=3) {
			H.add(h);
		}

		return H;
	}

	static int insertionSort(int[] A,int h) {
		int cnt=0;
		
		for(int i=h;i<A.length;i++) {
			int tmp=A[i],j;
			for(j=i; j>=h && tmp<A[j-h]; j-=h) {
				A[j]=A[j-h];
				cnt++;
			}
			A[j]=tmp;
			/*System.out.printf("A[%d]=%d\n",j,tmp);
			for(int k=0;k<A.length;k++) {
				if(k==A.length-1)System.out.println(A[k]);
				else System.out.print(A[k]+" ");
			}*/
		}
		return cnt;
	}

}



Measured memory_bytes: 298908
// https://atcoder.jp/contests/arc087/tasks/arc087_a
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
#define ip(arr, n) for(int i=0; i<n; i++) cin>>arr[i];
#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);

void solve(){
    int n,temp;
    cin>>n;
    map<ll ,ll>m;
    for(int i=0; i<n; i++){
        cin>>temp;
        m[temp]++;
    }
    ll ans=0;
    for(auto it: m){
        if(it.first < it.second){
            ans += (it.second-it.first);
        }
        else if(it.first > it.second){
            ans += it.second;
        }
    }
    cout<<ans<<endl;
}

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

Measured memory_bytes: 9436
import heapq

N, M = map(int, input().split())

ab = {}

for i in range(N):
    a,b = map(int, input().split())
    if not a in ab:
        ab[a] = [-b]
    else:
        ab[a].append(-b)


q = []
ans = 0
for day in range(1, M+1):
    if day in ab:
        for i in ab[day]:
            heapq.heappush(q, i)

    if q != None and len(q) != 0:
        ans += -1 * heapq.heappop(q)

print(ans)

Measured memory_bytes: 26020
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	int n, A[100000];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i];
	sort(A, A + n);
	long long ans = 0, ansa = 0, ansb = 0;
	if (n % 2 == 0) {
		for (int i = 0; i < n / 2; i++) ans -= A[i] * 2;
		for (int i = n / 2; i < n; i++) ans += A[i] * 2;
		ans = ans - A[n / 2] + A[n / 2 - 1];
	}
	else {
		for (int i = 0; i < (n-1) / 2; i++) ansa -= A[i] * 2;
		for (int i = (n-1) / 2; i < n; i++) ansa += A[i] * 2;
		ansa = ansa - A[(n-1) / 2] - A[(n+1) / 2 ];
		for (int i = 0; i < (n + 1) / 2; i++) ansb -= A[i] * 2;
		for (int i = (n + 1) / 2; i < n; i++) ansb += A[i] * 2;
		ansb = ansb + A[(n - 3) / 2] + A[(n - 1) / 2 ];
		ans = max(ansa, ansb);
	}
	cout << ans;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
// #define long long long 

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;


int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   long double val = 2 * 3.141592653589793238;
   long int r;
   cin>>r;

   val *= r;

   cout<<fixed<<setprecision(15)<<val;
   return 0;
}

Measured memory_bytes: 3768
s = input()
sl = list(s)
t = list(input())
flag = 0
for i in range(len(s) - len(t) + 1):
    cnt = 0
    for j in range(len(t)):
        if s[i + j] != t[j] and s[i + j] != '?':
            break
        else:
            cnt += 1
    if cnt == len(t):
        flag = 1
        index = i

if not flag:
    print('UNRESTORABLE')
else:
    for i in range(len(t)):
        sl[index + i] = t[i]
    for i in range(len(sl)):
        if sl[i] == '?':
            sl[i] = 'a'
    print("".join(sl))


Measured memory_bytes: 3064
class UnionFind
  def initialize()
    @table = Hash.new { |_hash, key| key }
    @rank = Hash.new { 0 }
  end

  def find(elt)
    if @table[elt].eql? elt
      elt
    else
      @table[elt] = find(@table[elt])
    end
  end
 
  def union(node1, node2)
    root1 = find(node1)
    root2 = find(node2)

    if @rank[root1] < @rank[root2]
      @table[root1] = root2
    elsif @rank[root1] > @rank[root2]
      @table[root2] = root1
    elsif root1 != root2
      @table[root2] = root1
      @rank[root1] += 1
    end
  end

end

n, m = gets.split.map(&:to_i)

uf = UnionFind.new

m.times do
  x, y, z = gets.split.map(&:to_i)
  uf.union(x, y)
end

puts 1.upto(n).map { |i| uf.find(i) }.uniq.size


Measured memory_bytes: 11384
def main():
    import math
    import collections
    N = int(input())
    A = list(map(int, input().split()))
    tt = 0
    #ans = list()
    ann = 0

    def comb(m, n):
        #return math.factorial(m) // (math.factorial(n) * math.factorial(m - n))
        return ((m - 1 + 1) / 1) * (m - 2 + 1) / 2

    '''
    def A_count(n):
        if n in memo:
            return memo[n]
        h = A.count(i)
        memo[n] = A.count(i)
        return h
    '''

    C = collections.Counter(A)
    for i in C.values():
        if i>=2:
            tt = tt + comb(i, 2)

    for i in A:
        f = C[i] #A_count(A[i])
        if f>=3:
            ann = (tt - comb(f, 2) + comb(f-1, 2))
        elif f==2:
            ann = tt - comb(f, 2)
        else:
            ann = tt
        print(int(ann))

    #for i in ans:
    #    print(i)


if __name__ == '__main__':
    main()

Measured memory_bytes: 26780
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner s = new Scanner(System.in);
      	int a = s.nextInt();
      	int b = s.nextInt();
      	int ans = 0;
     	
      	for (int n = 0; n <= a + b; n++) {
        	if (a + (a - 1) * (n - 1) >= b) {
            	ans = n;
              	break;
            }
        }
      
      System.out.println(ans);
    }
}


Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		sc.close();

		String s = Integer.toString(N, K);
		System.out.println(s.length());
	}
}


Measured memory_bytes: 22736
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    

	String inputnum;
	while(true){
		inputnum = sc.nextLine();
		if(inputnum.equals("0 0")){
			break;
		}
	System.out.println(select(inputnum));
	}

  }
  public static String select(String inputnum){
	String space = " ";
	String nums[] = inputnum.split(space);
        int x = Integer.parseInt(nums[0]);
        int y = Integer.parseInt(nums[1]);

        if(x > y){
		int temp = x;
		x = y;
		y = temp;
		return(x + space + y);
	}
	return(x + space + y);
  }


}

Measured memory_bytes: 35148
#include<iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int pm,pe,pj;
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>pm>>pe>>pj;
			if(pm==100||pe==100||pj==100||(pm+pe)/2>=90||(pm+pe+pj)/3>=80){
				cout<<"A"<<endl;
			}else if((pm+pe+pj)/3>=70){
				cout<<"B"<<endl;
			}else if((pm+pe+pj)/3>=50&&pm>=80||pe>=80){
				cout<<"B"<<endl;
			}else{
				cout<<"C"<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vvint ct(2,vint(n+1,0));
    REP(i,n+1) {
        rep(j,2) ct[j][i] = ct[j][i-1];
        if (s[i-1] == 'W') ct[0][i]++;
        if (s[i-1] == 'E') ct[1][i]++;
    }
    int ans = inf;
    rep(i,n) {
        ans = min(ans,ct[0][i]+(ct[1][n]-ct[1][i+1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4228
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin>>s;
    long long a=0,ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='W'){
            ans+=i-a;
            a++;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 640
#include<algorithm>
#include<iostream>
#include<string.h>
#include<cstring>
#include<vector>
#include<cstdio>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
using namespace std;

int main()
{

        double a,b,x,y,r,l,x1,x2,y1,y2;
        scanf("%lf%lf%lf%lf%lf",&a,&b,&x,&y,&r);
        l=sqrt((x-a)*(x-a)+(y-b)*(y-b));
        if(l<r)
            printf("NO\n");
        else if(l==r)
            printf("%.8f %.8f\n%.8f %.8f\n",a,b,a,b);
        else
        {
            double s1,s2,s3;
            s1=atan2(b-y,a-x);
            s2=acos(r/l);
            s3=s1+s2;
            x1=x+r*cos(s3);
            y1=y+r*sin(s3);
            s3=s1-s2;
            x2=x+r*cos(s3);
            y2=y+r*sin(s3);
            if(x1<0&&x1>-0.000000005)
                x1=0;
            if(x2<0&&x2>-0.000000005)
                x2=0;
            if(y1<0&&y1>-0.000000005)
                y1=0;
            if(y2<0&&y2>-0.000000005)
                y2=0;
            if(x1<x2)
                printf("%.8f %.8f\n%.8f %.8f\n",x1,y1,x2,y2);
            else if(x1==x2)
            {
                if(y1<y2)
                    printf("%.8f %.8f\n%.8f %.8f\n",x1,y1,x2,y2);
                else
                    printf("%.8f %.8f\n%.8f %.8f\n",x2,y2,x1,y1);
            }
            else
                printf("%.8f %.8f\n%.8f %.8f\n",x2,y2,x1,y1);
        }
    return 0;
}



Measured memory_bytes: 3580
import fileinput


def knapsack(capacity, item_weights, item_values):
    val_limit = sum(item_values) + 1

    prev_vals = [sum(item_weights)] * val_limit
    weight_table = [prev_vals]

    for item_id, item_value in enumerate(item_values):
        current_vals = [0] * val_limit
        for total_val in range(1, val_limit):
            if item_value >= val_limit - total_val:
                current_vals[total_val] = prev_vals[total_val]
            else:
                current_vals[total_val] = min(
                    prev_vals[total_val],
                    prev_vals[total_val + item_value] - item_weights[item_id]
                )

        prev_vals = current_vals
        weight_table.append(prev_vals)

    for val in range(0, val_limit)[::-1]:
        for item in range(1, len(item_weights) + 1):
            if weight_table[item][val] <= capacity:
                return val
    return 0


inp = fileinput.input()

first_line_split = inp.readline().split(" ")

item_count = int(first_line_split[0])
capacity = int(first_line_split[1])

item_weights = []
item_values = []
for _ in range(item_count):
    split = inp.readline().split(" ")
    item_weights.append(int(split[0]))
    item_values.append(int(split[1]))

print(knapsack(capacity, item_weights, item_values))

Measured memory_bytes: 116976
def inverse(a, mod):
    a %= mod # 除数が正なら正になる
    p = mod
    x, y = 0, 1
    while a > 0:
        n = p // a
        p, a = a, p % a, 
        x, y = y, x - n * y
    return x % mod # 除数が正なら正になる

def factorial(n, mod):
    fac = [0] * (n + 1)
    inv = [0] * (n + 1)
    fac[0], inv[0] = 1, 1
    for i in range(1, n + 1):
        fac[i] = fac[i-1] * i % mod
        inv[i] = inverse(fac[i], mod)
    return fac, inv

mod = 10 ** 9 + 7
s = int(input())
fac, inv = factorial(s, mod)

ans = 0
i = 1
while 3 * i <= s:
    t = s - 3 * i
    ans = (ans + fac[i+t-1] * inv[t] * inv[i-1]) % mod
    i += 1
print(ans)

Measured memory_bytes: 67988
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,ans=78678666,k;
int cnt[26];
vector<char> v;
signed main(){
	string s,r;
	cin>>s;
	r=s;
	n=s.size();
	rep(i,n){
		cnt[s[i]-'a']++;
	}
	int max=0;
	rep(i,26){
		if(max<cnt[i]){
			max=cnt[i];
		}
	}
	if(max==n){cout<<0<<endl;return 0;}
	rep(i,n){
		v.push_back(s[i]);
	}
	
	for(auto x:v){
		int flag=1,sans=0;
		s=r;n=s.size();
		n--;
		while(flag){
			string t;
			rep(i,n){
				if(s[i]==x)t+=s[i];
				else if(s[i+1]==x)t+=s[i+1];
				else t+=s[i];
			}
			s=t;
			int flag2=1;
			rep(i,s.size()-1){
				if(s[i]!=s[i+1])flag2=0;
			}
			if(flag2)flag=0;
			n--;sans++;
			//cout<<s<<endl;
		}
		ans=min(ans,sans);
	}
	cout<<ans<<endl;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int a[] = new int[N];
		for (int i=0;i<N;i++) {
			a[i] = sc.nextInt();
		}
		Arrays.parallelSort(a);
		int sum =0;
		for (int i=0;i<K;i++) {
			sum +=a[N-1-i];
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 35708
import sys
line = sys.stdin.readline
n = int(line())
a = list(map(int, line().split()))
h = 0
from collections import Counter
counter = Counter(a)
for key in sorted(counter.keys(), reverse = True):
    if h and counter[key] >= 2:
        print(h * key)
        sys.exit()
    if counter[key] >= 4:
        print(key * key)
        sys.exit()
    if counter[key] >= 2:
        h = key
print(0)

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

int kyu(const int x) {
    if (x >= 1800) return 1;
    if (x >= 1600) return 2;
    if (x >= 1400) return 3;
    if (x >= 1200) return 4;
    if (x >= 1000) return 5;
    if (x >= 800) return 6;
    if (x >= 600) return 7;
    if (x >= 400) return 8;
    return -1;
}

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

    int t;
    cin >> t;
    cout << kyu(t) << '\n';

    return 0;
}


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


bool dfs(int i , int j , vector<vector<char>> s, int H , int W){
  if(i <= H-2 && s.at(i+1).at(j) == '#') return true ; 
  else if(i >= 1 && s.at(i-1).at(j) == '#') return true ; 
  else if(j <= W-2 && s.at(i).at(j+1) == '#' ) return true; 
  else if(j >= 1 && s.at(i).at(j-1) == '#' ) return true ; 
  else return false ; 
}

int main(){
  int H , W ; 
  cin >> H >> W ; 
  vector<vector<char>> s(H , vector<char>(W)) ;
  
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      cin >> s.at(i).at(j) ; 
    }
  }
  
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      if(s.at(i).at(j) == '#'){
        if(dfs(i , j ,s , H , W)) continue ; 
        else{
          cout << "No" << endl;
          return 0 ; 
        }
      }      
    }
  }
    
  cout << "Yes" << endl; 
  
  
}

Measured memory_bytes: 3576
#include<cctype>
#include<cstdio>
#include<vector>
#include<cstring>
const int N=300007,P=998244353,i2=P-P/2;
int m,root,len,fa[N],dia[N],f[N][3][3],g[3][3];std::vector<int>e[N];
void inc(int&a,int b){a+=b-P,a+=a>>31&P;}
int mul(int a,int b){return 1ll*a*b%P;}
int read(){int x=0,c=getchar();while(isspace(c))c=getchar();while(isdigit(c))(x*=10)+=c&15,c=getchar();return x;}
void dfs(int u,int dep)
{
    if(dep>len) len=dep,root=u;
    for(int v:e[u]) if(v^fa[u]) fa[v]=u,dfs(v,dep+1);
}
void dp(int u,int fa,int d)
{
    (d==m/2? f[u][1][1]:f[u][0][0])=1;
    for(int v:e[u])
    {
	if(v==fa) continue;
	dp(v,u,d+1),memset(g,0,36);
	for(int x=0;x<3;++x) for(int y=0;y<3;++y) for(int p=0;p<3;++p) for(int q=0;q<3;++q) for(int k=0,r,t;k<3;++k) r=std::min(2,x+p*(k==1)),t=std::min(2,y+q*(k==2)),inc(g[r][t],mul(f[u][x][y],f[v][p][q]));
	memcpy(f[u],g,36);
    }
}
int main()
{
    int n=read(),p,q;
    for(int i=1,u,v;i<n;++i) u=read(),v=read(),e[u].push_back(v),e[v].push_back(u);
    dfs(1,1),memset(fa+1,0,n<<2),len=0,dfs(root,1);
    for(int i=root;i;i=fa[i]) dia[++m]=i;
    if(m&1) p=dia[m/2+1],dp(p,0,0),printf("%d",mul(i2,f[p][1][1]));
    else p=dia[m/2],q=dia[m/2+1],dp(p,q,1),dp(q,p,1),printf("%d",mul((1ll*f[p][1][0]+f[p][1][1]+f[p][1][2])%P,(1ll*f[q][1][0]+f[q][1][1]+f[q][1][2])%P));
}


Measured memory_bytes: 30080
#include <stdio.h>

int main() {
  int price[3];
  scanf("%d %d %d", &price[0], &price[1], &price[2]);
  if(price[0] >= price[1] && price[0] >= price[2]) {
    printf("%d\n", price[1] + price[2]);
  } else if(price[1] >= price[0] && price[1] >= price[2]) {
    printf("%d\n", price[0] + price[2]);
  } else {
    printf("%d\n", price[0] + price[1]);
  }
  return 0;
}


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

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

    int d, g;
    cin >> d >> g;
    vector<int> P(d), C(d);
    for(int i = 0; i < d; i++){
        cin >> P[i] >> C[i];
    }

    int mini = 1e9;
    for(int i = 0; i < (1 << d); i++){
        int point = 0, cnt = 0;
        for(int j = 0; j < d; j++){
            if((i >> j) & 1){
                point += (j + 1) * P[j] * 100 + C[j];
                cnt += P[j];
            }
        }
        if(point < g){
            for(int j = d - 1; j >= 0; j--){
                if((i >> j) & 1) continue;
                for(int k = 0; k < P[j]; k++){
                    point += (j + 1) * 100;
                    cnt++;
                    if(point >= g) break;
                }
                if(point >= g) break;
                point += C[j];
            }
        }
        mini = min(mini, cnt);
    }

    cout << mini << endl;

    return 0;
}

Measured memory_bytes: 256
S = input()
listS=[]
for i in range(len(S)):
    listS.append(int(S[i]))

n = len(S)
def dfs(i, total, formular):
    if i == n-1:
        if total == 7:
            print( formular+'=7')
            exit()

    else:
        next = S[i+1]
        dfs(i+1, total + int(next), formular + "+"+next)
        dfs(i+1, total-int(next), formular + '-' + next)




dfs(0, int(S[0]), S[0])


Measured memory_bytes: 3060
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

n = int(input())
cnt = 0
for i in range(n):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        cnt += 1
        if cnt >= 3:
            print("Yes")
            exit()
    else:
        cnt = 0
print("No")


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

int main() {
	int m, n, k;
	cin >> m >> n >> k;
	long long arra[m];
	int arrb[n];
	for (int i=0; i<m; i++){
		cin >> arra[i];
	}
	for (int i=0; i<n; i++){
		cin >> arrb[i];
	}
	for (int i=1; i<m; i++){
		arra[i]+=arra[i-1];
	}
	/*for (int i=1; i<n; i++){
		arrb[i]+=arrb[i-1];
	}*/
	/*for (int i=0; i<m; i++){
		cout << arra[i] << " ";
	}cout << endl;
	for (int i=0; i<n; i++){
		cout << arrb[i] << " ";
	}cout << endl;*/
	int t = 0;
	long long sum = 0;
	int j=n-1;
	long long total = 0;
	for (int i=0; i<n; i++){
		total+=arrb[i];
	}
	for (int i=-1; i<m; i++){
		sum = i == -1 ? 0 : arra[i];
		//cout << sum << endl;
		if (sum>k) break;
		while (sum+total>k and j>=0){
			total -= arrb[j];
			//cout << sum << endn;
			j--;
			//cout << 'j' << j << ' '
		}
		//cout << "sum" << sum << "sum ";
		t = max(t,i+j+2);
	}
	cout << t << endl;
}


Measured memory_bytes: 5472
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int n, m;
	cin >> n >> m;
	int s[10], c[10];
	rep(i, m) cin >> s[i] >> c[i];

	if(n >= 2) {
		rep(i, m) if(s[i] == 1 && c[i] == 0) {
			cout << -1 << endl;
			return 0;
		}
	}

	for(int i = 0; i <= 999; i++) {
		string str = to_string(i);
		if(str.size() != n) continue;
		bool ok = true;
		rep(i, m) if(str[s[i] - 1] != c[i] + '0') ok = false;
		if(ok) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


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

int main(){
  int n,k; cin >> n >> k;
  vector<ll> a(n);
  bool allm=1;
  rep(i,n){
    cin >> a[i];
    if(a[i]>=0) allm=0;
  }
  if((k%2==1&&allm)||k==n){
    sort(all(a));
    reverse(all(a));
    ll ans=1;
    rep(i,k){
      ans=(ans*a[i])%mod;
    }
    cout << (ans+mod)%mod << endl;
    return 0;
  }
  vector<pll> absv(n);
  rep(i,n){
    absv[i]=pll(abs(a[i]),a[i]);
  }
  sort(all(absv));
  reverse(all(absv));
  ll mminid=-1,pminid=-1;
  rep(i,k){
    if(absv[i].second<0) mminid=i;
    else pminid=i;
  }
  ll mmaxid=-1,pmaxid=-1;
  for(int i=k;i<n;i++){
    if(mmaxid==-1&&absv[i].second<0) mmaxid=i;
    if(pmaxid==-1&&absv[i].second>=0) pmaxid=i;
  }
  ll sum=1,sum1=-inf,sum2=-inf;
  rep(i,k){
    sum=(sum*absv[i].second)%mod;
  }
  if(mminid!=-1&&pmaxid!=-1){
    sum1=1;
    rep(i,k){
      if(i!=mminid) sum1=(sum1*absv[i].second)%mod;
    }
    sum1=(sum1*absv[pmaxid].second)%mod;
  }
  if(pminid!=-1&&mmaxid!=-1){
    sum2=1;
    rep(i,k){
      if(i!=pminid) sum2=(sum2*absv[i].second)%mod;
    }
    sum2=(sum2*absv[mmaxid].second)%mod;
  }
  if(sum>=0){
    cout << sum << endl;
    return 0;
  }
  if(sum1==-inf){
    cout << sum2 << endl;
  }
  else if(sum2==-inf){
    cout << sum1 << endl;
  }
  else if(sum1!=-inf&&sum2!=-inf&&absv[pmaxid].first*absv[pminid].first>=absv[mmaxid].first*absv[mminid].first){
    cout << sum1 << endl;
  }
  else{
    cout << sum2 << endl;
  }
}

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

int main() {
    int n, m, k;
    while (cin >> n >> m >> k, n || m || k) {
        vector<map<int,int> > dp(n+1);
        dp[0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (auto &j : dp[i]) {
                for (int l = 1; l <= m; l++) {
                    dp[i+1][j.first + l] += j.second;
                }
            }
        }

        int sum = 0;
        int count = 0;
        for (auto i : dp[n]) {
            if (i.first - k <= 1) count += i.second;
            else count += i.second * (i.first - k);
            sum += i.second;
        }

        printf("%.9f\n", (double)count/sum);
    }

    return 0;
}

Measured memory_bytes: 3608