akhauriyash/Code-Regression huggingface dataset:
/*
 * @Author: hesorchen
 * @Date: 2020-07-03 17:05:01
 * @LastEditTime: 2020-09-04 19:03:07
 * @Description: https://hesorchen.github.io/
 */
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <vector>
#include <bitset>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define endl '\n'
#define PI acos(-1)
#define PB push_back
#define ll long long
#define INF 0x3f3f3f3f
#define mod 1000000007
#define pll pair<ll, ll>
#define lowbit(abcd) (abcd & (-abcd))
#define max(a, b) ((a > b) ? (a) : (b))
#define min(a, b) ((a < b) ? (a) : (b))

#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define FRE                              \
    {                                    \
        freopen("in.txt", "r", stdin);   \
        freopen("out.txt", "w", stdout); \
    }

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

int main()
{
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    printf("%d", (x - z) / (y + z));

    return 0;
}

Measured memory_bytes: 3228
using System;

namespace ALDS1_6_A
{
    class Program
    {
        

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] array = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] A = new int[n + 1];
            int[] B = new int[n];
            int Max = int.MinValue;
            for (int i = 1; i < n + 1; i++)
            {
                A[i] = array[i - 1];
                if (Max < A[i]) Max = A[i];

            }
            CountingSort(A, B, Max, n);
        }


        static void CountingSort(int[] A, int[] B, int k, int n)
        {
            int[] C = new int[k + 1];
            for (int i = 0; i < k + 1; i++)
            {
                C[i] = 0;
            }

            // C[i]にiの出現数を記録する A配列は便宜上1オリジン　
            for (int j = 1; j <= n; j++)
            {
                C[A[j]]++;
            }

            // C[i]にi以下の数(の総和)を記録する 
            for (int i = 1; i <= k; i++)
            {
                C[i] = C[i] + C[i - 1];
            }

            for (int j = n; j >= 1; j--)
            {
                B[C[A[j]] - 1] = A[j];
                C[A[j]]--;
            }
            Console.WriteLine(string.Join(" ", Array.ConvertAll(B, b => b.ToString())));

        }
    }
}



Measured memory_bytes: 273160
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)

typedef long long ll;


using namespace std;


int main(){
    int a,b;
    cin>>a>>b;
    if(a>b){cout<<"a"<<" > "<<"b"<<endl;}
    else if(a<b){cout<<"a"<<" < "<<"b"<<endl;}
    else{cout<<"a"<<" == "<<"b"<<endl;}


    return 0;
};

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define per(i,n) for (int i = (n)-1; i >=0; --i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int n;
    cin>>n;
    set<int> d;
    int c;
    rep(i,n){
        cin>>c;
        d.insert(c);
    }
    cout << d.size() << endl;
    return 0;
}

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

using namespace std;
const int MAXN = 500010;
int _w;

int n, a[MAXN];
char s[MAXN];

void update( int &a, int b ) {
	a = max(a, b);
}

int b[MAXN], sz;
int f[MAXN][3];
int solve( int L, int R ) {
	sz = 0, b[sz] = 0;
	for( int i = L; i <= R; ++i )
		if( a[i] ) ++b[sz];
		else ++sz, b[sz] = 0;
	++sz;
	/*
	printf( "L = %d, R = %d, sz = %d\n", L, R, sz );
	for( int i = 0; i < sz; ++i )
		printf( "%d ", b[i] );
	puts("");
	//*/
	for( int i = 0; i <= sz; ++i )
		for( int j = 0; j <= 2; ++j )
			f[i][j] = -1;
	f[0][0] = 0;
	for( int i = 0; i < sz; ++i ) {
		if( f[i][0] != -1 ) {
			update( f[i+1][0], f[i][0] );
			update( f[i+1][1], f[i][0] );
			update( f[i+1][2], f[i][0] + b[i] );
		}
		if( f[i][1] != -1 ) {
			update( f[i+1][0], f[i][1] + b[i] );
			update( f[i+1][1], f[i][1] + b[i] - 1 );
		}
		if( f[i][2] != -1 ) {
			update( f[i+1][0], f[i][2] );
			if( b[i] > 1 )
				update( f[i+1][1], f[i][2] );
			update( f[i+1][2], f[i][2] + b[i] - 1 );
		}
	}
	// printf( "ans = %d\n\n", max( f[sz][0], f[sz][1] ) );
	return max( f[sz][0], f[sz][1] );
}

int main() {
	_w = scanf( "%d%s", &n, s );
	for( int i = 0; i < n; ++i )
		a[i] = s[i] - '0';
	int ans = 0;
	for( int L = 0; L < n; ++L ) {
		if( !a[L] ) continue;
		for( int R = L; R < n; ++R )
			if( !a[R+1] && !a[R+2] ) {
				ans += solve(L, R);
				L = R+1;
				break;
			}
	}
	printf( "%d\n", ans );
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  int b[110];
  rep(i,n-1)
  cin >> b[i];
  int ans=b[0]+b[n-2];
  for(int i=1;i<n-1;i++)
  ans+=min(b[i],b[i-1]);
  cout << ans << endl; 
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  int sum = 0;
  rep(i, m) {
    int a;
    cin >> a;
    sum += a;
  }
  if (n >= sum)
    cout << n - sum << endl;
  else
    cout << -1 << endl;
  return 0;
}


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

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

    int count = 1;
    for (int i = 1; i < N; i++) {
        bool flag = true;
        for (int j = 0; j < i; j++) {
            if (mount[i] < mount[j]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define thekingisborn ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ld  long double
#define f first
#define se second
#define pb push_back
#define maxn 200005
#define mod 1000000007
#define pi 3.14159265359

using namespace std;

typedef pair<int,int>pii;
typedef pair<ll,ll>pll;

/*ll power(ll a,ll n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    a = a%mod;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n>>1))%mod)%mod;
    return power((a*a)%mod,n>>1)%mod;
}
ll gcd(ll a,ll b)
{
    if(a%b == 0)return b;
    return gcd(b,a%b);
}*/
/*int root(int x)
{
    while(par[x] != x)
    x = par[x];
    return x;
}
void dsu(int x,int y)
{
  if(root(x) == root(y))return;
  par[root(y)] = root(x);
  return;
}
void dfs(int x)
{
    done[x] = true;
    for(int i=0;i<int(adj[x].size());++i)
    {
        int y = adj[x][i];
        if(!done1[y])
        dfs(y);
    }
}*/
int n,ans;
vector<int>v(105);

int main()
{
    thekingisborn;
    cin >> n;
    for(int i=0;i<n;++i)
    cin >> v[i];
    int i=0;
    while(i<n)
    {
        int cnt=1;
        while(i<n && v[i] == v[i+1])
        ++i,++cnt;
        ++i;
        ans += cnt/2;
    }
    cout << ans;
    return 0;
}


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

int main(void)
{
    long long int H, N;
    cin >> H >> N;
     vector<long long int >A(N);
    int count = 0;

    
    for (long long int& a : A)
    {
        cin >> a;
        H -= a;
    }

    if (H <= 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

}

    

Measured memory_bytes: 1024
h, w = map(int, input().split())

A = []
for i in range(h):
    s = list(input())
    if '#' in s:
        A.append(s)

h2 = len(A)
for j in range(w - 1, -1, -1):
    for i in range(h2):
        if A[i][j] == '#':
            break
        elif i == h2 - 1:
            for k in range(h2):
                del A[k][j]
            
for a in A:
    print(''.join(a))

Measured memory_bytes: 3064
def main(N,Y):
    for i in range(N+1):
        for j in range(N+1-i):
            k = N - i - j
            if 10000*i +5000*j + 1000*k == Y:
                return i, j, k
    else:
        return -1, -1, -1

N,Y = map(int, input().split())
print(*main(N,Y))

Measured memory_bytes: 3060
namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length === 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public async getNumbers(): Promise<number[]> {
      return (await this.getLine()).split(' ').map((x) => +x);
    }

    public async getStrings(): Promise<string[]> {
      return (await this.getLine()).split(' ');
    }

    public close(): void {
      process.stdin.pause();
    }
  }

  async function solve() {
    const sc = new Scanner();
    const [H, W]: number[] = await sc.getNumbers();
    const [h, w]: number[] = await sc.getNumbers();

    console.log((H - h) * (W - w));
    sc.close();
  }

  solve();
}


Measured memory_bytes: 11596
#標準入力を高速に
import sys
input = sys.stdin.readline

def factorial_mod(x, y, mod):
    factorial = 1
    for i in range(x,y+1):
        factorial *= i
        factorial %= mod
    return factorial
  
def n_C_k(n, k, mod, fact):
    inv = (pow(fact[n-k], mod-2, mod) * pow(fact[k], mod-2, mod)) % mod
    return (fact[n] * inv) % mod

"""
#main関数(若干早くなる)
def main():
    mod = 10**9+7
    n, k = map(int, input().split())         
    ans = 1+n*(n-1)

    a = n
    b = n-1

    for i in range(1, min(n, k)):
        temp1 = (n-i)*pow(i+1, mod-2, mod)%mod
        a *= temp1
        a %= mod
        temp2 = (n-1-i)*pow(i+1, mod-2, mod)%mod
        b *= temp2
        b %= mod
        temp3 = a*b%mod
        ans += temp3
        ans %= mod

    print(ans)
"""


#main関数(若干早くなる)
def main():
    mod = 10**9+7
    n, k = map(int, input().split())
    ans = (1+n*(n-1))%mod

    #階乗を使いまわすver.
    fact = [1]*(n+1)
    for i in range(1, n+1):
        fact[i] = fact[i-1]*i
        fact[i] %= mod

    for i in range(2, min(n-1, k)+1):
        ans += n_C_k(n, i, mod, fact)*n_C_k(n-1, i, mod, fact)
        ans %= mod

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 43100
a=int(input())
b,c=map(int,input().split())
d=[int(i) for i in input().split()]
e=f=999
g=0
for i in range(a):
    f=e
    e=min(e,abs(c-b+d[i]*0.006))
    if f!=e:
        g=i
print(g+1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
#include<cmath>
#include<string>
#include<iomanip>
#include <numeric>
#include <limits>
using namespace std;
 
int main()
{
int a,b,c; cin>>a>>b>>c;
if((a+b+c)==17)
{
    if(a==7||b==7||c==7)
        if(a==5||b==5||c==5)
         cout<<"YES";
         else cout<<"NO"; 
    else cout<<"NO";
}
else cout<<"NO";
return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

bool primes[int(1e5)+1];
void sieve()
{
	primes[0]=primes[1]= 0;
	for(int i = 2; i<=sqrt(int(1e5)+1); i++)
		if(primes[i])
			for(ll j = i*i; j<=int(1e5); j+=i)
				primes[j]= 0;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	memset(primes,1,int(1e5)+1);
	ll n, f= INT_MAX;
	cin>>n;
	for(int i = 1;i <= int(1e5); i++)
	{
		if(primes[i] && n%i==0)
		{
			ll h = n/i;
			ll t = log10(h)+1, k = log10(i)+1;
			t = max(t,k);
			if(t<f)
				f = t;
		}
	}
	cout<<f<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int,Int> pii;
typedef pair<Int,double> pid;
typedef pair<double,double> pdd;
typedef pair<Int,pii> pip;
typedef pair<double,Int> pdp;
#define A first
#define B second
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define Itype(a) typeof(a.begin()) 
#define REP(i,a,b) for(int i = (a);i <= (b);i++)
#define FORO(i,n) REP(i,0,(int)n-1)
#define FORI(i,n) REP(i,1,(int)n)
#define FORIT(i,t) for(Itype(t) i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a,_b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
template<typename T>void getMin(T &a,T b) { if(a > b) a = b; }
template<typename T>void getMax(T &a,T b) { if(a < b) a = b; }
const int MOD = 1000000007;

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

    int N;
    cin >> N;
    vector<string> vs(N);
    int ans = 0;
    int nA = 0;
    int nB = 0;
    int nBA = 0;
    FORO(i, N) {
        cin >> vs[i];
        for(int j = 0;j < SZ(vs[i]) - 1;j++) {
            if(vs[i][j] == 'A' && vs[i][j + 1] == 'B') ans++;
        }
        if(vs[i][0] == 'B' && vs[i][SZ(vs[i]) - 1] == 'A') {
            nBA++;
        } else if(vs[i][0] == 'B') {
            nB++;
        } else if(vs[i][SZ(vs[i]) - 1] == 'A') {
            nA++;
        }
    }

    if(nBA > 0) {
        ans += nBA - 1;
        if(nA > 0) { ans++; nA--; }
        if(nB > 0) { ans++; nB--; }
    }
    ans += min(nA, nB);

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

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

int main(){
  int num=0;
  string S;
  cin >> S;
  for(int i=0; i<4; i++){
    if(S.at(i)=='+') num++;
    if(S.at(i)=='-') num--;
  }
  cout << num << endl;
}

Measured memory_bytes: 256
//C - Welcome to AtCoder

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <functional>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()

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

const double PI = 3.14159265358979323846;

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

int main()
{
    int n, m;

    cin >> n >> m;

    int p[m];
    string s[m];

    REP(i, m) cin >> p[i] >> s[i];

    int ac = 0;
    int wa = 0;
    vector<int> wap(n, 0);
    vector<bool> f(n, false);

    REP(i, m){
        if (s[i] == "AC"){
            if (f[p[i]-1] == false){
                ac++;
                f[p[i]-1] = true;
            }
        } else {
            if (f[p[i]-1] == false){
                wap[p[i]-1]++;
            }
        }
    }

    REP(i, n){
        if (f[i]) wa+=wap[i];
    }

    cout << ac << " " << wa << endl;

    return 0;
}


Measured memory_bytes: 6528
module Main where

import Data.Functor

main :: IO ()
main = do
  { [a,b] <- getInts
  ; let result = hikaku (a,b)
  ; putStrLn result
  }

hikaku :: (Int, Int) -> String
hikaku (x,y)
  | x < y = "a < b"
  | x == y = "a == b"
  | x > y = "a > b"

getInts :: IO [Int]
getInts = map read . words <$> getLine

Measured memory_bytes: 3688
#include<stdio.h>
#include<string.h>
int main() {
	int cnt=0;
	int ans=0;
	int i;
	char s[11];
	scanf("%s", s);
	for (i = 0; i < 11; i++) {
		if (s[i] == 'A' ||s[i]== 'T' ||s[i]== 'C' ||s[i]== 'G') {
			cnt++;
		}
		else if(ans<cnt){
			ans = cnt;
			cnt = 0;

		}
	}
	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <map>

int main(){
	std::map<int, int> m;
	m[1] = 0;
	m[2] = 2;
	m[3] = 0;
	m[4] = 1;
	m[5] = 0;
	m[6] = 1;
	m[7] = 0;
	m[8] = 0;
	m[9] = 1;
	m[10] = 0;
	m[11] = 1;
	m[12] = 0;
	int x, y;
	scanf("%d%d", &x, &y);
	if(m[x] == m[y]) printf("Yes\n");
	else printf("No\n");
}

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

int main(){
    string s;
    cin>>s;
    if(s=="SSS"){
        cout<<0<<endl;
        return 0;}
    vector<string> v;
    v.push_back("RRR");
    v.push_back("SRR");
    v.push_back("RRS");
    v.push_back("SRS");
    v.push_back("RSR");
    v.push_back("SSR");
    v.push_back("RSS");
    vector<string>::iterator it;
    it=find(v.begin(),v.end(),s);
    if(*it=="RRR")
        cout<<3<<endl;
    else if(*it=="SRS"||*it=="RSR"||*it=="SSR"||*it=="RSS")
        cout<<1;
    else
        cout<<2;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

template <int mod>
struct ModInt {
  int x;
  ModInt(): x(0) {}
  ModInt(long long a) { x = a % mod; if (x < 0) x += mod; }
  ModInt &operator+=(ModInt that) { x = (x + that.x) % mod; return *this; }
  ModInt &operator-=(ModInt that) { x = (x + mod - that.x) % mod; return *this; }
  ModInt &operator*=(ModInt that) { x = (long long) x * that.x % mod; return *this; }
  ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
  ModInt inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return ModInt(u);
  }
  #define op(o, p) ModInt operator o(ModInt that) { return ModInt(*this) p that; }
    op(+, +=) op(-, -=) op(*, *=) op(/, /=)
  #undef op
  friend ostream& operator<<(ostream &os, ModInt m) { return os << m.x; }
};

using mint = ModInt<1000000007>;

void solve() {
  int n, k;
  cin >> n >> k;
  vi32 a(n);
  cin >> a;
  vi32 c(n), d(n);
  rep(i, n) rep(j, n) {
    if (i == j) continue;
    if (i < j && a[i] > a[j]) c[i]++;
    if (i > j && a[i] > a[j]) d[i]++;
  }
  mint ans = 0;
  rep(i, n) {
    ans += (mint) k * (k + 1) * c[i] / 2;
    ans += (mint) k * (k - 1) * d[i] / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    if(a*n>b){
        cout<<b<<endl;
    }else{
        cout<<a*n<<endl;
    }
}

Measured memory_bytes: 3592
n=int(input())
t,a=list(map(int,input().split()))
h=list(map(int,input().split()))
imin=100000
suf=0
for i in range(n):
  h[i]=t- h[i]*0.006
  if a>=h[i]:
    if imin>a-h[i]:
      #print("!!",a-h[i],h[i],i)
      imin=abs(a- h[i])
      suf=i
  else:
    if imin>h[i]-a:
      #print("!!",a-h[i],h[i],i)
      imin=abs( h[i]-a)
      suf=i 
print(suf+1)

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

int tax (int tax, int num){
  return num * (100 + tax) /100;
}


int main(){
  int X;
  int Y;
  int S;

  while(cin >> X >> Y >>S && X>0){

  int maximum = 0;

  for (int i=1; i<S; ++i){
    for (int j=i; j<S; ++j){
      if (tax(X,i)+tax(X,j) == S) maximum = max(maximum, tax(Y,i)+tax(Y,j));
      }
    }
    cout << maximum << endl;
  }
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = 50;
const int mod = (int)1e9 + 7;

int n, x, y, z;

void read()
{
	cin >> n >> x >> y >> z;
}

/*
   map<uint64_t, int> dp[2][MAXN];

   bool is_ok(list<int> &p)
   {
   int sum = 0, c = 0;
   for(auto it: p)
   {
   sum += it;
   if(c == 0 && sum > x) return false;
   if(c == 0 && sum == x) c++, sum = 0;
   if(c == 1 && sum > y) return false;
   if(c == 1 && sum == y) c++, sum = 0;
   if(c == 2 && sum > z) return false;
   if(c == 2 && sum == z) c++, sum = 0;
   }

   return c == 3;
   }

   uint64_t get_hash(list<int> &l) 
   {
   uint64_t ret = 0;
   for(int x: l)
   ret = ret * 11ull + x + 1;
   return ret;
   }

   int pw10[MAXN];
   set<int> lol;

   int rec(int l, list<int> lst, int has, int s = 0)
   {
   if(l == n) return has == 1;
   if(has) return pw10[n - l];

   uint64_t H = get_hash(lst);
   lol.insert(H);

   if(dp[has][l].count(H)) return dp[has][l][H];

   int &memo = dp[has][l][H];
   memo = 0;

   for(int d = 1; d <= 10; d++)
   {
   list<int> nw = lst;
   int ns = s + d;

   nw.push_back(d);

   while(ns > (x + y + z))
   {
   ns -= nw.front();
   nw.pop_front();
   }

   int nw_has = has;
   if(ns == (x + y + z) && !has) nw_has |= is_ok(nw);
   memo = (memo + rec(l + 1, nw, nw_has, ns));
   if(memo >= mod) memo -= mod;
   }	

   return memo;
   }*/

int dp[MAXN][1 << 17][2];

bool is_ok(int mask) 
{
	if(!((mask >> (z - 1)) & 1)) return false;
	if(!((mask >> (z + y - 1)) & 1)) return false;
	if(!((mask >> (x + y + z - 1)) & 1)) return false;
	return true;
}

int rec(int pos, int mask, int has)
{
	has |= is_ok(mask);
	if(pos == n) { return has == 1; }

	int &memo = dp[pos][mask][has];
	if(memo != -1) return memo;

	memo = 0;
	for(int d = 1; d <= 10; d++)
	{
		int n_mask = ((mask << 1) | 1) << (d - 1);
		n_mask &= (1 << 17) - 1;
	
		memo = (memo + rec(pos + 1, n_mask, has | is_ok(n_mask)));
		if(memo >= mod) memo -= mod;
	}

	return memo;
}

void solve()
{
	memset(dp, -1, sizeof(dp));
	cout << rec(0, 0, 0) << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 51584
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {
	int n;

	cin >> n;
	vector<int> a(n);

	long long sum = 0;
	int average;

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

	average = nearbyint(static_cast<double>(sum)/static_cast<double>(n));
	sum = 0;

	for(int i = 0; i < n; i++)
		sum += (average-a[i])*(average-a[i]);
	cout << sum << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {

        void solve(InputReader in, PrintWriter out) {
            int H = in.nextInt();
            int A = in.nextInt();
            out.println(H % A == 0 ? H / A : H / A + 1);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

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

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}


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

// マクロ //
#define rep(i,N) for(int i = 0; i < (int)(N); i++)
#define req(i,f,N) for(int i = f; i < (int)(N); i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using plili = pair<lint, lint>;
using vplili = vector<plili>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;


// 関数 //
template<class T, class Q> lint gcd_(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T, class Q> lint lcm_(T a, Q b) {
    return a * b / gcd_(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

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

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);


// キーワード //
#define elif else if

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
        
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    string S;
    cin >> S;
    int sharp = 0;
    int dot = 0;
    bool flag = false;
    bool change = D < C ? true : false;
    req(i, A - 1, S.size()) {
        if (S[i] == '#') dot = 0, sharp++;
        else {
            sharp = 0, dot++;
        }
        if (sharp == 2 && i < max(C, D)) {
            n(); exit(0);
        }
        elif (dot >= 3 && i <= min(C, D) && i >= B) flag = true;
        if (i == D && change && !flag) {
            n(); exit(0);
        }
    }
    if (change && !flag) n();
    else y();

}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long long ll;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 2000000009
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll i,n,m;cin>>n;vll d(n);
  for(i=0;i<n;i++){cin>>d[i];}
  cin>>m;vll t(m);
  for(i=0;i<m;i++){cin>>t[i];}
  //caricurate
  vsort(d);vsort(t);
  map<ll,ll> cnt;ll ex;
  for(i=0;i<m;i++){
    ex=1;
    while((i<m)&&(t[i]==t[i+1])){i++;ex++;}
    cnt[t[i]]=ex;
  }
  bool ans=true;ll j=0;
  for(i=0;i<n;i++){
    if(t[j]==d[i]){
    ex=1;
    while((i<n)&&(d[i]==d[i+1])){i++;ex++;}
    if(cnt[t[j]]>ex){ans=false;}
    while((j<m)&&(t[j]==t[j+1])){j++;}
    j++;
    }
  }
  //output
  if(ans&&(t[j-1]==t[m-1])){cout<<"YES"<<endl;return 0;}
  cout<<"NO"<<endl;
}

Measured memory_bytes: 15872
#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	f(int n)
{
	if (n % 2 == 0)
		return (n / 2);
	else
		return (3 * n + 1);
}

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

	int s;
	cin >> s;
	bitset<1000002> bs;
	int i = 1;
	while (1)
	{
		if (!bs.test(s))
		{
			bs.set(s);
			s = f(s);
			i++;
		}
		else
		{
			cout << i << endl;
			return (0);
		}
	}
}


Measured memory_bytes: 384
// AOJ CGL_1_B Reflection
// 2018.5.2 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct { double x, y; } PP;
typedef struct { PP s, e; } SEG, LINE;

#define INF			1e8
#define EPS			1e-8
#define EQ(a,b)		(fabs((a)-(b))<EPS)
#define PPeQ(a,b)	(EQ(a.x,b.x)&&EQ(a.y,b.y))

int dcmp(double x) { if (fabs(x) < EPS) return 0; return x <= 0 ? -1 : 1; }
PP vset(double x, double y) { PP r; r.x = x, r.y = y; return r; }
PP vadd(PP p1, PP p2) { PP r; r.x = p1.x + p2.x, r.y = p1.y + p2.y; return r; }
PP vsub(PP p1, PP p2) { PP r; r.x = p1.x - p2.x, r.y = p1.y - p2.y; return r; }
PP vsmul(PP p, double k) { PP r; r.x = p.x * k, r.y = p.y * k; return r; }
PP vmul(PP p1, PP p2) { PP r;
	r.x = p1.x * p2.x - p1.y * p2.y, r.y = p1.x * p2.y + p1.y * p2.x; return r; }
double vabs(PP a) { return hypot(a.x, a.y); }
double dist(PP p1, PP p2) {	return hypot(p1.x-p2.x, p1.y-p2.y); };
double cross(PP a, PP b) { return a.x * b.y - a.y * b.x; }
double dot(PP a, PP b) { return a.x * b.x + a.y * b.y; }
double norm(PP a) { return a.x * a.x + a.y * a.y; }

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

PP projection(PP p1, PP p2, PP p)
{
	PP p2p1 = vsub(p2, p1);
	PP pp1 = vsub(p, p1);
	return vadd(p1, vsmul(p2p1, dot(pp1, p2p1)/norm(p2p1)));
}

PP reflection(PP p1, PP p2, PP p)
{
	PP pp = projection(p1, p2, p);
	return vadd(p, vsmul(vsub(pp, p), 2));
}

int main()
{
	int q, x, y;
	PP p1, p2, p, ans;

	x = in(), y = in(), p1 = vset(x, y);
	x = in(), y = in(), p2 = vset(x, y);

	q = in(); while (q--) {
		x = in(), y = in(), p = vset(x, y);
		ans = reflection(p1, p2, p);
		printf("%.10lf %.10lf\n", ans.x, ans.y);
	}
	return 0;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define ll long long
#define oo 1000000010
using namespace std;

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

	ll x = min(n, b-1);

	cout << floor((a*x)/b) - a*floor(x/b);

    return 0;
}


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

string a,b;
int main()
{
	cin>>a>>b;
	int c=0;
	a=a+b;
	for(int i=0;i<a.size();i++)
		c=c*10+a[i]-'0';
	if(int(sqrt(c))==sqrt(c)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import math
while True:
    n = int(input())
    scores = [int(input()) for i in range(n)]
    scores.sort()
    
    if n == 0:
        break
    total = 0
    
    for i in range(1, n - 1):
        total += scores[i]
        
    print(math.floor(total / (n - 2)))


Measured memory_bytes: 5664
N=int(input())
G=N//15
E=N%15
P=60*G*G
if E==0:
  k=0
elif E<=1:
  k=1+15*G
elif E<=3:
  k=3+30*G
elif E<=6:
  k=7+45*G
elif E<=7:
  k=14+60*G
elif E<=10:
  k=22+75*G
elif E<=12:
  k=33+90*G
elif E<=13:
  k=46+105*G
elif E<=14:
  k=60+120*G

print(P+k)

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] name = new long[5];
		long count = 0;
		for (int i=0; i<N; i++){
			char ini = sc.next().charAt(0);
			if (ini=='M'){
				name[0]++;				
			}else if (ini=='A'){
				name[1]++;				
			}else if (ini=='R'){
				name[2]++;				
			}else if (ini=='C'){
				name[3]++;	
			}else if (ini=='H'){
				name[4]++;
			}
		}
		for (int i = 0; i < name.length; i++) {
			for (int j = i + 1; j < name.length; j++) {
				for (int k = j + 1; k < name.length; k++) {
					count += name[i] * name[j] * name[k];
				}
			}
		}
		System.out.println(count);
		
	}

}

Measured memory_bytes: 59004
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    string S, T;
    cin >> S;
    cin >> T;

    int output = T.length();
    for (int i = 0; i < S.length() - T.length() + 1; i++) {
        int tmp = 0;
        for (int j = 0; j < T.length(); j++) {
            if (S[i + j] != T[j]) {
                tmp++;
            }
        }
        if (tmp < output) output = tmp;
    }

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
 
using ll = long long;
using pll = pair<ll,ll>;
const ll INF = 1ll<<60;
 
void chmax (pll &a, pll b) {
    if (a.first < b.first) {
        a.second = max(a.first, b.second);
        a.first = b.first;
    }
    else a.second = max(a.second, b.first);
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n; scanf("%d", &n);
    vector<ll> a(1<<n);
    vector<pll> dp(1<<n);
    rep(i,1<<n) {
        scanf("%lld", &a[i]);
        dp[i] = pll(a[i], -INF);
    }
 
    // 高速ゼータ変換
    rep(j,n) rep(i,1<<n) if (i & 1<<j) chmax(dp[i], dp[i^(1<<j)]);
 
    ll ans = -INF;
    rep(i,1<<n) {
        ans = max(ans, dp[i].first + dp[i].second);
        if (i) printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 9488
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
  long long N;
  scanf("%lld\n",&N);
  char ch;
  int c[N];
  int num_l[4]={0,0,0,0};
  int num_r[4]={0,0,0,0};
  for(int i=0;i<N;i++){
    scanf("%c",&ch);
    if(ch=='R')c[i]=0;
    else if(ch=='G')c[i]=1;
    else c[i]=3;
    num_r[c[i]]++;
  }
  long long ans=0;
  int RGB=4;
  for(int i=0;i<N;i++){
    num_r[c[i]]--;
    if     (c[i]==0)ans+=num_l[1]*num_r[3]+num_l[3]*num_r[1];
    else if(c[i]==1)ans+=num_l[0]*num_r[3]+num_l[3]*num_r[0];
    else if(c[i]==3)ans+=num_l[0]*num_r[1]+num_l[1]*num_r[0];
    for(int t=0;;t++){
      if(i-t<0)break;
      if(i+t>=N)break;
      if(c[i]+c[i-t]+c[i+t]==RGB)ans--;
    }
    num_l[c[i]]++;
  }
  printf("%lld",ans);
  return 0;
}



Measured memory_bytes: 3824
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)

class Cube{
    public:
    char f[6];
    Cube(){}
    void roll_z(){ roll(1, 2, 4, 3);}
    void roll_y(){ roll(0, 2, 5, 3);}
    void roll_x(){ roll(0, 1, 5, 4);}
    void roll(int i, int j, int k, int l){
	char t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
    }
};

Cube C[8], D[8];
bool U[8];

bool invalid(char c1, char c2){
    return !( max(c1, c2) - min(c1, c2 ) == 32 );
}

bool rec( int p ){
    if ( p == 8 ) return true;
    rep(a, 8){
	if ( U[a] ) continue;
	Cube c = C[a];
	U[a] = true;
	for ( int i = 0; i < 6; i++, (i%2)?c.roll_x():c.roll_y()){
	    for ( int j = 0; j < 4; j++, c.roll_z()){
		D[p] = c;
		if ( p % 2 && invalid(D[p-1].f[2], D[p].f[3])) continue;
		if ( p > 3 && invalid(D[p-4].f[4], D[p].f[1])) continue;
		if ( p%4 > 1 && invalid(D[p-2].f[5], D[p].f[0])) continue;
		if ( rec(p+1) ) return true;
	    }
	}
	U[a] = false;
    }
    return false;
}

main(){
    string str;
    while( cin >> str && str != "0" ) {
	rep(s, 6) C[0].f[s] = str[s];
	for ( int i= 1; i < 8; i++ ) { cin >> str; rep(s, 6) C[i].f[s] = str[s]; };
	rep(i, 8) U[i] = false;
	if ( rec(0) ) cout << "YES" << endl;
	else cout << "NO" << endl;
    }
}

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

int main() {

  int X,A,B;
  cin >> X >> A >> B;
   if(B<=A){
    cout  << "delicious" << endl;
   }else if(B<=(X+A)){
     cout << "safe" << endl;
   }else{
     cout << "dangerous" << endl;
   }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=2e5+5;
int a[N],p[N],rk[N],d;
int get(int x){return x==p[x]?x:(p[x]=get(p[x]));}
bool un(int x,int y){
    if((x=get(x))==(y=get(y)))return 0;
    if(rk[x]<rk[y])swap(x,y);
    rk[x]+=(rk[x]==rk[y]),p[y]=x;
    return 1;
}
struct edge{
    int x,y,w;
};
bool operator<(const edge&p1,const edge&p2){
    return p1.w<p2.w;
}
int cost(int i,int j){
    return abs(i-j)*d+a[i]+a[j];
}
vector<edge> solve(int l,int r){
    vector<edge> res;
    res.reserve(r-l);
    if(l==r)return res;
    int m=(l+r)/2;
    auto lt=solve(l,m);
    auto rt=solve(m+1,r);
    int mnl=l;
    for(int i=l;i<=m;++i)if(a[i]-d*i<a[mnl]-d*mnl)mnl=i;
    int mnr=r;
    for(int i=m+1;i<=r;++i)if(a[i]+d*i<a[mnr]+d*mnr)mnr=i;
    vector<edge> ltomnr(m-l+1);
    forn(i,sz(ltomnr))ltomnr[i]=edge{l+i,mnr,cost(l+i,mnr)};
    vector<edge> mnltor(r-(m+1)+1);
    forn(i,sz(mnltor))mnltor[i]=edge{mnl,m+1+i,cost(mnl,m+1+i)};
    vector<edge> all;
    all.reserve(sz(lt)+sz(rt)+sz(ltomnr)+sz(mnltor));
    for(edge e:lt)all.pb(e);
    for(edge e:rt)all.pb(e);
    for(edge e:mnltor)all.pb(e);
    for(edge e:ltomnr)all.pb(e);
    sort(all.begin(),all.end());
    for(int i=l;i<=r;++i){
        p[i]=i;
        rk[i]=0;
    }
    for(edge e:all)
        if(un(e.x,e.y))
            res.pb(e);
    return res;
}
int32_t main(){

    int n;
    cin>>n>>d;
    for(int i=1;i<=n;++i)cin>>a[i];
    auto t=solve(1,n);
    int ans=0;
    for(edge e:t)ans+=e.w;
    cout<<ans<<'\n';

    return 0;
}


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

int main() {
  int a, b;
  cin >> a;
  
  for(int i = 7;i >= 0;i--) {
    b = pow(2, i);
    if(b <= a) {
      cout << b << endl;
      break;
    }
  }
}


Measured memory_bytes: 4084
#include <bits/stdc++.h>
 
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define mii map<int,int>


using namespace std;

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

    int sum=0;
    for(int i=0;i<n;i++){
    	int x;
    	cin>>x;
    	sum+=x;
    }

    if(sum>=h)
    	cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;
}

Measured memory_bytes: 256
class UnionFind:
    MAX_N = 0
    PAR  = [] 
    RANK = []

    def __init__(self,n):
        self.MAX_N = n
        self.PAR = [ i for i in range(n)]
        self.RANK= [ 0 ] * n

    def find(self,x):
        if self.PAR[x] == x:
            return x
        else:
            self.PAR[x] = self.find(self.PAR[x])
            return self.PAR[x] 

    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.RANK[x] < self.RANK[y]:
            self.PAR[x] = y
        else:
            self.PAR[y] = x
            if self.RANK[x] == self.RANK[y]:
                self.RANK[x] += 1

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

N,K,L = map(int,input().split())
path = UnionFind(N+1)
for _ in range(K):
    p,q = map(int,input().split())
    path.union(p,q)
rail = UnionFind(N+1)
for _ in range(L):
    p,q = map(int,input().split())
    rail.union(p,q)

Data = {}
for i in range(1,N+1):
    p = path.find(i)
    r = rail.find(i)
    k = str(p)+"-"+str(r)
    if k in Data.keys():
        Data[k] += 1
    else:
        Data[k] = 1

for i in range(1,N+1):
    p = path.find(i)
    r = rail.find(i)
    k = str(p)+"-"+str(r)
    print( Data[k], end= ' ')


Measured memory_bytes: 50452
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OfficialHouse
{
	class Program
	{
		static void Main(string[] args)
		{
			int lineCount = 0;

			if (!int.TryParse(Console.In.ReadLine(), out lineCount))
			{
				return;
			}

			College college = new College(4);
			for (int i = 0; i < lineCount; ++i)
			{
				List<int> bfrv = Console.In.ReadLine().Split(' ').Select(int.Parse).ToList();
				college.Buildings[bfrv[0] - 1].Floors[bfrv[1] - 1].Rooms[bfrv[2] - 1].MoveIn(bfrv[3]);
			}

			Console.Out.Write(college.ToString());
			return;
		}
	}

	internal class College
	{
		internal List<Building> Buildings { get; private set; }

		internal College(int buildingSize)
		{
			Buildings = Enumerable.Range(0, buildingSize).Select(_ => new Building(3)).ToList();
		}

		public override string ToString()
		{
			StringBuilder sb = new StringBuilder();
			foreach (var building in Buildings)
			{
				sb.Append(building.ToString());

				if (!IsLastBuilding(building)){
					sb.Append("####################");
					sb.AppendLine();
				}
			}
			return sb.ToString();
		}

		private bool IsLastBuilding(Building building)
		{
			return Buildings.IndexOf(building) == Buildings.Count - 1;
		}
	}

	internal class Building
	{
		internal List<Floor> Floors { get; private set; }

		internal Building(int floorSize)
		{
			Floors = Enumerable.Range(0, floorSize).Select(_ => new Floor(10)).ToList();
		}

		public override string ToString()
		{
			StringBuilder sb = new StringBuilder();
			foreach (var floor in Floors)
			{
				sb.Append(floor.ToString());
				sb.AppendLine();
			}
			return sb.ToString();
		}
	}

	internal class Floor
	{
		internal List<Room> Rooms { get; private set; }

		internal Floor(int roomSize)
		{
			Rooms = Enumerable.Range(0, roomSize).Select(_ => new Room()).ToList();
		}

		public override string ToString()
		{
			StringBuilder sb = new StringBuilder();

			foreach (var room in Rooms)
			{
				sb.Append(" ");
				sb.Append(room.ToString());
			}
			return sb.ToString();
		}
	}

	internal class Room
	{
		internal int PersonNumber { get; private set; }

		internal Room()
		{
			PersonNumber = 0;
		}

		internal void MoveIn(int size)
		{
			PersonNumber += size;
		}

		public override string ToString()
		{
			StringBuilder sb = new StringBuilder();
			sb.Append(PersonNumber);
			return sb.ToString();
		}
	}
}



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

int N; long double D , X , ans;

int main(){
	cin >> N >> D >> X;
	while(N){ans += D + X * (2 * N - 1) / 2; D = (5 * X + (2 * N + 2) * D) / 2 / N; X = X * (2 * N + 4) / 2 / N; --N;}
	cout << fixed << setprecision(10) << ans;
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007



n = I()
li = S()
cnt = li[1:].count('E')
ret = cnt
for i in range(n - 1):
    if li[i + 1] == 'E':
        cnt -= 1
    if li[i] == 'W':
        cnt += 1
    ret = min(ret, cnt)



print(ret)

Measured memory_bytes: 43632