akhauriyash/Code-Regression huggingface dataset:
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

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

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


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
const int inf = 1e9;
int main(){
    int n; cin >> n;
    vector<int> l(n, inf);
    int len = 0;
    rep(i,n){
        int a; cin >> a;
        //cout << " " << a;
        if(l[len] < a){
            len++;
            l[len] = a;
            //cout << "x";
        }
        else {
            vector<int>::iterator it = lower_bound(all(l), a);
            int tmp = it - l.begin();
            l[tmp] = min(l[tmp], a);
        }
        //cout << "len = " << len << "  " << l[len]<< endl;
    }
    //cout << endl;
    //cout << len << endl;
    //rep(i,len)cout << " " << l[i];
    //cout << endl;
    cout << len + 1 << endl;
    return 0;
}


Measured memory_bytes: 3124
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	u := getNextInt(scanner) - 1
	v := getNextInt(scanner) - 1

	tr := Tree{}
	tr.init(n)
	for i := 0; i < n-1; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		tr.addEdge(a, Edge{
			to: b,
		})
		tr.addEdge(b, Edge{
			to: a,
		})
	}

	lca := Lca{}
	lca.init(n, u, tr.edges)

	ans := lca.depth[v] - 1
	for i := 0; i < n; i++ {
		if i == u {
			continue
		}
		a := lca.get(i, v)
		if lca.depth[a] >= lca.depth[v]-lca.depth[a] {
			continue
		}
		d := lca.depth[v] - lca.depth[a] + lca.depth[i] - lca.depth[a] - 1
		if ans < d {
			ans = d
		}
	}

	fmt.Println(ans)

	writer.Flush()
}

// Tree ...
type Tree struct {
	n      int
	edges  [][]Edge
	dt, da []int
}

func (tr *Tree) init(n int) {
	edges := make([][]Edge, n)
	for i := 0; i < n; i++ {
		edges[i] = make([]Edge, 0)
	}
	tr.n = n
	tr.edges = edges
}

func (tr *Tree) addEdge(i int, e Edge) {
	tr.edges[i] = append(tr.edges[i], e)
}

// Edge ...
type Edge struct {
	to int
}

// Lca ...
type Lca struct {
	depth   []int
	parents [][]int
}

func (lca *Lca) init(n, r int, edges [][]Edge) {
	parents := make([][]int, 32)
	for i := 0; i < 32; i++ {
		parents[i] = make([]int, n)
	}
	lca.depth = make([]int, n)
	lca.parents = parents
	lca.dfs(r, -1, 0, edges)
	for i := 1; i < 32; i++ {
		for j := 0; j < n; j++ {
			lca.parents[i][j] = -1
			if lca.parents[i-1][j] == -1 {
				continue
			}
			lca.parents[i][j] = lca.parents[i-1][lca.parents[i-1][j]]
		}
	}
}

func (lca *Lca) dfs(i, p, h int, edges [][]Edge) {
	lca.depth[i] = h
	lca.parents[0][i] = p
	for _, e := range edges[i] {
		if e.to == p {
			continue
		}
		lca.dfs(e.to, i, h+1, edges)
	}
}

func (lca *Lca) get(u, v int) int {
	if lca.depth[u] > lca.depth[v] {
		u, v = v, u
	}
	h := lca.depth[v] - lca.depth[u]
	for i := 0; i < 32; i++ {
		if h>>uint(i)&1 == 1 {
			v = lca.parents[i][v]
		}
	}
	if u == v {
		return u
	}
	for i := 30; i >= 0; i-- {
		if lca.parents[i][u] == lca.parents[i][v] {
			continue
		}
		u = lca.parents[i][u]
		v = lca.parents[i][v]
	}
	return lca.parents[0][u]
}


Measured memory_bytes: 62848
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  char rev[2];
  cin >> s;
  int n = s.size();
  rev[0] = s[0];
  rev[1] = s[1];
  if( rev[0] == rev[1]){
    cout << 1 << " " << 2 <<endl;
    return 0;
  }

  for(int i = 2; i < n; i++){
    if( rev[0] == s[i] || rev[1] == s[i]){
      cout << i-1 << " " << i+1 <<endl;
      return 0;
    }
    rev[0] = rev[1];
    rev[1] = s[i];
  }
  cout << "-1 -1" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;

int n;
bool s[500], t[500], u[500], v[500];
int a[500][500];
ull ans[500][500];
void end(){
    cout << -1 << endl;
    exit(0);
}
void solve(){
    memset(a, 0xff, sizeof(a));
    list<int> x(n), y(n);
    auto px = x.begin(), py = y.begin();
    iota(x.begin(), x.end(), 0);
    iota(y.begin(), y.end(), 0);
    for(int i = 0; i < n; i++){
        if(s[i] ^ u[i]){
            for(int j = 0; j < n; j++) a[i][j] = u[i];
            px = x.erase(px);
        }
        else px++;
    }
    for(int j = 0; j < n; j++){
        if(t[j] ^ v[j]){
            for(int i = 0; i < n; i++){
                if(a[i][j] == (v[j] ^ 1)) end();
                a[i][j] = v[j];
            }
            py = y.erase(py);
        }
        else py++;
    }
    if(x.size() > 1 && y.size() > 1){
        bool b = 0;
        for(int i : x){
            bool c = b;
            for(int j : y){
                a[i][j] = c;
                c = !c;
            }
            b = !b;
        }
    }
    else if(x.size() == 1){
        const int i = x.front();
        for(int j : y){
            a[i][j] = u[i];
            bool flag = 1;
            for(int i = 0; i < n; i++) if(a[i][j] == v[j]) flag = 0;
            if(flag) a[i][j] = v[j];
        }
    }
    else if(y.size() == 1){
        const int j = y.front();
        for(int i : x){
            a[i][j] = v[j];
            bool flag = 1;
            for(int j = 0; j < n; j++) if(a[i][j] == u[i]) flag = 0;
            if(flag) a[i][j] = u[i];
        }
    }
    for(int i : x){
        bool flag = 1;
        for(int j = 0; j < n; j++) if(a[i][j] == u[i]) flag = 0;
        if(flag) end();
    }
    for(int j : y){
        bool flag = 1;
        for(int i = 0; i < n; i++) if(a[i][j] == v[j]) flag = 0;
        if(flag) end();
    }
}
int main(){
    cin >> n;
    vector<ull> u_(n), v_(n);
    for(int i = 0; i < n; i++) cin >> s[i];
    for(int i = 0; i < n; i++) cin >> t[i];
    for(auto& i : u_) cin >> i;
    for(auto& i : v_) cin >> i;
    for(int bit = 64; bit--; ){
        for(int i = 0; i < n; i++) u[i] = u_[i] >> bit & 1;
        for(int i = 0; i < n; i++) v[i] = v_[i] >> bit & 1;
        solve();
        for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){
            ans[i][j] <<= 1;
            ans[i][j] |= a[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++) cout << ans[i][j] << ' ';
        cout << '\n';
    }
}

Measured memory_bytes: 8464
# 1, 1, 3, 4, 15, 24, 105, 192, 945, 1920

N = gets.to_i
if N.odd?
    p 0
else
    ans = 0
    for i in 0..25
        ans += N / (10 * 5 ** i)
    end
    p ans
end

Measured memory_bytes: 1788
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
 
int main(void) {
    while(true) {
        int w, h;
        cin>>w>>h;
        if(w == 0 && h == 0) break;
        vector<vector<char> > m(h, vector<char>(w));
        vector<P> p;
        REP(i, h) {
            REP(j, w) {
                cin>>m[i][j];
                if(m[i][j] == 'o') {
                    p.pb(P(i, j));
                }
            }
        }
        REP(i, h) {
            REP(j, w) {
                if(m[i][j] == '*') {
                    p.pb(P(i, j));
                }
            }
        }
        vector<vector<ll> > d(p.size(), vector<ll>(p.size(), INF * INF));
        REP(i, p.size()) {
            P s = p[i];
            vector<vector<ll> > dir(h, vector<ll>(w, INF * INF));
            dir[s.first][s.second] = 0;
            queue<P> q;
            q.push(s);
            while(!q.empty()) {
                P np = q.front();
                q.pop();
                REP(j, 4) {
                    ll nh = np.first + dx[j];
                    ll nw = np.second + dy[j];
                    if(nh >= 0 && nh < h && nw >= 0 && nw < w && m[nh][nw] != 'x') {
                        if(dir[nh][nw] == INF * INF) {
                            dir[nh][nw] = dir[np.first][np.second] + 1;
                            q.push(P(nh, nw));
                        }
                    }
                }
            }
            REP(j, p.size()) {
                if(i == j) continue;
                d[i][j] = dir[p[j].first][p[j].second];
            }
        }
        bool det = false;
        FOR(i, 1, p.size()) {
            if(d[0][i] == INF * INF) det = true;
        }
        if(det) {
            cout<<-1<<endl;
            continue;
        }
        vector<int> perm;
        REP(i, p.size() - 1) {
            perm.pb((int)(i + 1));
        }
        ll ans = INF * INF;
        if(p.size() == 1) {
            cout<<"hoge"<<endl;
            cout<<0<<endl;
        }
        else {
            do {
                ll res = 0;
                res += d[0][perm[0]];
                REP(i, perm.size() - 1) {
                    res += d[perm[i]][perm[i + 1]];
                }
                ans = min(ans, res);
            } while(next_permutation(ALL(perm)));
            cout<<ans<<endl;
        }
    }
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int x1, x2, x3, x4, x5;

	cin >> x1 >> x2 >> x3 >> x4 >> x5;

	int ans = 0;
	if(x1 == 0){ ans = 1; }
	else if(x2 == 0){ ans = 2; } 
	else if(x3 == 0){ ans = 3; } 
	else if(x4 == 0){ ans = 4; } 
	else if(x5 == 0){ ans = 5; }

	printf("%d\n", ans);
	return 0;

}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0), ios::sync_with_stdio(false);
	int n; cin >> n;
	set<pair<int,int>> st;
	for(int i = 1; i < n; i++){
		for(int j = i+1; j <= n; j++){
			st.insert({i,j});
		}
	}
	if(n%2)	for(int i = 1; i <= n/2; i++)	st.erase({i,n-i});
	else for(int i = 1; i <= n/2; i++) st.erase({i,n-i+1});
	cout << st.size() << endl;
	for(auto x : st) cout << x.first << " " << x.second << endl;
	cout << "\n";
	return 0;
}


Measured memory_bytes: 3804
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;
// powmod p^n%mod
LL powmod(LL p,LL n,LL mod){
	LL q=p%mod;
	LL pow=1;
	while(n){
		if(n&1){
			pow*=q;
			pow%=mod;
		}
		q=q*q;
		q%=mod;
		n/=2;
	}
	return pow;
}
const LL M=1e9+7;
int main() {
	LL S;
	cin >> S;
	if(S==1){
		cout << 9 << endl;
		return 0;
	}
	LL l=1;
	LL dl=1;
	LL bl=10;
	LL r=1;
	LL dr=1;
	LL br=10;
	LL s=1;
	LL ret=0;
	//int debug=0;
	int phase=0;
	while(phase==0){
#if 0
		if(debug>4){
			break;
		}
		debug++;
#endif
		while(s<S){
			r++;
			if(r==br){
				dr++;
				br*=10;
			}
			s+=dr;
		}
		//cerr << r <<  " " << s << endl;
		while(S<=s){
			if(s==S){
				ret++;
			}
			s-=dl;
			l++;
			if(l==bl){
				dl++;
				if(9*bl*dl>=S){
					phase=1;
					break;
				}
				bl*=10;
			}
		}
	}
	//return 0;
	//cerr << ret << " " << r << ", " << l << endl;
	ret%=M;
	//LL k=r-l+1;
	//cerr << S/dl << endl;
	ret+=S/dl;
	ret%=M;
	for(LL k=1;k*k<=S;k++){
		if(S%k==0){
			// 個数がk
			//cerr << S/k << ", " << k << endl;
			if(S/k>=dl){
				ret+=9*powmod(10,S/k-1,M)%M+M-k;
			}
			// 桁数がk
			if(k*k<S&&k>=dl){
				//cerr << k << ", " << endl;
				ret+=9*powmod(10,k-1,M)%M+M-S/k;
			}
			ret%=M;
		}
	}
	cout << ret << endl;


	return 0;
}



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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

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

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

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	LL n;
	cin >> n;
	for (LL i = sqrt(n) + 1; i >= 1; i--) {
		if (n % i == 0) {
			cout << i + (n/i) - 2 << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int,x)

function main()
  N = parseInt(readline())
  A = zeros(Int,N)
  for i = 1:N
    A[i] = parseInt(readline())
  end
  B = sort(A)
  c = B[N]
  d = B[N-1]
  for i = 1:N
    A[i] == c ? println(d) : println(c)
  end
end

main()

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

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

part = [K - Q for _ in range(N)]

for _ in range(Q):
    part[int(input()) - 1] += 1

for x in part:
    if x <= 0:
        print('No')
    else:
        print('Yes')


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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  sort(s.begin(), s.end());
  long long equre = 0;
  long long result = 0;
  for (i = 1; i < s.size(); i++) {
    if (s[i - 1] == s[i]) {
      equre++;
    } else {
      result += (equre * (equre + 1)) / 2;
      equre = 0;
    }
  }
  result += (equre * (equre + 1)) / 2;
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 7296
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int k = sc.nextInt();
		boolean ans = false;

		for (int i=1; i<=k; i++){

			if (a >= c || b >= c){
				c = c * 2;
			} else if (a >= b){
				b = b * 2;
			}

			if (a < b && b < c){
				ans = true;
				break;
			}
		}
		if (ans){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}


}

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

using ll = long long int;
using P = std::pair<int, int>;

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

int n;

int f(int x, int y)
{
    if (x > y)
        std::swap(x, y);
    return x * (n - 1 + n - x) / 2 + y - x - 1;
}

std::vector<std::vector<int>> g;

std::vector<int> d;

int dfs(int x)
{
    if (d[x] > 0)
        return d[x];

    //std::cerr << x << std::endl;

    int res = 0;

    for (int y : g[x])
        res = std::max(res, dfs(y));

    return d[x] = res + 1;
}

std::vector<bool> used;
std::set<int> set;

bool det(int x)
{

    for (int y : g[x])
    {
        if (set.count(y))
            return 1;
        if (!used[y])
        {
            set.insert(y);
            used[y] = 1;
            if (det(y))
                return 1;
            set.erase(y);
        }
    }

    return 0;
}

int main()
{

    std::cin >> n;

    int m = n * (n - 1) / 2;

    g.resize(m);
    d.resize(m, 0);

    rep(i, n)
    {
        int x;
        std::cin >> x;
        rep(j, n - 2)
        {
            int y;
            std::cin >> y;
            g[f(i, x - 1)].emplace_back(f(i, y - 1));
            x = y;
        }
    }

    /*rep(i, m)
    {
        for (int x : g[i])
            std::cerr << x << ' ';
        std::cerr << std::endl;
    }*/

    used.resize(m, 0);

    rep(i, m)
    {
        used[i] = 1;
        set.clear();
        set.insert(i);
        //std::cerr << i << std::endl;
        if (det(i))
        {
            std::cout << -1 << std::endl;
            return 0;
        }
    }

    int ans = 0;

    rep(i, m)
    {
        ans = std::max(ans, dfs(i));
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 32756
#include <bits/stdc++.h>
#define maxn (1 << 20)
using namespace std;

int n = 0;
long long dp[maxn] = {0};
long long t[20][20] = {0};

long long solve(int x);
void reset();

int main() {
  while(1) {
    reset();
    cin >> n;
    if(n == 0) break;
    dp[(1 << n) - 1] = 0;
    for(int i = 0; i < n; ++i)
      for(int j = 0; j <= n; ++j) cin >> t[i][j];
    cout << solve(0) << endl;
  }
  return 0;
}

long long solve(int x) {
  if(dp[x] != -1) return dp[x];
  long long ans = 1LL << 59;
  for(int i = 0; i < n; ++i)
    for(int j = 0; j <= n; ++j)
      if(!((x >> i) & 1) &&
         (j == 0 || ((x >> (j - 1)) & 1)))
        ans = min(ans, t[i][j] + solve(x + (1 << i)));
  return dp[x] = ans;
}

void reset() {
  for(int i = 0; i < maxn; ++i) dp[i] = -1;
  for(int i = 0; i < n; ++i)
    for(int j = 0; j <= n; ++j) t[i][j] = 0;
}


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

int main(){
    int ti;char y;string hoge;
    map<string,int>gotiusa;
    while(cin>>ti>>y>>hoge)gotiusa[hoge]++;
    cout<<gotiusa["A"]<<endl;
    cout<<gotiusa["B"]<<endl;
    cout<<gotiusa["AB"]<<endl;
    cout<<gotiusa["O"]<<endl;
}

Measured memory_bytes: 3144
#include<stdio.h>
int main()
{
    int a, b, c, d, e, k;
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &k);
    if((e-a) <= k){
        printf("Yay!");
        }else{
            printf(":(");
        }
    
    return 0;

}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string>
using namespace std;

int main() {
    char c;

    if (scanf("%c", &c) < 1) return 0;

    if (c == 'a' || c == 'e' || c == 'i'
        || c == 'o' || c == 'u')
    {
        printf("%s\n", "vowel");
    }
    else
    {
        printf("%s\n", "consonant");
    }

    return 0;
}


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

main(){
  ll n,i;
  cin >> n;
  map<string,int> mp;
  for(i=0;i<n;i++){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    mp[s]++;
  }
  
  ll ans=0;
  for(auto&& p :mp){
    ll s=p.second;
    ans += s*(s-1)/2;
  }
  
  cout << ans << endl; 
 
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
const int maxn = 100005;
typedef pair<ll, ll>par;
const ll mod = 1e9+7;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    #ifdef acm
    freopen("a.in", "r",stdin);
    #endif // acm

    int n;
    cin >> n;

    int d = n%10;
    if( d == 2 || d == 4 || d == 5 || d == 7 || d == 9 )
        cout << "hon\n";

    if( d == 0 || d == 1 || d == 6 || d == 8 )
        cout << "pon\n";

    if( d == 3 )
        cout << "bon\n";

    return 0;
}


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

int main(){
  int N, Y;
  cin >> N >> Y;
  bool finish=false;
  int a=-1, b=-1, c=-1;
  for(int i=N; i>=0; i--){
    if(finish) break;
    for(int j=N-i; j>=0; j--){
      int y=10000*i+5000*j+1000*(N-i-j);
      if(y==Y){
        a=i;
        b=j;
        c=N-i-j;
        finish=true;
        break;      
      }
    }
  }
  cout << a << " " << b << " " << c <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cerr<<#x<<" "<<x<<endl;
#define f(i,n) for(ll i=0; i<n; i++)
#define f1(i,n) for(ll i=1; i<=n; i++)
#define fr(i,n) for(ll i=n-1; i>=0; i--)
#define f1r(i,n) for(ll i=n; i>0; i--)
#define mst(arr,val) memset(arr,val,sizeof(arr))
#define all(x) x.begin(),x.end()

typedef long long int ll;
typedef pair<ll,ll> pii;
ll M=1e9+7;
ll M2=998244353;
void show(vector<ll> v)
{
    for(ll i=0; i<v.size(); i++)
        cout<<v[i]<<" ";
    cout<<"\n";
}
void showrev(vector<ll> v)
{
    for(ll i=0; i<v.size(); i++)
        cout<<v[v.size()-i-1]<<" ";
    cout<<"\n";
}
void showarr(ll arr[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<arr[i]<<" ";
    cout<<"\n";
}
void showpv(vector<pair<ll,ll> > v)
{
    f(i,v.size())
        cout<<"("<<v[i].ff<<","<<v[i].ss<<")"<<" ";
    cout<<"\n";
}
int main()
{
    IOS
    ll T = 1,Q=1;
    //cin>>T;
    while(T--)
    {
        ll n; cin>>n;
        ll ans = 0;
        ans += 1000*(n/500);
        n %= 500;
        ans += 5*(n/5);
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}

// 割り算の切り上げ処理
template<typename T>
T round_up(T a, T b) {
  return (a + b - 1) / b;
}

// 約数列挙
template<typename T>
vector<T> calc_divisor(T n) {
   vector<T> res;
   for (T i = 1LL; i*i <= n; ++i) {
       if (n % i == 0) {
           res.push_back(i);
           T j = n / i;
           if (j != i) res.push_back(j);
       }
   }
   sort(res.begin(), res.end());
   return res;
}

// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    double t,x;
    cin >> t >> x;
    double ans = t / x;
    print(ans);
    
}


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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  memset(a, -1, sizeof(a));
  REP(i, k) {
    int b, c;
    cin >> b >> c;
    b--;c--;
    a[b] = c;
  }
  const int MOD = 10000;
  int dp[101][3][3];
  memset(dp, 0, sizeof(dp));
  dp[0][0][0] = 1;
  REP(i, n) {
    REP(j, 3) {
      REP(k, 3) {
        REP(l, 3) {
          if (i>=2 && j==k&&k==l) continue;
          if (a[i] != -1 && a[i] != l) continue;
          dp[i+1][k][l] = (dp[i+1][k][l] + dp[i][j][k]) % MOD;
        }
      }
    }
    // REP(j,3) {
    //   REP(k,3) cout << dp[i+1][j][k] << " ";
    //   cout << endl;
    // }cout << endl;
  }
  int ans = 0;
  REP(i,3)REP(j,3)
    ans = (ans + dp[n][i][j]) % MOD;
  cout << ans << endl;
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  S += "00000000";
  int i = 0;
  bool murimurikatatsumuri=0;
  int unchi=0;
  while(i<N) {
    if(S.at(i) == 'd' && S.at(i+1) == 'r' && 
       S.at(i+2) == 'e' && S.at(i+3) == 'a' &&
       S.at(i+4) == 'm') {
      unchi = 0;
      if(S.at(i+5) == 'e' && S.at(i+6) == 'r' &&
         S.at(i+7) != 'a') {
        i += 2;
      }
      i += 5;
    }
    else {
      unchi++;
    }
    if (unchi == 2){
    murimurikatatsumuri = 1;
    break;
    }
    if(S.at(i) == 'e' && S.at(i+1) == 'r' && 
       S.at(i+2) == 'a' && S.at(i+3) == 's' &&
       S.at(i+4) == 'e'){
      unchi = 0;
      if(S.at(i+5) == 'r') {
        i += 6;
      }
      else {
        i += 5;
      }
    }
    else {
      unchi++;
    }
  if (unchi == 2){
      murimurikatatsumuri = 1;
    break;
    }
  }
  if(murimurikatatsumuri == 1) {
    cout << "NO" << endl;
  }
  else {
    cout << "YES" << endl;
  }
}


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

const int MOD = 1e9+7;

bool check(string s) {
    bool ret = s.find("AGC") == string::npos;
    int n = s.length();
    for (int i = 0; i < n - 1; i++) {
        swap(s[i], s[i+1]);
        ret &= s.find("AGC") == string::npos;
        swap(s[i], s[i+1]);
    }
    return ret;
}

int main(void) {
    int n;
    cin >> n;
    vector<map<string, int>> dp(2);
    string acgt = "ACGT";

    dp[1][""] = 1;
    for (int i = 0; i < n; i++) {
        dp[i % 2].clear();
        for (auto p: dp[1 - i % 2]) {
            string s = p.first;
            for (auto c: acgt) {
                string t = s + c;
                if (check(t)) {
                    if (t.length() > 3) {
                        t = t.substr(1, 3);
                    }
                    dp[i % 2][t] = (dp[i % 2][t] + p.second) % MOD;
                }
            }
        }
    }

    int ans = 0;
    for (auto p: dp[1 - n % 2]) {
        // printf("%s %d\n", p.first.c_str(), p.second);
        ans = (ans + p.second) % MOD;
    }
    cout << ans << endl;
    return 0;
}

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

const int maxn=1e5+10;
int a[maxn];
signed main(){
    int n,m;
    scanf("%lld%lld",&n,&m);
    int lcm=1;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        if(lcm>1e9){
            continue;
        }
        lcm=lcm*a[i]/2/__gcd(lcm,a[i]/2);
    }
    //printf("debug %lld\n",lcm);
    int flag=0;
    for(int i=1;i<=n;i++){
        int temp=lcm*2/a[i];
        if(temp%2==0){
            flag=1;
            break;
        }
    }
    if(flag){
        puts("0");
        return 0;
    }
    int cnt=m/lcm;
    if(cnt&1){
        cnt=cnt/2+1;
    }
    else{
        cnt=cnt/2;
    }
    printf("%lld\n",cnt);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long double exp(long double n) {
    long double e = 0;
    for (long double i=1; i<=n; i++) e += i/n;
    return e;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<long double> ep(200001, -1);
    vector<long double> p(n+1);

    for (int i=0; i<n; i++) {
        int ip;
        cin >> ip;
        if (ep[ip] == -1) ep[ip] = exp(ip);
        p[i+1] = p[i] + ep[ip];
    }

    long double ans = 0;
    for (int i=0; i<=n-k; i++) ans = max(ans, p[i+k]-p[i]);
    cout << fixed;
    cout << setprecision(12) << ans << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#include<stdio.h>
#define int long long
#define pb emplace_back
#define Mod 1000000007
#define all(a) a.begin(),a.end()
using namespace std;
signed main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    n %= 10;
    if(n == 2 || n == 4 || n ==5 || n == 7 || n ==9) cout<<"hon\n";
    else if(n == 0 || n == 1 || n ==6 || n == 8) cout<<"pon\n";
    else cout<<"bon\n";
}


Measured memory_bytes: 3608
#include<iostream>
using namespace std;
int main(){
long n,a[100],t,i,j,k;
while(cin>>n){
if(n==0)break;
for(i=0;i<n;i++)cin>>a[i];
for(k=0,j=n-1;j>0;j--)
for(i=0;i<j;i++){
if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;k++;}
}
cout<<k<<endl;
}
return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#include<string>
#include<sstream>
#include<complex>
#include<tuple>

using namespace std;

#define reep(i, s, n) for(int i=s;i<(int)n;i++)
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define REP(i, n) for(int i=0;i<(int)n;i++)
#define all(v) v.begin(), v.end()
#define tyd typedef
#define vc vector
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
const int IINF = 1<<28;

#define fs first
#define sc second
#define X real()
#define Y imag()
typedef long double R;
R EPS = 1e-9;
inline int sig(const R &x){return abs(x) < EPS ? 0 : x > 0 ? 1 : -1;}
typedef complex<R> P;
inline  R inp(const P &a, const P &b){ return (conj(a)*b).X;}
inline R outp(const P &a, const P &b){ return (conj(a)*b).Y;}
inline int ccw(const P &s, const P &t, const P &p){
	int res = sig(outp(t-s, p-s));
	if(res) return res;
	if(sig(inp(t-s, p-s)) < 0) return -2;
	if(sig(inp(s-t, p-t)) < 0) return 2;
	return 0;
}
int intersect(const P &s0, const P &s1, const P &t0, const P &t1){
	int p = ccw(t0, t1, s0) * ccw(t0, t1, s1);
	int q = ccw(s0, s1, t0) * ccw(s0, s1, t1);
	return !(p>0 || q>0);
}

struct Data
{
	int id, af, sol, pen;
	Data( int id = 0, int af = 0, int sol = 0, int pen = 0 )
		:id(id), af(af), sol(sol), pen(pen)
	{
	}

	friend bool operator < ( const Data& d1, const Data& d2 )
	{
		return (d1.sol == d2.sol ? (d1.pen == d2.pen ? d1.id < d2.id : d1.pen < d2.pen) : d1.sol > d2.sol );
	}
};

int main(){
	Data data[200];
	int n;
	while( cin >> n, n != 0 ){
		rep(i, n){
			int id, af, sol, pen;
			cin >> id >> af >> sol >> pen;
			--af;
			data[i] = Data(id, af, sol, pen);
		}

		sort( data, data+n );
		int cnt_af[1000] = { 0 };
		vi rank;
		rep(i, n){
			if ( rank.size() < 10 ){
				if( cnt_af[data[i].af] < 3 ){
					rank.pb(data[i].id);
					cnt_af[data[i].af]++;
				}
			}
			else if ( rank.size() < 20 ){
				if( cnt_af[data[i].af] < 2 ){
					rank.pb(data[i].id);
					cnt_af[data[i].af]++;
				}
			}
			else if ( rank.size() < 26 ){
				if( cnt_af[data[i].af] == 0 ){
					rank.pb(data[i].id);
					cnt_af[data[i].af]++;
				}
			}			
		}

		rep(i, rank.size()){
			cout << rank[i] << endl;
		}
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<vector<int>> d(n,vector<int>(n));
  rep(i,n){
    rep(j,n){
      cin >> d[i][j];
    }
  }
  LL ans=0;
  rep(i,n){
    repp(j,i,n){
      ans+=min(d[i][j],d[j][i]);
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3192
letter = input()
N = len(letter)

slash_index = [-1]
gather_index = []
for i in range(N-1):
  if letter[i] == 'L' and letter[i+1] == 'R':
    slash_index.append(i)
  if letter[i] == 'R' and letter[i+1] == 'L':
    gather_index.append(i)
    
slash_index.append(N-1)
ans = [0]*N

for i in range(len(slash_index)-1):
  for k in range(slash_index[i]+1,slash_index[i+1]+1,1):
    if gather_index[i] % 2 == k % 2:
      ans[gather_index[i]] += 1
    elif (gather_index[i]+1) % 2 == k % 2:
      ans[gather_index[i]+1] += 1
      
ans_letter = ''
for i in range(len(ans)):
  ans_letter += str(ans[i])
  ans_letter += ' '
print(ans_letter)


Measured memory_bytes: 8524
#include <bits/stdc++.h>
using namespace std;
int n, k;
const int MOD = 1e9 + 7;
const int N = 1000000;
int ans[N], finans;
vector <int> V;
int powi(int a, int b)
{
    int c = 1;
    for (; b; b >>= 1, a = 1ll * a * a % MOD)
        if (b & 1) c = 1ll * c * a % MOD;
    return c;
}
int main()
{
    cin >> n >> k;
    for (int i = 1; i * i <= n; ++ i)
        if (n % i == 0)
        {
            V.push_back(i);
            if (i * i != n) V.push_back(n / i);
        }
    sort(V.begin(), V.end());
    for (int i = 0; i < V.size(); ++ i)
    {
        ans[i] = powi(k, (V[i] + 1) / 2);
        for (int j = 0; j < i; ++ j) if (V[i] % V[j] == 0)
            ans[i] = (ans[i] - ans[j] + MOD) % MOD;
        finans = (finans + 1ll * ans[i] * (V[i] & 1? V[i]: V[i] / 2)) % MOD;
    }
    cout << finans << endl;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())
A = map(int, input().split())
B = deque()
flag = 0
for a in A:
  if flag:
    B.appendleft(a)
  else:
    B.append(a)
  flag = 1 - flag

B = list(B)
if flag:
  print(*B[::-1])
else:
  print(*B)

Measured memory_bytes: 25544
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int h, w, B[410][410], W[410][410];
int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
vector<string> s;

bool in(int x, int y) { return (0 <= x && x < h && 0 <= y && y < w); }
void dfs(int x, int y, int z)
{
    if (s[x][y] == 'x' || s[x][y] == 'X')
        return;
    bool f = (s[x][y] == '.');
    s[x][y] = 'x';
    if (z == 1)
        s[x][y] = 'X';
    rep(i, 4)
    {
        int nx = x + dx[i], ny = y + dy[i];
        if (!in(nx, ny))
            continue;
        if ((f && s[nx][ny] == '#') || (!f && s[nx][ny] == '.'))
        {
            dfs(nx, ny, 0);
            W[x][y] += W[nx][ny];
            B[x][y] += B[nx][ny];
        }
    }
}

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

    cin >> h >> w;
    s.resize(h);
    rep(i, h) cin >> s[i];
    rep(i, h) rep(j, w)
    {
        if (s[i][j] == '.')
            W[i][j] = 1;
        else
            B[i][j] = 1;
    }
    rep(i, h) rep(j, w) dfs(i, j, 1);
    int ans = 0;
    rep(i, h) rep(j, w) if (s[i][j] == 'X') ans += B[i][j] * W[i][j];
    cout << ans << endl;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		
		while (true) {
			
			String tmp = br.readLine();
			if (tmp == null) break;
			
			st = new StringTokenizer(tmp," ");
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			int n = Integer.parseInt(st.nextToken());
			int s = 0;
			
			a %= b;
	        for(int i = 0;i < n; i++) {
	        	a *= 10;
	        	s += (a / b);
	        	a %= b;
	        }
			
			System.out.println(s);
			
		}

	}

}

Measured memory_bytes: 9236
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,a[100010],b[100010],c[100010];
    cin>>n;
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n-1) cin>>c[i];
    ll ans=0;
    rep(i,n){
        ans+=b[a[i]-1];
        if(i>0&&a[i-1]==a[i]-1) ans+=c[a[i-1]-1];
        // cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    unordered_map <string,int> res;
    res["AC"] = 0;
    res["WA"] = 0;
    res["TLE"] = 0;
    res["RE"] = 0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string g;
        cin>>g;
        res[g]++;
    }
    cout<<"AC x "<<res["AC"]<<endl;
    cout<<"WA x "<<res["WA"]<<endl;
    cout<<"TLE x "<<res["TLE"]<<endl;
    cout<<"RE x "<<res["RE"]<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
const static double PI = ::acos(-1);


int main()
{
    constexpr int64 mod = 1000000007;

    int n;
    cin >> n;
    vint a(n);
    Rep(i, n)
    {
        cin >> a[i];
    }

    vector<vint> pattern(3, vint(n + 1));

    auto c = [&](int i)
    {
        int64 r = 0;
        Rep(j, 3)
        {
            if (pattern[j][i] == a[i])
            {
                ++r;
            }
        }
        return r;
    };

    int64 count = 1;
    Rep(i, n)
    {
        count = (count * c(i)) % mod;

        bool b = false;
        Rep(j, 3)
        {
            if (pattern[j][i] == a[i] && !b)
            {
                pattern[j][i + 1] = pattern[j][i] + 1;
                b = true;
            }
            else
            {
                pattern[j][i + 1] = pattern[j][i];
            }
        }
    }
    
    cout << count << endl;

    return 0;
}


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

int main()
{
ll n ;
cin >> n ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
}
vector<vector<ll>> g(n);
rep(i, n-1)
{
    ll a,b;
    cin >> a>>b;
    g[a-1].push_back(b-1);
    g[b-1].push_back(a-1);
}
if(n==2){
  if(a[0]==a[1])cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}
ll root;
vector<vector<ll>> st(n);
vector<ll> par(n);
queue<ll> q;
queue<ll> qq;

rep(i,n)if(g[i].size()>1){root=i;break;}
q.push(root);
par[root]=-1;
while(!q.empty()){
  ll p=q.front();
  q.pop();
  if(g[p].size()==1)qq.push(p);
  for(auto r:g[p]){
    if(r==par[p])continue;
    par[r]=p;
    q.push(r);
  }
}
while(!qq.empty()){
  ll p=qq.front();
  qq.pop();
  st[par[p]].push_back(a[p]);
  if(st[par[p]].size()==g[par[p]].size()){
    ll sum=accumulate(st[par[p]].begin(),st[par[p]].end(),0);
    if(sum%2==0 && *max_element(st[par[p]].begin(),st[par[p]].end()) <=sum/2 && a[par[p]]==sum/2 )cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
  }
  if(st[par[p]].size()==g[par[p]].size()-1 && par[p]!=root){
    ll sum=accumulate(st[par[p]].begin(),st[par[p]].end(),0);
    if(max(*max_element(st[par[p]].begin(),st[par[p]].end()),(sum+1)/2)<=a[par[p]] && a[par[p]]<=sum ){
      a[par[p]]=a[par[p]]*2-sum;
    }
    else{
      cout << "NO" << endl;
      return 0;
    }
    qq.push(par[p]);
  }
}
return 0;
}

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


using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string a, b;
  int n;
  cin >> n;
  int c[26];
  for(int i = 0; i < 26; i++){
    c[i] = 1 << 25;
  }
  for(int i = 0; i < n; i++){
    string str;
    cin >> str;
    sort(str.begin(), str.end());
    for(int j = 0; j < 26; j++){
      c[j] = min<int>(c[j], upper_bound(str.begin(), str.end(), j + 'a') - lower_bound(str.begin(), str.end(), j + 'a'));
    }
  }
  for(int i = 0; i < 26; i++){
    while(c[i]--)
      cout << char(i + 'a');
  }
  cout << "\n";
}

Measured memory_bytes: 256
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

c = [0] * 5
for i in range(3):
    a, b = mi()
    c[a] += 1
    c[b] += 1
print('YES' if c.count(1) == 2 else 'NO')


Measured memory_bytes: 2940