akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env ruby
SIZE = 10
sheets = Array.new(SIZE * SIZE, 0)

def ok(x, y)
  0 <= x && x < SIZE && 0 <= y && y < SIZE
end

while line = gets
  x, y, s = line.chomp!.split(',').map(&:to_i)

  sheets[y * SIZE + x] += 1 if ok(x, y)

  sheets[(y-1) * SIZE + x] += 1 if ok(x, y-1)
  sheets[(y+1) * SIZE + x] += 1 if ok(x, y+1)
  sheets[y * SIZE + (x-1)] += 1 if ok(x-1, y)
  sheets[y * SIZE + (x+1)] += 1 if ok(x+1, y)
  if s > 1
    sheets[(y-1) * SIZE + (x-1)] += 1 if ok(x-1, y-1)
    sheets[(y+1) * SIZE + (x+1)] += 1 if ok(x+1, y+1)
    sheets[(y+1) * SIZE + (x-1)] += 1 if ok(x-1, y+1)
    sheets[(y-1) * SIZE + (x+1)] += 1 if ok(x+1, y-1)
  end
  if s > 2
    sheets[(y-2) * SIZE + x] += 1 if ok(x, y-2)
    sheets[(y+2) * SIZE + x] += 1 if ok(x, y+2)
    sheets[y * SIZE + (x-2)] += 1 if ok(x-2, y)
    sheets[y * SIZE + (x+2)] += 1 if ok(x+2, y)
  end
end

puts sheets.count(0)
puts sheets.max

Measured memory_bytes: 8708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
#define line cout << "------------------------\n" 
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int n, ba;
bool erase(VI& x) {
    eFOR(i, ba + 1, 2 * n) {
        if (x[i]) {
            ba = i;
            --x[i];
            return --x[0];
        }
    }
    ba = 0;
    return true;
}

int main() {
    init();

    VI a, b;
    while (cin >> n && n) {
        a.clear(); a.resize(2 * n + 1, 0);
        b.clear(); b.resize(2 * n + 1, 1);
        FOR(i, 0, n) {
            int in; cin >> in;
            a[in] = 1;
            b[in] = 0;
        }
        
        ba = 0, a[0] = n, b[0] = n;
        while (1) {
            if (!erase(a))break;
            if (!erase(b))break;
        }
        int x = 0, y = 0;
        eFOR(i, 1, 2 * n) {
            if (a[i])++y;
            if (b[i])++x;
        }
        cout << x << "\n" << y << "\n";
    }
}



Measured memory_bytes: 3100
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
int X[100000];
map <int, int> mod_counts;
map <int, int> mod_same_counts;
map <int, int> counts;
int main(){ 
    int N;
    int M;
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        cin >> X[i];
    }

    for(int i = 0; i < N; i++){
        if(counts.find(X[i]) != counts.end()){
            counts[X[i]] ++;
        } else {
            counts[X[i]] = 1;
        }
    }

    for(auto it = counts.begin(); it != counts.end(); it++){
        if(it->second % 2 == 1){
            if(mod_counts.find(it->first % M) != mod_counts.end()){
                mod_counts[it->first % M] ++;
            } else {
                mod_counts[it->first % M] = 1;
            }
            counts[it->first] --;
        }
    }

    for(auto it = counts.begin(); it != counts.end(); it++){
        if(it->second != 0){
            if(mod_same_counts.find(it->first % M) == mod_same_counts.end()){
                mod_same_counts[it->first % M] = 0;
            } 
            mod_same_counts[it->first % M] += it->second;
        }
    }

    int ans = 0;
    for(int i = 0; i < M; i++){
        if(mod_counts.find(i) == mod_counts.end()){
            mod_counts[i] = 0;
        }
        if(mod_same_counts.find(i) == mod_same_counts.end()){
            mod_same_counts[i] = 0;
        }
    }

    ans = (mod_counts[0] + mod_same_counts[0]) / 2;
    mod_same_counts[0] = 0;
    if(M % 2 == 0){
        ans += (mod_counts[M / 2] + mod_same_counts[M / 2]) / 2;
        mod_same_counts[M / 2] = 0;
    }
    for(int i = 1; i <= M / 2; i++){
        if(i == M - i){
            break;
        }
        if(mod_counts[i] > mod_counts[M - i]){
            ans += mod_counts[M - i];
            int left = mod_counts[i] - mod_counts[M - i];
            if(left < mod_same_counts[M - i]){
                ans += left;
                mod_same_counts[M - i] -= left;
            } else {
                ans += mod_same_counts[M - i];
                mod_same_counts[M - i] = 0;
            }
        } else {
            ans += mod_counts[i];
            int left = mod_counts[M - i] - mod_counts[i];
            if(left < mod_same_counts[i]){
                ans += left;
                mod_same_counts[i] -= left;
            } else {
                ans += mod_same_counts[i];
                mod_same_counts[i] = 0;
            }
        }
    }

    for(auto it = mod_same_counts.begin(); it != mod_same_counts.end(); it++){
        ans += it->second / 2;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 14976
import  itertools
n=int(input())
F=[]
for i in range(n):
    a=list(map(int,input().split()))
    F.append(a)
P=[]
for i in range(n):
    a=list(map(int,input().split()))
    P.append(a)

ans=-float("inf")

def j(a):
    tmp=0
    for i in range(n):
        cnt=0
        for j in range(10):
            if F[i][j]==1 and a[j]==1:
                cnt+=1
        tmp+=P[i][cnt]
    return tmp

for pa in itertools.product([0,1],repeat=10):
    pa=list(pa)
    if not pa.count(1)==0:
        ans=max(ans,j(pa))

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000009;
const double pi = acos(-1);

int dist_sum(int N) {
    int ans = 0;
    while(N > 0) {
        ans += N%10;
        N /= 10;
    }
    return ans;
}

int main() {
    int N; cin >> N;
    cout << (N%dist_sum(N) == 0 ? "Yes" : "No") << endl;
}

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

int main()
{
	int n,s=0;
	cin>>n;
	int a[n+1];
	a[0]=0;
	
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		
		if(a[i]>a[i-1])
			s+=a[i]-a[i-1];
	}
	
	cout<<s<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

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


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long int N,A;

int main(){
    cout << fixed << setprecision(18);
    cin>>N>>A;
    N%=500;
    IFYes(N<=A);
    
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k;
  cin >> n >> k;
  long double ans = 0.0;
  for(int i = 1; i <= n; i++){
    int j = 0, num = i;
    while(num < k){
      j++;
      num *= 2;
    }
    ans += pow(0.5, j) / n; 
  }
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 1e6+11;
int n,a[N];

int main() {
	scanf("%d", &n);
	REP(i,1,n) scanf("%d",a+i);
	int tot = 0;
	REP(i,1,n) {
		if (!tot) a[++tot]=a[i];
		else if (a[i]!=a[tot]) a[++tot]=a[i];
	}
	n = tot;
	if (n<=2) return puts("1"),0;
	int d = a[2]>a[1], ans = 1;
	REP(i,3,n) {
		if (d==1&&a[i]>a[i-1]) continue;
		if (d==0&&a[i]<a[i-1]) continue;
		d = a[i+1]>a[i];
		++i, ++ans;
	}
	printf("%d\n", ans);
}









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

int main(){
  int N,K;
  cin >>N>>K;
  vector<int> H(N);
  int ans = 0;
  for(int i=0;i<N;i++){
    int x;
    cin >>x;
    if(x>=K) ans ++;
  }
  
  cout << ans << endl;
 
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

using ll = long long int;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

	int n; cin >> n;
	const int lim = 6e5 + 100, offset = 2e5;
	vector<vector<array<int, 2>>> vert(200010), hor(200010);
	vector<vector<int>> left1(lim), right1(lim), left2(lim), right2(lim);
	vector<array<int, 2>> up, down;
	for (int i = 0; i < n; ++i) {
		int x, y; char dir;
		cin >> x >> y >> dir;
		if (dir == 'U') {vert[x].push_back({y, 0}); up.push_back({x, y});}
		else if (dir == 'D') {vert[x].push_back({y, 1}); down.push_back({x, y});}
		else if (dir == 'L') {
			hor[y].push_back({x, 0});
			left1[x+y+offset].push_back(y);
			left2[x-y+offset].push_back(y);
		}
		else {
			hor[y].push_back({x, 1});
			right1[x+y+offset].push_back(y);
			right2[x-y+offset].push_back(y);
		}
	}
	for (auto &vec : hor)
		sort(begin(vec), end(vec));
	for (auto &vec : vert)
		sort(begin(vec), end(vec));
	for (auto &vec : left1)
		sort(begin(vec), end(vec));
	for (auto &vec : left2)
		sort(begin(vec), end(vec));
	for (auto &vec : right1)
		sort(begin(vec), end(vec));
	for (auto &vec : right2)
		sort(begin(vec), end(vec));
	int ans = 2e9;
	for (auto &vec : hor) {
		int N = vec.size();
		for (int i = 0; i+1 < N; ++i) {
			if (vec[i][1] == 1 && vec[i+1][1] == 0)
				ans = min(ans, 5*vec[i+1][0] - 5*vec[i][0]);
			if (vec[i][0] == vec[i+1][0])
				ans = 0;
		}
	}
	for (auto &vec : vert) {
		int N = vec.size();
		for (int i = 0; i+1 < N; ++i) {
			if (vec[i][1] == 0 && vec[i+1][1] == 1)
				ans = min(ans, 5*vec[i+1][0] - 5*vec[i][0]);
			if (vec[i][0] == vec[i+1][0])
				ans = 0;
		}
	}
	for (auto [x, y] : up) {
		int sum = x+y+offset, dif = x-y+offset;
		auto it = upper_bound(begin(right1[sum]), end(right1[sum]), y);
		if (it != end(right1[sum]))
			ans = min(ans, 10*abs(y-*it));
		it = upper_bound(begin(left2[dif]), end(left2[dif]), y);
		if (it != end(left2[dif]))
			ans = min(ans, 10*abs(y-*it));
	}
	for (auto [x, y] : down) {
		int sum = x+y+offset, dif = x-y+offset;
		auto it = lower_bound(begin(left1[sum]), end(left1[sum]), y);
		if (it != begin(left1[sum])) {
			--it;
			ans = min(ans, 10*abs(y-*it));
		}
		it = lower_bound(begin(right2[dif]), end(right2[dif]), y);
		if (it != begin(right2[dif])) {
			--it;
			ans = min(ans, 10*abs(y-*it));
		}
	}
	if (ans < 2e9) cout << ans << '\n';
	else cout << "SAFE\n";
}

Measured memory_bytes: 82728
#[test]
fn test_solve() {
    assert_eq!(solve("3\n1\n"), "2\n");
    assert_eq!(solve("1\n2\n"), "3\n");
}

fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let a: usize = sc.read();
    let b: usize = sc.read();

    format!("{}\n", a^b)
}

fn main() {
    let mut buf = String::new();
    use std::io;
    use std::io::{Read, Write};
    io::stdin().read_to_string(&mut buf).unwrap();
    io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}

struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int f(int x){
    int sum = 0;
    string a;
	a = to_string(x);
	
	for (int i = 0; i < a.size(); i++) {
	    sum += (a[i] - '0');
	}
	return sum;
}

int main() {
	int n;
	cin >> n;
	
	if(n % f(n) == 0){
	    std::cout << "Yes" << std::endl;
	    
	}else{
	    std::cout << "No" << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
loop do
  n,k = gets.split.map(&:to_i)
  exit if n == 0 and k == 0
  a = k.times.map{gets.to_i}.sort
  bak = -3
  count = []
  chunk = []
  use_white = false
  a.each do |i|
    if i - bak == 1
      count[-1] += 1
      chunk[-1] += 1
    elsif i - bak == 2 and not use_white
      count[-1] += 2
      chunk << 1
      use_white = true
    elsif i - bak == 2 and use_white
      count << chunk.last + 2
      chunk << 1
      use_white = true
    elsif
      count << 1
      chunk << 1
      use_white = false
    end
    bak = i
  end
  result = (a.first == 0) ? count.max : chunk.max
  puts(result)
end

Measured memory_bytes: 7808
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll m1,d1,m2,d2;
cin>>m1>>d1>>m2>>d2;
if(m1!=m2)
{
    cout<<1<<endl;
}else
{
    cout<<0<<endl;
}
return 0;
}

Measured memory_bytes: 256
from __future__ import division, print_function
from sys import stdin, maxint
 
 
def main():
    num = int(stdin.readline())
 
    M = []
    for _ in xrange(num):
        M.append([int(s) for s in stdin.readline().split()])
 
    g = set(xrange(1, num+1))
    index = g.pop()
    h = {index}
    weight = 0
 
    while g:
        minimum = maxint
        for j in h:
            mj = M[j-1]
            for i in g:
                if 0 <= mj[i-1] < minimum:
                    index = i
                    minimum = mj[i-1]
        h.add(index)
        g.remove(index)
        weight += minimum
 
    print(weight)
 
 
main()

Measured memory_bytes: 6580
// 入力マクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::min;
fn main() {
    input! {
        k: isize, n: usize,
        a: [isize; n]
    }

    let mut ans = (a[0] - a[n-1]).abs();
    for i in 0..n-1 {
        ans = min(ans, (a[i] + k - a[i+1]).abs());
    }

    println!("{}", ans);
}


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

int main (){
  int x,y,z,z2;
  cin>> x >> y;
  z = y-x;

  if(z<0){
    z2=-z;
    cout<< z2 <<endl;
  }else{
    cout<<z<<endl;
  }
}



Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>
#include <map>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(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; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////



int main() {

	int N, M, X;
	cin >> N >> M >> X;

	vector<int> C(N);
	vector<vector<int>> A(N, vector<int>(M));

	rep(i, N) {
		cin >> C[i];
		rep(j, M) {
			cin >> A[i][j];
		}
	}

	ll mincost = 20000000;
	for (int bit = 0; bit < (1 << N); bit++) {
		vector<int> SumX(M,0);

		rep(i, N) {
			if (bit & (1 << i)) {
				rep(j, M) {
					SumX[j] += A[i][j];
				}
			}
		}

		bool ok = true;
		rep(i, M) {
			if (SumX[i] < X)ok = false;
		}


		if (ok) {
			ll cost = 0;
			rep(i, N) {
				if (bit & (1 << i)) {
					cost += C[i];
				}
			}
			if (cost < mincost)mincost = cost;
		}
		
	}
	if (mincost == 20000000) {
		cout << -1 << endl;
	}
	else cout << mincost << endl;
}


Measured memory_bytes: 3604
s=int(input())
a=s//100
b=s%100
if 0<a<13 and 0<b<13:
    print("AMBIGUOUS")
elif a==b==0 or (a>12 and b>12) or (a==0 and b>12) or (a>12 and b==0):
    print("NA")
elif a>12 and b<13 or (a==0 and 0<b<13):
    print("YYMM")
elif b>12 and a<13 or (b==0 and 0<a<13):
    print("MMYY")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
#define INF 100000000
using namespace std;

struct state {
  int y, x, d;
  bool operator<(const state &s) const {
    return d > s.d;
  }
};

int H, W, SY, SX;
char S[300][300];
int dd[5] = { 0, 1, 0, -1, 0 };
bool visited[300][300];

bool isin(int y, int x) {
  return 0 <= y && y < H && 0 <= x && x < W;
}

int main(void) {
  cin >> H >> W;
  REP(i, 0, H) REP(j, 0, W) {
    cin >> S[i][j];
    if(S[i][j] == '%') {
      SY = i;
      SX = j;
    }
  }

  REP(i, 0, H) REP(j, 0, W) visited[i][j] = false;
  queue<state> q;
  q.push((state) { SY, SX, 0 });

  int d1 = INF, d2 = INF;
  while(q.size()) {
    state c = q.front();
    q.pop();
    if(visited[c.y][c.x]) continue;
    visited[c.y][c.x] = true;
    if(S[c.y][c.x] == '@') {
      d1 = c.d;
    }
    if(S[c.y][c.x] == '$') {
      d2 = min(d2, c.d);
    }
    REP(i, 0, 4) {
      int ny = c.y + dd[i], nx = c.x + dd[i + 1];
      if(isin(ny, nx) && S[ny][nx] != '#' && !visited[ny][nx]) {
        q.push((state) { ny, nx, c.d + 1 });
      }
    }
  }
  cout << (d1 < d2 ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    string T;
    cin>>S>>T;
    int ls = S.size(), lt = T.size();
    vector<vector<int>> dp(ls+1,vector<int>(lt+1,0));
    vector<vector<int>> rdp(ls+1,vector<int>(lt+1,0)); //上０、左１、左上２
    reps(i,1,ls+1){
        reps(j,1,lt+1){
            int u = dp[i-1][j], l = dp[i][j-1], ul = dp[i-1][j-1];
            int &ndp = dp[i][j];
            ndp = max(u,l);
            rdp[i][j] = u>l ? 0 : 1;
            if(S.at(i-1) == T.at(j-1)){
                if(ndp < ul + 1){
                    ndp = ul + 1;
                    rdp[i][j] = 2;
                }
            }
        }
    }
    int i = ls, j = lt;
    vector<char> ans;
    while(i != 0 && j != 0){
        if(rdp[i][j] == 0) {
            i--;
            continue;
        }
        if(rdp[i][j] == 1) {
            j--;
            continue;
        }
        i--;
        j--;
        ans.push_back(S.at(i));
    }

    /*rep(i,ls+1){
        rep(j,lt+1){
            cout<<dp.at(i).at(j) << ' ';
        }
        cout << endl;
    }*/
    for(int i = ans.size() - 1; i >= 0; i--){
        cout<<ans.at(i);
    }

    if(ans.size() == 0) cout << ' ';
    cout<<endl;
}

Measured memory_bytes: 70912
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	String o = sc.next();
	String e = sc.next();
	for(int i = 0; i < e.length(); i++) {
		System.out.print(o.charAt(i));
		System.out.print(e.charAt(i));		
	}
	if(o.length() > e.length()) {
		System.out.println(o.charAt(o.length() - 1));
	}
}
}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>
#include <list>
using namespace std;
#define MAX 100
int main()
{
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    int city[4];
    for (int i = 0; i < 4; i++)
    {
        city[i] = 0;
    }
    for (int i = 0, tmp; i < 6; i++)
    {
        cin >> tmp;
        city[tmp - 1]++;
    }
    int maxs = 0;
    for (int i = 0; i < 4; i++)
    {
        if (city[i] > maxs)
        {
            maxs = city[i];
        }
    }
    if (maxs == 2)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
set<string> c;
map<ll,ll> mp;
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
int main(){
int n;
cin>>n;
double ans=0.0;
for(int i=0;i<n;i++){
    double a;
    cin>>a;
    ans+=1/a;
}
ans=1/ans;
printf("%.7f\n",ans);
}

Measured memory_bytes: 256
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>


using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




/*
class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;
	vector <ll> gr;

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

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d, e, H, W, L;
ll A[100005] = {};
ll B[300005] = {};
ll C[300005] = {};
bool f, ff;
string S,T;
set <long long>sll;
pl bufpl;
vector <long long>vl;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}



ll minn, maxx;
double ansa;
bool fl[30] = {};


string ss, sss;

int LL;

int main() {


	cin >> N>>LL;

	b = 100000;

	f = true;
	e = c;

	for (int i = 0; i < N; i++) {
		c = LL + i;
		e += c;
		d = abs(c);
		if (d < b) {
			b = d;
			a = c;
		}
	}

	cout << e - a << endl;

	return 0;

}


Measured memory_bytes: 256
#include<iostream>
  using namespace std;
  int a[1000000];
  int main()
  {
      int k,s;
      cin>>k>>s;
      for(int i=0;i<=k;i++)
    {
        for(int j=0;j<=k;j++)
         {
             a[5000+i+j]++;
         }
     }
     int sum=0;
     for(int i=0;i<=k;i++)
     {
         int pos=s-i;
         if(pos<0)
         {
             continue;
         }
         sum+=a[5000+pos];
     }
    cout<<sum<<endl;
    return 0;
  }


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (31 - __builtin_clz(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
	
const int maxN = 1 << 19;

vector <int> G[maxN];
bool vis[maxN];

void dfs(int v)
{
	vis[v] = true;
	for (int u : G[v])
		if (!vis[u])
			dfs(u);
}

void solve()
{	
	int n, m;
	scanf ("%d%d", &n, &m);
	while (m--)
	{
		int a, b;
		scanf ("%d%d", &a, &b);
		G[a].pb(b);
		G[b].pb(a);
	}
	
	int res = 0;
	FOR(i, 1, n+1)
		if (!vis[i])
			dfs(i), res++;
	printf("%d\n", res-1);
}

 
int main()
{
	int t = 1;
	//scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}





Measured memory_bytes: 19756
/*
    Ankit Singhal
 */
#define ll long long int
#include <bits/stdc++.h>
//#include <fstream>
using namespace std;
 
#define         ff               first
#define         ss               second
#define         mp               make_pair
#define         pb               push_back
#define         pf               push_front
#define         vi               vector<ll>
#define         pii              pair<ll,ll>
#define         qi               queue<ll>
#define         mem(a,b)         memset(a,b,sizeof(a))
#define         print(a)         cout<<a<<'\n'
#define         sorted(arr)      sort(arr.begin(),arr.end())
#define         gcd(a,b)         gcd((a),(b))
#define         lcm(a,b)         ((a)*(b))/gcd((a),(b))
#define         all(v)           v.begin(),v.end()
#define         read(a)          scanf("%d", &a)
#define         f(a,n)           for(ll i=a;i<n;i++)
#define         in2(n,m,arr)     for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cin>>arr[i][j];}
#define         debug(a)         cerr<<a<<" ";
#define         debug1(a)        cerr<<a<<'\n'
 
/*typedef tree<int, null_type, less<int>, rb_tree_tag , tree_order_statistics_node_update> Set;*/


const unsigned ll mod= (ll)1e9 ;
const ll inf = (ll)1e15 + 42;
const ll N = (ll)1e6 + 2;
 
ll power ( ll x , unsigned ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}
 
/*struct node{
    ll x , y , z;
};
vector<set<ll>> tree;
vector<ll> ar , ans;
set<ll> s;
ll get(ll x)
{
    if(x == ar[x])
        return x;
    return ar[x] = get(ar[x]);
}
void merge(ll a ,ll b)
{
    a = get(a);
    b = get(b);
    if(a == b)
        return;
    ar[b] = ar[a];
    //ans[a] += ans[b];
 }

ll sev[1000001];


void seive()
{
    for(ll i = 2 ; i <= 1000000 ; i ++)
    {
        if(!sev[i])
        {
            for(ll j = i ; j <= 1000000 ; j += i)
            {
                if(!sev[j])
                    sev[j] = i;
            }
        }
    }
}
*/

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t ;
    t = 1;
    //cin >> t;
    while(t --)
    {
        ll n;
        cin >> n;
        ll temp = n / 100;
        ll t1 = n % 100;
        if(t1 > 5 * temp)
            print(0);
        else
            print(1);
        
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
    
}
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef vector<int> vi;
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int INF = 1e5;
const int MAXN = (1 << 18) + 20;
int V[MAXN], W[MAXN];
map<int, lint> state[(1 << 9) + 20];
lint dp[(1 << 9) + 20][INF + 5];
inline void update(int i, int w, lint v) {
	if (w > INF) return;
	state[i][w] = max(state[i][w], v);
}
inline void dfs(int u, int lim) {
	for (auto & st : state[u]) {
		dp[u][st.fst] = max(dp[u][st.fst], st.sed);
	}
	rep (v, u * 2, u * 2 + 1) {
		if (v > lim) continue;
		for (auto & st : state[u]) {
			update(v, st.fst, st.sed);
			update(v, st.fst + W[v], st.sed + V[v]);
		}
		dfs(v, lim);
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n;
	cin >> n;
	rep (i, 1, n) {
		cin >> V[i] >> W[i];
	}
	state[1][0] = 0;
	state[1][W[1]] = V[1];
	int lim = min(n, (1 << 9) - 1);
	dfs(1, lim);
	rep (i, 1, lim) rep (j, 1, INF) {
		dp[i][j] = max(dp[i][j], dp[i][j - 1]);
	}
	int q;
	cin >> q;
	while (q--) {
		int p, l;
		cin >> p >> l;
		lint res = 0;
		function<void(int, int, int)> solve;
		solve = [&] (int u, int w, int v) {
			if (w > l) return;
			if (u <= lim) {
				res = max(res, v + dp[u][l - w]); return;
			}
			solve(u >> 1, w, v);
			solve(u >> 1, w + W[u], v + V[u]);
		};
		solve(p, 0, 0);
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 415868
import Data.List
toInt::String->Int
toInt = read
format::Show a=>[a]->String
format [x] = show x
format (x:xs) = show x ++ " " ++ format xs
format'::Show a=>(Int, [a])->String
format' (n, xs) = format xs ++ "\n" ++ show n
minBreak::Ord a=>[a]->([a], [a])
minBreak [x] = ([], [x])
minBreak (x:xs)
  | x > z = (x:ys, z:zs)
  | otherwise = ([], x:ys++z:zs)
    where
      (ys, (z:zs)) = minBreak xs
ssort::Ord a=>Int->[a]->[a]->(Int, [a])
ssort n xs [y] = (n, xs++[y])
ssort n xs (y:ys)
  | y > w = ssort (n+1) (xs++[w]) (zs++[y]++ws)
  | otherwise = ssort n (xs++[y]) (zs++[w]++ws)
    where
      (zs, (w:ws)) = minBreak ys
main = do
  getLine
  getLine >>=
    putStrLn.format'.(ssort 0 []).(map toInt).words


Measured memory_bytes: 4092
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
using namespace std;

int main() {
	
	int a, b;
	cin >> a >> b;
	
	if(a > b){
		cout << a - 1 << endl;
	}else{
		cout << a << endl;
	}
	
	return 0;
}



Measured memory_bytes: 764
n = gets.to_i

sum = (n * (n + 1) * (n + 2))/6


(n-1).times do |i|
  e = gets.chomp.split.map(&:to_i)
  a, b = 0, 0
  if e[0] > e[1]
    a = e[1]
    b = e[0]
  else
    a = e[0]
    b = e[1]
  end

  sum -= a * (n - b + 1)
end

p sum

Measured memory_bytes: 14208
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))


typedef unsigned long long int uint64;
typedef long long int          int64;

typedef struct _tmp_t {
  int64 a;
  int64 b;
} tmp_t;

void get_ab (int64 *a, int64 *b)
{
  int cnt;
  
  cnt = scanf("%lld %lld", a, b);

  return;
}

void get_n (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

int64 gcd(int64 a,int64 b){int64 c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int64 lcm(int64 a,int64 b){int64 c=gcd(a,b);a/=c;return a*b;};


#define SIZE (10*10*10*10*10*2)
tmp_t job[SIZE];


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

int main()
{
  int64 N;
  int64 i;
  int64 t = 0;

  get_n(&N);

  for (i=0; i<N; i++) {
    get_ab(&job[i].a, &job[i].b);
  }

  qsort_a(job, N);
  qsort_b(job, N);

  for (i=0; i<N; i++) {
    t += job[i].a;
    if (t > job[i].b) {
      printf("No");
      return 0;
    }
  }
  
  printf("Yes");

  return 0;
}



Measured memory_bytes: 6596
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

void bad() {
	puts("NO");
	exit(0);
}
void good() {
	puts("YES");
	exit(0);
}

const int MAXN = 100000 + 20;
int A[MAXN];
VI e[MAXN];

int DFS(int x, int p) {
	if(SZ(e[x]) == 1) {
		return A[x];
	}
	int sum = 0, big = 0;
	for(int u : e[x]) {
		if(u == p) continue;
		int r = DFS(u, x);
		sum += r;
		big = max(big, r);
	}
	if(sum < A[x]) bad();
	if(A[x] * 2 < sum) bad();
	int fold = sum - A[x];
	if(sum - big < fold) bad();
	debug("x = %d, fold = %d\n", x, fold);
	return sum - 2 * fold;
}

int main() {
	int N;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++)
		scanf("%d", &A[i]);
	for(int i = 1; i < N; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		e[a].PB(b);
		e[b].PB(a);
	}
	if(N == 2) {
		if(A[1] == A[2]) good();
		else bad();
	}
	for(int i = 1; i <= N; i++)
		if(SZ(e[i]) > 1) {
			if(DFS(i, 0) == 0) good();
			else bad();
		}
	return 0;
}


Measured memory_bytes: 12928
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = Long.parseLong(sc.next());
        long A = Long.parseLong(sc.next());
        long B = Long.parseLong(sc.next());

        if ((B-A)%2==0) System.out.println((B-A)/2);
        else System.out.println(Math.min(A-1, N-B)+(B-A+1)/2);
    }
}

Measured memory_bytes: 23764
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	Scanner scan=new Scanner(System.in);
	int hum[]=new int[1000001];
	for(int i=1;i<=1000000;i*=2)
	    {
		for(int j=1;i*j<=1000000;j*=3)
		    {
			for(int k=1;i*j*k<=1000000;k*=5)
			    {
				hum[k*j*i]=1;
			    }
		    }
	    }
	while(true)
	    {
		int m,n;
		m=scan.nextInt();
		if(m==0)break;
		n=scan.nextInt();
		int count=0;
		for(int i=m;i<=n;i++)
		    {
			if(hum[i]==1)count++;
		    }
		System.out.println(count);
	    }
    }
}

Measured memory_bytes: 21788
#include <bits/stdc++.h>
 
using namespace std;
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define mp make_pair
#define f first
#define s second
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
 
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const long double pi = 3.14159265358979323846;



void solve() {
  ll l, r, n; cin >> l >> r >> n;
  cout << r/n - (l - 1)/n << '\n';
}
 
int main() {
  fio();
  
  int T = 1;
  // cin >> T;
  while (T--) solve();
} 

Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

typedef long long ll;

int cntW[300010];
int cntE[300010];

int main() {
  int N; cin >> N;
  string S; cin >> S;

  cntW[0] = 0;
  cntE[N-1] = 0;
  for ( int i = 1; i < N; i++ ) {
    if ( S[i-1] == 'W' ) cntW[i] = cntW[i-1]+1;
    else cntW[i] = cntW[i-1];
  }

  for ( int i = N-2; i >= 0; i-- ) {
    if ( S[i+1] == 'E' ) cntE[i] = cntE[i+1]+1;
    else cntE[i] = cntE[i+1];
  }

  for ( int i = 0; i < N; i++ ) {
    // cout << S[i] << " " << cntW[i] << " " << cntE[i] << endl;
  }

  int ans = 1e9;
  for ( int i = 0; i < N; i++ ) {
    int tmp = cntE[i] + cntW[i];
    ans = min(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,i,j,k;
  cin>>h>>w;
  char a[h][w],b[h][w],c[h][w];
  bool ub[h][w],uc[h][w];
  memset(a,'.',sizeof(a));
  memset(b,'.',sizeof(b));
  memset(c,'.',sizeof(c));
  memset(ub,0,sizeof(ub));
  memset(uc,0,sizeof(uc));
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      cin >> a[i][j];
      if(a[i][j]=='#') b[i][j]=c[i][j]=a[i][j];
    }
  }
  for(j=1;j<w-1;j++) b[0][j]='#';
  for(i=0;i<h-1;i++) b[i][0]='#';
  for(i=1;i<h;i++) c[i][w-1]='#';
  for(j=1;j<w;j++) c[h-1][j]='#';

  typedef pair<int,int> P;
  queue<P> q;
  P p;
  int ax[]={1,-1,0,0};
  int ay[]={0,0,1,-1};
  q.push(P(0,0));
  while(!q.empty()){
    p=q.front();q.pop();
    if(p.first<0||p.first>=h||p.second<0||p.second>=w) continue;
    if(ub[p.first][p.second]||b[p.first][p.second]!='#') continue;
    ub[p.first][p.second]=true;
    for(k=0;k<4;k++) q.push(P(p.first+ay[k],p.second+ax[k]));
  }
  q.push(P(h-1,w-1));
  while(!q.empty()){
    p=q.front();q.pop();
    if(p.first<0||p.first>=h||p.second<0||p.second>=w) continue;
    if(uc[p.first][p.second]||c[p.first][p.second]!='#') continue;
    uc[p.first][p.second]=true;
    for(k=0;k<4;k++) q.push(P(p.first+ay[k],p.second+ax[k]));
  }

  for(j=1;j<w;j++){
    for(i=1;i<h;i++){
      if(ub[i][j]||b[i][j]!='#') continue;
      k=0;
      while((!ub[i-k-1][j])&&(!ub[i-k][j-1]))
	ub[i-k-1][j]=true,b[i-k-1][j]='#',k++;
      ub[i][j]=true;
    }
  }

  
  memset(uc,0,sizeof(uc));
  q.push(P(h-1,0));
  while(!q.empty()){
    p=q.front();q.pop();
    if(p.first<0||p.first>=h||p.second<0||p.second>=w) continue;
    if(uc[p.first][p.second]) continue;
    uc[p.first][p.second]=true;
    if(!ub[p.first][p.second]) c[p.first][p.second]='#'; 
    for(k=0;k<4;k++) q.push(P(p.first+ay[k],p.second+ax[k]));
  }

  
  for(i=0;i<h;i++){
    for(j=0;j<w;j++) cout << b[i][j];
    cout << endl;
  }
  cout << endl;
  for(i=0;i<h;i++){
    for(j=0;j<w;j++) cout << c[i][j];
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
	cout << fixed << setprecision(6);

	while(1){
		int n; cin >> n;
		if (n == 0) break;

		double* point = new double[n];
		double sum = 0;

		for (int i = 0; i < n; i++) {
			cin >> point[i];
			sum += point[i];
		}
		double mean = sum / n;

		double variance = 0;
		for (int i = 0; i < n; i++) {
			double diff_sq = (point[i] - mean) * (point[i] - mean);
			variance += diff_sq;
		}
		variance /= n;

		cout << sqrt(variance) << endl;

		delete[] point;
	}

	return 0;
}



Measured memory_bytes: 3232
// 2011/08/26 Tazoe

#include <iostream>
using namespace std;

void DFS(char M[104][104], int y, int x, int C[104][104], int c)
{
	C[y][x] = c;

	if(M[y-1][x]=='.'&&C[y-1][x]==-1)
		DFS(M, y-1, x, C, c);
	if(M[y+1][x]=='.'&&C[y+1][x]==-1)
		DFS(M, y+1, x, C, c);
	if(M[y][x-1]=='.'&&C[y][x-1]==-1)
		DFS(M, y, x-1, C, c);
	if(M[y][x+1]=='.'&&C[y][x+1]==-1)
		DFS(M, y, x+1, C, c);
}

void DFS2(char M[104][104], int y, int x, int C[104][104], int c)
{
	C[y][x] = c;

	if(M[y-1][x]=='.'&&C[y-1][x]==-1)
		DFS(M, y-1, x, C, c);
	if(M[y+1][x]=='.'&&C[y+1][x]==-1)
		DFS(M, y+1, x, C, c);
	if(M[y][x-1]=='.'&&C[y][x-1]==-1)
		DFS(M, y, x-1, C, c);
	if(M[y][x+1]=='.'&&C[y][x+1]==-1)
		DFS(M, y, x+1, C, c);

	if(M[y-1][x]=='#'&&C[y-1][x]==-1)
		DFS2(M, y-1, x, C, c);
	if(M[y+1][x]=='#'&&C[y+1][x]==-1)
		DFS2(M, y+1, x, C, c);
	if(M[y][x-1]=='#'&&C[y][x-1]==-1)
		DFS2(M, y, x-1, C, c);
	if(M[y][x+1]=='#'&&C[y][x+1]==-1)
		DFS2(M, y, x+1, C, c);
}

int main()
{
	while(true){
		int n, m;
		cin >> n >> m;
		if(n==0&&m==0)
			break;

		char M[104][104];
		for(int y=0; y<=m+3; y++)
			for(int x=0; x<=n+3; x++)
				M[y][x] = '#';
		for(int y=1; y<=m+2; y++)
			for(int x=1; x<=n+2; x++)
				M[y][x] = '.';

		int Y = -1;
		int X = -1;
		for(int y=2; y<=m+1; y++){
			for(int x=2; x<=n+1; x++){
				cin >> M[y][x];
				if(M[y][x]=='&'){
					Y = y;
					X = x;
					M[y][x] = '.';
				}
			}
		}
//		cout << Y << ' ' << X << endl;

		int C[104][104];
		for(int y=0; y<=m+3; y++)
			for(int x=0; x<=n+3; x++)
				C[y][x] = -1;

		int cnt = 0;
		DFS(M, Y, X, C, cnt);

		if(C[1][1]!=-1){
			cout << C[1][1] << endl;
			continue;
		}

	while(true){
		cnt++;
		for(int y=2; y<=m+1; y++){
			for(int x=2; x<=n+1; x++){
				if(M[y][x]=='#'&&C[y][x]==-1&&M[y-1][x]=='.'&&C[y-1][x]==cnt-1)
					DFS2(M, y, x, C, cnt);
				if(M[y][x]=='#'&&C[y][x]==-1&&M[y+1][x]=='.'&&C[y+1][x]==cnt-1)
					DFS2(M, y, x, C, cnt);
				if(M[y][x]=='#'&&C[y][x]==-1&&M[y][x-1]=='.'&&C[y][x-1]==cnt-1)
					DFS2(M, y, x, C, cnt);
				if(M[y][x]=='#'&&C[y][x]==-1&&M[y][x+1]=='.'&&C[y][x+1]==cnt-1)
					DFS2(M, y, x, C, cnt);
			}
		}

		if(C[1][1]!=-1){
			cout << C[1][1] << endl;
			break;
		}
	}
/*
		for(int y=0; y<=m+3; y++){
			for(int x=0; x<=n+3; x++){
				if(C[y][x]==-1)
					cout << '-';
				else
					cout << C[y][x];
			}
			cout << endl;
		}
*/
	}

	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int p, l, r;
};

struct Node T[MAX];
int n;

void prParse(int u){
  if ( u == NIL ) return;
  printf(" %d", u);
  prParse(T[u].l);
  prParse(T[u].r);
}
void inParse(int u){
  if ( u == NIL ) return;
  inParse(T[u].l);
  printf(" %d", u);
  inParse(T[u].r);
}
void postParse(int u){
  if ( u == NIL ) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d", u);
}

main(){
  int i, v, l, r, root;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) {
    T[i].p = NIL;
  }

i=0;  
while(i < n){
    i++;
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if ( l != NIL ) T[l].p = v;
    if ( r != NIL ) T[r].p = v;
  }

  for ( i = 0; i < n; i++ ) if ( T[i].p == NIL ) root = i;
  printf("Preorder\n");
  prParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2144
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
using namespace std;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int r=0,l=0;
    int ans=1000000;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='E')l++;
    }
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='E')l--;
        ans=min(ans,l+r);
        if(s.at(i)=='W') r++;
    }
    cout<<ans<<endl;
    return 0;
}



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

using namespace std;

int get_gcd(int a, int b) {
  if (b == 0) return a;
  return get_gcd(b, a % b);
}

int get_gcd(int a, int b, int c) {
  return get_gcd(a, get_gcd(b, c));
}

int main() {
  int K;
  cin >> K;
  long long ans = 0;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      for (int k = 1; k <= K; k++) {
        ans += get_gcd(i, j, k);
      }
    }
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 3636
#python 3.5.2

N, M = [int(i) for i in input().split()]
LRs = [[int(j) for j in input().split()] for i in range(M)]
LRs = list(map(list, zip(*LRs)))  # 転置
Lmax = max(LRs[0])
Rmin = min(LRs[1])
Rmin = min(Rmin, N)
num = Rmin - Lmax + 1 if Rmin >= Lmax else 0 
print(num)


Measured memory_bytes: 29828
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		final var n = scanner.nextInt();
		final var m = scanner.nextInt();
		var l = 1;
		var r = n;
		for (var i = 1; i <= m; i++) {
			var ll = scanner.nextInt();
			var rr = scanner.nextInt();
			l = Math.max(l, ll);
			r = Math.min(r, rr);

			if(r < l) {
				System.out.println(0);
				scanner.close();
				return;
			}
		}
		System.out.println(r - l + 1);
		scanner.close();
	}

}


Measured memory_bytes: 58252