akhauriyash/Code-Regression huggingface dataset:
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#pragma GCC optimize ("O3")
	#define NDEBUG
#endif
// #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

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...);
}

const array<int, 4> dx = {0, 1, 0, -1};
const array<int, 4> dy = {1, 0, -1, 0};


typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	LL n;
	while(cin >> n) {
		cout << n * (n - 1) / 2 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
from itertools import combinations

def main():
    N, M, X = [int(i) for i in input().split()]
    C, A = [], []
    for _ in range(N):
        ca = [int(i) for i in input().split()]
        C.append(ca[0])
        A.append(ca[1:])

    for m in range(M):
        if sum(a[m] for a in A) < X:
            print(-1)
            return

    sets = []
    comb_ix = [comb for i in range(1, len(A) + 1) for comb in combinations(range(len(A)), i)]
    for m in range(M):
        tmp_lst = []

        for comb in comb_ix:
            a = [a[m] for i, a in enumerate(A) if i in comb]
            if sum(a) >= X:
                tmp_lst.append(comb)
        
        sets.append(frozenset(tmp_lst))

    intersection = set.intersection(*map(set, sets))
    res = sum(C)
    for comb in intersection:
        sum_c = sum(c for i, c in enumerate(C) if i in comb)
        if sum_c < res:
            res = sum_c

    print(res)

main()


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
vector<int> e(n+1,0),w(n+1,0);
rep(i,n){
    if(s[i]=='E'){
        e[i + 1] = e[i] + 1;
        w[i + 1] = w[i];
    }
    else{
        e[i + 1] = e[i];
        w[i + 1] = w[i]+1;
    }
}
int ans=1e9;
rep(i,n){
    int w_num = w[i];
    int e_num = e[n] - e[i + 1];
    chmin(ans, w_num +e_num);
}
cout << ans << endl;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int s[m],t[m];
    vector<vector<int>>e(n);
    for(int i=0;i<m;i++){
        cin>>s[i]>>t[i];
        e[s[i]-1].push_back(t[i]-1);
    }
    vector<double>dp(n);
    vector<double>ma(n);
    dp[n-1]=0.0;
    for(int i=n-2;i>=0;i--){
        double x=0.0;
        for(int j=0;j<e[i].size();j++){
            x+=dp[e[i][j]];
            ma[i]=max(ma[i],dp[e[i][j]]);
        }
        dp[i]=x/double(e[i].size())+1.0;
    }
    double ans=dp[0];
    for(int i=0;i<n-2;i++){
        if(e[i].size()==1)continue;
        vector<double>dp_change(n);
        dp_change=dp;
        for(int j=i;j>=0;j--){
            double x=0.0;
            for(int k=0;k<e[j].size();k++)x+=dp_change[e[j][k]];
            if(j==i)dp_change[j]=(x-ma[j])/double(e[j].size()-1)+1.0;
            else dp_change[j]=x/double(e[j].size())+1.0;
        }
        ans=min(ans,dp_change[0]);
    }
    printf("%.10lf\n",ans);
    return 0;
}

Measured memory_bytes: 6368
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)

func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func()
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx++
		return cur
	}
	this.initWordIdx = func() {
		idx = 0
	}
	return &this
}

func (me *ReaderEx) ScanAndSplit() (isScanned bool) {
	isScanned = me.baseScanner.Scan()

	me.words = strings.Fields(me.baseScanner.Text())
	me.initWordIdx()
	return
}

func (me *ReaderEx) Scan() (ok bool) {
	ok = me.baseScanner.Scan()
	return
}
func (me *ReaderEx) getString() string {
	return me.baseScanner.Text()
}

func (me *ReaderEx) getInt() int {
	n, err := strconv.Atoi(me.baseScanner.Text())
	defer func() {
		if err != nil {
			panic(err)
		}
	}()

	return n
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, fa)
		}
	}
	if n > 1 {
		facts = append(facts, factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

type kv struct {
	key   int
	value int
}

func toInt(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}
func toBool(i int) (b bool) {
	if i != 0 {
		b = true
	} else {
		b = false
	}
	return
}
func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan()
	r.getInt()
	r.ScanAndSplit()
	a := r.nextStringArray().toInts()

	ok := 1
	for _, v := range a {
		ok ^= toInt(v%2 == 1)
	}

	fmt.Fprintln(stdout, []string{"NO", "YES"}[ok])

}



Measured memory_bytes: 5248
def test():
    a,b,k = map(int,input().split())
    c = []
    for i in range(1,max(a,b)+1):
        if a % i == 0 and b % i == 0:
            c.append(i)

    for j in range(k-1):
        c.remove(max(c))

    print(max(c))


if __name__ == "__main__":
    test()


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main()
{
	long long int ans = 0;
	long long int x;
	cin >> x;

	if (x < 7)
		ans = 1;
	else if (x < 11)
		ans = 2;
	else
	{
		ans = (x / 11) * 2;
		if (x % 11 > 6)
			ans += 2;
		else if (x % 11 != 0)
			ans++;
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
// #define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define PI 3.14159265358979323846
#define inf 200000000
#define N 81
// #define double long double

int32_t main()
{
    IOS;
  
    int cnt = 0;
    string s,t;
    cin >> s >> t;
    for(int i = 0;i < 3;i++)
        cnt += (s[i] == t[i]);
    cout << cnt;
    
}   
 
 


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

int main(){
  int N; cin >> N;
  vector<long long> V;
  for(int i = 0; i < N; ++i){
    int x; cin >> x;
    if(i == 0)V.push_back(x);
    else if(*V.rbegin() != x)V.push_back(x);
  }
  int cnt = 1;
  N = V.size();
  for(int i = 2; i < N; ++i){
    if((V[i] - V[i - 1]) * (V[i - 1] - V[i - 2]) < 0){
      cnt++;
      i++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007 
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i,a,b) for(int i=a;i<b;i++)
#define RF(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pii>
using namespace std;
ll dp[100005];
int main()
{
	SPEED;
   ll n,k,i,s,j;
   cin>>n;
   ll a[n+1];
   Fr(i,0,n)
   {
   	cin>>a[i+1];
   }
   dp[1]=0;
   for(i=2;i<=n;i++)
   {
   	dp[i]=LONG_MAX;
   	 for(j=1;j<=2;j++)
   	 {
   	 	if(i-j>=1)
   	 	{
   	 	dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
	    }
    }
   }
cout<<dp[n]<<endl;
return 0;
}

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

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("input.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
//#define left left228
//#define right right228
//#define next next228
#define rank rank228
//#define prev prev228
#define y1 y1228
#define dout if(debug) cout
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
using vpii = vector<pii> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 577;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100505;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
inline bool IF(int a, int b, int c) { return (a >= b && a <= c); }
inline bool IFS(int a, int b, int c) { return (a > b && a < c); }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
//typedef pair<int, int> pt;
//#define x first
//#define y second
//ifstream cin("input.txt");
//ofstream cout("output.txt");
/*
sort(a, a + n, [&](pair<pt, int> a, pair<pt, int> b){if (a.x.x != b.x.x)
        return a.x.x < b.x.x; return a.x.y > b.x.y;});
for(int c : s)
for(int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
__int128;
char 0 = int 48;
char c = cin;
int h = (int)c - 48;
*/

/*char memory[(int)1e8];

char memorypos;

inline void * operator new(size_t n){
    char * ret = memory + memorypos;
    memorypos += n;
    return (void *)ret;
}

inline void operator delete(void *){}
*/

int n, m;

vi g[nv];

vi res;

int used[nv], dist[nv];

void dfs(int v) {
    used[v] = 1;
    for(int u : g[v]) {
        if(used[u] == 0) dfs(u);
    }
    res.pb(v);
}

int inline solve() {
    //input;//,output;
    //fix;
    fast_io;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].pb(b);
    }
    //fill(dist, dist + n, 1);
    for (int i = 0; i < n; ++i) {
        if(used[i] == 0) dfs(i);
    }
    int ans = 0;
    for(int i : res) {
        int len = 0;
        for(int u : g[i]){
            len = max(len, dist[u]);
        }
        dist[i] = len + 1;
        ans = max(ans, dist[i]);
    }
    cout << ans - 1;
    return 0;
}

int32_t main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    solve();
    return 0;
}
/*
6
2 1 6 3 4 5
2 1 3 4 5 6
6 0
1 7 8 2 4 6
 * */

Measured memory_bytes: 9080
(defun solver ()
  (let ((n (read)) (k (read)) (lst nil) num)
    (loop repeat n do
            (push (read) lst))
    (setf lst (sort lst #'<))
    (setf lst (remove (car lst) lst))
    (when (null lst) (format t "1~%") (break))
    (setf num (length lst))
    (format t "~a~%" (ceiling num (1- k)))))

(solver)

Measured memory_bytes: 63332
s = input()
x = int(s[0:2])
y = int(s[2:4])
if 1 <= x <= 12 and (y == 0 or 13 <= y <= 99):
    print("MMYY")
elif 1 <= y <= 12 and (x == 0 or 13 <= x <= 99):
    print("YYMM")
elif 1 <= x <= 12 and 1 <= y <= 12:
    print("AMBIGUOUS")
else:
    print("NA")


Measured memory_bytes: 3060
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: usize = read();
    let mut a: Vec<u64> = read_vec();
    a.sort();
    let mut sum: u64 = 0;
    let mut cnt: u32 = 0;
    for i in 0..n - 1 {
        sum += a[i];
        if sum * 2 < a[i + 1] {
            cnt = 0;
        } else {
            cnt += 1;
        }
    }
    println!("{}", cnt + 1);
}


Measured memory_bytes: 8444
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
import sys

k = ni()
n = 50
p,r = divmod(k,n)
ans = [0]*n
for i in range(n):
    if i<n-r:
        ans[i]=i + p
    else:
        ans[i]=i+1 + p
print(n)
print(*ans)


Measured memory_bytes: 9348
#include <iostream>
#include <vector>
#include <map>
#include <array>
using namespace std;
int N, K, L;
vector<vector<int>> pq;
vector<vector<int>> rs;

class UnionFind {
    int n;
    vector<int> par;
    vector<int> rank;

public:
    UnionFind(int a) : n(a), rank(a, 0) {
        par.reserve(n);
        for (int i = 0; i < a; i++) par.push_back(i);
    }
    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        int x_root = find(x);
        int y_root = find(y);
        if (rank[x_root] > rank[y_root]) {
            par[y_root] = x_root;
        } else if (rank[x_root] < rank[y_root]) {
            par[x_root] = y_root;
        } else if (x_root != y_root) {
            par[y_root] = x_root;
            rank[x_root]++;
        }
    }
    bool same(int x, int y) { return find(x) == find(y); }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K >> L;
    UnionFind uf(N);
    UnionFind uf2(N);
    pq.resize(N);
    rs.resize(N);
    for (int i = 0; i < K; i++) {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        pq[p].push_back(q);
        pq[q].push_back(p);
    }
    for (int i = 0; i < L; i++) {
        int r, s;
        cin >> r >> s;
        r--;
        s--;
        rs[r].push_back(s);
        rs[s].push_back(r);
    }

    for (int i = 0; i < N; i++)
        for (int j = 0; j < pq[i].size(); j++) uf.unite(i, pq[i][j]);
    for (int i = 0; i < N; i++)
        for (int j = 0; j < rs[i].size(); j++) uf2.unite(i, rs[i][j]);

    map<array<int, 2>, int> mp;
    for(int i=0; i<N; i++){
        array<int, 2> ar = {uf.find(i), uf2.find(i)};
        mp[ar]++;
    }

    for (int i = 0; i < N; i++){
        array<int, 2> ar = {uf.find(i), uf2.find(i)};
        cout << mp[ar] << " ";
    }

    return 0;
}


Measured memory_bytes: 29312
def showBit(self):
    print("{:b}".format(data))

def bitCheck(n,i):
    return (int(bool(n&1<<i)))

def bitOn(n,i):
    return n|1<<i

def bitOff(n,i):
    return n&~(1<<i)

def bitFlip(n,i):
    return n^1<<i

def isbitAll(n):
    return int(bitCount(n)==64)

def isbitAny(n):
    return int(bitCount(n)>0)

def isbitNone(n):
    return int(bitCount(n)==0)

def bitCount(n):
    return bin(n).count('1')

n=0
q=int(input())
for i in range(q):
    qry=list(map(int,input().split()))
    if qry[0]==0:
        print(bitCheck(n,qry[1]))
    elif qry[0]==1:
        n=bitOn(n,qry[1])
    elif qry[0]==2:
        n=bitOff(n,qry[1])
    elif qry[0]==3:
        n=bitFlip(n,qry[1])
    elif qry[0]==4:
        print(isbitAll(n))
    elif qry[0]==5:
        print(isbitAny(n))
    elif qry[0]==6:
        print(isbitNone(n))
    elif qry[0]==7:
        print(bitCount(n))
    elif qry[0]==8:
        print(n)



Measured memory_bytes: 5624
using System;

public class Hello
{
    public static void Main()
    {
        var a = Console.ReadLine().Trim();
        var b = Console.ReadLine().Trim();
        if (a == b) { Console.WriteLine("EQUAL"); goto end; }
        if (a.Length > b.Length) { Console.WriteLine("GREATER"); goto end; }
        else if (a.Length < b.Length) { Console.WriteLine("LESS"); goto end; }
        var w = new string[2];
        w[0] = a;   w[1] = b;
        Array.Sort(w);
        if (w[0] == a) Console.WriteLine("LESS");
        else Console.WriteLine("GREATER");
        end:;
    }
}

Measured memory_bytes: 13408
N = int(input())
edges = [[] for _ in range(N)]

for _ in range(N - 1):
    fr, to, cost = map(int, input().split())
    fr -= 1
    to -= 1
    edges[fr].append((to, cost))
    edges[to].append((fr, cost))

Q, K = map(int, input().split())
K -= 1

minDist = [10**18] * N
minDist[K] = 0
st = [(K, 0)]
while st:
    now, dist = st.pop()
    for to, c in edges[now]:
        d = dist + c
        if minDist[to] > d:
            minDist[to] = d
            st.append((to, d))

ans = []
for _ in range(Q):
    X, Y = map(lambda a: int(a) - 1, input().split())
    ans.append(minDist[X] + minDist[Y])

print(*ans, sep='\n')


Measured memory_bytes: 49744
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let h: u64 = sc.cin();
    let w: u64 = sc.cin();
    if h == 1 && w == 1 {
        put!(1);
    } else if h == 1 {
        put!(w - 2);
    } else if w == 1 {
        put!(h - 2);
    } else {
        put!((w - 2) * (h - 2));
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
import scala.io.StdIn.readLine
import scala.collection.mutable.ArrayBuffer

case class Dice(var d:Seq[String]) {
  private val s = Array(4,0,2,3,5,1)
  private val w = Array(2,1,5,0,4,3)
  private val h = Array(0,2,4,1,3,5)
  private val buf = ArrayBuffer.empty[Seq[String]]

  def rotateAll() = {
    buf += d
    buf += s.map(d)
    buf += s.map(s).map(d)
    buf += s.map(s).map(s).map(d)
    buf += w.map(d)
    buf += w.map(w).map(w).map(d)

    buf += h.map(d)
    buf += s.map(s).map(s).map(h).map(d)
    buf += w.map(h).map(d)
    buf += w.map(w).map(w).map(h).map(d)
    buf += s.map(h).map(d)
    buf += s.map(s).map(h).map(d)

    buf += h.map(h).map(d)
    buf += s.map(s).map(s).map(h).map(h).map(d)
    buf += w.map(h).map(h).map(d)
    buf += w.map(w).map(w).map(h).map(h).map(d)
    buf += s.map(h).map(h).map(d)
    buf += s.map(s).map(h).map(h).map(d)

    buf += h.map(h).map(h).map(d)
    buf += s.map(s).map(s).map(h).map(h).map(h).map(d)
    buf += w.map(h).map(h).map(h).map(d)
    buf += w.map(w).map(w).map(h).map(h).map(h).map(d)
    buf += s.map(h).map(h).map(h).map(d)
    buf += s.map(s).map(h).map(h).map(h).map(d)
  }

  def getAllRot = buf.toArray
  def getFaces = d
}

object Main extends App {
  val faces1 = readLine.split(" ")
  val faces2 = readLine.split(" ").toSeq
  val dice1 = Dice(faces1)

  dice1.rotateAll()
  if(dice1.getAllRot.contains(faces2))
    println("Yes")
  else
    println("No")
}

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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(ll i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(ll j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

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

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


vector<string> splitStr(const string & s, char delim) {
    vector<string> elems;
    stringstream ss(s);
    string item;
    while (getline(ss, item, delim)) {
        if (!item.empty()) {
            elems.push_back(item);
        }
    }
    return elems;
}

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

    string s;
    cin >> s;

    vector<string> ss = splitStr(s, '/');

    if (stoi(ss[1]) <= 4) {
        cout << "Heisei" << endl;
    }
    else {
        cout << "TBD" << endl;
    }

    return 0;
}


Measured memory_bytes: 3656
n = int(input())
p = [int(i) for i in input().split()]
ans = 0
for i in range(1,n) :
    ix = p[i-1:i+2]
    if min(ix) != ix[1] and max(ix)!= ix[1] :
        ans += 1
#        print(ix)
print(ans)

Measured memory_bytes: 9188
import java.io.PrintWriter;
import java.util.*;

public class Main {

    private static final int M = 1046527;

    private static final String[] H = new String[M];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = Integer.parseInt(sc.next());

        for (int i = 0; i < n; i++) {
            String cmd = sc.next();
            String str = sc.next();

            if ("insert".equals(cmd)) insert(str);
            if ("find".equals(cmd)) pw.println(find(str) ? "yes" : "no");
        }

        pw.flush();
    }

    private static boolean insert(String str) {
        int key = getKey(str);
        for (int i = 0;; i++) {
            int h = h(key, i);
            if (str.equals(H[h])) return true;
            if (H[h] == null) {
                H[h] = str;
                return true;
            }
        }
    }

    private static boolean find(String str) {
        int key = getKey(str);
        for (int i = 0;; i++) {
            int h = h(key, i);
            if (str.equals(H[h])) return true;
            if (H[h] == null) return false;
        }
    }

    private static int getChar(char ch) {
        switch (ch) {
            case 'A': return 1;
            case 'C': return 2;
            case 'G': return 3;
            case 'T': return 4;
            default: return 0;
        }
    }

    private static int getKey(String str) {
        int sum = 0;
        int p = 1;
        for (int i = 0; i < str.length(); i++) {
            sum += p * getChar(str.charAt(i));
            p *= 5;
        }
        return sum;
    }

    /**
     * ハッシュ関数.
     * @param key キー.
     * @param i 衝突が発生して次のハッシュ値を計算した回数.
     * @return ハッシュ値.
     */
    private static int h(int key, int i) {
        return (h1(key) + i * h2(key)) % M;
    }


    private static int h1(int key) {
        return key % M;
    }

    private static int h2(int key) {
        return 1 + (key % (M - 1));
    }
}





Measured memory_bytes: 213768
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> P(N);
  vector<int64_t> C(N);
  for(int i=0; i<N; i++){
    cin >> P[i];
    P[i]--;
  }
  for(int i=0; i<N; i++){
    cin >> C[i];
  }
  
  int64_t INF = 1e18+10;
  int64_t ans = INF*-1;
  
  for(int i=0; i<N; i++){
    vector<int64_t> move(N,INF);
    vector<int64_t> num(N,0);
    int cnt = 0;
    int pos = i;
    int64_t score = 0;
    while(true){
      move[pos] = score + C[pos];
      score = move[pos];
      cnt++;
      num[pos] = cnt;
      if(move[P[pos]] != INF){
        break;
      }
      pos = P[pos];
    }
    for(int j=0; j<N; j++){
      if(num[j] == 0){
        continue;
      }
      else{
        if(num[j] > K){
          continue;
        }
        else{
          ans = max({ans, move[j], move[j] + ((K - num[j]) / cnt) * move[pos]});
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3784
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int X = scan.nextInt();
        int[] L = new int[N];
        for (int i = 0; i < N; i++) {
            L[i] = scan.nextInt();
        }
        int current = 0;
        int answer = 1;
        for (int i = 0; i < N; i++) {
            current = current + L[i];
            if (current <= X) {
                answer += 1;
            }
        }
        System.out.println(answer);
    }
}


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

using namespace std;

int main(int argc, char *argv[]) {
	string O, E;

	cin >> O >> E;
	for (int i = 0; i < E.size(); i++) {
		cout << O[i] << E[i];
	}
	if (E.size() < O.size()) cout << O.back();
	cout << endl;

	return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;

int seica(ll a, ll b){
	ll tmp = a ^ b;
	int ret = 0;
	REP(i, 20){
		if(tmp & (1 << i))ret++;
	}
	return ret;
}

void out(vector<int> v){
	cout << "YES" << endl;
	REP(i, v.size()){
		cout << v[i];
		if(i != v.size() - 1)cout << " ";
	}
	cout << endl;
}

vector<int> dfs(int s, int g, int mask, int n){
	//cout << s << " " << g << " " << bitset<10>(mask) << " " << n << endl;
	if(n == 1){
		return {s, g};
	}
	
	
	REP(i, 20){
		if(!(mask & (1<<i)))continue;
		int a = s & (1<<i);
		int b = g & (1<<i);
		if(a == b)continue;
		int nmask = mask ^ (1<<i);
		REP(j, 20){
			if(!(nmask & (1<<j)))continue;
			int tmp = (s & nmask) ^ (1<<j);
			auto l = dfs(s & nmask, tmp, nmask, n - 1); 
			auto r = dfs(tmp, g & nmask, nmask, n - 1); 
			vector<int> ret;
			REP(k, l.size())ret.PB(l[k] | (s & (1<<i)));
			REP(k, r.size())ret.PB(r[k] | (g & (1<<i)));
			return ret;
		}
	}	
}


int main(){
	
	ll n, a, b;cin >> n >> a >> b;
		
	if(seica(a, b) % 2 == 0){
		cout << "NO" << endl;
		return 0;
	}
	
	out(dfs(a, b, (1<<n)-1, n));
	
	return 0;
}


Measured memory_bytes: 1628
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;
  string key = "ACGT";
  int ans = 0, sum_val = 0;
  rep(i, 0, s.size()) {
    if (key.find(s[i]) != string::npos) {
      sum_val++;
      chmax(ans, sum_val);
    } else
      sum_val = 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define eps 1e-6
#define pi 3.141592653589793
using namespace std;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}

int main(int argc, char* argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	string s;
	cin>>s;
	
	int ans=0,c=0;
	for(auto x:s)
    {
	    if(x=='I')
	        c++;
	    else c--;
	    ans=max(ans,c);
    }
	cout<<ans;
	return 0;
}

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





int main() {
  string n;
  cin>>n;
  
  if (n.at(1)==n.at(2) and (n.at(0)==n.at(1) or n.at(2)==n.at(3))){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  
  
}

  













Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
    int W,a,b;
    cin >> W >> a >> b;
    if(b+W < a){
        cout << a- (b+W);
    }else if(b > a+W){
        cout << b - (a+W);

    }else{
        cout << 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main(){
	long long int s = 0 ; cin >> s; 
	long long int sum = 0;
	vector<long long int > v(s+1);
	for(int i =1 ; i<=s ; i++){
		if(i==1||i==2){
		continue;}
		v[i]=1;
		for(long long int j = 3; j<=i-3;j++){
			v[i]=(v[i]+v[i-j])%mod;
		}	
		}
		cout << v[s]%mod;
		}



Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }



const ll MOD = 1e9+7;
ll dp[1005][1005];
ll solve(){
    ll res = 0;
    ll n,k; cin >> n >> k;
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= k; j++){
            dp[i][j] += dp[i-1][j] * j;
            dp[i][j] += dp[i-1][j-1] * j;
            dp[i][j] %= MOD;
        }
    }
    res = dp[n][k];
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 11076
s=list(input())
buf=""

for i in range(len(s)):
    if s[i]=="0":
        buf="".join((buf,"0"))
    elif s[i]=="1":
        buf = "".join((buf, "1"))
    elif s[i]=="B":
        if len(buf)>0:
            buf=buf[:len(buf)-1]
    #print(buf)
print(buf)

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



int main() {
  string a,b;
  cin >> a >> b;
  int ab = atoi((a+b).c_str());
  int c = sqrt(ab);
  if(c*c==ab){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}

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

int main(){
	int a,b;
	cin >> a >> b;

		if( a == b )
		{
		cout << "a == b" << endl;
		}else{
			if( a > b)
			{
			cout << "a > b" << endl;
			}else{
			cout << "a < b" << endl;
			}
		}

}


Measured memory_bytes: 3080
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
print('x'*len(s))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	int x; cin >> x;
	int a = x/500;
	x -= a * 500;
	int b = x/5;
	int ans = 1000*a + 5*b;
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main(){


    int counter[26]={0};
    int i,num;
    char ch;

    while (scanf("%c",&ch)!=EOF)
    {
        if (isupper(ch))
        {
            ch=tolower(ch);
        }
        num=ch-'a';
        counter[num]++;
    }
    for (i=0; i<26; i++)
    {
        printf("%c : %d\n",i+'a',counter[i]);//ch-'a'??§??°??????????????????i+'a'??§???????????´???
    }
    return 0;
}

Measured memory_bytes: 548
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <bitset>
#include <iterator>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <random>
#include <numeric>
#include <set>
#include <cassert>
#include <cmath>
#include <cinttypes>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}
template<class T> T read_val() { throw 1; }
template<> int read_val() { int tmp; scanf("%" PRId32, &tmp); return tmp; }
template<> long long read_val() { long long tmp; scanf("%" PRId64, &tmp); return tmp; }
auto read_int = read_val<int>; auto read_long = read_val<long long>;
template<class T> void scanf_vec(vector<T>& vec) { for (int i = 0; i < vec.size(); i++) vec[i] = read_val<T>(); }

#define MOD 1000000007
#define inf 2000000000
#define FWT_SIZE 2000000
#define pii pair<int,int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define sort_all(x) sort(all(x))
#define make_unique(x) (x).erase(unique(all(x)), (x).end())


vector<int> dx = {1,-1,0,0}, dy = {0,0,1,-1};

int main() {

#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n = read_int();
	vector<int> vec(n * n);
//	cin >> vec;
	scanf_vec(vec);

	vector<vector<bool>> board(n, vector<bool>(n, true));
	vector<int> visited(n*n, -1);
	vector<vector<int>> dists(n, vector<int>(n, 0));

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			dists[i][j] = 1+min({ i,j,n - 1 - i,n - 1 - j });
		}
	}

	long long ans = 0;
	for (int v : vec)
	{
		v--;
		queue<int> pos;
		visited[v] = v;
		pos.push(v);
		ans += dists[v/n][v%n]-1;
		board[v / n][v % n] = false;
		while (pos.size() > 0)
		{
			int  x = pos.front();
			pos.pop();

			int row = x / n;
			int col = x % n;

			int min_other = n;
			for (int i = 0; i < 4; i++)
			{
				int r = row + dx[i], c = col + dy[i];
				if (r < 0 || c < 0 || r >= n || c >= n)
					min_other = 0;
				else
				{
					min_other = min(min_other, dists[r][c]);
				}
			}
			if (board[row][col])
				min_other++;

			dists[row][col] = min_other;
			for (int i = 0; i < 4; i++)
			{
				int r = row + dx[i], c = col + dy[i];
				if (r < 0 || c < 0 || r >= n || c >= n)
					min_other = 0;
				else
				{
					int vv = r * n + c;
					int other_dist = dists[r][c];
					if (visited[vv] != v && other_dist  > min_other + board[r][c])
					{
						visited[vv] = v;
						pos.push(vv);
					}
				}
			}
		}
	}


	printf("%" PRId64,ans);

	return 0;
}

Measured memory_bytes: 6416
#include <stdio.h>
#include <ctype.h>

int main(){

  char ch;

  while (1) {

    scanf("%c",&ch);
    if(ch=='\n') break;

    if(islower(ch)){
      ch=toupper(ch);
      printf("%c",ch);
    }else if(isupper(ch)){
      ch=tolower(ch);
      printf("%c",ch);
    }else{
      printf("%c",ch);
    }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	int N,sum=0;
	while(cin>>N)
	{
		for(int i=1;i<=N;i++)
		{
			sum+=i;
		}
		cout<<sum<<endl;
		sum=0;
	}
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;

int main(){
  int N;
  cin >> N;
  vector<LL> A(N);
  rep(i,N) cin >> A[i];
  sort(A.begin(),A.end());
  for(int i=0; i<N-1; i+=2){
    if(A[i]>=0) break;
    if(A[i]<0&&A[i+1]>0){
      if(A[i]+A[i+1]<0){ A[i]*=-1, A[i+1]*=-1;}
    }
    else A[i]*=-1, A[i+1]*=-1;
  }
  LL ans=0;
  rep(i,N) ans+=A[i];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
// https://atcoder.jp/contests/abc150/tasks/abc150_a
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int K, X;
    cin >> K >> X;
    if (500 * K >= X)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    
    return 0;
}


Measured memory_bytes: 3536
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;
const double pi = acos(-1.0);

signed main(){
    int n;cin>>n;
    int x[n],y[n];
    REP(i,n)cin>>x[i]>>y[i];
    double ans=0;
    for(double w=0;w<2*pi;w+=pi/18000.0){
        double vx=cos(w),vy=sin(w);
        double nx=0,ny=0;
        REP(i,n){
            double inpro = vx*x[i]+vy*y[i];
            if(inpro>0){
                nx+=x[i];
                ny+=y[i];
            }
        }
        chmax(ans,sqrt(nx*nx+ny*ny));
    }
    cout<<fixed<<setprecision(20.20)<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,a; cin>>n>>a;
    n%=500;
    cout<<((n<=a)?"Yes":"No")<<endl;
}

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

int main() {
	// your code goes here
	int r;
	cin >> r;
	if(r < 1200){
	    cout << "ABC";
	}
	else{
	    if(r < 2800){
	        cout << "ARC";
	    }
	    else cout << "AGC";
	}
	return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<math.h>

using namespace std;

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



signed main() {

	ll n;
	cin >> n;
	ll a;

	ll b = 1;
	bool flag = false;
	rep(i, n) {
		cin >> a;
		if (a == b) {
			b++;
			flag = true;
		}
	}
	if (flag == true) {
		cout << n - b + 1;
	}
	else {
		cout << -1;
	}
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll X;
    cin >> X;

    ll n = 100;
    ll count = 0;
    while(n<X){
        n = n * 1.01;
        count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
#include <cassert>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
int N;
double x[100],y[100],z[100],r[100];
vector<double> zs;
double sq(double a,double b){return (a-b)*(a-b);}
double dist(int a,int b){return sqrt(sq(x[a],x[b])+sq(y[a],y[b])+sq(z[a],z[b]));}
int par[100];
void init(int N){rep(i,N) par[i]=i;}
int find(int x){
	if(x==par[x]) return x;
	return par[x]=find(par[x]);
}
void unite(int x,int y){
	x=find(x),y=find(y);
	par[x]=y;
}
int cut(double a){
	double rr[100]={};
	bool is[100]={};
	rep(i,N) if(z[i]-r[i]<a&&a<z[i]+r[i]){
		is[i]=1;
		rr[i]=sqrt(r[i]*r[i]-sq(z[i],a));
	}
	init(N);
	rep(i,N) rep(j,i){
		if(!is[i]||!is[j]) continue;
		if(sqrt(sq(x[i],x[j])+sq(y[i],y[j]))<rr[i]+rr[j]) unite(i,j);
	}
	set<int> ps;
	rep(i,N) if(is[i]) ps.insert(find(i));
	return ps.size();
}
int main(){
	while(true){
		cin>>N;
		if(N==0) break;
		zs.clear();
		rep(i,N) cin>>x[i]>>y[i]>>z[i]>>r[i];
		rep(i,N) zs.pb(z[i]-r[i]),zs.pb(z[i]+r[i]);
		rep(i,N) rep(j,i){
			double d=dist(i,j);
			if(d>r[i]+r[j]) continue;
			if(abs(r[i]-r[j])>d) continue;
			double theta=acos( (r[i]*r[i]+d*d-r[j]*r[j])/(2.0*r[i]*d) );
			double phi=atan2( z[j]-z[i],sqrt(sq(x[i],x[j])+sq(y[i],y[j])) );
			zs.pb(z[i]+r[i]*sin(theta+phi));
			zs.pb(z[i]+r[i]*sin(-theta+phi));
		}
		sort(all(zs));
		int now=0;
		string ans;
		for(double a:zs){
			int t=cut(a+1e-4);
			if(t==now+1){
				ans+='1';
			}else if(t==now-1){
				ans+='0';
			}else if(t==now){
			}else{
				assert(0);
			}
			now=t;
		}
		cout<<ans.size()<<endl<<ans<<endl;
	}
}

Measured memory_bytes: 1416