akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std; 
int N; 
vector<int> E[200010]; 
vector<int> A[200010]; 
int S[200010]; // iを根とする部分木のサイズ
void dfs(int now, int parent){
	for(int i = 0; i < E[now].size(); i++){
		if(E[now].at(i) == parent) continue; 
		dfs(E[now].at(i), now); 
		S[now] += S[E[now].at(i)]; 
	}
}
void dfs2(int now, int parent){
	int tmp = N-1; 
	for(int i = 0; i < E[now].size(); i++){
		if(E[now].at(i) == parent) continue; 
		A[now].push_back(S[E[now].at(i)]); 
		tmp -= S[E[now].at(i)]; 
	}
	A[now].push_back(tmp); 
	for(int i = 0; i < E[now].size(); i++){
		if(E[now].at(i) == parent) continue; 
		dfs2(E[now].at(i), now); 
	}
}
long long int Pow(long long int a, int n, long long int m) {
	long long int powa[65];
  	powa[0] = a; 
  	for(int j = 0; j < 64; ++j){
     		powa[j+1] = (powa[j] * powa[j]) % m; 
  	}
	int c = n; 
  	long long int Q = 1; int k = 0; 
	while(c > 0){
  		if(c & 1) Q = (Q * powa[k]) % m; 
		c >>= 1; k++; 
	}
	return Q;
}
int main(){
	cin >> N; 
	for(int i = 0; i < N-1; i++){
		int a, b; cin >> a >> b;  
		a--; b--; 
		E[a].push_back(b); 
		E[b].push_back(a); 
	}
	for(int i = 0; i < N; i++) S[i] = 1; 
	dfs(0, -1); 
	dfs2(0, -1); 
	long long ans = (long long) N; 
	long long P = 1000000007; 
	for(int i = 0; i < N; i++){
		long long tmp = 1000000 * P; 
		for(int j = 0; j < A[i].size(); j++){
			tmp -= Pow(500000004, N - 1 - A[i].at(j), P); 
		}
		tmp += (((long long) A[i].size() - 1) * Pow(500000004, N - 1, P)) % P; 
		tmp %= P; 
		ans += tmp; ans %= P; 
	}
	ans *= 500000004; ans %= P; 
	cout << ans << endl; 
}

Measured memory_bytes: 36224
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char notes[110][10];
ll treasure[3030][3030];
ll dp[3030][3030][4];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>a(n), num;
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll target = a[(n - 1) / 2];
	num.push_back(target);
	a.erase(a.begin() + (n - 1) / 2);
	ll i = 0;
	while (1) {
		num.push_back(a[n - 2 - i]);
		if (num.size() == n)break;
		num.push_back(a[i]);
		if (num.size() == n)break;
		i++;
	}
	if (n % 2) {
		vector<ll>num2(1);
		num2[0] = target;
		ll j = 0;
		while (1) {
			num2.push_back(a[j]);
			if (num2.size() == n)break;
			num2.push_back(a[n - 2 - j]);
			if (num2.size() == n)break;
			j++;
		}
	}
	ll ans = 0;
	rep(i, n - 1) {
		ans += abs(num[i + 1] - num[i]);
	}
	if (n % 2) {
		vector<ll>num2(1);
		num2[0] = target;
		ll j = 0;
		while (1) {
			num2.push_back(a[j]);
			if (num2.size() == n)break;
			num2.push_back(a[n - 2 - j]);
			if (num2.size() == n)break;
			j++;
		}
		ll res = 0;
		rep(i, n - 1) {
			res += abs(num2[i + 1] - num2[i]);
		}
		ans = max(ans, res);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6640
#include<stdio.h>

void swap (int *x, int *y)
{
  int a;
  a=*x;
  *x=*y;
  *y=a;
}

int main(){
  int N,i,j;
  int minj;
  int A[100];
  int count=0;
  
  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<N-1;i++){
    minj = i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj]){
	minj = j;
      }
    }
    if(A[i]==A[minj]){
      count=count;
    }else{
      swap(&A[i],&A[minj]);
      count++;
    }
  }
  
  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i<N-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 604
#include <stdio.h>

void judge(int year, int month, int day)
{
    if ((year < 1868) || ((year == 1868) && ((month < 9) || ((month == 9) && (day <= 7))))) {
        printf("pre-meiji\n");
    } else if ((year < 1912) || ((year == 1912) && ((month < 7) || ((month == 7) && (day <= 29))))) {
        printf("meiji %d %d %d\n", year - 1868 + 1, month, day);
    } else if ((year < 1926) || ((year == 1926) && ((month < 12) || ((month == 12) && (day <= 24))))) {
        printf("taisho %d %d %d\n", year - 1912 + 1, month, day);
    } else if ((year < 1989) || ((year == 1989) && ((month < 1) || ((month == 1) && (day <= 7))))) {
        printf("showa %d %d %d\n", year - 1926 + 1, month, day);
    } else {
        printf("heisei %d %d %d\n", year - 1989 + 1, month, day);
    }
}

int main(void)
{
    int year, month, day;
    while (scanf("%d %d %d", &year, &month, &day) != EOF) {
        judge(year, month, day);
    }
    return 0;
}

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

#define FOR(i, a, b) for(int i = a; i<b; ++i)
#define FR(a, b) for(int i = a; i>=b;--i)
#define _upgrade cin.tie(0); ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define INF 1e16

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int, int> iPair;

const int MAX = 2e5+2;
const int M = 1e9+7;

string s;
int main()
{
    _upgrade;
    cin>>s;
    if(s[2] == s[3] && s[4] == s[5])
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
# C Many Requirements

from itertools import combinations_with_replacement as com

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

C = []
for q in range(Q):
  C.append(tuple(map(int, input().split())))

As = com([i for i in range(1, M+1)], N)

ans = 0
for A in As:
  point = 0
  for Ci in C:
    if A[Ci[1]-1] - A[Ci[0]-1] == Ci[2]:
      point += Ci[3]
  ans = max(ans, point)

print(ans)

Measured memory_bytes: 9140
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.root(x)]

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

    def members(self, x):  # 計算量n
        root = self.root(x)
        return [i for i in range(self.n) if self.root(i) == root]

    def all_roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.all_roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.all_roots()}

    def __str__(self):
        return ''.join('{}: {}'.format(r, self.members(r)) for r in self.all_roots())

n, m = map(int, input().split())
uf = UnionFind(m+n)


kl = [tuple(map(int,input().split())) for i in range(n)]

for i in range(n):
    for j in range(1,kl[i][0]+1):
        uf.union(m+i,kl[i][j]-1)

for i in range(1,n):
    if not uf.is_same(m,m+i):
        print('NO')
        exit()

print('YES')


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

N=int(input())
if N==2:
    print(-1)
    sys.exit()

if N==7:
    S=['.hhagg.\n', 'g..a..h\n', 'g.ee..h\n', 'bb..fcc\n', 'gg..f.h\n', '..hd..h\n', '..hdgg.\n']
    print("".join(S))
    sys.exit()

if N==11:
    S=['......abc..\n', '......abc..\n', '.....igg.dd\n', '.....i..hee\n', '....jj..hff\n', '..ll..kmm..\n', 'ff..h.k....\n', 'ee..hn.....\n', 'ddgg.n.....\n', '..abc......\n', '..abc......\n']
    print("".join(S))
    sys.exit()   

ANS=[["."]*N for i in range(N)]

if N%3==0:
    for i in range(0,N,3):
        ANS[i][i]="a"
        ANS[i][i+1]="a"
        ANS[i+1][i+2]="a"
        ANS[i+2][i+2]="a"
else:
    now=0
    while (N-now)%4!=0:

        i=now
        now+=5

        ANS[i][i]="a"
        ANS[i][i+1]="a"
        ANS[i][i+2]="b"
        ANS[i][i+3]="b"
        ANS[i][i+4]="c"
        ANS[i+1][i+4]="c"
        ANS[i+2][i+4]="d"
        ANS[i+3][i+4]="d"
        ANS[i+4][i+4]="e"
        ANS[i+4][i+3]="e"
        ANS[i+4][i+2]="f"
        ANS[i+4][i+1]="f"
        ANS[i+4][i]="g"
        ANS[i+3][i]="g"
        ANS[i+2][i]="h"
        ANS[i+1][i]="h"

        ANS[i+1][i+1]="i"
        ANS[i+1][i+2]="i"
        ANS[i+2][i+3]="j"
        ANS[i+3][i+3]="j"

    for i in range(now,N,4):
        ANS[i][i]="a"
        ANS[i][i+1]="a"
        ANS[i+1][i]="b"
        ANS[i+1][i+1]="b"

        ANS[i][i+2]="c"
        ANS[i+1][i+2]="c"
        ANS[i][i+3]="d"
        ANS[i+1][i+3]="d"

        ANS[i+2][i+2]="e"
        ANS[i+2][i+3]="e"
        ANS[i+3][i+2]="f"
        ANS[i+3][i+3]="f"

        ANS[i+2][i]="g"
        ANS[i+3][i]="g"
        ANS[i+2][i+1]="h"
        ANS[i+3][i+1]="h"
            
for ans in ANS:
    print("".join(ans))



Measured memory_bytes: 47728
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>

#include <random>
#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

//#define solvsh
//#define multi
#ifdef solvsh

void solve(){

}

#else

void solve() {

    ll x;
    cin >> x;
    ll answr = 0;

    answr = 1000 * (x / 500);
    x %= 500;
    answr += (x / 5) * 5;
    cout << answr;


}

#endif

void multisolve() {
    int t;
    cin >> t;

    int i = 1;
    while (t--) {
//        cout << "Case #" << (i++)  << ": ";
        solve();
//        cout << "\n";
    }
}


#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);


#ifdef multi
    multisolve();
#else
    solve();
//    gen();
#endif

#ifdef LOCAL
    //cout << '\n' << (double)clock() / CLOCKS_PER_SEC << '\n';
#endif
}

Measured memory_bytes: 256
object Main extends App {
  val n = io.StdIn.readLine.toInt
  val ans = Iterator.continually(io.StdIn.readLine)
    .take(n)
    .map(_.split(" ").map(_.toInt))
    .map(in => {
      val Array(t, x, y) = in
      if ((x + y > t) || ((t-x-y) & 1) == 1) false else true
    })
    .takeWhile(_ == true)
    .toArray

  println(if (ans.size == n) "Yes" else "No")
}

Measured memory_bytes: 60024
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>

struct Point
{
    Point(int x = 0, int y = 0) : x(x), y(y) {}

    int x, y;
};

Point operator - (const Point& a, const Point& b)
{
    return Point(a.x - b.x, a.y - b.y);
}

int det(const Point& a, const Point& b)
{
    return a.x * b.y - a.y * b.x;
}

int dot(const Point& a, const Point& b)
{
    return a.x * b.x + a.y * b.y;
}

const int N = 200;
const int MOD = 998244353;

int pw[N + 1];
Point p[N];

int main()
{
#ifdef LOCAL_JUDGE
    freopen("C.in", "r", stdin);
#endif
    int n;
    while (scanf("%d", &n) == 1) {
        for (int i = 0; i < n; ++ i) {
            scanf("%d%d", &p[i].x, &p[i].y);
        }
        pw[0] = 1;
        for (int i = 1; i <= n; ++ i) {
            pw[i] = pw[i - 1] * 2 % MOD;
        }
        int result = pw[n];
        (result += MOD - 1 - n) %= MOD;
        for (int i = 0; i < n; ++ i) {
            for (int j = i + 1; j < n; ++ j) {
                int cnt = 0;
                for (int k = 0; k < n; ++ k) {
                    cnt += det(p[k] - p[i], p[k] - p[j]) == 0 && dot(p[k] - p[i], p[k] - p[j]) < 0;
                }
                result += MOD - pw[cnt];
                if (result >= MOD) {
                    result -= MOD;
                }
            }
        }
        printf("%d\n", result);
    }
}

Measured memory_bytes: 128
use std::io;
use std::io::Write;

fn main() {

    let mut input = String::new();

    io::stdin().read_line(&mut input);
    let mut iter = input.split_whitespace();

    let h = iter.next().unwrap().parse::<usize>().unwrap();
    let w = iter.next().unwrap().parse::<usize>().unwrap();

    let mut a = [[0u8; 100]; 100];

    for i in 0..h {
        let mut line = String::new();

        io::stdin().read_line(&mut line);
        let line = line.as_bytes();
        for j in 0..w {
            a[i as usize][j as usize] = line[j as usize];
        }
    }

    for j in 0..(w+2) {
        print!("#");
    }
    println!("");

    for i in 0..h {
        print!("#");
        io::stdout().write(&a[i as usize][0usize..w]);
        println!("#");
    }

    for j in 0..(w+2) {
        print!("#");
    }
    println!("");
}

Measured memory_bytes: 4352
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    int N, K; cin >> N >> K;
    vector<bool> A(N);
    REP(i, N) A[i] = false;
    REP(i, K){
        int d; cin >> d;
        REP(j, d){
            int sunuke; cin >> sunuke;
            A[sunuke-1] = true;
        }
    }

    int cnt=0;
    REP(i, N){
        if( !A[i] ) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3628
while True:
    x = int(input())
    if x != 0:
        resa = 0
        resb = 0
        for i in range(x):
            a, b = [int(i) for i in input().split()]
            if a > b:
                resa += a + b
            elif b > a:
                resb += a + b
            elif a == b:
                resa += a
                resb += b
        print(resa, resb)
    else:
        break


Measured memory_bytes: 5624
#include "bits/stdc++.h"
using namespace std;
int main(){
    double a, b, c, d, e, f;
    while(cin >> a >> b >> c >> d >> e >> f){
        double M[2][3] = { 
            {a, b, c},
            {d, e, f}
        };
        double d = 0, m = 0;
        for(int i=0; i<2; ++i)
        {  
            d = M[i][i];
            for(int j=0; j<3; ++j){
                M[i][j] = M[i][j] / d;
            }
            for(int k = i+1; k<2; k++){
                m = M[k][i];
                for(int n = i; n<3; ++n){
                    M[k][n] = M[k][n] - m * M[i][n];
                }
            }
        }
        
        for(int i = 1; i>0; --i){
            for(int j= i-1; j>=0; --j){
                d = M[j][i];
                for(int n=i; n<3; ++n){
                    M[j][n] = M[j][n] - d * M[i][n];
                }
            }
        }
        for(int i=0; i<2; i++){
            if(i == 1) {
                printf("%.3lf\n", M[i][2]); break;
            }
            printf("%.3lf ", M[i][2]);
            
        }
    }
    return 0;
}

Measured memory_bytes: 3168
#include <iostream>
#include <vector>
using namespace std;


vector<int> graph[200000];

int f(int pos, int time, int terg);

int main()
{
  int n, m;
  int a, b;
  
  cin >> n >> m;
  for ( int i = 0; i < m; i++) {
    cin >> a >> b;
    a--; b--;

    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  if ( f(0, 0, n - 1) ) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return (0);
}

int f(int pos, int time, int terg) {
  if ( pos == terg ) {
    return 1;
  } else if ( time >= 2 ) {
    return 0;
  }

  int rec = 0;

  for ( int i = 0; i < graph[pos].size(); i++) {
    rec += f(graph[pos][i], time + 1, terg);
  }

  return rec;
}

Measured memory_bytes: 12016
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC optimize("Os")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(ll i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
void vok()
{
    FAST
    FO
    FI
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("error.txt","w",stderr);
    #endif
}
int main()
{
    vok();
    int n,m;
    ll k;
    IN n>>m>>k;
    ll tot=0;
    vll a(n), b(m);
    vll sums(m+1,0);
    loop(i,0,n)
    {
        IN a[i];
    }
    loop(j,0,m)
    {
        IN b[j];
        sums[j+1]=sums[j]+b[j];
    }
    ll curr=0;
    auto it=upper_bound(sums.begin(),sums.end(),k);
    it--;
    int ans=it-sums.begin();
    loop(i,0,n)
    {
        curr+=a[i];
        if(curr>k)
        {
            break;
        }
        int tans=i+1;
        auto it2=upper_bound(sums.begin(),sums.end(),k-curr);
        it2--;
        tans+=(it2-sums.begin());
        ans=max(ans,tans);
    }
    OUT ans<<endl
    return 0;
}

Measured memory_bytes: 7944
from math import fabs
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
tarinai = []
amari = []
for i in range(n):
    if a[i] - b[i] < 0:
        tarinai.append(a[i] - b[i])
    elif a[i] - b[i] > 0:
        amari.append(a[i] - b[i])
tarinai.sort()
amari.sort()
amari.reverse()

ans = 0
if fabs(sum(tarinai)) > sum(amari):
    print('-1')
else:
    ans += len(tarinai)
    val = fabs(sum(tarinai))
    for i in range(n+1):
        #print(val)
        if val <= 0:
            break
        val -= amari[i]
        ans += 1

    print(ans)

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

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for ( int i = 0 ; i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

struct BiMatch{
  int n;
  vector<vector<int> > G;
  vector<int> match,used;
  
  BiMatch(){}
  BiMatch(int sz):n(sz),G(sz),match(sz),used(sz){}
  
  void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }

  bool dfs(int v){
    used[v]=true;
    for(int i=0;i<(int)G[v].size();i++){
      int u=G[v][i],w=match[u];
      if(w<0||(!used[w]&&dfs(w))){
	match[v]=u;
	match[u]=v;
	return true;
      }
    }
    return false;
  }

  int build(){
    int res=0;
    fill(match.begin(),match.end(),-1);
    for(int v=0;v<n;v++){
      if(match[v]<0){
	fill(used.begin(),used.end(),0);
	if(dfs(v)){
	  res++;
	}
      }
    }
    return res;
  }
};

signed main() {
  int n;
  cin >> n;

  BiMatch BM(n+32);
  Rep(i, n) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    for ( int j = a; j <= b; j++ ) {
      BM.add_edge(i, n+j);
    }
  }

  cout << 50*31 + 50*BM.build() << endl;
}

Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>

int main(void){
    char S[16];
    int sl=0;
    int win=0;
    scanf("%s",S);
    sl=strlen(S);
    for(int i=0;i<sl;i++){
        if(S[i]=='o'){
            win++;
        }
    }
    if(win+15-sl>=8) printf("YES\n");
    else printf("NO\n");
    return 0;
}

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

public class Main{
	static void main() throws Exception{
		int x=sc.nextInt(),y=sc.nextInt();
		for(int tu=0;tu<=x;tu++) {
			int cr=x-tu;
			if(tu*4+cr*2==y) {
				pw.println("Yes");
				return;
			}
		}
		pw.println("No");
	}
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
//		int tc=sc.nextInt();
//		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}

Measured memory_bytes: 32876
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <cmath>
using namespace std;

typedef long long ll;

#define rep(i, n) for(ll i=0; i<n; ++i)

//--------------------



int main() {

  int n, d;
  cin >> n >> d;
  double x[n][d];
  rep(i, n) { rep(j, d) cin >> x[i][j]; }

  int cnt = 0;
  for(int i=0; i<n; ++i) {
    for(int j=i+1; j<n; ++j) {
      double s = 0;
      for(int k=0; k<d; ++k) {
        s += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      s = sqrt(s);
      if(ceil(s)==floor(s)) {
        ++cnt;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
vector<int> p(100005);
vector<int> r(100005);
void pre(){
    for(int i=1;i<100005;i++) p[i]=i;
}
int find(int x){
    return p[x]==x?x:p[x]=find(p[x]);
}
void un(int g,int h){
    int a=find(g),b=find(h);
    if(a==b) return;
    if(r[a]>r[b]) p[b]=p[a];
    else {p[a]=p[b];if(r[a]==r[b]) r[a]++;}
}
int main(){
    pre();
    int n,m,a,b,c,t=0;cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        un(a,b);
    }
    for(int i=1;i<=n;i++) if(p[i]==i) t++;
    cout<<t;   
}

Measured memory_bytes: 1024
import sys
import heapq
import math

INF = float("inf")


def main():
    N = int(input())
    ans = N

    for i in range(1, 10**6+1):
        if N % i == 0:
            ans = min(ans, (i - 1) + (N // i - 1))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38640
//author: Harsh :)
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define maxN 100007
using namespace std;
int main(){
  fastio;
  ll n=0,k=0;
  cin>>n>>k;
  ll ar[n];
  for(ll i=0;i<n;++i) cin>>ar[i];
  sort(ar,ar+n);
  cout<<accumulate(ar,ar+k,0);
  return 0;

}


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

mint = sum(a)
divs = []
for i in range(1, int(mint ** 0.5) +1):
    if mint % i == 0:
        divs.append(i)
        if i != mint // i:
            divs.append(mint // i)
divs.sort()
divs = divs[::-1]
result = 1
for i in range(len(divs)-1):
    cur = divs[i]
    sums = 0
    divList = []
    for j in range(n):
        numi = a[j] % cur
        sums += numi
        divList.append(numi)
    divList.sort()
    divList = divList[::-1]
    count = sums
    countV = 0
    for j in range(n):
        count -= divList[j]
        countV += cur - divList[j]
        if count == countV:
            break
    if count <= k:
        result = cur
        break

print(result)

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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int X; cin >> X;
	if(400 <= X && X <= 599){
		cout << 8 << '\n';
	}else if(600 <= X && X <= 799){
		cout << 7 << '\n';
	}else if(800 <= X && X <= 999){
		cout << 6 << '\n';
	}else if(1000 <= X && X <= 1199){
		cout << 5 << '\n';
	}else if(1200 <= X && X <= 1399){
		cout << 4 << '\n';
	}else if(1400 <= X && X <= 1599){
		cout << 3 << '\n';
	}else if(1600 <= X && X <= 1799){
		cout << 2 << '\n';
	}else if(1800 <= X && X <= 1999){
		cout << 1 << '\n';
	}
	
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 3664
#include<iostream>
#include<time.h>
#include<stdlib.h>
#include<string>

using namespace std;

int main(){
    int cnt = 0;
    int n = 0;
    cin >> n;
    string b; cin >> b;
    for(int i = 0; i < n - 2; i++){
        if(b[i] == 'A' && b[i+1] == 'B' && b[i+2] == 'C')
            cnt ++;
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static FastScanner sc;
	static PrintWriter out;
	public static void main(String[] args){
		sc = new FastScanner();
		out = new PrintWriter(System.out);
		out.println(solve());
		out.flush();
	}

	static int solve(){
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int max = Math.max(A, Math.max(B, C));
		if(max == A) return A *10 + B +C;
		else if(max == B) return A + B*10 +C;
		else return C*10 + A + B;
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  bool ok = true;
  rep(i,n) {
    if (a[i]%2 == 1) continue;
    if (a[i]%3 != 0 && a[i]%5 != 0) ok = false;
  }
  if (ok) puts("APPROVED");
  else puts("DENIED");
  return 0;
}

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



int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a >= b && a >= c) {
		cout << a * 10 + b + c << endl;
	}
	else if (b >= a && b >= c) {
		cout << a + b * 10 + c << endl;
	}
	else
		cout << a + b + 10 * c << endl;
	return 0;
}

Measured memory_bytes: 256
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		LL n = -1, k = -1, zc = 0, a, ans;
		cin >> n >> k;
		if (n < 0) return 0;
		vector<LL> neg, pos;
		for (LL i = 0; i < n; ++i) {
			cin >> a;
			if (a > 0) {
				pos.push_back(a);
			} else if (a == 0) {
				++zc;
			} else {
				neg.push_back(a);
			}
		}
		sort(neg.rbegin(), neg.rend());
		sort(pos.begin(), pos.end());
		LL negs = pos.size() * neg.size();
		LL zeros = zc * (pos.size() + neg.size()) + zc * (zc - 1) / 2;
		if (k <= negs) {
			LL left = -1LL << 60, right = 0;
			while (right - left > 1) {
				LL mid = (right + left) / 2;
				LL j = neg.size() - 1;
				LL cnt = 0;
				for (LL a : pos) {
					if (a == 0) continue;
					while (j >= 0 && a * neg[j] < mid) {
						--j;
					}
					cnt += j + 1;
				}
				if (negs - cnt >= k) {
					right = mid;
				} else {
					left = mid;
				}
			}
			ans = left;
		} else if (k <= negs + zeros) {
			ans = 0;
		} else {
			k -= (negs + zeros);
			LL left = -1, right = 1LL << 60;
			LL tot = neg.size() * (neg.size() - 1) / 2 + pos.size() * (pos.size() - 1) / 2;
			while (right - left > 1) {
				LL mid = (right + left) / 2;
				auto calc = [&](const vector<LL> &v) -> LL {
					LL cnt = 0, sz = v.size(), j = sz;
					for (LL i = 0; i < sz; ++i) {
						while (j > 0 && v[i] * v[j - 1] >= mid) {
							--j;
						}
						cnt += sz - j - (j <= i);
					}
					return cnt / 2;
				};
				if (tot - (calc(neg) + calc(pos)) >= k) {
					right = mid;
				} else {
					left = mid;
				}
			}
			ans = left;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 2420
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative

readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons

main = do
  n <- readLn :: IO Int
  let m = if odd n then n `div` 2 + 1 else n `div` 2
      ans = VU.length $ VU.filter ((==8) . length . divisor) $ VU.generate m (\m -> 2*m + 1)
  print ans

divisor' n = loop 1
  where
    loop d
      | n == d = [d]
      | otherwise = if n `mod` d == 0 then d : loop (d+1) else loop (d+1)

divisor n = loop 1
  where
    loop d
      | n < d^2 = []
      | n == d^2 = [d]
      | otherwise = if r == 0 then d : q : loop (d+1) else loop (d+1)
      where (q,r) = n `divMod` d


Measured memory_bytes: 508
my $X = glob <>;
my $Nf = int($X/105);
my $Ns = int($X/100);
for my $N ($Nf..$Ns){
  my $Y = $X - $N*100;
  my $n5 = int($Y/5);
  if ( $Y % 5 ) {
    if ( $n5+1 <= $N ) {
      print 1;
      exit 0;
    }
  } else {
    if ( $n5 <= $N ) {
      print 1;
      exit 0;
    }
  }
}
print 0;

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

public class Main {

    static StreamTokenizer in;

    static int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    static int mod = (int) (1e9 + 7);
    static LinkedList<Integer>[] linkedLists;

    public static void main(String[] args) throws Exception {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = nextInt();

        linkedLists = new LinkedList[n];

        for (int i = 0; i < n; i++) {
            linkedLists[i] = new LinkedList<>();
        }

        for (int i = 0; i < n-1; i++) {
            int node1 = nextInt() - 1;
            int node2 = nextInt() - 1;

            linkedLists[node1].add(node2);
            linkedLists[node2].add(node1);
        }

        Pair p = dfs(0, -1);

        out.println((p.numBlack + p.numWhite) % mod);

        out.close();
    }

    static int multiply(long a, int b) {

        return (int) ((a * b) % mod);
    }

    static Pair dfs(int node, int parent) {
        int white = 1; // always can be white
        int black = 0; // can't always be black

        for (int i : linkedLists[node]) {
            if (i != parent) {
                Pair p = dfs(i, node);
                int oldWhite = white;
                white = multiply(white, p.numWhite);
                black  = (multiply(black, (p.numWhite + p.numBlack) % mod) + multiply(oldWhite, p.numBlack)) % mod;
            }
        }

        return new Pair((white + black) % mod, white);
    }

    static class Pair {
        int numWhite, numBlack; // p.numWhite is the number of ways to color the subtree such that p is white, and conversely p.numBlack is the number of ways when this is black

        Pair(int numWhite, int numBlack) {
            this.numWhite = numWhite;
            this.numBlack = numBlack;
        }
    }
}

Measured memory_bytes: 76388
#include <bits/stdc++.h>
using namespace std;
#define int long long

int N, K, R, S, P;

int char2int(char c) {
  switch (c) {
    case 'r':
      return 0;
    case 's':
      return 1;
    case 'p':
      return 2;
    default:
      cout << "bugtteru" << endl;
      return 0;
  }
}

int dp[100005][3];

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    array<int, 3> point;
    cin >> N >> K >> point[0] >> point[1] >> point[2];
    string T;
    cin >> T;
    vector<string> v(K, "");
    for (int i = 0; i < N; i ++) {
      v[i % K] += T[i];
    }
    int sum = 0;
    for (int ki = 0; ki < K; ki++) {
      for (int j = 0; j < 3; j++) {
        dp[0][j] = 0;
      }
      string& s = v[ki];
      int len = s.length();
      for (int i = 0; i < len; i++) {
        int m = 0;
        for (int j = 0; j < 3; j++) {
          dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + point[j] * (int)((j + 1) % 3 == char2int(s[i]));
        }
      }
      int m = 0;
      for (int j = 0; j < 3; j++) {
        if (dp[len][j] > m) {
          m = dp[len][j];
        }
      }
      sum += m;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

int w, h;
int cnt;
bool B, W;
bool used[51][51];
char data[51][51];

void dfs( int y, int x )
{
  if( !used[y][x] ) {
    used[y][x] = true;
    cnt++;

    for(int i=0; i<4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      
      if( nx < 0 || ny < 0 || nx >= w || ny >= h ) continue;
      if( data[ny][nx] == 'B' ) { B = true; continue; }
      if( data[ny][nx] == 'W' ) { W = true; continue; }

      dfs( ny, nx );
    }
  }
}

main()
{
  while( cin >> w >> h, !(w == 0 && h == 0) ) {
    int Bcnt = 0, Wcnt = 0;
    fill_n( *used, 51*51, false );
 
    Rep(i, h) Rep(j, w) cin >> data[i][j];

    Rep(i, h) Rep(j, w) {
      if( used[i][j] || data[i][j] == 'B' || data[i][j] == 'W' ) continue;
      cnt = 0;
      B = W = false;
      dfs( i, j );
      if( B && !W ) Bcnt += cnt;
      if( W && !B ) Wcnt += cnt;
    }

    cout << Bcnt << " " << Wcnt << endl;
  }
  
}

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

struct p{
  double x;
  double y;
}typedef point;

void koch(int d, point p1, point p2){
  point s, u, t;
  double sin60,cos60;

  sin60 = sin(M_PI / 3);
  cos60 = cos(M_PI / 3);

  if(d == 0)
    {
      printf("%.8f %.8f\n", p2.x, p2.y);
      return;
    }

  s.x = (2 * p1.x + p2.x) / 3;
  s.y = (2 * p1.y + p2.y) / 3;
  t.x = (p1.x + 2 * p2.x) / 3;
  t.y = (p1.y + 2 * p2.y) / 3;
  u.x = (t.x - s.x) * cos60 - (t.y - s.y) * sin60 + s.x;
  u.y = (t.x - s.x) * sin60 + (t.y - s.y) * cos60 + s.y;

  koch(d - 1, p1, s);
  koch(d - 1, s, u);
  koch(d - 1, u, t);
  koch(d - 1, t, p2);
}

int main(){
  int d;
  point p1, p2;

  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;
  scanf("%d", &d);

  printf("%.8f %.8f\n", p1.x, p1.y);
  koch(d, p1, p2);

  return 0;
}

Measured memory_bytes: 644
defmodule Main do

  def main do
    [x, _n] = IO.gets("")
             |> String.trim()
             |> String.split()
             |> Enum.map(&String.to_integer/1)

    p    = IO.gets("")
           |> String.trim()
           |> String.split()
           |> Enum.map(&String.to_integer/1)

    right = x..101 |> Stream.filter(fn x -> not Enum.member?(p, x) end) |> Enum.take(1) |> List.first()
    left  = x..0   |> Stream.filter(fn x -> not Enum.member?(p, x) end) |> Enum.take(1) |> List.first()

    [left, right] |> Enum.sort(&(abs(&1-x) <= abs(&2-x))) |> List.first()
                  |> IO.puts()

  end
end


Measured memory_bytes: 31064
def isPrime(x):
    if x < 2:
        return 0
    elif x == 2:
        return 1
    if x%2 == 0:
        return 0
    ir=int(x**(0.5))+1
    for i  in range(3,ir,2) :
        if x%i == 0:
            return 0
    return 1

n=int(input())

p=[]
for i in range(n+1):
    if isPrime(i):
        p.append(i)

pp=[0]*len(p)
for ni in range(2,n+1):
    for pi in range(len(p)):
        pcnt=0
        nn=ni
        while nn>0:
            if nn%p[pi]==0:
                nn=nn//p[pi]
                pcnt+=1
            else:
                break
        pp[pi]=pp[pi]+pcnt
    
mod=10**9+7
ppp=1
for pi in range(len(p)):
    if pp[pi]!=0:
        ppp=ppp*(pp[pi]+1)%mod
print(ppp)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

//i番目のビットを返す
bool getBit(int num, int i){
    return ((num & (1 << i)) != 0);
}

//i番目を1にする
int setBit(int num, int i){
    return num | (1 << i);
}

//i番目を0にする
int clearBit(int num, int i){
    int mask = ~(1 << i);
    return num & mask;
}

//i番目をvで置き換える
int updateBit(int num, int i, int v){
    int mask = ~(1 << i);
    return (num & mask) | (v << i);
}

const int MAX_N = 50;

int main(){
    int n, ma, mb;
    cin >> n >> ma >> mb;

    int a[MAX_N], b[MAX_N], c[MAX_N];
    rep(i,n) cin >> a[i] >> b[i] >> c[i];

    int m = n / 2;
    n-=m;

    //要素wをnとmに分け、それぞれで全列挙する
    map<pair<int, int>, int> x, y;
    rep(i,(1 << n)){
        pair<int, int> p = make_pair(0,0);
        int sum = 0;
        rep(j,n){
            if(getBit(i,j)){
                p.first += a[j];
                p.second += b[j];
                sum += c[j];
            }
        }
        if(x.count(p)) x[p] = min(x[p], sum);
        else x[p] = sum;
    }
    rep(i,(1 << m)){
        pair<int, int> p = make_pair(0,0);
        int sum = 0;
        rep(j,m){
            if(getBit(i,j)){
                p.first += a[n + j];
                p.second += b[n + j];
                sum += c[n + j];
            }
        }
        if(y.count(p)) y[p] = min(y[p], sum);
        else y[p] = sum;
    }

    int ans = INF;
    for(auto it:y){
        range(j,1,405){
            pair<int, int> p = make_pair(ma * j - it.first.first, mb * j - it.first.second);
            if(x.count(p)){
                ans = min(ans, x[p] + it.second);
            }
        }
    }
    cout << ((ans == INF) ?  -1 : ans ) << endl;
}


Measured memory_bytes: 896
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
    
        double circumference;
        double PI = 3.14159265;
        circumference = 2 * PI * R;
        System.out.println(circumference);
    }
}

Measured memory_bytes: 35880