akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
    int H, W;
    while(1){
        cin>>H>>W;
        if(W==0&&H==0) break;
        for(int i=1; i<=H; i++){
            for(int a=1;a<=W; a++){
                cout<<'#';
            }
        cout<<endl;
        }
      cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3104
N, M = map(int, input().split())

ps = []
for i in range(M):
    ps.append(input().split())

penalties = [0] * N
corrects = [0] * N

for p, s in ps:
    if s == 'AC' and corrects[int(p) - 1] == 0:
        corrects[int(p) - 1] = 1
    elif s == 'WA' and corrects[int(p) - 1] == 0:
        penalties[int(p) - 1] += 1

for i in range(N):
    penalties[i] = penalties[i] * corrects[i]
print(sum(corrects), sum(penalties))


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

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

}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 400

ll dp[MAXN+2][MAXN+2];
bool used[MAXN+2][MAXN+2];
vector<ll>a(MAXN+1), suma(MAXN+2);


ll f(int l, int r){
  if(used[l][r])return dp[l][r];
  used[l][r]=true;

  if(l==r)return 0;

  ll sum = suma[r]-suma[l-1];
  ll fans = INF;
  for(int m=l; m<=r; m++){
    fans = min<ll>( fans, f(l, m) + f(m+1, r) );
  }
//cout<<l<<' '<<r<<' '<<sum<<' '<<fans<<endl;
  return dp[l][r] = fans + sum;
}

int main(){
  int n;cin>>n;
  rep(i, n)cin>>a[i];
  ll sum=0;
  rep(i, n)sum+=a[i];
  rep(i, n)suma[i+1]+=suma[i]+a[i];

  cout<<f(1, n)<<endl;

  return 0;

rep(i, n+1){
  rep(j, n+1)cout<<dp[i][j]<<' ';
  cout<<endl;
}

  return 0;
}


Measured memory_bytes: 5048
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;
void C_142()
{
  int N;
  cin >> N;

  vector<int> student(N);
  for (int i = 0; i < N; ++i)
  {
    int A;
    cin >> A;
    student[A - 1] = i+1;
  }

  for (int i = 0; i < N; ++i) cout << student[i] << endl;
}

int main()
{
  //C_140();
  //C_141();
  C_142();

  return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	int n, p;
	cin >> n;
	int m[100000] = {};
	for (int i = 0; i < n; i++) {
		cin >> p; if (i + 1 == p)m[i] = 1;
	}
	int count=0;
	for (int i = 0; i < n; i++) {
		if (m[i] == 1) {
			count++;
			if (i + 1 < n&&m[i + 1] == 1) {
				m[i + 1] = 0;
			}
		}
	}
	cout << count << endl;
	char nyaa;
	cin >> nyaa;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	
	cin>>n;
	int* a=new int[n];
	int* b=new int[n];
	memset(b,0,n*sizeof(int));
	for(int i = 0;i<n;i++)
		cin>>(a[i]);
	for(int i=0;i<n;i++){
		int tp=a[i];
		while(!(tp&1)){
			tp>>=1;b[i]++;
		}
	}
	
	int r=0;
	for(int i=0;i<n;i++){
		r+=b[i];
	}
	cout<<(r)<<endl;
    return 0;

}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int n, a, b; cin >> n >> a >> b;
    cout << min(a * n, b);
}


Measured memory_bytes: 256
N,K,Q = map(int,input().split())
A = [int(input()) for _ in range(Q)]
B=[0]*N

for i in range(Q):
    B[A[i]-1]+=1

for i in range(N):
    if Q-B[i]>=K:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 56024
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;
namespace Arithmetics {
	template<typename T>
	T original_pow(T a, T b) {
		T ans = 1;
		rep(i, b) {
			ans *= a;
		}

		return  ans;
	}
	template<typename T>
	T gcd(T a, T b) {
		if (a > b) {
			T c = a;
			a = b;
			b = c;
		}
		if (a == 0) {
			return b;
		}

		return gcd(b % a, a);
	}
	template<typename T>
	T gcd_of_all(vector<T> v) {
		T temp = v[0];
		for (T elem : v) {
			temp = gcd(temp, elem);
		}

		return temp;
	}
	template<typename T>
	T lcm(T a, T b) {
		T GCD = gcd(a, b);
		return a * b / GCD;
	}
	template<typename T>
	T lcm_of_all(vector<T> v) {
		T temp = v[0];
		for (T elem : v) {
			temp = lcm(temp, elem);
		}
		return temp;
	}
}
using namespace Arithmetics;
void prob138() {
	int N; cin >> N;
	priority_queue<double,vector<double>,greater<double>> pq;
	for (int i = 0; i < N; i++) {
		double x;
		cin >> x;
		pq.push(x);
	}

	for (int i = 0; i < N - 1; i++) {
		double x = pq.top(); pq.pop();
		double y = pq.top(); pq.pop();
		double z = (x + y) / 2;
		pq.push(z);
	}

	printf("%.10lf\n", pq.top());
}

void prob136() {
	int N; cin >> N;
	int max = 0, min = int_INF;
	bool flag = false;
	rep(i, N) {
		int x; cin >> x;
		if (x > max) {
			max = x; min = int_INF;
		}
		x <= min ? min = x : 1;
		if (max - min > 1) {
			flag = true;
			break;
		}
	}

	if (flag) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

void prob140() {
	int N; cin >> N;
	vector<int> B(N + 1);
	B[0] = int_INF; B[N] = int_INF;
	for (int i = 1; i < N; i++) {
		cin >> B[i];
	}
	ll ans = 0;
	for (int j = 0; j < N; j++) {
		ans += min(B[j], B[j + 1]);
	}

	cout << ans << endl;
}

void prob141() {
	int N, K, Q; cin >> N >> K >> Q;
	vi Contestants(N);
	rep(i, Q) {
		int x;
		cin >> x;
		Contestants[--x]++;
	}

	rep(i, N) {
		if (Contestants[i] + K - Q > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

void prob148() {
	ll a, b;
	cin >> a >> b;
	cout << lcm(a, b) << endl;
}
int main() {
	prob148();
}

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

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

ll dp[10010][2][105];

int main(){
    string k;
    cin >> k;
    ll ks = k.size(), i, j;
    ll d;
    cin >> d;
    dp[0][0][0] = 1;
    for(i = 0; i < ks; i++) { //i文字目
        for(j = 0; j < d; j++) { // Kと一致している時
            //dp[i + 1][0][j] = (dp[i + 1][0][j] + dp[i][0][j]) % MOD;
            dp[i + 1][0][(j + (k[i] - '0')) % d] = (dp[i + 1][0][(j + k[i] - '0') % d] + dp[i][0][j]) % MOD;
        }
        for(j = 0; j < d;j++){
            for(int x = 0; x < k[i] - '0';x++){
                dp[i + 1][1][(j + x) % d] = (dp[i + 1][1][(j + x) % d] + dp[i][0][j]) % MOD;
            }
            for(int x = 0; x < 10;x++){
                dp[i + 1][1][(j + x) % d] = (dp[i + 1][1][(j + x) % d] + dp[i][1][j]) % MOD;
            }
        }
    }
    cout << (dp[ks][0][0] + dp[ks][1][0] - 1 + MOD) % MOD << endl;
    return 0;
}

Measured memory_bytes: 16640
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

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

int a[20];
int main() {
    for (int i = 1; i <= 4; ++i) {
        a[read()] = 1;
    }
    if (a[1] && a[9] && a[4] && a[7]) puts("YES");
    else puts("NO");
    return 0;
}

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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("d",&a,&b)
#define sfff(a,b,c)     scanf("d%d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int z=1 ; z<=t ; z++)
#define PRINT_CASE printf("Case %d: ",z)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)1e5+5;
const int inf = 1e9+2;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;

int v[110],w[110];
ll DP[110][maxn];
int n,cap;

ll cal(int pos, int val){

    if(val==0) return 0;
    if(pos==n || val<0) return inf;

    ll &res = DP[pos][val];

    if(res!=-1){
        return res;
    }

    ll res0= cal(pos+1,val);
    ll res1 = cal(pos+1, val-v[pos])+w[pos];
    res=min(res0,res1);
    return res;

}


int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin>>n>>cap;

    f0(i,n) cin>>w[i]>>v[i];
    memset(DP , -1 , sizeof(DP));
    for(int i=n*1000 ; i>=0 ; i--){

        if(cal(0,i)<=cap){
            cout<<i<<endl;
            return 0;
        }
    }

    return 0;
}



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

#define MAX 100002

int n;

vector<pair<int, long long int> > v[MAX];
int dp[MAX];
int mx[MAX];

inline long long int dfs2(int b, int pr = -1, long long int dep = 0){
	long long int r = dep;
	for (int i = 0; i < v[b].size(); i++){
		int go = v[b][i].first;
		if (go == pr)continue;
		r+=dfs2(go, b, dep + v[b][i].second);
	}
	return r;
}
long long int ans = 0;
inline void dfs(int b,int pr=-1){
	dp[b]++;
	int ii = 0;
	for (int i = 0; i < v[b].size(); i++){
		if (v[b][i].first == pr)continue;
		dfs(v[b][i].first, b);
		dp[b] += dp[v[b][i].first];
		mx[b] = max(mx[b], dp[v[b][i].first]);
		if (mx[b] == dp[v[b][i].first]){
			ii = v[b][i].first;
		}
	}
	mx[b] = max(mx[b], n - dp[b]);
	if (mx[b] == n - dp[b]){
		ii = pr;
	}
	if (mx[b] * 2 == n){
		long long int res = dfs2(b) * 2;
		long long int mit = LLONG_MAX;
		for (int i = 0; i < v[b].size(); i++){
			if (v[b][i].first != ii)continue;
			mit = min(mit, v[b][i].second);
		}
		res -= mit;
		ans = max(ans, res);
		return;
	}
	if (mx[b] <= n / 2){
		long long int res = dfs2(b)*2;
		long long int mit = LLONG_MAX;
		for (int i = 0; i < v[b].size(); i++){
			mit = min(mit, v[b][i].second);
		}
		res -= mit;
		ans = max(ans, res);
	}
}
int main(){
	cin >> n;
	for (int i = 1; i < n; i++){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		a--;
		b--;
		v[a].push_back(make_pair(b, c));
		v[b].push_back(make_pair(a, c));
	}
	dfs(0);
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

int n, ans[200005];
char x[200005];
set<int> s;
set<int>::iterator at;

int main() {
	scanf("%s", x);
	n = strlen(x);
	for (int i = 1; i < n; i++)
		if (x[i - 1] == 'R' && x[i] == 'L')
			s.insert(i);
	for (int i = 0; i < n; i++) {
		at = s.upper_bound(i);
		if (x[i] == 'L')
			at--;
		if (*at % 2 == i % 2)
			ans[*at]++;
		else
			ans[*at - 1]++;
	}
	for (int i = 0; i < n; i++)
		printf("%d%c", ans[i], " \n"[i == n - 1]);
}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long k = sc.nextLong();
        long total = 100;
        int count = 0;
        while(total < k) {
            total *= 1.01;
            count++;
        }
        System.out.println(count);
    }
}

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

#define rep(x, y) for (int i = (x); i < (y); i++)

typedef long long ll;

using namespace std;

int main() {
    ll h, n;
    cin >> h >> n;

    ll a, sum = 0;
    rep(0, n) {
        cin >> a;
        sum += a;
    }

    cout << (h <= sum ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);		
		long a=in.nextLong();
		long b=in.nextLong();
		long c=in.nextLong();
		long d=in.nextLong();
		long g=gcd(c,d);
		long q=c*d/g;
		long ans=b/c-(a-1)/c;
		ans=ans+b/d-(a-1)/d;
		ans=ans-b/q+(a-1)/q;
		ans=b-a-ans+1;
		System.out.println(ans);
	}
	
	public static long gcd(long a,long b)
	{
		if(a%b==0)
			return b;
		return gcd(b,a%b);
	}
}
	

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

using namespace std;

int main(){
	string S,T;
	cin>>S>>T;
	if(S.length()>T.length()){
		swap(S,T);
	}
	vector<vector<short>>memo(S.length() + 1, vector<short>(26));
	for(int i = 0; i < S.length(); i++){
		memo[i+1]=memo[i];
		memo[i+1][S[i]-'a']++;
	}
	vector<vector<short>>memo2(T.length() + 1, vector<short>(26));
	for(int i = 0; i < T.length(); i++){
		memo2[i+1]=memo2[i];
		memo2[i+1][T[i]-'a']++;
	}
	vector<short>now(26);
	int ans=0;
	set<vector<short>>SVI;
	for(int len = S.length(); len >= 1; len--){
		SVI.clear();
		for(int i = 0; i + len < memo.size(); i++){
			for(int k = 0; k < 26; k++){
				now[k] = memo[i+len][k] - memo[i][k];
			}
			SVI.insert(now);
		}
		for(int i = 0; i + len < memo2.size(); i++){
			for(int k = 0; k < 26; k++){
				now[k] = memo2[i+len][k] - memo2[i][k];
			}
			if(SVI.count(now)){
				cout<<len<<endl;
				return 0;
			}
		}
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 4028
#include <iostream>

using namespace std;

int main() {
  string o, e;
  cin >> o >> e;
  int i = 0;
  for (; i < e.size(); i++) {
    cout << o[i] << e[i];
  }
  if (o.size() - 1 == i) {
    cout << o[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
int puzzle[4][4];
int tmp[4][4];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
void empty(int *,int *);
int dfs(int,int,int,int,const int);
int cal();
void swap(int *,int *);
 
int main() {
    int i,j,a,x,y,l;
    for(i=0; i<4; i++) {
        for(j=0; j<4; j++) scanf("%d",&puzzle[i][j]);
    }
 
    empty(&x,&y);
    for(l=0; l<100; l++) {
        for(i=0; i<4; i++) {
            for(j=0; j<4; j++) tmp[i][j] = puzzle[i][j];
        }
 
        a = dfs(x,y,-1,0,l);
        if(a!=-1) {
            printf("%d\n",a);
            break;
        }
 
        for(i=0 ; i<4; i++) {
            for(j=0 ; j<4; j++) puzzle[i][j] = tmp[i][j];
        }
        a = -1;
        if(l==99) printf("%d\n",a);
    } 
    return 0;
}
 
void empty(int *x,int *y) {
    int i,j;
    for(i=0; i<4; i++) {
        for(j=0; j<4; j++) {
            if(!puzzle[i][j]) {
                *x = j;
                *y = i;
                return;
            }
        }
    }
}
 
void swap(int *a,int *b) {
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}
 
 
int cal() {
    int i,a,sum=0;
    for(i=0; i<16; i++) {
        a = puzzle[i/4][i%4];
        if(a) {
            a--;
            sum += abs(i/4 - a/4) + abs(i%4 - a%4);
        }
    }
    return sum;
}
 
 
int dfs(int x,int y,int p,int dep,const int lim) {
    int i,h,nx,ny,res;
 
    h = cal();
    if(h==0) return dep;
    if(dep+h>lim) return -1;
 
    for(i=0; i<4; i++) {
        nx = x+dx[i];
        ny = y+dy[i];
 
        if(~p && i==(p+2)%4) continue;
        if(!(0<=nx && nx<4 && 0<=ny && ny<4)) continue;
 
        swap(&puzzle[y][x],&puzzle[ny][nx]);
        res = dfs(nx,ny,i,dep+1,lim);
        if(~res) return res;
 
        swap(&puzzle[y][x],&puzzle[ny][nx]);
    }
 
    return -1;
}

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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  set<int> st;
  int n, k, q;
  cin >> n >> k >>q;
  vector<int> a(n);
  for(int &e : a) cin >> e;
  auto b = a;
  sort(begin(b), end(b));
  int ans = 1e9;
  for(int i = 0; i < n; i++) {
    int mi = b[i];
    if(st.count(mi)) continue;
    st.emplace(mi);
    vector<int> val;
    vector<int> t;
    for(int j = 0; j < n; j++) {
      if(a[j] < mi) {
        if(t.size()) {
          sort(begin(t),end(t));
          for(int x = 0; x < (int) t.size() + 1 - k; x++) {
            val.emplace_back(t[x]);
          }
          t.clear();
        }
      } else {
        t.emplace_back(a[j]);
      }
    }
    if(t.size()) {
      sort(begin(t),end(t));
      for(int x = 0; x < (int) t.size() + 1 - k; x++) {
        val.emplace_back(t[x]);
      }
    }
    if(val.size()) {
      sort(begin(val),end(val));
      if(val.size() < q) continue;
      ans = min(ans, val[q - 1] - b[i]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <tuple>

using namespace std;

int main()
{  
    int A,B,C;
    cin >> A >> B >> C;
    int yo1 = A-B;
    if((C-yo1) < 0){
        cout << 0 << endl;
    }else{
        cout << C-yo1 << endl;
    }
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

struct state {
	int p, c;
	state(int p, int c) : p(p), c(c) {};
	bool operator<(const state &o)const {
		return o.c<c;
	}
};

int main() {
	int n, m;
	while(cin >> n >> m, n) {
		int a, b, c;
		vvi dist(n, vi(n, INF));
		REP(i, m) {
			cin >> a >> b >> c;
			dist[a][b] = min(dist[a][b], c);
			dist[b][a] = min(dist[b][a], c); 
		}

		priority_queue<state> Q;
		vi used(n);
		Q.push(state(0, 0));
		int ans = 0;
		while(!Q.empty()) {
			state st = Q.top();
			Q.pop();

			if(used[st.p]) {
				continue;
			}

			used[st.p] = 1;
			ans += st.c;

			REP(i, n) {
				if(dist[st.p][i] != INF && st.p != i) {
					Q.push(state(i, dist[st.p][i]));
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1264
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int a[100];

int main() {
  int n,m,x;
  cin >> n >> m >> x;
  int tm;
  rep(i, m){
    cin >> tm;
    a[tm]= 1;
  }
  int l = 0;
  rep(i,x){
    l += a[i];
  }
  int r = 0;
  for(int i = n -1; i > x; i--){
    r += a[i];
  }
  cout << min(l, r) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<int,int>t;
int n,a,s;
main(){
    cin>>n;
    while(cin>>a){
        s+=t[a]*-2+1;
        t[a]=!t[a];
    }
    cout<<s<<endl;
return 0;
}

Measured memory_bytes: 4992
import sys
sys.setrecursionlimit(10000)

nCr = {}
def combination(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = combination(n-1,r) + combination(n-1,r-1)
    return nCr[(n,r)]

N, K = map(int, input().split())
for i in range(1, K+1):
	if i <= N-K+1:
		A = combination(N-K+1, i)
		P = combination(K-1, i-1)
		B = A * P
		print(B % (10**9+7))
	else:
		print(0)

Measured memory_bytes: 166112
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define R(i,c,n) for(int i=c;i<n;i++)
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> flowers(n+1,0);
  r(i,n) cin >> flowers[i];
  n++;
  int begin = 0;
  int count = 0;
  bool flag = false;
  while(true){
      flag = false;
      for(int i=begin;i<n;i++){
          if(flowers[i]>0){
              flowers[i]--;
              flag = true;
          }else{
              if(flowers[begin]==0) begin ++;
              break;
          }
      }
      if(flag) count ++;
      if(begin >= n-1) break;
  }
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 998244353;
const int INF = 9e18;

signed main() {
    int N, M;
    cin >> N >> M;
    vector<list<int>> like(N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            int sport;
            cin >> sport;
            like[i].push_back(sport);
        }
    }
    int ans = INF;
    for (int i = 0; i < M; i++) {
        map<int, int> check;
        for (int j = 0; j < N; j++) {
            check[*like[j].begin()]++;
        }
        int sport = 0, count = -1;
        {
            auto itr = check.begin();
            while (itr != check.end()) {
                if (count < itr->second) {
                    count = itr->second;
                    sport = itr->first;
                }
                ++itr;
            }
        }
        ans = min(ans, count);
        for (int j = 0; j < N; j++) {
            auto itr = like[j].begin();
            while (itr != like[j].end()) {
                if ((*itr) == sport) {
                    like[j].erase(itr);
                    break;
                }
                ++itr;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3072
#include<stdio.h>
     
    int main()
    {
    	int a[3][3],n,b[10],i,j,k;
     
    	for(i=0;i<3;i++)
    		for(j=0;j<3;j++)
    			scanf("%d",&a[i][j]);
    	scanf("%d",&n);
    	for(i=0;i<n;i++)
    		scanf("%d",&b[i]);
    	for(i=0;i<3;i++)
    		for(j=0;j<3;j++)
    			for(k=0;k<n;k++)
    				if(a[i][j]==b[k])
    					a[i][j]+=100;
     
    	for(i=0;i<3;i++)
    		if((a[i][0]>100)&&(a[i][1]>100)&&(a[i][2]>100)){
    			printf("Yes\n");
    			return 0;
    		}
    	for(j=0;j<3;j++)
    		if((a[0][j]>100)&&(a[1][j]>100)&&(a[2][j]>100)){
    			printf("Yes\n");
    			return 0;
    		}
    	if((a[0][0]>100)&&(a[1][1]>100)&&(a[2][2]>100)){
    		printf("Yes\n");
    		return 0;
    	}	
    	else if((a[0][2]>100)&&(a[1][1]>100)&&(a[2][0]>100)){
    		printf("Yes\n");
    		return 0;
    	}
    	else
    		printf("No\n");
    	return 0;
    }

Measured memory_bytes: 128
/*----- || Hare Krishna || -----*/

/*  "WHY DO WE FALL, BRUCE?"  */

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define elif else if
#define pb push_back
#define pf push_front
#define PI 3.1415926535897932384
#define MOD 1000000007
using namespace std;

char alpha[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

string s;
ll t;
vector<ll> adj[200009];

ll dfsUtil(ll u, vector<bool> &visited){
	
	visited[u]=true;
	
	ll ans2=1;
	
	ll adds=0;
	
	for(auto child:adj[u]){
		if(!visited[child]){
			adds += dfsUtil(child,visited);
		}
	}
	return ans2+adds;
}

ll dfs(ll V){
	vector<bool> visited(V+1,false);
	ll ans=0;
	for(int i=1; i<=V; i++){
		if(!visited[i]){
			ll els = dfsUtil(i,visited);
			ans = max(ans, els);
		}
	}
	return ans;
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,m;
    cin >> n >> m;
    for(ll i=0; i<m; i++){
    	ll a,b;
    	cin >> a >> b;
    	adj[a].pb(b);
    	adj[b].pb(a);
	}
	cout << dfs(n);
}


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

ans = [0] * n

def prc(L):
    res = []
    for x in L:
        res.append(chr(ord('a') + x))
    print(''.join(res))

while 1:
    prc(ans)
    for i in range(n-1, 0, -1):
        temp = max(ans[:i])
        if ans[i] <= temp:
            ans[i] += 1
            for j in range(i+1, n):
                ans[j] = 0
            break
    else:
        break

Measured memory_bytes: 4404
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void) {

	int N;
	scanf("%d", &N);
	int A[100];
	int max = 1;
	int min = 1000000000;
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
		if (A[i] > max) max = A[i];
		if (A[i] < min) min = A[i];
	}
	
	printf("%d", abs(max-min));


	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

int main(){

	const int N_MAX = 14;
	int n,b,f,r,v;
	int num[5][4][11] = { { { 0 } } };


	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		num[b][f][r] = num[b][f][r] + v;
	}

	for (int i = 1; i < 5; i++){
		for (int j = 1; j < 4; j++){
			for (int k = 1; k < 11; k++){
				cout << " " << num[i][j][k];
			}
			cout << endl;
		}
		if (i != 4) cout << "####################" << endl;
	}


	return 0;
}

Measured memory_bytes: 1164
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

class UnionFindTree
{
private:
    int n;
    int groupNum;       // グループの数
    vector<int> parent; // 親ノード
    vector<int> rank;   // 木の高さの上限
    vector<int> num;    // グループの要素数
    int find(int i){
        if(parent[i] == i)
            return i;
        else
            return parent[i] = find(parent[i]);
    }
public:
    UnionFindTree(int n){ // コンストラクタ
        this->n = n;
        groupNum = n;
        parent.resize(n);
        for(int i=0; i<n; ++i)
            parent[i] = i;
        rank.assign(n, 0);
        num.assign(n, 1);
    }
    void unite(int a, int b){ // aとbのグループを併合
        if((a = find(a)) != (b = find(b))){
            if(rank[a] < rank[b]){
                parent[a] = b;
                num[b] += num[a];
            }
            else{
                parent[b] = a;
                if(rank[a] == rank[b])
                    ++ rank[a];
                num[a] += num[b];
            }
            -- groupNum;
        }
    }
    bool same(int a, int b){ // aとbのグループが同じかを調べる
        return find(a) == find(b);
    }
    int getNum(){ // グループの数を返す
        return groupNum;
    }
    int getNum(int a){ // aのグループの要素数を返す
        return num[find(a)];
    }
};

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

    UnionFindTree uft(n);
    for(int i=0; i<m; ++i){
        int a, b;
        cin >> a >> b;
        uft.unite(a-1, b-1);
    }

    long long x = min(uft.getNum(0), uft.getNum(1));
    long long y = n - x;
    long long ans = x * (x - 1) / 2 + y * (y - 1) / 2 - m;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
#define N 100000
int n, k;
double T[N];
int check(double P){
  int i = 0, j = 0;
  double s;
  for(j=0;j<k;j++){
    s = 0.0;
    while(s+T[i] <= P){
      s += T[i];
      i++;
      if(i == n) return n;
    }
  }
  return i;
}

int solve(){
  double left = 0.0;
  double right = 100000*10000;
  double mid;
  int v;
  while(right - left > 1){
    mid = (left+right) / 2;
    v = check(mid);
    if(v >= n) right = mid;
    else left = mid;
  }
  return right;
}

int main(){
  int i;
  double ans;
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++) scanf("%lf", &T[i]);
  ans = solve();
  printf("%d\n",(int)ans);  
  return 0;
}



Measured memory_bytes: 2636
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		int n = int.Parse(Console.ReadLine());
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
        var arr = new List<int>();
        foreach (var i in input)
        {
          arr.Add(int.Parse(i));
        }
      
        if (arr.Count < 1) {
          Console.WriteLine("Yes");
        } else {
          for (int i = arr.Count - 2; i != -1; i--)
          {
            if (arr[i] > arr[i+1]) arr[i]--;
            if (arr[i] > arr[i+1]) {Console.WriteLine("No"); return;}
          }
        }
      Console.WriteLine("Yes");
		
	}
}

Measured memory_bytes: 29404
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> x(n);
    for(int i = 0; i < n; i++) cin >> x[i];
    ll l; cin >> l;
    const ll LOG = 32;
    vector table(LOG+1, vector<ll>(n));
    ll right = 0;
    rep(i,0,n){
        while(right < n && x[right] <= x[i] + l){
            right++;
        }
        table[0][i] = right-1;
        if(i == right)right++;
    }
    debug(table[0]);
    rep(k,0,LOG){
        rep(i,0,n){
            table[k+1][i] = table[k][table[k][i]];
        }
    }

    auto c = [&](ll f, ll t, ll x){
        rrep(k,LOG,0){
            if((x >> k) & 1)f = table[k][f];
        }
        return f >= t;
    };
    ll q; cin >> q;
    rep(_,0,q){
        ll f,t; cin >> f >> t;
        f--;t--;
        if(!(f < t))swap(f, t);
        ll ng = 0, ok = 1e5+10;
        while(abs(ok - ng) > 1){
            ll x = (ok + ng) / 2;
            if(c(f, t, x))ok = x;
            else ng = x;
        }


        cout << ok << "\n";
    }
}

Measured memory_bytes: 30624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) throws Exception {
		MyScanner sc = new MyScanner();
		int t = sc.nextInt();
		double area = (2 * Math.PI * (double)t);
		System.out.println(area);
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}

Measured memory_bytes: 33112
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>

using namespace std;

#define INF 999999999

int main(){
	int N, M, g[21][21], x, y, i, j, k, l, c;
	string d;
	while(1){
		cin >> N;
		if(!N)break;
		for(j=0;j<21;j++){
			for(k=0;k<21;k++){
				g[j][k]=0;
			}
		}
		for(i=0;i<N;i++){
			cin >> x >> y;
			g[x][y] = 1;
		}
		cin >> M;
		x = 10;
		y = 10;
		c = 0;
		for(i=0;i<M;i++){
			cin >> d >> l;
			for(k=0;k<l;k++){
				if(d[0]=='N') y ++;
				else if(d[0]=='S') y --;
				else if(d[0]=='E') x ++;
				else if(d[0]=='W') x --;
				//cout << x << "," << y << endl;
				if(g[x][y]){
					g[x][y] = 0;
					c++;
				}
			}
		}
		if(c==N) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
	string S;
	string T;

	cin >> S;
	cin >> T;

	string alp = "abcdefghijklmnopqrstuvwxyz";

	for (int a=0; a<alp.size(); a++){
		vector<int> S_id;
		vector<int> T_id;
		for (int i=0; i<S.size(); i++){
			if (alp[a] == S[i]){
				S_id.push_back(i);
			}
		}

		if (S_id.size() == 0){
			continue;
		}

		char target = T[S_id[0]];
		for (int j=0; j<T.size(); j++){
			if (target == T[j]){
				T_id.push_back(j);
			}
		}

		//check
		if (S_id != T_id){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 1904
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
bool count(string s,int a,int b){
    int yay=0;
    for(char x:s)yay+=x-'0';
    if(yay<=b&&yay>=a)return true;
    return false;
}

int main(){
int n,a,b;cin>>n>>a>>b;
int ans=0;
for(int i=1;i<=n;i++){
    string s=to_string(i);
    if(count(s,a,b))ans+=i;
}

   cout<<ans; 
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#include<queue>
#include<stack>
#include<set>
#define MAX 1000000000000000000LL
long long inf=1000000007;
using namespace std;
int main(){
    int n,m; cin>>n>>m;
    int ro[1005];int we[1005];
    for(int i=1; i<=n;i++){
        cin>>ro[i];
    }
    for(int i=1; i<=m; i++){
        cin>>we[i];
    }
    long long  dp[1005][1005]={};
    for(int i=1; i<=n;i++){
        for(int j=i; j<=m; j++){
            if(i==j)dp[j][i]=dp[j-1][i-1]+ro[i]*we[j];
            else dp[j][i]=min(dp[j-1][i],dp[j-1][i-1]+ro[i]*we[j]);
        }
    }
    cout<<dp[m][n]<<endl;
    return 0;
}

Measured memory_bytes: 10972
from collections import defaultdict
from math import sqrt
def primeFactors(n):
    d = defaultdict(int)
    while n % 2 == 0:
        d[2] += 1
        n = n // 2
    for i in range(3,int(sqrt(n))+1,2):
        while n % i == 0:
            d[i] += 1
            n = n // i
    if n > 2:
        d[n] += 1

    return d

if __name__ == '__main__':
    N = int(input())
    ans = 0
    for i in range(3, N+1, 2):
        d = primeFactors(i)
        num_of_factor = 1
        for _, v in d.items():
            num_of_factor = num_of_factor * (v + 1)
        if num_of_factor == 8:
            ans += 1

    print(ans)


Measured memory_bytes: 3316
dice1 = [int(i) for i in input().split()]
dice2 = [int(i) for i in input().split()]

if dice2[0] == dice1[1]:
    dice1[0], dice1[1], dice1[4], dice1[5] = dice1[1], dice1[5], dice1[0], dice1[4]
elif dice2[0] == dice1[2]:
    dice1[0], dice1[2], dice1[3], dice1[5] = dice1[2], dice1[5], dice1[0], dice1[3]
elif dice2[0] == dice1[3]:
    dice1[0], dice1[2], dice1[3], dice1[5] = dice1[3], dice1[0], dice1[5], dice1[2]
elif dice2[0] == dice1[4]:
    dice1[0], dice1[1], dice1[4], dice1[5] = dice1[4], dice1[0], dice1[5], dice1[1]
elif dice2[0] == dice1[5]:
    dice1[0], dice1[1], dice1[4], dice1[5] = dice1[5], dice1[4], dice1[1], dice1[0]

while dice2[1] != dice1[1]:
    dice1[1], dice1[2], dice1[4], dice1[3] = dice1[3], dice1[1], dice1[2], dice1[4]
    
if dice1 == dice2:
    print('Yes')
else:
    print('No')



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

int main()
{
	string S;
  cin >> S;
  bool flag = false;
  
  for(int i = 0; i < S.size(); i++){
   if(i%2 == 0){
     if(S.at(i) == 'L'){
       cout << "No" << endl;
       return 0;
     }	else {
     }
   } else{
     if(S.at(i) == 'R'){
       cout << "No" << endl;
       return 0;
     } else {
     }
   }
  }    
  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	int N;
	string S,B;
	cin >> N >> S;
	vector<int> vec(N);
	if (S.at(0) == 'E') {
		vec.at(0) = 0;
	}
	else {
		vec.at(0) = 1;
	}
	for (int i = 1; i < N; i++) {
		if (S.at(i) == 'E') {
			vec.at(i) = vec.at(i - 1);
		}
		else {
			vec.at(i) = vec.at(i - 1)+1;
		}
	}
	int m = 500000;
	for (int i = 1; i < N-1; i++) {
		m = min(m, vec.at(i - 1) +(N-1-i)-( vec.at(N-1) - vec.at(i )));
	}
	m = min(m, min(vec.at(N - 2),(N-1)- (vec.at(N-1) - vec.at(0))));
		cout << m << endl;
}

Measured memory_bytes: 1796
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

//#define BIG_NUM 9999999999999

struct Info{
	Info(){
		row = col = move_cost = sum_cost = 0;
	}

	Info(int arg_row,int arg_col,ll arg_move_cost,ll arg_sum_cost){
		row = arg_row;
		col = arg_col;
		move_cost = arg_move_cost;
		sum_cost = arg_sum_cost;
	}
	bool operator<(const struct Info &arg) const{
		return sum_cost > arg.sum_cost;
	}
	int row,col;
	ll move_cost,sum_cost;
};

int H,W;
int diff_row[4] = {-1,0,0,1},diff_col[4] = {0,-1,1,0};
ll min_cost[30][30][901],base_map[30][30];


bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1){
		return true;
	}else{
		return false;
	}
}


int main(){

	scanf("%d %d",&H,&W);

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++)scanf("%lld",&base_map[row][col]);
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			for(int i = 0; i <= H*W; i++)min_cost[row][col][i] = BIG_NUM;
		}
	}

	priority_queue<Info> Q;
	min_cost[0][0][0] = 0;
	Q.push(Info(0,0,0,0));

	int adj_row,adj_col,next_move_cost,next_sum_cost;
	ll ans = BIG_NUM;

	Info info;

	while(!Q.empty()){

		if(Q.top().row == H-1 && Q.top().col == W-1){
			ans = min(ans,Q.top().sum_cost);
			Q.pop();
		}else if(Q.top().sum_cost > min_cost[Q.top().row][Q.top().col][Q.top().move_cost]){
			Q.pop();
		}else if(Q.top().move_cost == H*W+1){
			Q.pop();
		}else{

			info = Q.top();
			Q.pop();

			for(int i = 0; i < 4; i++){
				adj_row = info.row+diff_row[i];
				adj_col = info.col+diff_col[i];

				if(!rangeCheck(adj_row,adj_col))continue;

				next_move_cost = info.move_cost+1;
				next_sum_cost = info.sum_cost+(base_map[adj_row][adj_col]*(2*info.move_cost+1))+1;

				if(adj_row == H-1 && adj_col == W-1){
					next_sum_cost -= info.move_cost+1;
				}

				if(min_cost[adj_row][adj_col][next_move_cost] > next_sum_cost){
					min_cost[adj_row][adj_col][next_move_cost] = next_sum_cost;
					Q.push(Info(adj_row,adj_col,next_move_cost,next_sum_cost));
				}
			}
		}
	}

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

	return 0;
}



Measured memory_bytes: 15312
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()

def check(cost):
    if cost == n:
        return 1
    if cost > n:
        return 0

    return check(cost+4) or check(cost+7)

if check(0) == 1:
    print('Yes')
else:
    print('No')

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

using namespace std;

#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define f(n) for(int i=0;i<n;++i)
#define f2(n) for(int j=0;j<n;++j)
#define f3(n) for(int k=0;k<n;++k)
#define F(i,x,n,y) for(i=x;i<n;i+=1)
#define fi(i) for(i=0;i<n;++i)
#define fa(x,y) for(auto x:y)

//Warsaw debug template
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1,debug&>::type operator<<(c i){
sim > struct rge {c b,e;};
sim > rge<c> range(c i, c j) {return rge<c>{i,j};}
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug{
#ifdef LOCAL
~debug() {cerr<<endl; }
eni(!=) cerr<< boolalpha << i; ris;}
eni(==) ris <<range(begin(i),end(i)); }
sim, class b dor(pair<b,c> d){
ris<<"("<<d.first<<","<<d.second<<")";
}
sim dor(rge<c> d){
    *this << "[";
    for(auto it=d.b;it!=d.e;++it)
        *this <<"," +(it==d.b)<< *it;
    ris<<"]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) "["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"
//End of debug template        
    

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


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int d,n;
    cin>>d>>n;
    int p=1;
    f(d) p*=100;
    if(n!=100) cout<<p*n;
    else cout<<p*n+p;
    cout<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(hoge) hoge.begin(),hoge.end()
const long long INF = 1LL << 60;


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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {//降順second
	if (a.second != b.second) {
		return a.second > b.second;
	}
	else {
		return a.first > b.first;
	}
}

bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {//降順first
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second > b.second;
	}
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd


int main() {
	ll x, y;
	cin >> x >> y;
	ll cnt = 0;
	while (x <= y) {
		cnt++;
		x *= 2;
	}
	cout << cnt;
	return 0;
}


Measured memory_bytes: 256