akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int main()
{
    lli n;
    cin>>n;
    if(n%2==0){
    	ld an=((ld)1/(ld)2);
    	cout<<fixed<<setprecision(10)<<an;
    	return 0;
    }
    lli x=n/2+1;
    ld an=((ld)(x)/(ld)(n));
    cout<<fixed<<setprecision(10)<<an;


 	return 0;
 }

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

int main()
{
	ll n;
	cin >> n;
	vector<ll> M(n + 1);
	cin >> M[0];
	for (int i = 1; i < n; i++) {
		cin >> M[i] >> M[i];
	}
	cin >> M[n];
	vector<vector<ll>> dp(n, vector<ll>(n, INF));
	for (int i = 0; i < n; i++) {
		dp[i][i] = 0;
	}
	for (ll k = 1; k < n; k++) {
		for (ll i = 0; i + k < n; i++) {
			for (ll j = 0; j <= i + k - 1; j++) {
				ll cost = dp[i][j] + dp[j + 1][i + k] + M[i] * M[j + 1] * M[i + k + 1];
				if (cost < dp[i][i + k]) {
					dp[i][i + k] = cost;
				}
			}
		}
	}
	cout << dp[0][n - 1] << endl;
	return 0;
}

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

int main(){
	int n;
  cin >> n;
  int d[n];
  rep(i,n){
  	cin >> d[i];
  }
  int ans=0;
  rep(i,n){
  	for(int j=i+1;j<n;j++){
    	ans+=d[i]*d[j];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int A,B,C,K;
  cin >> A >> B >> C >> K;
  if(abs(A-B) > pow(10,18)){
    cout << "Unfair" << endl;
  }else{
    if(K%2 == 0){
      cout << A-B << endl;
    }else{
      cout << B-A << endl;
    }
  }
}

Measured memory_bytes: 256
if __name__=="__main__":
    # Problem C
    X, N = map(int, (input().split(' ')))
    if N > 0:
        P = sorted(map(int, input().split(' ')))
        P_max = max(P)
        P_min = min(P)
        if X in P:
            for i in range(100):
                if (X-i) not in P:
                    print(X-i)
                    break

                elif (X+i) not in P:
                    print(X+i)
                    break
        elif X not in P:
            print(X)
    else:
        print(X)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

string s[55];

int main() {
	int h, w;
	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++) {
			if (s[i][j] == '.') {
				int cnt = 0;
				for (int k = -1; k <= 1; k++) {
					for (int l = -1; l <= 1; l++) {
						int ni = i + k;
						int nj = j + l;
						if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
						if (s[ni][nj] == '#') cnt++;
					}
				}
				s[i][j] = cnt + '0';
			}
		}
	}

	for (int i = 0; i < h; i++)
		cout << s[i] << endl;
}

Measured memory_bytes: 3588
#include <stdio.h>

int main(void) {

  int path[6];
  for (int i = 0; i < 6; i++) {
    scanf("%d", &path[i]);
  }
  int city[4];
  for (int i = 0; i < 4; i++) {
    city[i] = 0;
  }
  for (int i = 0; i < 6; i++) {
    city[path[i]-1]++;
  }
  int count1 = 0;
  int count2 = 0;
  for (int i = 0; i < 4; i++) {
    if (city[i] == 1) {
      count1++;
    }
    if (city[i] == 2) {
      count2++;
    }
  }
  if (count1 == 2 && count2 == 2) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>  
#define xx first  
#define yy second  
#define mp make_pair  
#define pb push_back  
#define fill( x, y ) memset( x, y, sizeof x )  
#define copy( x, y ) memcpy( x, y, sizeof x )  
using namespace std;  
//因为一种取出顺序可以对应若干种初始状态,因此我们只选取可以让红球个数为0的
//初始状态代表这种取出顺序
typedef long long LL;  
typedef pair < int, int > pa;  
  
const int MAXN = 3005;  
const int mod = 1e9 + 7;  
  
inline void inc(int &x, int y) { x += y; if( x >= mod ) x -= mod; }  
  
int n, m, dp[MAXN][MAXN][2], ans;  
  
int main()  
{  
    scanf( "%d%d", &n, &m );  
    for( int i = 1 ; i <= n ; i++ ) dp[ 0 ][ i ][ 0 ] = 1;  
    dp[ 0 ][ 0 ][ 1 ] = 1;  
    for( int i = 0 ; i < m ; i++ )  //第i次操作
        for( int j = 0 ; j <= n ; j++ )  //当前有j个红球
            for( int k = 0 ; k < 2 ; k++ )  //待定
            if( int cur = dp[ i ][ j ][ k ] )  
            {  
                if( !j )            //没有红球
                {  
                    inc( dp[ i + 1 ][ j ][ 1 ], cur );  
                    inc( dp[ i + 1 ][ j + 1 ][ 1 ], cur );    
                }  
                else if( j == n )  //全是红球
                {  
                    inc( dp[ i + 1 ][ j ][ k | ( j == 1 ) ], cur );  
                    inc( dp[ i + 1 ][ j - 1 ][ k | ( j == 1 ) ], cur );  
                }  
                else  
                {  
                    inc( dp[ i + 1 ][ j ][ k ], cur );  
                    inc( dp[ i + 1 ][ j + 1 ][ k ], cur );  
                    inc( dp[ i + 1 ][ j ][ k | ( j == 1 ) ], cur );  
                    inc( dp[ i + 1 ][ j - 1 ][ k | ( j == 1 ) ], cur );  
                }  
            }  
    for( int i = 0 ; i <= n ; i++ ) inc( ans, dp[ m ][ i ][ 1 ] );  
    return printf( "%d\n", ans ), 0;  
}  

Measured memory_bytes: 70656
n=int(input())
s=list(input())
mod=10**9+7
s.sort()
k=1
lst=[]
for i in range(1,n):
    if s[i]==s[i-1]:
        k+=1
    else:
        lst.append(k)
        k=1
lst.append(k)
m=len(lst)
ans=1
for u in lst:
    ans=(ans*(u+1))%mod
print(ans-1)

Measured memory_bytes: 50160
#![allow(unused_imports)]
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]

use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Write};
use std::ops::{Add, Div, Mul, Sub};
use std::str::{self, FromStr};
use std::{cmp, fmt};

fn main() {
    let (m, xyzs): (usize, Vec<(i64, i64, i64)>) = {
        let mut sc = InputScanOnce::new(io::stdin(), 1024);
        let n = sc.next();
        (sc.next(), sc.trios(n))
    };
    let mut r = 0;
    for &(k1, k2, k3) in &[
        (-1, -1, -1),
        (-1, -1, 1),
        (-1, 1, -1),
        (-1, 1, 1),
        (1, -1, -1),
        (1, -1, 1),
        (1, 1, -1),
        (1, 1, 1),
    ] {
        let mut xyzs_ = xyzs
            .iter()
            .map(|&(x, y, z)| k1 * x + k2 * y + k3 * z)
            .collect::<Vec<_>>();
        xyzs_.sort();
        let m = xyzs_.into_iter().rev().take(m).sum::<i64>();
        r = cmp::max(r, m);
    }
    println!("{}", r);
}

struct InputScanOnce {
    buf: Vec<u8>,
    pos: usize,
}

#[allow(dead_code)]
impl InputScanOnce {
    fn new<R: Read>(mut reader: R, estimated: usize) -> Self {
        let mut buf = Vec::with_capacity(estimated);
        let _ = io::copy(&mut reader, &mut buf).unwrap();
        InputScanOnce { buf: buf, pos: 0 }
    }

    #[inline]
    fn next<T: FromStr>(&mut self) -> T
    where
        T::Err: fmt::Debug,
    {
        let mut start = None;
        loop {
            match (self.buf[self.pos], start.is_some()) {
                (b' ', true) | (b'\n', true) => break,
                (_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
                (_, false) => start = Some(self.pos),
            }
        }
        let target = &self.buf[start.unwrap()..self.pos];
        unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        T::Err: fmt::Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<T1: FromStr, T2: FromStr>(&mut self, n: usize) -> Vec<(T1, T2)>
    where
        T1::Err: fmt::Debug,
        T2::Err: fmt::Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<T1: FromStr, T2: FromStr, T3: FromStr>(&mut self, n: usize) -> Vec<(T1, T2, T3)>
    where
        T1::Err: fmt::Debug,
        T2::Err: fmt::Debug,
        T3::Err: fmt::Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        T::Err: fmt::Debug,
    {
        (0..m).map(|_| self.vec(n)).collect()
    }

    fn strings_as_mat<T, F: FnMut(u8) -> T>(&mut self, h: usize, mut f: F) -> Vec<Vec<T>> {
        (0..h)
            .map(|_| {
                let l = self.next::<String>();
                l.as_bytes().iter().cloned().map(&mut f).collect()
            })
            .collect()
    }
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

struct Matrix2x2 {
	ll a[2][2];
	Matrix2x2 operator*(const Matrix2x2 &m){
		Matrix2x2 c;
		for(int i = 0; i < 2; ++i){
			for(int j = 0; j < 2; ++j){
				ll sum = 0;
				for(int k = 0; k < 2; ++k){
					sum = (sum + a[i][k] * m.a[k][j]) % MOD;
				}
				c.a[i][j] = sum;
			}
		}
		return c;
	}
};

const Matrix2x2 E = { { { 1, 0 }, { 0, 1 } } };

Matrix2x2 modpow(const Matrix2x2 &m, ll e){
	if(e == 0){ return E; }
	Matrix2x2 p = modpow(m, e / 2);
	p = p * p;
	if(e % 2 == 1){ p = p * m; }
	return p;
}

const Matrix2x2 FIB_MAT = { { { 1, 1 }, { 1, 0 } } };
ll fib(ll n){
	Matrix2x2 m = modpow(FIB_MAT, n);
	return (m.a[0][0] + m.a[0][1]) % MOD;
}

int main(){
	ll K;
	cin >> K;
	--K;
	ll left = 0, right = 3400000000ll;
	while(left < right){
		ll center = (left + right) / 2;
		ll begin = center * (center + 1);
		if(K >= begin){
			left = center + 1;
		}else{
			right = center;
		}
	}
	--left;
	K -= left * (left + 1);
	ll answer = 0;
	if(K <= left){
		ll base = left * 2;
		if(K <= left / 2){
			answer = fib(base - K * 2) * fib(K * 2) % MOD;
		}else{
			answer = fib(base - K * 2 + 1) * fib(K * 2 - 1) % MOD;
		}
	}else{
		ll base = left * 2 + 1;
		K -= (left + 1);
		answer = fib(base - K * 2) * fib(K * 2) % MOD;
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 1160
/*
 *
 * Author: r3gz3n
 * 
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define rep(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)


#define endl '\n'


class Solution {
public:
    const int static MAX = 55;
    string a[MAX], b[MAX];
    void solve(std::istream& in, std::ostream& out) {
		int n, m;
        in >> n >> m;
        rep(i, 0, n, 1) in >> a[i];
        rep(i, 0, m, 1) in >> b[i];
        int x = 0;
        rep(i, 0, n-m+1, 1) {
            rep(j, 0, n-m+1, 1) {
                if (a[i].substr(j, m) == b[0]) {
                    x = 0;
                    rep(k, 0, m, 1) {
                        if (a[i+k].substr(j, m) == b[x]) x++;
                        else break;
                    }
                }
            }
            if (x == m) break;
        }
        if (x == m) out << "Yes" << endl;
        else out << "No" << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[1000001];
int start,tmp=0;
int main()
{
	gets(a);
	int n=strlen(a); 
	for(int i=0;i<n;i++) 
	  if (a[i]=='C') {start=i;tmp=1;break;}
	for(int i=start+1;i<n;i++)
	  if(a[i]=='F'&&tmp) {cout<<"Yes";return 0;}
	cout<<"No";
	return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template <typename P, typename Q>
ostream& operator<<(ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T> v)
{
  os << "(";
  each (i, v)
    os << i << ",";
  os << ")";
  return os;
}

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

  string s;
  while (cin >> s) {
    int a = count(s.begin(), s.end(), '0');
    int b = count(s.begin(), s.end(), '1');
    if (s.size() == a || s.size() == b) {
      cout << s.size() << endl;
      continue;
    }

    int mn = 1 << 29;
    for (int i = 0; i + 1 < s.size(); ++i) {
      if (s[i] != s[i + 1]) {
        int x = max<int>(i + 1, (int)s.size() - i - 1);
        mn = min(mn, x);
      }
    }
    cout << mn << endl;
  }

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>

int main(){
	int t, n;
	while(std::cin >> t >> n, !std::cin.eof()){
		int sum = 0;
		while(n--){
			int s, f;
			std::cin >> s >> f;
			sum += f - s;
		}
		if(sum >= t){
			puts("OK");
		}else{
			printf("%d\n", t-sum);
		}
	}
}

Measured memory_bytes: 1148
<?php
/**
 * AGC035
 * A - XOR Circle
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

fscanf(STDIN, "%d", $N);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));

$sum = 0;
for ($i = 0; $i < $N; $i++) {
    $sum ^= $a[$i];
}

if ($sum === 0) {
    echo 'Yes', PHP_EOL;
} else {
    echo 'No', PHP_EOL;
}



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

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

const ll LLINF = 1LL << 60;

struct Edge { ll to, cost; };

ll N, M, X;
ll H[100005];
vector < Edge > G[100005];
ll mc[100005];
priority_queue < Pi , vector < Pi > , greater < Pi > > pq;
int main()
{
    cin >> N >> M >> X;
    for(int i = 0; i < N; i++) cin >> H[i];
    for(int i = 0; i < M; i++) {
        ll a, b, c;
        cin >> a >> b >> c; --a, --b;
        G[a].push_back((Edge){b, c});
        G[b].push_back((Edge){a, c});
    }
    fill_n(mc, 100005, LLINF);
    mc[0] = 0; pq.push(Pi(0, 0));
    while(!pq.empty()) {
        Pi d = pq.top(); pq.pop();
        ll v = d.second;
        for(int i = 0; i < G[v].size(); i++) {
            ll u = G[v][i].to, w = d.first + G[v][i].cost;
            if(G[v][i].cost > H[v]) continue;
            if(X - w > H[u]) w += (X - w) - H[u];
            if(w < mc[u]) {
                mc[u] = w; pq.push(Pi(w, u));
            }
        }
    }
    if(mc[N - 1] == LLINF) cout << -1 << endl;
    else cout << mc[N - 1] * 2 - X + H[N - 1] << endl;
    return (0);
}


Measured memory_bytes: 23216
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main() {
    int a,b,c,d;
    cin >> a>>b>>c>>d;
    if((int)((a+d-1)/d) >= (int)((c+b-1)/b)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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


//defines...
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define in insert
#define pi 2*acos(0.0)1
#define srt(s) sort(s.begin(),s.end())
#define rsrt(s) sort(s.rbegin(),s.rend())
#define all(x) x.begin(),x.end()

const ll mod=1e9+7;
const ll MX=2e5+5;

//code goes from here...



int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);
#endif

    boost
    //---------------------------------
    ll n;
    cin >>  n;
    ll ans=1;
    while (ans*2<=n) ans*=2;
    cout << ans << endl;
    
    //---------------------------------
    
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
map<int,int> pos;
int n;
int a[maxn];
bool check(int mxnum)
{
//	cout<<"check "<<mxnum<<endl;
	pos.clear();
	for(int i=0;i<n;i++)
	{
		if(!i||a[i]>a[i-1])continue;
		int here=a[i];
	//	cout<<here<<endl;
	//	cout<<pos.count(here)<<" "<<pos[here]<<endl;
		while(here>=1&&pos.count(here)&&pos[here]==mxnum-1)
		{
			pos.erase(here);
		//	cout<<here<<endl;
			here--;
		}
		if(here<1)return 0;
		if(!pos.count(here))pos[here]=1;
		else pos[here]++;
	//	cout<<here<<" "<<pos[here]<<endl;
		if(pos[here]>=mxnum)return 0;
		for(map<int,int>::iterator it=pos.begin();it!=pos.end();)
			if(it->first>here)
			{
				map<int,int>::iterator tmp=it;
				it++;
	//			cout<<tmp->first<<endl;
				pos.erase(tmp);
			}
			else it++;
	//	system("pause");
	}
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	int l=0,r=n;
	while(r-l>1)
	{
		int mid=(l+r)>>1;
		if(check(mid))r=mid;
		else l=mid;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 1024
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int i,j,k,l;
  int h,w,n;
  while(scanf("%d%d%d",&h,&w,&n),h||w||n){
    vector<vector<vector<int> > > a(h);
    for(i=0;i<h;++i){
      a[i].push_back(vector<int>(w));
      for(j=0;j<w;++j)
      	scanf("%d",&a[i][0][j]);
    }
    if(w>h){
      for(;(int)a.back().back().size()>1;){
	for(i=0;i<h;++i){
	  a[i].push_back(vector<int>(a[i].back().size()/2));
	  for(j=0;j<(int)a[i].back().size();++j)
	    a[i].back()[j]=min(a[i][a[i].size()-2][j*2],a[i][a[i].size()-2][j*2+1]);
	}
      }
      for(i=0;i<n;++i){
	int y0,x0,y1,x1;
	scanf("%d%d%d%d",&y0,&x0,&y1,&x1);
	int mn=(1ll<<31)-1;
	for(j=x0;j<=x1;j+=(1<<k)){
	  for(k=0;j%(1<<(k+1))==0&&j+(1<<(k+1))-1<=x1;++k);
	  for(l=y0;l<=y1;++l)
	    mn=min(mn,a[l][k][j/(1<<k)]);
	}
	printf("%d\n",mn);
      }
    }else{
      vector<vector<vector<int> > > b(w);
      for(i=0;i<w;++i){
	b[i].push_back(vector<int>(h));
	for(j=0;j<h;++j)
	  b[i][0][j]=a[j][0][i];
      }
      for(;(int)b.back().back().size()>1;){
	for(i=0;i<w;++i){
	  b[i].push_back(vector<int>(b[i].back().size()/2));
	  for(j=0;j<(int)b[i].back().size();++j)
	    b[i].back()[j]=min(b[i][b[i].size()-2][j*2],b[i][b[i].size()-2][j*2+1]);
	}
      }
      for(i=0;i<n;++i){
	int y0,x0,y1,x1;
	scanf("%d%d%d%d",&y0,&x0,&y1,&x1);
	int mn=(1ll<<31)-1;
	for(j=y0;j<=y1;j+=(1<<k)){
	  for(k=0;j%(1<<(k+1))==0&&j+(1<<(k+1))-1<=y1;++k);
	  for(l=x0;l<=x1;++l)
	    mn=min(mn,b[l][k][j/(1<<k)]);
	}
	printf("%d\n",mn);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 57000
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(998244353)
#define INF (2e9)
#define EPS (1e-6)
#ifdef LOCAL_TEST
#define debug(...) do{\
	cerr<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<\
	" : ("#__VA_ARGS__<<") = ";\
	_OUT(__VA_ARGS__);\
}while(0)
template<typename T>void _OUT(T x){cerr<<x<<endl;}
template<typename T,typename...I>void _OUT(T x,I ...tail){cerr<<x<<", ";_OUT(tail...);}
#else
#define debug(...)
#endif

void INIT(){
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
}

ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll fpow(ll b,ll p){
	b%=MOD;
	ll ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

int32_t main() {
	INIT();
	//code...
	int n; cin>>n;
	cout<<(n+n*n+n*n*n)<<"\n";
	return 0;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main() 
{
    int ans=700;
    char a,b,c;
    cin>>a>>b>>c;
    if(a=='o') ans+=100;
    if(b=='o') ans+=100;
    if(c=='o') ans+=100;
    cout<<ans<<endl;
    return 0;
}

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

const int INF = (1 << 30) - 1;

int N, Q;
int S[1000005], sIdx[1000005];
pair < int , int > sorted[1000005];

int main()
{

    cin >> N >> Q;
    for ( int i = 0; i < N; i++ ) { cin >> S[i];
        sorted[i] = make_pair(S[i], i);
    }

    sort(sorted, sorted + N);

    for ( int i = 0; i < N; i++ ) {
        sIdx[sorted[i].second] = i;
    }

    set < int > leader;

    while ( Q > 0 ) {
        string T;
        cin >> T;
        int a, x;
        if ( T == "ADD" ) {
            cin >> a;
            leader.insert(a - 1);
        } else if ( T == "REMOVE" ) {
            cin >> a;
            leader.erase(a - 1);
        } else {
            int ng = -1, ok = INF;
            bool flag = false;
            vector < int > pos;

            cin >> x;
            for ( auto &d : leader ) {
                pos.push_back(sIdx[d]);
            }
            sort(begin(pos), end(pos));

            while ( abs(ng - ok) > 1 ) {
                int r = (ng + ok) / 2;
                int cnt = 0;
                int covered = -1; //どこまでやってるか
                for ( auto right : pos ) {
                    int left = lower_bound(sorted, sorted + N, make_pair(sorted[right].first - r, -INF)) - sorted;
                    right = upper_bound(sorted, sorted + N, make_pair(sorted[right].first, INF)) - sorted - 1;

                    left = max(covered + 1, left);

                    cnt += right - left + 1;
                    covered = right;
                }
                if ( (N - x) <= cnt ) {
                    ok = r;
                    flag = true;
                } else {
                    ng = r;
                }
            }
            if ( flag ) {
                cout << ok << endl;
            } else {
                cout << "NA" << endl;
            }
        }
        Q--;
    }
    return ( 0 );
}



Measured memory_bytes: 18788
'use strict'

function main(input) {
  input = input
    .trim()
    .split(' ')
    .map(Number)
  const k = input[0]
  const s = input[1]
  let count = 0
  for (let xi = 0; xi <= k; xi++) {
    for (let yi = 0; yi <= k; yi++) {
      // for (let zi = 0; zi <= k; zi++) {
      const diff = s - xi - yi
      // console.log(diff)
      if (diff >= 0 && diff <= k) count++
      // }
    }
  }
  console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7372
#include <iostream>
#include <string>
using namespace std;
int main(){
    string A;
    while(1){
        cin>>A;
        if(A=="0") {
            break;
        }
        else{
            int sum=0;
            for ( int i = 0; i<A.size(); i++ ){
                int number;
                number=A[i]-'0';
                sum+=number;
                
            }
            cout<<sum<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3172
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <string.h>

using namespace std;

int main()
{
    int a, b, c;
    scanf("%d %d %d",&a,&b,&c);
    if((c<=b&&c>=a)||(c<=a&&c>=b))
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 760
#include <stdio.h>

int main(void){
	while(1){
		int n, i;
		long a[100], key;
	
		scanf(" %d", &n);
		if(n==0) break;
		
		for(i=0; i<n; i++) scanf(" %ld", &a[i]);
		scanf(" %ld", &key);
	
		int left=0, right=n-1;
		int count = 0;
		
		while(left <= right){
			++count;
		
			int p = (left+right)/2;
			if(a[p] > key) {
				right = p-1;
			}
			else if(a[p] < key) {
				left = p+1;
			}
			else break;
			
			//printf("%d~%d ;%d\n",left,right, p);
		}
	
		printf("%d\n", count);
	
	}

	return 0;
}

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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for (auto& hi : h) {
        cin >> hi;
    }
    sort(h.begin(), h.end());
    int ans = numeric_limits<int>::max();
    for (int i = 0; i < N; i++) {
        if (i + K - 1 < N) {
            ans = min(ans, h[i + K - 1] - h[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void){
	int room[4][3][10] = {};
	int n,b,f,r,v;
	int i,j,k,l;
	scanf("%d",&n);

	for(i = 0;i < n;i++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		for(j = 0;j < 4;j++){
			if(j == b - 1){
				for(k = 0;k < 3;k++){
					if(k == f - 1){
						for(l = 0;l < 10;l++){
							if(l == r - 1){
								room[j][k][l] += v;
								break;
							}
						}
					}
				}
			}
		}
	}

	for(i = 0;i < 4;i++){
		for(j = 0;j < 3;j++){
			for(k = 0;k < 10;k++){
				printf(" %d",room[i][j][k]);
			}
			putchar('\n');
		}
		if(i != 3){
			for(l = 0;l < 20;l++){
				putchar('#');
			}
			putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 600
for i in range(int(input())):
  a,b,c,d,e,f,g,h = map(float,input().split())
  if a == c:
    print("YES" if e == g else "NO")
  elif e == g:
    print("NO")
  else:
    print("YES" if abs((b-d)/(a-c) - (f-h)/(e-g)) < 1e-10 else "NO")



Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF 1000000000
#define EPS      1e-10
#define MOD      1000003
#define HOGE 100000
#define HUGA 100000
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
typedef pair<double,P> PQ;

int n;
int x[HOGE], y[HOGE];
bool dp[HUGA];

void solve(){
    memset(dp,0,sizeof(dp));
    rep(i,n) cin >> x[i] >> y[i];
    int ma = 0;
    int ig = 0;
    rep(i,n){
        if(ma < x[i]){
            ma = x[i];
            ig = i;
        }
    }
    sort(x,x+n,greater<int>());
    ll sum = 0;
    ll sumy = 0;
    rep(i,n) sumy += y[i];
    for(int i = 1; i < n; i++) sum += x[i];
    if(x[0] <= sum){
        cout << x[0]+sum+sumy << endl;
    } else{
        ll p = x[0]-sum;
        dp[0] = true;
        rep(i,n){
            if(i == ig){
                ig = -1;
                continue;
            }
            for(int j = p; j >= y[i]; j--){
                if(dp[j-y[i]]) dp[j] = true;
            }
        }
        ll b = 0;
        for(int i = p; i >= 0; i--){
            if(dp[i]){
                b = i;
                break;
            }
        }
        cout << x[0]+sum+sumy+p-b << endl;
    }
}

int main(){
    while(cin >> n){
        if(n == 0) break;
        solve();
    }
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vs = vector<string>;
template <typename T>
using ost = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
#define forn(i,n) for(int i=0; i<int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ff first
#define ss second

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi xs(n);
    forn(i, n) cin >> xs[i];
    ll ans = 0;
    forn(i, n) {
        if (xs[i]%2 && i+1<n && xs[i+1])
            ++xs[i], --xs[i+1];
        ans += xs[i]/2;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 640
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}
struct union_find{
  vector<int> par;
  vector<int> rank;
  union_find(int n){
    rank = vector<int>(n,0);
    for(int i=0; i<n; i++){
      par.push_back(i);
    }
  }

  int root(int x){
    if(par[x]==x){
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);

    if(rx==ry)
      return;

    if(rank[rx]<rank[ry]){
      par[rx] = ry;
    } else {
      par[ry] = rx;
      if(rank[rx]==rank[ry])
        rank[rx]++;
    }
  }

  bool equiv(int x, int y){
    return root(x)==root(y);
  }
};


/*
n k l
p1 q1
...
pk qk
r1 s1
...
rl sl

n 2*10^5
k.l 10^5
p q r s <= n
p < q
r < s
 */
int n,k,l;

int main(){
  cin>>n>>k>>l;
  union_find uf1(n);
  union_find uf2(n);
  REP(i,k){
    int p,q;
    cin>>p>>q;
    p--;
    q--;
    uf1.unite(p,q);
  }
  REP(j,l){
    int r,s;
    cin>>r>>s;
    r--;
    s--;
    uf2.unite(r,s);
  }
  map<int, map<int, int>> root;

  REP(i,n)
    root[uf1.root(i)][uf2.root(i)]++;

  REP(i,n)
    cout << root[uf1.root(i)][uf2.root(i)] << " ";

  cout << endl;
  return 0;
}

Measured memory_bytes: 29300
#include <stdio.h>
#include <algorithm>

long long int N, K, a[112345];
long long int b[112345], c[112345], among, l, r, ans = 0;

int main(void)
{
	scanf("%lld%lld", &N, &K);
	for (long long int i = 0; i < N; ++i) { scanf("%lld", &a[i]); }

	b[0] = a[0];
	c[0] = std::max(0LL, a[0]);
	for (long long int i = 1; i < N; ++i)
	{
		b[i] = b[i - 1] + a[i];
		c[i] = c[i - 1] + std::max(0LL, a[i]);
	}
	ans = c[N - 1] - c[K - 1] + std::max(0LL, b[K - 1]);
	for (long long int i = 1; i <= N - K; ++i)
	{
		among = b[i + K - 1] - b[i - 1];
		among = (among < 0 ? 0 : among);
		l = c[i - 1], r = c[N - 1] - c[i + K - 1];
		ans = std::max(ans, std::max(0LL, among) + l + r);
	}

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

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

int main()
{
  int a,b,c; cin>>a>>b>>c;
  cout << min(b/a, c) << endl;

  return 0;
}


Measured memory_bytes: 256
from fractions import gcd
 
 
def get_difference():
	# get input from raw_input()
	n, k = map(int, raw_input().split(' '))
	l = [int(e) for e in raw_input().split(' ')]
	if k in l:
		print "POSSIBLE"
		return
	if k>max(l):
		print "IMPOSSIBLE"
		return
	gcd_v = reduce(gcd, l)
	if k%gcd_v==0:
		print "POSSIBLE"
	else:
		print "IMPOSSIBLE"
 
 
if __name__ == "__main__":
	get_difference()

Measured memory_bytes: 13148
#include <cstdio>
using namespace std;


int main(){
    int A,B,C,D,m;

    scanf("%d %d %d %d",&A,&B,&C,&D);

    if(A<=B) m=A;
    else m=B;

    if(C<=D) m=m + C;
    else m=m + D;

    printf("%d\n", m);

    return 0;
}

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

#define ll long long
#define vi vector<int>
#define vc vector<char>
#define vt vector<string>
#define si set<int>
#define sc set<char>
#define st set<string>
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back;

using namespace std;
int main()
{
    int k,x;
    cin>>k>>x;
    int tmp1=k;
    tmp1--;
    k--;
    si v;
    v.insert(x);
    for(int i=x-1;k--;i--)
        v.insert(i);
    for(int i=x+1;tmp1--;i++)
        v.insert(i);
    for(auto e:v)
            cout<<e<<" ";
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
const int dx4[4] = {1,0,-1,0};
const int dy4[4] = {0,1,0,-1};
const int dx8[8] = {-1,0,1,1,1,0,-1,-1};
const int dy8[8] = {1,1,1,0,-1,-1,-1,0};
typedef long long ll;
const int mod = 1e9+7;

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

  int h, w;
  cin >> h >> w;
  vector<string> field(h);
  rep(i,h) cin >> field[i];
  vector<vector<int>> dis(h, vector<int>(w, -1));
  dis[0][0] = 0;
  queue<P> que;
  que.push(make_pair(0,0));
  while(!que.empty()){
    int vy = que.front().first;
    int vx = que.front().second;
    que.pop();
    rep(i,4){
      int ny = vy + dy4[i];
      int nx = vx + dx4[i];
      if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
      if(dis[ny][nx] == -1 && field[ny][nx] == '.'){
        dis[ny][nx] = dis[vy][vx] + 1;
        que.push(make_pair(ny, nx));
      }
    }
  }
  int ans = h*w - (dis[h-1][w-1] + 1);
  int bluck = 0;
  rep(i,h)rep(j,w){
    if(field[i][j] == '#') bluck++;
  }
  ans -= bluck;
  if(dis[h-1][w-1] == -1) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b;
	if(a>b)
		swap(a,b);
	if(a==2)
		cout<<1;
	else if(b==3)
		cout<<2;
	else
		cout<<3;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];

    vi sum(n+1);
    vi num(1);
    rep(i, n) {
        sum[i+1] = sum[i] + a[i] - k;
        num.emplace_back(sum[i+1]);
    }
    sort(all(num));
    num.erase(unique(all(num)), num.end());
    rep(i, n+1) {
        auto itr = lower_bound(all(num), sum[i]);
        sum[i] = itr-num.begin();
    }

    vi bits(num.size()+1);
    auto add = [&](int i, int x) {
        while(i <= num.size()) {
            bits[i] += x;
            i += i&-i;
        }
    };
    auto bsum = [&](int i) {
        int res = 0;
        while(i) {
            res += bits[i];
            i &= i-1;
        }
        return res;
    };

    ll ans = 0;
    rep(i, n+1) {
        ans += bsum(sum[i]+1);
        add(sum[i]+1, 1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 9344
n=input()
dic={}
for i in range(1,int(n)+1):
  wkstr=str(i)[0]+str(i)[len(str(i))-1]
  if wkstr in dic:
    dic[wkstr]+=1
  else:
    dic[wkstr]=1
ans=0
for key in dic.keys():
  revkey=key[len(key)-1]+key[0]
  if key==revkey:
    ans+=dic.get(key)*dic.get(revkey)
  else:
    ans+=dic.get(key)*dic.get(revkey,0)
print(ans)

Measured memory_bytes: 3064
function Main(input) {
  var n = parseInt(input.split("\n")[0]);
  var h = input.split("\n")[1].split(" ");
  var flg = "Yes";
  for(var i=h.length-1; i>=0; i--){
  	if(parseInt(h[i])>parseInt(h[i+1])){
    	h[i]--;
      	if(parseInt(h[i])>parseInt(h[i+1]))flg = "No";
    }
  }
  console.log(flg);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int order(vector<int> a) {
  int ret = 0;
  while (next_permutation(a.begin(), a.end()))
    ++ret;
  return ret;
}

int main() {
  int n;
  cin >> n;
  vector<int> P(n), Q(n);
  for (int& p : P)
    cin >> p;
  for (int& q : Q)
    cin >> q;
  cout << abs(order(P) - order(Q)) << "\n";

  return 0;
}


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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    int N;
    string S;
    cin >> N >> S;
    if (N % 2 == 1)
    {
        cout << "No" << endl;
        return 0;
    }

    if (S.substr(0, N / 2) == S.substr(N / 2, N / 2))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bn begin()
#define en end()
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007
#define pi 3.141592653589
using namespace std;

int power(int x, int y) ;
int gcd(int a, int b) ;


signed main() {
    quickie
    int n, k ;
    cin >> n >> k ;
    int a[n] ;
    rep(i, 0, n) cin >> a[i] ;
    sort(a, a+n) ;
    int s =0 ;
    rep(i, 0, k) s += a[i] ;
    cout << s << "\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

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


Measured memory_bytes: 3624
import sys
sys.setrecursionlimit(10 ** 6)


N = int(input())
ans = []
a = ord('a')


def dfs(S, mx):
    global N
    if len(S) == N:
        ans.append(S)
    else:
        for c in range(0, mx + 2):
            dfs(S + chr(c + a), max(mx, c))


dfs('a', 0)
print(*ans, sep='\n')


Measured memory_bytes: 14464
from itertools import combinations
n = int(input())
P = []
for i in range(n):
    xy = list(map(int, input().split()))
    P.append(xy)

#全部の組み合わせの総合距離を求める
L = 0
for v in combinations(range(n), 2):
    V = list(v)
    L += ((P[V[0]][0] - P[V[1]][0])** 2 + (P[V[0]][1] - P[V[1]][1])** 2)** 0.5    

#ある区間が使われるのは2×(n-1)!通り　※例えば(1,2)をひとまとまりとすると順列は(n-1)!とおり(2,1)の順もあるので2倍する
#全部の順列はn!とおり
#よって答えは
print(L * 2 / n)

Measured memory_bytes: 3188
a, b, k = map(int, input().split())

for i in range(k):
    if i%2 == 0:
        if a%2 == 0:
            tmp = a//2
            b += tmp
            a = tmp
        else:
            tmp = (a-1)/2
            b += tmp
            a = tmp
    else:
        if b%2 == 0:
            tmp = b //2
            a += tmp
            b = tmp
        else:
            tmp = (b-1)//2
            a += tmp
            b = tmp
print(int(a), int(b))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans; 
}
void solve()
{
    int n,w;
    cin>>n>>w;
    ll a[n][2];
    int i,j;
    for(i=0;i<n;i++)
    {
        cin>>a[i][0];
        cin>>a[i][1];
    }
    ll dp[n][w+1];
    for(i=0;i<n;i++)
    {
        for(j=0;j<=w;j++)
        {
            if(i==0)
            {
                if(j>=a[i][0])
                {
                    dp[i][j]=a[i][1];
                }
                else
                {
                    dp[i][j]=0;
                }
            }   
            else if(j==0)
            {
                dp[i][j]=0;
            }
            else
            {
                if(j>=a[i][0])
                {
                    dp[i][j]=max(dp[i-1][j],a[i][1]+dp[i-1][j-a[i][0]]);
                }
                else
                {
                    dp[i][j]=dp[i-1][j];
                }
            }
        }
    }
    cout<<dp[n-1][w]<<nl;


}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    ll TC = 1;
    //cin>>TC;
    while(TC--){
        solve();
    }
}


Measured memory_bytes: 81620
#include <iostream>

using namespace std;

int main()
{
	long long a, b, x;
	cin >> a >> b >> x;
	
	long long ans = b / x;
	if(a % x == 0)
	{
		ans++;
	}
	ans -= a / x;


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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

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

    LL N,M; cin >> N >> M;
    LL ans1 = 1;
    LL ans2 = 1;
    if(abs(N-M) <= 1)
    {
        if(N == M)
        {
            for(LL i = 1; i < N+1; i++)
            {
                ans1 = (ans1 * i) % MOD;
            }
            for(LL i = 1; i < M+1; i++)
            {
                ans1 = (ans1 * i) % MOD;
            }

            ans1 = (ans1 * 2) % MOD;
            cout << ans1 << endl;
            return 0;
        }
        else
        {
            for(LL i = 1; i < N+1; i++)
            {
                ans1 = (ans1 * i) % MOD;
            }
            for(LL i = 1; i < M+1; i++)
            {
                ans1 = (ans1 * i) % MOD;
            }
            cout << ans1 << endl;
            return 0;

        }

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

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int r,c,k;
    cin>>r>>c>>k;
    vector<unordered_map<int,ll>> v(r);
    {
        int R,C,V;
        fr(i,k){
            cin>>R>>C>>V;
            --R,--C;
            v[R][C]=V;
        }
    }
    ll dp[3000][4]={},ndp[3000][4];
    dp[0][1]=v[0][0];
    fr(i,r){
        fr(j,c) fr(l,4) ndp[j][l]=0;
        fr(j,c) fr(l,4){
            if(i<r-1){
                chmax(ndp[j][0],dp[j][l]);
                chmax(ndp[j][1],dp[j][l]+v[i+1][j]);
            }
            if(j<c-1){
                chmax(dp[j+1][l],dp[j][l]);
                if(l<3) chmax(dp[j+1][l+1],dp[j][l]+v[i][j+1]);
            }
        }
        swap(dp,ndp);
    }
    cout<<max({ndp[c-1][0],ndp[c-1][1],ndp[c-1][2],ndp[c-1][3]})<<'\n';
}

Measured memory_bytes: 372924
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    vector<vector<int>> tree(n);
    for(int i=0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        tree[x].push_back(y);
        tree[y].push_back(x);
    }
    
    for(int i=0; i<n; i++){
        if(tree[i].size()==1){
            int cur=i;
            while(1){
                int p=tree[cur][0];
                if(tree[p].size()==2){
                    int q=tree[p][0]==cur?tree[p][1]:tree[p][0];
                    tree[cur].clear();
                    tree[p].clear();
                    tree[p].push_back(q);
                    cur=p;
                }
                else{
                    break;
                }
            }
        }
    }
    /*
    for(int i=0; i<n; i++){
        for(int j:tree[i]){
            if(i<j) cout<<i<<" "<<j<<endl;
        }
    }
    */
    vector<bool> visited(n,false);
    int myp=-1;
    int ct=0, pct=0;
    for(int i=0; i<n; i++){
        if(tree[i].size()==1 && !visited[i]){
            //pct++;
            int p=tree[i][0];
            int ctt=0;
            //cout<<p<<endl;
            for(int j:tree[p]){
                if(tree[j].size()==1){
                    visited[j]=true;
                    ctt++;
                    //cout<<j<<" ";
                }
            }
            if(ctt>=2){
                pct++;
                myp=p;
            }
            
            //cout<<ctt<<endl;
            //cout<<endl;
            ct+=ctt-1;
        }
    }
    /*
    if(!pct){
        cout<<1;
        return 0;
    }
    if(pct==1){
        
        
    }
    cout<<ct;
    */
    cout<<(pct?ct:ct+1);
   
    
    
    
  
    return 0;
}

Measured memory_bytes: 6272
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, m, x, y ] <- readInts
	xs <- readInts
	ys <- readInts
	let z = minimum ys
	putStrLn $ which "No War" "War" $  x < z && z <= y && all ( < z ) xs

Measured memory_bytes: 508