akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	vector<pair<int, int> > coords(n);
	for(int i = 0; i < n; i++)
		scanf("%d%d", &coords[i].first, &coords[i].second);
	vector<int> town(n);
	for(int i = 0; i < n; i++)
		town[i] = i;
	double sum = 0;
	int num = 0;
	do {
		for(int i = 1; i < n; i++) {
			sum += sqrt(pow(coords[town[i]].first - coords[town[i-1]].first, 2) + pow(coords[town[i]].second - coords[town[i-1]].second, 2));
		}
		num++;
	} while(next_permutation(town.begin(), town.end()));
	printf("%.12lf\n", sum / num);
}


Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 01.01.2020 20:17:49       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) {
    cout << "No" << '\n';
    return 0;
  }
  cout << "Yes" << '\n';
  vector<int> a(2 * n - 1);
  a[n - 1] = x;
  a[n - 2] = x - 1;
  a[n] = x + 1;
  int ptr = 0;
  for (int i = 2 * n - 1; i >= 1; i--) {
    if (abs(i - x) <= 1) {
      continue;
    }
    while (ptr >= n - 2 && ptr <= n) {
      ++ptr;
    }
    a[ptr++] = i;
  }
  for (int i = 0; i < 2 * n - 1; i++) {
    cout << a[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 2304
import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		try{
			while(scan.hasNextLine()) {
				String str1=scan.nextLine();
				String str2=scan.nextLine();
				str1=str1+str1;
				int result=str1.indexOf(str2);
				if(result!=-1) {
					System.out.println("Yes");
				}
				else{
					System.out.println("No");
				}
			}
			scan.close();
		}catch(InputMismatchException e){
			System.out.println("入力しなおしてください");
		}
		}
}


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

#define N_MAX 1000000
#define M_MAX 100

int count = 0;

int
insertion_sort(int *a, int n, int g)
{
	int i, j, v;

	if (g == 0)
		return 1;

	for (i = g; i < n; i++) {
		v = a[i];
		j = i - g;
		while (0 <= j && v < a[j]) {
			a[j + g] = a[j];
			j -= g;
			count++;
		}
		a[j + g] = v;
	}
	return 0;
}

int
shell_sort(int *a, int n, int m, int *g)
{
	int i;
	count = 0;

	for (i = m - 1; i >= 0; i--)
		insertion_sort(a, n, g[i]);
}

int
main(int argc, char **argv)
{
	int p0, n = 0, m, i;
	int *a;
	int g[M_MAX];

	scanf("%d", &p0);

	if (p0 < 1 || N_MAX < p0)
		return 1;

	a = (int *)malloc(sizeof(int) * p0);
	if (a == NULL)
		return 1;

	for (n = 0; n < p0; n++)
		scanf("%d", a + n);

	m = 1;
	g[0] = 1;
	while ((1 << (m * 2)) < (n / 2)) {
		g[m] = (1 << (m * 2)) - 1;
		m++;
	}

	printf("%d\n%d", m, g[m - 1]);
	for (i = m - 2; i >= 0; i--)
		printf(" %d", g[i]);
	printf("\n");

	shell_sort(a, n, m, g);
	printf("%d\n", count);
	if (argc < 2) {
		for (i = 0; i < n; i++)
			printf("%d\n", a[i]);
	}

	return 0;
}



Measured memory_bytes: 5628
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args)throws IOException {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0){break;}
			run(n,n,"");
		}
	}

	static void run(int n, int limit, String ans){
		for(int i=limit;i>0; i--){
			if(n == i){
				System.out.println(ans+i);
			}else{
				run(n-i,(n-i)<i ? n-i:i,ans+i+" ");
			}
		}
	}
}

Measured memory_bytes: 47668
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> a(n-1);
	vector<int> buka(n);
	for(int i=0;i<n-1;i++)cin>>a.at(i);
	sort(a.begin(),a.end());
	for(int i=0;i<n-1;i++){
				buka.at(a.at(i)-1)++;
			/*while(a.at(j)==a.at(j+1)){
				sum++;
				j++;
			}

			i=j;
			sum++;
			buka.at((a.at(i)-1))=sum;
			sum=0;
			j=0; */
	}
	for(int i=0;i<n;i++)cout<<buka.at(i)<<endl;
}


Measured memory_bytes: 4844
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


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 V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

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

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑





string a, b;
int main() {
	while (cin >> a) {
		cin >> b;
		int dp[4005][4005], ans = 0;
		for (int i = 0; i < a.length(); ++i) {
			for (int j = 0; j < b.length(); ++j) {
				if (a[i] == b[j]) { dp[i + 1][j + 1] = dp[i][j] + 1; }
				else { dp[i + 1][j + 1] = 0; }
				ans = max(ans, dp[i + 1][j + 1]);
			}
		}

		cout << ans << endl;
	}
}


Measured memory_bytes: 65692
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
def bingo(a, b, c):
    if a[0] == b[0] == c[0]:
        return True
    if a[1] == b[1] == c[1]:
        return True
    if a[2] == b[2] == c[2]:
        return True
    if a[0] == a[1] == a[2]:
        return True
    if b[0] == b[1] == b[2]:
        return True
    if c[0] == c[1] == c[2]:
        return True
    if a[0] == b[1] == c[2]:
        return True
    if a[2] == b[1] == c[0]:
        return True
    return False

l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
n = int(input())
ans = "No"
for i in range(n):
    b = int(input())
    for j in range(3):
        if l1[j] == b:
            l1[j] = 0
        if l2[j] == b:
            l2[j] = 0
        if l3[j] == b:
            l3[j] = 0
    if (bingo(l1,l2,l3)):
         ans = "Yes"

print(ans)




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

signed main()
{
    string S;
    int month[2][13] = { { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
                         { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } };

    while ( cin >> S, S != "#" ) {

        int period = 0;
        for ( int i = 0; i < S.size(); i++) {
            if ( S[i] == '.' ) {
                period++;
            }
        }

        if ( period == 4 ) {
            int a, b, c, d, e;

            int cnt = 0;
            sscanf(S.c_str(), "%lld.%lld.%lld.%lld.%lld", &a, &b, &c, &d, &e);
            cnt = e + d * 20 + c * 360 + b * 7200 + a * 144000;

            a = 2012, b = 12, c = 21;
            for ( int i = 0; i < cnt; i++ ) {
                c++;
                bool isUru = (a % 400 == 0 || a % 100 != 0 && a % 4 == 0);
                int uru;
                if ( isUru ) {
                    uru = 1;
                } else {
                    uru = 0;
                }
                if ( month[uru][b] < c ) {
                    c = 1;
                    b++;
                    if ( b > 12 ) {
                        b = 1;
                        a++;
                    }
                }
            }
            cout << a << "." << b << "." << c << endl;
        } else {
            int a,b,c;
            sscanf(S.c_str(), "%lld.%lld.%lld", &a,&b,&c);
            int cnt = 11 + (a - 2013) * 365;
            if ( a == 2012 ) cnt--;
            for(int i=2013;i<a;i++){
                if(i%400==0||(i%100!=0&&i%4==0)){
                    cnt++;
                }
            }
            int bb = 1, cc = 1;
            while ( bb != b || cc != c ) {
                cc++;
                bool isUru = (a % 400 == 0 || a % 100 != 0 && a % 4 == 0 );
                int uru;

                if ( isUru ) uru = 1;
                else uru = 0;

                if ( cc > month[uru][bb] ) {
                    cc = 1;
                    bb++;
                }
                cnt++;
            }
            cout << (cnt / 144000) % 13 << "." << (cnt / 7200) % 20 << "." << (cnt / 360) % 20 << "." << (cnt / 20) % 18 << "." << cnt % 20 << endl;
        }

    }
}



Measured memory_bytes: 3244
import java.util.Scanner;

public class Main
{
    public static void main(String[] args) 
    {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        
        System.out.println( a*b + " " + (a*2 + b*2));
        
        
        return;
    }
}


Measured memory_bytes: 25804
package main

import "fmt"

type extent struct {
	l int
	r int
}

func main() {
	var (
		n, q int
		s    string
	)
	fmt.Scan(&n, &q, &s)

	sliceExtent := make([]extent, q)
	for i := range sliceExtent {
		fmt.Scan(&sliceExtent[i].l, &sliceExtent[i].r)
	}

	solve(sliceExtent, s)
}

func solve(sliceExtent []extent, s string) {
	sliceCumsum := make([]int, len(s)) // 累積和

	cumsum := 0
	for i := 1; i < len(sliceCumsum); i++ {
		if s[i-1] == 'A' {
			if s[i] == 'C' {
				cumsum++
			}
		}
		sliceCumsum[i] = cumsum
	}

	for _, e := range sliceExtent {
		countAC := sliceCumsum[e.r-1] - sliceCumsum[e.l-1]
		fmt.Println(countAC)
	}
}


Measured memory_bytes: 5632
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		vector<int>in(n+1);
		rep(i,n)cin>>in[i+1];
		n++;
		loop(i,1,n)in[i]+=in[i-1];
		int ma=-1e9;
		rep(i,n)loop(j,i+1,n)ma=max(ma,in[j]-in[i]);
		cout<<ma<<endl;
	}
}

Measured memory_bytes: 1204
import java.util.Scanner;

class Solver {
    void solve(Scanner sc) {
        int N = sc.nextInt();
        int mod2 = 0;
        int mod4 = 0;
        for (int i = 0; i < N; i++) {
            int n = sc.nextInt();
            if (n % 4 == 0) mod4++;
            else if (n % 2 == 0) mod2++;
        }
        if (mod4 >= N / 2 || mod4 >= (N - (mod2 & ~1)) / 2) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

class Main {
    public static void main(String... args) {
        Scanner in = new Scanner(System.in);

        new Solver().solve(in);

        in.close();
    }
}

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

public class Main {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null; }
        String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try { tokenizer = new StringTokenizer(reader.readLine()); } 
                catch (IOException e) { throw new RuntimeException(e);} }
            return tokenizer.nextToken(); }
        public int nextInt() { return Integer.parseInt(next()); }
        public long nextLong() { return Long.parseLong(next()); }
        public double nextDouble() { return Double.parseDouble(next()); }
    }

    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        
        String s = r.next();
        String t = r.next();
        int ans = 0;
        for(int i = 0; i < 3; i++){
            if(s.charAt(i) == t.charAt(i)){
                ans++;
            }
        }
        pw.println(ans);
        pw.close();
    }
}

/**
                _        _                 _                                                
               | |      | |               | |                                               
   ___ ___   __| | ___  | |__  _   _    __| | __ _ _ __ _ __ ___ _ __     _   _  __ _  ___  
  / __/ _ \ / _` |/ _ \ | '_ \| | | |  / _` |/ _` | '__| '__/ _ \ '_ \   | | | |/ _` |/ _ \ 
 | (_| (_) | (_| |  __/ | |_) | |_| | | (_| | (_| | |  | | |  __/ | | |  | |_| | (_| | (_) |
  \___\___/ \__,_|\___| |_.__/ \__, |  \__,_|\__,_|_|  |_|  \___|_| |_|   \__, |\__,_|\___/ 
                                __/ |                               ______ __/ |            
                               |___/                               |______|___/             
 */

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
int main() {
	string a;
	cin>>a;
	string b=a;
	reverse(a.begin(),a.end());
	int len=a.size();
	for(int i=1;i<=len;i++) {
		if(b[i]=='b') {
			b[i]='d';
		}
		else if(b[i]=='d') {
			b[i]='b';
		}
		else if(b[i]=='q') {
			b[i]='p';
		}
		else if(b[i]=='p') {
			b[i]='q';
		}
	}
	for(int i=1;i<=len;i++) {
		if(b[i]==a[i])
		{
			continue;
		}
		else
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int L = A + B,
  	  R = C + D;
  if (L > R) {
    cout << "Left" << endl;
  } else if (L < R) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}

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

int main() {
	int n;
	cin >> n;
	vector<int>a(3*n,-1);
	vector<int>b(100005, 0);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		a[n + i] = a[i] + 1;
		if (a[i] == 0)continue;
		a[2*n + i] = a[i] - 1;
	}
	for (int i = 0; i < a.size(); ++i) {
		if (a[i] == -1)continue;
		++b[a[i]];
	}
	sort(b.begin(), b.end());
	cout << b[b.size()-1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
using namespace std;

int main(){
  
  long int A, B, C;
  scanf("%ld", &A);
  scanf("%ld", &B);
  scanf("%ld", &C);
  
  if(C-1 <= A+B){
    // if Takahashi-kun can eat all poisnous cookies
    printf("%d", B+C);
  }
  else{
    // if Takahashi-kun cannot eat all poisnous cookies
    printf("%d", B + (A+B+1));
  }
  
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int ikodoko[26][100011];
int main(){
	string s,t;
	scan(s>>t);
	int N=s.size();
	rep(j,26) ikodoko[j][N]=-1;
	for(int i=N-1;i>=0;i--){
		ikodoko[s[i]-'a'][i]=i;
		rep(j,26){
			if(j==s[i]-'a') continue;
			ikodoko[j][i]=ikodoko[j][i+1];
		}
	}
	int T=t.size();
	int flag=1;
	ll retunum=0;
	ll now=0;
	rep(i,T){
		if(ikodoko[t[i]-'a'][0]==-1){
			flag=0;
			break;
		}
		else if(ikodoko[t[i]-'a'][now]==-1){
			retunum++;
			now=0;
		}
		now=ikodoko[t[i]-'a'][now]+1;
	}
	if(flag) prin(retunum*N+now);
	else prin(-1);
	return 0;
}


Measured memory_bytes: 10752
n  = int(input())

d = {}
for _ in range(n):
    string = "".join(sorted(list(input())))
    if string not in d:
        d[string] = 1
    else:
        d[string] += 1

ans = 0
for v in d.values():
    ans += v*(v-1)//2

print(ans)




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

"""
・参考：http://arc060.contest.atcoder.jp/data/arc/060/editorial.pdf
　　　　https://www.youtube.com/watch?v=LzxPxJ-cSHk
・b <= √nは愚直に当たっていく。
・b > √nは、b^2 > nなので、b進数で2桁以下になる。
　例) 10^2は10進数で100、100 > n → nは99以下
　その2桁の数字はn = p*b + qと表せる。
　例) 67 = 6*10 + 7
　今回の問題の条件から、s = p + q
　n = p*b + q
　s = p + q
　上記2つの式から、連立方程式でqを消すと、
　n-s = p*b - p
　と表せる。
　pはb以上なら桁が上がってしまうので p < b
　p < b から p*p < p*b なので、p*b > p^2
　よって、n = p*b + q >= p*b > p^2
　n > p^2 なので、√n > p
　つまりpについて√nまでを全探索すればOK。
　n-s = p*b - p をbについての形に変形すればbが出せる。
　b = (n-s)/p + 1
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n // b) + n % b

n = INT()
s = INT()

if s > n:
    print(-1)
elif s == n:
    print(n+1)
elif ceil(n/2) < s < n:
    print(-1)
else:
    # b <= √n の全探索
    for b in range(2, int(sqrt(n))+2):
        if f(b, n) == s:
            print(b)
            exit()
    # b > √n について、式を元に探す
    # pが大きい程bが小さいので、このループは逆順で回す
    for p in range(int(sqrt(n))+2, 0, -1):
        # 整数にならないものは除外
        if (n-s)%p: continue
        b = (n-s)//p + 1
        if f(b, n) == s:
            print(b)
            exit()
    # 見つからなかった
    print(-1)


Measured memory_bytes: 5204
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2000+10,inf=0x3f3f3f3f;
int a[maxn];
bitset<maxn*maxn> f;
int main(){
	int n=read(),num=0,ans=inf,sum=0;
	REP(i,1,n) a[i]=read(),sum+=a[i];
	sort(a+1,a+n+1);
	num=(sum+1)/2;
	f[0]=1;
	REP(i,1,n)
		f|=f<<a[i];
	REP(i,num,sum){
		if(f[i]==1){
			printf("%d\n",i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1792
N = int(input())

def getDivisors(x):
    anss = set()
    for d in range(1, int(x**0.5)+1):
        if x%d == 0:
            anss.add(d)
            anss.add(x//d)
    return sorted(anss)

divs = getDivisors(N)

ans = N
for div in divs:
    k = N//div
    ans = min(ans, div+k-2)

print(ans)


Measured memory_bytes: 3828
from bisect import bisect_left
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    A, B, Q = map(int, input().split())
    S = [int(input()) for _ in range(A)]
    T = [int(input()) for _ in range(B)]

    ans = []
    for _ in range(Q):
        x = int(input())

        i = bisect_left(S, x)
        if i == 0:
            s_left = None
        else:
            s_left = S[i - 1]
        if i < A:
            s_right = S[i]
        else:
            s_right = None

        j = bisect_left(T, x)
        if j == 0:
            t_left = None
        else:
            t_left = T[j - 1]

        if j < B:
            t_right = T[j]
        else:
            t_right = None

        # 左にいきっぱなし
        if s_left is not None and t_left is not None:
            ans1 = x - min(s_left, t_left)
        else:
            ans1 = INF

        # みぎにいきっぱなし
        if s_right is not None and t_right is not None:
            ans2 = max(s_right, t_right) - x
        else:
            ans2 = INF

        # 右神社 左寺
        if s_right is not None and t_left is not None:
            ans3 = min(s_right - x + s_right - t_left, x - t_left + s_right - t_left)
        else:
            ans3 = INF

        # 右寺，左神社
        if t_right is not None and s_left is not None:
            ans4 = min(t_right - x + t_right - s_left, x - s_left + t_right - s_left)
        else:
            ans4 = INF

        a = min(ans1, ans2, ans3, ans4)
        ans.append(a)

    for a in ans:
        print(a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 16092
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, A, B;

	cin >> N;
	if (N == 1)
	{
		cout << "Hello World" << endl;
	}
	else
	{
		cin >> A >> B;
		cout << A + B << endl;
	}

	return 0;
}

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

#define count_ones __builtin_popcountl
#define all(a) a.begin(), a.end()
#define gcd(a, b) __gcd(a, b)
#define lca(a, b) a / __gcd(a, b) * b
typedef long long ll;
typedef long long ld;
using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    cout << max(0, a - 2 * b);

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            int[] input;
            while(((input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray())[0] | input[1]) != 0) {
                Console.WriteLine(new String('#', input[1]));
                for(int i = 0; i < input[0] - 2; ++i){
                    Console.WriteLine("#{0}#", new String('.', input[1] - 2));
                }
                Console.WriteLine(new String('#', input[1]));
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 5912
(defun read-list(N &optional (l nil))
  (if (<= N 0) l (read-list  (1- N) (cons (read) l))))

(princ (if (remove-if
	    (lambda (x) (or (/= (mod x 2) 0) (= (mod x 3) 0) (= (mod x 5) 0)))
	    (read-list (read)))
	   "DENIED" "APPROVED"))

Measured memory_bytes: 8036
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        if (a % 2 == 0) {
            System.out.println(a);
        } else {
            System.out.println(a * 2);
        }
    }
}


Measured memory_bytes: 21716
//In the Name of God
//Let Our Voices Echo
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define X real()
#define Y imag()
typedef long long ll;
typedef double ld; 
typedef complex<ld> point;
const ld eps=1e-9;
const int MAX=809,MOD=1e9+7;
int h,w,k,x,y,dis[MAX][MAX];
char ch[MAX][MAX];
queue<pair<int,int> > q;
int dx[]={0,+1,0,-1},dy[]={+1,0,-1,0};
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	memset(dis,-1,sizeof dis);
	cin>>h>>w>>k;
	for (int i=0;i<h;i++)
		for (int j=0;j<w;j++)
		{
			cin>>ch[i][j];
			if (ch[i][j]=='S') 
				x=i,y=j,ch[i][j]='.';
		}
	q.push({x,y});
	dis[x][y]=0;
	while (q.size())
	{
		int x=q.front().first,y=q.front().second;
		q.pop();
		if (dis[x][y]==k) continue;
		for (int i=0;i<4;i++)
		{
			int xx=x+dx[i],yy=y+dy[i];
			if (xx<0 || xx>=h || yy>=w || yy<0 || ch[xx][yy]=='#') continue;
			if (dis[xx][yy]==-1)
				dis[xx][yy]=dis[x][y]+1,q.push({xx,yy});
		}
	}
	int ans=1e9;
	for (int i=0;i<h;i++)
		for (int j=0;j<w;j++)
			if (dis[i][j]!=-1)
			{
				int d=min({i,h-i-1,j,w-j-1});
				if (d==0) ans=1;
				ans=min(ans,(d+k-1)/k+1);
			}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  ll xmin = x[4];
  rep(i,4) xmin = min(xmin,x[i]);

  cout << (n+xmin-1)/xmin + 4 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int x;
	int n;
	
	n = 1;
	
	while (1){
		scanf("%d", &x);
		
		if (x == 0){
			break;
		}
		
		printf("Case %d: %d\n", n, x);
		
		n++;
	}
	
	return (0);
}

Measured memory_bytes: 600
#!/usr/bin/env python3

import math

n = int(input())

result = [0] * (n + 1)
border = 0
if n>=3:
    border = int(math.sqrt(n - 2))
for x in range(1, border):
    for y in range(1, border):
        for z in range(1, border):
            r = ((x + y) ** 2 + (y + z) ** 2 + (z + x) ** 2) // 2
            if r > n:
                break
            else:
                result[r] += 1

for num in result[1::]:
    print(num)

Measured memory_bytes: 9116
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<numeric>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl

#define rep(i,n) for(int i = 0; i < (n);++i)
#define repc(i,a,b) for(int i = (a);i <(b);++i)
#define repa(n,array) for(auto n :(array))

typedef long long ll ;
typedef vector<int> vi ;
typedef vector<ll> vl ;

constexpr int IMAX = ((1<<30)-1)*2+1 ;
constexpr int INF = 100000000;
double EPS = 1e-10 ;

template <typename T>
T out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
  return 0 ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double v1,v2,l1 = 0,l2,ans;
  char c;
  vi v(10,0) ;
  while(cin >> v[0] >> c){
    l1 = 0;
    repc(i,1,10){
      cin >> v[i] >> c;
    }
    cin >> v1 >> c>>v2;
    l2 = accumulate(all(v),0) * 1000 ;
    v1 = v1/3600 * 1000;
    v2 = v2/3600 * 1000;
    while(l1<=l2){
      l1 += v1 ;
      l2 -= v2 ;
    }
    //debug(l1) ;
    //debug(l2) ;
    ans = 0 ;
    rep(i,10){
      ans += v[i] * 1000;
      //debug(ans) ;
      if((int)l1 == (int)ans){
        //debug(ans) ;
        ans = i + 1;
        break ;
      }
      else if(l1 < ans){
        //debug(ans) ;
        ans = i + 1 ;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

struct STX {
    int s, t, x;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int n, q;
    cin >> n >> q;
    vector<STX> stx(n);
    rep(i, n) cin >> stx[i].s >> stx[i].t >> stx[i].x;
    sort(all(stx), [](const STX &a, const STX &b) { return a.x < b.x; });
    vector<int> ans(q, -1);
    set<pair<int, int>> p;
    rep(i, q) {
        int d;
        cin >> d;
        p.insert(make_pair(d, i));
    }
    rep(i, n) {
        int s = stx[i].s - stx[i].x;
        int t = stx[i].t - stx[i].x;
        int x = stx[i].x;
        auto itr = p.lower_bound(make_pair(s, -1));
        while(itr != p.end()) {
            if (itr->first >= t) break;
            ans[itr->second] = x;
            p.erase(itr++);
        }
    }
    rep(i, q) cout << ans[i] << endl;
    return 0;
}


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

int main()
{
	int n; cin >> n;
	int a[3*n];
	for (int i = 0; i < 3*n; ++i)
		cin >> a[i];
	sort(a, a+3*n);
	ll ans = 0;
	for (int i = 3*n-2; i > n-1; i -= 2) ans += a[i];
	cout << ans << endl;
}



Measured memory_bytes: 4816
#include<stdio.h>
#define INF 10000000

int main(){
  int n,p[101],m[101][101];
  int i,j,k,l,q;

  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d%d",&p[i-1],&p[i]);

  for(i=1;i<=n;i++) m[i][i] = 0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k=i;k<j;k++){
	q = m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	m[i][j] = (m[i][j]>q) ? q : m[i][j];
      }
    }
  }

  printf("%d\n",m[1][n]);

  return 0;
}



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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end();
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

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

  int A, B;
  CIN(A >> B);

  if (A == 1 && B == 2)
    COUT(3);
  if (A == 1 && B == 3)
    COUT(2);

  if (A == 2 && B == 1)
    COUT(3);
  if (A == 2 && B == 3)
    COUT(1);

  if (A == 3 && B == 1)
    COUT(2);
  if (A == 3 && B == 2)
    COUT(1);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmax(a,b) a=max(a,b);
#define chmin(a,b) a=min(a,b);
class Segtree{
	
	private:
	int V;
	typedef struct st{
		ll a;
	}st;
	st st0=(st){(ll)1e18};
	typedef struct op{
		ll a;
	}op;
	op op0=(op){-1};
	st f(st p,st q){
		return (st){min(p.a,q.a)};
	}
	void g(st &p,op q){
		if(q.a==-1)return;
		p.a=q.a;
	}
	void h(op &p,op q){
		if(q.a==-1)return;
		p.a=q.a;
	}
	
	st *dat;
	op *laz;
	
	st propagate(ll k){
		if(k<V){
			h(laz[k*2],laz[k]);
			h(laz[k*2+1],laz[k]);
		}
		g(dat[k],laz[k]);
		laz[k]=op0;
		return dat[k];
	}
	void upd(ll l,ll r,op p){
		l+=V,r+=V+1;
		for(ll d=20;d>=0;d--){
			propagate(l>>d);
			propagate(r>>d);
		}
		for(ll a=l,b=r;a<b;a>>=1,b>>=1){
			if(a&1){h(laz[a],p);a++;}
			if(b&1){b--;h(laz[b],p);}
		}
		for(ll a=l,b=r;a+b;a>>=1,b>>=1){
			dat[a/2]=f(propagate(a/2*2),propagate(a/2*2+1));
			dat[b/2]=f(propagate(b/2*2),propagate(b/2*2+1));
		}
	}
	st qry(ll l,ll r){
		l+=V,r+=V+1;
		for(ll d=20;d>=0;d--){
			propagate(l>>d);
			propagate(r>>d);
		}
		st L=st0,R=st0;
		for(ll a=l,b=r;a<b;a>>=1,b>>=1){
			if(a&1){L=f(L,propagate(a));a++;}
			if(b&1){b--;R=f(propagate(b),R);}
		}
		st res=f(L,R);
		return res;
	}
	
	public:
	void init(int ns){
		V=1;
		while(V<=ns)V*=2;
		dat=new st[2*V];
		laz=new op[2*V];
		for(int i=0;i<2*V;i++){
			dat[i]=st0;
			laz[i]=op0;
		}
	}
	void update(ll l,ll r,ll a){
		upd(l,r,(op){a});
	}
	ll query(ll l,ll r){
		st res=qry(l,r);
		return res.a;
	}
};
Segtree seg;

int main(){
	int n,q;
	cin>>n>>q;
	seg.init(n);
	rep(i,n)seg.update(i,i,2147483647);
	while(q--){
		ll p,s,t,x;
		cin>>p;
		if(p==0){
			cin>>s>>t>>x;
			seg.update(s,t,x);
		}
		if(p==1){
			cin>>s;
			cout<<seg.query(s,s)<<"\n";
		}
	}
}



Measured memory_bytes: 7196
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct aaa{
	int x,y;
}a[500010];
int n,m,tot,e[500010],hd[500010],nt[500010],v[500010],fr[500010],b[500010],c[500010],ans[500010];
bool cmp(aaa a,aaa b){
	return a.x<b.x;
}
void build(int x,int y,int w){
	tot++;
	e[tot]=y;fr[tot]=w;
	nt[tot]=hd[x];hd[x]=tot;
}
void dfs(int x,int fa){
	int i;v[x]=1;
	for(i=hd[x];i;i=nt[i]){
		if(v[e[i]])continue;
		dfs(e[i],fr[i]);
		if(b[e[i]])b[x]^=1;
	}
	if(b[x])c[fa]=1;
}
int main(){
	int i,x,y,l,r,mid,mn,mx;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);
	sort(a+1,a+n+1,cmp);
	for(i=1;i<=n+1;i++)b[i]=a[i].y^a[i-1].y;
	for(i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		l=1;r=n;
		mn=n+1;mx=0;
		while(l<=r){
			mid=(l+r)/2;
			if(x<=a[mid].x)mn=mid,r=mid-1;
			 else l=mid+1;
		}
		l=1;r=n;
		while(l<=r){
			mid=(l+r)/2;
			if(y>=a[mid].x)mx=mid,l=mid+1;
			 else r=mid-1;
		}
		if(mn<=mx)build(mn,mx+1,i),build(mx+1,mn,i);
	}
	for(i=1;i<=n+1;i++)if(!v[i]){
		dfs(i,0);
		if(b[i])return puts("-1"),0;
	}
	for(i=1;i<=m;i++)if(c[i])ans[++ans[0]]=i;
	printf("%d\n",ans[0]);
	for(i=1;i<=ans[0];i++)printf("%d ",ans[i]);
}

Measured memory_bytes: 19072
h,w = map(int,input().split())
field = [list(input())for i in range(h)]
a= [[10**4]*w for i in range(h)]

vec = [(-1,0),(1,0),(0,1),(0,-1)]
ans = 0
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":continue
        stack = [(i,j)]
        visited = [[0]*w for i in range(h)]
        a[i][j] = 0
        
        while stack:
            next = []
            for x,y in stack:
                
                if visited[x][y]:continue

                visited[x][y] = 1
                

                for tx,ty in vec:
                    nx = x+tx
                    ny = y+ty
                    if nx < 0 or ny <0 or nx >=h or ny >=w:continue
                    if field[nx][ny] == "#" :continue
                    if visited[nx][ny]:continue
                    next.append((nx,ny))
                    a[nx][ny] = min(a[x][y] + 1,a[nx][ny])
                    
                    
            stack = next
   
        for m in range(h):
            for n in range(w):
                if a[m][n] != 10**4:
                    ans = max(ans,a[m][n])
                a[m][n] = 10**4
print(ans)
            
            
            
            


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

#define ll long long

ll n, cache[int(1e5)];
vector <ll> h;


ll dp(ll i)
{
	if (i == n - 1){
		return 0;
	}
	if (i >= n)	return 2e9;
	if (cache[i] != -1)	return cache[i];
	return cache[i] = min(abs(h[i] - h[i + 1]) + dp(i + 1), abs(h[i] - h[i + 2]) + dp(i + 2));
}

int main()
{	
	ll _n;	cin >> _n;	vector <ll> _h(_n);	for (ll i = 0; i < _n; i ++)	cin >> _h[i];
	n = _n;	h = _h;	memset(cache, -1, sizeof(cache));
	cout << dp(0) << "\n";
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

const int N = 2e5+5;
vector<int>g[N], v;
set<int>s;
long long m=INT_MAX, k,nn, c=0;
bool f=0;

void dfs1(int u)
{
    s.insert(u);
    for(auto i:g[u])
    {
        ++c;
        if(s.find(i) != s.end())
        {
            c-=v[i];
            m = v[i];
            nn = i;
            f=1;
            return;
        }
        v[i] = c;
        dfs1(i);
        if(f==1)
            return;
    }
}
void dfs(int u)
{
    //cout<<u<<' ';
    if(k==0)
    {
        cout<<u;
        return;
    }   
    for(auto i:g[u])
    {
        --k;
        dfs(i);
        if(0==k)
            return;
    }
}

int main()
{
 
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    long long n;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        g[i].emplace_back(x);
    }
    v.assign(n+1,0);
    dfs1(1);
    //cout<<c<<'\n';
    if(k > m)
    {
        k = (k-m)%c;
        //cout<<k<<'\n';
        dfs(nn);
    }
    else
    {
        dfs(1);
    }

    return 0;
}

Measured memory_bytes: 33528
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,a,b;
  cin>>n>>a>>b;
  if(b<a){cout<<0;return 0;}
  if(n==1 && a==b){cout<<1;return 0;}
  else if(n==1 && a!=b){cout<<0;return 0;}
  //now there can be a lot of2 4 8 - lower_sum higher sum;
  //3 4 8 - 4 5 8 4 6 8 4 6 8 4 4 8 4 8 8 - 5 different sums
  //4 4 8 - 4 4 4 8 - 4 8 8 8 - 
  long long minsum = (n-1)*a+b;
  long long maxsum = (n-1)*b+a;
  cout<<maxsum-minsum+1;
  
}

Measured memory_bytes: 3488
N, P = map(int, input().split())
As = list(map(int, input().split()))

MOD = 2 ** 61 - 1
table_len = 100

fac = [1, 1]
for i in range(2, table_len):
    fac.append(fac[-1] * i % MOD)

finv = [0] * table_len
finv[-1] = pow(fac[-1], MOD - 2, MOD)
for i in range(table_len-1, 0, -1):
    finv[i-1] = finv[i] * i % MOD

C = 0
D = 0
for A in As:
    if A % 2:
        D += 1
    else:
        C += 1

ans = pow(2, C)
ans *= sum( ((fac[D] * finv[i] * finv[D-i])%MOD for i in range(P, D+1, 2)) )
print(ans)

Measured memory_bytes: 61804
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
int h,w;
string s[22];
int dist[22][22];
int res=0;
void bfs(int sy,int sx,int gy,int gx){
    for(int a=0;a<h;a++){
        for(int b=0;b<w;b++){
            dist[a][b]=-1;
        }
    }
    queue<pair<int,int>> Q;
    while(!Q.empty()){
        Q.pop();
    }
    Q.push(make_pair(sy,sx));
    dist[sy][sx]=0;
    bool flag=true;
    while((!Q.empty())&&flag){
        auto now=Q.front();
        Q.pop();
        int y=now.first;
        int x=now.second;
        if(y==gy&&x==gx){
            res=max(res,dist[gy][gx]);
            flag=true;
        }else{
            for(int i=0;i<4;i++){
                int ny=y+dy[i];
                int nx=x+dx[i];
                if(ny<0||nx<0||ny>=h||nx>=w)continue;
                if(s[ny][nx]=='#')continue;
                if(dist[ny][nx]!=-1)continue;
                dist[ny][nx]=dist[y][x]+1;
                Q.push(make_pair(ny,nx));
            }
        }
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>h>>w;
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int p=0;p<h;p++){
                for(int q=0;q<w;q++){
                    if(s[i][j]=='#'||s[p][q]=='#')continue;
                    if(i==p&&j==q)continue;
                    bfs(i,j,p,q);
                }
            }
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define VI vector<int>
#define VLL vector<long long>
 
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
 
ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);
 
 
ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
 
ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,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;
}
 
void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */
 
    ll q=1;
    //cin>>q;
    while(q--)
    {
        ll n;
        cin>>n;
        ll a[n];
        REP(i,0,n)
        {
            ll t;
            cin>>t;
            a[i]=t;
        }
        ll flag=0;
        REPI(i,0,n-1)
        {
            if(a[i]<=a[i+1]) continue;
            else if(a[i]==a[i+1]+1) a[i]--;
            else
            {
                flag=1;
                break;
            }
        }
        if(flag==0) cout<<"Yes\n";
        else cout<<"No\n";
    }
 
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ld long double
using namespace std;


int main() {
  	int N;
  	cin >> N;
  	vector<ld> prob(N+1, 0);
  	vector<vector<ld> > dp(N+1, vector<ld> (N+1, -1));
  	ld res = 0;
  
  	for(int i = 1 ; i <= N ; i++) {
    	cin >> prob[i];
    }
  	
  	// first set up the answer for getting 0 heads using
  	// first i coins, it is the product (1-p1) * (1-p2)* ..*(1-pi)
  	dp[0][0] = 1.0;
    for(int i = 1; i <= N; ++i)
        dp[i][0] = dp[i - 1][0] * (1.0 - prob[i]); // coins are 1 based index
  	
  	// the prob of getting x heads using x coins
  	// is the product of all pis till here
  	for(int i = 1 ; i <= N ; i++)
      	dp[i][i] = dp[i-1][i-1] * prob[i];
  	
  	// probability of selecting head from this coin * probability of getting j - 1
    // heads from all the previous coins + probability of selecting a tail here
    // * probability of getting j heads from all the previous coins
  	for(int i = 1 ; i <= N ; i++) 	// no of coins
    	for(int j = 1 ; j < i ; j++)	// no. of heads
        	dp[i][j] = dp[i - 1][j] * (1 - prob[i])
          				+ dp[i-1][j-1] * (prob[i]);
  
  	for(int i = N/2+1 ; i <= N ; i++)
      	res += dp[N][i];
  	cout<<fixed<<setprecision(10) << res << endl;
  	
  	//for(auto row : dp) {
    	//for(auto i : row)
          	//cout << i << "\t";
      	//cout<<endl;
    //}
  	return 0;
}

Measured memory_bytes: 141056
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO 自動生成されたメソッド・スタブ
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long sum = 0;
        //配列入力用
        Integer s[] = new Integer[n];

        for(int i=0;i<n;i++){
            s[i]= scan.nextInt();
            sum = sum + s[i];
        }
        Arrays.sort(s);
        System.out.println(s[0] + " " + s[n-1] + " " + sum); 

    }

}



Measured memory_bytes: 42884
class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
 
    def sum(self, i):
        # [0, i) の要素の総和を返す
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s
    # 0 index を 1 index に変更  転倒数を求めるなら1を足していく
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    # 総和がx以上になる位置のindex をbinary search
    def bsearch(self,x):
        le = 0
        ri = 1<<(self.size.bit_length()-1)
        while ri > 0:
            if le+ri <= self.size and self.tree[le+ri]<x:
                x -= self.tree[le+ri]
                le += ri
            ri >>= 1
        return le+1

n,q = map(int,input().split())
a = list(map(int,input().split()))
bit = BIT(n)
for i,x in enumerate(a):
    bit.add(i,x)
for i in range(q):
    t,l,r = map(int,input().split())
    if t == 0:
        bit.add(l,r)
    else:
        print(bit.sum(r)-bit.sum(l))

Measured memory_bytes: 65208
S=input()
N=len(S)
D={"a":0,"b":0,"c":0}
for i in range(N):
    D[S[i]]+=1

if N==1:
    print("YES")
    exit()
elif N==2:
    if len(set(S))==1:
        print("NO")
    else:
        print("YES")
    exit()


a=D["a"]
b=D["b"]
c=D["c"]
MIN=min(a,b,c)
MAX=max(a,b,c)

if MAX-MIN<=1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int []w = new int [n];
		
		for(int i =0; i < n ; i++) {
			 w [i] = sc.nextInt();		
		}
		int t1 = 0;
		int t2 = 0 ;
		int k = 0;
		int l = 0;
		
		while(k + l < n  ) {
			if(t1 <= t2) {
				t1 = w[k] + t1;
			k++;}
			
			else {
				t2 = w [n - 1 - l]  + t2;
			l++;
			}
		}
		 int ans = Math.abs(t2-t1);
		 System.out.println(ans);
				
		
		}
	
	 
	
	}




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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;
#define DBG(x) cerr << x << endl;

/*
	http://abc072.contest.atcoder.jp/tasks/arc082_b
*/
int n;
VI A;
int solve()
{
	int ret = 0;
	for(int i = 1; i <= n; ++i)
	{
		if(A[i] == i)
		{
			++ret;
			int delta = i == n ? -1 : 1;
			swap(A[i], A[i + delta]);
		}
	}
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
	//freopen("tmp.out", "w", stderr);
#endif
	cin >> n;
	
	A.assign(n + 1, 0);
	REPC(i, 1, n) cin >> A[i];

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 640