akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;
#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;}
template<class T> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T lcm(T a,T b){return a*b/gcd(a,b);}

const ll INF = 1LL << 60;



//大文字小文字気をつけろ


int main(){
  string s;
  bool a=1;
  cin >> s;
  reverse(s.begin(),s.end());
  FOR(i,s.size()){
    if(s.substr(i,5)=="maerd"){i+=4;}else
    if(s.substr(i,5)=="esare"){i+=4;}else
    if(s.substr(i,6)=="resare"){i+=5;}else
    if(s.substr(i,7)=="remaerd"){i+=6;}else{
      a=0;
    }
  }

  if(a){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 512
n = int(input())
s = input()
one = ''
two = ''


if n % 2 != 0:
  print('No')

else:
  for i in range(int(n/2)):
    one += s[i]
    two += s[i+int(n/2)]
  
  if one == two:
    print('Yes')
  else:
    print('No')

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

int n,a[201001],l,r,mid,ans,fa[201001];

int getup(int x) {int L=1; for (; L<=x; L<<=1); return L;}
int ask(int x) {return fa[x]==x?x:fa[x]=ask(fa[x]);}

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n),a[0]=a[n+1]=0;
	for (int i=0; i<=n+1; i++) fa[i]=i;
	for (int i=n; i; i--)
		if (fa[i]==i)
		{
			int t=getup(a[i])-a[i];
			l=1,r=i-1,ans=0;
			while (l<=r)
			{
				mid=(l+r)>>1;
				if (a[mid]>=t) ans=mid,r=mid-1; else l=mid+1;
			}
			ans=ask(ans);
			if (ans>=i||a[ans]!=t) continue;
			fa[i]=i+1,fa[ans]=ans+1;
		}
	ans=0;
	for (int i=1; i<=n; i++) if (fa[i]!=i) ans++;
	printf("%d\n",ans>>1);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

std::vector<bool> sieve;
std::vector<int> primes;

void eratosthenes(int maximum){
	sieve = std::vector<bool>(maximum+1);
	sieve[0]=sieve[1]=false;
	for(int i=2; i<sieve.size(); i++) sieve[i]=true;
	for(int j=4; j<sieve.size(); j+=2) sieve[j]=false;
	for(int i=3; 2*i<sieve.size(); i++){
		if(!sieve[i]) continue;
		for(int j=2*i; j<sieve.size(); j+=i) sieve[j] = false;
	}
}

void get_primes(int maximum){
	if(sieve.size() < maximum) eratosthenes(maximum);
	for(int i=2; i<sieve.size(); i++){
		if(sieve[i]) primes.push_back(i);
	}
}

std::map<long long, int> get_factors(long long x){
	std::map<long long, int> factors;
	for(int p: primes){
		if(p*p>x) break;
		while(x%p==0){
			factors[p]++;
			x /= p;
		}
	}
	if(x>1) factors[x]++;
	return factors;
}

/*
int main(){
	using namespace std;
	get_primes(10000000);
	for(int i=0; i<20; i++) cout << primes[primes.size()-1-i] << endl;
	for(auto p: get_factors(9999995)) cout << p.first << " " << p.second << endl;
}
*/

int main(){
	get_primes(200000);
	//cout << primes[0] << " " << primes[primes.size()-1] << endl;;

	int x;
	cin >> x;
	for(int i=0; i<primes.size(); i++){
		if(primes[i]<x) continue;
		cout << primes[i] << endl;
		break;
	}

	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
 
int main( void ){
 
   int width, height;
   int x, y, r;
 
   scanf( "%d %d %d %d %d", &width, &height, &x, &y, &r );
    
   if( x >= r && x <= width - r && y >= r && y <= height - r)
     printf("Yes\n");
   else
     printf("No\n");
 
   return 0;
 
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>void print(T x){cout << x << endl;}
template<class T>void printvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
int main()
{
    int k; cin >> k;
    if(k<10) {printf("%d\n", k); return 0;}

    queue<ll> que;
    rep(i, 9) {
        // print(i+1);
        que.push(i+1);
    }

    int cnt=9;
    ll ans=0;
    while(1){
        ll x = que.front(); que.pop();
        // printf("x=%lld\n", x);
        if(x%10!=0) {
            cnt++;
            que.push(10*x + x%10 - 1);
            // print(10*x + x%10 - 1);
            if(cnt==k) {ans=10*x + x%10 - 1; break;}
        }
        cnt++;
        que.push(10*x + x%10);
        // print(10*x + x%10);
        if(cnt==k) {ans=10*x + x%10; break;}
        if(x%10!=9) {
            cnt++;
            que.push(10*x + x%10 + 1);
            // print(10*x + x%10 + 1);
            if(cnt==k) {ans=10*x + x%10 + 1; break;}
        }
    }
    print(ans);

    return 0;
}

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

int main() {
  int n,a,b;
  string s;
  cin>>n>>a>>b>>s;
  int x=a+b;
  for(int i=0;i<n;i++){
    if(s[i]=='c') cout<<"No"<<endl;
    else if(s[i]=='b'){
      if(x>0 && b>0){
        cout<<"Yes"<<endl;
        x--;
        b--;
      }
      else cout<<"No"<<endl;
    }
    else{
      if(x>0){
        cout<<"Yes"<<endl;
        x--;
      }
      else cout<<"No"<<endl;
    }
  }
        
}


Measured memory_bytes: 896
#include <cstdio>
#include <vector>

using namespace std;

int c[100000];
int d[100000];
vector <int> v[100000];

void dfs(int x, int z) {
    int i;
    
    d[x] = z;
    
    for (i = 0; i < v[x].size(); i++) {
        int y = v[x][i];
        
        if (d[y] == 0) {
            dfs(y, z + 1);
            
            if (c[y] % 2 == 0) {
                c[x]++;
                printf("%d %d\n", x + 1, y + 1);
            } else {
                c[y]++;
                printf("%d %d\n", y + 1, x + 1);
            }
        } else if (d[y] > d[x]) {
            c[x]++;
            printf("%d %d\n", x + 1, y + 1);
        }
    }
}

int main() {
    int n, m, i;
    
    scanf("%d %d", &n, &m);
    
    for (i = 0; i < m; i++) {
        int x, y;
        
        scanf("%d %d", &x, &y);
        
        x--;
        y--;
        
        v[x].push_back(y);
        v[y].push_back(x);
    }
    
    if (m % 2 == 1) {
        puts("-1");
        
        return 0;
    }
    
    dfs(0, 1);
    
    return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n; cin >> n;
	int ret = 0;
	int step = 0;
	int ph; cin >> ph;
	for (int i=0; i<n-1; i++) {
		int h; cin >> h;
		if (h <= ph) {
			step++;
		} else {
			ret = max(ret, step);
			step = 0;
		}
		ph = h;
	}
	ret = max(ret, step);
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[100009];
ll ans(ll *arr, int n, int k){
	dp[0] = 0;
	for(int i=1; i<=k; i++){
		dp[i] = INT_MAX;
		for(int j=1; j<=i; j++){
			dp[i] = min(dp[i-j] + abs(arr[i] - arr[i-j]), dp[i]);
		}
	}
	for(int i=k+1; i<n; i++){
		dp[i] = INT_MAX;
		for(int j=1; j<=k; j++){
			dp[i] = min(dp[i-j] + abs(arr[i] - arr[i-j]), dp[i]);
		}
	}
	return dp[n-1];
}
int main(){
	int n, k; cin >> n >> k;
	ll arr[n];
	for(int i=0; i<n; i++) {cin>>arr[i]; dp[i] = -1;}
	ll anss = ans(arr, n, k);
	cout << anss << endl;
}

Measured memory_bytes: 1792
//A*
//优先对“起点到当前位置的成本+当前位置到目标状态的推测值”最小的状态进行状态迁移
#include<bits/stdc++.h>

using namespace std;

#define N 4
#define N2 16

const int dx[4]={0,-1,0,1};
const int dy[4]={1,0,-1,0};
const char dir[4]={'r','u','l','d'};
int MDT[N2][N2];

struct Puzzle{
    int f[N2],space,MD;
    int cost;
    bool operator < (const Puzzle &p)const{
        for(int i=0;i<N2;i++){
            if(f[i]==p.f[i]){
                continue;
            }
            return f[i]<p.f[i];
        }
        return false;
    }
};

struct state{
    Puzzle puzzle;
    int estimated;
    bool operator < (const state &s)const{
        return estimated>s.estimated;
    }
};

int getALLMD(Puzzle pz)
{
    int sum=0;
    for(int i=0;i<N2;i++){
        if(pz.f[i]==N2){
            continue;
        }
        sum+=MDT[i][pz.f[i]-1];
    }
    return sum;
}

int astar(Puzzle s)
{
    priority_queue<state>pq;
    s.MD=getALLMD(s);
    s.cost=0;
    map<Puzzle,bool>V;
    Puzzle u,v;
    state initial;
    initial.puzzle=s;
    initial.estimated=getALLMD(s);
    pq.push(initial);
    while(!pq.empty()){
        state st=pq.top();
        pq.pop();
        u=st.puzzle;
        if(u.MD==0){
            return u.cost;
        }
        V[u]=true;
        int sx=u.space/N;
        int sy=u.space%N;
        for(int r=0;r<4;r++){
            int tx=sx+dx[r];
            int ty=sy+dy[r];
            if(tx<0||ty<0||tx>=N||ty>=N){
                continue;
            }
            v=u;
            v.MD-=MDT[tx*N+ty][v.f[tx*N+ty]-1];
            v.MD+=MDT[sx*N+sy][v.f[tx*N+ty]-1];
            swap(v.f[sx*N+sy],v.f[tx*N+ty]);
            v.space=tx*N+ty;
            if(!V[v]){
                v.cost++;
                state news;
                news.puzzle=v;
                news.estimated=v.cost+v.MD;
                pq.push(news);
            }
        }
    }
    return -1;
}

int main()
{
    for(int i=0;i<N2;i++){
        for(int j=0;j<N2;j++){
            MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
        }
    }
//    for(int i=0;i<N2;i++){
//        for(int j=0;j<N2;j++){
//            cout<<MDT[i][j]<<" ";
//        }
//        cout<<endl;
//    }
    Puzzle in;
    for(int i=0;i<N2;i++){
        cin>>in.f[i];
        if(in.f[i]==0){
            in.f[i]=N2;
            in.space=i;
        }
    }
    cout<<astar(in)<<endl;
    return 0;
}


Measured memory_bytes: 257740
/*
 * s????????????????´??????????s'????????????????´?????????¨????????¨
 * i < l s'[i] = s[i]
 * l <= i <= r s'[i] = s[i] + x*i - x*(l-1)
 * r < i s'[i] = s[i] + x*(r-l+1)
 * ?????????BIT???????????¨??????????£?
 * ????´°????????¬
 * dsl2_g,poj3468??¨??????
 */
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

//BIT
struct BIT{
	int N;
	ll data[200100];
	void init(int n){
		N = n;
		REP(i,N+1)data[i] = 0;
	}
void add(int a,ll w){
	for(int x = a;x <= N;x += x & -x) data[x] +=w;
}
//bit[1] + ... + bit[a]
ll sum(int a){
	ll ret = 0;
	for(int x = a; x > 0; x -= x & -x) ret+= data[x];
	return ret;
}
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n,q;
	cin >> n >> q;
	BIT bit0,bit1;
	bit0.init(n+1);
	bit1.init(n+1);
	REP(i,q){
		int c;cin >> c;
		if(!c){
			int l,r;cin >> l >> r;
			int x;cin >> x;
			bit0.add(l,x);
			bit0.add(r+1,-x);
			bit1.add(l,-(l-1)*x);
			bit1.add(r+1,r*x);
		}else{
			int a;cin >> a;
			cout << bit0.sum(a)*a + bit1.sum(a) - (bit0.sum(a-1)*(a-1) + bit1.sum(a-1)) << endl;
		}
	}
  return 0;
}

Measured memory_bytes: 4744
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        n: usize,
        aa: [usize;n]
    }
    let mut aa = aa.iter().enumerate().collect::<Vec<_>>();
    aa.sort_by_key(|a| a.1);
    let res = aa.iter().map(|a| (a.0 +1).to_string())
                .collect::<Vec<_>>().join(" ");
    println!("{}", res);
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 12540
N, M = [int(i) for i in input().split()]
Student = [[int(i) for i in input().split()] for j in range(N)]
Checkpoint = [[int(i) for i in input().split()] for j in range(M)]

for x, y in Student:
    ans = [-1, float('inf')]
    for j, (x2, y2) in enumerate(Checkpoint):
        dist = abs(x2 - x) + abs(y2 - y)
        if dist < ans[1]:
            ans = [j, dist]
    print(ans[0] + 1)

Measured memory_bytes: 3064
from scipy.sparse import csr_matrix #pypyだとエラーになるので、pythonを使うこと
from scipy.sparse.csgraph import shortest_path, floyd_warshall
import numpy as np

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

N, M, L = list(map(int, input().split()))

A = np.zeros(M)
B = np.zeros(M)
C = np.zeros(M)
for i in range(M):
	Ai, Bi, Ci = list(map(int, input().split()))
	A[i] = Ai - 1
	B[i] = Bi - 1
	C[i] = Ci

graph = csr_matrix((C, (A, B)), shape=(N, N))
#print(graph)
dist = floyd_warshall(graph, directed=False)

graph2 = np.full((N, N), np.inf)
graph2[dist <= L] = 1
graph2 = csr_matrix(graph2)
num = floyd_warshall(graph2, directed=False)


Q = int(input())
for q in range(Q):
	s, t = list(map(int, input().split()))
	if num[s - 1][t - 1] < 10000000:
		print(int(num[s - 1][t - 1] - 1))
	else:
		print(-1)

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

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

using namespace std;

int main(){
	int n,d,x; cin>>n>>d>>x;
	int ans=x;
	rep(i,n){
		int a; cin>>a;
		ans+=(d-1)/a+1;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
// luogu-judger-enable-o2
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b;
	c=(a+b)/2;
	if(2*c!=a+b)
		cout<<c+1<<endl;
	else
		cout<<c<<endl;
	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 PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    
    int N;
    cin>>N;

    int D[N][2];
    bool d[N];
    rep(i,N){
        cin>>D[i][0]>>D[i][1];
        if(D[i][0]==D[i][1])d[i]=true;
        else d[i]=false;
    }
    int c=0;
    rep(i,N){

        if(d[i]){
            c++;
            if(c==3){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
        else{
            c=0;
        }
    }
    cout<<"No"<<endl;

    


    

}


Measured memory_bytes: 3644
use std::cmp::max;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut p = (0i32, 0i32, 0i32);
    for _ in 0..n {
        let pa = p.0;
        let pb = p.1;
        let pc = p.2;
        let a: i32 = read(&mut stdin_lock, &mut buf, b' ');
        let b: i32 = read(&mut stdin_lock, &mut buf, b' ');
        let c: i32 = read(&mut stdin_lock, &mut buf, b'\n');
        p.0 = a + max(pb, pc);
        p.1 = b + max(pa, pc);
        p.2 = c + max(pa, pb);
    }
    println!("{}", max(max(p.0, p.1), p.2));
}


Measured memory_bytes: 4352
N, K = map(int, input().split())
x = list(map(int, input().split()))
xl = []
xr = []
for i in x:
    if i > 0:
        xr.append(i)
    elif i < 0:
        xl.append(i)
xl = [0] + list(reversed(xl))
xr = [0] + xr

ans = 10 ** 9
k = K
if 0 in x:
    k -= 1

for i in range(max(0, k - (len(xl) - 1)), min(len(xr), k + 1)):
    # i:　ろうそくの数
    ans = min(ans, 2 * xr[i] + abs(xl[k - i]))
for i in range(max(0, k - (len(xr) - 1)), min(len(xl), k + 1)):
    ans = min(ans, 2 * abs(xl[i]) + abs(xr[k - i]))
print(ans)

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

using namespace std;
const int maxn = 3010;

int n, m;
char a[maxn], b[maxn];
int dp[maxn][maxn];
int rec[maxn][maxn];

int main() {
	scanf("%s%s", a, b); n = strlen(a), m = strlen(b);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			dp[i][j] = dp[i - 1][j];
			if (dp[i][j - 1] > dp[i][j]) dp[i][j] = dp[i][j - 1], rec[i][j] = 1;
			if (a[i - 1] == b[j - 1] && dp[i - 1][j - 1] + 1 > dp[i][j]) dp[i][j] = dp[i - 1][j - 1] + 1, rec[i][j] = 2;
		}
	}
	string x;
	while (n > 0 && m > 0) {
		if (rec[n][m] == 2) {
			x.push_back(a[--n]);
			m--;
		} else if (rec[n][m] == 1) m--;
		else n--;
	}
	reverse(x.begin(), x.end());
	cout << x;
	return 0;
}


Measured memory_bytes: 70912
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

int naive(int A,int K)
{
	queue <int> que;
	for(int i=0;i<=A;i++)
	{
		if(i%K==0) que.push(i/K);
		else
		{
			int t=que.front();que.pop();
			que.push(t);
		}
	}
	int ans=0;
	while(!que.empty())
	{
		ans=que.front();
		que.pop();
	}
	return ans;
}
int getxor()
{
	int A,K;
	scanf("%d %d",&A,&K);
	//printf("%d\n",naive(A,K));
	if((A%K)%(A/K+1)==0) return A/K;
	int last=A/K-(A%K)%(A/K+1)+1,now=A/K;
	while(1)
	{
		int t=last/K;
		last-=t*K;
		now-=t;
		if(last==0) return now;
		last-=K%now;
		if(last<=0) last+=now;
		now--;
		if(last==now+1) return now;
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	int ret=0;
	for(int i=0;i<n;i++)
	{
		int g=getxor();
		//printf("%d\n",g);
		ret^=g;
	}
	if(ret==0) puts("Aoki");
	else puts("Takahashi");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

bool is_prime(int x){
  int max = sqrt(x);
  if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(int i=3;i<=max;i=i+2){
    if(x % i == 0) return false;
  }
  return true;
}

int main(){
  int n; cin>>n;

  int x;
  int prime=0;
  for(int i=0;i<n;i++){
    cin>>x;
    if(is_prime(x)) prime++;
  }
  cout<<prime<<endl;
}

Measured memory_bytes: 3100
import collections

num_of_nums = int(input())
numbers = list(map(int, input().split(" ")))
numbers_odd = [numbers[i] for i in range(1, num_of_nums, 2)]
numbers_even = [numbers[j] for j in range(0, num_of_nums, 2)]
c_odd = collections.Counter(numbers_odd)
c_even = collections.Counter(numbers_even)

counter_odd = 0
counter_even = 0

if sum(numbers) / int(len(numbers)) != numbers[0]:
    if c_odd.most_common()[0][0] != c_even.most_common()[0][0]:
        counter_odd += int(len(numbers_odd)) - c_odd.most_common()[0][1]
        counter_even += int(len(numbers_even)) - c_even.most_common()[0][1]
        print(counter_even + counter_odd)
    else:
        if c_odd.most_common()[1][1] <= c_even.most_common()[1][1]:
            counter_odd += int(len(numbers_odd)) - c_odd.most_common()[0][1]
            counter_even += int(len(numbers_even)) - c_even.most_common()[1][1]
            print(counter_even + counter_odd)
        else:
            counter_odd += int(len(numbers_odd)) - c_odd.most_common()[1][1]
            counter_even += int(len(numbers_even)) - c_even.most_common()[0][1]
            print(counter_odd + counter_even)
else:
    print(int(int(len(numbers)) / 2))



Measured memory_bytes: 19040
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int tre[N];
int n;
int lowbit(int x)
{
	return x & -x;
}
void add(int x)
{
	for(int i = x;i;i -= lowbit(i))tre[i]++;
}
int ask(int x)
{
	int ans = 0;
	for(int i = x;i <= n;i += lowbit(i))ans += tre[i];
	return ans;
}
int f[N];
int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)scanf("%d",&f[i]);
	int pri = 1;
	add(f[1]);
	for(int i = 2;i <= n;i++)
	{
		int tt = ask(f[i]);
		if(tt == i - 1)pri ++;
		add(f[i]);
	}
	printf("%d",pri);
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;


int main() {
    ll N;
    cin >> N;
    vector<ll> P(N), Q(N), X(N);
    vector<vector<ll> > permutations;

    for (int i = 0; i < N; i++) {
        cin >> P[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> Q[i];
    }
    for (int i = 0; i < N; i++) {
        X[i] = i + 1;
    }
    do {
        permutations.push_back(X);
    } while (next_permutation(X.begin(), X.end()));
    bool flag;
    ll a = 0, b = 0;
    for (int i = 0; i < permutations.size(); i++) {
        flag = true;
        for (int j = 0; j < N; j++) {
            if (permutations[i][j] != P[j]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            a = i + 1;
        }
    }

    for (int i = 0; i < permutations.size(); i++) {
        flag = true;
        for (int j = 0; j < N; j++) {
            if (permutations[i][j] != Q[j]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            b = i + 1;
            break;
        }
    }

    ll ans = abs(a - b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4404
// 2020-09-14 20:57:26
// clang-format off
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
void answer() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  int d = 0;
  rep(ai, n) {
    auto itr = lower_bound(ALL(b), a[ai]);
    if (itr != b.end() && a[ai] == *itr) {
      chmax(d, ai - int(itr - b.begin() - 1));
    }
  }
  bool ok = true;
  rep(i, n) ok &= (a[i] != b[(n + i - d) % n]);
  if (ok) {
    cout << "Yes" << '\n';
    rep(i, n) {
      if (i) cout << ' ';
      cout << b[(n + i - d) % n];
    }
    cout << '\n';
  } else {
    cout << "No" << '\n';
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 4780
#!/usr/bin/env python
from __future__ import division, print_function

import io
import os
import sys

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from cStringIO import StringIO
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    from io import BytesIO as StringIO

sys.stdout, stream = io.IOBase(), StringIO()
sys.stdout.flush = lambda: os.write(1, stream.getvalue()) and not stream.truncate(0) and stream.seek(0)
sys.stdout.write = stream.write if sys.version_info[0] < 3 else lambda s: stream.write(s.encode())

input, flush = sys.stdin.readline, sys.stdout.flush
input = StringIO(os.read(0, os.fstat(0).st_size)).readline


def main():
    a, b, c = map(int, input().split())
    print('Yes' if a == b == c else 'No')


if __name__ == '__main__':
    main()


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vi arr (N);
	F0R(i, N) cin >> arr[i];
	sort(arr.begin(), arr.end());
	reverse(arr.begin(), arr.end());
	int matches = 0;
	for (int i = 0; i < arr.size(); ++i) {
		int val = arr[i];
		int pow = 1 << ((int)log2(val) + 1);
		
		int l = i + 1;
		int r = arr.size() - 1;
		while (l < r) {
			int mid = l + (r - l) / 2;
			if (arr[mid] > pow - val) {
				l = mid + 1;
			} else {
				r = mid;
			}
		}

		if (l < arr.size() && arr[l] == pow - val) {
			arr.erase(arr.begin() + l);
			++matches;
		}
	}
	print(matches);
}

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

int main()
{
    int n , k ;
    cin >> n >> k ;
    vector<int> vec(n) ;
    rep(i,n)
    {
        cin >> vec.at(i) ;
    }

    sort(vec.begin(), vec.end()) ;
    int sum = 0 ;
    rep(i,k)
    {
        sum += vec.at(i) ;
    }

    cout << sum << endl ;
}

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

using namespace std;
const int N = 1000005;

long long tot;
char s[15];
int l;

void calc(int p, long long SUM, long long sum){
	if(p == l){
		SUM += sum;
		tot += SUM;
		return;
	}
	calc(p + 1, SUM + sum, s[p] - '0');
	calc(p + 1, SUM, sum * 10 + s[p] - '0');
}

void init(){
	scanf("%s",s);
	l = strlen(s);
	calc(1,0,s[0] - '0');
	printf("%lld\n",tot);
}

int main(){
	
	init();
	return 0;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
//gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T> //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <class T>
bool chmax(T &a, const T &b) //最大値更新 返り値はbool
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) //最小値更新 返り値はbool
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    int cnt = 0;
    while (n > 0)
    {
        cnt += n % 10;
        n /= 10;
    }

    if (cnt == 1)
        cnt *= 10;
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	int a[N];
	for (int i=0; i<N; i++) {
		cin>>a[i];
	}

    int ans;
    sort(a,a+N);
    int A=0,B=0;
    for(int i=1;i<=N;i++){
        if(i%2==1){
            A+=a[N-i];
        }
        else{
            B+=a[N-i];
        }
    }
    ans=A-B;


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


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    ll a,b,c,x,y;
    ll mx,p,m = 10e9;
    cin >> a >> b >> c >> x >> y;
    mx = max(x,y);
    for(ll i = 0; i/2 <= mx; i += 2) {
        p = i * c;
        p += (i/2 < x) ? (x - i/2) * a:0;
        p += (i/2 < y) ? (y - i/2) * b:0;
        m = min(m,p);
    }
    cout << m << endl;
}


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

int main(){
    int N;
    double ans;
    cin >> N;
    vector<int>vec(N);
    for(int i = 0; i < N; i++){
        cin >> vec.at(i);
    }
    for(int i = 0; i < N; i++){
        ans = 1.000 / vec.at(i) + ans;
    }
  	ans = 1.000 / ans;
    cout << ans <<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
 
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
 
#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
 
const int hell=1000000007;
 
 
int pw(int a,int b)
{
  int x=a;
  rep(i,1,b){a=a*x;
    a%=10000000000LL;}
  return a;
}
 
 ll power(ll a,ll b)
{
  if(b==0)return 1;
  if(b==1)return a%hell;
  ll t=power(a,b/2);
  t*=t;
  t%=hell;
   if(b&1)
   {
       t*=a;
       t%=hell;
   }
   return t;
 
}

int inverse(int a)
{
  return power(a,hell-2);
}
 
int gcd(int a,int b)
{   
  
  if(b==0)return a;
  return gcd(b-a%b,a%b);
}
 
bool cmp(pii a,pii b)
{
  return a.SS<b.SS;
}
 
 
int sum(int a,int b )
{
   int ans=a-a/b; 
   return ans;
}


 
int solve()
{  
 
int n,d;
cin>>n>>d;
vi a;
rep(i,1,1000)a.pb(i*i);
vector<int> g[n];
rep(i,0,n)
{
  rep(j,0,d)
  {
    int x;
    cin>>x;
    g[i].pb(x);
  }
}
int ans=0;
rep(i,0,n)
{
   rep(j,i+1,n)
   {
       int x=0;

       rep(k,0,d)
       {
        x+=(g[i][k]-g[j][k])*(g[i][k]-g[j][k]);
       }
       //cout<<x<<endl;
       if(binary_search(all(a),x))ans++;

   }
}

cout<<ans;
 return 0;
}
 
 
signed main()
{  int t=1;
//pri();
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
  
   cin.exceptions(cin.failbit);                                                                    
 
 


  clock_t time_req;
 
    // Without ung pow function
                                                                                                                   
 //cin>>t;
 
    int k=1;
     
   while(t--)
     {
      //cout<<"Case #"<<k<<":"<<" ";k++;
      solve();
     }
        exit(0);
 
         time_req = clock() - time_req;
    cout <<endl<< "Processor time taken is "
      << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;
 
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
long long isPowOfFive(long long k){
	for(int i=-1000;i<=1000;++i){
    	if(pow(i,5)==k) return i;
    }
  	return 99999;
}
 
int main(){
	long long x; cin >> x;
  	for(long long i=1000;i>=-1000;--i){
      	int j = isPowOfFive(x+pow(i,5));
    	if(j != 99999){
        	cout << j << " " << i;
          	return 0;
        }
    }
}

Measured memory_bytes: 4024
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXM = 200000;
const int MAXN = 300000;
struct edge{
	int u, v, c;
}edges[MAXM + 5];
bool operator < (edge a, edge b) {
	return a.c < b.c;
}
vector<int>G[MAXN + 5];
void addedge(int u, int v) {
	G[u].push_back(v);
	G[v].push_back(u);
}
int vcnt, fa[MAXN + 5], con[MAXN + 5], vis[MAXN + 5];
int Find(int x) {
	if( fa[x] == x ) return x;
	return fa[x] = Find(fa[x]);
}
void Union(int x, int y) {
	int fx = Find(x), fy = Find(y);
	if( fx != fy ) fa[fx] = fy;
}
int dis[MAXN + 5];
void bfs(int s) {
	memset(dis, -1, sizeof dis);
	queue<int>que; que.push(s);
	dis[s] = 0;
	while( !que.empty() ) {
		int f = que.front(); que.pop();
		for(int i=0;i<G[f].size();i++) {
			if( dis[G[f][i]] == -1 ) {
				dis[G[f][i]] = dis[f] + 1;
				que.push(G[f][i]);
			}
		}
	}
}
int main() {
	int N, M;
	scanf("%d%d", &N, &M);
	for(int i=1;i<=M;i++)
		scanf("%d%d%d", &edges[i].u, &edges[i].v, &edges[i].c);
	sort(edges+1, edges+M+1);
	vcnt = N; int lst = 1;
	for(int i=2;i<=M+1;i++) {
		if( edges[i].c != edges[i-1].c ) {
			for(int j=lst;j<i;j++) {
				fa[edges[j].u] = edges[j].u;
				fa[edges[j].v] = edges[j].v;
				con[edges[j].u] = con[edges[j].v] = 0;
				vis[edges[j].u] = vis[edges[j].v] = false; 
			}
			for(int j=lst;j<i;j++)
				Union(edges[j].u, edges[j].v);
			for(int j=lst;j<i;j++) {
				if( fa[edges[j].u] == edges[j].u )
					if( con[edges[j].u] == 0 )
						con[edges[j].u] = (++vcnt);
				if( fa[edges[j].v] == edges[j].v )
					if( con[edges[j].v] == 0 )
						con[edges[j].v] = (++vcnt);	
			}
			for(int j=lst;j<i;j++) {
				if( !vis[edges[j].u] ) {
					addedge(edges[j].u, con[Find(edges[j].u)]);
					vis[edges[j].u] = true;
				}
				if( !vis[edges[j].v] ) {
					addedge(edges[j].v, con[Find(edges[j].v)]);
					vis[edges[j].v] = true;
				}
			}
			lst = i;
		}
	}
	bfs(1);
	if( dis[N] == -1 ) puts("-1");
	else printf("%d\n", dis[N] / 2);
}

Measured memory_bytes: 24192
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int m,num;
int mem[15][1005][1005]={0};

long int lfor(int n,int sum,int mininum)
{
    long int lsum=0;
    if(mem[n][sum][mininum]!=-1)
    {
        return mem[n][sum][mininum];
    }
    if(n==0&&sum==0)
    {
        return 1;
    }
    if(n==0)
    {
        return 0;
    }
    for(int i=mininum;i<=100;i++)
    {
        if(sum-i>=0)lsum=lsum+lfor(n-1,sum-i,i+1);
    }
    mem[n][sum][mininum]=lsum;
    return lsum;
}

int main()
{
    memset(mem, -1, sizeof(mem));
    long int ans;
    while(1)
    {
        ans=0;
        scanf("%d %d",&m,&num);
        if(m==0&&num==0)break;
        ans=lfor(m,num,0);
        printf("%lld\n",ans);
    }
    return 0;
}


/*n/k

(n+k-1)/k*/

//fill_n(mem[0][0], 10 * 1002 * 1002, 114514);
//fill(**memo, **memo+sizeof(mem),
//fill((int*)mem, (int*)mem + 10 * 1002 * 1002, 114514);
//fill(mem[0][0], mem[10][0], 114514);

Measured memory_bytes: 60220
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;



Int h, w;
string field[110];
Int dist[110][110];

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

    dist[0][0] = 0;
    if(field[0][0] == '#')dist[0][0]++;
    
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(i + 1 < h){
                if(field[i][j] == '.' && field[i+1][j] == '#'){
                    dist[i+1][j] = min(dist[i+1][j], dist[i][j]+1);
                }
                else{
                    dist[i+1][j] = min(dist[i+1][j], dist[i][j]);
                }                
            }
            if(j + 1 < w){
                if(field[i][j] == '.' && field[i][j+1] == '#'){
                    dist[i][j+1] = min(dist[i][j+1], dist[i][j]+1);
                }
                else{
                    dist[i][j+1] = min(dist[i][j+1], dist[i][j]);
                }                
            }
        }
    }
    cout << dist[h-1][w-1] << endl;
    return 0;
}

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

int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

void foreach_permutation(int n,int *x,int *y) {
  int indexes[n];
    long double sumd=0;

  for (int i = 0; i < n; i++) indexes[i] = i;
  do {
     //std::cout << indexes[0] << ',' << indexes[1] << ',' << indexes[2] << std::endl; 
    for(int i =0; i<n-1; i++){
      long double d=0;
      d =  sqrt(pow(x[indexes[i]] - x[indexes[i+1]], 2) + pow(y[indexes[i]] - y[indexes[i+1]], 2));
      //cout << "d: " << d << endl;
      sumd+=d;
      //cout << "sumd: " << sumd << endl;
    }
  
  } while (std::next_permutation(indexes, indexes + n));

  cout <<  fixed << setprecision(10) << sumd / facctorialMethod(n) << endl;

}

int main()
{
    int n;
    cin >> n;
    int x[n],y[n];
    for(int i=0;i<n;i++){
        cin >> x[i]>> y[i];
    }

    ll num = facctorialMethod(n);
    ll count=0;
    foreach_permutation(n,x,y);
    ++count;

    
    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long int ll;
typedef vector< pair<int, int> > vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef pair<int, int> pii;

const ll INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;

ll arr[nax];
int main()
{
    ios::sync_with_stdio(0);
    int n; cin >> n;
    for(int i = 1; i <= n; i++) cin >> arr[i];

    ll moves = 0;
    ll flag = 0;

        ll cur = 0;
        for(int i = 1; i <= n ; i++)
        {
            cur += arr[i];
            //cout << cur << endl;
            if(flag == 0)
            {
                // we have to make it positive
                if(cur > 0)
                    {
                        ;
                    }
                else
                {

                    moves += (1 - cur);
                     cur = 1;
                }
            }
            else
            {
                // we have to make it negative;
                if(cur < 0)
                {
                    {
                        ;
                    }
                }
                else
                {

                    moves += (cur - (-1));
                    cur = -1;
                }
            }
            flag = 1 - flag;

        }

        // second
         ll moves1 = 0;
     flag = 1;

         cur = 0;
        for(int i = 1; i <= n ; i++)
        {
            cur += arr[i];
            //cout << cur << endl;
            if(flag == 0)
            {
                // we have to make it positive
                if(cur > 0)
                    {
                        ;
                    }
                else
                {

                    moves1 += (1 - cur);
                     cur = 1;
                }
            }
            else
            {
                // we have to make it negative;
                if(cur < 0)
                {
                    {
                        ;
                    }
                }
                else
                {

                    moves1 += (cur - (-1));
                    cur = -1;
                }
            }
            flag = 1 - flag;

        }
    cout << min(moves, moves1) << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N, K; cin >> N >> K;
  int p[N]; rep(i,N) cin >> p[i]; sort(p,p+N);
  int result = 0;
  rep(i,K) result += p[i];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

void fin(){
	freopen("test.txt", "r", stdin);
}

ll ytoi(ll y){
	y--;
	return y*365+y/4-y/100+y/400;
}

int isu(int y){
	if(y%400 == 0) return 1;
	if(y%100 == 0) return 0;
	if(y%4 == 0) return 1;
	return 0;
}

int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int mtoi(int m, int y){
	int u = isu(y);
	mon[2] += u;
	int days = 0;
	rep(i, m) days += mon[i];
	mon[2] -= u;
	return days;
}

ll ymdtoi(ll y, ll m, ll d){
	return ytoi(y)+mtoi(m, y)+d;
}

int itoy(ll i){
	int yl=0, yh=10000001;
	while(yh-yl>1){
		int mid = (yh+yl)/2;
		if(i > ytoi(mid)) yl = mid;
		else yh = mid;
	}
	return yl;
}

int itom(int i, int y){
	int u = isu(y);
	for(int j = 1; j <= 12 ; j++){
		i -= mon[j] + (u&&(j==2));
		if(i <= 0) return j;
	}
	return -1;
}

void itoymd(ll i){
	int y = itoy(i);
	i -= ytoi(y);
	int m = itom(i, y);
	i -= mtoi(m, y);
	int d = i;
	cout << y << '.' << m << '.' << d << endl;
}

ll bkatwkitoi(ll b, ll ka, ll t, ll w, ll ki){
	ka += b*20;
	t += ka*20;
	w += t*18;
	ki += w*20;
	return ki+ymdtoi(2012, 12, 21);
}

void itobkatwki(ll i){
	i -= ymdtoi(2012, 12, 21);
	ll ki = i%20; i /= 20;
	ll w = i%18; i /= 18;
	ll t = i%20; i /= 20;
	ll ka = i%20; i /= 20;
	ll b = i%13;
	cout << b << '.' << ka << '.' << t <<
		'.' << w << '.' << ki << endl;
}

int dotcnt(string s){
	int cnt = 0;
	rep(i, s.size()) if(s[i] == '.') cnt++;
	return cnt;
}

int main(){
//	fin();
	string s;
	while(cin >> s, s != "#"){
		stringstream ss;
		ss << s;
		if( dotcnt(s) == 2){
			int y, m, d; char c;
			ss >> y >> c >> m >> c >> d;
			itobkatwki(ymdtoi(y, m, d));
		}else{
			int b, ka, t, w, ki; char c;
			ss >> b >> c >> ka >> c >> t >> c >> w >> c >> ki;
			itoymd(bkatwkitoi(b, ka, t, w, ki));
		}
	}

	return 0;
}

Measured memory_bytes: 1236
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,c,t,temp,x,y;
string str;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	vll v(3);
	read(v);
	sor(v);
	cout<<(v[0]*v[1])/2;
	
	
	
	
	
}

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

int cntMatch(string left, string right){
	int cnt = 0;
	for(char c='a'; c<='z'; c++){
		if(find(left.begin(), left.end(), c)!=left.end() && find(right.begin(), right.end(), c)!=right.end())
			cnt++;
	}

	return cnt;
}

int main(void)
{
	int N;
	cin >> N;

	string str;
	cin >> str;

	int ret = 0;
	for(int i=1; i<N-1; i++){
		ret = max(ret, cntMatch(str.substr(0, i), str.substr(i, N-i)));
	}

	cout << ret << endl;

	return 0;
}


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

int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    if(b<=a)
        cout<<"delicious"<<endl;
    if(b>a && b<=x+a)
        cout<<"safe"<<endl;
    if(b>x+a)
        cout<<"dangerous"<<endl;

    return 0;
}


Measured memory_bytes: 3632
def c_build_stairs(N, H):
    max_current = 0
    for h in H:
        max_current = max(max_current, h)
        if h < max_current - 1:
            return 'No'
    return 'Yes'

N = int(input())
H = [int(i) for i in input().split()]
print(c_build_stairs(N, H))

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

int n;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> n;
    int dp[n + 1], placed[n + 1];
    for (int i = 1; i <= n; i++) {
		cin >> dp[i];
		placed[i] = 0;
	}
    
    vector<int> ans;
    for (int i = n; i >= 1; --i) {
		int sum = 0;
		for (int j = 2 * i; j <= n; j += i) sum	+= placed[j];
		sum %= 2;
		if (sum != dp[i]) {
			placed[i] = true;
			ans.push_back(i);
		}
	}
	
	cout << ans.size() << "\n";
	for (auto& i : ans) cout << i << " ";
    return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
    return 0;
}

Measured memory_bytes: 256