akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li,li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li,li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = 9223372036854775807;

void Yes(li b){
  if(b)cout<<"Yes";
  else cout<<"No";
}
void yes(li b){
  if(b)cout<<"yes";
  else cout<<"no";
}

li calc(li x, li y, li z){
	return x*x+y*y+z*z+x*y+y*z+z*x;
}

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

  li N;
  cin >>N;

  vi ans(10001,0);

  li x =1,y=1,z=1;

  while(1){
  	li c = calc(x,y,z);
  	if(c>10000){
  		++y;
  		x=y;
  		if(calc(x,y,z)>10000){
  			++z;
  			y =z;x=z;
  			if(calc(x,y,z)>10000){
  				break;
  			}
  			continue;
  		}
  		continue;
  	}
  	if(x==y&&y==z)ans[c]++;
  	else if(x==y||y==z||z==x)ans[c] += 3;
  	else ans[c] += 6;
	++x;
  }

	Rep1(i,N){
		cout<<ans[i]<<'\n';
	}

}

Measured memory_bytes: 3700
import math
import sys

k, a, b = map(int, sys.stdin.readline().rstrip().split())

if b - a <= 2:
    print(k + 1)
else:
    t = max(0, (k - a + 1) // 2)
    print(k + 1 + t * (b - a - 2))
    # print(max(0, math.ceil((k - a + 1)/2)))


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

int N, x;
int a[2010];

struct segtree {
    int size;
    vector<int> node;
    
    segtree(int n) {
        size = 1;
        while (size<n) size *= 2;
        node.resize(2*size-1);
        fill(node.begin(), node.end(), 1000000000000000);
    }

    void update(int k, int a) {
        k += size-1;
        node[k] = a;
        while (k>0) {
            k = (k-1)/2;
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }
    
    int query(int a, int b, int k, int l, int r) {
        if (r<=a || b<=l) return 1000000000000000;
        if (a<=l && r<=b) return node[k];
        else {
            int vl = query(a, b, 2*k+1, l, (l+r)/2);
            int vr = query(a, b, 2*k+2, (l+r)/2, r);
            return min(vl, vr);
        }
    }
    
    int get(int a, int b) {
        return query(a, b, 0, 0, size);
    }
};
 
signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> x;
    rep(i, N) cin >> a[i];
    segtree st(2*N);
    rep(i, 2*N) st.update(i, a[i%N]);
    int ans = 1000000000000000;
    rep(d, N) {
        int ans_cand = x*d;
        rep(i, N) ans_cand += st.get(N+i-d, N+i+1);
        ans = min(ans, ans_cand);
    }
    cout << ans << endl;
}

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

 public class Main{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}

//......................................@uthor_Alx..............................................


   public static void main(String[] args) throws  IOException{
	        		  assign();
	        		  //int n=int_v(read());
	        		  int[] a=int_arr();
	        		  int n=a[0],k=a[1];
	        		  if(k>=n){out.write("unsafe");}
	        		  else{out.write("safe");}
                      out.flush();
	        		 
	}
}
	       
	          



	
  





Measured memory_bytes: 32524
import io
import sys

MOD = 10 ** 9 + 7


def IN_S():
  return input()


def IN_I():
  return int(input())


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


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
3
500 300 200
'''


def MAIN():
  # T_IN()
  A()


def A():
  n = IN_I()
  nums = IN_L_I()
  nums.sort()
  t = nums.pop(0)

  for num in nums:
    t = (t + num) / 2

  print(t)

  return None


def B():
  return None


def C():
  return None


MAIN()


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int n,ans=0;
int main()
{
//	freopen("1580.in","r",stdin);
//	freopen("1580.out","w",stdout);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        ans=ans+(b-a+1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	string s;
	cin >> s;
	cout << "2018" << s.substr(4) << endl;
	return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char *argv[])
{
        int n, i;
        int *data;

        scanf("%d\n", &n);
        data = (int *)malloc(n * sizeof(int));

        for (i = 0; i < n; i++) {
                scanf("%d", data + i);
        }
        for (i = n - 1; i > 0; i--) {
                printf("%d ", data[i]);
        }

        printf("%d\n", data[0]);
        
        return 0;
}

Measured memory_bytes: 596
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let nm : Vec<i32> = read_vec();
    let ans = (nm[0] - 1) * (nm[1] - 1);
    println!("{}",ans);
}

Measured memory_bytes: 4352
#pragma comment (linker, "/STACK:256000000")
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(const size_t n, const size_t m, const T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
constexpr ll pow2(const int n) { return 1ll << n; }
constexpr int INF = 1 << 28; constexpr ll LINF = 1ll << 60;
constexpr int MAX = 1e5 + 5; constexpr int MOD = 1e9 + 7; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N;
vi A, B, C;

int main() {
    cin >> N;
    A.resize(N);
    B.resize(N);
    rep(i, N) {
        cin >> A[i];
    }
    rep(i, N) {
        cin >> B[i];
    }

    int ans = 0;
    C.resize(N);
    rep(bit, 29) {
        rep(i, N) {
            C[i] = B[i] % (1 << bit + 1);
        }
        sort(all(C));

        ll cnt = 0;
        rep(i, N) {
            const int x = A[i] % (1 << bit + 1);
            const int a = (1 << bit) - x;
            const int b = 2 * (1 << bit) - x;
            const int c = 3 * (1 << bit) - x;
            const int ia = lower_bound(all(C), a) - C.begin();
            const int ib = lower_bound(all(C), b) - C.begin();
            const int ic = lower_bound(all(C), c) - C.begin();

            cnt += ib - ia;
            cnt += N - ic;
        }

        ans |= cnt % 2 << bit;
    }

    write(ans);
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  char s[200000];
  cin >> s;
  cout << s[0] << strlen(s)-2 << s[strlen(s)-1];
  /*
  bool b;
  for(char i='a';i<='z';i++){
    b=false;
    for(int j=0;j<strlen(s);j++){
      if(s[j]==i){
        b=true;
        break;
      }
    }
    if(!b){
      cout << i << endl;
    }
  }
  if(b)cout << "None";
  */
}


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

template <class T>
inline bool read(T &ret)
{
    char c;
    int sgn;
    if (c = getchar(), c == EOF)
    {
        return 0;
    }
    while (c != '-' && (c < '0' || c > '9'))
    {
        c = getchar();
    }
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9')
    {
        ret = ret * 10 + (c - '0');
    }
    ret *= sgn;
    return 1;
}

template <class T>
inline void write(T x)
{
    if (x > 9)
    {
        write(x / 10);
    }
    putchar(x % 10 + '0');
}

const int MAXN=110;
const double PI=acos(-1.0);

int n;
struct point
{
    double x,y;
};
point points[MAXN];
double ans;

double dfs()
{
    double r=rand();
    r/=RAND_MAX,r*=2*PI;
    double ansx=0,ansy=0;
    for(int i=1;i<=n;i++)
    {
        double ccx=cos(r)*points[i].x-sin(r)*points[i].y;
        double ccy=sin(r)*points[i].x+cos(r)*points[i].y;
        if(ccx>=0)
        {
            ansx+=ccx,ansy+=ccy;
        }
    }
    return sqrt(ansx*ansx+ansy*ansy);
}

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>points[i].x>>points[i].y;
    for(int i=1;i<=1000;i++)
        ans=max(ans,dfs());
    cout<<fixed<<setprecision(13)<<ans<<endl;
}

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

int increment(vector<vector<int>> &c, int parent, int start, int x, vector<ll> &steps,
              vector<ll> &scores) {
    x += steps.at(start);
    scores.at(start) = x;
    for(int node : c.at(start)) {
        if(node == parent){
            continue;
        }
        increment(c, start, node, x, steps, scores);
    }
    return 0;
}

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<vector<int>> c(N);
    vector<ll> scores(N);
    int a, b;
    for(int i = 0; i < N - 1; i++) {
        cin >> a >> b;
        a--;
        b--;
        c.at(a).push_back(b);
        c.at(b).push_back(a);
    }

    int p, x;
    vector<ll> steps(N);
    for(int i = 0; i < Q; i++) {
        cin >> p >> x;
        p--;
        steps.at(p) += x;
    }

    increment(c, -1, 0, 0, steps, scores);

    for(int i = 0; i < N; i++) {
        if(i != 0) {
            cout << " ";
        }
        cout << scores.at(i);
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 32128
<?php
$S = $H = $C = $D = array();
for ($i=1; $i <= 13; $i++) {
  $S[$i] = $i;
  $H[$i] = $i;
  $C[$i] = $i;
  $D[$i] = $i;
}
$count = trim(fgets(STDIN));
for ($i=0; $i < $count; $i++) {
  $inputs = explode(' ', trim(fgets(STDIN)));
  $suit = $inputs[0];
  $num = intval($inputs[1]);
  unset(${$suit}[$num]);
}
print_lost($S, 'S');
print_lost($H, 'H');
print_lost($C, 'C');
print_lost($D, 'D');

function print_lost($losts, $suit) {
  foreach ($losts as $lost) {
    echo $suit.' '.$lost."\n";
  }
}

Measured memory_bytes: 15296
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <random>
#include <time.h>
#include <chrono>
#include <cmath>
using namespace std;

int main() {
    int N, H, W;
    cin >> N;
    cin >> H;
    cin >> W;
    cout << (N - H + 1)*(N - W + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()

txy = [(0,0,0)]
for _ in range(n):
    txy.append(tuple(li()))
 
exist = True

for i in range(n):
    tp,xp,yp = txy[i]
    tn,xn,yn = txy[i+1]
    
    dt = tn-tp
    dx = xn-xp
    dy = yn-yp
    
    if abs(dx) + abs(dy) > dt:
        exist = False
        break
    
    if (dx+dy)%2 != dt%2:
        exist = False
        break
    
if exist:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 17360
import sys
input = sys.stdin.buffer.readline
from operator import itemgetter


class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n

    def root(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.parent[x] > self.parent[y]:
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x

    def is_same(self, x, y):
        return self.root(x) == self.root(y)


def kruskal(n, edges):
    """クラスカル法によって最小全域木の重みを求める"""
    sorted_edges = sorted(edges, key=itemgetter(2))
    uf = UnionFind(n)
    res = 0
    for u, v, cost in sorted_edges:
        if not uf.is_same(u, v):
            uf.merge(u, v)
            res += cost
    return res


n, m = map(int, input().split())
edges = [list(map(int, input().split())) for i in range(m)]


ans = kruskal(n, edges)
print(ans)


Measured memory_bytes: 29024
#include <stdio.h>

int main(void)
{
	double time1,time2;
	int lank1,lank2,lank;
	
	while(scanf("%lf %lf",&time1,&time2)!=EOF)
	{
	if(time1<35.5)
		lank1=1;
	else if(time1<37.5)
		lank1=2;
	else if(time1<40.00)
		lank1=3;
	else if(time1<43.00)
		lank1=4;
	else if(time1<50.00)
		lank1=5;
	else if(time1<55.00)
		lank1=6;
	else if(time1<70.00)
		lank1=7;
	else
		lank1=8;
	
	if(time2<71.00)
		lank2=1;
	else if(time2<77.00)
		lank2=2;
	else if(time2<83.00)
		lank2=3;
	else if(time2<89.00)
		lank2=4;
	else if(time2<105.00)
		lank2=5;
	else if(time2<116.00)
		lank2=6;
	else if(time2<148.00)
		lank2=7;
	else
		lank2=8;
		
	if(lank1<lank2)
		lank=lank2;
	else
		lank=lank1;
	
	if(lank==1)
		printf("AAA\n");
	else if(lank==2)
		printf("AA\n");
	else if(lank==3)
		printf("A\n");
	else if(lank==4)
		printf("B\n");
	else if(lank==5)
		printf("C\n");
	else if(lank==6)
		printf("D\n");
	else if(lank==7)
		printf("E\n");
	else if(lank==8)
		printf("NA\n");
		
	}
	return 0;
}

Measured memory_bytes: 608
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			long K = scan.nextLong();
			long[]a = new long[N];
			long[]b = new long[N];
			Map<Long,Long>map = new TreeMap<Long,Long>();
			for(int i = 0;i<N;i++) {
				a[i] = scan.nextLong();
				b[i] = scan.nextLong();
				if(map.containsKey(a[i])) {
					map.put(a[i], map.get(a[i])+b[i]);
				}else {
					map.put(a[i], b[i]);
				}
			}
			
			long ans = 0;
			for(Long key:map.keySet()) {
				K-=map.get(key);
				if(K<=0) {
					ans = key;
					break;
				}else if(K>0){
					ans = key;
				}
				
			}
			
			
			System.out.println(ans);
			
			
			
			
			
		}
		
		
	}
		

}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007ll
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

#define PRIME_MAX 1000010

bool isp[PRIME_MAX] = {false};
vector<li> primes;

inline void prime_init() {
    repp(i, 2, PRIME_MAX)isp[i] = true;
    repp(i, 2, sqrt(PRIME_MAX) + 2) {
        if (isp[i]) {
            for (li j = 2; i * j < PRIME_MAX; j++) {
                isp[i * j] = false;
            }
        }
    }
    rep(i, PRIME_MAX)if (isp[i])primes.pb(i);
}

inline vector<PI> decom(li x) {
    vector<PI> res;
    rep(i, sz(primes)) {
        li tres = 0;
        while (x % primes[i] == 0) {
            tres++;
            x /= primes[i];
        }
        if (tres > 0)res.pb({primes[i], tres});
        if (x <= 1)break;
    }
    if (x > 1) {
        res.pb({x, 1});
    }
    return res;
}

PI a[100100];


int main() {
    prime_init();
    li a, b;
    cin >> a >> b;
    li g = __gcd(a, b);

    auto d = decom(g);

    li n = sz(d);
    cout << n + 1 << endl;

    return 0;
}


Measured memory_bytes: 2424
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define maxn 1000100
using namespace std;
typedef long long ll;
ll n,k;
ll sans[maxn];
ll s[maxn];
ll chara[maxn];
ll lowbit(ll x)
{
    return x&(-x);
}
void upd(ll x,ll t)
{
    while(x<=n)
    {
        sans[x]+=t;
        x+=lowbit(x);
    }
}
ll sum(ll x)
{
    ll ans=0;
    while(x>0)
    {
        ans+=sans[x];
        x-=lowbit(x);
    }
    return ans;
}


int main()
{
    scanf("%I64d%I64d",&n,&k);
    ll a;
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%I64d",&a);
        s[i]=s[i-1]+a-k;
        chara[cnt++]=s[i];
    }
    s[0]=0;
    ll ans=0;
    sort(chara,chara+cnt);
    int siz=unique(chara,chara+cnt)-chara;
    ll t;
    for(int i=0;i<=n;i++)
    {
        t=lower_bound(chara,chara+siz,s[i])-chara+1;
        ans+=sum(t);
        upd(t,1);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 9984
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#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 SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    typedef tuple<ll, char> t;
    vector<t> v;
    v.push_back(make_tuple(q * 8, 'q'));
    v.push_back(make_tuple(h * 4, 'h'));
    v.push_back(make_tuple(s * 2, 's'));
    v.push_back(make_tuple(d * 1, 'd'));
    sort(v.begin(), v.end(),
        [](t const &lhs, t const &rhs) {
            if (get<0>(lhs) != get<0>(rhs)) return get<0>(lhs) < get<0>(rhs);
            if (get<1>(lhs) != get<1>(rhs)) return get<1>(lhs) < get<1>(rhs);
            return true;
        }
    );
    ll res = 0;
    REP(i, v.size()) {
        switch (get<1>(v[i])) {
            case 'q':
                if (n > 0) {
                    res += 4 * q * n;
                    n = 0;
                }
                break;
            case 'h':
                if (n > 0) {
                    res += 2 * h * n;
                    n = 0;
                }
                break;
            case 's':
                if (n >= 1) {
                    res += s * n;
                    n = 0;
                }
                break;
            case 'd':
                if (n >= 2) {
                    res += d * (n / 2);
                    if (n % 2 == 0)  {
                        n = 0;
                    } else {
                        n = 1;
                    }
                }
                break;
        }
        if (n == 0) {
            break;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _1001
{
	class Program
	{
		String Tree1 = "";
		String Tree2 = "";
		StringBuilder Result = new StringBuilder();

		static void Main(string[] args)
		{
			TextReader input = Console.In;
			if (args.Length > 0)
			{
				input = File.OpenText(args[0]);
			}

			string line = null;
			while ((line = input.ReadLine()) != null)
			{
				var tuple = line.Split(' ');
				var p = new Program();
				p.Tree1 = tuple[1];
				p.Tree2 = tuple[2];

				if (tuple[0][0] == 'i')
				{
					// intersection
					p.Intersection(0, p.Tree1.Length, 0, p.Tree2.Length);
					Console.Out.WriteLine(p.Result.ToString());
				}
				else 
				{
					// union
					p.Union(0, p.Tree1.Length, 0, p.Tree2.Length);
					Console.Out.WriteLine(p.Result.ToString());
				}
			}
		}

		void Intersection(int b1, int e1, int b2, int e2)
		{
			int r1 = FindRoot(Tree1, b1, e1);
			int r2 = FindRoot(Tree2, b2, e2);

			Result.Append('(');

			if ((b1 + 1) < r1 && (b2 + 1) < r2)
			{
				// 左側にノードあり
				Intersection(b1 + 1, r1, b2 + 1, r2);
			}

			Result.Append(',');

			if ((e1 - 2) > r1 && (e2 - 2) > r2)
			{
				// 右側にノードあり
				Intersection(r1 + 1, e1 - 1, r2 + 1, e2 - 1);
			}

			Result.Append(')');
		}

		void Union(int b1, int e1, int b2, int e2)
		{
			int r1 = FindRoot(Tree1, b1, e1);
			int r2 = FindRoot(Tree2, b2, e2);

			Result.Append('(');

			if ((b1 + 1) < r1 || (b2 + 1) < r2)
			{
				// 左側にノードあり
				if ((b1 + 1) >= r1)
				{
					// Tree2だけ
					Result.Append(Tree2.Substring(b2 + 1, r2 - b2 - 1));
				}
				else if ((b2 + 1) >= r2)
				{
					// Tree1だけ
					Result.Append(Tree1.Substring(b1 + 1, r1 - b1 - 1));
				}
				else
				{
					// 両方
					Union(b1 + 1, r1, b2 + 1, r2);
				}
			}

			Result.Append(',');

			if ((e1 - 2) > r1 || (e2 - 2) > r2)
			{
				// 右側にノードあり
				if ((e1 - 2) <= r1)
				{
					// Tree2だけ
					string s = Tree2.Substring(r2 + 1, e2 - r2 - 2);
					Result.Append(s);
				}
				else if ((e2 - 2) <= r2)
				{
					// Tree1だけ
					string s = Tree1.Substring(r1 + 1, e1 - r1 - 2);
					Result.Append(s);
				}
				else
				{
					// 両方
					Union(r1 + 1, e1 - 1, r2 + 1, e2 - 1);
				}

			}

			Result.Append(')');
		}

		int FindRoot(String tree, int b, int e)
		{
			int depth = 0;
			for (int index = b; index <= e; ++index)
			{
				if (tree[index] == '(')
				{
					depth++;
				}
				else if (tree[index] == ')')
				{
					depth--;
				}
				else if (depth == 1) 
				{
					// 深さ1で,を見つけたら、それがルートの位置
					return index;
				}
			}

			return 0;// ここにはこないはず
		}

	}
}

Measured memory_bytes: 5284
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
      int age = Integer.parseInt(reader.readLine());
      switch (age) {
        case 7:
        case 5:
        case 3:
          System.out.println("YES");
          break;
        default:
          System.out.println("NO");
          break;
      }
    }
  }

}


Measured memory_bytes: 20692
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}

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

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
int main() {
	int n, m;
	cin >> n >> m;
	UF tree(n);
	rep(i, 0, m) {
		int a, b, c;
		cin >> a >> b >> c;
		tree.unite(a - 1, b - 1);
	}
	map<int, int> S;
	int ans = 0;
	rep(i, 0, n) {
		if (!S[tree.root(i)]) {
			ans++;
			S[tree.root(i)] = 1;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 5376
import java.util.Scanner;

public class Main {

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

		if(r - l >= 2019) {
			System.out.println(0);
			return;
		}

		l = l % 2019;
		r = r % 2019;

		int tes = 2 * 1000000000;

		if((l * r) % 2019 == 0) {
			System.out.println(0);
			return;
		}

		long min = 2019;

		for(long i = l; i <= r-1; i++) {
			for(long j = i + 1; j <= r; j++) {

				long tmp = (i * j) % 2019;
				min = (min <= tmp) ? min : tmp;

			}
		}

		System.out.println(min);
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define n 500000
#define mem(arr) memset(arr, 0, sizeof(arr))
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
void solve();
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int times = 1;
//	cin >> times;
	for(int i=0; i<times; i++)
	{
		solve();
		cout << '\n';
	}
	return 0;
}

int a, b, c, d, e, f, g, h;
int arr[n + 50], arr1[n + 50], arr2[n + 50];

//type here

void solve()
{
	char tmp;
	cin >> tmp;
	tmp ++;
	if(tmp > 'z') tmp = 'a';
	cout << tmp << '\n';
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>
#include <stack>
#include <set>
#include <map>
#

#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define ALLOF(c) c.begin(), c.end()
#define RANGEOF(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
#define INF 1000000000
using namespace std;

typedef complex<int> POINT;
template <class T>
class vevector : public vector<vector<T>>
{
public:
	using vector<vector<T>>::operator []; 
	T& operator [](const POINT &index) { return (*this)[index.real()][index.imag()]; }
};

template <class T> T read() { T t; cin >> t; return t; }
template <> POINT read<POINT>() { int x, y; cin >> x >> y; return POINT(x, y); }
template <class T> vector<T> read(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i,n) v.push_back(read<T>(m)); return v; }
template <class T> void write(const T &t) { cout << t << endl; }
template <class T> void write(const T &t, const T &t2) { cout << t << ' ' << t2 << endl; }

template <class T> void write(const vector<T> &v)
{
	ostringstream ss; 
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	cout << s.substr(0, s.length() - 1) << endl;
}

template <class T> string toString(const T &t) { stringstream ss; ss << t; return ss.str(); }

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__
#define countof(a) (sizeof(a)/sizeof(a[0]))

void solve();
int main() { solve(); return 0; }

vector<unsigned char> isPrime;
vector<int> primes;
void initPrimes(int n)
{
	isPrime = vector<unsigned char>(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	FOR(i, 2, n)
	{
		if (!isPrime[i]) continue;
		primes.push_back(i);
		for (int j = i * 2; j <= n; j += i)
			isPrime[j] = false;
	}
}

/// template end ///

void solve()
{
	initPrimes(200000);
	REP (testcase, INF)
	{
		READ(int, N, P);
		if (N < 0) { break; }

		vector<int> candidates;
		int startIndex = upper_bound(ALLOF(primes), N) - primes.begin();

		REP(i,P) REP(j,P) candidates.push_back( primes[i + startIndex] + primes[i + j + startIndex]);
		partial_sort(candidates.begin(), candidates.begin() + P, candidates.end());
		write(candidates[P - 1]);
	}
}

Measured memory_bytes: 1540
#include <stdio.h>

int main(){
  char nums[5];  scanf("%s", nums);
  int ans;
  for(int bit=0; bit<(1<<3); bit++){
    int calc = (int)(nums[0]-'0');
    for(int j=0; j<3; j++){
      if(bit & (1<<j))
	calc = calc + (int)(nums[j+1]-'0');
      else
	calc = calc - (int)(nums[j+1]-'0');
    }
    if(calc == 7){
      ans = bit;
      break;
    }
  }
  printf("%c", nums[0]);
  for(int i=0; i<3; i++){
    if(ans & (1<<i))
      printf("+");
    else
      printf("-");
    printf("%c", nums[i+1]);
  }
  printf("=7\n");
  return 0;
}
    


Measured memory_bytes: 128
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		List <Integer> list = new LinkedList<Integer>();
		ListIterator<Integer> listIter = list.listIterator();
		try (Scanner sc = new Scanner (System.in)){
			int n = sc.nextInt();
			for (int i = 0; i < n; i++) {
				int command = sc.nextInt();
				switch (command) {

				case 0:
					int x = sc.nextInt();
					listIter.add(x);
					listIter.previous();
					break;

				case 1:
					int d = sc.nextInt();
					if (d > 0) {
						for (int j = 0; j < d; j++) {
							listIter.next();  
						}
					} else if (d < 0){
						int a = -d; 
						for (int j=0; j<a; j++) {
							listIter.previous(); 
						}
					}
					break;
					
				case 2:
					listIter.next();  
					listIter.remove();
					break;
				}
			}
			ListIterator<Integer> ite = list.listIterator();			
			while (ite.hasNext()) {
				System.out.println(ite.next());  
			}
		}
	}
}




Measured memory_bytes: 309628
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

mod=10**9+7
fcl=[1]*(n+1)
for i in range(1,n+1):
  fcl[i]=(fcl[i-1]*i)%mod
def comb(x,y,p):
  return ((fcl[x]*pow(fcl[y],p-2,p))%mod*pow(fcl[x-y],p-2,p))%mod

maxs=0
for i in range(k,n+1):
  maxs+=a[i-1]*comb(i-1,k-1,mod)
  maxs%=mod
mins=0
for i in range(n-k+1):
  mins+=a[i]*comb(n-i-1,k-1,mod)
  mins%=mod
ans=(maxs-mins)%mod
print(ans+mod if ans<0 else ans)

Measured memory_bytes: 14416
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

ll gcd(ll a,ll b){
  if(a%b == 0) return b;
  else return gcd(b,a%b);
}
int main(){
  bool p[1000000];
  for(int i=2;i<1000000;i++){
    p[i] = true;
  }
  p[1] = false;
  for(int i=2;i<1000000;i++){
    if(!p[i]) continue;
    for(int j=2;j<1000000/i;j++) p[j*i] = false;
  }
  ll x;
  cin >> x;
  ll ans = -1;
  for(int i=x;i<1000000;i++){
    if(p[i]){
      ans = i;
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N,R;
    cin >> N >> R;
    int ans = 0;
    if(N<10){
        ans = R+100*(10-N);
    }else{
        ans = R;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
l=make_divisors(n)
if l[-1]**2==n:print((l[-1]-1)*2)
else:print(l[-2]-1+l[-1]-1)

Measured memory_bytes: 3268
#include<stdio.h>
#define NM 1000000
#define QM 50000
#define NOT_FOUND -1

int binarySearch(int *A,int key,int length){
  
  int mid,left = 0,right = length;
  
  while(left < right){
    mid = (left + right)/2;
    if(key == A[mid]) return mid;
    if(key > A[mid]) left = mid +1;
    else if(key < A[mid]) right = mid;
  }
  return NOT_FOUND;
}
  

int main(){

  int i,j,count=0,x,y,A[NM],B[QM],k;

  scanf("%d",&x);

  for(i=0;i<x;i++) scanf("%d",&A[i]);

  scanf("%d",&y);

  for(i=0;i<y;i++) scanf("%d",&B[i]);

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

    k = binarySearch(A,B[i],x);
    if(k >= 0) count++;

  }
    

  printf("%d\n",count);

  return 0;
}



Measured memory_bytes: 2332
#include <iostream>
using namespace std;
int main(void) {
  int n;
  int i = 1;
  
  while(1) {
      cin >> n;
      if(n == 0) {
          break;
      }
      cout << "Case " << i << ": " << n << endl;
      ++i;
  }
  return 0;
}



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

using namespace std;
typedef long long ll;
typedef double ld;
#define MAX (1LL << 63LL) - 1LL
#define MIN (-1LL) * (1LL << 63LL) + 1LL

ll n;
ll ss = 1000000007;
ll gap = 1;
ll gap3 = 1;
ll gap2 = 1;

int main(void)
{
	scanf("%lld", &n);
	
	for(ll i = 0 ; i < n ; i++)
	{
		gap = (gap * 10) % ss;
		gap3 = (gap3 * 9) % ss;
		gap2 = (gap2 * 8) % ss;
	}
	
	gap = gap - (gap3 * 2) % ss + gap2;
	
	printf("%lld", gap % ss < 0 ? gap % ss + ss : gap % ss);
	return 0;
}

Measured memory_bytes: 3864
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

def ceil(x,y):
  return (x-1)//y+1
n,a,b=map(int,input().split())
if abs(b-a)%2==0:
    print(abs(b-a)//2)
else:
    if a>b: a,b=b,a
    s1=a
    b1=b-s1
    k1=(b1-1)//2+s1
    s2=n-b+1
    a2=a+s2
    k2=(n-a2)//2+s2
    print(min(k1,k2))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ui N; cin >> N;
  string S; cin >> S;
  vector<ui> res(N);

  ui cnt{};
  for(int i = 0; i < N; ++i)
  {
    res[i] += cnt;
    if(S[i] == 'E')
      ++cnt;
  }

  cnt = 0;
  for(int i = N -1; i >= 0; --i)
  {
    res[i] += cnt;
    if(S[i] == 'W')
      ++cnt;
  }

  auto ans = *boost::max_element(res);
  cout << (N - 1 - ans) << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 1812
#include <iostream>
#include <cmath>
#include <string.h> 
#include <vector>
#include <bits/stdc++.h> 
#include <iomanip>
#include<algorithm> 
#include <string> 
using namespace std;

int main(){
    int n,w;
    cin>>n>>w;
    int wt[n]; int val[n];
    for(int i=0;i<n;i++){
        int a1,b1;
        cin>>a1>>b1;
        wt[i]=a1; val[i]=b1;
    }
    long long int K[n+1][w+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++){
            if(i==0||j==0) K[i][j]=0;
            else if(wt[i-1]<=j){
                K[i][j] = max(val[i-1]+K[i-1][j-wt[i-1]],K[i-1][j]);
            }
            else K[i][j]=K[i-1][j];
        }
    }
    cout<<K[n][w];
    return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stack>
using namespace std;
const int maxn=1e6;
typedef long long ll;
int a,b,c;
int x,y;
int main()
{
    scanf("%d%d%d",&a,&b,&c);
    if(a>b){x=a;y=b;}
    else{x=b;y=a;}
    if(y<=c&&c<=x){printf("Yes\n");}
    else{printf("No\n");}
}


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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll h, w;
	cin >> h >> w;
	ll p = h * w;
	if (h == 1 || w == 1)
		cout << 1;
	else if (p % 2 == 0)
		cout << p / 2;
	else
		cout << p / 2 + 1;
	return 0;
}


Measured memory_bytes: 3628
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

ll dp[60][60][2510];

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

    int n, a; cin>>n>>a;
    vector<int> x(n);
    for(int i=0; i<n; i++) cin>>x[i];

    dp[0][0][0] = 1;
    for(int i=0; i<n; i++){
        for(int j=0; j<=i; j++){
            for(int k=0; k<=2500; k++){
                if(k + x[i] <= 2500){
                    dp[i+1][j+1][k+x[i]] += dp[i][j][k];
                }

                dp[i+1][j][k] += dp[i][j][k];
            }
        }
    }

    ll ans = 0;
    for(int i=1; i<=n; i++){
        ans += dp[n][i][a*i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 59648
# -*- coding: utf-8 -*-
import math

def main():
    """Function."""
    a, b = map(str, input().split())

    num = int(a + b)
    if math.sqrt(num) % 1 == 0:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template <typename P, typename Q>
ostream& operator<<(ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T> v)
{
  os << "(";
  each (i, v)
    os << i << ",";
  os << ")";
  return os;
}

int main(int argc, char* argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  int a, b;
  while (cin >> n >> m >> a >> b) {
    vector<int> x(n);
    vector<int> y(m);
    each (i, x)
      cin >> i;
    each (i, y)
      cin >> i;
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    a = max(a, x.back()) + 1;
    b = min(b, y.front());
    cout << (a <= b ? "No War" : "War") << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.array, std.algorithm, std.conv, std.typecons, std.numeric, std.math;

void main()
{
    auto nw = readln.split.to!(int[]);
    auto N = nw[0];
    auto W = nw[1];
    int[] vs, ws;
    foreach (_; 0..N) {
        auto vw = readln.split.to!(int[]);
        vs ~= vw[0];
        ws ~= vw[1];
    }

    auto DP = new int[][](N+1, W+1);
    foreach (i; 0..N) {
        foreach_reverse (j; 0..W+1) {
            auto w = j-ws[i];
            if (w >= 0) {
                DP[i][w] = max(DP[i][w], DP[i][j] + vs[i]);
            }
            DP[i+1][j] = max(DP[i+1][j], DP[i][j]);
        }
    }
    int r = -1;
    foreach (dp; DP[N]) r = max(r, dp);
    writeln(r);
}


Measured memory_bytes: 6372
N = int(input())
A = [0] + [int(x) for x in input().split()] + [0]

B = []
for i in range(1,N+2) :
    B.append(abs(A[i] - A[i-1]))

C = []
for i in range(2,N+2) :
    C.append(abs(A[i] - A[i-2]))

tlen = sum(B)
for i in range(N) :
    print(tlen - B[i] - B[i+1] + C[i])


Measured memory_bytes: 16688
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        String S = sc.next();
        
        String ans = S;
        if(S.length() > K) {
            ans = S.substring(0,K) + "...";
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 38492
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define CAT(a,b)a b
#define VASIZE(a,b,N,...)N
template<class T>auto size(T&&a)->decltype(a.size(), int()) { return a.size(); }
template<class T>typename make_signed<decltype(T() % 0)>::type size(T a) { return a; }
#define REP(t,a,N)for(decltype(size(N))t=size(a),_l##t=size(N);t<_l##t;t++)
#define RREP(t,a,N)for(decltype(size(N))t=size(N)-1,_l##t=size(a);t>=_l##t;t--)
#define rep(t,...)CAT(REP,VASIZE(__VA_ARGS__,(t,__VA_ARGS__),(t,0,__VA_ARGS__)))
#define rrep(t,...)CAT(RREP,VASIZE(__VA_ARGS__,(t,__VA_ARGS__),(t,0,__VA_ARGS__)))
#define all(a)begin(a),end(a)

void Calc();
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner
{
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for ( A&i : a ) cin >> i; return a; }
  string Line() { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/
ll solve(ll a, ll b, ll c)
{
  ll ab = a * b;
  ll ans = abs(ab * (c / 2) - ab*(c / 2 + c % 2));
  amin(ans, abs(ab*(c / 2 + c % 2) - ab*(c / 2)));
  return ans;
}
void Calc()
{
  ll a, b, c;
  in, a, b, c;
  ll ans = solve(a, b, c);
  amin(ans, solve(a, c, b));
  amin(ans, solve(b, c, a));
  cout << (ans) << endl;

}


Measured memory_bytes: 256