akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	long long a, b, k;

	scanf("%lld %lld %lld", &a, &b, &k);

	if (k < a){
		printf("%lld %lld\n", a-k, b);
	} else if (k == a){
		printf("%lld %lld\n", 0LL, b);
	} else {
		printf("%lld %lld\n", 0LL, max(b-(k-a), 0LL));
	}

	return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
int divisor(int a,int b)
{
    if(a==b)
    {
        return a;
    }
    if(a==0)
    {
        return b;
    }
    else if(b==0)
    {
        return a;
    }
    
    if(a>b)
    {
    return divisor(b,a%b);
    }
    else
    {
    return divisor(a,b%a);
    }
}
int main()
{
    int k;
    cin>>k;
    long int e=0;
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=k;j++)
        {
            for(int c=1;c<=k;c++)
            {
                int c1=divisor(c,j);
                e=e+divisor(i,c1);
            }
        }
    }
    cout<<e<<endl;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(){
  int x,y,z,temp;
  scanf("%d%d",&x,&y);
  if(x<y){
    temp = x;
    x = y;
    y = temp;
  }

  z = x % y;
  while(z!=0){
    x = y;
    y = z;
    z = x % y;
  }
  printf("%d\n",y);
  return 0;
}



Measured memory_bytes: 2128
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

void err(){
  std::cout << "No" << '\n';
  exit(0);
}
void ok(){
  std::cout << "Yes" << '\n';
  exit(0);
}
int main(int argc, char const *argv[]) {
  ll n, m;std::cin >> n >> m;
  map<ll, ll> mp;
  vll fi(m+1, -1);
  ll q;std::cin >> q;
  vll a(q);
  vll num;

  re(i, q) scanf("%lld", &a[i]);
  for(int i=q-1;i>=0;i--){
    if(mp.find(a[i])!=mp.end()) continue;
    num.push_back(a[i]);
    mp.emplace(a[i], num.size());
    fi[a[i]] = i; //初めて現れる
  }
  for(int i=1;i<=m;i++) if(mp.find(i)==mp.end()) num.push_back(i);
  ll las = m-1;
  while(las!=0&&num[las]>num[las-1]) las--;

  multiset<ll> st;
  for(int i=q-1;i>=0;i--){
    ll x = mp.at(a[i]);
    if(x>las) continue;
    if(x==1&&st.size()!=n) st.insert(1);
    else{
      auto itr = st.find(x-1);
      if(itr==st.end()) continue;
      st.erase(itr);
      st.insert(x);
    }
  }
  if(las==0) ok();
  if(st.size()!=n) err();
  for(auto t:st) if(t!=las) err();
  ok();
  return 0;
}


Measured memory_bytes: 8820
N,M=map(int,input().split())
x=[0]*M
y=[0]*M

for i in range(M):
  x[i],y[i] = map(int,input().split())
  
pos = [1]+[0]*(N-1)
num = [1]*N

for i in range(M):
  if pos[x[i]-1]==1:
    if num[x[i]-1]==1:
      pos[x[i]-1]=0
      pos[y[i]-1]=1
      num[x[i]-1] -= 1
      num[y[i]-1] += 1
    else:
      pos[y[i]-1]=1
      num[x[i]-1] -= 1
      num[y[i]-1] += 1
  else:
      num[x[i]-1] -= 1
      num[y[i]-1] += 1
  #print(i,pos)
  #print(i,num)
  
print(sum(pos))

Measured memory_bytes: 12404
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a = 0, b = 0, x = 0;
  cin >> a;
  cin >> b;
  x = a + b;
  
  if(x % 2 == 0){
  	cout << x/2;
  } else {
  	cout << (x/2) + 1;
  }
}

Measured memory_bytes: 3588
//ITNOA
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
const long long INF=1e9+10,MAX=2e5+1e4,MOD=1e9+7,MAXL=25;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
void OUT(long double o,int x){
	 cout<<fixed<<setprecision(x)<<o;
	 return;
}
ll a[MAX];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,x=0,l,r;
	cin>>n;
	while(n--){
		cin>>l>>r;
		x+=r-l+1;
	}
	cout<<x;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio> 
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define fo(i,j,k) for(i=j;i<=k;i++)
#define fd(i,j,k) for(i=j;i>=k;i--)
#define cmax(a,b) (a=(a>b)?a:b)
#define cmin(a,b) (a=(a<b)?a:b)
typedef long long ll;
const int N=1e6+5,M=2e6+5,mo=998244353;
int fac[N],rev[N],n,m,ans,i;
int ksm(int x,int y)
{
	int ret=1;
	while (y)
	{
		if (y&1) ret=1ll*ret*x%mo;
		y>>=1;
		x=1ll*x*x%mo;
	}
	return ret;
}
int c(int n,int m)
{
	return 1ll*fac[m]*rev[n]%mo*rev[m-n]%mo;
}
int main()
{
	scanf("%d %d\n",&n,&m);
	if (n<m) swap(n,m);
	fac[0]=1;
	fo(i,1,n+m) fac[i]=1ll*fac[i-1]*i%mo;
	rev[n+m]=ksm(fac[n+m],mo-2);
	fd(i,n+m,1) rev[i-1]=1ll*rev[i]*i%mo;
	fo(i,1,m)
	{
		ans=(ans+1ll*c(i,i*2)*c(n-i,n+m-2*i))%mo;
	}
	ans=1ll*ans*ksm(2*c(n,n+m),mo-2)%mo;
	ans=(ans+n+mo)%mo;
	printf("%d",ans);
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> x(n), d(100010), r(m), p(m);
    rep(i, 0, n){
        cin >> x[i];
        d[x[i]]++;
        r[x[i] % m]++;
    }
    int ans = 0;
    rep(i, 0, 100010){
        // ans += d[i] / 2;
        // r[i % m] -= (d[i] / 2) * 2;
        p[i % m] += d[i] / 2;
    }
    // rep(i, 0, m) cout << r[i] << endl;
    rep(i, 0, m){
        int op = (m - i) % m;
        if(i > op) break;
        if(i == op){
            ans += r[i] / 2; r[i] %= 2;
        }else{
            int pr = min(r[i], r[op]);
            ans += pr;
            r[i] -= pr;
            r[op] -= pr;
            ans += min(p[i], r[i] / 2);
            ans += min(p[op], r[op] / 2);
            // cout << i << " " << op << " " << pr << " " << r[i]  << " " << r[op]  << endl;
        }
    }
    cout << ans << endl;
}

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

int main()
{
    string s;
    cin>>s>>w;
    if (w==1){
        cout<<s;
        return 0;
    }
    for (int i=0;s[i];i+=w){
        cout<<s[i];
    }
    return 0;
}



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

	public static void main(String[] args) {
    	System.out.println(metodo());   
    }
 
    public static int metodo() {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int m = sc.nextInt();
    	List<Integer>[] numbers = new ArrayList[n];
    	int[] array1 = new int[n];
        for (int i = 0; i < n; i++) {
        	numbers[i] = new ArrayList<>();
        }
        for (int  i= 0; i < m; i++) {
            int s = sc.nextInt() - 1;
            int t = sc.nextInt() - 1;
            numbers[s].add(t);
        }
        Arrays.fill(array1, -1);
        int n1 = 0;
        for (int i = 0; i < n; i++) {
            n1 = Math.max(n1, metodo2(i,array1, numbers));
        }
        return n1;
    }
 
    public static int metodo2(int v, int[] array1, List<Integer>[] numbers) {
        if (array1[v] != -1) return array1[v];
 
        int n1 = 0;
 
        for (int u: numbers[v]) {
            if (array1[u] == -1) {
            	metodo2(u,array1,numbers);
            }
            n1 = Math.max(n1, array1[u] + 1);
        }
 
        return array1[v] = n1;
    }
}


Measured memory_bytes: 63868
require 'matrix'

loop do
  n = gets.to_i
  break if n.zero?

  printf_format = "%5d" * (n + 1) + "\n"
  sums = Vector[*([0] * (n + 1))]
  n.times do
    a = gets.split.map(&:to_i)
    a.push(a.inject(&:+))
    printf printf_format, *a

    sums += Vector[*a]
  end

  printf printf_format, *sums
end

Measured memory_bytes: 9188
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
int N,M,Q;
int A[505][505];
int dp[505][505];
//dp[i][j]: form i to j , the number of car in it
//d[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]+A[i][j]
int main(){
	cin>>N>>M>>Q;
	int left,right;
	for(int i=0;i<M;i++){
		cin>>left>>right;
		A[left][right]++;
	}
	for(int i=1;i<=N;i++)
		dp[i][i]=A[i][i];
	for(int i=N-1;i>=1;i--){
		for(int j=i+1;j<=N;j++){
			dp[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]+A[i][j];
		}
	}
	
	int p,q;
	for(int i=0;i<Q;i++){
		cin>>p>>q;
		cout<<dp[p][q]<<endl;	
	} 
	return 0;
} 

Measured memory_bytes: 2944
import os
import sys
#import numpy as np

def solve(N, X, D):
    if D == 0:
        if X == 0:
            return 1
        return N+1
    #L = {0: [(0, 1), (1, -1)]}
    L = [[(0, 1), (1, -1)]]
    mapping = {0: 0}
    coef_l = 0
    coef_r = 1
    for coef_x in range(1, N+1):
        m = X * coef_x % D
        l = X * coef_x // D + coef_l
        r = X * coef_x // D + coef_x * N - coef_r
        coef_l = coef_r
        coef_r += coef_x + 1
        if m not in mapping:
            mapping[m] = len(L)
            L.append([(0, 0)] * 0)
        idx_L = mapping[m]
        L[idx_L].append((l, 1))
        L[idx_L].append((r+1, -1))
    ans = 0
    for Q in L:
        Q.sort()
        cnt = 0
        last = None
        for val, sign in Q:
            if cnt > 0:
                ans += val - last
            cnt += sign
            last = val
    return ans

# >>> numba compile >>>
numba_config = [
    [solve, "i8(i8,i8,i8)"],
]
if sys.argv[-1] == "ONLINE_JUDGE":
    from numba import njit
    from numba.pycc import CC
    cc = CC("my_module")
    for func, signature in numba_config:
        vars()[func.__name__] = njit(signature)(func)
        cc.export(func.__name__, signature)(func)
    cc.compile()
    exit()
elif os.name == "posix":
    exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
else:
    from numba import njit
    for func, signature in numba_config:
        vars()[func.__name__] = njit(signature, cache=True)(func)
    print("compiled!", file=sys.stderr)
# <<< numba compile <<<


N, X, D = map(int, input().split())
print(solve(N, X, D))


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll H[100005];
ll dp[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> H[i];
    }
    REP(i, N) {
        dp[i] = INF;
    }
    dp[0] = 0;
    REP(i, N) {
        if (i + 1 < N)
            dp[i + 1] = std::min(dp[i + 1], dp[i] + abs(H[i + 1] - H[i]));
        if (i + 2 < N)
            dp[i + 2] = std::min(dp[i + 2], dp[i] + abs(H[i + 2] - H[i]));
    }
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    int n,k,q;
    cin >> n >> k >> q;
    bool fact;
    if(k>q)    fact = true;
    else    fact = false;
    vector< pair< int,bool > > bhai_jitsen(n,make_pair((k-q),fact));
    for(int i =0;i<q;i++){
        int x;
        cin >> x;
        bhai_jitsen[x-1].first++;
        if(bhai_jitsen[x-1].first>0)bhai_jitsen[x-1].second = true;
    }
    for(int i=0;i<n;i++){
        if(bhai_jitsen[i].second == true)   cout << "Yes" << endl;
        else cout << "No" << endl;
    }

}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;


vector<bool> seen(7);

int main()
{
    int n;
    cin>>n;
    if(n%1000==0){
        cout<<0<<endl;
        return 0;
    }
    n %=1000;
    cout<<1000-n<<endl;
    return 0;
}


Measured memory_bytes: 3628
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    h, a = gets.split.map(&:to_i)
    # puts h, a

    puts (h + a - 1) / a

  end
end

if __FILE__ == $0
  Solver.new.main
end


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

int main () {
    string s; cin >> s;
    long long k; cin >> k;
	
    int ans;
    long long size = s.size();
    for (int i = 0; i < min(size, k); i++) {
        if (s[i] != '1') {
            ans = s[i] - '0';
            cout << ans << endl;
            return 0;
        }
    }
	cout << 1 << endl;
}
  


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

int main(){
  int N;
  cin >> N;
  
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  vector<int> Copy(N);
  Copy = A;
  
  sort(Copy.begin(),Copy.end());
  int maxim=Copy.at(N-1);
  int seconds=Copy.at(N-2);
  
  for(int i=0; i<N; i++){
    if(A.at(i)==maxim){
      cout << seconds << endl;
    }
    else{
      cout << maxim << endl;
    }
  }
    return 0; 
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v) cerr << "- " << #v << endl; rep(i,v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;

int main() {
  int a,b;cin>>a>>b;
  int ans = 6 - a - b;
  cout << ans << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  if (N%K==0) {
    cout << 0 << endl;
  }
  else {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
using namespace std;
#pragma warning (disable: 4996)

template<typename Type> class RangeMin {
private:
	int size_;
	std::vector<Type> dat;
public:
	RangeMin() : size_(0), dat(std::vector<Type>()) {};
	RangeMin(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat.resize(size_ << 1, std::numeric_limits<Type>::max());
	}
	template<class T>
	RangeMin(T begin_, T end_) {
		int n = end_ - begin_;
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::numeric_limits<Type>::max());
		for (int i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
		for (int i = size_ - 1; i > 0; i--) dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
	}
	inline unsigned size() { return size_; }
	inline void update(int i, Type x) {
		i += size_; dat[i] = x;
		while (i > 1) {
			i >>= 1;
			dat[i] = std::min(dat[i << 1], dat[i << 1 | 1]);
		}
	}
	inline Type query(int l, int r) {
		Type ret = std::numeric_limits<Type>::max();
		l += size_; r += size_;
		while (l != r) {
			if (l & 1) ret = std::min(ret, dat[l++]); l >>= 1;
			if (r & 1) ret = std::min(ret, dat[--r]); r >>= 1;
		}
		return ret;
	}
};

long long N, M, A[5009], B[209][5009], C[5009][5009];
RangeMin<long long>X;

void add(int px, int py, int qx, int qy, int x) {
	//cout << "! " << px << " " << py << " " << qx << " " << qy << endl;
	C[px][py] += x; C[qx + 1][qy + 1] += x;
	C[px][qy + 1] -= x; C[qx + 1][py] -= x;
}

void dfs(int L, int R) {
	if (L > R) return;
	long long G = X.query(L, R + 1); G *= -1;
	long long num = G / 10000, pos = G % 10000;
	add(L, L, R, R, num);
	add(L, L, pos - 1, pos - 1, -num);
	add(pos + 1, pos + 1, R, R, -num);
	dfs(L, pos - 1);
	dfs(pos + 1, R);
}

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N - 1; i++) cin >> A[i];
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) scanf("%lld", &B[j][i]); }
	for (int i = 1; i <= M; i++) {
		X = RangeMin<long long>(N + 2);
		for (int j = 1; j <= N; j++) X.update(j, -(B[i][j] * 10000 + j));
		dfs(1, N);
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) C[i][j] += C[i][j - 1];
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) C[i][j] += C[i - 1][j];
	}
	long long minx = -(1LL << 60);
	for (int i = 1; i <= N; i++) {
		long long dst = 0;
		for (int j = i; j <= N; j++) {
			minx = max(minx, C[i][j] - dst);
			dst += A[j];
		}
	}
	cout << minx << endl;
	return 0;
}

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

Ss = [list(map(int, input().split()[1:])) for _ in range(M)]

p = list(map(int, input().split()))


cnt = 0
for L in range(pow(2, N)):

    for pi, s in zip(p, Ss):
        x = pi
        for si in s:
            x ^= ((L & (1 << (si - 1))) != 0) * 1
        if x != 0:
            break
    else:
        cnt += 1

print(cnt)


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N;
  cin >> N;
  int sum = 0, ans = 0;

  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    sum += tmp;
    if (tmp == 0) {
      ans += sum / 2;
      sum = 0;
    }
  }
  ans += sum / 2;
  cout << ans << endl;
  return 0;
}


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

int main() {
	
	int n;
	string s;
	cin >> n >> s;
	
	int cnt = 0;
	for(int i = 1; i < n; i++){
		if(s[i] == 'E') cnt++;
	}
	int ans = cnt;
	for(int i = 1; i < n; i++){
		if(s[i] == 'E') cnt--;
		if(s[i - 1] == 'W') cnt++;
		if(ans > cnt) ans = cnt;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define MAX_N 1111111
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 0; 

int n;
ll dat[2*MAX_N - 1];

void init(int n_){
  n = 1;
  while(n < n_) n *= 2;
  for(int i = 0; i < 2 * n - 1; i++) dat[i] = INF;
}

void update(int k, ll a){
  k += n - 1;
  dat[k] = a;
  while(k > 0){
    k = (k-1)/2;
    dat[k] = dat[k*2+1]+ dat[k*2+2];
  }
}

ll query(int a, int b, int k, int l, int r){
  if(b<=a)return 0;
  if(r <= a || b <= l) return INF;
  if(a <= l && r <= b) return dat[k];
  else{
    ll vl = query(a, b, k*2+1, l, (l+r)/2);
    ll vr = query(a, b, k*2+2, (l+r)/2, r);
    return vl+vr;
  }
}


int main(void){
  ll T;
  int N;
  cin >> T >> N;
  vector<P> s(N);
  vector<P> t;
  init(N);
  for(int i = 0; i < N; i++){
    cin >> s[i].first >> s[i].second;
    update(i, s[i].second - s[i].first);
  }
  for(int i = 0; i < N; i++){
    t.push_back(P(s[i].first,0));
    t.push_back(P(s[i].second,1));
  }

  ll ans = 0;

  for(int s_ind = 0; s_ind < N; s_ind++){
  int idx = upper_bound(t.begin(), t.end(), P(s[s_ind].first + T, 0)) - t.begin();
  if(idx == 2*N) idx--;
  else if(t[idx].second == 1){
      idx -= 2;
   }else{
      idx -= 1;
   }
  //   idx = max(0, idx+1);
  ll r=query(s_ind, (idx+1)/2, 0, 0, n);
  
  ans = max(ans, r+(idx+1 >= 2*N ? 0 :max(0ll,s[s_ind].first + T - t[idx+1].first)));
  }


  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 12900
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    p = [int(input()) for _ in range(n)]
    print(sum(p)-max(p)//2)

if __name__ == '__main__':
    main()

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

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define ll long long
#define Size(v) (int)v.size()

using namespace std;
// using namespace __gnu_pbds;

const int nax = 2005;
int color[nax];
bool found = false;

vector<int> ver;

bool removed[nax];
int trace[nax];
int n, m;
vector<vector<int>> adjlist;

void dfs(int v) {
	color[v] = 1;
	if (found) return;
	for (auto &c : adjlist[v]) {
		if (color[c] == 0) {
			if (found) return;
			trace[c] = v;
			dfs(c);
		}
		else if (color[c] == 1) {
			if (found) return;
			// cerr << "cycle found:\n";
			found = true;
			ver.push_back(v);
			int u = trace[v];

			// cerr << "v - c: " << v << ' ' << c << '\n';

			// cerr << "u - c: " << u << ' ' << c << '\n';
			while (u != c) {
				// cerr << "u: " << u << '\n';
				ver.push_back(u);
				u = trace[u];
			}

			ver.push_back(c);
			// ver.push_back(v);
			// cerr << "done cycle\n";
			return;
		}
		else if (color[c] == 2) continue;
	}

	color[v] = 2;
}

bool edge[nax][nax];

void solve() {
	cin >> n >> m;

	for (int i = 0; i < nax; ++i) color[i] = 0;

	adjlist.resize(n + 1);

	for (int i = 1; i <= m; ++i) {
		int u, v;
		cin >> u >> v;

		adjlist[u].push_back(v);

		edge[u][v] = true;
	}

	// cerr << "here\n";

	for (int i = 1; i <= n; ++i) {
		if (found) break;
		if (color[i] == 0) dfs(i);
	}

	// cerr << "here\n";

	// co duoc cycle
	reverse(ver.begin(), ver.end());
	int num = Size(ver);

	// for (auto &c : ver) cerr << "c: " << c << '\n';
	
	// cerr << Size(ver) << '\n';

	for (int i = 0; i < Size(ver); ++i) {
		for (int j = i + 1; j < Size(ver); ++j) {
			int u = ver[i], v = ver[j];

			// neu co canh giua v va u

			if (removed[u] || removed[v]) continue;

			if (edge[u][v]) {
				for (int k = i + 1; k < j; ++k) removed[ver[k]] = true;
			}
			else if (edge[v][u]) {
				for (int k = j + 1; k < num; ++k) removed[ver[k]] = true;
				for (int k = 0; k < i; ++k) removed[ver[k]] = true;
			}
		}
	}

	set<int> ans;

	for (int i = 0; i < num; ++i) {
		if (!removed[ver[i]]) ans.insert(ver[i]);
	}

	if (Size(ans) == 0) cout << -1;
	else cout << Size(ans) << '\n';

	for (auto &c : ans) cout << c << '\n';
}

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

	// freopen("out", "w", stdout);

	int t = 1;
	while (t--) 
		solve();
	return 0;
}

Measured memory_bytes: 5808
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int main(){
	int a,b;
	cin>>a>>b;
	if(a%b==0)
	cout<<a/b;
	else
	cout<<a/b+1;
	
	
	
	
	return 0;
} 

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=998244353;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int xa,ya,xb,yb;cin>>xa>>ya>>xb>>yb;
	cout<<xb+ya-yb<<" "<<yb+xb-xa<<" "<<xa+ya-yb<<" "<<ya+xb-xa<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int Mt;
	int t[3];
	int i, j;
	
	for (i = 0; i < 10; i++) {
		scanf("%d", &Mt);
		
		if (i == 0) {
			t[0] = Mt;
			t[1] = 0;
			t[2] = 0;
			
			continue;
		}
		else {
			if (Mt > t[0]) {
				t[2] = t[1];
				t[1] = t[0];
				t[0] = Mt;
			}
			
			else if (Mt > t[1]) {
				t[2] = t[1];
				t[1] = Mt;
			}
			
			else if (Mt > t[2]) {
				t[2] = Mt;
			}
		}
	}
	
	for (i = 0; i < 3; i++) {
		printf("%d\n", t[i]);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main(){
  int n,k;
  scanf("%d",&n);
  scanf("%d",&k);
  vector<int> h(n);
  for(int& x : h) {
    scanf("%d",&x);
  }
  vector<int> dp(n,INF);
  dp[0]=0;
  for(int i=0;i<n;++i){
    for(int j = i+1; j<=i+k;++j){
      if(j < n) {
        dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]));
      }
    }
  }
  printf("%d\n",dp[n-1]);
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int a,b;
    while(~scanf("%d %d",&a,&b))
    {
        if((a==1||a==3||a==5||a==7||a==8||a==10||a==12)&&(b==1||b==3||b==5||b==7||b==8||b==10||b==12))
            printf("Yes\n");
        else if((a==4||a==6||a==9||a==11)&&(b==4||b==6||b==9||b==11))
            printf("Yes\n");
        else if(a==2&&b==2)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int gcd(int a, int b){
   int tmp;
   while(a%b==0){
      tmp=a%b;
      a=b;
      b=tmp;
   }
}

int lcm(int a,int b){
   return a*b/gcd(a,b);
}

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

int main(){
   int n,a, sum,ans;
   VI s;
   while(1){
      cin >> n;
      s=VI(n);
      if(!n) break;
      REP(i,n){
         cin >> s[i];
      }
      ans=s[0];
      REP(i,n){
         sum=s[i];
         if(sum>ans) ans=sum;
         FOR(j,i+1,n){
            sum+=s[j];
            if(sum>ans) ans=sum;
         }
      }
      cout << ans << endl;
   }
   return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <unordered_set>

using namespace std;

int func(int n)
{
	if (n % 2)
	{
		return 3 * n + 1;
	}
	else
	{
		return n / 2;
	}
}

int main()
{
	int s;
	cin >> s;
	unordered_set<int> history;
	for (int i = 1;i<1000000; ++i)
	{
		history.insert(s);
		s = func(s);
		if (history.find(s) != history.end())
		{
			cout << i+1;
			break;
		}
	}
}

Measured memory_bytes: 256
def decode(s):
    ret = 0
    u = 1
    for c in 'ixcm':
        i = s.find(c)
        if i < 0:
            pass
        elif i == 0 or not s[i-1].isdigit():
            ret += u
        else:
            ret += u * int(s[i-1])
        u *= 10
    return ret

def encode(n):
    ret = ''
    for c in 'ixcm':
        d = n % 10
        if d == 1:
            ret = c + ret
        elif d > 1:
            ret = str(d) + c + ret
        n //= 10
    return ret

N = int(input())
for i in range(N):
    a,b = input().split()
    print(encode(decode(a) + decode(b)))

Measured memory_bytes: 5620
#include <stdio.h>

int main(){
int a, b, c, t;
    scanf("%d %d %d", &a, &b, &c);
    if(a>b){
        t=a;
        a=b;
        b=t;
    }
    if(b>c){
        t=b;
        b=c;
        c=t;
    }
    if(a>b){
        t=a;
        a=b;
        b=t;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#define NIL -1

struct Node{
  int parent;
  int left;
  int right;
};
struct Node T[25], V[25], W[25];

void Preorder(int);
void Inorder(int);
void Postorder(int);

int main()
{
  int n, i, j, id, left, right, root;


  scanf("%d",&n);
  for( i=0 ; i<n ; i++ ){
    T[i].parent = NIL;
  }

  for( i=0 ; i<n ; i++ ){
    scanf("%d %d %d",&id,&left,&right);
    T[id].left = left;
    T[id].right = right;
    if(left!=NIL)
    T[left].parent = id;
    if(right!=NIL)
    T[right].parent = id;
  }

  for( i=0 ; i<n ; i++ ){
    V[i] = T[i];
    W[i] = T[i];
    if(T[i].parent==NIL) 
      root = i;
  }

  

  printf("Preorder\n");
  Preorder(root);
  printf("\n");

  printf("Inorder\n");
  Inorder(root);
  printf("\n");

  printf("Postorder\n");
  Postorder(root);
  printf("\n");

  return 0;
}

void Preorder(int u)
{
  if(u==NIL) return;
  printf(" %d",u);
  Preorder(T[u].left);
  Preorder(T[u].right);
}

void Inorder(int u)
{
  if(u==NIL) return;
  Inorder(V[u].left);
  printf(" %d",u);
  Inorder(V[u].right);
}

void Postorder(int u)
{
  if(u==NIL) return;
  Postorder(W[u].left);
  Postorder(W[u].right);
  printf(" %d",u);
}

Measured memory_bytes: 616
H1,M1,H2,M2,K = map(int,input().split())

min_before = H1*60+M1
min_after = H2*60+M2
if(min_before < min_after):
    print(min_after-min_before-K)
else:
    print(1440-min_before+min_after-K)


Measured memory_bytes: 9160
import sys

c500, c100, c50, x = [int(v) for v in sys.stdin.read().splitlines()]
count = 0
for i in range(c500+1):
  for j in range(c100+1):
    for k in range(c50+1):
      if 500 * i + 100 * j + 50 * k == x:
        count += 1
print(count)


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#ifndef LOCAL
#define endl '\n'
#endif

const int mod = 1e9 + 7;

int pwr(int a,int b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

void solve() {
	int n;
	bool pos = 0;
	cin >> n;
	while(n) {
		if(n % 10 == 7) pos = 1;
		n /= 10;
	}
	cout << ((pos) ? "Yes" : "No");
}

int main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	// cin >> t;
	t = 1;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;

int main()
{
    int a,b;cin >>a>>b;
    int tmp=1;
    int ans;
    bool flg=true;
    rep(i,21){
        if(b<=tmp&&flg){
                ans=i;
                flg=false;
        }
        tmp--;
        tmp+=a;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;

int main(int argc, char const *argv[]) {
  int num, k;
  cin >> num >> k;
  VI a(num);
  for (int i = 0; i < num; i ++) {
    cin >> a[i];
  }

  VVB dp1(num + 1, VB(k, false));
  dp1[0][0] = true;
  for(int i = 0; i < num; i ++) {
    for(int j = 0; j < k; j ++) {
      dp1[i + 1][j] = dp1[i][j];
    }
    for(int j = 0; j + a[i] < k; j ++) {
      dp1[i + 1][j + a[i]] = dp1[i + 1][j + a[i]] || dp1[i][j];
    }
  }
  VVI max1(num + 1, VI(k, 0));
  for(int i = 0; i <= num; i ++) {
    for(int j = 1; j < k; j ++) {
      max1[i][j] = max1[i][j - 1];
      if(dp1[i][j]) max1[i][j] = j;
    }
  }
  VVB dp2(num + 1, VB(k, false));
  dp2[num][0] = true;
  for(int i = num; i > 0; i --) {
    for(int j = 0; j < k; j ++) {
      dp2[i - 1][j] = dp2[i][j];
    }
    for(int j = 0; j + a[i - 1] < k; j ++) {
      dp2[i - 1][j + a[i - 1]] = dp2[i - 1][j + a[i - 1]] || dp2[i][j];
    }
  }
  VVI max2(num + 1, VI(k, 0));
  for(int i = 0; i <= num; i ++) {
    for(int j = 1; j < k; j ++) {
      max2[i][j] = max2[i][j - 1];
      if(dp2[i][j]) max2[i][j] = j;
    }
  }
  ll ans = 0;
  for(int i = 0; i < num; i ++) {
    bool b = a[i] >= k;
    for(int j = 0; j < k; j ++) {
      b |= max1[i][j] + max2[i + 1][k - j - 1] >= k - a[i];
    }
    if(!b) ans ++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 202624
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

vector<int> buf;
void dfs(int i, const int size, const int range_start, const int range_end, int &cnt, int N)
{
   if (i == size) {
      int tmp = 0;
      for(int i = 0; i < buf.size(); ++i){
         tmp += buf[i] * pow(10, buf.size() - 1 - i);
      }
      if (tmp <= N) {
         string s = to_string(tmp);
         int cnt3 = 0;
         int cnt5 = 0;
         int cnt7 = 0;
         for (int j = 0; j < (int)s.size(); j++) {
            if (s[j] == '3') cnt3++;
            else if (s[j] == '5') cnt5++;
            else if (s[j] == '7') cnt7++;
         }
         if (cnt3 > 0 && cnt5 > 0 && cnt7 > 0) {
            cnt++;
         }
      }
   }
   else{
      for(int j = range_start; j <= range_end; ++j){
         if (j == 1) buf[i] = 3;
         if (j == 2) buf[i] = 5;
         if (j == 3) buf[i] = 7;
         dfs(i + 1, size, range_start, range_end, cnt, N);
      }
   }
}

int main() {
   int N;
   cin >> N;
   string S = to_string(N);
   int ans = 0;
   int len = (int)S.size();
   int range_start = 1;
   int range_end = 3;
   for (int i = 3; i <= len; i++) {
      buf.clear();
      buf.resize(i);
      dfs(0, i, range_start, range_end, ans, N);
   }
  
   cout << ans << endl;
   return 0;

}


Measured memory_bytes: 256
n,*a=map(int,open(0).read().split())
b=a[::-1]
from math import gcd
L=[0]
R=[0]
for i in range(n-1):
  L.append(gcd(L[-1],a[i]))
  R.append(gcd(R[-1],b[i]))
ans=0
R=R[::-1]
#print(L,R)
for i in range(0,n-1+1):
  tmp=gcd(L[i],R[i])
  ans=max(ans,tmp)
print(ans)
  

Measured memory_bytes: 101240
f n=if n>=1&&n<=12 then True else False
main=do
 s<-getLine
 let a=read(take 2 s):: Int
     b=read(drop 2 s):: Int
 putStrLn$if f a&&f b then "AMBIGUOUS" else if f b then "YYMM" else if f a then "MMYY" else "NA"

Measured memory_bytes: 508
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef pair<string, long long int> P;

int main() {
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		vector<P> hyou(n);
		for (int i = 0; i < n; i++) {
			cin >> hyou[i].first >> hyou[i].second;
		}
		long long int counter = 0;
		for (int i = 0; i < m; i++) {
			string a;
			cin >> a;
			for (int j = 0; j < n; j++) {
				bool hantei = true;
				for (int k = 0; k < (hyou[j].first).size(); k++) {
					if ((hyou[j].first)[k] != '*') {
						if ((hyou[j].first)[k] == a[k]) {
						} else {
							hantei = false;
							break;
						}
					}
				}
				if (hantei) {
					counter += hyou[j].second;
					break;
				}
			}
		}
		cout << counter << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
n,m=map(int,input().split())
lr = [list(map(int, input().split())) for _ in range(m)]

lr_min=1145141919
lr_max=0

for i in range(m):
    lr_max=max(lr_max,lr[i][0])
    lr_min=min(lr_min,lr[i][1])

if (lr_min-lr_max+1)<=0:
    print(0)
else:
    print(lr_min-lr_max+1)

Measured memory_bytes: 27332
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int a=n%10;
    if(a==2||a==4||a==5||a==7||a==9)
        cout<<"hon";
    else if(a==0||a==1||a==6||a==8)
        cout<<"pon";
    else
        cout<<"bon";


}



Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

int main() {
  ll a,b,c,d,e;
  while(cin>>a>>b>>c>>d>>e,a) {
    ll na,nb,nc;
    cin >> na >> nb >> nc;
    ll ans = 0;
    if (nc >= d) {
      ans = e * nc;
      ans += a * na + b * nb;
    } else {
      ll tmpVal = nc * c;
      ll tmp = nc;
      ll t = min(nb, d-tmp);
      nb -= t;
      tmp += t;
      tmpVal += b * t;
      t = min(na, d-tmp);
      na -= t;
      tmp += t;
      tmpVal += a * t;
      ans = min(tmpVal, d*e);
      ans += a * na + b * nb;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
#-*-coding:utf-8-*-

def main():
    a, b = map(int, input().split())

    trump = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]

    if trump.index(a) > trump.index(b):
        print('Alice')
    elif trump.index(a) < trump.index(b):
        print('Bob')
    else:
        print('Draw')
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
#define ll long long int
using namespace std;

int i, sx, sy, tx, ty;
string s;

int main()
{
    sf("%d%d%d%d", &sx, &sy, &tx, &ty);
    for (i = sy; i < ty; i++) s += 'U';
    for (i = sx; i < tx; i++) s += 'R';
    for (i = ty; i > sy; i--) s += 'D';
    for (i = tx; i > sx; i--) s += 'L';
    s += 'L';
    for (i = sy; i < ty; i++) s += 'U';
    s += 'U';
    for (i = sx; i < tx; i++) s += 'R';
    s += 'R';
    s += 'D';
    s += 'R';
    for (i = ty; i > sy; i--) s += 'D';
    s += 'D';
    for (i = tx; i > sx; i--) s += 'L';
    s += 'L';
    s += 'U';
    cout << s << endl;
    return 0;
}

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

int main() {
  int H, W;
  std::cin >> H >> W;
  std::string a[H];
  for (int i = 0; i < H; ++i) {
    std::cin >> a[i];
  }

  for (int i = -1; i <= H; ++i) {
    if ( i == -1 || i == H ) {
      for (int j = -1; j <= W; ++j) std::cout << '#';
      std::cout << std::endl;
    } else {
      std::cout << "#" << a[i] << "#" << std::endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define MOD 1000000007

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> vec(n);
  rep(i,n) scanf("%d", &vec[i]);

  vector<vector<long> > dp(n+1, vector<long>(256, 0));
  // dp[i][j] i個使ってxorでjをつくる
  dp[0][0]=1;
  rep(d,n){ //vec[d]を追加
    vector<vector<long> >nxt(n+1, vector<long>(256, 0));
    rep(i,d+1){
      rep(j, 256) if(dp[i][j]>0){
        nxt[i][j] += dp[i][j]%MOD;
        nxt[i+1][j^vec[d]] += dp[i][j]%MOD;
      }
    }
    swap(dp, nxt);
  }

  long res=0;
  long fact=1;
  repl(i,1,n+1){
    fact = fact*i%MOD;
    res = (res+dp[i][k]*fact%MOD)%MOD;
  }

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<vector<ll>> matrix;//matrix A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
typedef vector<bool> vb;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
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;}
ll llpow(ll e,ll x){ll res=1LL;while(x){if(x&1)res*=e;e*=e;x/=2;}return res;}
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007 //998244353

void CumuSum(vl &A){rep(i,A.size())if(i)A[i]+=A[i-1];}

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

    // solution comes here

    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];

    CumuSum(A);

    ll ans=INF;
    rep(i, N-1) chmin(ans, abs(A[i]*2 - A[N-1] ));
    cout << ans << nl;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>

using namespace std;

int A[5005],B[5005];
int AN,BN;

int fun(int Blu)
{
	int date=0;
	for(int i=0;i<AN;i++)
	{
		if(Blu+date>=BN)break;
		if(A[i]==B[Blu+date])date++;
	}
	return date;
}



int main()
{
	int ans=0;
	fill(A,A+5005,0);
	fill(B,B+5005,0);
	scanf("%d%d",&AN,&BN);
	for(int i=0;i<AN;i++)
	{
		scanf("%d",&A[i]);
	}
	for(int j=0;j<BN;j++)
	{
		scanf("%d",&B[j]);
	}


	for(int i=0;i<BN;i++)
	{
		int t_ans=fun(i);
		if(t_ans>ans)ans=t_ans;
	}
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 1064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <bitset>
#include <utility> 
using namespace std;

int main() {
   int R,G,B,N; cin >> R >> G >> B >> N;
   int ans=0;
   for (int i=0;i<=N/R;i++){
       for (int j=0;j<=N/G;j++){
           int tmp = N - i*R - j*G;
           if (tmp>=0&&tmp%B==0) ans++;
       }
   }
   cout << ans << endl;
}

Measured memory_bytes: 256
s = raw_input()

if all(e == s[0] for e in s[0::2]) and all(e == s[1] for e in s[1::2]):
    print "Second"
    exit(0)

if s[0] == s[-1]:
    print ["First", "Second"][len(s)%2]
else:
    print ["Second", "First"][len(s)%2]


Measured memory_bytes: 2820
#include<stdio.h>
const int MOD=1e9+7;
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
int main()
{
  int N=IN(),M=IN(),a=1,p=1,q=0,temp=p,keep=q;
  for(int i=0;i<N;i++)
  {
    a=(1l*a*(M-i))%MOD;temp=p,keep=q;
    p=(1l*p*(M-N)%MOD+1l*keep*(M-N+1)%MOD)%MOD;q=1l*(temp+keep)*(N-i-1)%MOD;
  }
  OUT(1l*a*p%MOD);return puts(""),0;
}

Measured memory_bytes: 1532
a = int(input())
b = int(input())
c = int(input())
x = int(input())
res = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
                total = i*500 + j*100 + k*50
                if total == x:
                    res += 1

print(res) 

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

char a[20][20];
int w,h,cx,cy,count=1;

void check(int x,int y){
  if (a[y][x]=='.'){
    count ++;
    a[y][x]='*';
    if (x>0) check(x-1,y);
    if (x<w-1) check(x+1,y);
    if (y>0) check(x,y-1);
    if (y<h-1) check(x,y+1);
  }
}

int main(){
  cin >> w >> h;
  while (w!=0||h!=0){
    for (int i=0;i<h;i++){
      for (int j=0;j<w;j++){
	cin >> a[i][j];
	if (a[i][j]=='@'){
	  cx=j;
	  cy=i;
	}
      }
    }

    if (cx>0) check(cx-1,cy);
    if (cx<w-1) check(cx+1,cy);
    if (cy>0) check(cx,cy-1);
    if (cy<h-1) check(cx,cy+1);
    
    cout << count << endl;
    count =1;
    cin >> w >> h;
  }
  return 0;
}

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

ll l1[55];

int main()
{
    ll n,m;
    cin>>n>>m;
    ll a,b;
    for(int i=1;i<=m;i++){
        cin>>a>>b;
        l1[a]++;l1[b]++;
    }
    for(int i=1;i<=n;i++){
        cout<<l1[i]<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int c = 0;
  cin >> a;
  while(a){
  	if(a % 2 == 1){
  		c++;
  	}
  	a /= 10;
  }
  cout << c << endl;
}

Measured memory_bytes: 256