akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> dp(n+1), dq(n+1);
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < n; ++j) {
            if(s[j] == 'W') dp[j]++;
            else dq[j+1]++;
        }
    }
    for (int i = 1; i <= n; ++i) dq[i] += dq[i-1];
    for (int i = n-1; i >= 0; --i) dp[i] += dp[i+1];
    int M = dp[0]+dq[0], ans = 0;
    for (int i = 0; i <= n; ++i) {
        if(dp[i]+dq[i] < M){
            M = dp[i]+dq[i];
            ans = i;
        }
    }
    cout << ans << " " << ans+1 << "\n";
    return 0;
}


Measured memory_bytes: 3296
#include "bits/stdc++.h"
using namespace std;

int main() {
    long long N, M;
    cin >> N >> M;

    if (N >= 2 && M >= 2) {
        cout << (N - 2) * (M - 2) << endl;
    }
    else if (N == 1 && M >= 2) {
        cout << M - 2 << endl;
    }
    else if (M == 1 && N >= 2) {
        cout << N - 2 << endl;
    }
    else {
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,c=0;
    string S;
    cin >> N >> S;

    for (int i = 0; i < N-2; i++)
    {
        if(S.at(i)=='A'&&S.at(i+1)=='B'&&S.at(i+2)=='C'){
            c++;
        }
    }
    cout << c << endl;
}

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

using namespace std;

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

typedef long long ll;
const ll MAXN = 2e6 + 10, inf = 1e18, mod = 1e9 + 7;

struct pair_hash {
	template <class T1, class T2>
	std::size_t operator () (const std::pair<T1,T2> &p) const {
		auto h1 = std::hash<T1>{}(p.first);
		auto h2 = std::hash<T2>{}(p.second);

		return h1 ^ h2;  
	}
};

ll pw(ll te, ll tee) {
	if (tee == 0)	return 1;
	ll res = pw(te, tee / 2);
	return (tee % 2 ? te * res * res : res * res);
}

ll a[MAXN], n, h, w, ans[105][105];

void Read_input() {
	cin >> h >> w >> n;
	for (ll i = 1; i <= n; i++)	cin >> a[i];
}

void Solve() {
	ll cnt = 0, k = 1;
	for (ll i = 1; i <= h; i++) {
		if (i % 2) {
			for (ll j = 1; j <= w; j++) {
				ans[i][j] = k;
				cnt++;
				if (cnt >= a[k]) {
					cnt = 0;
					k++;
				}
			}
		}
		else {
			for (ll j = w; j > 0; j--) {
				ans[i][j] = k;
				cnt++;
				if (cnt >= a[k]) {
					cnt = 0;
					k++;
				}
			}
		}
	}
	for (ll i = 1; i <= h; i++) {
		cout << ans[i][1];
		for (ll j = 2; j <= w; j++)
			cout << " " << ans[i][j];
		cout << endl;
	}
}


int main() {

	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	//freopen("input.txt", "r", stdin),	freopen("output.txt", "w", stdout);

	Read_input(),	Solve();
	return 0;
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 200007;

int n,val[_]={0};

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	n=ty(),val[0]=-1;
	for(int i=1;i<=n;i++)val[i]=ty();
	for(int i=1;i<=n;i++)if(val[i]>val[i-1]+1){cout<<-1<<lf;return 0;}
	lint ans=0;
	for(int i=1;i<=n;i++)if(val[i]!=val[i+1]-1)ans+=val[i];
	cout<<ans<<lf;	
	
	return 0;
}


Measured memory_bytes: 1024
import sys
import numpy as np 
def minimize():
    L, R=map(int,input().split())
    lis=[]
    if (L+2019) >= R:
        
        for i in range(L,R):
            for j in range(i+1, R+1):
                x=(i*j) %2019
                lis.append(x)
        lis=np.array(lis)
        ans=lis.min()
        print(ans)
    
    else :
        for i in range(L,(L+2019)):
            for j in range(i+1, L+2020):
                x=(i*j) %2019
                lis.append(x)
        lis=np.array(lis)
        ans=lis.min()
        print(ans)


minimize()






Measured memory_bytes: 100660
#include<bits/stdc++.h>
using namespace std;
int m,n,x;
int main(){
	cin>>m>>n;
	int sum=0;
	for(int i=0;i<n;i++)
	{ cin>>x;
	 sum+=x;
	}
	if(sum>=m) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
/*      ░░█ ▄▀█ █   █▀ █░█ █▀█ █▀▀ █▀▀   █▀█ ▄▀█ █▀▄▀█  
        █▄█ █▀█ █   ▄█ █▀█ █▀▄ ██▄ ██▄   █▀▄ █▀█ █░▀░█     */

// Author : Udit "luctivud" Gupta @ (https://www.linkedin.com/in/udit-gupta-1b7863135/)


#include <bits/stdc++.h>
#pragma GCC optimize "trapv"

using namespace std;

typedef long long int lld;
typedef unsigned long long int llu;


#define       TESTCASES()  cin >> (T3X0); T353 = T3X0; while(T3X0--)
#define       _input(V3C)  for(auto &V3C_I7 : (V3C)) cin >> (V3C_I7)
#define mems(A77AY, V4LU)  memset((A77AY), (V4LU), sizeof((A77AY)))
#define  CH3K(I7, E4, S7)  (((S7)<0) ? (I7)>(E4) : (I7)<(E4))
#define for4(I7,S4,E4,S7)  for(auto I7=(S4); CH3K(I7,E4,S7); (I7)+=(S7))




void solveEachTest(lld T35TC453N = 1) {
    
    vector<int> arr(4);
    for4(i, 0, 3, 1) {
        int a, b; cin >> a >> b;
        arr[a-1]++; arr[b-1]++;
    }
    // vector<bool> visited(4, false);
    // int st = 0;
    // visited[st] = true;
    // while (true) {
    //     int nx = arr[st];
    //     if (visited[nx] == true) break;
    //     visited[nx] = true;
    // }

    // for (auto i : visited) {
    //     if (!i) {
    //         cout << "NO\n";
    //         return;
    //     }
    // }

    for (auto i : arr) {
        if (i > 2) {
            cout << "NO\n";
            return;
        }
    }

    cout << "YES\n"; 

    return;
}


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

    lld T3X0 = 0, T353 = 1;

    // TESTCASES() 
        solveEachTest(T353 - T3X0);
    return 0;
}
// Random Thought : ok   

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    string N;
    cin >> N;
    if(N[0] == N[1] and N[1] == N[2]) {
        cout << "Yes" << endl;
        return 0;
    }
    if(N[1] == N[2] and N[2] == N[3]) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

bool bl[1000001];  //falseで初期化

int main(){
	ll n,ans=0;
	cin >> n;
	ll a[n];
	cinf(a,n);
	sort(a,a+n);
	ll max=a[n-1]+1;
	ll cnt[max];
	rep(i,max){
		cnt[i]=0;
	}

	rep(i,n){
		cnt[a[i]]++;
	}

	rep(i,n){
		bl[a[i]]=true;
	}

	arep(1,i,max){
		if(bl[i]&&cnt[i]==1)
			ans++;
		if(bl[i])
			for(ll j=i;j<max;j+=i){
				bl[j]=false;
			}
	}

	cout << ans << endl;
}

Measured memory_bytes: 13908
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <cmath>
#include <limits>
#include <stack>
#define ll long long
using namespace std;
int main(){
    int N,L;
    cin >> N >> L;
    string s[N];
    for(int i=0;i<N;i++){
        cin >> s[i];
    }
    sort(s,s+N);
    for(int i=0;i<N;i++){
        cout << s[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

struct mon{
    ll x;
    ll h;
    bool operator<(const mon &another) const
    {
        return x < another.x;
    };
};

ll haji = pow(2, 20);
vector <ll> bit(haji, 0);

void add(ll idx, ll val){
    while (idx > 0){
        bit[idx] += val;
        idx -= idx & -1*idx;
    }
    return;
}

void addrange(ll idx1, ll idx2, ll val){
    add(idx2, val);
    add(idx1, val*(-1));
    return;
}

ll damage(ll idx){
    ll val = 0;
    while (idx <= haji+1){
        val += bit[idx];
        idx += idx & -1*idx;
    }
    return val;
}



int main(void){
    ll n; ll d; ll a;
    cin >> n >> d >> a;
    vector <mon> mons;
    REP(i, n){
        ll x; cin >> x;
        ll h; cin >> h;
        mons.push_back({x, h});
    }
    sort(mons.begin(), mons.end());
    vector <ll> xs = {-1};
    vector <ll> hs = {0};
    REP(i, n){
        xs.push_back(mons[i].x);
        hs.push_back(mons[i].h);
    }
    xs.push_back(1e18);
    hs.push_back(0);
    vector <ll> front_idx;
    ll idx = 0;
    REP(i, n){
        ll next = xs[i] + d;
        while (xs[idx+1] <= next){
            idx++;
        }
        front_idx.push_back(idx);
    }
    ll ans = 0;
    ll first_idx = 1;
    for(int i=first_idx; i<n+2; i++){

        ll begin = i;
        ll hp = hs[i] - damage(begin);
        if (hp <= 0){
            continue;
        }
        ll end = upper_bound(xs.begin(), xs.end(), xs[begin] + 2*d) - xs.begin() - 1;
        ll dmg = ((hp+a-1) / a) * a;
        addrange(begin-1, end, dmg);
        ans += dmg/a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 19948
# frozen_string_literal: true

loop do
  n = gets.to_i
  break if n == 0

  s2 = 0
  s5 = 0
  m = n
  while m > 0
    m /= 2
    s2 += m
  end
  m = n
  while m > 0
    m /= 5
    s5 += m
  end
  puts s5 < s2 ? s5 : s2
end



Measured memory_bytes: 6832
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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 S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll nine[10], six[10];
ll ans;
std::set<ll> st;
ll dp[20][100010];

int main()
{
  std::cin >> N;

  nine[0] = 1;
  six[0] = 1;

  st.emplace( 1 );

  rep( i, 7 )
  {
    nine[i+1] = nine[i]*9;
    st.emplace( nine[i+1] );
  }

  rep( i, 8 )
  {
    six[i+1] = six[i]*6;  
    st.emplace( six[i+1] );
  }

  ll p = 0;

  rep( i, 20 ) rep( j, 100010 )
    dp[i][j] = INF;

  dp[0][0] = 0;

  for( auto it = st.rbegin(); it != st.rend(); ++it )
  {
    rep( j, 100010 )
    {
      if( j-(*it) >= 0 )
        chmin( dp[p+1][j], std::min( dp[p+1][j-(*it)]+1, dp[p][j] ) );
      else
        chmin( dp[p+1][j], dp[p][j] );
    }

    ++p;
  }

  std::cout << dp[st.size()][N] << std::endl;

  return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;
    for(int i=0; i<n; ++i){
        vector<int> a(3);
        for(int j=0; j<3; ++j)
            cin >> a[j];
        sort(a.begin(), a.end());
        if(a[0] * a[0] + a[1] * a[1] == a[2] * a[2])
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int a, b;
    string s;

    cin >> a >> b;
    cin >> s;

    int len = s.length();
    const char* cstr = s.c_str();

    bool ans = true;
    if (len != a + b + 1){
        ans = false;
    } else {
        for (int i = 0; i < a; i++){
            if (!('0' <= cstr[i] && cstr[i] <= '9')){
                ans = false;
                break;
            }
        }

        if (ans){
            if (cstr[a] != '-'){
                ans = false;
            }

            if (ans){
                for (int i = a + 1; i < a + b + 1; i++){
                    if (!('0' <= cstr[i] && cstr[i] <= '9')){
                        ans = false;
                        break;
                    }
                }
            }
        }
    }

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

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N;
vector <int > H;
vector <int > a;





int main()
{

	cin >> N;

	H.resize(N);

	REP(i,N){
		cin >> H[i];

	}

	sort(H.begin(),H.end());
	int ans = 0;
	int num = H[0];
	int count = 1;
	FOR(i,1,N){
		if(num != H[i]) {
			if(count >= H[i-1]){
				ans += count - H[i-1];
			} else {
				ans += count;
			}
			count=1;
			num = H[i];
		}else{
			count++;
		}
	}

	if(count >= H[N-1]){
		ans += count - H[N-1];
	} else {
		ans += count;

	}

	cout << ans;

}




Measured memory_bytes: 640
N, M = map(int, input().split())
X = [[i] + list(map(int, input().split())) for i in range(M)]
X.sort(key=lambda x: (x[1], x[2]))

city = X[0][1]
num = 0
for v in X:
    if city == v[1]:
        num += 1
    else:
        city = v[1]
        num = 1
    v.append(num)

X.sort()
for v in X:
    print('{:06}{:06}'.format(v[1], v[3]))


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

const int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int N, M;
    cin >> N >> M;
    vector<string> A(N), B(M);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];

    bool f2 = false;

    for (int i = 0; i+M <= N; i++) {
        for (int j = 0; j+M <= N; j++) {
            bool flag = true;
            for (int k = 0; k < M; k++) {
                for (int l = 0; l < M; l++) {
                    if (B[k][l] != A[i+k][j+l]) flag = false;
                }
            }
            if (flag) f2 = true;
        }
    }

    if (f2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main() {
	int n, m; cin >> n >> m;
	scc_graph g(n);
	for(int i = 0; i < m; ++i) {
		int a, b; cin >> a >> b;
		g.add_edge(a, b);
	}
	auto v = g.scc();
	cout << v.size() << '\n';
	for(auto& vv : v) {
		int vn = vv.size();
		cout << vn;
		for(int i : vv) {
			cout << " " << i;
		}
		cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 40100
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
s=a[n-1]
a[n-1]=s*10
k=bisect.bisect_left(a,s//2)
b=a[k-1]
c=a[k]
if abs(b*2-s)<abs(c*2-s):
  ans=b
else:
  ans=c
print(s,ans)

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

int main()
{
	int A, B, C, K, sum = 0;

	cin >> A >> B >> C >> K;
	while (1)
	{
		if (A == 0 || K == 0)
		{
			break;
		}
		sum++;
		A--;
		K--;
	}
	while (1)
	{
		if (B == 0 || K == 0)
		{
			break;
		}
		B--;
		K--;
	}
	while (1)
	{
		if (K == 0)
		{
			break;
		}
		sum--;
		K--;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3600
package main

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

func main() {
	A := oneInt()
	B := oneInt()
	ans := A * B
	if 0 < A && A < 10 {
		if 0 < B && B < 10 {
			fmt.Print(ans)
			return
		} else {
			fmt.Print(-1)
			return
		}
	} else {
		fmt.Print(-1)
		return
	}

}

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

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

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


Measured memory_bytes: 640
#include <stdio.h>

#define N (int)1e6
int p[N];

int main(void)
{
  int i, j;
  int n;

  for (i = 2; i < N; ++i) p[i] = 1;
  for (i = 2; i < N; ++i) {
    if (!p[i]) continue;
    for (j = i + i; j < N; j += i) {
      p[j] = 0;
    }
  }

  for (i = 2; i < N; ++i) p[i] += p[i - 1];

  while (~scanf("%d", &n)) printf("%d\n", p[n]);

  return 0;
}

Measured memory_bytes: 4500
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	StringBuilder output = new StringBuilder();
	
	//ヒープのサイズ
	int H;
	//節点の番号(1...H),要素数はH+1で確保する
	int[] Array;
	
	public void input() {
		H = sc.nextInt();
		Array = new int[H+1];
		//0...H
		for(int i=1; i<Array.length; i++) { Array[i] = sc.nextInt(); }
	}
	
	public void buildMaxHeap() { for(int i=H/2; i>=1; i--) { maxHeapify(i); } }
	
	public void maxHeapify(int i) {
		int left = 2 *i;
		int right = 2 * i + 1;
		int large;
		int temp;
		
		//左の子、右の子、自分で値が最大の節を選択
		if(left <= H && Array[left] > Array[i]) { large = left; }
		else { large = i; }
		if(right <= H && Array[right] > Array[large]) { large = right; }
		if(large != i) {
			temp = Array[i];
			Array[i] = Array[large];
			Array[large] = temp;
			maxHeapify(large);
		}
	}
	
	public void output() {
		for(int i=1; i<Array.length; i++) {
			System.out.print(" "+Array[i]);
		}
		System.out.println();
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
		obj.buildMaxHeap();
		obj.output();
	}
}



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

int N,C,X;
int D[30][39];
int t[3][30];
int main(){
  cin >> N >> C;
  rep(i,C)rep(j,C)cin >> D[i][j];
  rep(i,N)rep(j,N)cin >> X,t[(i+j)%3][X-1]++;
  int res = 1<<30;
  rep(i,C)rep(j,C)if(i!=j)rep(k,C)if(i!=k&&j!=k){
    int tt =0;
    rep(l,C)tt += D[l][i]*t[0][l];
    rep(l,C)tt += D[l][j]*t[1][l];
    rep(l,C)tt += D[l][k]*t[2][l];
    if(tt<res)res=tt;
  }
  printf ("%d\n",res);
  return 0;
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	int ans = n;
	int sCount = 0;
	FOR(i,0,n){
		if(s[i] == 'S'){
			sCount++;
		}else{
			if(sCount > 0){
				ans -=2;
				sCount--;
			}
		}
	}
	ANS(ans);
	return 0;
}


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

int main(){
  ll n,m;
  cin >> n >> m;
  vector<ll> a(n);
  ll sum = 0;
  for(ll i=0;i<n;i++){
    cin >> a.at(i);
    sum += a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  
  double j = (double)sum/(double)(4*m);
  if( (double)a.at(m-1) < (double)j ){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int,int> mp;
typedef pair<int,mp> mmp;

vector<int> ver[5005];
int rode[5005]={};
int tdat[5005][2];
int n,k;
int main(void){
	scanf("%d%d",&n,&k);
	rep(i,n){
		scanf("%d%d",&(tdat[i+1][0]),&(tdat[i+1][1]));
	}
	rep(i,k){
		int a,b;
		scanf("%d%d",&a,&b);
		ver[a].push_back(b);
		ver[b].push_back(a);
	}
	
	priority_queue<mmp,vector<mmp>,greater<mmp> > que;
	que.push(mmp(0,mp(1,0)));
	while(!que.empty()){
		mmp pa=que.top();
		que.pop();
		int co=pa.first,
			no=pa.second.first,
			nt=pa.second.second;
		if(no==n){
			printf("%d\n",co);
			return 0;
		}
		if(nt!=0)rep(i,ver[no].size())que.push(mmp(co,mp(ver[no][i],nt-1)));
		if(rode[no])continue;
		rode[no]=1;
		que.push(mmp(co+tdat[no][0],mp(no,tdat[no][1])) );
	}
	return 0;
}

Measured memory_bytes: 4860
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

// for i in f..<t { as swift
#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;
int n;

string s[300];

bool isSymmetry(int m) {
    forin(i, 0, n) {
        forin(j, 0, n) {
            if (i == j) continue;
            if (s[i][(j + m) % n] != s[j][(i + m) % n])
                return false;
        }
    }
    return true;
}

int main() {
    cin >> n;
    forin(i, 0, n) cin >> s[i];
    ll count = 0;
    forin(m, 0, n) {
        if (isSymmetry(m)) count++;
    }
    cout << count * n << endl;
}



Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>

using namespace std;


const int MAXN=1e5+10;
using ll=long long int;

struct Node{
    int lbound,rbound;
    ll diff;
    ll sum;
    Node *left,*right;
};

Node segtree[MAXN*2];
Node* next_pos=segtree;
int n,q;

Node* build(int left,int right){
    auto* cur=next_pos;
    next_pos++;
    cur->lbound=left;
    cur->rbound=right;

    cur->diff=0;
    

    int mid=(left+right)/2;

    //リーフノードのケース
    if (right-left==1) return cur;

    cur->left=build(left,mid);
    cur->right=build(mid,right);
    //総和を集計
    cur->sum=0;
    return cur;
}

//シングルノードの更新
void update(Node& self,ll d){
    self.diff+=d;
    self.sum+=d;
}

void update(Node& self,int l,int r,int u){
    int mid=(self.lbound+self.rbound)/2;
    
    if (self.rbound-self.lbound!=1&&self.diff!=0){
        update(*self.left,self.diff);
        update(*self.right,self.diff);
        self.diff=0;
    }

    if (l==self.lbound&&r==self.rbound){
        update(self,u);
    }else if (l>=mid){
        update(*self.right,l,r,u);
        self.sum=min(self.left->sum,self.right->sum);
    }else if (r<=mid){
        update(*self.left,l,r,u);
        self.sum=min(self.left->sum,self.right->sum);
    }else{
        update(*self.left,l,mid,u);
        update(*self.right,mid,r,u);
        self.sum=min(self.left->sum,self.right->sum);
    }
}

//シングルポイント
int query(Node& self,int i){
    // puts("q");
    if (self.rbound-self.lbound==1&&self.lbound==i) return self.diff;
    int mid=(self.lbound+self.rbound)/2;
    if (i>=mid) return query(*self.right,i)+self.diff;
    else return query(*self.left,i)+self.diff;
}

//区間
ll query(Node& self,int l,int r){
    int mid=(self.lbound+self.rbound)/2;

    //更新があるノードの区間をプッシュボタン
    if (self.rbound-self.lbound!=1&&self.diff!=0){
        update(*self.left,self.diff);
        update(*self.right,self.diff);
        self.diff=0;
    }

    if (l==self.lbound&&r==self.rbound){
        return self.sum;
    }else if (l>=mid){
        return query(*self.right,l,r);
    }else if (r<=mid){
        return query(*self.left,l,r);
    }else{
        return min(query(*self.left,l,mid),query(*self.right,mid,r));
    }
}

int main(){
    scanf("%d%d",&n,&q);
    build(0,n);
    for(int i=0;i<q;i++){
        int t;
        scanf("%d",&t);
        if (t==0){
            int s,t,x;
            scanf("%d%d%d",&s,&t,&x);
            update(segtree[0],s,t+1,x);
        }else{
            int l,r;
            scanf("%d%d",&l,&r);
            printf("%lld\n",query(segtree[0],l,r+1));
        }

    }
    return 0;
}


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

int main() 
{ 
    int t;
    cin>>t;
    unordered_map<string,int>m;
    while(t--){
        string s;
        cin>>s;
        m[s]++;
    }
    cout<<"AC x "<<m["AC"]<<endl;
    cout<<"WA x "<<m["WA"]<<endl;
    cout<<"TLE x "<<m["TLE"]<<endl;
    cout<<"RE x "<<m["RE"]<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    map<int,int64_t> mp;
    for(int i=0; i<N; i++) {
        mp[i-A[i]]++;
    }

    int64_t ans = 0;
    for(int i=0; i<N; i++) {
        mp[i-A[i]]--;
        ans += mp[A[i]+i];
    }

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


Measured memory_bytes: 26572
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        if (i % 2 != 0) cnt++;
    }
    printf("%.7f\n", (double)cnt/n);
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000)

def ins(): return input().split()
def ii(): return int(input())
def iil(): return list(map(int, ins()))
def lin(): return list(input())
def iin(): return map(int, ins())

import decimal

r = ii()
pi = decimal.Decimal('3.141592653589793238462643383279')
print(pi*r*2)


Measured memory_bytes: 10008
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    rep(i, n) {
        if (i == 0) continue;
        if (s[i-1] != s[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
ll N,M;
#define MAXN 100001
#define MAXM 100001
ll A[MAXN];
int main(){
    cin >> N >> M;
    ll ans = 0;
    priority_queue<int> PQ;
    rep(i,N){
        cin >> A[i];
        PQ.push(A[i]);
    }
    rep(i,M){
        ll S = PQ.top();
        PQ.pop();
        PQ.push(S/2);
    }
    rep(i,N){
        ans += PQ.top();
       PQ.pop();
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 1528
import java.util.*;
public class Main{
    public static void main(String [] args){
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt(),B=sc.nextInt(),C=sc.nextInt(),D=sc.nextInt();
        int flag;
        while(true){
            C=C-B;
            if(C<=0){
                flag=0;
                break;
            }
            A=A-D;
            if(A<=0){
                flag=1;
                break;
            }
        }
        if(flag==0)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 35724
#include<bits/stdc++.h>
using namespace std;
int main() {
	int x[5];
	for (int i = 0; i < 5; i++)
	{
		cin >> x[i];
		if(x[i] == 0) {
			cout << i+1 << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 3568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 * for (int i = 0; i < N; i++) {}
 * System.out.println();
 * HashMap<Integer, Integer> hm = new HashMap<>();
 * int[] s = new int[M];
 * ArrayDeque<Integer> deq = new ArrayDeque<>();
 *
 */
public class Main implements Runnable { //クラス名はMainC

	public static void main(String[] args) {
		Thread.setDefaultUncaughtExceptionHandler((t, e) -> System.exit(1));
		new Thread(null, new Main(), "", 1024 * 1024 * 1024).start(); //16MBスタックを確保して実行
	}

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

		try {
			String S = sc.nextLine().trim();
			int N = S.length();
			String ans = (String) S.subSequence(0, 1);
			ArrayList<Long> arr = new ArrayList<Long>();

			/*
			for (int i = 0; i < N; i++) {
				//System.out.println(S.subSequence(i, i + 1));
				A[i] = (String) S.subSequence(i, i + 1);
			}
			*/

			dfs(ans, S, N, 1, arr);
			long printans = 0;
			for (int i = 0; i < arr.size(); i++) {
				printans += arr.get(i);
			}

			//System.out.println("----");
			System.out.println(printans);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void dfs(String Ans, String S, int N, int next, ArrayList<Long> arr) {
		if (next == N) {
			//System.out.println(Ans);
			long ansn = 0;
			String[] plus = Ans.split(",", -1);
			for (int i = 0; i < plus.length; i++) {
				//	System.out.println(" " + Integer.valueOf(plus[i]));
				ansn += Long.valueOf(plus[i]);
			}
			arr.add(ansn);
			//System.out.println(ansn);

		} else {
			String Ans1 = Ans + "," + (String) S.subSequence(next, next + 1);
			dfs(Ans1, S, N, next + 1, arr);

			String Ans2 = Ans + (String) S.subSequence(next, next + 1);
			dfs(Ans2, S, N, next + 1, arr);

		}

	}
}

//高速なScanner
class FastScannerMainC {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScannerMainC(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


Measured memory_bytes: 28756
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
	long long a,b,c,k,ans;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
	if (k&1) ans = b-a;
		else ans = a-b;
	if (ans > 1e18 || ans < -1e18) printf("Unfair");
		else 		printf("%lld",ans);
	return 0;
}



Measured memory_bytes: 128
import math
while True:
    N = int(input())
    if N == 0:
        break
    S = list(map(int, input().split()))
    SS = [x**2 for x in S]

    avg_S = sum(S)/len(S)
    avg_SS = sum(SS)/len(SS)
    print(math.sqrt(avg_SS - avg_S**2))


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

int main(){
  int N;
  int count = -1;
  int ans = 0;
  cin >> N;
  vector<vector<int>> vec(N, vector<int> (2));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < 2;j++){
      cin >> vec[i][j];
    }
    if (vec[i][0] == vec[i][1]) count++;
    else count = -1;
    
    
    if (count == 2){
      ans = 1;
      break;
    }
  }
    
    if (ans == 1) cout << "Yes" << endl;
    else cout << "No" <<endl;
  
}

Measured memory_bytes: 3632
def main():
    q = int(input())
    a = [list(int(i) for i in input().split()) for i in range(q)]
    MAX = 10**5
    is_prime = [1]*MAX
    for i in range(2, MAX):
        if not is_prime[i]:
            continue
        for j in range(i*2, MAX, i):
            is_prime[j] = 0
    s = [0]*MAX
    for i in range(3,MAX):
        s[i] = s[i-1] + 1 if is_prime[i] and is_prime[(i+1)//2] else s[i-1]
    for i in range(q):
        l,r = a[i]
        print(s[r]-s[l-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 29812
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
	scanf("%d%d",&a,&b);
	if (a<=0&&b>=0){
		puts("Zero");return 0;
	}
	if (a>0){
		puts("Positive");return 0;
	}
	if ((b-a+1)%2==0){
		puts("Positive");return 0;
	}
	puts("Negative");
} 

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

using namespace std;

static int mem[16][1<<16][5];
int vs[16][16];
int lg[16] = {1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};

int search(int win, int lose, int cnt, int n){
	if(~mem[win][lose][cnt]) return mem[win][lose][cnt];
	if(!lose) return mem[win][lose][cnt] = 1;
	if(cnt == 0) return mem[win][lose][cnt] = 0;
	int res = 0, loseBit = 0;
	for(int t=lose;t;t&=(t-1)) loseBit++;
	if(lg[loseBit] > cnt) return mem[win][lose][cnt] = 0;
	for(int i=0;i<n;i++){
		if(!(lose&(1<<i))) continue;
		if(!vs[win][i]) continue;
		int mask = lose^(1<<i);
		int b = mask;
		do{
			res += search(win, b, cnt-1, n) * search(i, mask^b, cnt-1, n);
			b = (b-1)&mask;
		} while (b != mask);
	}
	return mem[win][lose][cnt] = res;
}

int main(){
	int n, m;
	while(cin >> n >> m, n){
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				cin >> vs[i][j];
		memset(mem,-1,sizeof(mem));
		cout << search(m-1, (((1<<n)-1)^(1<<(m-1))), lg[n-1], n) << endl;
	}
}

Measured memory_bytes: 20000
#include <iostream>                                             
using namespace std;                                            
                                                                
int main(void) {                                                
  int r, c;                                                     
  cin >> r >> c;                                                
  int a[r+1][c+1];                                              
  for (int i=0; i<r+1; i++) {                                   
    for (int j=0; j<c+1; j++) {                                 
      a[i][j] = 0;                                              
    }                                                           
  }                                                             
  for (int i=0; i<r; i++) {                                     
    for (int j=0; j<c; j++) {                                   
      cin >> a[i][j];                                           
      a[r][j] += a[i][j];                                       
      a[i][c] += a[i][j];                                       
      a[r][c] += a[i][j];                                       
    }                                                           
  }                                                             
  for (int i=0; i<r+1; i++) {                                   
    for (int j=0; j<c+1; j++) {                                 
      cout << a[i][j] << flush;                                 
      if (j==c) {                                               
        cout << endl;                                           
      } else {                                                  
        cout << " " << flush;                                   
      }                                                         
    }                                                           
  }                                                             
  return 0;                                                     
}                                                               
                                                                
                                  

Measured memory_bytes: 3092
#include<stdio.h> 
    double zenka(double q){   
    double x=q/2;  
    while(x*x*x-q>=0.00001*q || x*x*x-q<=-0.00001*q)    {  
        x=x-((x*x*x)-q)/(3*x*x); 
        }   
        return x;
        
    }
    int main(void){
        int q;     
        while(1)    {     
            scanf("%d",&q);  
            if(q==-1) 
            break;    
            else      
            {         
                printf("%.7f\n",zenka(q));     
                }  
                }     
    return 0;
        
    }



Measured memory_bytes: 2668
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
int main(void){
    int n;
    while(cin>>n,n){
        int ans=10000000;
        for(int z=0 ;z*z*z<=n;z++){
            for(int y=0; y*y<=n-z*z*z;y++){
                ans=min(ans, n-z*z*z-y*y+y+z);
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3076
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<double> x(N), y(N);
	for (int i = 0; i < N; i++) cin >> x[i] >> y[i];

	double ans = .0;
	vector<int> perm(N);
	iota(perm.begin(), perm.end(), 0);
	do {

		double sum = .0;
		for (int i = 0; i < N - 1; i++) {
			sum += sqrt((x[perm[i]] - x[perm[i + 1]]) * (x[perm[i]] - x[perm[i + 1]]) +
				(y[perm[i]] - y[perm[i + 1]]) * (y[perm[i]] - y[perm[i + 1]]));
		}

		ans += sum;

	} while (next_permutation(perm.begin(), perm.end()));

	for (int i = 1; i <= N; i++) ans /= i;
	cout << fixed << setprecision(10) << ans << "\n";

	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<string> s(n);
  for (int i = 0; i < n; i++) cin >> s.at(i);
  
  int onlyl = 0, onlyr = 0, equal = 0;
  vector<pair<int, int>> lbig, rbig;
  for (int i = 0; i < n; i++) {
    stack<char> st;
    for (int j = 0; j < s[i].size(); j++) {
      if (st.empty()) {
        st.push(s[i][j]);
      }
      else {
        if (s[i][j] == ')' && st.top() == '(') st.pop();
        else st.push(s[i][j]);
      }
    }
    int countl = 0, countr = 0;
    while (!st.empty()) {
      if (st.top() == '(') countl++;
      else countr++;
      st.pop();
    }
    if (countr == 0) onlyl += countl;
    else if (countl == 0) onlyr += countr;
    else if (countl == countr) equal = max(equal, countl);
    else if (countl > countr) lbig.emplace_back(make_pair(countl, countr));
    else rbig.emplace_back(make_pair(countl, countr));
  }
  
  //cout << onlyl << " " << onlyr << " " << lbig.size() << " " << equal.size() << " " << rbig.size() << " " << endl;
  
  int judgel = onlyl, judger = onlyr;
  for (int i = 0; i < lbig.size(); i++) {
    judgel += lbig.at(i).first;
    judger += lbig.at(i).second;
    swap(lbig.at(i).first, lbig.at(i).second);
  }
  for (int i = 0; i < rbig.size(); i++) {
    judgel += rbig.at(i).first;
    judger += rbig.at(i).second;
  }
  
  if (judgel != judger) {
    cout << "No\n";
    return 0;
  }
  
  sort(lbig.begin(), lbig.end());
  sort(rbig.begin(), rbig.end());
  
  for (int i = 0; i < rbig.size(); i++) {
    if (onlyr < rbig.at(i).first) {
      cout << "No\n";
      return 0;
    }
    onlyr += rbig.at(i).second - rbig.at(i).first;
  }
  for (int i = 0; i < lbig.size(); i++) {
    if (onlyl < lbig.at(i).first) {
      cout << "No\n";
      return 0;
    }
    onlyl += lbig.at(i).second - lbig.at(i).first;
  }
  
  if (onlyl < equal) {
    cout << "No\n";
    return 0;
  }
  else {
    cout << "Yes\n";
    return 0;
  }
}

Measured memory_bytes: 34284
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff(i,c,n) for(ll i=c;i<n;i++)

int main() {
	// your code goes here
	string a,b;
	cin>>a>>b;
	ll dp[a.length()+1][b.length()+1];
    ff(i,0,a.length()+1){
        ff(j,0,b.length()+1){
            if(i==0||j==0) dp[i][j]=0;
            else if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string s="";
    int i = a.length(), j = b.length(); 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (a[i-1] == b[j-1]) 
      { 
          s.push_back(a[i-1]); // Put current character in result 
          i--; j--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   } 
    reverse(s.begin(),s.end());
    cout<<s;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define isz(x) (int)(x).size()
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
	for (int n; std::cin >> n; ) {
        std::vector<int> pos(1+n,n);
        pos[0] = -1;
        int answ = n;
        for (int i = 0; i < n; i++) {
            int it; std::cin >> it;
            if (pos[it-1] < i) {
                answ = std::min(answ, n - it);
                pos[it] = std::min(pos[it], i);
            }
        }
        if (answ == n) answ = -1;
        std::cout << answ << std::endl;
    }
}


Measured memory_bytes: 1024
import scala.io.StdIn

object Main extends App {
  
  val a = StdIn.readLine().trim.split(' ').map(_.toInt)
  val t = a(2)
  val result = (a(0) to a(1)).foldLeft(0) { (acc, i) =>
    if(t % i == 0) acc + 1 else acc
  }
  println(result)

}


Measured memory_bytes: 44104
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <random>
#include <functional>

#include <fstream>
#include <vector>
#include <algorithm>

#define ll long long int
#define MOD 1000000007

using namespace std;

bool isPrime(ll n)
{
    if(n == 1)
    {
        return false;
    }
    for(ll i = 2; i*i <= n; i++)
    {
        if(n % i == 0)
        {
            return false;
        }
    }
    
    return true;
}

ll f(ll n)
{
    ll res = 0;
    for(ll x = 1; x*x <= n-2; x++)
    {
        for(ll y = x; y*y <= n-2; y++)
        {
            for(ll z = y; z*z <= n-2; z++)
            {
                if(x*x + y*y + z*z + x*y + y*z + z*x == n)
                {
                    if(x==y && y==z && z==x)
                    {
                        res++;
                    }
                    else if((x==y && y!=z) || (y==z&&z!=x) || (z==x&&x!=y))
                    {
                        res += 3;
                    }
                    else if(x!=y && y!=z)
                    {
                        res += 6;
                    }
                }
            }
        }
    }
    
    return res;
}

int main(void)
{
    
    ll n;
    
    cin >> n;
    
    for(ll i = 1; i <= n; i++)
    {
        cout << f(i) << endl;
    }
    
    
    return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    ll ans = K % 2 == 0 ? A - B : B - A;

    cout << ans << endl;
}


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

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,t,a;
  cin >> n;
  cin >> t >> a;
  int h[n];
  for(int i=0;i<n;++i) cin >> h[i];
  double def=1000000;
  int ans;
  for(int i=0;i<n;++i) {
    def=min(def,abs(a-(t-(h[i]*0.006))));
    if(def>=abs(a-(t-(h[i]*0.006)))) ans=i+1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256