akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Question();
			Instance.Exec();
		}
	}

	public class Question
	{
		public void Exec()
		{
			long n = long.Parse(Console.ReadLine());
			var vx = Console.ReadLine().Split(' ').Select(i => double.Parse(i)).ToArray();
			var vy = Console.ReadLine().Split(' ').Select(i => double.Parse(i)).ToArray();

			double[] distances = new double[4];
			double max = 0.0;
			for (var i = 0; i < n; ++i) {
				double diff = Math.Abs(vx[i] - vy[i]);
				distances[0] += diff;
				distances[1] += Math.Pow(diff, 2.0);
				distances[2] += Math.Pow(diff, 3.0);
				max = Math.Max(max, diff);
			}

			distances[1] = Math.Sqrt(distances[1]);
			distances[2] = Math.Pow(distances[2], 1.0 / 3.0);
			distances[3] = max;

			foreach (var item in distances) {
				Console.WriteLine($"{item:f6}");
			}
			
			Console.ReadKey();
		}
	}
}


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

int main(void){
    char input[12];
    cin >> input;
    
    int n = 0, s = 0;
    int i = 0;
    while(input[i]){
        n *= 10;
        n += input[i] - '0';
        s += input[i] - '0';
        i++;
        
    
    }
    
    if(n % s){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
MOD = 10 ** 9 + 7

LR = [None] * (N * 2)
left_left = 0
ans = 1
for i in range(2 * N):
    if i:
        LR[i] = LR[i - 1] ^ (S[i - 1] == S[i])
    else:
        LR[i] = S[i] == "B"
    if LR[i]:
        left_left += 1
    else:
        ans *= left_left
        ans %= MOD
        left_left -= 1
if left_left != 0:
    ans = 0
for i in range(1, N + 1):
    ans *= i
    ans %= MOD

print(ans)


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

int main(){
  string S, T;
  cin >> S;
  long long K;
  cin >> K;
  T = S;
  
  long long cnt = 0, ans = 0;
  
  if (S.length() == 1) {
    ans = K / 2;
    cout << ans;
    return 0;
  }
  
  for (int i = 1; i < T.length(); i++) {
    if (T.at(i) == T.at(i-1)) {
      T.replace(i, 1, "-");
      cnt++;
    }
  }
  
  ans = cnt * K;
  
  if (T.at(0) == T.at(T.length() - 1)) {
    int j = 0;
    while (j < S.length() - 1) {
      if (S.at(S.length() - 1) != S.at(j)) break;
      j++;
    }
    if (j == S.length() - 1) {
      ans = (long long) S.length() * K / 2;
    } else {
      if (j % 2 == 0) ans = cnt * K;
      else ans = cnt * K + K - 1;
    }
  }
  
  cout << ans;
  
  return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main(void){
  long N;
  cin >> N;
  bool exitFlag=false;
  for(int h=1;h<=3500;h++){
    for(int n=1;n<=3500;n++){
      long num=N*h*n;
      long den=4*h*n-N*(h+n);
      if(den<=0) continue;
      if(num%den==0){
	cout << h << " " << n << " " << num/den << endl;
	exitFlag=true;
	break;
      }
    }
    if(exitFlag) break;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int b,a,c; 
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>a>>b>>c;
	if(b-a==c-b) cout<<"YES"<<endl;
	else cout<<"NO"<<endl; 
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int m1 = sc.nextInt();
		int d1 = sc.nextInt();
		int m2 = sc.nextInt();
		int d2 = sc.nextInt();
		
		if (m1 == m2) { 
			System.out.print("0");
		}else{
			System.out.print("1");
		}
	}
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int n, sum = 0, both = 0, left = 0, right = 0;
  cin >> n;
  rep(i, n) {
    string s;
    cin >> s;
    if (s[0] == 'B' && s[s.length() - 1] == 'A')
      both++;
    else if (s[0] == 'B')
      left++;
    else if (s[s.length() - 1] == 'A')
      right++;
    rep(i, s.length() - 1) {
      if (s[i] == 'A' && s[i + 1] == 'B') sum++;
    }
  }
  if (both != 0) {
    if (left + right > 0) {
      cout << sum + both + min(left, right) << endl;
    } else {
      cout << sum + both - 1 << endl;
    }
  } else
    cout << sum + min(left, right) << endl;
  return 0;
}

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


int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ar[n];
    int bl[9]={};
    for(int i=0; i<n; i++){
        cin >> ar[i];
        if(ar[i] < 400)
            bl[0] = true;
        else if(ar[i] < 800)
            bl[1] = true;
        else if(ar[i] < 1200)
            bl[2] = true;
        else if(ar[i] < 1600)
            bl[3] = true;
        else if(ar[i] < 2000)
            bl[4] = true;
        else if(ar[i] < 2400)
            bl[5] = true;
        else if(ar[i] < 2800)
            bl[6] = true;
        else if(ar[i] < 3200)
            bl[7] = true;
        else bl[8]++;
    }
    int mn =0,mx=0;
    for(int i=0; i<8; i++){
        if(bl[i])
            mn++;
    }

    mx = mn+bl[8];
    if(mn == 0 && bl[8] > 0) mn = 1;
    cout << mn << " " << mx << endl;
}


Measured memory_bytes: 256
/* 
    @author : srinathbalaji_99
*/


#include<bits/stdc++.h>

#define PB push_back
#define MP make_pair
#define endl '\n'
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define rep(i, a, b, inc) for(long long i = a; i < b; i += inc)
#define REP(i, n) rep(i, 0, n, 1)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define PLL pair<long long, long long>
#define VL vector<long long>
#define VS vector<string>
#define VLL vector<PLL>
#define VVL vector<VL>
#define MPLL map<long long, long long>
#define UMPLL unordered_map<long long, long long>
#define SETL set<long long>
#define MSETL multiset<long long>
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) (a * b)/GCD(a, b)
#define ff first
#define ss second
#define pall(a) REP(i, sizeof(a)/sizeof(a[0]))cout << a[i] << " ";cout << endl;
#define pvall(v) REP(i, v.size())cout << v[i] << " ";cout << endl;
#define gall(a, n) REP(i, n)cin >> a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;


using namespace std;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main()
{
    fast();


    LL t,n,i,j,k,x,y,c,m;
    LL a, b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b));
}

Measured memory_bytes: 256
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
W = []
for i in range(N):
  a = list(map(int, input().split()))
  heappush(W, a)
  
ans = 0
C = []

for i in range(1,M+1):
  j = -i
  while W != [] and W[0][0] <= i:
    a,b = heappop(W)
    heappush(C,-b)
  if C != []:
    ans += -heappop(C)
print(ans)

Measured memory_bytes: 28064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

1-26 = a-z
27 = aa

26進数
でも0がない感じ

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  ll N; cin >> N;
  string word = "zabcdefghijklmnopqrstuvwxy";
  string ans;
  N--;
  while (1){
    char c = N%26 + 'a';
    ans += c;
    N /= 26;
    N--;
    if (N < 0)
      break;
  }
  ll end = ans.size();
  while(--end >= 0)
    cout << ans[end];    
  cout << endl;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define faster ios::sync_with_stdio(false)
#define ll long long int
#define sz 200005
#define mp(x,y) make_pair(x,y) 
#define pii pair<long long int,long long int>
#define tor ::iterator
#define letsgo long long  int i,j,k,q=0,t,tmp,n,flg=0,cntr=0,maxxer = 0
#define fi first
#define se second
#define be begin()
#define en end()
#define mod 1000000007
#define debug(x) cout<<" "<<x<<endl


ll dp[1005][1005];
char mat [1005][1005];
int trav(int i,int j){
	// cout<<i<<"  "<<j<<endl;
	if(i<0 || j<0){
		return 0;
	}
		
	if(dp[i][j]!=-1)
		return dp[i][j];
	// if(i>=0 && j>=0)
	if(mat[i][j]=='#'){
		dp[i][j]=0;	
	}
	else
		dp[i][j] = ((trav(i-1,j)%mod)+(trav(i,j-1)%mod))%mod;

	return dp[i][j];
	
}
int main(){
	faster;
	letsgo; 
	string s1,s2;
	ll m;
	cin>>n>>m;

	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>mat[i][j];
		}
	}
	for(i=0;i<=n;i++){
		for(j=0;j<=m;j++){
			dp[i][j]=-1;
		}
	}
	dp[0][0] = 1;
	trav(n-1,m-1);
	// for(i=0;i<=n;i++){
	// 	for(j=0;j<=m;j++){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	// cout<<mat[1][1];
	cout<<dp[n-1][m-1];
	return 0;	
}


Measured memory_bytes: 9216
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]){
  int hour, min, sec;
  scanf("%d", &sec);

  hour = sec / 3600;
  sec -= (hour * 3600);
  min = sec / 60;
  sec -= (min * 60);

  printf("%d:%d:%d\n", hour, min, sec);
  return 0;
}



Measured memory_bytes: 2132
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll N, X, x;
  cin >> N >> X;
  optional<ll> res;
  REP(i, N) {
    cin >> x;
    res = res ? gcd(res.value(), abs(X - x)) : abs(X - x);
  }
  cout << res.value() << endl;
  return 0;
}


Measured memory_bytes: 3648
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
int main()
{
  int n;
  cin >> n;
  std::vector<int> var, copyvar;
  std::vector<int> count(n, 0);

  for (int i = 1; i < n+1; i++) {
    var.push_back(i);
  }
  copyvar = var;
  for (int i = 0; i < n; i++) {
    int j = 0;
    while(true){
      if(var[i]%2 == 1)
        break;
      else {
        var[i]/=2;
        ++j;
      }
      count[i] = j;
    }
  }

  std::vector<int>::iterator maxitr = std::max_element(count.begin(), count.end());
  int maxindex = std::distance(count.begin(), maxitr);

  cout << copyvar[maxindex] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
 
using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU 
 
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll NN = N;
    ll n = 2;
    vll Ans;
    while (n * n <= N) {
        while (N % n == 0) {
            Ans.push_back(n);
            N /= n;
        }
        n++;
    }
    if (n <= N) {
        Ans.push_back(N);
    }
    cout << NN << ":";
    for (ll a : Ans) {
        cout << " " << a;
    }
    cout << endl;
    PAU;
    return 0;
}


Measured memory_bytes: 3172
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String a = scanner.next();
        String b = scanner.next();
        String target = a + b;
        String result = "No";

        for(int i = 1; i < 100100; i++){
            String squareNumbers = Integer.toString(i*i);

            if(squareNumbers.equals(target)){
                result = "Yes";
                break;
            }
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 28372
N = int(input())
ans = 0
if N%4 == 0 or N%7 == 0 or N%11 == 0:
    print("Yes")
else:
    for i in range(0,25):
        for j in range(0,14):
            if i*4+j*7 == N:
                print("Yes")
                ans += 1
                break
        if ans == 1:
            break
    if ans == 0:
        print("No")

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

int main() {
	vector<int> vec; int an; int set = 0;
	cin >> an; vec.resize(an);
	for (int i = 0; i < an; i++) cin >> vec[i];
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	for (int i : vec) cout << (set++ ? " " : "") << i;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3148
n = int(input())
a = list(map(int, input().split()))

# 平均を出す
mean = sum(a)/n

# 差分を求める
a = [abs(i-mean) for i in a]

temp = 101
ans = -1

for i in range(n):
    if temp > a[i]:
        temp = a[i]
        ans = i

print(ans)

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()

string S;

int sub(vector<char> c) {
    ll res = S.size();
    REP (i, S.size()) if (S[i] == c[i&1]) res--;
    return res;
}

int solve() {
    vector<char> c1({'0', '1'}), c2({'1', '0'});
    return min(sub(c1), sub(c2));
}

int main() {
    cin >> S;
    cout << solve() << endl;
}

Measured memory_bytes: 512
using Atcoder;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            Dictionary<int, string[]> allList = new Dictionary<int, string[]>();
            for (int i = 0; i < N; i++)
            {
                var K = Console.ReadLine().Split(' ');
                allList.Add(i + 1,K);
            }

            var tmp = allList.OrderBy(x => x.Value[0]).ThenByDescending(x => int.Parse(x.Value[1]));
            foreach (var item in tmp)
            {
                Console.WriteLine(item.Key);
            }
        }

    }

    //var N = int.Parse(Console.ReadLine());
    //var S = Console.ReadLine();
    //var K = Console.ReadLine().Split(' ');
    //var N = int.Parse((K[0]));
    //var M = int.Parse((K[1]));
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    unsigned int  sum = 0, ans, n; cin >> n;

    for(ans = 1; sum < n; ans++) sum += ans;

    cout << ans - 1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (ll i = x; i < (ll)(n); i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 100000000000000099;
const ll LINF = (ll)(1e18 + 99);
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};


signed main()
{
    ll n;cin>>n;
    vector<PL> v(n);

    rep(i,n){
        cin>>v[i].fi;
        v[i].se=i+1;
    }
    sort(all(v));

    rep(i,n){
        cout<<v[i].se<<(i==n-1?'\n':' ');
    }
}



Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // ABC150C - Count Order

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] p = new int[n];
        int[] q = new int[n];
        
        int a = 1;
        int b = 1;

        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            int cnt = 1, x = 1;
            for (int j = 0; j < i; j++) {
                if (p[i] > p[j]) {
                    ++cnt;
                }
            }
            for (int k = n - 1 - i; k > 0; k--) {
                x *= k;
            }
            a += x * (p[i] - cnt);
//            System.out.println("x=" + x + ", cnt=" + cnt + ", a=" + a);
        }
        
        for (int i = 0; i < n; i++) {
            q[i] = sc.nextInt();
            int cnt = 1, x = 1;
            for (int j = 0; j < i; j++) {
                if (q[i] > q[j]) {
                    ++cnt;
                }
            }
            for (int k = n - 1 - i; k > 0; k--) {
                x *= k;
            }
            b += x * (q[i] - cnt);
//            System.out.println("x=" + x + ", cnt=" + cnt + ", b=" + b);
        }

        System.out.println(Math.abs(a - b));
    }
}

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




int main()
{
    int n,m;
    std::cin >> n >> m;
    std::vector<std::pair<int,int>> a(m);
    for(int i = 0; i < m; i++)std::cin >> a[i].second >> a[i].first;
    int cnt = 0;
    int right = 0;
    std::sort(a.begin(),a.end());
    for(int i = 0; i < m; i++){
        if(a[i].second >= right){
            cnt++;
            right = a[i].first;
        }
    }
    std::cout << cnt << std::endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<29;
const double eps=1e-09;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<long double> X(N),Y(N);
    long double ans=INF;
    
    for(int i=0;i<N;i++){
        cin>>X[i]>>Y[i];
    }
    
    if(N==2){
        cout<<setprecision(25)<<hypot(X[0]-X[1],Y[0]-Y[1])/2.0<<endl;
    }else{
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                for(int k=j+1;k<N;k++){
                    long double a=X[i],b=Y[i],c=X[j],d=Y[j],e=X[k],f=Y[k];
                    long double x,y;
                    
                    x=0.5*((a*a+b*b)*(d-f)+(c*c+d*d)*(f-b)+(e*e+f*f)*(b-d))/((a*(d-f)+c*(f-b)+e*(b-d)));
                    y=0.5*((a*a+b*b)*(e-c)+(c*c+d*d)*(a-e)+(e*e+f*f)*(c-a))/((a*(d-f)+c*(f-b)+e*(b-d)));
                    
                    long double r=hypot(a-x,b-y);
                    bool ok=true;
                    
                    for(int l=0;l<N;l++){
                        if(r+eps<hypot(X[l]-x,Y[l]-y)) ok=false;
                    }
                    
                    if(ok) ans=min(ans,r);
                    
                    //cout<<maxi<<endl;
                }
            }
        }
        
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                long double x=(X[i]+X[j])/2.0,y=(Y[i]+Y[j])/2.0;
                
                long double r=hypot(X[i]-x,Y[i]-y);
                bool ok=true;
                
                for(int l=0;l<N;l++){
                    if(r+eps<hypot(X[l]-x,Y[l]-y)) ok=false;
                }
                
                if(ok) ans=min(ans,r);
            }
        }
        
        cout<<setprecision(25)<<ans<<endl;
    }
}



Measured memory_bytes: 384
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
	ll n, m, ans;
	cin >> n >> m;
	if (n * 2 >= m) {
		ans = m/2;
	}
	else {
		ans = n;
		if ((m - n * 2) / 4 > 0) {
			ans += (m - n * 2) / 4;
		}
	}

	cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int MOD=1e9+7;

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

  int n;cin>>n;
  int res=1;
  if(n==1){
      cout<<1<<endl;
      return 0;
  }
  std::vector<ll> v;
  int p=0;
  for(int i=0;i<n;i++){
      int a;cin>>a;
      if(a!=p){
          v.push_back(a);
          p=a;
      }
  }
  int st=0;
  for(int r=1;r<(int)v.size();r++){
      if((v[st]<v[st+1])==(v[r-1]<v[r])) continue;
      else{
          st=r;
          res++;
      }
  }
  cout<<res<<endl;
  return 0;

  //cout<<fixed<<setprecision(10)<<endl;
  //VVI v(n,vector<int>(n));
}


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

#define fst first
#define snd second
#define fore(i,a,b) for(int i=a, ThxDem=b; i<ThxDem; ++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define SZ(s) int(s.size())
#define DBG(x) cerr <<#x << " = " << (x) << "\n"

#define SQR(x) ((x) * (x))

#define PI 3.1415926535897932385
#define INF 1000111222
#define eps 1e-7
#define maxN 11

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<string> vstr;
typedef vector<vll> vvll;
typedef vector<bool> vbool;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<vbool> vvbool;

int main(){FIN
	ll n;
	double h,t;
	cin >> n;
	vector<double> p(n+1);
	fore(i,1,n+1)cin >> p[i];
	vector<vector<double>> dp(n+1,vector<double>(n+1,0.0));
	dp[0][0]=1;
	fore(i,1,n+1){
		h = p[i], t = 1-p[i];
		dp[0][i] = t*dp[0][i-1];
		fore(j,1,i+1) dp[j][i] = h*dp[j-1][i-1]+t*dp[j][i-1];
	}
	double ans = 0;
	fore(i,n/2+1,n+1) ans+=dp[i][n];
	cout << setprecision(10) << ans;
	return 0;
}


Measured memory_bytes: 73732
#include<stdio.h>
#define N 100
  int main(){
    int A[N][N];
    int n,u,k,v,i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++){
      for(j=0;j<n;j++)A[i][j]=0;
    }
    for(i=0;i<n;i++){
      scanf("%d%d",&u,&k);
      u--;
      for(j=0;j<k;j++){
        scanf("%d",&v);
        v--;
        A[u][v]=1;
      }
    }
for(i=0;i<n;i++){
  for(j=0;j<n;j++){
    if(j!=0&&j<=n-1)printf(" ");
    printf("%d",A[i][j]);
  }
  printf("\n");
}
return 0;
}



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

const int mod = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define ll long long
#define vi vector < int >
#define vll vector < ll >
#define pii pair < int , int >
#define ff first
#define tc \
    int ttt; cin >> ttt;\
    while(ttt --)
#define ss second
#define f(i,a,b) for(int i=a;i<b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define nl '\n'
#define all(x) x.begin() , x.end()
#define mne min_element
#define mxe max_element
ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);}
int logg(ll x , ll y) {if (x == 0) return -1; return logg(x / y, y) + 1;}
ll poww(ll a, ll b, ll m) {
	if (b == 0) return 1;
	ll ans = 1;
	ans = poww(a, b >> 1, m);
	ans = (ans * ans) % m;
	if (b & 1) ans = (ans * a) % m;
	return ans;
}
// Start of code
const int N = 1e5 + 5;
int dp[105][N];
int weight[105];
int val[105];
int n, w;

int solve() {

	memset(dp, 0, sizeof dp);
	dp[1][weight[1]] = val[1];
	int maxg = dp[1][weight[1]];
	f(i, 2, n + 1) {
		f(j, 0, w + 1) {
			dp[i][j] = dp[i - 1][j];
			if (weight[i] > j) continue;
			dp[i][j] = max(dp[i][j], val[i] + dp[i - 1][j - weight[i]]);
			maxg = max(maxg, dp[i][j]);
		}
	}
	return maxg;
}

int32_t main() {


	fast;

	cin >> n >> w;

	f(i, 1, n + 1) cin >> weight[i] >> val[i];
	cout << solve() << nl;
}


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

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

        int ans = (int)Math.ceil((a + b) / 2);
        System.out.println(ans);

        sc.close();
    }
}

Measured memory_bytes: 21460
package main

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

func StrStdin() string {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	return strings.TrimSpace(scanner.Text())
}

func SliceStrsStdin(delim string) []string {
	stringInput := StrStdin()
	return SplitWithoutEmpty(stringInput, delim)
}

func SplitWithoutEmpty(stringTargeted string, delim string) []string {
	stringSplited := strings.Split(stringTargeted, delim)
	strs := []string{}

	for _, str := range stringSplited {
		if str != "" {
			strs = append(strs, str)
		}
	}
	return strs
}

func SliceIntStdin() []int {
	stringSplited := SliceStrsStdin(" ")

	intSlice := []int{}

	for ni := range stringSplited {
		num, _ := strconv.Atoi(stringSplited[ni])
		intSlice = append(intSlice, num)
	}

	return intSlice
}

func max(nums ...int) int {
	m := nums[0]
	for i, v := range nums {
		if i == 0 {
			continue
		}
		if m < v {
			m = v
		}
	}
	return m
}

func main() {

	abcd := SliceIntStdin()
	fmt.Println(max(abcd[0]*abcd[2], abcd[0]*abcd[3], abcd[1]*abcd[2], abcd[1]*abcd[3]))

}


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

int main(){
    int N, K;
    cin >> N >> K;
    double ans = 0;
    for (int i = 1; i <= N; ++i){
        int num = i;
        int counter = 0;
        while (num < K){
            num*=2;
            counter++;
        }
        ans += 1/(double)(1<<counter);
    }

    cout << setprecision(15) << ans/(double)N << endl;
    return 0;
}

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

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, A, B, C, D;
int dp[1001][1001];
int fact[1001];
int factinv[1001];
int comb[1001][1001];

int modpow(int x, int k) {
  int a = 1;
  while (k > 0) {
    if (k & 1) a = (1LL*a*x) % MOD;
    x = (1LL*x*x) % MOD;
    k >>= 1;
  }
  return a;
}

int inv(int x) {
  return modpow(x, MOD-2);
}

int nCr(int n, int k) {
  if (n < 0 || k < 0 || n < k) return 0;
  return (1LL * fact[n] * inv((1LL*fact[k]*fact[n-k]) % MOD)) % MOD;
}

int f(int x, int n) {
  if (dp[x][n] != -1) return dp[x][n];
  if (n == 0) return dp[x][n] = 1;
  if (x < A) return dp[x][n] = 0;
  long long s = 0;
  s += f(x-1, n);
  int y = 1;
  for (int k=1; k<C; k++) {
    if (n-k*x < 0) break;
    y = (1LL * y * comb[n-(k-1)*x][x]) % MOD;
  }
  for (int k=C; k<=D; k++) {
    if (n-k*x < 0) break;
    y = (1LL * y * comb[n-(k-1)*x][x]) % MOD;
    int b = (1LL * y * factinv[k]) % MOD;
    s = (s + 1LL * b * f(x-1, n-k*x)) % MOD;
  }
  return dp[x][n] = s;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> A >> B >> C >> D;
  fact[0] = 1;
  factinv[0] = 1;
  for (int i=1; i<=N; i++) {
    fact[i] = (1LL*i*fact[i-1]) % MOD;
    factinv[i] = inv(fact[i]);
  }
  for (int i=0; i<=1000; i++) {
    for (int j=0; j<=1000; j++) {
      dp[i][j] = -1;
      comb[i][j] = nCr(i, j);
    }
  }

  cout << f(B, N) << "\n";
  return 0;
}


Measured memory_bytes: 8192
#include<stdio.h>
#include<string.h>
#define LEN 100005
#define MAX 100000
typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail]=x;
  if(tail+1==MAX)tail=0;
  else tail++;

}

P dequeue(){
  P x;
  x=Q[head];
  if(head +1==MAX) head=0;
  else head++;
  return x;

}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
    enqueue(Q[i]);
  }

  while(head!=tail){
    u=dequeue();

    if(u.t>q){
      elaps=elaps+q;
      u.t=u.t-q;
      enqueue(u);
    }
    else {
      elaps=elaps+u.t;
      u.t=elaps;
      printf("%s %d\n",u.name,u.t);
      
    }
  }
 
  
  return 0;
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

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

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}


int main(){

    ll a, b, c, k; cin >> a >> b >> c >> k;
    
    while(b<=a){
        b*=2;
        k--;
    }

    while(c<=b){
        c*=2;
        k--;
    }


    if(k<0){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }


    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        while(true){
            int n= sc.nextInt();
            if(n==0) break;
            int i;
            int[] ten;
            ten=new int[n];
            int sum=0;
            for(i=0;i<n;i++){
                ten[i]=sc.nextInt();
                sum=sum+ten[i];
            }
            double ave=(double)sum/n;
            double t;
            double s;
            t=0;
            for(i=0;i<n;i++){
                t=t+(ten[i]-ave)*(ten[i]-ave);
            }
            s=t/n;
            System.out.printf("%f\n",Math.sqrt(s));
        }
    }
}


Measured memory_bytes: 31884
#include <stdio.h>

int main(void)
{
	int i,j;
	char c1[10],c2[10],c3[10];
	
	scanf("%s\n%s\n%s",c1,c2,c3);
	
	printf("%c%c%c\n",c1[0],c2[1],c3[2]);
	
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;




public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);

    	int A=sc.nextInt();
    	int B=sc.nextInt();

    	String str=sc.next();
    	String[] S=str.split("");

    	if(S[A].equals("-")) {

    		int length=str.length();
    		int lengthnum=str.replaceAll("-","").length();

    		int diff=length-lengthnum;

    		if(diff==1) {
    			System.out.println("Yes");
    		}else {
    			System.out.println("No");
    		}

    	}else {
			System.out.println("No");
		}
    }


}



Measured memory_bytes: 23124
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=parseMap(split(readline()))
    ans=0
    for i in a
        ans+=i-1
    end
    println(ans)
end
main()

Measured memory_bytes: 165516
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;

template <class T> using V = vector<T>;

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

const long long INF = 1LL << 60;

using ll = long long;
using db = long double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;



#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define pb(a) push_back(a);



ll Sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}



const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


#define comuse Comuse()

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

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


ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}


vll div(ll n){
  vll ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  SORT(ret);
  return (ret);
}

ll modpow(ll a,ll n,ll mod){
  ll ans=1;
  while(n>0){
    if(n&1){
      ans=ans*a%mod;
    }

    a=a*a%mod;
    
    n>>=1;
  }

  return ans;
}

void Solve();


const int MAX_N = 131072;
//segment tree 
int NN;
int seg[MAX_N*2-1];
void seguse(){
  for(int i=0;i<2*NN-1;i++){
    seg[i]=INT_MAX;
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;
  Solve();
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
//segtreeの葉の先頭の添え字はn-1
void Solve(){
  //vll segtree(524287);
  //ll N=262144;
  ll k,t;
    cin>>k>>t;
  vll A(t);
  if(t==1){
    cout<<k-1<<endl;
    return;
  }

  FOR(i,0,t){
    cin>>A[i];
  }

  SORT(A);
  k-=A[t-1];
  ll ans=A[t-1]-1-k;
  cout<<max(0LL,ans)<<endl;
}

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

using namespace std;

#define ll long long

const int N = 1e5 + 10;

struct E{
    ll x,y;

}a[N];

bool cmp1(E e1,E e2) {
    return e1.y > e2.y;
}

bool cmp2(E e1,E e2) {
    return e1.x > e2.x;
}

int main(){
    ios_base::sync_with_stdio(0);
    int n,s;cin>>n>>s;
    for(int i = 0;i < n;i++) {
        cin>>a[i].x>>a[i].y;
    }
    sort(a,a+n,cmp2);
    ll max_x = a[0].x;
    sort(a,a+n,cmp1);
    int len_t = n;
    for(int i = 0;i < n;i++) {
        if(a[i].y < max_x) {
            len_t = i;
            break;
        }
    }
    ll sum = 0;
    int res = 0;
    for(int i = 0;i < len_t;i++) {
        sum += a[i].y;
        res++;
        if(sum >= s) {
            cout<<res<<endl;
            return 0;
        }
    }
    s -= sum;
    res += ceil(s*1.0/max_x);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n, m = map(int, input().split())
    am = set([int(input()) for i in range(m)])
    ans = [0] * (n + 1000)
    ans[0] = 1
    md = (10 ** 9) + 7
    for i in range(n):
        if (i + 1) not in am:
            ans[i + 1] = (ans[i] + ans[i + 1]) % md
        if (i + 2) not in am:
            ans[i + 2] = (ans[i] + ans[i + 2]) % md
    print(ans[n])

if __name__ == "__main__":
    solve()


Measured memory_bytes: 56664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
const ll MOD=1000000007;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    rep (i,N){
        cin >> A[i];
    }
    vector<ll> B(N+1);
    map<ll,ll> m;
    m[0]++;
    rep (i,N){
        B[i+1]=B[i]+A[i];
        m[B[i+1]]++;
    }
    ll ans=0;
    for (auto x:m){
        ll p=x.second;
        ans+=p*(p-1)/2;
    }
    cout << ans << endl;
}

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

int main()
{
    int N, count=0;
    cin >> N;
    vector<int> data(N);
    for (int i = 0; i < N; i++){
        cin >> data.at(i);
    }

        for (int i = 0; i < N; i++)
        {
            if (data.at(i) != i + 1)
            {
                count++;
                //cout << data.at(i) << endl;
            }
        }
    if(count==2 || count==0){
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    

}

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

#define ll long long

using namespace std;
const ll INF = 1e18;
const int SIZE_LIMIT = 1e3+5;
char maze[SIZE_LIMIT][SIZE_LIMIT];

ll dp[SIZE_LIMIT][SIZE_LIMIT];

int main() {
  //memset(maze, 0, sizeof(maze));
 // memset(dp, 0x3f, sizeof(dp));

  int h = 0, w = 0, ch, cw, dh, dw;
  scanf("%d%d%d%d%d%d", &h, &w, &ch, &cw, &dh, &dw);
  ch--;cw--;dh--;dw--;

   for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>maze[i][j];
          dp[i][j]=INF;
        }
    }

  deque<pair<int, int>> movable;
  movable.push_back({ch, cw});
  dp[ch][cw]=0;

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


  while (!movable.empty()) {
    auto p = movable.front();
    movable.pop_front();


    for (int i = 0; i < 4; ++i) 
    {
      int nx = dx[i]+p.first, ny = dy[i]+p.second;
      if (nx>=0 and nx<h and ny>=0 and ny<w and maze[nx][ny] == '.' && dp[nx][ny] > dp[p.first][p.second]+0)
      {
        dp[nx][ny] = dp[p.first][p.second]+0;
        movable.push_front({nx, ny});
      }
    }
    // jump
    for (int i = -2; i <= 2; ++i) {
      for (int j = -2; j <= 2; ++j) {
        int nx = p.first+i, ny = p.second+j;
        if (nx>=0 && nx<h && ny>=0 && ny<w && maze[nx][ny] == '.' && dp[nx][ny] > dp[p.first][p.second]+1) {
          dp[nx][ny] = dp[p.first][p.second]+1;
          movable.push_back({nx, ny});
        }
      }
    }

  }

  if (dp[dh][dw] == INF) printf("-1\n");
  else printf("%d\n", dp[dh][dw]);



  return 0;
}


Measured memory_bytes: 12660
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class KuraInfo{
public:
	int num;
	int dist;
	int weight;
};

double dp[(1<<15)][15];
int dp2[(1<<15)][15];

int n;
KuraInfo kuras[15];
const int INF=100000000;

int best;

double dfs(const int s,const int d,const double sumWeight,const int depth){
	if(s==0)
		return 0;
	double minCost=INF;
	if(d==-1){
		for(int i = 0; i < n; i++){
			if(((s>>i)&1)){
				double ret = dfs((s&~(1<<i)),i,sumWeight+kuras[i].weight,depth+1);
				if(minCost>ret){
					best=i;
					minCost=min(minCost,ret);
				}
			}
		}
	}
	else{
		if(dp[s][d]!=INF)
			return dp[s][d];
		for(int i = 0; i < n; i++){
			if(((s>>i)&1)){
				double ret = dfs((s&~(1<<i)),i,sumWeight+kuras[i].weight,depth+1)
					+(
					((double)abs(kuras[i].dist-kuras[d].dist))
					/(((double)2000)/(70+sumWeight)));
				if(minCost>ret){
					dp2[s][d]=i;
					minCost=min(minCost,ret);
				}
			}
		}

	}
	dp[s][d]=minCost;
	return dp[s][d];
}

int main(){

	while(cin>>n){
		for(int i = 0; i < n; i++){
			cin>>kuras[i].num>>kuras[i].dist>>kuras[i].weight;
			kuras[i].weight*=20;
		}
		for(int i = 0; i < (1<<15); i++){
			fill(dp[i],dp[i]+15,INF);
			fill(dp2[i],dp2[i]+(15),INF);
		}
		
		dfs((1<<n)-1,-1,0,0);
		
		int s = (1<<n)-1;
		bool first=true;
		int prv;
		while(1){
			if(first){
				cout<<kuras[best].num;
				s=(s&~(1<<best));
				first=false;
				prv=best;
			}
			else{
				if(s==0){
					cout<<endl;
					break;
				}
				else
					cout<<" ";
				cout<<kuras[dp2[s][prv]].num;
				int np=dp2[s][prv];
				s=(s&~(1<<dp2[s][prv]));
				prv=np;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
def run():
    row,col=tuple(map(int,input().split()))
    
    A=[]
    
    for i in range(row):
        row_ls=list(map(int,input().split()))
        
        row_sum=sum(row_ls)
        
        A.append(row_ls+[row_sum])
        
    
    col_sum=[0 for i in range(col+1)]
    
    for j in range(col+1):
        for i in range(row):
            col_sum[j]+=A[i][j]
            
    A.append(col_sum)
    
    for i in range(row+1):
        for j in range(col+1):
            if j!=col:
                print(f"{A[i][j]} ",end="")
            else:
                print(f"{A[i][j]}")
                
run()


Measured memory_bytes: 6256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include<cassert>
using namespace std;
#include<atcoder/all>
using namespace atcoder;


#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

using mint = modint998244353;

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

/////////////////////////////////////

int main() {
	ll N;
	cin >> N;
	vll x(N+1), y(N+1);
	repn(i, N)cin >> x[i] >> y[i];

	vll za(N+1);
	vll id(N+1);
	repn(i, N) {
		za[x[i]] = y[i];
		id[x[i]] = i;
	}

	vll mx(N + 2);
	mx[N+1] = 0;
	for (ll i = N; i >= 1; i--) {
		mx[i] = max(mx[i + 1], za[i]);
	}
	vll mn(N + 1);
	mn[0] = INF;
	repn(i, N)mn[i] = min(mn[i - 1], za[i]);

	vll div;
	div.push_back(0);
	repn(i, N) {
		if (mn[i] > mx[i + 1]) { div.push_back(i); }
	}

	vll ans(N + 1);
	repn(i, N) {
		auto itr = lower_bound(div.begin(), div.end(), i);
		ll dis = distance(div.begin(), itr);
		
		ans[id[i]] = div[dis] - div[dis - 1];
	}

	repn(i, N)cout << ans[i] << endl;

}


Measured memory_bytes: 14296
#include <stdio.h>

int main(){
  

  int a, b, r, tmp;
 
 
  scanf("%d %d", &a,&b);
 
  
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 

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



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

int main() {
  int n,ans;
  cin >> n;
  vector<int> l(n),r(n);

  ans = 0;
  for(int i=0;i<n;i++){
    cin >> r.at(i) >> l.at(i);
    ans += 1+l.at(i)-r.at(i);
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

long long N, M, V, P;
std::vector<long long > A;

bool judge(long long n){
  if (n<P){ // 最初からP番目までであった場合は必ず選べるのでtrue
    return true;
  } else if (A[n]+M>=A[P-1] && (P-1)+(N-n)>=V){
    return true;
  } else if (A[n]+M<A[P-1]) {
    return false; // M票足しても最低必要な票数(左からP番目の人の数)に届かない
  }
  long long sum = 0;
  for (long long i=P-1; i<N; i++){
    if (i==n){
      continue;
    }
    if (i<n && A[n]+M<A[i]){
      return false;
    }
    sum += std::min(M, A[n]+M-A[i]); // i番目の人に足せる票数は、M票(全員投票する場合)かA[n]+M-A[i]票のうち少ない方
  }
  if (sum >= M*(V-P)){ // 各ジャッジが投票すべき票数はあとV-P票ずつ残っている
    return true;
  } else {
    return false;
  }
}

int main(){
  scanf("%lld", &N);
  scanf("%lld", &M);
  scanf("%lld", &V);
  scanf("%lld", &P);
  long long temp;
  for (int i=0; i<N; i++){
    scanf("%lld", &temp);
    A.push_back(temp);
  }
  sort(A.begin(), A.end(), std::greater<long long>()); // 大きい順になるようにソート

  long long edge_start = 0;
  long long edge_end = N-1;
  long long cand;
  // 二分探索実施
  while (edge_end - edge_start > 1){
    cand = (edge_start+edge_end)/2;
    //printf("judge(%lld) = %d\n",cand,judge(cand));
    if (judge(cand)){
      edge_start = cand;
    } else {
      edge_end = cand;
    }
  }
  if (judge(edge_end)){
    printf("%lld\n", edge_end+1);
  } else {
    printf("%lld\n",edge_start+1);
  }
  return 0;
}


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

int main(){
    long long a,b,c,k,ans = 0;
    cin >> a >> b >> c >> k;
    if(k > a)ans += a;
    else ans = k;
    k = max(0ll,k - a);

    k = max(0ll,k - b);
    
    if(k > c)ans -= c;
    else ans -= k;

    cout << ans << endl;

}

Measured memory_bytes: 3636