akhauriyash/Code-Regression huggingface dataset:
n,p=map(int,input().split())
a=list(map(int,input().split()))
k=m=0
for i in a:
    if i%2==0:
        k +=1
m=n-k

ans_x=ans_y=0

def cbn(b,c):
    z=1
    for i in range(2,b+1):
        z *= i
    for i in range(2,c+1):
        z //= i
    for i in range(2,b-c+1):
        z //= i
    return(z)


if p==0:

    for i in range(k+1):
        ans_x += cbn(k,i)
    for i in range(0,m+1,2):
        ans_y += cbn(m,i)

    print(ans_x * ans_y)

else:

    for i in range(k+1):
        ans_x += cbn(k,i)
    for i in range(1,m+1,2):
        ans_y += cbn(m,i)

    print(ans_x * ans_y)    


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

using namespace std;

typedef pair<long long int, long long int> P;
typedef pair<P, long long int> Q;


int main() {

	long long int n, m;
	cin >> n >> m;

	vector<Q> py(m);

	for (long long int i = 0; i < m; i++) {
		cin >> (py[i].first).first >> (py[i].first).second;
		py[i].second = i;
	}

	sort(py.begin(), py.end());

	vector<P> ans(m);

	ans[py[0].second] = P((py[0].first).first, 1);
	long long int prep = (py[0].first).first;
	long long int count = 1;

	for (long long int i = 1; i < m; i++) {
		if ((py[i].first).first == prep) {
			count++;
			ans[py[i].second] = P((py[i].first).first, count);
		}
		else {
			count = 1;
			ans[py[i].second] = P((py[i].first).first, count);
			prep = (py[i].first).first;
		}
	}

	for (long long int i = 0; i < m; i++) {
		printf("%06lld%06lld\n", ans[i].first, ans[i].second);
	}

	return 0;
}

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

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

// code starts
int ans=0;

void dfs(int val, int dep, vector<vector<int>> &abc, int n, vector<int> &kans, int m)
{
  int i;
  if(dep==n)
  {
    int k=0;
    rep(i,abc.size())
    {
      if(kans[abc[i][1]]-kans[abc[i][0]]==abc[i][2])
      {
        k+=abc[i][3];
      }
    }
    ans=max(ans,k);
    return;
  }
  else
  {
    for(i=val;i<m;i++)
    {
      kans.emplace_back(i);
      dfs(i,dep+1,abc,n,kans,m);
      kans.erase(kans.end()-1);
    }
  }
  
}

int main()
{
  int n,m,q;cin>>n>>m>>q;
  vector<vector<int>> abc(q,vector<int>(4));
  int i,j;
  rep(i,q)
  {
    rep(j,4)
    {
      cin>>abc[i][j];
      if(j<=1)abc[i][j]--;
    }
  }
  vector<int> kans(0);
  dfs(0,0,abc,n,kans,m);
  cout<<ans<<endl;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

struct ant{
  int p;
  int d;
  int id;
};

int main(){
  while(1){
    int n,l;
    cin >> n >> l;
    if(n==0) return 0;
    vector<ant> pos(n);
    char c;
    rep(i,n){
      cin >> c >> pos[i].p;
      pos[i].d=(c=='R'?1:-1);
      pos[i].id=i+1;
    }
    int count=n,t=0;
    while(1){
      t++;
      int num=-1;
      rep(i,n){
        pos[i].p+=pos[i].d;
      }
      sort(all(pos),[](ant &l, ant &r){
        return l.p<r.p;
      });
      rep(i,n-1){
        if(pos[i].p==pos[i+1].p){
          pos[i].d*=-1;
          pos[i+1].d*=-1;
        }
      }
      rep(i,n){
        if((pos[i].p==0&&pos[i].d==-1)||(pos[i].p==l&&pos[i].d==1)){
          if(num==-1) num=pos[i].id;
          count--;
          pos[i].p=100000;
          pos[i].d=0;
        }
      }
      if(count==0){
        cout << t SP num << endl;
        break;
      }
    }
  }
  return 0;
}



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

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

#define mod 1000000007



using namespace std;

class CompareFirst

{

public:

  bool operator()(pair<int,int> n1,pair<int,int> n2) {

    return n1.first>n2.first; //>:desc <:asc

  }

};





int main(){



  string s,t,ss;
  int i,j,k,l,n,m;
  vector<string> vs;
  vector<int> v[26];
  pair<int,int> pr;
  //unordered_map<string,int> mp;
  //priority_queue<int> pq; // default ‘å‚«‚¢‡
  //priority_queue<pair<int,int>,vector<pair<int,int>>,CompareFirst> pq

  cin >> s;
  cin >> t;
  
  long ans = 0;
  long pos = 0;
 
  ss = s+s;
  rep(i,0,(int)(ss.size())-1){
    n = (int)(ss[i] - 'a');
    v[n].push_back(i+1);
  }
  rep(i,0,(int)(t.size())-1){
    n = (int)(t[i] - 'a');
    if(v[n].empty()){
     cout << -1 << endl;
      return 0;
    }
    pos = *lower_bound(v[n].begin(),v[n].end(),pos+1);
  //  rep(j,0,v[n].size()-1){
  //    if(v[n][j] > pos){
    //    pos = v[n][j];
      //  break;
     // }
   // }
    if(pos > (int)(s.size())){
      ans += (int)(s.size());
      pos -= (int)(s.size());
    }
  }
  ans += pos;
  
  cout << ans << endl;

  return 0;

}

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, VL, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N, T;

signed main() {
    cin >> N >> T;
    ll ans = 0, last = IN();
    REP(i, N - 1) {
        LCIN(t);
        ans += min(t - last, T);
        last = t;
    }
    cout << ans + T << "\n";
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int a[]=new int[n];
			int max=Integer.MIN_VALUE;
			for(int i=0;i<n;i++)a[i]=in.nextInt();
			for(int i=0;i<n;i++)
			{
				int sum=0;
				for(int j=i;j<n;j++)
				{
					sum+=a[j];
					max=Math.max(sum, max);
				}
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 12000
use proconio::input;

fn main() {
    input! {
        a: char,
        b: char,
    };
    let ans = match a {
        'H' => b,
        'D' => match b {
            'H' => 'D',
            'D' => 'H',
            _ => unreachable!(),
        },
        _ => unreachable!(),
    };
    println!("{}", ans);
}


Measured memory_bytes: 2140
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-06-01 14:57:47
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

#if __cplusplus >= 201703L
template <class Ch, class Tr, class Tuple, std::size_t... Is>
void tuple_out(std::basic_ostream<Ch, Tr>& os, const Tuple& tp, std::index_sequence<Is...>) {
  ((os << (Is ? ", " : "(") << std::get<Is>(tp)), ...) << ")";
}

template <class Ch, class Tr, class... Args>
auto& operator<<(std::basic_ostream<Ch, Tr>& os, const std::tuple<Args...>& tp) {
  tuple_out(os, tp, std::index_sequence_for<Args...>{});
  return os;
}
#endif

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class Compare>
std::ostream& operator<<(std::ostream& os, const std::set<T, Compare>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U, class Compare>
std::ostream& operator<<(std::ostream& os, const std::map<T, U, Compare>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

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

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

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

  int n; cin >> n;
  vector<int64> a(n); cin >> a;
  if (any_of(all(a), [](int64 e){ return e == 0LL; })) {
    cout << 0 << endl; return 0;
  }

  int64 acc = 1LL;

  constexpr int64 inf = (int64)1e18;

  for (int i = 0; i < n; ++i) {
    if (a[i] > inf / acc) {
      cout << -1 << endl; return 0;
    } else {
      acc *= a[i];
    }
  }

  cout << acc << endl;

  return 0;
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int a;
    cin>>a;
    cout<<48-a<<endl;
}

Measured memory_bytes: 256
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import itertools
# import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 ** 9

N, M = map(int, readline().split())
PS = [line.split() for line in readlines()]
AC = [False] * (N + 1)
WA = [0] * (N + 1)

penal = 0
for p, s in PS:
    p = int(p)
    if AC[p]:
        continue
    if s == b'WA':
        WA[p] += 1
    else:
        AC[p] = True
        penal += WA[p]

ac = sum(AC)
print(ac, penal)

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define int ll

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

  string S;
  cin>>S;
  reverse(rng(S));
  int N=S.size();
  vector<ll>ten(1000000);
  ten[0]=1;
  for(int i=1;i<1000000;i++)ten[i]=(ten[i-1]*10)%13,ten[i]%=13;
  vector<vector<ll>>dp(N+1,vector<ll>(13,0));
  dp[0][0]=1;
  for(int i=1;i<=N;i++){
    for(int j=0;j<13;j++){
      if(S[i-1]!='?'){
        dp[i][(j+(S[i-1]-'0')*ten[i-1])%13]+=dp[i-1][j]%MOD;
        dp[i][(j+(S[i-1]-'0')*ten[i-1])%13]%=MOD;
      }
      else{
        for(int k=0;k<10;k++){
          dp[i][(j+k*ten[i-1])%13]+=dp[i-1][j]%MOD;
          dp[i][(j+k*ten[i-1])%13]%=MOD;
        }
      }
    }
  }
  cout<<dp[N][5]<<endl;
  return 0;
}


Measured memory_bytes: 21456
#include <stdio.h>

typedef struct {
  char c,calt,n,nalt;
  int count;
} Record;
  
int isstable(Record *,int);
int main(){
  int i,j,minj,len;
  char cnum,inum;
  Record data[36];
  
  scanf("%d",&len);
  for(i=0;i<len;i++){
    scanf(" %c%c",&data[i].c,&data[i].n);
    data[i].calt=data[i].c;
    data[i].nalt=data[i].n;
   
  }
  
  for(i=0;i<len;i++){
    for(j=len-1;j>=i+1;j--){
      if(data[j].nalt<data[j-1].nalt){
	  inum=data[j].nalt;
	  data[j].nalt=data[j-1].nalt;
	  data[j-1].nalt=inum;

	  cnum=data[j].calt;
	  data[j].calt=data[j-1].calt;
	  data[j-1].calt=cnum;
	  
      }
    }
    
  }

 
  
  for(i=0;i<len;i++){
    printf("%c%c",data[i].calt,data[i].nalt);
    if(i==len-1) printf("\n");
    else printf(" ");
  }
 
  if(isstable(data,len)==1) printf("Stable\n");
  else printf("Not stable\n");
  
  for(i=0;i<len;i++){
    data[i].calt=data[i].c;
    data[i].nalt=data[i].n;
  }

  for(i=0;i<len;i++){
    minj=i;
    for(j=i;j<len;j++){
      if(data[j].nalt<data[minj].nalt) minj=j;
    }
    if(i!=minj){
      inum=data[i].nalt;
      data[i].nalt=data[minj].nalt;
      data[minj].nalt=inum;

      cnum=data[i].calt;
      data[i].calt=data[minj].calt;
      data[minj].calt=cnum;
    }
  }
  for(i=0;i<len;i++){
    printf("%c%c",data[i].calt,data[i].nalt);
    if(i==len-1)printf("\n");
    else printf(" ");
  }
  if(isstable(data,len)==1) printf("Stable\n");
  else printf("Not stable\n");
  return 0;
}

int isstable(Record * data,int len){
  int i,j,a,b;
  for(i=0;i<len;i++){
    for(j=i+1;j<len;j++){
      for(a=0;a<len;a++){
	for(b=a+1;b<len;b++){
	  if(data[i].n==data[j].n && data[i].n==data[b].nalt &&data[j].n==data[a].nalt && data[i].c==data[b].calt && data[j].c==data[a].calt ) return 0;
	}
      }
    }
  }
  return 1;
}



Measured memory_bytes: 2104
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

vector<int> del[3000];

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int ans = intmax;
    for (int i = 0; i < N; i++) {
        int minnum = A[i];
        vector<int> now;
        for (int j = 0; j < N; j++) {
            if (A[j] >= minnum) {
                now.push_back(A[j]);
            } else {
                sort(now.begin(), now.end());
                int m = now.size();
                for (int k = 0; k < m - K + 1; k++) {
                    del[i].push_back(now[k]);
                }
                now.clear();
            }
        }
        sort(now.begin(), now.end());
        int m = now.size();
        for (int k = 0; k < m - K + 1; k++) {
            del[i].push_back(now[k]);
        }
        sort(del[i].begin(), del[i].end());
        int p = del[i].size();
        if (p >= Q) {
            ans = min(ans, del[i][Q - 1] - minnum);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 16384
//#define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
const double pi = acos(-1);

struct point {
  long double x,y;

  point(long double r, long double theta) {
    this->x = r*cos(pi/2 - theta);
    this->y = r*sin(pi/2 - theta);
  }

};

double dist(point a, point b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

int main() {
  fastio;
  long double a, b, h, m;
  cin >> a >> b >> h >> m;

  point hour = point(a, (h*(pi/6) + pi/6*m/60));
  point min = point(b, m * pi/30);
  cout << setprecision(20);
  cout << dist(min, hour) << endl;




  
  #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


Measured memory_bytes: 4184
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 100005
#define lo long long
using namespace std;
int n,A[li];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&A[i]);
	A[1]-=1;
	for(int i=2;i<=n;i++){
		if(A[i]<A[i-1]){
			printf("No\n");
			return 0;
		}
		if(A[i]-1>=A[i-1]){
			A[i]-=1;
		}
	}
	printf("Yes\n");
	return 0;
}




Measured memory_bytes: 640
import math, sys, random

N, M = list(map(int,input().split()))
# N, M = 1111, 1000000000

def is_prime(n):
    if n == 2: return True
    if n == 1 or n & 1 == 0: return False

    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for k in range(100):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)

        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1

        if y != n - 1 and t & 1 == 0:
            return False

    return True

d = int(math.floor(M/N))

if M%N == 0:
	print(d)
	sys.exit()

i = 0
f = False
while True:
	if M%(N+i+1) == 0:
		print(int(M/(N+i+1)))
		sys.exit()
	i += 1
	if i == 100000 and is_prime(M):
		print(1)
		sys.exit()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x);
#define rl(x) scanf("%lld",&x);
#define pi(x) printf("%d",x);
#define pl(x) printf("%lld",x);
#define lfd() printf("\n");
#define sp() printf(" ");
int n,k;
int a[200100];
int cnt[200100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		cnt[a[i]]++;
	}
	vector<int> v;
	for(int i=1;i<=n;i++)
		if(cnt[i])
			v.push_back(cnt[i]);
	sort(v.begin(),v.end());
	if(v.size()<k){
		cout<<0<<endl;
		return 0;
	}
	int res=0;
	for(int i=0;i<v.size()-k;i++)
		res+=v[i];
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 2936
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == ',') {
			s[i] = ' ';
		}
	}
	cout << s << endl;
}


Measured memory_bytes: 3592
n = int(input())
s = input()
E = s.count("E")
W = 0
min_num = n
for s_i in s:
    if s_i == "E":
        E -= 1
    else :
        W += 1

    change_man = E + W - bool(s_i == "W")
    min_num = min(min_num, change_man)
print(min_num)

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	int n;cin>>n;
  	long long int m=0, a=0, r=0, c=0, h=0,ans=0;
  	vector <long long int> d(5,0);
  	int one[10]={0,0,0,0,0,0,1,1,1,2};
  	int two[10]={1,1,1,2,2,3,2,2,3,3};
  	int thr[10]={2,3,4,3,4,4,3,4,4,4};
  	for(int i=0;i<n;i++){
      	string s;
    	cin>>s;
      	if(s[0]=='M') d[0]++;
      	if(s[0]=='A') d[1]++;
      	if(s[0]=='R') d[2]++;
      	if(s[0]=='C') d[3]++;
      	if(s[0]=='H') d[4]++;
    }
  	for(int i=0;i<10;i++){
    	ans+=d[one[i]]*d[two[i]]*d[thr[i]];
    }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int n,k;
    cin>>n>>k;

    vector<int>A;

    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        A.push_back(a);
    }

    map<int,int>dp;

    for(int remstone = 0 ; remstone<=k; remstone++){
        for(int i=0;i<A.size();i++){
            int x = A[i];

            if(x>remstone)continue;

            if(dp[remstone-x]==0){
                dp[remstone]=1;
            }
        }
    }

    if(dp[k]==1)    cout<<"First\n";
    else            cout<<"Second\n";
}


Measured memory_bytes: 4992
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int n,ans=0x7fffffff;
	cin>>n;
	for (int i=1; i<=n-1; ++i)
	{
		int x=i,y=n-i,sum=0;
		while (x)
		{
			sum+=x%10;x/=10;
		}
		while (y)
		{
			sum+=y%10;y/=10;
		}
		ans=min(ans,sum);
	}
	cout<<ans;
}

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

int main()
{
    int h, a;
    cin >> h >> a;
    int ans;
    ans = h/a;
    if (h%a != 0) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3532
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define gcd __gcd
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define mp make_pair
#define pb push_back
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sbits(a) __builtin_popcount(a)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define nani(x) cerr << #x << " is " << x << endl;
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

typedef long long ll;

const int N = 1e5 + 5;

int A[N];

int main()
{
    fast;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

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

    ll ans = 0;

    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            ans += A[i] * A[j];

    cout << ans;
    return 0;
}


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

int main(){
string S;   cin >> S;
bool s_is_even = false;
int ans = 0;
for (int i = 1; i <= (S.size() - 1)/2; i++) {
    if (S.substr(0, i) == S.substr(i, i)) {
        s_is_even = true;
        ans = 2*i;
    }
}
cout << ans << endl;
}

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

int main(){
  string s;
  string t;
  cin >> s;
  cin >> t;
  int cnt = 0;
  for(int i = 0;i<3;i++){
    if(s.at(i) == t.at(i)){
      cnt++;
    }
  }
  cout << cnt;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d)
	{
		cout << "Left";
	}
	else if (a + b < c + d)
	{
		cout << "Right";
	}
	else
	{
		cout << "Balanced";
	}
	cout << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){	
	int ans=0,a,b,c,s,n;
	cin>>a>>b>>c>>n;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				s=500*i+100*j+50*k;
				if(s==n){
					ans++;
				}
			}
		}
	}
	cout<<ans;
	return 0;
} 

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

int main() {
  int N,M,count = 0;
  cin >> N >> M;
  int x=-1,y=-1,z=-1;
  
  rep(i,N){
    rep(k,N-i){
       count = 10000*i + 5000*k + 1000*(N-i-k);
       if(count == M){
         x=i;
         y=k;
         z=N-i-k;
   	   }
    }
  }

  cout << x <<" "<< y <<" "<< z << endl;
}

Measured memory_bytes: 384
# import sys
import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    a,b = readInt()
    print(a*b)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 9192
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int& x) { int k, m = 0; x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
void writer(int x, char c) { int s = 0, m = 0; char f[10]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
using namespace std;
typedef pair<int, int>P;

vector<P>E[100000];
int l[100000], d[100000], b[100000], cnt[200001], u[200000], v[200000], r[200000], que[100000];
int main() {
	int n, m, q; reader(n); reader(m); reader(q);
	rep(i, m) {
		reader(u[i]); reader(v[i]); u[i]--; v[i]--; r[i] = q;
		l[u[i]]++; l[v[i]]++;
	}
	rep(i, n)E[i].reserve(l[i]), l[i] = 0;
	rep(i, q) {
		int a; reader(a); r[a - 1] = i;
	}
	rep(i, m) {
		E[u[i]][l[u[i]]++] = P(v[i], r[i]);
		E[v[i]][l[v[i]]++] = P(u[i], r[i]);
	}
	d[0] = 1; b[0] = q;
	int s = 0, g = 1;
	while (s != g) {
		int p = que[s++];
		rep(i, l[p]) {
			P v = E[p][i];
			if (d[v.first] == 0) {
				d[v.first] = d[p] + 1; que[g++] = v.first;
			}
			if (d[v.first] == d[p] + 1)
				b[v.first] = max(b[v.first], min(b[p], v.second));
		}
	}
	rep(i, n)cnt[b[i]]++;
	int ans = 0;
	rep(i, q) {
		ans += cnt[i];
		writer(ans, '\n');
	}
}

Measured memory_bytes: 14600
void call(int n) {
    int i = 1;
    int x;
    do {
        x = i;
        if (x % 3 == 0) {
            printf(" %d", i);
        }else{
            do {
                if (x % 10 == 3) {
                    printf(" %d", i);
                    x = 0;
                }
                else x /= 10;
            }
            while (x);
        }
    }
    while (++i <= n);
    putchar('\n');
}

int main(int argc, const char * argv[]){
    int n;
    scanf("%d", &n);
    call(n);
    return 0;
}



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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    string s = to_string(n);

    int tmp = 0;
    rep(i, s.size()){
        tmp += s[i] - '0';
    }

    if(n % tmp == 0) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
M = []
for i in range(H):
    M.append(input())

dir = [[1, 0], [0, 1], [-1, 0], [0, -1]]
ans = 0
for i in range(H):
    for j in range(W):
        if M[i][j] == '#':
            continue
        stack = [[i, j]]
        cs = [[0 for i in range(W)] for i in range(H)]
        while stack:
            pos = stack.pop(0)
            cs[pos[0]][pos[1]] += 1
            for d in dir:
                npos = [pos[0] + d[0], pos[1] + d[1]]
                if 0 <= npos[0] < H and 0 <= npos[1] < W and cs[npos[0]][npos[1]] == 0 and M[npos[0]][npos[1]] == '.':
                    stack.append(npos)
                    cs[npos[0]][npos[1]] = cs[pos[0]][pos[1]]
                else:
                    ans = max(ans, cs[pos[0]][pos[1]])
print(ans - 1)


Measured memory_bytes: 3188
#include <iostream>
#include<vector>
#include<cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
typedef long long ll;

using namespace std;

ll f(ll n){ return n*(n+1)/2; }

int main() {
    int n;
    cin>>n;
    /*vector<ll>f(1e7+1);
    rrep(i,n){
        for(int j = i; j <= n; j+=i){
            f[j]+=j;
        }
    }*/
    ll ans = 0;
    rrep(i,n){
        ll r = n/i;
        ans += f(r)*i;
    }
    //rrep(i,n)ans += f[i];
    cout<<ans<<endl;
    

    return 0;
}

Measured memory_bytes: 3604
import numpy as np

N=int(input())
A=np.array(input().split(),dtype=np.int32)-1
B=np.array(input().split(),dtype=np.int32)
C=np.array(input().split(),dtype=np.int32)

s=0
for i in range(len(A)):
    key=A[i]
    s+=B[key]
    if(i+1<=len(A)-1):
        if(key+1==A[i+1]):
            s+=C[key]

print(s)

Measured memory_bytes: 21660
X,K,D=map(int,input().split())
sub_even=abs(X)//D
sub_odd=sub_even+1
if sub_even%2==1:
	sub_odd=sub_even
	sub_even=sub_odd+1
if K%2==0:
	if K>= sub_even:
		print(abs(abs(X)-sub_even*D))
	else:
		print(abs(abs(X)-K*D))
else:
	if K>= sub_odd:
		print(abs(abs(X)-sub_odd*D))
	else:
		print(abs(abs(X)-K*D))


Measured memory_bytes: 9152
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector< pii > vii;

#define ll          long long
#define ff          first
#define ss          second
#define pb          push_back
#define mkp         make_pair
#define sz          size()

#define forf(a,b,c)    for(int i=a;i<=b;i+=c)
#define forr(a,b,c)    for(int i=a;i>=b;i-=c)
#define all(a)      a.begin(),a.end()
#define mem(a,b)    memset(a,b,sizeof(a))
#define pi          2*acos(0.0)
#define End         return 0;
#define nl endl

#define scan1(a)    scanf("%d",&a)
#define scan2(a,b)  scanf("%d %d",&a,&b)
#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scanl(a)    scanf("%lld",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define print1(a)    printf("%d",a)
#define print2(a,b)  printf("%d %d",a,b)
#define print3(a,b,c)  printf("%d %d %d",a,b,c)
#define printl(a)    printf("%lld",a)
#define printll(a,b) printf("%lld %lld",a,b)
#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)

#define MAXN        100000007
#define INF 0x3f3f3f3f
bool mark[100005];vi prime;
void seive(ll N){for(int i=2;i<=N;i++){if(mark[i]==false){prime.pb(i);for(int j=i+i;j<N;j+=i)mark[j]=true;}}}
//freopen("input.txt", "r", stdin);

int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   long long l,r,cnt=111111111111111111110;
   cin>>l>>r;
    long long t=l/2019;
    if(t*2019==l){
           /* if(t*2019==r){
                cout<<((t*2019)*((t*2019)-1))%2019<<endl;
                return 0;
            }*/

        if((t+1)*2019<=r){
            cout<<0<<endl;
            return 0;
        }
        else{
            cout<<((t*2019)*((t*2019)+1))%2019<<endl;
            return 0;
        }
    }
    t++;
    if(t*2019<r){
            if((2019*(t+1)<=r)){
                cout<<0<<endl;
                return 0;
            }
                cout<<((t*2019)*((t*2019)+1))%2019<<endl;
                return 0;
    }
    else{
        for(long long i=l;i<=r;i++){
            for(int j=i+1;j<=r;j++){
                cnt=min(cnt,(i*j)%2019);
            }
        }
        cout<<cnt<<endl;
    }

}


Measured memory_bytes: 256
/*input

*/


// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}

const ll N = 1e5+5;
vector<set<ll>> adj(N);
ll n;

	// void dfs(ll u,ll p=-1)
	// {
	// 	rep(i,0,sz(adj[u]))
	// 	{
	// 		ll ch = adj[u][i];
	// 		if(ch==p) continue;
	// 		dfs(ch,u);
	// 	}
	// 	return ;
	// }

int solve()
{
	ll m;
	cin>>n;
	cin>>m;

	vi h(n);;
	rep(i,0,n) cin>>h[i];
	
	rep(i,0,m)
	{
		ll x,y;cin>>x>>y;
		x--,y--;
		adj[x].insert(h[y]);
		adj[y].insert(h[x]);
	}	


	ll ans=0;
	rep(x,0,n)
		if(adj[x].empty() || h[x]>*adj[x].rbegin()) ans++;

	cout<<ans<<"\n";



	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}


Measured memory_bytes: 18020
from sys import stdin


def input():
    return stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    A.sort()
    B.sort()
    C.sort()

    nums = [0] * (N + 1)

    for i, b in enumerate(B):
        ng = -1
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if C[mid] > b:
                ok = mid
            else:
                ng = mid

        nums[i] = N - ok

    for i in range(N, 0, -1):
        nums[i - 1] += nums[i]

    ans = 0
    for a in A:
        ng = -1
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if B[mid] > a:
                ok = mid
            else:
                ng = mid

        ans += nums[ok]

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 23328
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,I[266],R[266],O[266],M=256;
int S,A,C;
double H;

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>N && N){
		rep2(i,1,N+1)cin>>I[i];
		H=INF;
		rep(s,16)rep(a,16)rep(c,16){
			R[0]=s;
			rep2(i,1,N+1)R[i]=(a*R[i-1]+c)%M;
			rep2(i,1,N+1)O[i]=(I[i]+R[i])%M;
			double res=0;
			double x[266]={};
			rep2(i,1,N+1)x[O[i]]++;
			rep(i,M)if(x[i])res-=x[i]/N*log2(x[i]/N);
			if(res<H-EPS){
				H=res;
				S=s,A=a,C=c;
			}
		}
		cout<<S<<" "<<A<<" "<<C<<endl;
	}
}

Measured memory_bytes: 1232
if __name__ == '__main__':
    s = input()
    q = int(input())

    pref = []
    suff = []
    rev = False

    for i in range(q):
        curr = [c for c in input().split()]
        if curr[0] == '1':
            rev = not rev
        else:
            if curr[1] == '1':
                if not rev:
                    pref.append(curr[2])
                else:
                    suff.append(curr[2])
            else:
                if not rev:
                    suff.append(curr[2])
                else:
                    pref.append(curr[2])

    res = "{}{}{}".format("".join(pref[::-1]), s, "".join(suff))
    if rev:
        print(res[::-1])
    else:
        print(res)


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

using namespace std;

#define LL long long

#define MAX_N 100005
#define MAX_Q 100005
#define MAX_M 50

int N;
LL X[MAX_N];
LL L;
int Q;
int A[MAX_N], B[MAX_Q];

void input()
{
  cin >> N;
  for (int i = 0; i < N; i++) {
    scanf("%lld", &X[i]);
  }
  cin >> L;
  cin >> Q;
  cin.ignore();
  for (int i = 0; i < Q; i++) {
    scanf("%d %d", &A[i], &B[i]);
    A[i]--; B[i]--;
    if(A[i] > B[i]){
      swap(A[i], B[i]);
    }
  }
}

int m_next[MAX_N][MAX_M];

int calc(int pos)
{
  int l = pos, r = N;
  while(r-l > 1){
    int mid = (l+r)/2;
    if(X[mid] - X[pos] <= L){
      l = mid;
    }
    else{
      r = mid;
    }
  }
  return l;
}

int main()
{
  input();

  for (int i = 0; i < N; i++) {
    m_next[i][0] = calc(i);
  }

  m_next[N-1][0] = -1;

  for (int j = 0; j < MAX_M-1; j++) {
    for (int i = 0; i < N; i++) {
      int n = m_next[i][j];
      if(n == -1){
        m_next[i][j+1] = -1;
      }
      else{
        m_next[i][j+1] = m_next[n][j];
      }
    }
  }

  for (int i = 0; i < Q; i++) {
    LL ans = 0;
    int pos = A[i];
    while(pos < B[i]){
      if(pos == -1){
        cerr << "unk " << endl;
        return 0;
      }
      int _N = -1;
      bool flag = false;
      for (size_t j = 0; j < MAX_M; j++) {
        if(m_next[pos][j] >= B[i] ||
          m_next[pos][j] == -1){
            _N = j;
            if(m_next[pos][j] == B[i]){
              flag = true;
            }
            break;
          }
        }
        if(flag){
          ans += ((LL)1 << (_N));
          pos = m_next[pos][_N];
          break;
        }
        if(_N == 0){
          ans++;
          pos = m_next[pos][_N];
        }
        else{
          ans += ((LL)1 << (_N-1));
          pos = m_next[pos][_N-1];
        }

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

    return 0;
  }


Measured memory_bytes: 21888
D = int(input())
c = [int(x) for x in input().split()]
s = [[int(x) for x in input().split()] for _ in range(D)]

T = [int(input())-1 for _ in range(D)]

last = [-1 for _ in range(26)]
satisfy = 0
for day, t in enumerate(T):
    last[t] = day
    loss = sum(c[i]*(day-last[i]) for i in range(26))
    satisfy += s[day][t] - loss
    print(satisfy)

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

void testcase()
{
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	for(int &i: a) cin >> i;
	int maxi = a[0];
	long long ans = 0;
	for(int i = 1; i < n; i++) {
		if(a[i] < maxi) {
			ans += maxi-a[i];
		} else {
			maxi = a[i];
		}
	}
	printf("%lld", ans);
}

int main()
{
	int t = 1;
	//scanf("%d", &t);
	while(t--) {
		testcase();
		puts("");
	}
}


Measured memory_bytes: 4064
# Wrote in Mar 28, 2020 21:00 by reetok
require 'time'
require 'prime'
require 'bigdecimal'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n,datatype=".to_i")
  t = []
  n.times do
    t.push(eval("gets.chomp#{datatype}"))
  end
  return t
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
class Integer
  def divisor_list
    devisors = [1]
    2.upto(self/2) do |i|
      devisors << i if self%i == 0
    end
    devisors << self
    return devisors.uniq.sort
  end
end
class Array
  def upper(a) #aより上
    self.sort.select{|n|n>=a}
  end
  def downer(a) #aより下
    self.sort.select{|n|n<=a}
  end
end
#---------------

s = gets.chomp
if s[2]==s[3]&&s[4]==s[5]
  yes
else
  no
end



Measured memory_bytes: 2552
#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
class Solution {
public:
    int a[2][100];
    void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n; j++) {
                in >> a[i][j];
            }
        }
        int ans = 0;
        int memo[100] = {};
        for (int i = 0; i < n; i++) {
            for (int k = 0; k < n; k++) {
                if (i < k) {
                    memo[i] += a[1][k];
                }
                else if (i == k) {
                    memo[i] += a[0][k] + a[1][k];
                }
                else {
                    memo[i] += a[0][k];
                }
            }
            ans = max(ans, memo[i]);
        }
        out << ans << endl;
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


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

int main(){
    int r, g, b, n;
    cin >> r >> g >> b >> n;

    int ans=0;
    for(int i=0;i*r<=n;i++){
        for(int j=0;i*r+j*g<=n;j++){
            if((n-i*r-j*g)%b==0){
                ans+=1;
            }
        }
    }

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

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

using namespace std;

int main(){
	int n;
	double students[1000] = {0},sum,m,div;

	while(true){
		scanf("%d",&n);
		if(n == 0) break;
		div = sum = 0;
		for(int i = 0; i < n; i++){
			scanf("%lf",&students[i]);
			sum += students[i];
		}
		m = sum/n;
		for(int i = 0; i < n;i++){
			div += (students[i] - m)*(students[i] - m);
			students[i] = 0;
		}
		printf("%.8lf\n",sqrt(div/n));
	}
}





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

int main(){
    int x, len;
    int i;
    if(scanf("%d\n", &x) == EOF)
        return -1;
    char s[100];
    if(scanf("%s", s) == EOF)
        return -1;
    len = strlen(s);

    if(len <= x){
        printf("%s\n", s);
    }else{
        for(i = 0; i < x; i++)
            printf("%c", s[i]);
        printf("...\n");
    }

    return 0;
}

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

int main(){
int a,b;
cin >> a >> b;
if(a >= 13)
cout << b << endl;
else if(a >=6 && 12 >=a)
cout << b/2 << endl;
else
{
    cout << 0 <<endl;
}


}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>

using namespace std;
#define ll          long long
#define endl        "\n"
#define inf         10000000002
#define pb          push_back
#define pf          push_front
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(a)      a.begin(),a.end()
#define mp          make_pair
#define MAX         100
#define yes         cout<<"YES"<<endl
#define no          cout<<"NO"<<endl
#define bye         return 0

ll gcd(ll a, ll b)
{
      if(!b) return a;
      return gcd(b,a%b);
}

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      //freopen("inputNew.txt", "r", stdin);

      ll n;
      cin>>n;
      cout<<n+(n*n)+(n*n*n)<<endl;


      bye;
}


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

int main(void)
{
    long long N;
    cin >> N;

    if ( N % 1000 == 0)
    {
        cout << 0 << endl;
    }

    else{
        cout << 1000 - (N % 1000) << endl;
    }
}

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

int main(){
  string s;
  cin>>s;

  if(s=="a"||s=="i"||s=="u"||s=="e"||s=="o"){cout<<"vowel"<<endl;}
  else{cout<<"consonant"<<endl;}
  
  return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

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

		BigDecimal a = new BigDecimal(sc.next());
		BigDecimal b = new BigDecimal(sc.next());

		System.out.println(a.multiply(b).setScale(0, BigDecimal.ROUND_DOWN));
	}
}


Measured memory_bytes: 27212