akhauriyash/Code-Regression huggingface dataset:
# 複素数版

# 凸包 Monotone Chain O(nlogn)
# 参考: https://matsu7874.hatenablog.com/entry/2018/12/17/025713
def get_convex_hull(points):
    def det(p, q):
        return (p.conjugate()*q).imag
    points.sort(key=lambda x: (x.real, x.imag))
    ch = []
    for p in points:
        while len(ch) > 1:
            v_cur = ch[-1]-ch[-2]
            v_new = p-ch[-2]
            if det(v_cur, v_new) > 0:
                break
            ch.pop()
        ch.append(p)
    t = len(ch)
    for p in points[-2::-1]:
        while len(ch) > t:
            v_cur = ch[-1]-ch[-2]
            v_new = p-ch[-2]
            if det(v_cur, v_new) > 0:
                break
            ch.pop()
        ch.append(p)
    return ch[:-1]


N = int(input())
XY = [complex(*map(int, input().split())) for _ in range(N)]
ps = [complex(0, 0)]
for p in XY:
    ps_new = ps[:]
    for p_ in ps:
        ps_new.append(p+p_)
    ps = get_convex_hull(ps_new)
ans = 0
for p in ps:
    ans = max(ans, abs(p))
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sstream>

using namespace std;

int main(){
    unsigned long W, H, x, y;
    cin >> W >> H >> x >> y;

    cout << double(W * H) / 2 << " ";
    if((x*2) == W && (y * 2) == H) cout << 1 << endl;
    else                           cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from bisect import bisect_left, bisect_right


def input():
    return sys.stdin.readline().rstrip()


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

    L.sort()
    count = 0

    for j in range(1, N - 1):
        rem = L[j + 1:]
        for i in range(j):
            if L[i] == L[j]:
                break

            count += bisect_left(rem, L[i] + L[j]) - bisect_right(rem, L[j])

    print(count)


if __name__ == "__main__":
    main()


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int a, b;
    cin >> a >> b;
    int diff = b - a;
    int ans = (diff * (diff + 1) / 2) - b;
    c(ans);
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toInt)
    val g = Array(n) { BooleanArray(n) }
    repeat(m) {
        val (a, b) = readLine()!!.split(' ').map(String::toInt)
        g[a - 1][b - 1] = true
        g[b - 1][a - 1] = true
    }
    val visited = BooleanArray(n)
    fun dfs(v: Int): Int {
        if (visited.all { it }) return 1
        var cnt = 0
        for (i in 0 until n) {
            // println("g[$v][$i] = ${g[v][i]}; visited[$i] = ${visited[i]}")
            if (!g[v][i] || visited[i]) continue
            visited[i] = true
            cnt += dfs(i)
            visited[i] = false
        }
        return cnt
    }
    visited[0] = true
    println(dfs(0))
}


Measured memory_bytes: 38080
#include <iostream>
using namespace std;
int n,W;
long long ans,w[110],v[110],f[110][100010];
int main()
{
	cin>>n>>W;
	for(int i=1;i<=n;i++) cin>>w[i]>>v[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=W;j++)
		{
			f[i][j]=f[i-1][j];
			if(j>=w[i]) f[i][j]=max(f[i][j],f[i-1][j-w[i]]+v[i]);
		}
	for(int i=1;i<=W;i++) ans=max(ans,f[n][i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 81704
#include<cstdio>
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main() {
	int a, b, c, k, t = 0;
	cin >> a >> b >> c >> k;
	if (k > a + b) {
		t = a - (k - a - b);
	}
	else if (k == a + b) {
		t = a;
	}
	else if (k > a && k < a + b) {
		t = a;
	}
	else if (k == a) {
		t = a;
	}
	else if (k < a) {
		t = k;
	}
	cout << t << endl;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N); 
	int Max = 0;
	for (int n = 0;n<N;++n) {
		cin >> A[n];
		Max = max(Max,A[n]);
	}	
	//桁数求めて
	int l = 0;
	while (true) {
		int q = 1 << l;
		q--;
		if (q >= Max) {
			break;
		}
		l++;
	}
	int x = 0;
	for (int m = 0; m < N; ++m) {
		x = x xor A[m];
	}
	//偶数奇数場合分け必要。
	for (int n = 0; n < N; ++n) {
		int y;
		y = x xor A[n];

		if (0 == N%2) {
			cout << y << endl;
		}
		else {
			int n = 1 << l;
			n--;
			y = n xor y;
			cout << y << endl;
		}
	}

	return 0;
}

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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;
typedef pair<int, int> pii;

int w, h;
int m[20][20];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void dfs(int nw, int nh){
  REP(i, 4){
    if(nw + dx[i] < 0 or nw + dx[i] >= w or nh + dy[i] < 0 or nh + dy[i] >= h) continue;
    if(m[nw+dx[i]][nh+dy[i]] == 1) { m[nw+dx[i]][nh+dy[i]] = 2; dfs(nw+dx[i], nh+dy[i]); }
  }
  return;
}

int main(){
  while(cin >> w >> h and w + h){
    int sw, sh;
    REP(i, h){
      string str;
      cin >> str;
      REP(j, w) { m[j][i] = (str[j] == '#' ? -1 : 1); if(str[j] == '@') { sw = j; sh = i; m[j][i] = 2; } }
    }
    dfs(sw, sh);
    int res = 0;
    REP(i, h) REP(j, w) if(m[j][i] == 2) res++;
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class I,class V=typename I::value_type>V sum_up(const I&l,const I&r){V v;for(I i=l;i!=r;i++)v=i==l?*i:v+*i;return v;}
template<class I,class T=iterator_traits<I>>I operator+(I it,int n){for(int i=0;i<n;i++)it++;return it;}
template<class I,class T=iterator_traits<I>>I operator-(I it,int n){for(int i=0;i<n;i++)it--;return it;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    const int INF = 1e8;
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    for(int &x : A) cin >> x;
    int ans = INF;
    for(int i = 0; i < N; i++) {
        int x = A[i];
        int y = i ? A[i - 1] : A[N - 1];
        if (i) {
            ans = min(ans, K - (x - y) );
        } else {
            ans = min(ans, K - (x + (K - y)));
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        String s = sc.next();
        
        int x = 0;
        int max = 0;
        for(int i=0; i<n; i++){
            char c = s.charAt(i);
            if(c == 'I'){
                x++;
            }
            if(c == 'D'){
                x--;
            }
            if(max < x){
                max = x;
            }
        }
        
        System.out.println(max);    
    }
}

Measured memory_bytes: 23764
#include<stdio.h>
int main(void){
    int num,num2,num3,kazu[1001],ans,run,i,j,k,k2,l;
    for(;;){
        ans=0;
        scanf("%d",&num);
        if(num==0)break;
            for(i=0;i<num;i++){
                scanf("%d",&kazu[i]);
                num2=num-1;
            }
                for(j=0;j<num;j++){
                    for(k=0;k<num2;k++){
                        k2=k+1;
                        if(kazu[k]>kazu[k2]){
                            run=kazu[k];
                            kazu[k]=kazu[k2];
                            kazu[k2]=run;
                            ans++;
                        }
                    }
                }
                printf("%d\n",ans);
    }
return 0;
}

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

int main(void){
	int n;
	int tmp;
	int sum = 0;
	cin >> n;
	int a[200]={999};
	for(int i=0;i<2*n;i++){
		cin >> a[i];
	}
	for(int i=0;i<(2*n)-1;i++){
		for(int j=i;j<(2*n);j++){
			if(a[i]>a[j]){
				tmp=a[i];
				a[i]=a[j];
				a[j]=tmp;
			}
		}
	}
	for(int i=0;i<n;i++){
		if(a[2*i]!=999)	sum += a[2*i];
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstring>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <unordered_map>

#define DEBUG false
#define OJ_DEBUG

#define $(x) {if (DEBUG) {cout << __LINE__ << ": "; {x} cout << endl;}}
#define _(x) {cout << #x << " = " << x << " "; }
const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef std::pair<int, int> pii;
typedef unsigned long ul;

int main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, r;
    cin >> n >> r;
    if (n >= 10) {
        cout << r << '\n';
        return 0;
    }
    cout << r + 100 * (10 - n) << '\n';
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define PB push_back
#define F first
#define S second
#define mkp make_pair

static const int INF=1<<24;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;





struct E{
	int v,l,thief;
};

int N,M,L;
vector<vector<E> > a;
priority_queue<E> pq;
int dp[110][110];

bool operator < (E a,E b){
	return a.thief>b.thief;
}


int dij(){
	rep(i,110) rep(j,110) dp[i][j]=INF;
	E tmp;
	tmp.v=0;
	tmp.l=0;
	tmp.thief=0;
	pq.push(tmp);
	dp[0][0]=0;
	int ans=INF;
	while(!pq.empty()){
		E now = pq.top();
		//cout<<now.v<<" "<<now.l<<" "<<now.thief<<endl;
		pq.pop();
		if(now.v==N-1){
			if(now.l<=L) ans=min(ans,now.thief);
			continue;
		}
		rep(i,a[now.v].size()){
			E next = a[now.v][i];
			//雇う
			if(next.l+now.l<=105){
				if(now.thief<dp[next.l+now.l][next.v]){
					// if(next.l+now.l>110) cout<<"hoge "<<dp[next.l+now.l][next.v]<<" "<<next.l+now.l<<endl; 
					dp[next.l+now.l][next.v]=now.thief;
					// cout<<"dp "<<dp[next.l+now.l][next.v]<<" "<<next.l+now.l<<" "<<next.v<<endl;
					E t1=next;
					t1.l+=now.l;
					t1.thief=now.thief;
					pq.push(t1);
				}
			}
			//雇わない
			if(now.thief+next.thief<dp[now.l][next.v]){
				dp[now.l][next.v]=now.thief+next.thief;
				// cout<<"dp "<<dp[now.l][next.v]<<" "<<now.l<<" "<<next.v<<endl;
				E t1=next;
				t1.l=now.l;
				t1.thief+=now.thief;
				pq.push(t1);				
			}
		}
	}
	return ans;
}


int main(){
	while(cin>>N>>M>>L,N||M||L){
		a.resize(N);
		rep(i,N) a.clear();
		rep(i,M){
			int b,c,l,thi;
			cin>>b>>c>>l>>thi;
			b--;
			c--;
			E t1,t2;
			t1.v=b;
			t1.l=l;
			t1.thief=thi;
			t2.v=c;
			t2.l=l;
			t2.thief=thi;
			a[c].PB(t1);
			a[b].PB(t2);
		}
		cout<<dij()<<endl;
	}
	return 0;
}

Measured memory_bytes: 2264
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long k, n, ans = k; cin >> k >> n;

    vector<long long> a(n);

    for(long long i = 0; i < n; i++) {
        cin >> a[i];
        if(i) ans = min(ans, k - (a[i] - a[i - 1]));
    }

    ans = min(ans, k - (k - a[n - 1]) - a[0]);

    cout << ans;

    return 0;
}


Measured memory_bytes: 4764
package main

import "fmt"

func main() {
	var k int
	fmt.Scan(&k)
	var r, ans int
	m := make(map[int]bool)
	for {
		ans++
		r *= 10
		r += 7
		r %= k
		if r == 0 {
			fmt.Println(ans)
			return
		}
		if m[r] {
			fmt.Println("-1")
			return
		}
		m[r] = true
	}
}


Measured memory_bytes: 51712
#include <bits/stdc++.h>
using namespace std;
 
#define forn(a, e) for (int a = 0; a < (int)(e); a++)
#define forr(a, s, e) for (int a = s; a < (int)(e); a++)
#define fore(e, a) for (auto& e : a)
 
#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logvff(a, f1, f2) {cerr << #a".{"#f1 << ", "#f2 << "} = \n"; fore(e, a) { cerr << "(" << e.f1 <<", " << e.f2 << ") ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logvff(a, f1, f2)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif
 
using i64 = long long;
using iip = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;
template<typename T> using vec = vector<T>;
 
template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }
 
template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }
 
template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }
 
// template<typename ...T>
// istream& read(T&... args) { return (cin >> ... >> args); }
 
static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }
i64 gcd (i64 a, i64 b) {
	if (b == 0)
		return a;
	else
		return gcd (b, a % b);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 
  i64 n;
  while (cin >> n) {
    const i64 maxN = 1e18;
    i64 p5 = 1;
    i64 pp5 = 0;
    while (p5 * 5 <= maxN) {
      p5 *= 5;
      pp5++;
    }

    if (n % 2 == 1) {
      cout << 0 << endl;
      continue;
    }

    i64 a = p5;
    i64 s = 0;
    i64 ans = 0;
    i64 p = pp5;
    while (a > 1) {
      i64 c = (n / a) / 2 - s;
      s += c;
      ans += c * p;
      p--;
      a /= 5;
    }
    // logss(c5, c2);
    // ans += min(c5, c2);
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
import std.stdio, std.algorithm;

int getNum(ulong state, int i){
	return (state >> i*4) & 0xf;
}
ulong setNum(ref ulong state, int i, int j){
	state &= ~(0xfuL<<i*4);
	return state |= (j&0xfuL)<<i*4;
}

int solve(ulong state, int[][] landNeighbor, int[][] numNeighbor, int dim = 0, int[ulong] memo = [0:0]){
	if(int* res = state in memo) return *res;
	
	int rec(int chestnum, ulong state, int[] neighbors){
		if(chestnum == 0) return solve(state, landNeighbor, numNeighbor, dim+1, memo);
		int result = int.max;
		foreach(i, land; neighbors[0..$-chestnum+1]){
			bool ok = true;
			ulong newState = state;
			foreach(num; landNeighbor[land]){
				int cnum;
				if((cnum = newState.getNum(num)) == 0){
					ok = false;
					break;
				}
				newState.setNum(num, cnum-1);
			}
			if(ok) result = result.min(rec(chestnum-1, newState, neighbors[i+1..$]));
		}
		return result;
	}
	
	int num = state.getNum(dim);
	int result = rec(num, state, numNeighbor[dim]);
	if(result != int.max) result += num;
	return memo[state] = result;
}

void main(){
	while(true){
		int h, w;
		readf("%d %d\n", &h, &w);
		if(h == 0 || w == 0) break;
		int[2][] land;
		int[2][] num;
		ulong numstate = 0;
		char[] buf;
		int rad = 0;
		foreach(y; 0..h){
			readln(buf);
			foreach(int x, c; buf[0..$-1]){
				switch(c){
				case '.': break;
				case '*': land ~= [y,x]; break;
				default:
					if('0' <= c && c <= '9'){
						land ~= [y,x];
						if(c != '0') {
							num ~= [y,x];
							numstate.setNum(rad++, c-'0');
						}
						break;
					}
				}
			}
		}
		int[][] numNeighbor, landNeighbor;
		numNeighbor.length = num.length;
		foreach(k; land){
			size_t landNum = size_t.max;
			foreach(y; max(0,k[0]-1)..min(h,k[0]+1)+1)
				foreach(x; max(0,k[1]-1)..min(w,k[1]+1)+1){
					ptrdiff_t n = num.countUntil([y, x]);
					if(n >= 0){
						if(landNum == size_t.max) {
							landNum = landNeighbor.length;
							landNeighbor ~= [cast(int)n];
						}else{
							landNeighbor[landNum] ~= cast(int)n;
						}
						numNeighbor[n] ~= cast(int)landNum;
					}
				}
		}
		writeln(solve(numstate, landNeighbor, numNeighbor));
	}
}

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

int main()
{
	long long n, k;
	cin >> n >> k;
	vector<long long> a(n), f(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> f[i];
	sort(a.begin(), a.end());
	sort(f.rbegin(), f.rend());
	long long l = -1;
	long long r = 1e12;
	while(abs(l - r) > 1) {
		long long mid = (l + r) / 2;
		bool ok = [&] {
			long long s = 0;
			for(int i = 0; i < n; i++) {
				s += max(0LL, a[i] - mid / f[i]);
			}
			return s <= k;
		}();
		if(ok) r = mid;
		else l = mid;
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 6400
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef pair<int, int> P;
typedef long long int ll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

string s[12];
int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
int ans;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(cin >> s[0]){
		rep(i,11) cin >> s[i+1];
		bool check[12][12];
		queue<P> que;
		clr(check,0);
		ans = 0;
		rep(i,12){
			rep(j,12){
				if(s[i][j]=='0'||check[i][j]==true) continue;
				check[i][j] = true;
				ans++;
				que.push(P(i,j));
				while(que.size()){
					P q = que.front(); que.pop();
					rep(k,4){
						P p;
						p.fi = q.fi+dx[k]; p.sec = q.sec+dy[k];
						if(0<=p.fi&&p.fi<12&&0<=p.sec&&p.sec<12){
							if(check[p.fi][p.sec]==false&&s[p.fi][p.sec]=='1'){
								check[p.fi][p.sec]=true;
								que.push(P(p.fi,p.sec));
							}
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}

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

int main(){
  char s[258] = {}, tmp[258] = {};
  int m, h, i, l;
  while(scanf("%s", s) && s[0] != '-'){
    scanf("%d", &m);
    while(m--){
      scanf("%d", &h);
      strcpy(tmp, s + h);
      s[h] = '\0';
      strcat(tmp, s);
      strcpy(s, tmp);
    }
    puts(s);
  }
  return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <algorithm>

using namespace std;

int h, w;
int data[10][10000];
int next[10][10000];

main(){
  while(cin >> h >> w && (h || w)){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> data[i][j];
      }
    }
    int ans = 0;
    for(int t=0;t<(1<<h);t++){
      int sum1 = 0;
      for(int j=0;j<w;j++){
	int sum2 = 0;
	for(int i=0;i<h;i++){
	  if((1<<i) & t) sum2 += 1-data[i][j];
	  else sum2 += data[i][j];
	}
	sum1 += max(sum2, h-sum2);
      }
      ans = max(ans, sum1);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Tree Construction
// 2012/12/20
public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;

	int n;
	int[] xs, ys;

	void run(){
		n=sc.nextInt();
		xs=new int[n];
		ys=new int[n];
		for(int i=0; i<n; i++){
			xs[i]=sc.nextInt();
			ys[i]=sc.nextInt();
		}
		solve();
	}

	void solve(){
		int[][] dp1=new int[n+1][n+1];
		int[][] dp2=new int[n+1][n+1];
		int[][] dp=new int[n+1][n+1];
		int[][] k=new int[n+1][n+1];
		for(int i=0; i<=n; i++){
			fill(dp1[i], INF);
			fill(dp2[i], INF);
			fill(dp[i], INF);
			dp1[i][i]=dp2[i][i]=0;
			if(i<n){
				dp1[i][i+1]=dp2[i][i+1]=0;
			}
			k[i][i]=i;
		}
		for(int w=1; w<=n; w++){
			for(int i=0, j=w; j<=n; i++, j++){
				int min=INF;
				for(int r=k[i][j-1]; r<=k[i+1][j]; r++){
					int v=dp1[i][r]+dp2[r][j];
					if(v<min){
						min=v;
						k[i][j]=r;
						dp1[i][j]=v+xs[j-1]-xs[i];
						dp2[i][j]=v+ys[i]-ys[j-1];
						dp[i][j]=v+xs[j-1]-xs[i]+ys[i]-ys[j-1];
					}
				}
			}
		}
		println(dp[0][n]+"");
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 28000
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int n,m;
int a[200010];
int cnt[200010];
int sum[200010];
int ans;
void upd(int x,int v)
{
	if(x>cnt[x])
	{
		sum[x-cnt[x]]+=v;
		if(v==1 && sum[x-cnt[x]]==1)ans--;
		if(v==-1 && sum[x-cnt[x]]==0)ans++;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	ans=n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",a+i);
		upd(a[i],1);
		cnt[a[i]]++;
	}
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		cnt[a[x]]--;
		upd(a[x],-1);
		upd(y,1);
		cnt[y]++;
		a[x]=y;
		printf("%d\n",ans);
	}
	return 0;
} 

Measured memory_bytes: 3712
N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]


mod = 998244353
dp = [0] * (N + 1)
dpsum = [0] * (N + 1)
dp[1] = 1
dpsum[1] = 1
for i in range(2, N + 1):
    for j in range(K):
        li = max(i - LR[j][1], 1)
        ri = i - LR[j][0]
        if ri < 0:
            continue
        dp[i] += dpsum[ri] - dpsum[li - 1]
        dp[i] %= mod
    dpsum[i] = dpsum[i - 1] + dp[i]

print(dp[N])


Measured memory_bytes: 76784
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
       int A =sc.nextInt();
       int B =sc.nextInt();
       if(A==1)A=14;
       if(B==1)B=14;
       if(A==B)System.out.println("Draw");
       if(A>B)System.out.println("Alice");
       if(B>A)System.out.println("Bob");
    }
}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC166B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);
            int[] Array=new int[N];
            int[] d = new int[K];
            Queue<int> Arrayd = new Queue<int>();
            for(int i = 0; i < K; i++)
            {
                d[i] = int.Parse(Console.ReadLine());
                string[] Ad=Console.ReadLine().Split(' ');
                for(int j = 0; j < d[i]; j++)
                {
                    Arrayd.Enqueue(int.Parse(Ad[j]));
                }
            }
            while (Arrayd.Count != 0)
            {
                Array[Arrayd.Dequeue()-1] += 1;
            }
            //Console.WriteLine(Arrayd.ElementAt(1));
            int count = 0;
            for (int i = 0; i < N; i++)
            {
                if (Array[i] == 0)
                {
                    count += 1;
                }
            }
            Console.WriteLine(count);
        }
    }
}


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

int gcd(int a, int b)
{
	if (b == 0)
		return a;

	return gcd(b, a % b);
}

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

	vector<int> v, f, b, t;
	for (int i = 0; i < n; ++i)
	{
		int num;
		cin >> num;
		v.push_back(num);
	}

	f.push_back(v[0]);
	b.push_back(v[n - 1]);
	for (int i = 0; i < n - 2; ++i)
	{
		f.push_back(gcd(f[i], v[i+1]));
		b.push_back(gcd(b[i], v[n - 2 - i]));
	}

	t.push_back(f[n - 2]);
	t.push_back(b[n - 2]);

	for (int i = 0; i < n - 2; ++i)
		t.push_back(gcd(f[i], b[n - 3 - i]));
	
	int max = 1;
	for (int i = 0; i < n; ++i)
	{
		if (max < t[i])
			max = t[i];
	}
	
	cout << max;

	return 0;
}

Measured memory_bytes: 2296
import numpy as np

N = int(input())

dp = np.zeros(N+1, dtype=int)

dp[0] = 0


for n in range(1, N+1):
    minv = dp[n-1]

    multi = 1
    six = n - int(pow(6, multi))
    while six >= 0:
        value = dp[six]
        if value < minv:
            minv = value
        multi += 1
        six = n - int(pow(6, multi))

    multi = 1
    nine = n - int(pow(9, multi))
    while nine >= 0:
        value = dp[nine]
        if value < minv:
            minv = value
        multi += 1
        nine = n - int(pow(9, multi))

    dp[n] = minv + 1

print(dp[N])


Measured memory_bytes: 14404
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

class UF{
public:
  Int V;
  vector<Int> par,rnk,sz;
  UF(){}
  UF(Int V):V(V),par(V),rnk(V,0),sz(V,1){for(Int i=0;i<V;i++)par[i]=i;}
  
  Int find(Int x){
    assert(x < V);
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(Int x,Int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(rnk[x]<rnk[y])par[x]=y, sz[y] += sz[x];
    else{
      par[y]=x;
      sz[x] += sz[y];
      if(rnk[x]==rnk[y])rnk[x]++;
    }
  }

  bool same(Int x,Int y){return find(x)==find(y);}

  Int size(Int x){return sz[find(x)];}
};


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, M;
  cin>>N>>M;
  vector<Int> A(M), B(M);
  for(Int i=0;i<M;i++) cin>>A[i]>>B[i], A[i]--, B[i]--;
  
  UF uf(N);
  vector<Int> ans(M);
  Int num = (N * (N - 1)) / 2;
  ans[M-1] = num;
  for(Int i=0;i<M-1;i++){
    Int a = A[M-1-i], b = B[M-1-i];
    if(!uf.same(a, b)){
      Int sizeA = uf.size(a);
      Int sizeB = uf.size(b);
      num = num - (sizeA * (N - sizeA)) - (sizeB * (N - sizeB)) + (sizeA * sizeB);
      uf.unite(a, b);
      num = num + (uf.size(a) * (N - uf.size(a)));
    }
    ans[M-2-i] = num;
  }

  for(Int i=0;i<M;i++) cout<<ans[i]<<endl;
  return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;

int main(){
   int n;cin >>n;
   vector<int>a(n);
   map<int,int>cnt;
    for (int i = 0; i < n; ++i) {
        cin >>a[i];
        cnt[a[i]]++;
        cnt[a[i]+1]++;
        cnt[a[i]-1]++;
    }
    int mx=0;
    for(auto p:cnt){
        mx=max(mx,p.second);
    }
    cout <<mx<<endl;
}


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

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] ss = line.split(" ");
		int a = Integer.parseInt(ss[0]);
		int b = Integer.parseInt(ss[1]);
		int c = Integer.parseInt(ss[2]);
		int cnt = 0;

		for (int i = a; i <= b; i++) {
			if (c % i == 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 26140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

ll n;
void test() {
    cin>>n;
    vector<ll> a(n*2);
    for (ll i=0; i<n*2; i+=2) {
        cin>>a[i];
        a[i+1]=a[i];
    }
    sort(a.begin(),a.end(),greater<ll>());
    ll ans=0;
    for (ll i=1; i<n; ++i) {
        ans+=a[i];
        //cout<<a[i]<<' ';
    }
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int t; cin>>t;
    // while (t--) {
    //     test();
    // }
    test();
    // for (int i=1; i<=t; ++i) {
    //     cout<<"Case #"<<i<<": ";
    //     test();
    // }
    return 0;
}

Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 200005;
const long long MOD = 1000000007;
const long long MODMOD = 998244353;

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long gcd(long long a, long long b) {
  if(a % b == 0) return b;
  else return gcd(b, a % b);
}

int main() {
  vector<vector<int>> a(3, vector<int>(3));
  rep(i, 3) rep(j, 3) cin >> a[i][j];
  vector<vector<int>> ans(3, vector<int>(3));
  int n;
  cin >> n;
  rep(i, n) {
    int b;
    cin >> b;
    rep(j, 3) rep(k, 3) {
      if(a[j][k] == b) ans[j][k]++;
    }
  }
  bool yes = false;
  rep(i, 3) {
    bool equal = true;
    rep(j, 3) {
      if(!ans[i][j]) equal = false;
    }
    if(equal) yes = true;
  }
  rep(i, 3) {
    bool equal = true;
    rep(j, 3) {
      if(!ans[j][i]) equal = false;
    }
    if(equal) yes = true;
  }
  if(ans[0][0] != 0 && ans[1][1] != 0 && ans[2][2] != 0) yes = true;
  if(ans[2][0] != 0 && ans[1][1] != 0 && ans[0][2] != 0) yes = true;

  if(yes) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();

        int ans = 0;

        for (int i = 0; i<a.length();i++){
            if (a.charAt(i) == '1')
                ans+=1;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 35588
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

bool isLucky(string &s) {
	for (char ch : s)
		if(ch=='7') return true;
	return false;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	cout<<(isLucky(s) ? "Yes" : "No")<<endl;
	return 0;
}

Measured memory_bytes: 3644
N,M=map(int,input().split())
numbers=[{} for n in range(N)]
for m in range(M):
    P,Y=map(int,input().split())
    numbers[P-1][m]=Y
answers={}
for n in range(N):
    number=numbers[n]
    if len(number)==0:
        continue
    new_number=sorted(number.items(), key=lambda x:x[1])
    suuji=1
    for num in new_number:
        answers[num[0]]=(6-len(str(n+1)))*'0'+str(n+1)+(6-len(str(suuji)))*'0'+str(suuji)
        suuji+=1
answer=sorted(answers.items(), key=lambda x:x[0])
for ans in answer:
    print(ans[1])
    

Measured memory_bytes: 59824
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)

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

    ll n, m;
    cin >> n >> m;
    vector<ll> a(m);
    vector<ll> c(m);
    rep(i, 0, m) {
        cin >> a[i];
        int b;
        cin >> b;
        while (b--) {
            int d;
            cin >> d;
            c[i] += 1 << (d - 1);
        }
    }
    vector<ll> dp(10000, 1e18);
    dp[0] = 0;
    rep(i, 0, m) {
        for (ll j = (1 << n) - 2; j >= 0; j--) {
            dp[j | c[i]] = min(dp[j | c[i]], dp[j] + a[i]);
        }
    }

    if (dp[(1 << n) - 1] == 1e18)
        cout << -1 << endl;
    else
        cout << dp[(1 << n) - 1] << endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int ans;
int main()
{
    string s, t = "CODEFESTIVAL2016";
    cin>>s;
    for(int i = 0 ; i < s.size(); i++ )
        if( s[i] != t[i] ) ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
N,A,B = map(int,input().split())
if (B - A) % 2 == 0:
  print((B - A) // 2)
else:
  LB = B - (A - 1) - 1
  L = (A - 1) + 1 + (LB - 1) // 2
  RA = A + (N - B + 1)
  R = (N - B + 1) + (N - RA) // 2
  print(min(L,R))

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

int main()
{
    int wp[14][14]={0};
    int x,y,s;
    while(scanf("%d,%d,%d",&x,&y,&s)!=EOF)
    {
        if(s==1){
            int dx[5]={-1,1,0,0,0},dy[5]={0,0,1,-1,0};
            for(int i=0;i<5;++i){
                wp[x+2+dx[i]][y+2+dy[i]]+=1;
            }
        }
        if(s==2){
            int dx[9]={-1,1,0,0,0,-1,-1,1,1},dy[9]={0,0,1,-1,0,-1,1,-1,1};
            for(int i=0;i<9;++i){
                wp[x+2+dx[i]][y+2+dy[i]]+=1;
            }
        }
        if(s==3){
            int dx[13]={-1,1,0,0,0,-1,-1,1,1,0,0,2,-2},dy[13]={0,0,1,-1,0,-1,1,-1,1,-2,2,0,0};
            for(int i=0;i<13;++i){
                wp[x+2+dx[i]][y+2+dy[i]]+=1;
            }
        }
    }
    int wc=0,mdc=0;
    for(int i=2;i<12;++i){
        for(int j=2;j<12;++j){
            if(!wp[i][j])wc++;
            if(wp[i][j]>mdc)mdc=wp[i][j];
        }
    }
    cout<<wc<<endl<<mdc<<endl;
    return 0;
}

Measured memory_bytes: 1204
#include<iostream>
using namespace std ;
int main()
{
    int n,x;
    cin >> n ;
    string s ;
    cin >> s ;
    for(int i=0;i<s.size();i++)
    {
        char c = s[i];
        x = c-'0';
        x+=n;
        if(x>42)
        {
            x=x%42-1;
            c='A';
            c+=x;
        }
        else
        {
            c+=n;
        }
        cout << c ;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<array>
#include<list>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<functional>
#include<memory>
#include<random>
#include<sstream>
#include<iomanip>
#include<thread>

using namespace std;

using ll = unsigned long long;

using vec = vector<ll>;
using mat = vector<vec>;


mat cell;
vec parent;
vec white;
vec black;

ll H, W, HW;

ll find(ll i)
{
	if (parent[i] == i)
	{
		return i;
	}
	else
	{
		return parent[i] = find(parent[i]);
	}
}

void unite(ll i, ll j)
{
	i = find(i);
	j = find(j);

	if (i == j)return;

	parent[j] = i;
	white[i] += white[j];
	black[i] += black[j];

}

ll index(ll x,ll y)
{
	return y*W + x;
}


int main()
{
	cin >> H >> W;
	HW = H*W;

	cell = mat(H, vec(W));
	parent = vec(HW, 0);
	white = vec(HW, 0);
	black = vec(HW, 0);

	for (ll i = 0; i < HW; ++i)
	{
		parent[i] = i;
	}

	for (ll y = 0; y < H; ++y)
	{
		string s;
		cin >> s;
		for (ll x = 0; x < W; ++x)
		{
			
			cell[y][x] = (s[x] == '#') ? 1 : 0;
			
			if (cell[y][x] == 1)
			{
				black[index(x, y)] = 1;
			}
			else
			{
				white[index(x, y)] = 1;
			}
			
		}
	}
	
	for (ll y = 0; y < H - 1; ++y)
	{
		for (ll x = 0; x < W - 1; ++x)
		{
			if (cell[y][x] != cell[y][x + 1])
			{
				unite(index(x, y), index(x + 1, y));
			}
			if (cell[y][x] != cell[y + 1][x])
			{
				unite(index(x, y), index(x, y + 1));
			}
		}
	}

	for (ll y = 0; y < H - 1; ++y)
	{
		if (cell[y][W - 1] != cell[y + 1][W - 1])
		{
			unite(index(W - 1, y), index(W - 1, y + 1));
		}
	}
	for (ll x = 0; x < W - 1; ++x)
	{
		if (cell[H - 1][x] != cell[H - 1][x + 1])
		{
			unite(index(x, H - 1), index(x + 1, H - 1));
		}
	}


	ll ans = 0;

	for (ll i = 0; i < HW; ++i)
	{
		if (parent[i] == i)
		{
			ans += white[i] * black[i];
		}
	}

	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 5248
arr = [1.0]
2.upto(10) do |i|
  if i%2 == 0
    arr[i-1] = arr[i-2]*2.0
  else
    arr[i-1] = arr[i-2]/3.0
  end
end
sum = arr.inject(:+)
while gets do
  n = $_.to_f
  puts sprintf("%.8f", n*sum)
end

Measured memory_bytes: 6132
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

void printvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void printvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void prints(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void printvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}

ll gcd(ll x, ll y)
{
	ll r;

	if (x == 0 || y == 0)  // 引数チェック
	{
		fprintf(stderr, "引数エラーです。\n");
		return 0;
	}

	// ユーグリッドの互除法
	while ((r = x % y) != 0)  // yで割り切れるまでループ
	{
		x = y;
		y = r;
	}
	return y;
}
struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll  c, d, n, m, k, ans = 0, ret = M;
	bool flag = false;
	string s, t;
	ll h, w;
	cin >> n;
	map<ll, ll> mp;
	rep(i, n) {
		cin >> c;
		if (!mp[c]++) ans++;
	}
	if (ans % 2 == 1) cout << ans << endl;
	else cout << ans - 1 << endl;
	return 0;
}


Measured memory_bytes: 6528
package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	fmt.Scan(&N)
	t := make([]int, N+1)
	x := make([]int, N+1)
	y := make([]int, N+1)
	t[0] = 0
	x[0] = 0
	y[0] = 0
	for i := 1; i < N+1; i++ {
		fmt.Scan(&t[i], &x[i], &y[i])
	}
	for i := 1; i < N+1; i++ {
		d := t[i] - t[i-1]
		s := abs(x[i]-x[i-1]) + abs(y[i]-y[i-1])
		if d < s {
			fmt.Println("No")
			return
		}
		if d%2 != s%2 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")

}
func abs(a int) int {
	return int(math.Abs(float64(a)))
}

Measured memory_bytes: 5504
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    long long a,b,c,x,y,p[3];
    cin>>a>>b>>c>>x>>y;
    if(x>=y)
    {
        p[0]=2*x*c;
        p[1]=a*(x-y)+2*c*y;
        p[2]=a*x+b*y;
        sort(p,p+3);
        cout<<p[0]<<endl;
    }
    else
    {
        p[0]=2*y*c;
        p[1]=b*(y-x)+2*x*c;
        p[2]=a*x+b*y;
        sort(p,p+3);
        cout<<p[0]<<endl;
    }
    return 0;
}


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

using namespace std;


int main(void){
	string lef="qwertasdfgzxcvb";
	while(1){
		string str;
		cin >> str;
		if(str=="#")break;
		int cnt=0,flag=-1;
		for(int i=0;i<str.size();i++){
			bool lr=false;
			for(int j=0;j<lef.size();j++){
				if(str[i]==lef[j])lr=true;
			}
			if(flag==0 && !lr){
				flag=1;
				cnt++;
			}
			if(flag==1 && lr){
				flag=0;
				cnt++;
			}
			if(flag==-1){
				if(lr)flag=0;
				else flag=1;
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
typedef long long l;
int main(){
    string s;
    cin>>s;
    int x=0,y=0;
    for(int i=0;i<s.size();i++){
        if(i==0&&s[i]!='A'){
            cout<<"WA"<<endl;
            return 0;
        }
        else if(i>=2&&i<=s.size()-2&&s[i]=='C') x++;
        if(s[i]<97){
          y++;
        }
    }
    if(x==1&&y==2) cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
s=input()
w=[0]*(n+1)
e=[0]*(n+1)
for i in range(n):
    if s[i]=="W":
        w[i+1]=w[i]+1
        e[i+1]=e[i]
    else:
        e[i+1]=e[i]+1
        w[i+1]=w[i]
l=[]
for i in range(1,n+1):
    l.append(w[i-1]+e[n]-e[i])
print(min(l))


Measured memory_bytes: 67420
#include<stdio.h>
#include<math.h>
#define _USE_MATH_DEFINES
int main(){
  int unused __attribute__((unused));
  int A, B, H, M;
  long double rad, rsq;
  unused = scanf("%d %d %d %d", &A, &B, &H, &M);

  rad = 2*M_PI*((long double)H/12.0 + ((long double)M/60.0)/12.0 - (long double)M/60.0);
  rsq = (long double)(A*A + B*B) - (long double)(2*A*B)*cosl(rad);
  printf("%20.20Lf", sqrtl(rsq));
  return 0;
}

Measured memory_bytes: 2576
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int h,w;//h:行，w:列
char garden[110][110];
int dirx[4]={-1,0,1,0};
int diry[4]={0,1,0,-1};
int area;
void DFS(int dx,int dy)
{
    int x,y;
    if(garden[dx][dy]=='#')
    {
        garden[dx][dy]='^';
        for(int i=0;i<4;i++)
        {
            x=dx+dirx[i];
            y=dy+diry[i];
            if(x>=0&&x<h&&y>=0&&y<w&&garden[x][y]=='#')
                DFS(x,y);
        }
    }
    else if(garden[dx][dy]=='*')
    {
        garden[dx][dy]='^';
        for(int i=0;i<4;i++)
        {
            x=dx+dirx[i];
            y=dy+diry[i];
            if(x>=0&&x<h&&y>=0&&y<w&&garden[x][y]=='*')
                DFS(x,y);
        }
    }
    else if(garden[dx][dy]=='@')
    {
        garden[dx][dy]='^';
        for(int i=0;i<4;i++)
        {
            x=dx+dirx[i];
            y=dy+diry[i];
            if(x>=0&&x<h&&y>=0&&y<w&&garden[x][y]=='@')
                DFS(x,y);
        }
    }
}
void solve()
{
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(garden[i][j]=='#')
            {
                DFS(i,j);
                area++;
            }
            else if(garden[i][j]=='*')
            {
                DFS(i,j);
                area++;
            }
            else if(garden[i][j]=='@')
            {
                DFS(i,j);
                area++;
            }
        }
    }
}
int main()
{
    while(scanf("%d%d",&h,&w))
    {
        getchar();
        if(w==0&&h==0)
            break;
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                scanf("%c",&garden[i][j]);
            }
            getchar();
        }
        area=0;
        solve();
        printf("%d\n",area);
    }
    return 0;
}



Measured memory_bytes: 3480