akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto N = readln.chomp.to!int;
    auto G = new int[][](N);
    auto H = new int[][](N);
    auto D = new int[](N);
    foreach (i, p; readln.split.map!(to!int).enumerate) {
        G[p-1] ~= i.to!int;
        H[i] ~= p-1;
        D[p-1] += 1;
    }
    auto A = new int[](N);
    fill(A, -1);

    
    int mex(int n) {
        auto X = G[n].map!(j => A[j]).filter!"a >= 0".array.sort().uniq().array;
        int m = X.length.to!int;
        foreach (i; 0..X.length.to!int) {
            if (i != X[i]) {
                m = i;
                break;
            }
        }
        return m;
    }

    bool check() {
        return N.iota.map!(i => mex(i) == A[i]).all;
    }
    
    void dfs(int n) {
        A[n] = mex(n);
        foreach (m; H[n]) {
            D[m] -= 1;
            if (D[m] == 0 && A[m] == -1) {
                dfs(m);
            }
        }
    }


    
    foreach (i; 0..N) {
        if (D[i] == 0 && A[i] == -1) {
            dfs(i);
        }
    }

    if (!A.canFind(-1)) {
        writeln("POSSIBLE");
        return;
    }

    foreach (i; 0..N) {
        if (A[i] == -1) {
            int k = -1;
            foreach (j; H[i]) if (A[j] == -1) k = j;
            
            int m = mex(i);
            auto AA = new int[](N);
            auto DD = new int[](N);
            foreach (j; 0..N) AA[j] = A[j], DD[j] = D[j];
            A[i] = m;
            dfs(k);
            if (check) {
                writeln("POSSIBLE");
                return;
            }
            
            foreach (j; 0..N) A[j] = AA[j], D[j] = DD[j];
            auto X = G[i].map!(j => A[j]).filter!"a >= 0".array ~ m;
            X = X.sort().uniq().array;
            m = X.length.to!int;
            foreach (j; 0..X.length.to!int) {
                if (j != X[j]) {
                    m = j;
                    break;
                }
            }
            A[i] = m;
            dfs(k);
            if (check) {
                writeln("POSSIBLE");
                return;
            }
            break;
        }
    }

    writeln("IMPOSSIBLE");
}



Measured memory_bytes: 41128
// Last Change: 04/02/2019 22:01:29.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  vector<int> A(3);

  for (int i = 0; i < 3; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());

  int diff12 = abs(A[1] - A[0]), diff23 = abs(A[2] - A[1]);
  /*
  if (diff12 > diff23) {
    cout << diff23 << endl;
  } else {
    cout << diff12 << endl;
  }*/
  cout << diff12 + diff23 << endl;

  //NS::LoopUntilZeroInpput();
}


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

signed main(){
	int x=read();
	int g=x/11;
	g=g*2;
	if(x%11==0)
		;
	else if(x%11<=6)
		g+=1;
	else
		g+=2;
	cout<<g<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define GO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
const int N = 3e4 + 5;
const int M = 1e6 + 5;
const int Mod = 1e9 + 7;

ll __gcd(ll a, ll b) {
	while (a) b %= a, swap(a, b);
	return b;
}


int main()
{
	GO;
	int k;
	cin >> k;
	ll ans = 0;
	for (int i = 1; i <= k; i++)
		for (int j = 1; j <= k; j++)
			for (int kk = 1; kk <= k; kk++)
				ans += __gcd(i, __gcd(j, kk));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var N int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N)

	ls := make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &ls[i])
	}

	sort.Sort(sort.IntSlice(ls))
	max := ls[len(ls)-1]
	sum := 0
	for _, l := range ls {
		sum = sum + l
	}
	sum = sum - max

	if max < sum {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

def gcd(a, b):
  return a if b == 0 else gcd(b, a % b)

def solve(A, B, C, D):
  if A < B or D < B:
    print("  V1", file=stderr)
    return False
  CC = C + 1
  if B <= CC:
    print("  V2", file=stderr)
    return True
  g = gcd(D, B)
  # [CC, B) is prohobited
  if CC <= B - g:
    print("  V3", file=stderr)
    return False
  else:
    print("  V4", file=stderr)
    return A % g < CC % g

T = read()
for _ in range(T):
  A, B, C, D = reads()
  print("Yes" if solve(A, B, C, D) else "No")

Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

double dp[44444][222];

int main(){
  ll n,t[111],v[111];
  cin>>n;
  ll sum_t=0;
  for(int i=0;i<n;i++){
    cin>>t[i];
    t[i]*=2;
    sum_t+=t[i];
  }
  for(int i=0;i<n;i++){
    cin>>v[i];
    v[i]*=2;
  }
  fill_n(*dp,44444*111,-1);
  dp[0][0]=0;
  
  ll tv[44444];
  ll cnt=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<t[i];j++){
	 if(j==0&&i)tv[cnt++]=min(v[i-1],v[i]);
	 else tv[cnt++]=v[i];
    }
  }

  for(int i=0;i<sum_t;i++){
    for(int j=0;j<=tv[i];j++){
	 if(dp[i][j]<0)continue;
	 dp[i+1][j]=max(dp[i+1][j],dp[i][j]+(double)j/2.0);
	 dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+((double)j+0.5)/2.0);
	 if(j)dp[i+1][j-1]=max(dp[i+1][j-1],dp[i][j]+((double)j-0.5)/2.0);
	 
    }
  }
  printf("%.10lf\n",dp[sum_t][0]/2.0);
  /*
  for(int i=0;i<=sum_t;i++){
    for(int j=0;j<=40;j++){
	 cout<<dp[i][j]<<" ";
    }
    cout<<endl;
  }
  */
  return 0;
}


Measured memory_bytes: 70144
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;

  ll x, y;
  ll x_vertex[N];
  ll y_vertex[N];
  vector<ll> x_coords;
  vector<ll> y_coords;
  for (int i = 0; i < N; ++i) {
    cin >> x >> y;

    x_vertex[i] = x;
    y_vertex[i] = y;

    x_coords.push_back(x);
    y_coords.push_back(y);
  }

  sort(x_coords.begin(), x_coords.end());
  sort(y_coords.begin(), y_coords.end());

  ll ans = (x_coords[N - 1] - x_coords[0]) * (y_coords[N - 1] - y_coords[0]);

  for (int i = 0; i < N - 1; ++i) {
    ll x1 = x_coords[i];

    for (int j = i + 1; j < N; ++j) {
      ll x2 = x_coords[j];

      for (int k = 0; k < N - 1; ++k) {
        ll y1 = y_coords[k];

        for (int l = k + 1; l < N; ++l) {
          ll y2 = y_coords[l];

          int cnt = 0;

          for (int n = 0; n < N; ++n) {
            if (x_vertex[n] < x1 || x2 < x_vertex[n]) continue;
            if (y_vertex[n] < y1 || y2 < y_vertex[n]) continue;

            ++cnt;
          }

          ll area = abs(x2 - x1) * abs(y2 - y1);

          if (cnt >= K && ans > area) {
            ans = area;
          }
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
/*
    1) Notice the range of data;
    2) while(scanf) format need to init;
    3) Enough maxn;
    4) delete the freopen;
    5) remember to read this before submit;
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
int gcd(int a,int b){if (b == 0) return a; return gcd(b , a%b);}
int lcm(int a, int b){ return a/gcd(a,b)*b;}
inline int read(){
    int f = 1, x = 0;char ch = getchar();
    while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
    while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
    return x * f;
}
int main(){
    string s;
    cin >> s;
    int ans1 = 0,ans2 = 0;
    for(int i=0; i<s.length(); i++){
        if (i & 1){
            if (s[i] == '0') ans1++;
        }else{
            if (s[i] == '1') ans1++;
        }
    }
    for(int i=0; i<s.length(); i++){
        if (i & 1){
            if (s[i] == '1') ans2++;
        }else{
            if (s[i] == '0') ans2++;
        }
    }
    cout << min(ans1,ans2) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
constexpr auto INF = 1000000007;
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}
int Max(int x, int y) {
	if (x > y)return x;
	else return y;
}
int Min(int x, int y) {
	if (x < y)return x;
	else return y;
}
int kai(int x) {
	int cnt = 1;
	if (x == 0)return 1;
	cnt = kai(x - 1);
	return x * cnt;
}
int prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
/*Library End!*/
map<int, int>mp;
int ans, memo[105];
signed main() {
	int n;
	cin >> n;
	for (int i = 2; i < n; i++) {
		if (!prime(i))continue;
		int m = n, cnt = 0;
		while (m) {
			cnt += m / i;
			m /= i;
		}
		mp[cnt]++;
	}
	for (int i = 100; i >= 2; i--) {
		memo[i] = mp[i] + memo[i + 1];
	}
	ans += memo[74];
	ans += memo[24] * (memo[2] - 1);
	ans += memo[14] * (memo[4] - 1);
	ans += (memo[4] * (memo[4] - 1)) / 2 * (memo[2] - 2);
	cout << ans << endl;
	endre;
}


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

int main(){
  int n;
  int a[1000];

  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=n-1;i>=0;i--){
    if(i==0) cout<<a[i]<<endl;
    else cout<<a[i]<<" ";

  }
  return 0;
}

Measured memory_bytes: 3100
n = int(input())
s = str(input())

MOD = 10**9 + 7
s_d = {}
for curr_s in s:
    s_d.setdefault(curr_s,0)
    s_d[curr_s] += 1

ans = 1
for k,v in s_d.items():
    ans *= (v+1)
    ans%=MOD
ans-=1
ans%=MOD
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int M=3e5+5,mod=1e9+7;
int mmp[8][2]={3,1,5,2,2,2,4,7,3,3,6,1,5,5,3,1},dp[M][8],len,i,j;
char ch[M];
void in(){scanf("%s",ch);}
void ac()
{
    len=strlen(ch);dp[len][1]=dp[len][2]=1;
    for(i=len-1;i>=0;--i)for(j=0;j<8;++j)
    {
        if(ch[i]!='0')dp[i][j]+=dp[i+1][mmp[j][1]];
        if(ch[i]!='1')dp[i][j]+=dp[i+1][mmp[j][0]];
        dp[i][j]%=mod;
    }
    printf("%d",dp[0][0]);
}
int main(){in();ac();}

Measured memory_bytes: 9856
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int N, Q;
	string S;
	int count[100100];
	for (int i = 0; i < 100100; ++i)count[i] = 0;
	cin >> N >> Q;
	cin >> S;
	for (int i = 0; i < N-1; ++i) {
		if (S[i] == 'A'&&S[i + 1] == 'C') {
			count[i + 1] = 1;
		}
	}
	int ans[100100];
	for (int i = 0; i < 100100; ++i)ans[i] = 0;
	for (int i = 0; i < N; ++i) {
		ans[i + 1] = ans[i];
		if (count[i + 1]) {
			ans[i + 1]++;
		}
	}
	int res[100100];
	for (int i = 0; i < Q; ++i) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		res[i] = ans[r] - ans[l];
	}
	for (int i = 0; i < Q; ++i) {
		cout << res[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 2176
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]

mon = 0
length = len(B) - 1

for i in range(len(B)):
	j = length - i
	if B[j] >= A[j+1]:
		mon += A[j+1]
		B[j] -= A[j+1]
		A[j+1] = 0
		if B[j] >= A[j]:
			mon += A[j]
			A[j]=0
		else:
			mon += B[j]
			A[j]-=B[j]
	else:
		mon += B[j]
		B[j] = 0
		A[j+1] -= B[j]

print(mon)
	

Measured memory_bytes: 19648
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`
										`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	n := nextInt()
	h := nextInt()

	amax := 0
	blist := makeSlist()

	for i := 0; i < n; i++ {
		a := nextInt()
		b := nextInt()

		amax = maxInt(amax, a)
		blist.add(b)
	}

	ans := 0

	for i := n - 1; i >= 0; i-- {
		if blist.l[i] > amax {
			ans++
			h -= blist.l[i]
		} else {
			break
		}
		if h <= 0 {
			break
		}
	}
	if h > 0 {
		ans += int(math.Ceil(float64(h) / float64(amax)))
	}

	//fmt.Fprintln(out, "[DEBUG]", a)
	fmt.Fprintln(out, ans)

}

// 挿入ソート配列
type slist struct {
	l []int
}

func makeSlist() slist {
	return slist{[]int{}}
}

func (s *slist) add(a int) {
	pos := sort.Search(len(s.l), func(i int) bool { return s.l[i] >= a })
	if pos < len(s.l) {
		s.l = append(s.l[:pos+1], s.l[pos:]...)
		s.l[pos] = a
	} else {
		s.l = append(s.l, a)
	}
}
func (s slist) contains(a int) bool {
	pos := sort.Search(len(s.l), func(i int) bool { return s.l[i] >= a })
	return pos < len(s.l) && s.l[pos] == a
}

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

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func printArray(a []int) {
	for i := 0; i < len(a); i++ {
		if i >= 1 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, a[i])
	}
	fmt.Fprintln(out)
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func log10(x int) float64 {
	return math.Log10(float64(x))
}


Measured memory_bytes: 7216
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

struct Edge {
  long long to;
  long long cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<long, int>;
const long long INF = 1LL << 60;


/* dijkstra(G,s,dis,prev)
   入力：グラフ G, 開始点 s, 距離を格納する dis, 最短経路の前の点を記録するprev
   計算量：O(|E|log|V|)
   副作用：dis, prevが書き換えられる
   */
void dijkstra(const Graph &G, int s, vector<long long> &dis, vector<int> &prev) {
  int N = G.size();
  dis.resize(N, INF);
  prev.resize(N, -1); // 初期化
  priority_queue<P, vector<P>, greater<P>> pq;
  dis[s] = 0;
  pq.emplace(dis[s], s);
  while (!pq.empty()) {
    P p = pq.top();
    pq.pop();
    int v = p.second;
    if (dis[v] < p.first) {
      continue;
    }
    for (auto &e : G[v]) {
      if (dis[e.to] > dis[v] + e.cost) {
        dis[e.to] = dis[v] + e.cost;
        prev[e.to] = v; // 頂点 v を通って e.to にたどり着いた
        pq.emplace(dis[e.to], e.to);
      }
    }
  }
}
/* get_path(prev, t)
   入力：dijkstra で得た prev, ゴール t
   出力： t への最短路のパス
   */
vector<int> get_path(const vector<int> &prev, int t) {
  vector<int> path;
  for (int cur = t; cur != -1; cur = prev[cur]) {
    path.push_back(cur);
  }
  reverse(path.begin(), path.end()); // 逆順なのでひっくり返す
  return path;
}
int h, w, ch, cw, dh, dw;

ll f(int y, int x) {
  return y*w + x;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--;cw--;dh--;dw--;
  vector<string> v(h);
  rep(i, h) cin >> v[i];
  Graph g(h*w);
  rep(i, h) rep(j, w){
    if(v[i][j] == '#') continue;
    for (int k1 = -2; k1 <= 2; k1++) {
      for (int k2 = -2; k2 <= 2; k2++) {
        if(k1 == 0 && k2 == 0) continue;
        int ny = i+k1;
        int nx = j+k2;
        if(ny >= h || nx >= w || ny < 0 || nx < 0) continue;
        if(v[ny][nx] == '#') continue;
        // cout << i << ' ' << j  << ' ' << k1 << ' ' << k2 << endl;
        // cout << f(i, j) << ' ' << f(ny, nx) << endl;
        if((k1==1&&k2==0) || (k1==-1&&k2==0) || (k1==0&&k2==1) || (k1==0&&k2==-1)){
          g[f(i, j)].push_back({f(ny, nx), 0});
        }else{
          g[f(i, j)].push_back({f(ny, nx), 1});
        }
      }
    }
  }

  vector<ll> dist;
  vector<int> prev;

  // dijkstra(g, f(0, 0), dist, prev);
  dijkstra(g, f(ch, cw), dist, prev);

  ll res = dist[f(dh, dw)];
  if(res == INF) cout << -1 << endl;
  else cout << res << endl;
}


Measured memory_bytes: 171560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  //freopen("input.txt","r",stdin);
#endif

  ll n,m;
  cin>>n>>m;
  if(n==m)
  {
    cout<<0<<endl;
  }
  else if(m>n)
  {
    cout<<min(n,abs(n-m));
  }

  else
  {
    cout<<min(n%m,abs(n%m-m))<<endl;
  }
  return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
        	while(true) {
        		int n = sc.nextInt();
        		int m = sc.nextInt();
        		if(n==0 && m==0) break;
        		int [] dif = new int[m+1];
        		for(int i=1;i<=m;i++) {
        			dif[i] = 0;
        		}
        		for(int i=0;i<n;i++) {
        			int d = sc.nextInt();
        			int v = sc.nextInt();
        			if(v>dif[d]) {
        				dif[d] = v;
        			}
        		}
        		int sum = 0;
        		for(int i=1;i<=m;i++) {
        			sum += dif[i];
        		}
        		System.out.println(sum);
        	}
        }
    }
}



Measured memory_bytes: 34012
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

class Procon {
    static void Main (string[] agrs) {
        for (int i = 1; i<= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                Console.WriteLine("{0}x{1}={2}", i, j, i*j);
            }
        }
    }

    static string String () => Scanner.nextString ();
    static int Int () => int.Parse (Scanner.nextString ());
    static long Long () => long.Parse (Scanner.nextString ());
    static double Double () => double.Parse (Scanner.nextString ());
    static char[] Chars () => String ().ToCharArray ();
    static string[] Strings () => Console.ReadLine ().Split (' ');
    static int[] Ints () => Strings ().Select (v => int.Parse (v)).ToArray ();
    static long[] Longs () => Strings ().Select (v => long.Parse (v)).ToArray ();
    static double[] Doubles () => Strings ().Select (v => double.Parse (v)).ToArray ();
    const int M = 1000000007;
}

class PriorityQueue<T> where T : IComparable<T> {
    public T[] heap;
    public int size;
    public int sign;
    public PriorityQueue (int N, bool descend = false) {
        heap = new T[N];
        sign = 1;
        if (descend) sign = -1;
    }
    public int Compare (T x, T y) {
        return x.CompareTo (y) * sign;
    }
    public void Push (T x) {
        int i = size++;
        while (i > 0) {
            int p = (i - 1) / 2;
            if (Compare (x, heap[p]) >= 0) {
                break;
            }
            heap[i] = heap[p];
            i = p;
        }
        heap[i] = x;
    }
    public T Pop () {
        T ret = heap[0];
        T x = heap[--size];
        int i = 0;
        while (i * 2 + 1 < size) {
            int a = i * 2 + 1;
            int b = i * 2 + 2;
            if (b < size && Compare (heap[a], heap[b]) > 0) {
                a = b;
            }
            if (Compare (heap[a], x) >= 0) {
                break;
            }
            heap[i] = heap[a];
            i = a;
        }
        heap[i] = x;
        return ret;
    }
    public int Count () {
        return size;
    }
}

class Scanner {
    static string[] s = new string[0];
    static int i = 0;
    static int max_i = 0;
    static public string nextString () {
        if (i >= s.Length) {
            s = Console.ReadLine ().Split (' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0) {
                return "";
            }
            return s[i++];
        }
        return s[i++];
    }
}



Measured memory_bytes: 17824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);
const int MAXN = 100010;
ll dp[MAXN] = {0};
bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; ll(i) <= ll(sqrtNum); i += 2)
    {
        if (num % ll(i) == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
    int q;
    cin >> q;
    vector<ll> l(q),r(q);
    for(int i=0;i<q;i++){
        cin >> l[i] >> r[i];
    }
    dp[1] = 0;
    for(int i=3;i<MAXN;){
        ll p1 = ll(i),p2 = (p1 + 1) / 2;
        if(IsPrime(p1) && IsPrime(p2)){
            dp[i] = dp[i-2] + 1;
        }
        else{
            dp[i] = dp[i-2];
        }
        i+=2;
    }
    /*
    for(int i=1;i<=15;){
        cout << i << " " << dp[i] << endl; 
        i+=2;
    }
    */
    for(int i=0;i<q;i++){
        cout << dp[r[i]] - dp[l[i] - 2] << endl;
    }

}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

struct Edge {
    int from;
    int to;
    int weight;
    Edge(int from, int to, int weight) : from(from), to(to), weight(weight) {
    }
    
    int other(int u) {
        return u == from ? to : from;
    }
};

struct LCA {
    int n;
    vector<vector<int>> g;
    vector<Edge> edges;
    vector<int> depth;
    vector<int> parent;
    vector<vector<int>> points;
    
    int height;
    int logHeight;
    
    LCA(int n) : n(n) {
        g.assign(n, vector<int>());
        depth.assign(n, 0);
        parent.assign(n, -1);
    }
    
    void addEdge(int from, int to, int w) {
        edges.push_back(Edge(from, to, w));
        g[from].push_back(edges.size() - 1);
        g[to].push_back(edges.size() - 1);
    }
    
    void init(int root) {
        dfs(root, -1, 0);
        logHeight = (int) (log(height) / log(2)) + 1;
        initJumpTable();
    }
     
    void dfs(int u, int p, int d) {
        height = max(height, d);
        depth[u] = d;
        parent[u] = p; 
        for (int e : g[u]) {
            Edge edge = edges[e];
            int v = edges[e].other(u);
            if (v != p) {
                dfs(v, u, d + 1);
            }
        }
    }
    
    void initJumpTable() {
        points.assign(n, vector<int>(logHeight, -1));
        
        for (int i = 0; i < n; i++) {
            points[i][0] = parent[i];
        }
        for (int j = 1; j < logHeight; j++) {
            for (int i = 0; i < n; i++) {
                if (points[i][j - 1] != -1) {
                    points[i][j] = points[points[i][j - 1]][j - 1];
                }
            }
        }
    }
    
    int lca(int p, int q) {
        if (depth[p] < depth[q]) {
            swap(p, q);
        }

        int logP = (int) (log(depth[p]) / log(2));

        for (int i = logP; i >= 0; i--) {
            if ((depth[p] - (1 << i)) >= depth[q]) {
                p = points[p][i];
            }
        }

        if (p == q) {
            return p;
        }

        for (int i = logP; i >= 0; i--) {
            if (points[p][i] != -1 && points[q][i] != points[p][i]) {
                p = points[p][i];
                q = points[q][i];
            }
        }
        return parent[p];
    }
};

int main() {
    int n;
    cin >> n;
    
    LCA d(n);
    for (int i = 0; i < n; i++) {
        int count;
        cin >> count;
        for (int j = 0; j < count; j++) {
            int to;
            cin >> to;
            d.addEdge(i, to, 1);
        }
    }
    d.init(0);
    //cout << "continue" << endl; 
    int q;
    cin >> q;
    //cout << "num of q " << q << endl;
    for (int i = 0; i < q; i++) {
        int u, v;
        cin >> u >> v;
        cout << d.lca(u, v) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 26964
#include <stdio.h>

int calcu(int, int);

int C = 0;
int S[10001];

int main()
{
  int i, n, q;
  int key; 

  scanf("%d",&n);

  for( i = 0 ; i < n ; i++ ) scanf("%d", &S[i]);
  
  scanf("%d",&q);
  
  for( i = 0 ; i < q ; i++ ){
    scanf("%d", &key);
    if( calcu(key, n) ) C++;;
  }
  
  printf("%d\n", C);
  
  return 0;
}
 
int calcu(int k, int n)
{
  int i=0;

  S[n] = k;
  while( S[i] != k ) i++;

  return  i != n;
}

Measured memory_bytes: 636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()
typedef long long ll;


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    set<int> st;
    rep(i, 1<<n){
        vector<int> use(n);
        rep(j,n) if (i>>j & 1) use[j] = 1;
        int sum = 0;
        rep(j,n) if (use[j]) sum+=a[j];
        st.insert(sum);
    }

    int q;
    cin >> q;
    rep(i,q){
        int m;
        cin >> m;
        if (st.find(m) == st.end()) cout << "no" << endl;
        else cout << "yes" << endl;
    }
}


Measured memory_bytes: 3112
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

vector<int> cards;
int n,r;

void f(int t){
	vector<int> a,b,c;
	int i;
	for(i=0;i<n;i++){
		if(i>=n/2)a.push_back(cards[i]);
		else b.push_back(cards[i]);
	}
	int j;
	for(i=0;i<n;i+=t){
		for(j=0;j<t&&i+j<a.size();j++){
			c.push_back(a[i+j]);
		}
		for(j=0;j<t&&i+j<b.size();j++){
			c.push_back(b[i+j]);
		}
	}
	cards=c;
}

int main() {
	while(cin>>n>>r){
		cards.clear();
		int i;
		for(i=0;i<n;i++){
			cards.push_back(i);
		}
//int j;
//for(j=0;j<n;j++){
//cout<<cards[j];
//}
//cout<<endl;
		for(i=0;i<r;i++){
			f(in());
//int j;
//for(j=0;j<n;j++){
//cout<<cards[j];
//}
//cout<<endl;
		}
		cout<<cards[n-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,M;
	cin >> N >> M;
	vector<ll> a(N),b(N+1);
	rep(i,N) cin >> a[i];
	b[0] = 0;
	for(int i=1;i<=N;i++)b[i] = b[i-1] + a[i-1];
	vector<ll> c(N+1);
	rep(i,N+1)c[i] = b[i]%M;
	sort(ALL(c));
	ll ans = 0;
	for(int i=0;i<=N;i++){
		ll cnt = 1;
		while(c[i] == c[i+1] && i+1 <=N){
			cnt++;
			i++;
		}
		ans += cnt*(cnt-1)/2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
#include <boost/multiprecision/cpp_int.hpp>
#endif

#define p std::pair
#define ll long long
#define ull unsigned long long
#define pi (acos(-1))
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
constexpr ll mod=1000000000+7;

int main()
{
	int n;
	string s;
	unordered_set<string> set;
	cin>>n;
	rep(i,n){
		cin>>s;set.insert(s);
	}
	cout<<set.size()<<endl;

	return 0;
}

ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}



Measured memory_bytes: 17644
a,b=map(int,input().split())
l=[]
for i in range(a,b+1):
  l.append(i)

def st(n):
  return str(n)

li=list(map(st,l))

ans=0
for j in li:
  if j[0]==j[-1] and j[1]==j[-2]:
    ans+=1
  else:
    pass

print(ans)

Measured memory_bytes: 12312
from bisect import bisect_left

N = int(input())
A = list(map(int,input().split()))

"""
方針
符号を変えられるのは偶数箇所
ソートしてどこまでが負の値かを調べる
境界のところで符号を変えるかは境界付近の値を見て決める
"""

A.sort()

ans,pt = 0,bisect_left(A,0)

if pt % 2 == 0:
    ans = sum(map(abs,A))
else:
    if pt == N:
        ans = sum(map(abs,A)) + 2*A[N-1]
    else:
        if A[pt-1] + A[pt] >= 0:
            ans = sum(map(abs,A)) + 2*A[pt-1]
        else:
            ans = sum(map(abs,A)) - 2*A[pt]

print(ans)


Measured memory_bytes: 14480
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<cassert>
using namespace std;

#define REP(i,a,b) for(i=a; i<b; ++i)
#define rep(i,n) REP(i,0,n)

int dx[8] = {0, 1, 0, -1, -1, -1, 1, 1};
int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
int n;

struct State{
    string mp;
    int turn,x,y;
    State(string mp,int turn,int x,int y) : mp(mp), turn(turn), x(x), y(y) {;}
};

pair<int,int> getPos(string mp) {
    int i,j;
    rep(i,mp.length()) if(mp[i] == '@') return make_pair(i/n,i%n);
}


string update(string &mp) {
    int i,j,k;
    string tmp = mp;

    rep(i,n) rep(j,n) {
        int adj = 0;
        if(mp.at(i*n+j) == '@') continue;
        rep(k,8) {
            if(i+dy[k] < 0 || i+dy[k] >= n) continue;
            if(j+dx[k] < 0 || j+dx[k] >= n) continue;
            if(mp.at((i+dy[k])*n+(j+dx[k])) == '#'
               || mp.at((i+dy[k])*n+(j+dx[k])) == '@') adj++;
        }
        if(mp.at(i*n+j) == '#') {
            if(adj == 2 || adj == 3) continue;
            else tmp.at(i*n+j) = '.';
        }else{
            if(adj == 3) tmp.at(i*n+j) = '#';
        }
    }
    return tmp;
}

int bfs(string bmap,int y,int x) {
    int i,j;
    queue<State> Q;
    set<string> memo;
    memo.insert(bmap);
    Q.push(State(bmap,0,x,y));
    while(!Q.empty()) {
        State now = Q.front();
        string nmap = now.mp;
        int ii = now.turn;
        Q.pop();

        if(nmap.find("#") == string::npos) return ii;

        for(int i=0; i<8; ++i) {
            if(now.y+dy[i] < 0 || now.y+dy[i] >= n) continue;
            if(now.x+dx[i] < 0 || now.x+dx[i] >= n) continue;
            if(nmap.at((now.y+dy[i])*n+(now.x+dx[i])) == '#') continue;
            string next = string(nmap);
            next.at((now.y+dy[i])*n+now.x+dx[i]) = '@';
            next.at((now.y)*n+now.x) = '.';
            next = update(next);
            if(memo.find(next) != memo.end()) continue;
            memo.insert(next);
            Q.push(State(next,ii+1,now.x+dx[i],now.y+dy[i]));
        }
    }
    return -1;
    assert(false);
}

int main() {
    while(cin>>n, n) {
        string imap = "",tmp;
        for(int i=0; i<n; ++i) {
            cin>>tmp;
            imap += tmp;
        }
        cout<<bfs(imap,getPos(imap).first,getPos(imap).second)<<endl;
    }
}

Measured memory_bytes: 3080
A,B = map(int,input().split(" "))
Ad = A
Bd = B

a = []
b = []
while Ad > 0:
    a.append(Ad%2)
    Ad //= 2

while Bd > 0:
    b.append(Bd%2)
    Bd //= 2

while len(a) < len(b):
    a.append(0)

a = ''.join(map(str,a))
b = ''.join(map(str,b))

r = []

for i in range(len(a)):
    if i == 0:
        r.append(
            ((B-A)//2+(A%2 or B%2))%2
        )
        continue
    if a[i::] == b[i::]:
        r.append(int(a[i]) and (B-A+1)%2)
        continue
    s = 0
    if a[i] == '1':
        s += A % 2
    if b[i] == '1':
        s += B % 2 + 1
    r.append(s%2)

s = 0
for i in range(len(a)):
    s += r[i] * (2**i)

print(s)


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

#define pb push_back
#define ll long long int
#define mpi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define si set<int>
#define pii pair<int, int>
#define vpi vector<pii>
#define vs vector<string>
#define pri priority_queue<int>
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define For(i, n) for (int i = 0; i < n; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define Rep(i, x, y) for (int i = x; i <= y; i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

double tick()
{
    static clock_t oldt, newt = clock();
    double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
    oldt = newt;
    return diff;
}

ll fastExpo(ll a, ll n)
{
    ll res = 1;
    while (n)
    {
        if (n % 2)
            res = res * a;
        n /= 2;
        a = a * a;
    }
    return res;
}

int main()
{
    long double a, b;
    cin >> a >> b;
    ll res = floor((long double)a * b);

    cout << res << endl;
    cerr << "execution time is: " << tick() << "\n";
}


Measured memory_bytes: 3776
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;

int n,m,k,a[10][10],b[10][10],ans=0,z=0;
char c[10][10];

int cal(int x,int y)
{
	int s=0,t=1;
	for(int i=1;i<=x+y;++i)
	  {
	  	  s+=t;
	  	  t*=2;
	  }
	return s;  
}

int main()
{
	cin>>n>>m>>k;
	int s=cal(n,m);
	for(int i=1;i<=n;++i)
	  for(int j=1;j<=m;++j)
	  {
	  	  cin>>c[i][j];
	  	  if(c[i][j]=='.') a[i][j]=0;
	  	    else a[i][j]=1;
	  }
	for(int z=0;z<=s;++z)
	  {
	  	  for(int i=1;i<=n;++i)
	  	    for(int j=1;j<=m;++j)
	  	      b[i][j]=a[i][j];
	  	  int g=z;    
	  	  for(int i=1;i<=n;++i)
			{
				if(g%2==1)
				{
					for(int j=1;j<=m;++j)
					  b[i][j]=0;
				}
				g/=2; 
			}     
		  for(int i=1;i<=m;++i)
		    {
		    	if(g%2==1)
		    	{
		    		for(int j=1;j<=n;++j)
		    		  b[j][i]=0;
		    	}
		    	g/=2; 
		    }	
		  //if(z==8) cout<<g<<endl;  
		  int sum=0;
		  for(int i=1;i<=n;++i)
	  	    for(int j=1;j<=m;++j)
	  	      sum+=b[i][j];
		  if(sum==k) 
		  {
		  	  ans++;
		  	  /*if(z==8)
		  	  {
		  	  	for(int i=1;i<=n;++i)
	  	        {
	  	        	for(int j=1;j<=m;++j)
	  	        	  cout<<b[i][j];
	  	        	cout<<endl;  
	  	        }
	  	      cout<<z<<endl;  
		  	  }*/
		  }
		  
	  }
	cout<<ans<<endl;
}




Measured memory_bytes: 3640
import bisect
N = int(input())
L = [int(i) for i in input().split()]
L.sort()
count = 0
for a in range(N-2):
    for b in range(a+1, N-1):
        count += bisect.bisect_left(L, L[a]+L[b])-b-1
print(count)

Measured memory_bytes: 3188
#include <iostream>
#define N_MAX 100000
using namespace std;
int main(){
  int N;
  long long A[N_MAX]={0},Asum=0,Atmp=0;
  long long x[N_MAX]={0};
  cin >> N;
  for(int i=1;i<=N;i++){
    cin >>A[i];
    Asum+=A[i];
    if(i%2==0)
      Atmp+=A[i];
  }
  x[1]=Asum/2-Atmp;
  for(int i=1;i<N;i++){
    x[i+1]=A[i]-x[i];
  }
  for(int i=1;i<N;i++){
    cout << 2*x[i] << " ";
  }
  cout << 2*x[N] << endl;
  return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    int n;
    int tmp;
    vector<double> a;
    
    double sum = 0.0;
    
    cin >> n;
    while(cin >> tmp){
        a.push_back((double)tmp);
    }
    
    for(int i=0;i<n;i++){
        sum += 1.0/a[i];
    }
    
    cout << 1.0/sum << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>

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

int sat[100];
int F[100][100];
bool used[100];
vector<P> G[100]; //to, f
int N,M;
vector<array<int, 3>> E;

int greedy(int ret){
    int n = 2;
    while(true){
        int best_v=-1, best_score=ret, best_s=0;
        for(int i=0;i<N;i++){
            int cnt=0,s=10000000;
            int score=0;
            if(used[i]) continue;
            for(auto e:G[i]){
                int to = e.first, f = e.second;
                if(!used[to]) continue;
                cnt++;
                score += min(sat[to], f);
                s = min(f,s);                
            }
            if(cnt!=n) s=0;
            score += s;
            if(score>best_score){
                best_v = i;
                best_score = score;
                best_s = s;
            }
        }
        if(best_v==-1){
            return ret;
        }else{
            n++;
            ret = best_score;
            used[best_v]=true;
            for(int i=0;i<N;i++){
                if(!used[i]||i==best_v) continue;
                sat[i]=min(sat[i],F[best_v][i]);
            }
            sat[best_v]=best_s;
        }
    }
    return -1;
}

int main(){
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        G[a].emplace_back(b,c);
        G[b].emplace_back(a,c);
        F[a][b]=F[b][a]=c;
        E.push_back(array<int, 3>{a,b,c});
    }
    int ans=0;
    for(auto e:E){
        fill(used,used+100,false);
        fill(sat,sat+100,0);
        used[e[0]]=used[e[1]]=true;
        sat[e[0]]=sat[e[1]]=e[2];
        
        ans = max(ans,greedy(2*e[2]));
    }
    cout<<ans<<endl;
    return 0;
}

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

using lli = int64_t;
using vi = vector<lli>;

int main()
{
    ios_base::sync_with_stdio(0);

    string s; cin >> s;

    int n = s.size();

    vi v(26);

    lli ans = 1;

    for(int i = 0; i < n; i++)
    {
        int x = s[i] - 'a';

        for(int j = 0; j < 26; j++) ans += v[j] * (x != j);

        v[x]++;
    }

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

Measured memory_bytes: 720
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

int H,W;
string A[200];
int freq[26];

int main(void){
    cin>>H>>W;
    REP(i,H)
        cin>>A[i];
    REP(i,H)
        REP(j,W)
        freq[A[i][j]-'a']++;
    if(H%2==0&&W%2==0){
        REP(i,26)
            if(freq[i]%4!=0){
                cout<<"No"<<endl;
                return 0;
            }
        cout<<"Yes"<<endl;
        return 0;
    }else if((H%2==0&&W%2==1)||(H%2==1&&W%2==0)){
        if(H%2==0)
            swap(H,W);
        int R=W;
        REP(i,26){
            if(freq[i]%4==2)
                R-=2;
            else if(freq[i]%4!=0){
                cout<<"No"<<endl;
                return 0;
            }
        }
        if(0<=R&&R%4==0){
            cout<<"Yes"<<endl;
            return 0;
        }else{
            cout<<"No"<<endl;
            return 0;
        }
    }else{
        int center=1;
        int R=H-1+W-1;
        REP(i,26){
            if(freq[i]%4==2)
                R-=2;
            else if(freq[i]%4==1)
                center-=1;
            else if(freq[i]%4==3){
                cout<<"No"<<endl;
                return 0;
            }
        }
        if(center==0&&0<=R&&R%4==0){
            cout<<"Yes"<<endl;
            return 0;
        }else{
            cout<<"No"<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())

tot = 0
for i in range(1, N+1):
    q = i
    s = 0
    while q > 0:
        q, r = divmod(q, 10) #;print(i, q, r, s)
        s += r       
    if A<= s <=B:        
        tot += i #;print(i)
        
print(tot)

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();
		int X = x2 - x1;
		int Y = y2 - y1;
		System.out.println((x2 - Y) + " " + (y2 + X) + " " + (x1 - Y) + " " + (y1 + X));
	}
}


Measured memory_bytes: 27072
// C - Digits in Multiplication
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int len_digits(ll n){
	int c = 0;
	while(n>0){ n /= 10; c++; }
	return c;
}

int main(){
	ll N; cin>>N;
	int ans = 11;
	ll s = sqrt(N);
	for(ll a=1; a<=s; a++)
		if(N%a==0) ans = min(ans, len_digits(max(a, N/a)));
	cout<< ans <<endl;
}

Measured memory_bytes: 256
a, b = map(int, raw_input().split())
print 100, 100
a -= 1
b -= 1
d = [list('#' * 100) for i in xrange(50)] + [list('.' * 100) for i in xrange(50)]
for i in xrange(a):
    x, y = divmod(i, 49)
    d[x*2+1][y*2+1] = '.'
for i in xrange(b):
    x, y = divmod(i, 49)
    d[x*2+51][y*2+1] = '#'
for r in d:
    print ''.join(r)


Measured memory_bytes: 2692
#include <stdio.h>
#define MAX 100
int main()
{
  int i,j,k=0,a,l,mini;
  int A[MAX];

  scanf("%d",&l);
  for(i=0;i<l;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<l;i++){
    mini=i;
    for(j=i;j<l;j++){
      if(A[j]<A[mini]){
        mini=j;
      }
    }
    if(i!=mini){
      k++;
    }
    a=A[mini];
    A[mini]=A[i];
    A[i]=a;
    printf("%d",A[i]);
    if(i!=l-1){
      printf(" ");
    }
  }
  printf("\n%d\n",k);
  return 0;
}

Measured memory_bytes: 604
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val s = sc.next()
    var count = 0
    s.forEachIndexed { index, c ->
        if (index > 1 && c == 'C' && s[index - 1] == 'B' && s[index - 2] == 'A') {
            count++
        }
    }
    println(count)
}

Measured memory_bytes: 31260
from collections import deque
n=int(input())
table=[-1]*100001
table[0]=0
d=deque()
d.append(0)
can=[]
can.append(1)
for i in range(1,50):
    if 6**i<=100000:
        can.append(6**i)
    else:
        break
    if 9**i<=100000:
        can.append(9**i)
while d:
    w=d.popleft()
    for i in can:
        if w+i>100000:
            continue
        if not table[w+i]==-1:
            continue
        table[w+i]=table[w]+1
        d.append(w+i)
print(table[n])

Measured memory_bytes: 10832
#include<stdio.h>
#define S 100000
int main(void){
  int N,K,c=0,sum=1;
  int A[S]={0};
  scanf("%d %d",&N,&K);
  for(int i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  while(sum<N){
    sum+=K-1;
    c++;
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 512
using System;
class ProgramB
    {
        static void Main(string[] args)
        {
            
            //入力
            string[] input = Console.ReadLine().Split(' ');
            long h = long.Parse(input[0]);
            long w = long.Parse(input[1]);

            //hかwが1のときは移動できない
            if(h == 1 || w == 1)
            {
                Console.WriteLine("1");
                return;
            }

            //両方奇数のときは足し合わせる
            if(h % 2 == 1 && w % 2 == 1)
                Console.WriteLine(h*w /2 + 1);
            else
                Console.WriteLine(h*w /2);
    
        }
    }

Measured memory_bytes: 13012