akhauriyash/Code-Regression huggingface dataset:
while True:
    m,f,r = list(map(int,input().split(" ")))
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        print("F")
    elif m+f >= 80:
        print("A")
    elif m+f < 80 and m+f >= 65:
        print("B")
    elif m+f < 65 and m+f >= 50:
        print("C")
    elif m+f < 50 and m+f >= 30 and r >= 50:
        print("C")
    elif m+f < 50 and m+f >= 30 and r < 50:
        print("D")
    else:
        print("F")


Measured memory_bytes: 5592
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

const int MX = 200005;

struct UF{
	int t[MX];
	ll ans[MX], tB[MX];
	int find(int x){ return t[x] ? t[x] = find(t[x]) : x; }
	int merge(int a, int b){ // a <- b
		a = find(a), b = find(b);
		if(a == b) return false;
		t[b] = a; tB[a] += tB[b]; return true;
	}
}uf;

int N, M;
pii D[MX];
vector<int> G[MX];
int P[MX], chk[MX];

int main()
{
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= N; i++) scanf("%d%d", &D[i].first, &D[i].second);
	for(int i = 1; i <= M; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(int i = 1; i <= N; i++) P[i] = i;
	sort(P+1, P+N+1, [](int l, int r){ 
		return D[l].first - D[l].second < D[r].first - D[r].second;
	});
	for(int i = 1; i <= N; i++) uf.tB[i] = D[i].second;
	for(int i = 1; i <= N; i++){
		int cur = P[i], A = D[cur].first, B = D[cur].second;
		ll ans = max(A-B, 0);
		for(int c : G[cur]){
			if(!chk[c]) continue;
			int u = uf.find(c);
			ans = min(ans, max(uf.ans[u], A - (B+uf.tB[u])));
		}
		uf.ans[cur] = ans;
		for(int c : G[cur]) if(chk[c]) uf.merge(cur, c);
		chk[cur] = 1;
	}
	int p = uf.find(1);
	printf("%lld\n", uf.ans[p] + uf.tB[p]);
}


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

const ll mod = 1000000007;

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


int main() {
    ll n;
    cin >> n;
    map<ll, ll> mp;
    for (int i = 0; i < n; ++i) {
        ll a;
        cin >> a;
        mp[a]++;
    }
    map<ll, ll> nmp;
    for (ll i = n - 1; i >= 0; i -= 2) {
        if (i == 0) nmp[i] = 1;
        else nmp[i] = 2;
    }
    if (mp != nmp) {
        cout << 0 << endl;
        return 0;
    }
    cout << modpow(2, n / 2, mod) << endl;
}


Measured memory_bytes: 7296
#include "stdio.h"

main(){

  int v, i, j, A[1001], N;

  scanf("%d",&N);

  for(i=0 ; i<N ; i++){

    scanf("%d", &A[i]);

  }



  for(i=1 ; i<=N-1 ; i++){

  for(j=0 ; j<N ; j++){

    printf("%d", A[j]);
    if(j<N-1) printf(" ");

  }

  printf("\n");


    v = A[i];
    j = i-1;

    while(j>=0 && A[j]>v){

      A[j+1] = A[j];
      j--;
    }
    
    A[j+1] = v;
    
  }

  
  for(i=0 ; i<N ; i++){

    printf("%d", A[i]);
    if(i<N-1) printf(" ");

  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ull = unsigned long long;

ull r[500][500];
char x[500][500] = {};

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

    int n;
    cin >> n;

    auto transpose = [&](auto a) {
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                swap(a[i][j], a[j][i]);
            }
        }
    };

    int s[2][500];
    ull u[2][500];
    for (int h = 0; h < 2; h++) {
        for (int i = 0; i < n; i++) {
            cin >> s[h][i];
        }
    }
    for (int h = 0; h < 2; h++) {
        for (int i = 0; i < n; i++) {
            cin >> u[h][i];
        }
    }

    for (int k = 0; k < 64; k++) {
        ull l = 1ULL << k;
        memset(x, -1, sizeof(x));

        for (int h = 0; h < 2; h++) {
            for (int i = 0; i < n; i++) {
                int b = (bool)(u[h][i] & l);
                if (!(s[h][i] ^ b)) continue;
                for (int j = 0; j < n; j++) {
                    x[i][j] = b;
                }
            }
            transpose(x);
        }
        for (int g = 0; g < 2; g++) {
            for (int h = 0; h < 2; h++) {
                for (int i = 0; i < n; i++) {
                    int b = (bool)(u[h][i] & l);
                    if (s[h][i] ^ b) continue;
                    int j1 = -1;
                    for (int j = 0; j < n; j++) {
                        if (x[i][j] == b) { j1 = -1; break; }
                        if (x[i][j] < 0) {
                            if (j1 >= 0) { j1 = -1; break; }
                            j1 = j;
                        }
                    }
                    if (j1 >= 0) x[i][j1] = b;
                }
                if (g) break;
                transpose(x);
            }
        }
        int i0 = -1, j0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (x[i][j] < 0) {
                    if (i0 < 0) {
                        i0 = i;
                        j0 = j;
                    }
                    x[i][j] = (i == i0) ^ (j == j0);
                }
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                r[i][j] ^= (ull)x[i][j] << k;
            }
        }
    }

    for (int h = 0; h < 2; h++) {
        for (int i = 0; i < n; i++) {
            ull p[2] = { numeric_limits<ull>::max(), 0 };
            for (int j = 0; j < n; j++) {
                p[0] &= r[i][j];
                p[1] |= r[i][j];
            }
            if (p[s[h][i]] != u[h][i]) {
                cout << -1 << endl;
                exit(0);
            }
        }
        transpose(r);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << r[i][j] << " \n"[j == n - 1];
        }
    }

    return 0;
}


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

# (P ^ Q) ^ P -> Qなので楽っぽい
sum = 0
# P ^ Q の最大値って P + Qなはず
# そうなら、しゃくとりでいい
xor = 0
right = 0
cnt = 0
for left in range(n):
    while right < n and xor ^ a[right] == sum + a[right]:
        xor = sum + a[right]
        sum = xor
        right += 1
    #print(left, right)
    cnt += right - left
    if right == left:
        xor = a[right]
        sum = a[right]
        right += 1
    else:
        xor = xor ^ a[left] # マイナスでもいい
        sum -= a[left]
print(cnt)


Measured memory_bytes: 24840
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int INF=1e15;

typedef pair<int,int>P;
int H,W;
vector<vector<char>>MAZE(20,vector<char>(20));
vector<vector<int>>d(20,vector<int>(20));
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int counter=0;

int bfs(int sx,int sy,int counter){
    int ret=0;
    if(MAZE[sx][sy]=='#')return 0;
    counter--;
    queue<P> que;
    REP(i,H){
        REP(j,W) d[i][j]=INF;
    }
    que.push(P(sx,sy));
    d[sx][sy]=0;
    while(que.size()){
        if(counter==0)return ret;
        P p=que.front();
      	que.pop();
        REP(i,4){
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];
            if(nx>=0&&nx<H&&ny>=0&&ny<W&&MAZE[nx][ny]!='#'&&d[nx][ny]==INF){
                que.push(P(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
                ret=max(ret,d[nx][ny]);
                --counter;
            }
        }
    }
}

int solve(){
    cin>>H>>W;
    REP(i,H){
        REP(j,W){
          	cin>>MAZE[i][j];
            if(MAZE[i][j]=='.')counter++;
        }
    }
    int ans=0;
    REP(i,H){
        REP(j,W){
          	int ccopy=counter;
            ans=max(ans,bfs(i,j,ccopy));
        }
    }
    return ans;
}

signed main(){
    cout<<solve()<<endl;
}

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

using ll=long long;
const ll MOD=998244353;
ll dp[4001][4001],a,b,c,d;
ll f(ll A,ll B){
  if(A<a||B<b)return 0;
  if(dp[A][B])return dp[A][B];
  return dp[A][B]=(MOD+f(A-1,B)*B+f(A,B-1)*A-f(A-1,B-1)*(A-1)*(B-1)%MOD)%MOD;
}

int main(){
  cin>>a>>b>>c>>d;
  dp[a][b]=1;
  cout<<f(c,d)<<endl;
}


Measured memory_bytes: 86264
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l=[0]+l+[0]

  sm=sum([abs(l[i+1]-l[i]) for i in range(len(l)-1)])

  for i in range(1,len(l)-1):
    a=abs(l[i]-l[i-1])
    b=abs(l[i+1]-l[i])
    c=abs(l[i+1]-l[i-1])
    print(sm-(a+b-c))

main()

Measured memory_bytes: 17776
#include <iostream>
#include <string>
#include <vector>

//typedef long long ll;
using ll = long long;

template< typename Iterator >
bool is_same(Iterator begin, Iterator end)
{
  Iterator it;
  for (it = begin; it != end; ++it) { if (*it != *begin) return false; }
  return true;
}

template< typename Iterator >
bool is_even(Iterator begin, Iterator end)
{
  Iterator it;
  for (it = begin; it != end; ++it) { if (*it % 2 != 0) return false; }
  return true;
}

template< typename Head > void print(Head head)
{
  std::cout << head << std::endl;
}

template< typename Head, typename... Tail > void print(Head head, Tail... tail)
{
  std::cout << head << " ";
  print(tail...);
}


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

  std::vector< ll > va(3);
  for (ll i = 0; i < 3; i++) {
    std::cin >> va[i];
  }

  ll cnt = 0;
  while (!is_same(va.begin(), va.end()) && is_even(va.begin(), va.end())) {
    const ll A = (va[1] + va[2]) / 2;
    const ll B = (va[0] + va[2]) / 2;
    const ll C = (va[0] + va[1]) / 2;
    va[0] = A;
    va[1] = B;
    va[2] = C;
    cnt++;
  }

  if (is_even(va.begin(), va.end()) && (is_same(va.begin(), va.end()))) {
    cnt = -1;
  }

  print(cnt);

  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  string s;
  cin >> s;
  if(s=="RRR"){
    cout << 3 << endl;
  }else if(s=="RRS" || s=="SRR"){
    cout << 2 << endl;
  }else if(s=="SSS"){
    cout << 0 << endl;
  }else{
    cout << 1 << endl;
  }
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    double n;
    cin >> n;

    double ans = 6.28318530717958623200 * n;

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


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

typedef long long ll;

int main() {
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL); 
	int n;
	cin>>n;

	ll ans = 0;

	for(int i = 1; i <= n; ++i){
		for(int j = 1; j  <= n; ++j){
			for(int k = 1; k <= n; ++k){
				ans += __gcd(k, __gcd(i,j));
			}
		}
	}

	cout<< ans << endl;

}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector< vector<int> > s(m);
  for (int i = 0; i < m; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      int tmp;
      cin >> tmp;
      tmp--;
      s[i].push_back(tmp);
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; ++i) cin >> p[i];
  int ans = 0;
  for (int i = 0; i < 1 << n; ++i) {
    bool ok = true;
    for (int j = 0; j < m; ++j) {
      int cnt = 0;
      for (int k: s[j]) {
	if (i >> k & 1) cnt++;
      }
      if (cnt % 2 != p[j]) ok = false;
    }
    if (ok) ans++;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int U[2003][2003];

int main() {
  ll H,W;
  ll y;
  int k;
  cin >> H >> W;
  char S[2003][2003];
  rep(i,H){
      cin >> S[i];
  }
  y=0;
  rep(i,H){
      rep(j,W){
          if(S[i][j]=='.'){
              y++;
          }
          if(S[i][j]=='#' &&y>0){
              for(k=j-y;k<j;k++){
                  U[i][k]+=y;
              }
              y=0;
          }
          else if(j==W-1&&y>0){
              for(k=j-y+1;k<=j;k++){
                  U[i][k]+=y;
              }
              y=0;
          }
      }
  }
  rep(j,W){
      rep(i,H){
          if(S[i][j]=='.'){
              y++;
          }
          if(S[i][j]=='#' &&y>0){
              for(k=i-y;k<i;k++){
                  U[k][j]+=y;
              }
              y=0;
          }
          else if(i==H-1&&y>0){
              for(k=i-y+1;k<=i;k++){
                  U[k][j]+=y;
              }
              y=0;
          }
      }
  }
  y=0;
  rep(i,H){
      rep(j,W){
          if(U[i][j]>y) y=U[i][j];
      }
  }
  cout << (y>0 ? y-1 : 0)<< endl;
}

Measured memory_bytes: 19840
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define endl '\n'
#define ll long long int
using namespace std;

ll a, b, ans;

int main(){
    IOS;
    cin >> a >> b;
    for(ll i=a; i<=b; i*=2){
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#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>;



int main(){
    int n;
    cin >> n;
    if(n%10==3){
        cout << "bon" << "\n";
        return 0;
    }else if(n%10==0 || n%10==1 || n%10== 6 || n%10==8){
        cout << "pon" << "\n";
        return 0;
    }else{
        cout << "hon" << "\n";
    }
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int A, B, M;
    while(cin >> A >> B >> M){
        vector<int> a(A), b(B);
        for(auto& t : a) cin >> t;
        for(auto& t : b) cin >> t;
        int res = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
        for(int i=0;i<M;i++){
            int x, y, c; cin >> x >> y >> c;
            res = min(res, a[x-1] + b[y-1] - c);
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

//aのp乗を求めるアルゴリズム。計算量はO(logp)
ll modpow(ll a, ll p) {
    if(p == 0) {
        return 1;
    }
    if(p%2 == 0) {
        //pが偶数の時
        ll halfP = p/2;
        ll half = modpow(a, halfP);
        //a^(p/2)をhalfとして、half*halfを計算
        return half * half % mod;
    }
    else {
        //pが奇数の時は、pを偶数にするために1減らす
        return a * modpow(a, p-1) % mod;
    }
}
 
ll Comb(ll a, ll b) {
    if(b > a-b) {
        return Comb(a, a-b);
    }
    ll ansMul = 1;
    ll ansDiv = 1;
    rep(i, b) {
        ansMul *= (a-i);
        ansDiv *= (i+1);
        ansMul %= mod;
        ansDiv %= mod;
    }
    // ansMul/ansDivをやりたい
    // ansDivの逆元を使って求めよう
    ll ans = ansMul * modpow(ansDiv, mod-2) % mod;
    return ans; 
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = (modpow(2LL, n) + 3*mod - (Comb(n, a) + Comb(n, b) + 1))%mod; 
    out(ans);
    re0;
}

Measured memory_bytes: 256
#include <iostream>
#include<limits.h>
using namespace std;
int dp[100004];
int k;
int mincost(int n,int height[])
{
    if(n==1||n==0)
    return 0;
    if(dp[n]!=-1)
    return dp[n];
  int cost1=INT_MAX;
  for(int i=1;i<=k;i++)
  {
      if(n-i-1>=0&&n-i>=0)
      cost1=min(cost1,abs(height[n-1]-height[n-i-1])+mincost(n-i,height));
  }
  return dp[n]=cost1;

}
int main() {
    int n;
    cin>>n;
    cin>>k;
    int height[100004];
    for(int i=0;i<n;i++)
    cin>>height[i];
    for(int i=0;i<100004;i++)
    dp[i]=-1;
    cout<<mincost(n,height);

}

Measured memory_bytes: 8832
# coding: utf-8
N = int(input())
if N == 1:
    print(1)
    exit()
ans = 0
for i in range(1, N+1):
    ans += i
    if ans >= N:
        end = i
        break
res = ans - N
for i in range(1, end+1):
    if i != res:
        print(i)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
//#include<atcoder/all>
// Begin Header {{{
//using namespace atcoder;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
template<class T, class S> inline bool chmax(T &a, const S &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T, class S> inline bool chmin(T &a, const S &b) { if (a>b) { a = b; return 1; } return 0; }
#define INT(...)                                                                                                                                               \
    int __VA_ARGS__;                                                                                                                                           \
    IN(__VA_ARGS__)
#define LL(...)                                                                                                                                                \
    ll __VA_ARGS__;                                                                                                                                            \
    IN(__VA_ARGS__)
#define STR(...)                                                                                                                                               \
    string __VA_ARGS__;                                                                                                                                        \
    IN(__VA_ARGS__)
#define CHR(...)                                                                                                                                               \
    char __VA_ARGS__;                                                                                                                                          \
    IN(__VA_ARGS__)
#define DBL(...)                                                                                                                                               \
    double __VA_ARGS__;                                                                                                                                        \
    IN(__VA_ARGS__)
template<class T> void scan(T &a) { cin >> a; }
void IN() {}
template<class Head, class... Tail> void IN(Head &head, Tail &... tail){ scan(head); IN(tail...); }
// }}} End Header



int main() {
	LL(n);
	STR(s);
	ll west_cnt = 0;
	ll east_cnt = 0;

	loop(i, 1, n) if(s[i] == 'E') east_cnt++;
	ll min = east_cnt;
	loop(i, 1, n){
		if(s[i-1] == 'W') west_cnt++;
		if(s[i] == 'E') east_cnt--;
		chmin(min, west_cnt+east_cnt);
	}
	cout << min << endl;
	return 0;
}


Measured memory_bytes: 3904
import java.util.*;

public class Main{

  static int h;
  static long[] a;

  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    h = sc.nextInt();
    a = new long[h+1];
    for (int i=1; i<=h; i++){
      a[i] = sc.nextLong();
    }
    buildMaxHeap();
    for (int i=1; i<=h; i++){
      System.out.print(" "+a[i]);
    }
    System.out.println();
  }

  public static int left(int i){
    return 2*i;
  }

  public static int right(int i){
    return 2*i+1;
  }

  public static int parent(int i){
    return i/2;
  }

  public static void maxHeapify(int i){
    int l = left(i);
    int r = right(i);
    int largest;
    if (l <= h && a[l]>a[i]){
      largest = l;
    } else {
      largest = i;
    }
    if (r <= h && a[r] > a[largest]){
      largest = r;
    }

    if (largest != i){
      long t = a[i];
      a[i] = a[largest];
      a[largest] = t;
      maxHeapify(largest);
    }
  }

  public static void buildMaxHeap(){
    for (int i=h/2; i>0; i--){
      maxHeapify(i);
    }
  }
}


Measured memory_bytes: 166172
#include <iostream>
int main(){
    int a,b;
    std::cin >> a >> b;
    if(a<b){
        std::cout << "a < b" << std::endl;
    }
    else if(a>b){
        std::cout << "a > b" <<std::endl;
    }
    else{
        std::cout << "a == b" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 1156
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            List<int> list = new List<int>();
            for (int i = 0; i < s.Length - 2; i++)
            {
                list.Add(Abs(int.Parse(s.Substring(i, 3)) - 753));
            }

            Console.WriteLine(list.Min());
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        #endregion
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	V<T> dish(n);
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		dish[i] = make_tuple(a + b, a, b);
	}

	sort(all(dish), greater<T>());

	ll taka = 0, aoki = 0;
	rep(i, n) {
		if (i & 1) aoki += get<2>(dish[i]);
		else taka += get<1>(dish[i]);
		
	}

	cout << taka - aoki << endl;

}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

int n; ll a, b, h[100010];

bool
enough(ll t)
{
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    if (h[i] - b * t > 0) cnt += (h[i] - b * t - 1) / (a - b) + 1;
  }
  if (cnt <= t) return true;
  return false;
}

int
main(int argc, char *argv[])
{
  scanf("%d %lld %lld", &n, &a, &b);
  ll max_h = -1;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &h[i]);
    max_h = Max(max_h, h[i]);
  }

  ll l = 0, r = max_h / b + 1;
  while (r - l > 1) {
    ll med = (l + r) / 2;
    if (enough(med)) r = med;
    else l = med;
  }
  printf("%lld\n", r);

  return 0;
}

  


Measured memory_bytes: 896
#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 = 0; j < N; j++) {
			if (A[j].value < A[j - 1].value){
				swap(A[j], A[j - 1]);
			}
		}
	}
}

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;
		}
		swap(A[i], A[minj]);
	}
}

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 <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 1e18;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()

int n, m;

int id(int x, int y){
	return x*m+y;
}

P p(int x){
	return {x/n,x%n};
}

int main(){
	cin >> n >> m;
	vector<string> s(n);
	REP(i,n) cin >> s[i];
	mf_graph<int> G(n*m+2);
	REP(i,n)REP(j,m){
		if(s[i][j]=='#') continue;
		if((i+j)%2==0){
			if(i>0){
				if(s[i-1][j]=='.')
					G.add_edge(id(i,j),id(i-1,j),1);
			}
			if(i<n-1){
				if(s[i+1][j]=='.')
					G.add_edge(id(i,j),id(i+1,j),1);
			}
			if(j>0){
				if(s[i][j-1]=='.')
					G.add_edge(id(i,j),id(i,j-1),1);
			}
			if(j<m-1){
				if(s[i][j+1]=='.')
					G.add_edge(id(i,j),id(i,j+1),1);
			}
			G.add_edge(n*m,id(i,j),1);
		}
		else{
			G.add_edge(id(i,j),n*m+1,1);
		}
	}
	cout << G.flow(n*m,n*m+1) << endl;
	for(auto e:G.edges()){
		if(e.flow==0) continue;
		if(e.from==n*m||e.to==n*m+1) continue;
		int x1=e.from/m, y1=e.from%m;
		int x2=e.to/m, y2=e.to%m;
		//cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
		if(x1+1==x2){
			s[x1][y1]='v';
			s[x2][y2]='^';
		}
		else if(x1-1==x2){
			s[x2][y2]='v';
			s[x1][y1]='^';
		}
		else if(y1+1==y2){
			s[x1][y1]='>';
			s[x2][y2]='<';
		}
		else if(y1-1==y2){
			s[x2][y2]='>';
			s[x1][y1]='<';
		}
	}
	REP(i,n) cout << s[i] << endl;
	return 0;
}

Measured memory_bytes: 5512
#include<iostream>

using namespace std;

typedef long long ll;

#define rep(i,n) for(int i=0;i<(n);i++)

#define MAX_N 500000//頂点の最大数

ll par[MAX_N];//親の番号
ll urank[MAX_N];//集合のランク
ll usize[MAX_N];//集合の要素数
ll num;//集合の数

void init(int n) {//0〜n-1までの要素を初期化 最初はバラバラ
    num = n;
    rep(i,n) {
        par[i] = i;
        urank[i] = 0;
        usize[i] = 1;
    }
}

ll find(ll x) {//xが属する集合の親を見つける
    if(par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

ll get_usize(ll x) {//xが属する集合の要素数を返す。
    return usize[find(x)];
}

void unite(ll x,ll y) {//xが属する集合とyが属する集合を併合する。
    x = find(x);
    y = find(y);
    if(x == y) return;

    ll s = usize[x] + usize[y];
    num--;
    if(urank[x] < urank[y]) {
        par[x] = y;
        usize[y] = s;
    } else {
        par[y] = x;
        usize[x] = s;
        if(urank[x] == urank[y]) urank[x]++;
    }
}

bool same(ll x,ll y) {//同じ集合に属するかを判定する
    return find(x) == find(y);
}

ll num_set() {//集合の数(木の数)を返す。
    return num;
}

ll n,q;

int main() {
    cin >> n >> q;
    init(n);

    rep(i,q) {
        ll com,x,y;
        cin >> com >> x >> y;
        if(com) {
            cout << same(x,y) << endl;
        }else {
            unite(x,y);
        }
    }
}



Measured memory_bytes: 3340
import os

import math
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


r = int(sys.stdin.buffer.readline())
a = r * 2 * math.pi
print(a)


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

int main () {
  int N, K;
  cin >> N >> K;
  vector <bool> snuke(N);
  for (int i = 0; i < K; i++){
    int d ;
    cin >> d;
    vector <int> treat(d);
    for (int i = 0; i < d; i++){
      cin >> treat.at(i);
      int a = treat.at(i)-1;
      snuke.at(a) = true;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++){
    if (!snuke.at(i)) ans++;
  }
  cout << ans << endl;
}

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

#define ll long long int
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int cnt=1;
    for(int i=1;i<n;i++){
      if(s[i-1]!=s[i]) cnt++;
    }
    cout<<cnt<<endl;

}


Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse -> greater<long long>()
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back

int main(){
   ll n;cin>>n;
   VI a(n);
   rep(i,n)cin>>a[i];
   sort(ALL(a));
   VI sum(n+1);
   sum[0]=0;
   rep(i,n){
      sum[i+1]=sum[i]+a[i];
   }
   for(int i=n-1;i>=0;i--){
      if(a[i]>2*sum[i]){
         cout<<n-i<<endl;
         return 0;
      }
   }
}

Measured memory_bytes: 4856
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int edgenum[100000];
vector<pair<int, int>> edge;
int main() {
	char c;
	cin >> c;
	switch (c) {
	case 'A':
		cout << 'T' << endl;
		break;
	case 'T':
		cout << 'A' << endl;
		break;
	case 'G':
		cout << 'C' << endl;
		break;
	case 'C':
		cout << 'G' << endl;
		break;
	}
}


Measured memory_bytes: 256
//long long -> ll
//http://web.mit.edu/~ecprice/acm/acm08/notebook.html#file12
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include<bits/stdc++.h>
typedef long long ll;
#define x first
#define y second
#define all(aaa) (aaa).begin(),(aaa).end()
#define REP(i,sss,eee) for(long long i=sss;i<=eee;++i)
#define pb push_back
#define pii pair<long long,long long>
#define vi vector<long long>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}
typedef tree<
long long,
null_type,
less<long long>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
std::vector<long long> h,a;
std::vector<long long> seg;
bool cmp(long long i1,long long i2)
{
	return  (h[i1]<h[i2]);
}
long long query(long long ix, long long s, long long e, long long qs, long long qe)
{
	if(e<qs||qe<s){return -1;}
	if(qs<=s&&e<=qe){return seg[ix];}
	long long lft=(2*ix+1),rgt=(2*ix+2),mid=((s+e)/2);
	long long ans=MAX(query(lft,s,mid,qs,qe),query(rgt,mid+1,e,qs,qe));
	return ans;
}
long long update(long long ix, long long s, long long e, long long upd, long long val)
{
	if(s==e&&s==upd){seg[ix]=val;return val;}
	if(e<upd||upd<s){return seg[ix];}
	long long lft=(2*ix+1),rgt=(2*ix+2),mid=((s+e)/2);
	seg[ix]=MAX(update(lft,s,mid,upd,val),update(rgt,mid+1,e,upd,val));
	return seg[ix];
}
long long solve()
{
	long long n;cin>>n;
	h.resize(n);a.resize(n);
	seg.resize(4*n,-1);
	std::vector<long long> v,ans(n);
	REP(i,0,n-1){cin>>h[i];v.pb(i);}
	REP(i,0,n-1){cin>>a[i];}
	sort(v.begin(),v.end(),cmp);
	for(auto index:v)
	{
		ans[index]=MAX((query(0,0,n-1,0,index-1)+a[index]),a[index]);//O(log(n))
		update(0,0,n-1,index,ans[index]);//O(log(n))
	}
	long long fin=-1;
	for(auto it:ans)
	{
		fin=MAX(it,fin);
	}
	cout<<fin<<"\n";
}
signed main(){
	long long tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 13428
/* Don't try to hack it :|
 
            _/﹋\_
            (҂`_´)
            <,︻╦╤─҉- - - - - - - - - - - - - - -
            _/﹋\_
*/

#include <bits/stdc++.h>
#define ll long long 
#define all(v) v.begin() , v.end()
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define tr(con) for(auto it = con.begin(); it!= con.end() ; it++)
#define INF 1e9+7   // 1 * 10^9+ 7
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a , b;
	cin >> a >> b ;
	if(a<10 && b<10) cout << a*b ;
	else cout << "-1";
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#define P 1000000007
#define A(x,y) f[((x)+2100)*4200+(y)]
using namespace std;
int f[22000000];
int fac[13000],ifac[13000],n;
long long ans,inv2;
struct node{
	int x,y;
}a[220000];
long long power(long long x,int k){
	long long ans=1;
	while(k){
		if(k&1)(ans*=x)%=P;
		(x*=x)%=P;
		k>>=1;
	}
	return ans;
}
int pre(){
	fac[0]=1;
	for(int i=1;i<=12000;i++)fac[i]=1LL*fac[i-1]*i%P;
	ifac[12000]=power(fac[12000],P-2);
	for(int i=12000-1;i>=0;i--)ifac[i]=1LL*ifac[i+1]*(i+1)%P;
}
long long C(int m,int n){
	return 1LL*fac[n]*ifac[m]%P*ifac[n-m]%P;
}
int main(){
	pre();
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x,y;
		scanf("%d%d",&a[i].x,&a[i].y);
		x=-a[i].x;
		y=-a[i].y;
		A(x,y)++;
	}
	for(int i=-2000;i<=2000;i++)
		for(int j=-2000;j<=2000;j++)
			A(i,j)=(0LL+A(i-1,j)+A(i,j-1)+A(i,j))%P;
	for(int i=1;i<=n;i++)(ans+=A(a[i].x,a[i].y))%=P;
	inv2=power(2,P-2);
	for(int i=1;i<=n;i++)(ans-=C(a[i].x+a[i].x,a[i].x+a[i].x+a[i].y+a[i].y))%=P;
	ans%=P;
	ans+=P;
	ans%=P;
	ans=1LL*ans*inv2%P;
	printf("%lld\n",ans);
}

Measured memory_bytes: 69504
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  tmp1 = input[0];
  tmp2 = input[1];

  var arr1 = [];
  var arr2 = [];

  for (var i = 0; i < tmp1.length; i++) {
      if (tmp1.substr(i, 1) !== '\r'){
        arr1.push(tmp1.substr(i, 1));
      }
      
  }
  // console.log(arr1);
  for (var i = 0; i < tmp2.length; i++) {
    if (tmp2.substr(i, 1) !== '\r'){
      arr2.push(tmp2.substr(i, 1));
    }
    // arr2.push(tmp2.substr(i, 1));
  }

  arr1.sort();

  // 降順ソート
  // arr2.sort(function (p1, p2) {
  //   return (p2 - p1);
  // });
  arr2.sort();
  var arr3 = [];
  for (var i = arr2.length -1; i >= 0; i--) {
    arr3.push(arr2[i]);
  }

  // console.log(arr2);

  var str1 = arr1.join();
  var str2 = arr3.join();
  // console.log(str1);
  // console.log(str2);
  if (str1 < str2) {
    console.log('%s', 'Yes');
  } else {
    console.log('%s', 'No');
  }

  //出力
  // console.log('%d %s', a + b + c, s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 21064
#include<stdio.h>
int n,o,d,x,i;
int a[200001];
int main(void)
{
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		
		if(a[i]%4==0){
			o++;
		}else if(a[i]%2==0){
			d++;
		}else{
			x++;
		}
	}
		
		if(d==1){
			x++;
			d--;
		}
		
		if(n==d){
			puts("Yes");
		}else if(o>=x&&d>1){
			puts("Yes");
		}else if(o+1>=x&&d==0){
			puts("Yes");
		}else{
			puts("No");
		}
	
	return 0;
}

Measured memory_bytes: 512
h, w = (int(i) for i in input().split())
list_a = [input() for s in range(0, h)]
list_tmp = []
for i in range(0, h):
    for j in range(0, w):
        if list_a[i][j] == '#':
            list_tmp.append(list(list_a[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_tmp_t = [list(x) for x in zip(*list_tmp)]
list_tmp2 = []
for i in range(0, len(list_tmp_t)):
    for j in range(0, len(list_tmp_t[i])):
        if list_tmp_t[i][j] == '#':
            list_tmp2.append(list(list_tmp_t[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_ans = [list(x) for x in zip(*list_tmp2)]
for i in range(0, len(list_ans)):
    print("".join(list_ans[i]))

Measured memory_bytes: 9380
S = int(input())
if S <= 10**9:
    print('0 0 1 0 0 {}'.format(S))
else:
    from math import ceil
    X2 = 10**9
    Y3 = ceil(S/X2)
    X3 = 1
    Y2 = 10**9*Y3-S
    print('0 0 {} {} {} {}'.format(X2,Y2,X3,Y3))


Measured memory_bytes: 38384
fn main() {
    let n = read::<usize>();
    let s = read::<String>().chars().collect::<Vec<_>>();
    let mut es = vec![0; n + 1];
    let mut ws = vec![0; n + 1];
    for i in 0..n {
        if s[i] == 'E' {
            es[i + 1] = es[i] + 1;
            ws[i + 1] = ws[i];
        } else {
            es[i + 1] = es[i];
            ws[i + 1] = ws[i] + 1;
        }
    }
    let mut ans = 1000000000;
    for i in 1..n + 1 {
        ans = std::cmp::min(ans, es[n] - es[i] + ws[i - 1]);
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();

		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(h);

		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < n - k + 1; i++) {
			int d = h[i + k - 1] - h[i];
			ans = Math.min(ans, d);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 49476
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/operators.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> v(n+1);
  rep(i, n+1) cin >> v[i];
  // dp[i] = 上から見た時のi番目の最大頂点数
  vector<ll> dp(n+10, -1);
  dp[0] = 1;

  // n == 0の時の処理
  if(n == 0 && v[0] > 1){
    cout << -1 << endl;
    return 0;
  }else if(n == 0 && v[0] == 1){
    cout << 1 << endl;
    return 0;
  }else if(n == 0){
    cout << -1 << endl;
    return 0;
  }

  cpp_int res = 0;
  // 上から見るか
  for (int i = 0; i < n; ++i) {
    if(dp[i] - v[i] > LLONG_MAX / 2) dp[i+1] = LLONG_MAX;
    else dp[i+1] = (dp[i] - v[i]) * 2;
  }

  // ans[i] = 深さiの最大頂点数
  vector<ll> ans(n+1);
  // 下から見るか
  ans[n] = v[n];
  for (int i = n; i >= 1 ; --i) {
    // cout << dp[i-1] << ' ' << ans[i]+v[i-1] << endl;
    ans[i-1] = ans[i] + v[i-1];
  }
  rep(i, n+1) chmin(ans[i], dp[i]);
  // print(dp);
  // print(ans);

  // 構築できるかチェック
  bool flag = false;
  for(int i = 0; i < n; i++){
    res += ans[i];
    if(ans[i] <= v[i]) flag = true;
  }
  if(ans[n] != v[n]) flag = true;
  res += ans[n];
  // res += ans[n];
  // print(ans);

  if(flag) cout << -1 << endl;
  else cout << res << endl;
}


Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
pair<bool,long long int>mat[101][100002];
int main(){
	#ifdef EVAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int N,W;
	cin>>N>>W;
	long long int val[N];
	long long int pes[N];
	for(int i=0;i<N;i++)cin>>pes[i]>>val[i];
	mat[0][val[0]].first=1;
	mat[0][val[0]].second=pes[0];
	for(int i=1;i<N;i++){
		for(int j=0;j<100001;j++){
			if(mat[i-1][j].first==1){
				if(mat[i-1][j+val[i]].first==1){
					mat[i][j+val[i]].first=1;
					mat[i][j+val[i]].second=min(mat[i-1][j+val[i]].second,mat[i-1][j].second+pes[i]);
				}else{
					mat[i][j+val[i]].first=1;
					mat[i][j+val[i]].second=mat[i-1][j].second+pes[i];
				}
			}
			if(mat[i-1][j].first==1 && mat[i][j].first==0){
				mat[i][j].first=mat[i-1][j].first;
				mat[i][j].second=mat[i-1][j].second;
			}
		}
		if(mat[i-1][val[i]].first==0){
			mat[i][val[i]].first=1;
			mat[i][val[i]].second=pes[i];
		}else{
			mat[i][val[i]].first=1;
			mat[i][val[i]].second=min(mat[i-1][val[i]].second,pes[i]);
		}
	}
	for(int i=100001;i>=0;i--){
		if(mat[N-1][i].first==1 && mat[N-1][i].second<=W){
			cout<<i;
			return 0;
		}		
	}
}


Measured memory_bytes: 155904
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  if (n == m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3648
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C_fix_2
# CreatedDate:  2020-07-29 15:34:23 +0900
# LastModified: 2020-07-29 15:51:13 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n, m = map(int, input().split())
    num = [None] * (n+1)
    for _ in range(m):
        s, c = map(int, input().split())
        if (num[s] is not None and num[s] != c) or (s == 1 and c == 0 and len(num)>2):
            print(-1)
            return
        num[s] = c
    num = [0 if x is None else x for x in num]
    for i in range(1, n+1):
        if num[i] == 0 and i == 1 and len(num) > 2:
            print("1", end="")
            continue
        elif i == 1 and num[i] == 0 and len(num) == 2:
            print(0)
            return
        print("{}".format(num[i]), end="")
    print()

if __name__ == "__main__":
    main()


Measured memory_bytes: 9044