akhauriyash/Code-Regression huggingface dataset:
# EDPC-B.py
import sys
input = sys.stdin.readline

N,K=map(int,input().split())
import numpy as np
hights=np.array(list(map(int,input().split())))
steps=np.array([10**10]*N)
steps[0]=0
for i in range(N-1):
    gaps=hights[i+1:i+K+1]-hights[i]
    gaps=np.abs(gaps)
    gaps+=steps[i]
    steps[i+1:i+K+1]=np.minimum(steps[i+1:i+K+1],gaps)
print(steps[-1])

"""
例えば、入力が
5 3
10 30 40 50 20
のとき

一回目の操作で、(i=0)
hights[0+1:0+3+1] = [30, 40, 50]
hights[0] = 10
gaps = [20, 30, 40]
gaps += steps[0] (=0)
np.minimum([inf, inf, inf], [20, 30, 40])
-> steps = [0, 20, 30, 40, inf, inf...] # これでsteps[1]は 10->30 のみできまる。

これを１つずつずらしていく。
i=1のとき
hights[1+1:1+3+1] = [40, 50, 20]
hights[1] = 30
gaps = [10, 20, 10]
gaps += steps[1] (=20) # steps[1]への最小の方法
np.minimum([30, 40, inf], [30, 40, 30])
-> steps = [0, 20, 30, 40, 30, inf...] # これでsteps[2]は 10->30->40 と 10->40を比較したことになる。

i=2のとき
hights[2+1:2+3+1] = [50, 20]
hights[2] = 40
gaps = [10, 20]
gaps += steps[2] (=30)
np.minimum([40, 30], [40, 50])
-> steps = [0, 20, 30, 40, 30] # これでsteps[3]は min(40)->50 と min(30)->50 と min(10)->50 を比較したことになる。
.
.
.

"""

Measured memory_bytes: 23056
W, H, N = map(int, input().split())
max1=0
min2=W
max3=0
min4=H
for i in range(N):
    x, y, a = map(int, input().split())
    if (a==1 and max1<x):
        max1=x
    elif(a==2 and min2>x):
        min2=x
    elif(a==3 and max3<y):
        max3=y
    elif(a==4 and min4>y):
        min4=y

if (max1>=min2 or max3>=min4):
    print(0)
else:
    print((min2-max1)*(min4-max3))

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

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

  int a,p;cin>>a>>p;
  cout<<(a*3+p)/2<<endl;
  
  return 0;
}


Measured memory_bytes: 3616
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    
    int[] ans = new int[N+1];
    for (int i = 0; i < M; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      ans[a]++;
      ans[b]++;
    }
    for (int i = 1; i <= N; i++) {
      System.out.println(ans[i]);
    }
  }
}

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

ll add(ll x,ll y,ll mod){return (x+y)%mod;}
ll mul(ll x,ll y,ll mod){return (x*y)%mod;}

ll mpow(ll x,ll y,ll mod){
  ll v=1;
  for(;y;x=mul(x,x,mod),y>>=1)
    if(y&1)v=mul(v,x,mod);
  return v;
}

ll divi(ll x,ll y,ll mod){return mul(x,mpow(y,mod-2,mod),mod);}

ll ncr[5000][5000];

ll nCr(ll n,ll r,ll mod){
  if(n==r)return 1;
  if(r==0)return 1;
  if(ncr[n][r])return ncr[n][r];
  ncr[n][r]=(nCr(n-1,r-1,mod)+nCr(n-1,r,mod))%mod;
  return ncr[n][r];
}


/*

void solve(){
  map<int,int> mp;
  vector<ll> v;
  for(int i=1;i<8;i++)v.push_back(i);
  
  int size=v.size();
  for(int i=0;i<(1<<size);i++){
    ll A=0;
    bool flag=true;
    for(int j=0;j<size;j++){
      if(i>>j&1){
        if( (A&v[j]) > 0 )flag=false;
        A|=v[j];
      }
    }
    if(flag){
      int w= __builtin_popcount(i);
      mp[ w ] ++;
    }
  }
  for(int i=0;i<=8;i++){
    cout<<i<<' '<<mp[i]<<endl;
  }

}
*/

ll N,M;
ll dp[3005][3005];

void solve(){
  for(int i=0;i<3005;i++)
    for(int j=0;j<3005;j++)
      dp[i][j]=0;
  
  dp[0][0]=1;
  for(int i=0;i<N+1;i++){
    for(int j=0;j<N+1;j++){
      dp[i][j+1]+=dp[i][j];
      dp[i][j+1]+=dp[i][j]*i;
      dp[i][j+1]%=M;
      
      dp[i+1][j+1]+=dp[i][j];
      dp[i+1][j+1]%=M;
    }
  }
}

int main(){
  
  cin>>N>>M;
  solve();

  ll count= mpow(2, N, M-1 );
  
  ll base = mpow( 2, count, M );

  ll ans=0;
  for(int i=1;i<=N;i++){
    
    ll other = mpow( 2, N-i, M-1);
    ll p_other = mpow( 2, other ,M);

    other = mpow( 2, N-i, M);
    ll val=1;
    for(int j=1;j<=N;j++)
      val = add(val ,  dp[j][i]*mpow(other,j,M)   ,M);

    ll tmp= mul( val, p_other , M);
    ll k=nCr(N,i,M);
    tmp=mul(tmp,k, M);
    if(i%2==1)ans=add(ans,tmp, M);
    else ans=add(ans, M-tmp, M);
    
  }

  cout<< add( base, M - ans , M) <<endl;
  return 0;
}


Measured memory_bytes: 188800
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;
typedef long long ll;


struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a){
        return mint(v) *= a;
    }

    mint operator+(mint a){
        return mint(v) += a;
    }

    mint operator-(mint a){
        return mint(v) -= a;
    }

    mint pow(long long k){
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};


int main(){
    string s;
    getline(cin, s);

    vector<mint> dp(s.size());
    dp.at(s.size() - 1) = (s.back() == '1') ? 3 : 1;
    mint pow3(3);
    for(int i = s.size() - 2; i >= 0; --i){
        if(s.at(i) == '1'){
            dp.at(i) = dp.at(i + 1) * 2 + pow3;
        }else{
            dp.at(i) = dp.at(i + 1);
        }
        pow3 *= 3;
    }
    cout << dp.at(0).v << endl;
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
vector<ll> a , p;
ll f(ll n , ll x){
	if(n == 0){
        return ((x <= 0) ? 0 : 1);
    }
	else if(x <= 1 + a[n - 1]){
        return f(n - 1 , x - 1);
    }
	else{
        return p[n - 1] + 1 + f(n - 1 , x - 2 - a[n - 1]);
    }
}
int main(){
	ll n , x;
	cin >> n >> x;
	a.push_back(1);
	p.push_back(1);
	for(int i = 0; i < n; i++){
		a.push_back(a[i] * 2 + 3);
		p.push_back(p[i] * 2 + 1);
	}
	cout << f(n , x) << endl;
	return 0;
}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int l = s.length();

		System.out.print(s.charAt(0));
		System.out.print(l-2);
		System.out.print(s.charAt(l-1));

	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int n, a[100010];
int main() {
	scanf("%d", &n);
	for(int i=1; i<=n; i++) scanf("%d", a+i);
	sort(a+1, a+n+1);
	int mn = 2e9, idx = 0;
	for(int i=1; i<n; i++) {
		if(a[n] % 2) {
			int v = min(abs(a[n] / 2 - a[i]), abs(a[n] / 2 + 1 - a[i]));
			if(v < mn) mn = v, idx = i;
		} else {
			int v = abs(a[n] / 2 - a[i]);
			if(v < mn) mn = v, idx = i;
		}
	}
	printf("%d %d", a[n], a[idx]);
	return 0;
}

Measured memory_bytes: 640
int main() {

	int a;
	int b;

	scanf( "%d%d" , &a , &b );
	if ( a < b ) {
		printf( "a < b\n" );
	} else if ( a > b ) {
		printf( "a > b\n" );
	} else printf( "a == b\n");

	return 0 ;

}


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

int main(void)
{
	int x, y;
	cin >> x >> y;

	if (x == 2 || y == 2 || x == 11 )
		cout << "No" << endl;
	else if (x == 4 || x == 6 || x == 9) {
		if (y == 6 || y == 9 || y == 11)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	else if (y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) {
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    ll K,N;
    cin >> K >> N;
    vector<ll> A(N);
    ll dst = 0;
    rep(i,N) cin >> A[i];
    for(int i=0;i<N-1;i++){
        dst = max(dst,A[i+1]-A[i]);
    }
    dst = max(dst,K-A[N-1]+A[0]);
    cout << K-dst << endl;
    return 0;
}

Measured memory_bytes: 1792
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	for n := getNextInt(scanner); n > 0; n = getNextInt(scanner) {
		sum := 0
		for j := 0; j < n/4; j++ {
			sum += getNextInt(scanner)
		}
		fmt.Fprintln(writer, sum)
	}
}



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

int main(void){
	while(1){
		int w,ans=1150;
		cin >> w;
		if(w==-1)break;
		if(w>=10)ans+=125*(w-10);
		if(w>=20)ans+=15*(w-20);
		if(w>=30)ans+=20*(w-30);
		cout << 4280-ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	private final static long MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long K = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();

		long count = K + 1 - A;
		long bis = A;
		for (int i = 0; i < count / 2; i++) {
			bis += B - A;
		}
		bis += count % 2;

		System.out.println(Math.max(K + 1, bis));
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;
		private StringBuilder buffer = new StringBuilder();

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			int read = skip();
			do {
				buffer.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			String text = buffer.toString();
			buffer.delete(0, buffer.length());

			return text;
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 21460
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    int N;cin>>N;
    int base;cin>>base;
    ll ans = 0;
    for(int i=1;i<N;i++){
        int a;cin>>a;
        if(a<=base) ans += base - a;
        else base = a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<int,int>
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define FORR(I,A,B) for(int I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
int gcd(int a,int b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
int lcm(int a,int b){int c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,wa=0,maxp=0;
	cin >> n;
	FOR(i,0,n){
		int k ;
		cin >> k;
		wa += k;
		maxp = max(maxp,k);
	}
	cout << wa - maxp/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

int main(){
    ll a,b;
    cin>>a>>b;
    cout<<(a-1)*(b-1);

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;
const int maxn=100100;
int n;
char sz[maxn];
int main(){
    scanf("%s",sz+1);
    n=strlen(sz+1);
    if(sz[n]=='1'||sz[1]=='0'||sz[n-1]=='0'){
        printf("-1\n");
        return 0;
    }
    for(int i=2;i<=n-1;i++){
        if(sz[i]!=sz[n-i]){
            printf("-1\n");
            return 0;
        }
    }
    int root=2,num=1,now=2;
    printf("2 1\n");
    while(now<=n-now){
        if(sz[now]=='1'){
            printf("%d %d\n",++now,root);
            root=now;
        }else{
            printf("%d %d\n",++now,root);
        }
        num++;
    }
    for(int i=num+1;i<n;i++){
        printf("%d %d\n",root,++now);
    }
    return 0;
}


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

void swap(int x[],int i,int j){
	int tmp=x[i];
	x[i]=x[j];
	x[j]=tmp;
}
void Qsort(int x[],int left,int right){
	int i,j;
	int pivot;

	i=left;
	j=right;

	pivot=x[(left+right)/2];

	while(true){
		while(x[i]<pivot)i++;
		while(x[j]>pivot)j--;
		if(i>=j)break;
		swap(x,i,j);
		i++;
		j--;
	}
	if(left<i-1)Qsort(x,left,i-1);
	if(j+1<right)Qsort(x,j+1,right);
}

int main(void){
	int n,c,k;
	int *t;

	scanf("%d%d%d",&n,&c,&k);
	t=(int *)malloc(sizeof(int)*n);

	for(int i=0; i<n; i++){
		scanf("%d",&t[i]);
	}
	Qsort(t,0,n-1);
	int current=t[0],cnt=1;
	int ans=1;
	//for(int i=0; i<n; i++)printf("t[%d]=%d ",i,t[i]);
	for(int i=1; i<n; i++){
		//printf("cnt=%d,current=%d,t[%d]=%d\n",cnt,current,i,t[i]);
		if(cnt==c || current+k<t[i]){
			ans++;
			current=t[i];
			cnt=1;
		}
		else cnt++;
	}

	printf("%d\n",ans);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

signed main() {
  int N, K; cin >> N >> K;
  vector<int> vec(N, 0);
  rep(i, K) {
    int d; cin >> d;
    rep(j, d) {
      int a; cin >> a;
      vec[a-1]++;
    }
  }

  int ans = 0;
  
  rep(i, N) if(vec[i] == 0) ans++;

  cout << ans << endl;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int a, b;
  cin >> a >> b;
  cout << ((a * b) % 2 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;

signed main(){
	ll n,k; cin>>n>>k;
	ll m=0;
	vl a(n); rep(i,0,n)cin>>a[i],chmax(m,a[i]);
	ll left=0;
	ll right=m;
	while(right-left>1){
		ll mid=(right+left)/2;
		ll cnt=0;
		rep(i,0,n){
			cnt+=(a[i]+mid-1)/mid-1;
		}
		if(cnt<=k)right=mid;
		else left=mid;
	}
	cout<<right<<endl;



	return 0;
}

Measured memory_bytes: 4740
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define MAX 30
int N,M;
int graph[MAX][MAX];
void solve(int *ans,int *stamp,int k){
    int f = 1;
    stamp[k] = 1;
    for(int i=1;i<=N;i++){
        if(stamp[i] == 0){
            f = 0;
            break;
        } 
    }
    if(f){
        (*ans)++;
        return;
    }

    for(int i=1;i<=N;i++){
        if(stamp[i] == 0 && (graph[k][i] || graph[i][k])){
            solve(ans,stamp,i);
            stamp[i] = 0;
        }
    }
}
int main(){
    int a[MAX],b[MAX];
    int stamp[MAX]={0};
    memset(graph,0,sizeof(graph));
    scanf("%d %d",&N,&M);
    for(int i=1;i<=M;i++){
        scanf("%d %d",a+i,b+i);
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = 1; 
    }
    int ans = 0;
    solve(&ans,stamp,1);
    printf("%d",ans);
}


Measured memory_bytes: 1704
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N; cin >> N;
    ll A[200200];
    rep(i, N) {
        ll a; cin >> a;
        A[i] = a - i - 1;
    }
    sort(A, A + N);
    int k = (N + 1) / 2 - 1;
    ll ans = 0;
    rep(i, N) {
        ans += abs(A[k] - A[i]);
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long int N,i,A,B,C,D,E,ans;
    cin >> N;
    if(N == 1){
        cout << 0 << endl;
    }
    else{
        // 0,9が両方とも存在しないものを引く
        A = 1;
        for(i = 0;i < N;i++){
            A = (A * 10) % 1000000007;
        }
        B = 1;
        for (i = 0; i < N; i++){
            B = (B * 9) % 1000000007;
        }
        C = 1;
        for (i = 0; i < N; i++){
            C = (C * 8) % 1000000007;
        }
        D = (A - B + 1000000007) % 1000000007;
        E = (((D * 2) % 1000000007) + C) % 1000000007;
        ans = (E - A + 1000000007) % 1000000007;
        cout << ans << endl;
    }
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005


int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
  int a,b;
  cin >> a >> b;
  if(a>9 || b>9)cout << -1;
  else{
cout << a*b;
  }
        

}


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

using namespace std;

int main()
{
    unsigned long long a, b, k;
    cin >> a >> b >> k;

    bool aa = true;
    while (k--)
    {
        if (aa) b += (a/=2);
        else a += (b/=2);
        aa ^= 1;
    }

    cout << a << ' ' << b;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b1, b2;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < n; i++) {
    if (i & 1)
      b1.push_back(a[i]);
    else
      b2.push_back(a[i]);
  }

  if (n & 1) {
    reverse(b2.begin(), b2.end());
    for (int i = 0; i < n; i++) {
      if (i < b2.size()) {
        cout << b2[i];
      } else {
        cout << b1[i - b2.size()];
      }
      if (i < n - 1) {
        cout << ' ';
      } else {
        cout << '\n';
      }
    }
  } else {
    reverse(b1.begin(), b1.end());
    for (int i = 0; i < n; i++) {
      if (i < b1.size()) {
        cout << b1[i];
      } else {
        cout << b2[i - b1.size()];
      }
      if (i < n - 1) {
        cout << ' ';
      } else {
        cout << '\n';
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='C'){
            for(int j=i+1;j<s.size();j++){
                if(s[j]=='F'){
                    cout<<"Yes";
                    return 0;
                }
            }
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define _GLIBCXX_DEBUG
static const int MAX = 20;


int main(){
  int A, B, x, count = 0;
  cin >> A >> B;
  x = A;
  rep2(i, 1, B){
    if(B == 1) break;
    if(x >= B){
      count = i;
      break;
    }
    x += (A-1);
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int A, B;
    scanf("%d %d", &A, &B);
    A = (A == 1) ? 14 : A;
    B = (B == 1) ? 14 : B;
    if(A > B){
        printf("Alice\n");
    }else if(A < B){
        printf("Bob\n");
    }else{
        printf("Draw\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

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

struct UnionFind{
    int sz;     // vertex number
    vector<int> par;
    vector<int> rank;

    UnionFind(int n) : sz(n) {
        par.resize(sz);
        rank.assign(sz, 0);
        for(int i = 0; i < sz; ++i){
            par[i] = i;
        }
    }

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

    bool same(int x, int y){
        return find(x) == find(y);
    }

    void unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y)  return;
        if(rank[x] < rank[y])   par[x] = y;
        else{
            par[y] = x;
            if(rank[x] == rank[y])  ++rank[x];
        }
    }
};

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

    int N, Q;
    cin >> N >> Q;
    UnionFind uf(N);
    for(int i = 0; i < Q; ++i){
        int t, u, v;
        cin >> t >> u >> v;
        if(t)   cout << uf.same(u, v) << '\n';
        else    uf.unite(u, v);
    }
}

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


int main() {
    int N;
    cin >> N;
    int p[4], t[4];
    rep(i, 4) cin >> p[i];
    rep(i, 4) cin >> t[i];

    int ans = 1e8;
    rep(a, 101) rep(b, 101) rep(c, 101) rep(d, 101) {
        if (a*t[0] + b*t[1] + c*t[2] + d*t[3] >= N) {
            ans = min(ans, a*p[0] + b*p[1] + c*p[2] + d*p[3]);
        }
    }
    cout << ans << endl;

    return 0;
}



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


const int MAX = 10000;
const int NIL = -1;

struct Node {
    int p;
    int l;
    int r;
};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d){
    if (u == NIL) return;
    D[u] = d;
    setDepth(T[u].l, d+1);
    setDepth(T[u].r, d+1);
}

int setHeight(int u){
    int h1 = 0, h2 = 0;
    if(T[u].l != NIL) h1 = setHeight(T[u].l) + 1;
    if(T[u].r != NIL) h2 = setHeight(T[u].r) + 1;
    return H[u] = max(h1, h2);
}

int getDegree(int u){
    int degree = 0;
    if(u == NIL) return NIL;
    if(T[u].l != NIL) degree++;
    if(T[u].r != NIL) degree++;
    return degree;
}

int getSibling(int u){
    int p = T[u].p;
    if( p == NIL ) return NIL;
    if(T[p].r != NIL && T[p].l != NIL) return T[p].l + T[p].r - u;
    else return NIL;
}


void print(int u){
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "sibling = " <<  getSibling(u) << ", ";
    cout << "degree = " << getDegree(u) << ", ";
    cout << "depth = " << D[u] << ", ";
    cout << "height = " << H[u] << ", ";

    if(T[u].p == NIL) cout << "root\n";
    else if(T[u].l == NIL && T[u].r == NIL) cout << "leaf" << endl;
    else cout << "internal node" << endl;
}


int main(){
    int v, l, r, root = 0;
    cin >> n;

    for(int i=0; i<n; i++) T[i].p = NIL;

    for(int i=0; i<n; i++){
        cin >> v >> l >> r;
        T[v].l = l;
        T[v].r = r;
        if(l != NIL) T[l].p = v;
        if(r != NIL) T[r].p = v;
    }

    for(int i=0; i<n; i++) {
        if(T[i].p == NIL) root = i;
    }
    
    setDepth(root, 0);
    setHeight(root);

    for(int i=0; i<n; i++) print(i);
    



    return 0;
}

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

# In[12]:


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


# In[15]:


dist = []
for i in range(1,len(A)):
    dist.append(A[i]-A[i-1])
dist.append(K+A[0] - A[-1])
print(K-max(dist))


# In[ ]:






Measured memory_bytes: 26444
from collections import Counter

def solve():
    n = int(input())
    c = list(map(lambda p: p[1], sorted(Counter(int(si) for si in input().split()).items())))
    if c[-1] != 1:
        print('No')
        return
    c.pop()
    dp = [0] * (n + 1)
    dp[0] = 1
    for cnt in reversed(c):
        dp_next = [0] * (n + 1)
        for j in range(n):
            consume = dp[j] if dp[j] < cnt else cnt
            cnt -= consume
            dp_next[j] += dp[j] - consume
            dp_next[j + 1] += consume
            dp[j + 1] += consume
        if cnt != 0:
            print('No')
            return
        dp = dp_next
    print('Yes')
    return

if __name__ == '__main__':
    solve()


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

int h,w;
string s[100];
int dx[]={0, 1, 1, 1, 0, -1, -1, -1};
int dy[]={1, 1, 0, -1, -1, -1, 0, 1};

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

  cin>>h>>w;
  for(int i=0;i<h;i++)cin>>s[i];

  for(int y=0;y<h;y++){
    for(int x=0;x<w;x++){
      if(s[y][x]=='#'){
        cout<<'#';
      } else {
        int t=0;
        for(int i=0;i<8;i++){
          int nx=x + dx[i];
          int ny = y + dy[i];
          if(0<=nx&&nx<w&&0<=ny&&ny<h&&s[ny][nx]=='#')t++;
        }
        cout<<t;
      }
    }
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
h = {}
n.times do
  s = gets
  h[s.chomp] = 1
end

for m in ["S", "H", "C", "D"] do
  for i in 1..13 do
    puts "#{m} #{i}" if !h.has_key?(m+" "+i.to_s)
  end
end

Measured memory_bytes: 8624
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String line = scan.nextLine();
    int max = Integer.parseInt(line.split(" ")[0]);
    int target =Integer.parseInt(line.split(" ")[1]);
    line = scan.nextLine();
    char ch = line.charAt(target-1);
    ch = (char) (ch + 0x20);
    System.out.print(line.substring(0, target-1)+ ch + line.substring(target,max) );

  }

}

Measured memory_bytes: 21972
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define mrep(p,mp) for(auto p : mp)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
int a,b,c;
cin >>a >>b >>c;
vector<int> s(3);
s[0] = a;
s[1] = b;
s[2] = c;
sort(s.begin(),s.end());
int count = 0;
while(!(a==b && b==c) || count%2==1){
    count++;
    if(a<=b && a<=c) a++;
    else if(b<=a && b<=c) b++;
    else c++;
}
count /= 2;
cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 305
#define ll long long
using namespace std;
ll read(){
	ll x=0,c;while(!isdigit(c=getchar()));
	while(x=x*10+c-'0',isdigit(c=getchar()));
	return x;
}
ll n,k,a[maxn][maxn],f[maxn][maxn];
ll Mod;
int main(){
	n=read();k=read();Mod=read();
	for(ll i=1;i<maxn;i++)f[i][1]=1;
	for(ll i=1;i<maxn;i++)f[0][i]=1;
	a[0][0]=1;
	for(ll i=1;i<maxn;i++)
		for(ll j=0;j<=i;j++){
		a[i][j]=a[i-1][j];
		if(j)a[i][j]=(a[i][j]+a[i-1][j-1]*(i-j+1)%Mod)%Mod;
	}
	for(ll i=1;i<maxn;i++)
		for(ll j=2;j<maxn;j++)
			for(ll t=0;t<=i;t++)
				f[i][j]=(f[i][j]+f[i-t][j-1]*a[i][t])%Mod;
	printf("%lld\n",f[n][k]);
	return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <string.h>
#include <vector>

using namespace std;
int main() {
    int P, Q, R;
    cin >> P >> Q >> R;
    cout << P + Q + R - max({P, Q, R}) << endl;

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;

int main() {
  string N;
  ll sum = 0;
  cin >> N;
  for(ll i = 0; i < N.size(); i++) {
    sum += (ll)(N.at(i) - '0');
  }
  if(sum % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3720
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<map>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const ll mod = 1000000007;
const ll INF = mod * mod;

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define stop char nyaa;cin>>nyaa;

struct edge {
	int to; ll cost;
};
vector<edge> G[300];

ll dist[300];
ll ans[300][300];
void solve() {
	int n, m;ll l; cin >> n >> m >> l;
	rep(i, m) {
		int a, b, c; cin >> a >> b >> c; a--; b--;
		G[a].push_back({ b,c });
		G[b].push_back({ a,c });
	}
	rep(i, n) {
		fill(dist, dist + n, INF);
		priority_queue<LP, vector<LP>, greater<LP>> q;
		q.push({ 0,i }); dist[i] = 0;
		while (!q.empty()) {
			LP p = q.top(); q.pop();
			int id = p.second;
			if (p.first > dist[id])continue;
			rep(j, G[id].size()) {
				if (G[id][j].cost > l)continue;
				ll d = p.first / l;
				ll nd = p.first + G[id][j].cost;
				if (nd > (d + 1)*l) {
					nd = (d + 1)*l + G[id][j].cost;
				}
				int to = G[id][j].to;
				if (nd < dist[to]) {
					dist[to] = nd;
					q.push({ nd,to });
				}
			}
		}
		rep(j, n) {
			if (dist[j] == INF)ans[i][j] = -1;
			else ans[i][j] = (dist[j]-1) / l;
		}
	}
	int q; cin >> q;
	rep(i, q) {
		int s, t; cin >> s >> t; s--; t--;
		cout << ans[s][t] << endl;
	}
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();

	//stop
	return 0;
}


Measured memory_bytes: 4460
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        String s = sc.next();
        
        int count = 0;
        int[] x = new int[n];
        for(int i = 0; i < n; i++){
            x[i] = Integer.parseInt(s.substring(i, i+1));
        }
        for(int i = 0; i <= 9; i++){
            for(int j = 0; j <= 9; j++){
                for(int k = 0; k <= 9; k++){
                    int a = 0;
                    while(a < n){
                        if(x[a] == i){
                            a++;
                            break;
                        }
                        a++;
                    }
                    while(a < n){
                        if(x[a] == j){
                            a++;
                            break;
                        }
                        a++;
                    }
                    while(a < n){
                        if(x[a] == k){
                            count++;
                            break;
                        }
                        a++;
                    }
                }
            }
        }
        
        System.out.println(count);
    }
}

Measured memory_bytes: 25912
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
//printf("%.10f\n", n);
ll yo[12345678], ta[12345678];
signed main() {
    ll n = 0, m;
    string s; cin >> s;
    if (s.size() % 2 == 1) { cout << "No" << endl; return 0; }
    for (int h = 0; h < s.size(); h++) {
        if (h % 2 == 0) {
            if (s[h] != 'h') { n++; }
        }
        else {
            if (s[h] != 'i') { n++; }
        }
    }
    if (n == 0) { cout << "Yes" << endl; }
    else { cout << "No" << endl; }
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

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

int main() {
	int N, X;
	vector<int> v;

	cin >> N >> X;
	for (int i = 0; i < N; i++)
	{
		int tmp;
		cin >> tmp;
		v.push_back(abs(X - tmp));
	}

	int ans=v.at(0);

	for (int i = 1; i < N; i++)
	{
		ans = gcd(max(v.at(i), ans),min(v.at(i), ans));
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 892
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i, N) cin >> H[i];
    for(int i = N - 1; i >= 0; i--) {
        if(H[i + 1] + 1 == H[i])
            H[i]--;
    }
    rep(i, N - 1) {
        if(H[i + 1] < H[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

#define tc(t) int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int cnt = 0;
    string s;
    for (int i = 1; i <= n; ++i) {
        s = to_string(i);
        if (s.length() % 2 != 0) cnt++;
    }
    cout << cnt << endl;

}






Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    m = n-(n>>1);

    long double res = (long double)m/(long double)n;

    cout<<fixed;
    cout.precision(9);

    cout<<res<<"\n";

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstdlib>

using namespace std;

int n, k;
int x[111111];

int solve(int x[]) {
  int z = -1;
  for (int i = 0; i < n; i++) {
    if (z < 0 && x[i] > 0) {
      z = i;
      break;
    }
  }

  int res = 1145141919;
  for (int i = 0; i < n; i++) {
    int a = k;
    if (i < z) {
      a -= z - i;
    } else if (z == -1) {
      a -= n - i;
    }

    // printf("%d %d\n", a, s);
    if (z != -1 && z + a - 1 >= n) continue;
    if (z == -1 && a > 0) continue;
    if (a > 0) {
      res = min(res, abs(x[i]) + abs(x[z + a - 1] - x[i]));
    } else {
      res = min(res, abs(x[i]));
    }
  }
  return res;
}

int main(void) {
  scanf("%d%d", &n, &k);
  int z = -1;
  for (int i = 0; i < n; i++) scanf("%d", x+i);
  int res = solve(x);
  for (int i = 0; i < n; i++) x[i] = -x[i];
  reverse(x, x+n);
  printf("%d\n", min(res, solve(x)));
  return 0;
}


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

using namespace std;

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

struct Point {
	double x, y;

	Point() = default;
	Point(double x_, double y_) : x(x_), y(y_) {}

	Point operator+(const Point& rhs) const { return Point(x + rhs.x, y + rhs.y); }
	Point operator-(const Point& rhs) const { return Point(x - rhs.x, y - rhs.y); }

	double length() const { return sqrt(x * x + y * y); }
	double distanceFrom(const Point& rhs) const { return (*this - rhs).length(); }

	friend istream& operator>>(istream& is, Point& rhs) { return is >> rhs.x >> rhs.y; }
};

struct Circle {
	Point p;
	double r;

	Circle() = default;
	Circle(const Point& p_, double r_) :p(p_), r(r_) {}

	bool contains(const Point& rhs) const {
		return p.distanceFrom(rhs) < r + 1e-8;
	}

	vector<Point> intersections(const Circle& rhs) const {
		double d = p.distanceFrom(rhs.p), r1 = rhs.r;
		if (d > r + r1 + 1e-8 || fabs(r - r1) > d + 1e-8) return vector<Point>();
		else {
			double theta = acos((d * d + r * r - r1 * r1) / (2 * d * r));
			double a = atan2(rhs.p.y - p.y, rhs.p.x - p.x);
			vector<Point> res;
			for (int i = -1; i <= 1; i += 2) {
				res.emplace_back(p + Point(r * cos(a + i * theta), r * sin(a + i * theta)));
			}
			return res;
		}
	}

	friend istream& operator>>(istream& is, Circle& cir) { return is >> cir.p >> cir.r; }
};

int n, k;
Circle cir[60];
double rad[60];

int g(const Point& p) {
	int res = 0;
	rep(i, n) {
		if (cir[i].contains(p)) ++res;
	}
	return res;
}

bool f() {
	rep(i, n) {
		if (k <= g(cir[i].p)) return true;
	}

	rep(i, n - 1) {
		const Circle& c = cir[i];
		repn(j, i + 1, n) {
			for (const Point& c1 : c.intersections(cir[j])) {
				if (k <= g(c1)) return true;
			}
		}
	}
	return false;
}

void update(double t) {
	rep(i, n) {
		cir[i].r = t / rad[i];
	}
}

int main() {
	cin >> n >> k;
	rep(i, n) {
		cin >> cir[i];
		rad[i] = cir[i].r;
	}
	double l = 0.0, r = 5.0 * 1e5, eps = 1e-7;
	while (fabs(r - l) > eps) {
		double mid = 0.5 * (l + r);
		update(mid);
		if (f()) r = mid;
		else l = mid;
	}
	printf("%.7lf\n",r);
}

Measured memory_bytes: 4428
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn search(g: &Vec<Vec<usize>>, i: usize, seen: &mut Vec<bool>, ans: &mut usize) {
    if seen[i] {
        return;
    }

    seen[i] = true;
    let mut ok = true;
    for i in 0..seen.len() {
        ok &= seen[i];
    }
    if ok {
        *ans += 1;
        seen[i] = false;
        return;
    }

    for &n in g[i].iter() {
        search(g, n, seen, ans);
    }
    seen[i] = false;
}

fn main() {
    input!{
      n: usize,
      m: usize,
      aa: [(usize, usize); m],
    }

    let mut g = vec![vec![]; n+1];
    for &(a, b) in aa.iter() {
        g[a].push(b);
        g[b].push(a);
    }
    let mut seen = vec![false; n+1];
    seen[0] = true;

    let mut ans = 0;
    search(&g, 1, &mut seen, &mut ans);
    println!("{}", ans);
}


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

int a[200010], b[200010], n;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cin >> n;
    for(int i = 1; i <= n; ++i) {cin >> a[i]; b[i] = a[i];}
    sort(a + 1, a + n + 1);
    int mid = n / 2 + 1;
    for(int i = 1; i <= n; ++i) {
        if(b[i] < a[mid]) cout << a[mid];
        else cout << a[mid - 1];
        cout << endl;
    }
    return 0;
}

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

void solve(long long N, std::vector<long long> A, std::vector<long long> B,
           std::vector<long long> C) {
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
   sort(C.begin(),C.end());
   vector<long long> B_A;
  B_A.push_back(0);
   for(int i  = 0;i<N;i++){
      B_A.push_back(lower_bound(A.begin(),A.end(),B[i])-A.begin());
   }
// for(auto x:B)cout<<x<<" ";
 //  cout<<"\n";
 // for(auto x:A)cout<<x<<" ";
 // cout<<"\n";
 // for(auto x:B_A)cout<<x<<" ";
 // cout<<"\n";
   for(int i = 1;i<N+1;i++){B_A[i]+=B_A[i-1];}
  long long  rick = 0;
    for(int i  =0;i<N;i++){
      auto it1  = lower_bound(B.begin(),B.end(),C[i]);
    // cout<<"posA"<<i<<it1-B.begin()<<"\n";
      // cout<<"posA"<<i<<"posB"<<B_A[it1-B.begin()-1]<<"\n";
        rick+=B_A[it1-B.begin()];
    }
    cout<<rick;
  }

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  std::vector<long long> B(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &B[i]);
  }
  std::vector<long long> C(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &C[i]);
  }
  solve(N, std::move(A), std::move(B), std::move(C));
  return 0;
}



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

int main()
{    
    int H, W;

    while(1){

        cin >> H >> W;

        if(H==0 && W==0){
            break;
        }

        for(int i=0; i<H; i++){
            if(i%2==0){
                for(int j=0; j<W; j++){
                    cout << '#';
                    j++;
                    if(j==W){
                        break;
                    }
                    cout << '.';
                }
            }
            else{
                for(int j=0; j<W; j++){
                    cout << '.';
                    j++;
                    if(j==W){
                        break;
                    }
                    cout << '#';
                }
            }
            cout << "\n";
        }
        cout << "\n";

    }

    return 0;
}


Measured memory_bytes: 3068