akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		String[] S = new String[N];
		for (int i = 0; i < N; i++)
			S[i] = sc.next();
		long[] a = new long[5];
		for (int i = 0; i < N; i++) {
			if (S[i].charAt(0) == 'M')
				a[0]++;
			else if (S[i].charAt(0) == 'A')
				a[1]++;
			else if (S[i].charAt(0) == 'R')
				a[2]++;
			else if (S[i].charAt(0) == 'C')
				a[3]++;
			else if (S[i].charAt(0) == 'H')
				a[4]++;
		}
		long s = 0;
		s = a[0] * a[1] * a[2] + a[0] * a[1] * a[3] + a[0] * a[1] * a[4] + a[0] * a[2] * a[3] + a[0] * a[2] * a[4]
				+ a[0] * a[3] * a[4] + a[1] * a[2] * a[3] + a[1] * a[2] * a[4] + a[1] * a[3] * a[4]
				+ a[2] * a[3] * a[4];
		System.out.println(s);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 33208
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
ll n,h[100001];
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n){
		cin>>h[i];
	}
	int ans=1,now=0;
	for(int i=n-1;i>=1;i--){
		now++;
		ans=max(ans,now);
		if(h[i]>h[i-1])
		now=0;
	}
	now++;
	ans=max(ans,now);
	cout<<ans-1;
	re 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int N,ans;

signed main(){
  cin>>N;
  vector<int> l(N);
  for(int i=0;i<N;i++)cin>>l[i];
  sort(l.begin(),l.end());
  for(int i=2;i<N;i++)
    for(int j=1;j<i;j++)
      for(int k=0;k<j;k++)
        if(l[k]+l[j]>l[i])ans++;
  cout<<ans<<endl;
}


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

#define v vector
#define ll long long 
#define vpll vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define lf long float
#define pb push_back
#define pii pair<int,int>
#define pci pair<char,int>
 
using namespace std; 


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    s[k-1] = ((s[k-1]-'A')+'a');
    cout<<s;
    return 0;
}

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

int main() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    s = list(map(int,input().split()))

    if (s[0] / 2.0 == s[2]) and (s[1] / 2.0 == s[3]):
        print(s[0] * s[1] / 2.0, 1)
    else:
        print(s[0] * s[1] / 2.0, 0)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,d,ans=0;
	cin>>n>>d;
		vvl vv(n,vl(d));
	rep(i,n)rep(j,d){
		cin>>vv[i][j];
	}
	rep(i,n){
		rep(j,i){
			ll sum=0;
			rep(k,d)sum+=(vv[i][k]-vv[j][k])*(vv[i][k]-vv[j][k]);
			for(int l=1;l*l<=sum;l++){
				if(l*l==sum)ans++;
			}
		}
	}
	cout<<ans<<endl;
}


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

int main(){
  int i, j, N, a;
  int min=0x7fffffff;
  scanf("%d", &N);
  
  for(i=0;i<N;i++){
    scanf(" %d", &a);
    for(j=0;;j++){
      if((a>>j)&0x1)break;
    }
    if(min>j)min=j;
  }
  
  printf("%d\n", min);
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int X, A;
	cin >> X >> A;

	if (X < A) {
		cout << 0 << endl;
	} else {
		cout << 10 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import collections

N, M = map(int, input().split())

ways = collections.defaultdict(set)
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    ways[a].add(b)
    ways[b].add(a)

dist = [-1] * N
q = collections.deque()

dist[0] = True
q.append(0)

while q:
    n = q.popleft()
    for adjacent in ways[n]:
        if dist[adjacent] != -1:
            continue
        dist[adjacent] = dist[n] + 1
        q.append(adjacent)


if -1 in dist:
    print('No')
else:
    print('Yes')
    for n, d in enumerate(dist):
        if n == 0:
            continue
        for adjacent in ways[n]:
            if d - 1 == dist[adjacent]:
                print(adjacent + 1)
                break


Measured memory_bytes: 133112
# coding: utf-8
# Your code here!

"""
01-BFS
辺の重みが0 or 1 のとき、dequeを使ってdijkstraを高速化できる
"""
from collections import deque
def bfs01(g,start):
    n = len(g)
    res = [float("inf")]*n #startからの最短距離
    res[start] = 0
    pending = n-1 #未確定の点の個数
    q = deque([(0,start)]) #(そこまでの距離、点)
    while q and pending:
        dv,v = q.popleft()
        if res[v] < dv: continue
        pending -= 1
        #if v==goal: break
        for to,cost in g[v]:
            if dv + cost < res[to]:
                res[to] = dv + cost
                if cost: q.append((res[to],to))
                else: q.appendleft((res[to],to))
    return res

######################################################################
#ARC084 small multiple
#
######################################################################

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

k = int(input())

g = [[] for _ in range(k)]
for i in range(k):
    g[i].append(((i+1)%k,1))
    g[i].append((10*i%k,0))

res = bfs01(g,1)
print(res[0]+1)


Measured memory_bytes: 38508
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

long long const MOD = 1000000007LL;

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

    vector<pair<long, long> > store(n);
    for (int i = 0; i < n; i++) {
        int yen, hon;
        cin >> yen >> hon;
        store[i] = make_pair(yen, hon);
    }

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

    long long res = 0;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (sum + store[i].second > m) {
            res += (m - sum) * store[i].first;
            sum += m - sum;
        } else {
            res += store[i].first * store[i].second;
            sum += store[i].second;
        }

        if (sum == m) break;
    }

    cout << res << endl;
}


Measured memory_bytes: 1920
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, ans;
std::vector<LL> A;

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

	ans=114514810;
	rep(i,N)
	{
		int cou=0;
		while(A[i]%2==0)
		{	A[i]/=2;++cou;}
		ans=std::min<LL>(ans,cou);
	}

	out<<ans<<std::endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
arr = list(map(int,input().split()))

arr.reverse()

now = arr[0]
flag = True
for i in range(1,n):
    if arr[i] > now+1:
        flag = False
        break
    elif arr[i] == now or arr[i] == now+1:
        continue
    else:
        now = arr[i]

if flag:
    print("Yes")
else:
    print("No")






Measured memory_bytes: 14396
n,m=map(int,input().split())
arr=[0]+list(map(int,input().split()))
g=[[] for _ in range(n+1)]
for _ in range(m):
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
ans=0
for v in range(1,n+1):
 for u in g[v]: #i番目の展望台から1本の道を通っていけるすべての展望台と高さを比較する
   if arr[u]>=arr[v]:
     break
 else: #i番目の展望台の高さが他のすべての展望台の高さより真に大きければ答えを1増やす
   ans+=1
print(ans)

Measured memory_bytes: 29520
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
const ll MOD = 1000000007;
 
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}
 
#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll a,b,c,k;

    cin >> a >> b >> c >> k;

    while(a>=b){
        b*=2;
        k--;
        print(a,b,c,k)
    }

    while(b>=c){
        c*=2;
        k--;
        print(a,b,c,k)
    }

    string ans = "Yes";

    if(k<0){
        ans = "No";
    }
    
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define lli long long int

using namespace std;

int main()
{
  int n;
  cin>>n;
  lli a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  lli maxd=0;
  for(int i=0;i<n-1;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      lli d=abs(a[i]-a[j]);
      if(maxd<d)
      {
        maxd=d;
      }
    }
  }
  cout<<maxd<<endl;
  return 0;
}


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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
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; }

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353




int main() {
    string s; cin >> s;
    rep(i,3){
        int x =  10 - (s[i] -'0');
        s[i] = x + '0';
    }
    cout << s << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N;
  int p[110];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  for (int i = 100; i >= 0; i--) {
    int cnt = 0;
    for (int j = 0; j < N; j++) {
      cnt += p[j] >= i;
    }
    if (cnt < i) continue;
    cout << i << endl;
    break;
  }

  return 0;
}


Measured memory_bytes: 3188
#include<stdio.h>
#include<iostream>
#include<algorithm>
#define debug freopen("in.txt","r",stdin); freopen("out.txt","w",stdout)
using namespace std;
const int MAXN=20;
typedef long long ll;
int a[MAXN][MAXN],temp[MAXN],ans[MAXN],mon[MAXN];
int n,m,x,sum=0,price=1e9;
int main()
{
	cin>>n>>m>>x;
	for(int i=0;i<n;i++){
		cin>>mon[i];
		for(int j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			if((i>>j)&1){
				for(int k=0;k<m;k++){
					ans[k]+=a[j][k];
				}
				sum+=mon[j];
			}
		}
		int flag=0;
		for(int j=0;j<m;j++){
			if(ans[j]<x){
				flag=1;
				break;
			}
		}
		if(!flag) price=min(price,sum);
		sum=0;
		for(int j=0;j<n;j++){
			if((i>>j)&1){
				for(int k=0;k<m;k++){
					ans[k]-=a[j][k];
				}
			}
		}
	} 
	if(price==1e9) cout<<-1<<'\n';
	else cout<<price<<'\n';
	return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int x;
	cin>>x;
	int a=100,ans=0;
	while(a<x)
	{
		a+=(a/100);
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3608
#if defined(LOCAL)
#define PROBLEM_NAME "c"
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define I(x, ...) (x)
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define I(x, ...) (x)
#define C(x, ...) ;
#include <bits/stdc++.h>
#endif

using namespace std;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ii = pair<int,int>; using lu = unsigned long long; using l = long long;
using vs = vector<string>; using vii = vector<ii>;
using vl = vector<l>; using vvl = vector<vl>; using vvvl = vector<vvl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(c) - 1; a >= l(b); a--)
#define VVL(x, a, b, i) vvl x(a, vl(b, l(i)));
#define VVVL(x, a, b, c, i) vvvl x(a, vvl(b, vl(c, l(i))));

void solve(istream& cin, ostream& cout) {
  l n; cin >> n;
  string s; cin >> s;
  vl ww(n + 1), ee(n + 1);
  F(i, 0, n) {
    ww[i + 1] = ww[i];
    if (s[i] == 'W') ww[i + 1]++;
  }
  B(i, 0, n) {
    ee[i] = ee[i + 1];
    if (s[i] == 'E') ee[i]++;
  }
  l z = n;
  F(i, 0, n) z = min(z, ww[i] + ee[i + 1]);
  cout << z << lf;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


Measured memory_bytes: 5396
X = int(input())
def check(mid):
    if mid%2 == 0:
        point = 11*mid//2
    else:
        point = 6*(mid//2+1)+5*(mid//2)
    return point >= X
left = 0
right = 10**18
while right-left > 1:
    mid = (right+left)//2
    if check(mid):
        right = mid
    else:
        left = mid
if check(left):
    print(left)
else:
    print(right)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
const int Mod=1e9+7;
const int MAXN=1e6+10;
int n,k;
ll Ans,Tot,Mi[MAXN]={1};
inline int Read()
{   rg int a=0,c=1;   rg char b=getchar();
	while(b!='-'&&(b<'0'||b>'9'))b=getchar();
	if(b=='-')c=-1,b=getchar();
	while(b>='0'&&b<='9')a=a*10+b-48,b=getchar();
	return a*c;
}
inline ll Fast(rg ll Di,rg ll Mi)
{   ll Back=1;
	while(Mi>=1)
	{   if(Mi&1)  Back=(Back*Di)%Mod;
		Di=(Di*Di)%Mod;   Mi>>=1;
	}
	return Back;
}
int main()
{   n=Read();   k=(n+1)/2;
	for(rg int i=1;i<=n;i++)  Mi[i]=(Mi[i-1]*i)%Mod;
	for(rg int i=k;i<=n-1;i++)
	{   ll x=2*i-n,y=n-i-1,Now=0,Size=Tot;
		Now=((Mi[i-1]*Fast(Mi[x]*Mi[y]%Mod,Mod-2)%Mod)*Mi[i]%Mod*Mi[y])%Mod;
		Tot=Now;   Now-=Size;   Now=(Now%Mod+Mod)%Mod;
		Ans=(Ans+1ll*Now*i)%Mod;
	}
	printf("%lld\n",Ans);
}


Measured memory_bytes: 8064
#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 = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int main()
{

    ll x;
    cin >> x;
    ll cur = 100;
    ll ans = 0;
    while (cur < x)
    {
        cur = cur + (cur / 100);
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
import sys
 
stdin = sys.stdin
 
ni = lambda:int(ns())
na = lambda:list(map(int,stdin.readline().split()))
ns = lambda:stdin.readline().rstrip()  # ignore trailing spaces

N = ni()
answer = 0
cur = 1
while cur * (cur + 2) <= N:
    y = N - cur
    if y % cur != 0:
        cur += 1
        continue
    x = y // cur
    if x > cur:
        #print(cur)
        answer += x
    cur += 1
print(answer)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		sc.close();
		if(x == y) {
			System.out.println(0);
		}else if(-x == y) {
			System.out.println(1);
		}else if(x < 0 && y < 0) {
			if(Math.abs(x) <= Math.abs(y)) {
				System.out.println(2 + Math.abs(y - x));
			}else {
				System.out.println(Math.abs(y - x));
			}
		}else if(x < 0 && y > 0) {
			if(Math.abs(x) <= Math.abs(y)) {
				System.out.println(1 + Math.abs(y + x));
			}else {
				System.out.println(Math.abs(y + x) + 1);
			}
		}else if(x > 0 && y < 0) {
			System.out.println(1 + Math.abs(y + x));
		}else if(x > 0 && y > 0){
			if(Math.abs(x) <= Math.abs(y)) {
				System.out.println(Math.abs(y - x));
			}else {
				System.out.println(2 + Math.abs(y - x));
			}
		}
		if(x == 0 && y == 0) {
			System.out.println(0);
		}else if(x == 0 && y > 0) {
			System.out.println(y);
		}else if(x == 0 && y < 0) {
			System.out.println(-y + 1);
		}else if(x > 0 && y == 0) {
			System.out.println(x + 1);
		}else if(x < 0 && y == 0) {
			System.out.println(-x);
		}

	}
}

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

using namespace std;
typedef long long ll;

int N, X;
vector<int> A;
ll sum = 0;
int ans = 0;



int calc(){
    if(X>sum) return N-1;
    if(X==sum) return N;
    for(int i=0; i<N; i++){
        if(X>=A[i]){
            ans++;
            X -= A[i];
        } else break;
    }
    return ans;
}


int main() {
    cin >> N >> X;
    A.resize(N);
    for(int &a:A){
        cin >> a;
        sum += a;
    }
    sort(A.begin(), A.end());
    
    cout << calc() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int main(){
	string S,T;

	cin >> S >> T;
	int R[26],R2[36];
	memset(R,-1,sizeof(R));
	memset(R2,-1,sizeof(R2));
	
	bool ans = true;

	REP(i,S.length()){
		R[S[i]-'a']++;
		R2[T[i]-'a']++;
	}
	sort(R,R+26);
	sort(R2,R2+26);
	REP(i,26){
		if (R[i] != R2[i]) ans = false;
	}

	if (ans) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int X,Y,A,B,C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> red(A),green(B),no(C);
    REP(i,A) cin >> red[i];
    REP(i,B) cin >> green[i];
    REP(i,C) cin >> no[i];
    sort(ALL(red));
    sort(ALL(green));
    sort(ALL(no));
    reverse(ALL(red));
    reverse(ALL(green));
    reverse(ALL(no));
    priority_queue<int> q;
    REP(i,X) q.push(red[i]);
    REP(i,Y) q.push(green[i]);
    REP(i,C) q.push(no[i]);
    ll ans = 0;
    REP(i,X+Y) {ans += q.top(); q.pop();}
    cout << ans << endl;
}

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

Measured memory_bytes: 6420
'use strict';

function main(arg) {
    let X = arg.split("\n")[0].split(" ").map(n=>parseInt(n))[2];
    let Y = arg.split("\n")[0].split(" ").map(n=>parseInt(n))[3];
    
    let x = arg.split("\n")[1].split(" ").map(n=>parseInt(n));
    let y = arg.split("\n")[2].split(" ").map(n=>parseInt(n));
    
    x.push(X);
    y.push(Y);
    
    if(Math.max(...x) < Math.min(...y)) {
            console.log("No War");
            return;
    }
    
    console.log("War")
    
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7624
N = int(raw_input())
A = map(int, raw_input().split())

def selectionSort(A, N):
    count = 0
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            temp = A[i]
            A[i] = A[minj]
            A[minj] = temp
            count += 1
    return count

count = selectionSort(A, N)

print " ".join(map(str, A))
print count

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

const int MAX = 510000;
const int mod = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

//mod mでの a の逆元を求める
long long modinv(long long a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod; 
    if (u < 0) u += mod;
    return u;
}

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




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

    ll b,w;
    cin>>b>>w;
    COMinit();
    ll n = b+w;
    ll p=0,q=0;
    for(int i=1;i<=n;i++){
        ll ans = (q + (1LL - p - q + 2LL*mod)%mod*inv[2]%mod)%mod;
        cout << ans <<"\n";
        p += modinv(modpow(2,i)) * COM(i-1,b-1)%mod;
        q += modinv(modpow(2,i)) * COM(i-1,w-1)%mod;
        if(p>=mod) p-=mod;
        if(q>=mod) q-=mod;
    }

    
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}
 
int main() { 
    int n;
    cin >> n;
    int k = n % 10;
    if(k == 2 || k == 4 || k == 5 || k == 7 || k == 9) cout << "hon" << endl;
    else if (k == 3) cout << "bon" << endl;
    else cout << "pon" << endl;
}

Measured memory_bytes: 3604
import heapq

N, M = map(int, input().split())
jobs = {m: [] for m in range(1, M + 1)}
for _ in range(N):
    a, b = map(int, input().split())
    if a in jobs:
        jobs[a].append(b)

q = []
ans = 0
for m in range(1, M + 1):
    for b in jobs[m]:
        heapq.heappush(q, -b)
    if len(q) > 0:
        neg_b = heapq.heappop(q)
        ans += -neg_b

print(ans)


Measured memory_bytes: 27232
<?php
fscanf(STDIN, "%d %d", $h, $w);
$n = 0;
for ($i = 0; $i < $h; $i++) {
	$s[] = trim(fgets(STDIN));
	$n += substr_count($s[$i], '.');
}
$vs = [[1,0],[0,1],[-1,0],[0,-1]];
$ex = $h - 1;
$ey = $w - 1;
$tmp[] = [0, 0, 1];
while ($tmp) {
	list($x, $y, $z) = array_shift($tmp);
	$st = $z + 1;
	foreach ($vs as $v) {
		$nx = $x + $v[0];
		$ny = $y + $v[1];
		if ($nx == $ex && $ny == $ey) {
			$n -= $st; exit("$n");
		}
		if (isset($s[$nx][$ny]) && $s[$nx][$ny] == '.') {
			$s[$nx][$ny] = '#';
			$tmp[] = [$nx, $ny, $st];
		}
	}
}
echo '-1';

Measured memory_bytes: 4604
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#define rtn return
#define endl '\n'
#define F first
#define S second
#define mt make_tuple
#define pb push_back
#define int long long
#define value_at find_by_order
#define index_of order_of_key
#define fill(a, v) memset(a,v,sizeof(a))
#define copy(a, b) memcpy(b,a,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i, n) for(int i=0;i<(int)n;++i)
#define per(i, n) for(int i=(int)n-1;i>=0;--i)
#define rep1(i, n) for(int i=1;i<=(int)n;++i)
#define per1(i, n) for(int i=(int)n;i>=1;--i)
#define loop(i, begin, end) for(int i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef string str;
typedef long double db;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<db> vdb;

template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;
const db EPS = 1e-15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

bool isP(str s, int l, int r) {
  while (l < r) {
    if (s[l] != s[r])
      rtn false;
    l++; r--;
  }
  rtn true;
}

int32_t main() {
  FAST_IO;
  str s;
  cin >> s;
  int n = s.size();
  if (isP(s, 0, n - 1) && isP(s, 0, (n - 1) / 2 - 1) && isP(s, (n + 3) / 2 - 1, n - 1)) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  rtn 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 0) {
				break;
			} else {
				for (int i = 0; i < H; i++) {
					for (int j = 0; j < W; j++) {
						if ((i + j) % 2 == 0) {
							System.out.print("#");
						} else if ((i + j) % 2 == 1) {
							System.out.print(".");
						} else {
						}
					}
					System.out.println("");
				}
				System.out.println("");
			}
		}
	}
}


Measured memory_bytes: 32992
#include <iostream>


int main() {
	int K, N;
	int previousBuffer = -1;
	int buffer;
	int firstElement = 0;
	int maxGap = 0;
	int result = 0;
	int count = 0;
	int flag = 0;

	std::cin >> K >> N;
	for (int i = 0; i < N; i++) {
		std::cin >> buffer;
		if (i == 0) {
			firstElement = buffer;
		}
		if (previousBuffer != -1) {
			int bufferFlag = 1;
			int distance = std::abs(buffer - previousBuffer);
			int otherDistance = std::abs(K - std::max(buffer, previousBuffer) + std::min(buffer, previousBuffer));

			if (distance > otherDistance) {
				bufferFlag = -1;
				distance = otherDistance;
			} else {
				distance = distance;
			}

			distance = std::min(distance, std::abs(K - std::max(buffer, previousBuffer) + std::min(buffer, previousBuffer)));
			if (distance > maxGap) {
				count = i;
				maxGap = distance;
				flag = bufferFlag;
			}
		}
		previousBuffer = buffer;
	}

	if (N == 2) {
		std::cout << maxGap;
		return 0;
	}

	int distance = std::abs(previousBuffer - firstElement);
	distance = std::min(distance, std::abs(K - std::max(firstElement, previousBuffer) + std::min(firstElement, previousBuffer)));
	if (distance >= maxGap) {
		maxGap = distance;
		result = flag == -1 ? maxGap : K - maxGap;
		std::cout << result;
		return 0;
	}

	if (count == N - 1) {
		result = flag != 1 ? maxGap : K - maxGap;
	} else {
		result = K - maxGap;
	}



	/*
	if (count - 1 > N - count - 1) {
		result = flag != 1 ? maxGap : K - maxGap;
	} else if (count - 1 == N - 1 - count) {
		result = std::min(maxGap, K - maxGap);
	} else {
		result = flag == 1 ? maxGap : K - maxGap;
	}
	*/


        std::cout << result;




}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	string s;
	cin>>s;
	rep(i,s.size()){
		cout<<(char)('A'+(s[i]-'A'+n)%26);
	}
	cout<<endl;
}


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

int N, M, Q;
string S;
int s0[2002][2002],s1[2002][2002],s2[2002][2002];

int main() {
  cin >> N >> M >> Q;

  for(int i = 1; i <= N; i++) {
    cin >> S;
    for(int j = 1; j <=S.length(); j++) {
      s0[i][j] = S[j-1]-'0';
      s1[i][j] = s0[i][j] & s0[i][j-1];
      s2[i][j] = s0[i-1][j] & s0[i][j];
      //  cout << s0[i][j] << "   " << s1[i][j] << "   " <<s2[i][j] <<endl;
      
    }
  }

  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= M; j++) {
      s0[i][j] += s0[i][j-1];
      s1[i][j] += s1[i][j-1];
      s2[i][j] += s2[i][j-1];
    }
    for(int j = 1; j <= M; j++) {
      s0[i][j] += s0[i-1][j];
      s1[i][j] += s1[i-1][j];
      s2[i][j] += s2[i-1][j];
    }
  }

  for(int i = 0; i < Q; i++) {
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int ans = 0;
    ans += s0[x2][y2] + s0[x1-1][y1-1] - s0[x1-1][y2] - s0[x2][y1-1];
    ans -= s1[x2][y2] + s1[x1-1][y1] - s1[x2][y1] - s1[x1-1][y2];
    ans -= s2[x2][y2] + s2[x1][y1-1] - s2[x2][y1-1] - s2[x1][y2];
    cout << ans << endl;
  }
}
    
    
      


  
  


Measured memory_bytes: 48768
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S,T;
    cin>>S>>T;
    long long base=0;
    long long curr=-1;
    map<int,vector<long long>> mp;
    for(int i=0;i<S.length();i++){
        mp[S[i]-'a'].push_back(i);
    }
    vector<vector<int>> next(26);
    for(int i=0;i<26;i++){
        vector<long long> temp=mp[i];
        if(temp.size()==0){
            for(int j=0;j<S.length();j++){
               next[i].push_back(-1); 
            }
        }else{
            int y=0;
            for(int j=0;j<temp.size();j++){
                //int y=0;
                while(y<S.length()){
                    if(y<temp[j]){
                        next[i].push_back(temp[j]);
                        y++;
                    }else{
                        break;
                    }
                }
            }
            while(y<S.length()){
                next[i].push_back(temp[0]);
                y++;
            }
            
        }
    }
    /*for(int i=0;i<26;i++){
        cout<<(char)(i+'a')<<" ";
        for(int j=0;j<S.length();j++){
            cout<<next[i][j]<<" ";
        }
        cout<<endl;
    }*/
    vector<long long> ff=mp[T[0]-'a'];
    if(ff.size()==0){
        cout<<-1<<endl;
        return 0;
    }else{
        curr=ff[0];
    }
    for(int i=1;i<T.length();i++){
        int ncur=next[T[i]-'a'][curr];
        if(ncur==-1){
            cout<<-1<<endl;
            return 0;
        }
        if(ncur>curr){
            curr=ncur;
        }else{
            base++;
            curr=ncur;
        }
    }
    //cout<<base<<" "<<curr<<endl;
    long long ans=S.length()*base+curr+1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 12840
#include <bits/stdc++.h>
#define ep emplace_back
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>

typedef long long ll;

using namespace std;
int a[15][15];
int price[15];
int main()
{
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);
    int n,m,x;
    cin >> n >> m >> x;
    for(int i=0;i<n;++i){
        cin >> price[i];
        for(int j=0;j<m;++j){
            cin >> a[i][j];
        }
    }
    int res = 0x3f3f3f3f;
    int all = 1<<n;
    for(int mask=0;mask<all;++mask){
        vector<int> level(m);
        int cost=0;
        for(int i=0;i<n;++i){
            if ((mask>>i) & 1){
                cost += price[i];
                for(int j=0;j<m;++j){
                level[j] += a[i][j];
                }
            }

        }
        bool ok =true;
        for(auto c:level) {
            if (c<x) ok =false;
        }
        if (ok) res = min (res,cost);

    }
    if(res == 0x3f3f3f3f) cout << -1 << endl;
    else cout << res << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const int INF = 987654321;

string s;

int pal(int st, int fi) {
	if (st > fi) return 0;
	if (s[st] == s[fi]) return pal(st + 1, fi - 1);
	else {
		return pal(st + 1, fi - 1) + 1;
	}
}

int main() {
	cin >> s;
	cout << pal(0, s.length() - 1) << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int r,c,n;
	cin >> r >> c >> n;
	vector<vector<pii>> xy(n, vector<pii>(2));
	trav(v, xy){
		trav(pa, v) cin >> pa.first >> pa.second;
	}
	auto tonum = [&](pii pa){
		int x = pa.first, y = pa.second;
		if(x == 0) return y;
		if(y == c) return c+x;
		if(x == r) return c+r+(c-y);
		if(y == 0) return c+r+c+(r-x);
		return -1;
	};
	vector<pii> bs;
	rep(i,0,n){
		int a = tonum(xy[i][0]), b = tonum(xy[i][1]);
		if(a ==-1 || b == -1) continue;
		bs.emplace_back(a,i);
		bs.emplace_back(b,i);
	}
	sort(all(bs));
	stack<int> st;
	trav(pa, bs){
		if(!st.empty() && st.top()==pa.second)
			st.pop();
		else
			st.push(pa.second);
	}
	if(st.empty()) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 8944
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			// 整数の入力
			long a = sc.nextLong();
			long r = (long) Math.sqrt(a);
			long factA = 0;
			long factB = 0;
			for (long i = r; i > 0; i--) {
				if (a % i == 0) {
					factA = i;
					factB = a / i;
					break;
				}
			}
			System.out.println(factA + factB - 2);
		}
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll K,N,X,A[200010];
ll ans=0;
ll S[3][5000];
map< int64_t, int > ret;
int main(){
    cin>>N>>K;
    REP(i,N+1){
        A[i]=i;
    }REP(i,N+1){
        A[i+1]+=A[i];
    }
    REP(i,N+1){
        //DEB(i)DEB(A[i])DEB(N-1-i)DEB(A[N-1-i])END;
        if(i+1>=K){
            if(N-1-i>=0)ans=(ans+(A[N]-A[N-1-i]-A[i])+1)%MOD;
            else ans=(ans+(A[N]-A[i])+1)%MOD;
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 5088
import io.{StdIn => in}

object Main extends App {
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)
  val x = in.readLine.split(" ").map(_.toInt).sorted
  val ans = x.tail.scanLeft(0, x.head)((acc,i) => {
    (i - acc._2, i)
  }).tail.map(_._1).sorted.take(m-n).sum
  println(ans)
}


Measured memory_bytes: 46068
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
#include <fstream>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

vector<ll> dx = { 0, 1, 0, -1, 1, -1, 1, -1, 0};
vector<ll> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0};

void chmin(ll& x, ll y) {
	x = min(x, y);
}

void chmax(ll& x, ll y) {
	x = max(x, y);
}

ll pow_long(ll x, ll y) {
	ll res = 1;
	while (y > 0) {
		if (y % 2 == 1) res *= x;
		x *= x;
		y /= 2;
	}
	return res;
}

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 1000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

vector <ll> par; // 各元の親を表す配列
vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

void init_u(ll sz_) {
	par.resize(sz_);
	siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
	for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
}

ll a, b;

void solve() {
	cin >> a >> b;
	rep(i, 10000) {
		double u = 1.0 * i * 0.08;
		double v = 1.0 * i * 0.1;
		ll U = u, V = v;
		if (a == U && b == V) {
			cout << i << endl;
			return;
		}
	}
	cout << -1 << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T = 1;
	//cin >> T;
	rep(i, T) solve();
}


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


int main(){
  string n;
  cin>>n;
  ll len = n.size();
  ll sum=0;
  for(ll i=0;i<len;i++){
    ll k=n.at(i)-'0';
    sum+=k;
    sum=sum%9;
  }
  if(sum%9==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3716