akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
  int n; cin>>n;
  int cnt = 0;
  while(n--){
    int a,b; cin>>a>>b;
    if(a==b) ++cnt;
    else cnt = 0;
    if(cnt == 3){
      cout<<"Yes\n";
      return 0;
    }
  }
  cout<<"No\n";
  return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << min(A, B) + min(C, D) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {

    long long int a, b;
    cin >> a >> b;

    if ( b * 2 >= a ) {
        cout << 0 << endl;
    } else {
        cout << a - b * 2 << endl;
    }

    return 0;

}


Measured memory_bytes: 256
# coding: utf-8

import sys

# ??¢??????????????????????????£????????§???????????????
alphabet_list = [chr(i) for i in range(97, 97+26)]
alphabet_dict = {}
for a in alphabet_list:
    alphabet_dict.update({a:0})

for strings in sys.stdin:
    for s in strings:
        if (s.isalpha()):
            s = s.lower()
            alphabet_dict[s] += 1

for key in sorted(alphabet_dict.keys()):
    print(str(key) + ' : '+ str(alphabet_dict[key]))

Measured memory_bytes: 7436
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
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; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0) return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1) t = t * a;
return t;
}
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

// 愚直計算による二項係数計算
mint com(long long n, long long r) {
mint res = 1;
for (long long i = 0; i < r; ++i) {
res *= (n-i);
res /= (i+1);
}
return res;
}

int main() {
    int n;
    cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];

    mint sum = 0;
    rep(i,n) sum += a[i];

    mint t = 0;
    rep(i,n) t += a[i]*a[i];

    cout << (sum*sum-t)/2 << endl;
    return 0;
}

Measured memory_bytes: 4816
package main

import "fmt"

func contain(nums []int, n int) bool {
	for _, num := range nums {
		if num == n {
			return true
		}
	}
	return false
}

func main() {
	// input
	var a, b, c int
	fmt.Scanf("%d %d %d", &a, &b, &c)
	nums := []int{a, b, c}

	// create unique-num-slice
	uniques := []int{}
	for _, num := range nums {
		if !contain(uniques, num) {
			uniques = append(uniques, num)
		}
	}

	// count
	fmt.Println(len(uniques))
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  int ans = 0;
  for(int i=1;i<=n;i++){
    string s=to_string(i);
    if(s.size()%2==1)ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3776
h, w = gets.chomp.split().map(&:to_i)
a = []
h.times do
  a.push gets.chomp.split().map(&:to_i)
end

ans = []
add = 0
left = ''
h.times do |y|
  if y.even?
    yoko = 0.upto(w-1)
  else
    yoko = (w-1).downto(0)
  end
  yoko.each do |x|
    if add == 1
      ans.push left + ' ' + [y+1, x+1].join(' ')
    end
    if (a[y][x] + add).odd?
      add = 1
      left = [y+1, x+1].join(' ')
    else
      add = 0
      left = nil
    end
  end
end

puts ans.size
ans.each do |line|
  puts line
end


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

#define int long long

const int NUM = 8;

string field[NUM];

int check(int y, int x, char cookie){
  int res = 0;
  
  for(int i = -1; i <= 1; i++){
    for(int j = -1; j <= 1; j++){
      if(!i && !j) continue;
      int num = 0;
      for(int nx = x+j, ny = y+i; 0 <= nx && nx < NUM && 0 <= ny && ny < NUM ; ny += i,nx += j){
	if(field[ny][nx] == cookie){
	  res += num;
	  break;
	} else if(field[ny][nx] == '.'){
	  break;
	} else {
	  num++;
	}
      }
    }
  }
  return res;
}

void put(int y, int x, char cookie){

  field[y][x] = cookie;
  
   for(int i = -1; i <= 1; i++){
    for(int j = -1; j <= 1; j++){
      if(!i && !j) continue;
      bool flag = false;
      for(int nx = x+j, ny = y+i, n; 0 <= nx && nx < NUM && 0 <= ny && ny < NUM ; ny += i,nx += j){
	if(field[ny][nx] == cookie){
	  flag = true;
	  break;
	} else if(field[ny][nx] == '.'){
	  break;
	} else {
	}
      }

	if(flag){
	  for(int nx = x+j, ny = y+i, n; 0 <= nx && nx < NUM && 0 <= ny && ny < NUM ; ny += i,nx += j){
	     if(field[ny][nx] == cookie){
	       break;
	     } else if(field[ny][nx] == '.'){
	       break;
	     } else {
	       field[ny][nx] = cookie;
	     }
	  }
	}
	
    }
   }
}
   
void print(){
    for(int i = 0; i < NUM; i++){
    cout<<field[i]<<endl;
  }
}

signed main(){

  for(int i = 0; i < NUM; i++){
    cin>>field[i];
  }

  while(true){
    pair<int,pair<int,int> > TOMOEMAMI, CHARLOTTE;
    
    for(int i = 0; i < NUM; i++){
      for(int j = 0; j < NUM; j++){
	if(field[i][j] != '.') continue;
	int num = check(i,j, 'o');
	if(TOMOEMAMI.first < num) TOMOEMAMI = make_pair(num,make_pair(i,j));
      }
    }
    if(TOMOEMAMI.first) put(TOMOEMAMI.second.first, TOMOEMAMI.second.second,'o');
    
    
    for(int i = NUM-1; i >= 0; i--){
      for(int j = NUM-1; j >= 0; j--){
	if(field[i][j] != '.') continue;
	int num = check(i,j, 'x');
	
	if(CHARLOTTE.first < num) CHARLOTTE = make_pair(num,make_pair(i,j));
      }
    }
    if(CHARLOTTE.first) put(CHARLOTTE.second.first,CHARLOTTE .second.second,'x');

    if(!TOMOEMAMI.first && !CHARLOTTE.first) break;
  }

  
  print();
  return 0;
}



Measured memory_bytes: 3200
#include <iostream>

using namespace std;

int main(){
    string s; cin >> s;
    bool flag = false;

    for(int i = 0; i < s.size(); i++){
        if(i % 2 == 0){
            if(s[i] == 'L') flag = true;
        }
        else{
            if(s[i] == 'R') flag = true;
        }
    }
    if(flag) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

int main() {
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a) cout<<k<<endl;
    else if(k<=a+b) cout<<a<<endl;
    else cout<<2*a-k+b<<endl;
}

Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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


int main(){
    int N; ll M;
    cin >> N >> M;
    VI A(N); VLL sum(N+1, 0);
    REP(i, N) cin >> A[i];
    SORT(A);
    FORS(i, 1, N) sum[i] = sum[i-1] + A[i-1];
    ll lt = 0, rt = 200001;
    ll cnt = 0;
    while(lt + 1 < rt){//lt: ギリギリm個
        int mid = (lt + rt) / 2;
        cnt = 0;
        REP(i, N){
            cnt += ll(A.end() - lower_bound(ALL(A), mid-A[i]));
        }
        if(cnt >= M) lt = mid;
        else rt = mid;
    }
    cnt = 0;
    REP(i, N){
        cnt += ll(A.end() - lower_bound(ALL(A), lt-A[i]));
    }
   // cout << lt << endl;
    ll ans = 0;
    REP(i, N){
        int idx = A.end() - lower_bound(ALL(A), lt-A[i]);
        ans += (ll)idx * A[i] +  sum[N] - sum[N - idx];
    }
    if(cnt > M) ans -= (cnt - M) * lt;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
#define MAX 100000

int X[MAX],num;

int partition(int p,int r){
  int y,i,j,m;
  y = X[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(X[j] <= y){
      i++;
      m = X[i];
      X[i] = X[j];
      X[j] = m;
    }
  }
  m= X[i+1];
  X[i + 1] = X[r];
  X[r] =m;
  return i+1;
}

int main(){
  int i,q;

  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d",&X[i]);
  }

  q= partition(0,num-1);

  for(i=0;i<num;i++){
    if(i){
      printf(" ");
    }
    if(i == q){
      printf("[");
    }
    printf("%d",X[i]);
    if(i==q){
      printf("]");
    }
  }
    printf("\n");

    return 0;
  }
		  



Measured memory_bytes: 2168
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
using namespace std;
int head[101000],NUM_EDGE;
bool BOOK[101000];
long long DIS[101000];
struct edge
{
	int TO;
	int NEXT;
	int DIS;
}EDGE[201000];
void ADD(int FROM,int TO,int DIS)
{
	EDGE[++NUM_EDGE].NEXT=head[FROM];
	EDGE[NUM_EDGE].TO=TO;
	EDGE[NUM_EDGE].DIS=DIS;
	head[FROM]=NUM_EDGE;
}
int read()
{
	int x=0,f=1; char c=getchar();
	while (c>'9'||c<'0') {if (c=='-') f=-1; c=getchar();}
	while (c>='0'&&c<='9') {x=x*10+(c-'0'); c=getchar();}
	return x*f;
}
void DFS(int X) {
	for (int i=head[X]; i; i=EDGE[i].NEXT)
	if (BOOK[EDGE[i].TO]==0) {
		BOOK[EDGE[i].TO]=1;
		DIS[EDGE[i].TO]=DIS[X]+EDGE[i].DIS;
		DFS(EDGE[i].TO);
	}
}
int N,Q,K,U,V,W,X[101000],Y[101000],INF=111199999,MIN;
int main()
{
	N=read();
	for (int i=1; i<=N-1; i++) {
		U=read(); V=read(); W=read();
		ADD(U,V,W); ADD(V,U,W);
	}Q=read(); K=read();
	BOOK[K]=1;
	DFS(K);		
	for (int i=1; i<=Q; i++) {
		X[i]=read(); Y[i]=read(); printf("%lld\n",DIS[X[i]]+DIS[Y[i]]);
	}
	return 0;
}


Measured memory_bytes: 7936
/* ex7_3
   seira3 */

#include <stdio.h>
#include <stdlib.h>

int arrayIn(int obj,int size, int arr[]){ //objがarr内にあるかどうかを判別する関数,あれば1なければ0を返す
    int count = 0;
    for(int i = 0; i < size; i++){
        if(arr[i]==obj){
            count++;
            break;
        }
    }
    return count;
}

int main(void){
    int row, line, count, countRow, countLine, i, j; //変数宣言
    char **square; //元の迷路の二次元配列のポインタ
    int *whiteRow, *whiteLine; //行,列全て'.'の番号を記憶する配列のポインタ
    scanf("%d %d",&row,&line); //rowとlineに入力
    square = (char**)calloc(row, sizeof(char*)); //squareを動的確保
    if(square == NULL){
        fprintf(stderr, "memory allocation errer.\n");
        exit(1);
    }
    for(i = 0; i < row; i++){ //square[i]を動的確保
        square[i] = (char*)calloc(line, sizeof(char));
        if(square[i] == NULL){
            fprintf(stderr, "memory allocation errer.\n");
            exit(1);
        }
    }
    whiteRow = (int*)calloc(row, sizeof(int)); //whiteRowを動的確保
    if(whiteRow == NULL){
        fprintf(stderr, "memory allocation errer.\n");
        exit(1);
    }
    whiteLine = (int*)calloc(line, sizeof(int)); //whiteLineを動的確保
    if(whiteLine == NULL){
        fprintf(stderr, "memory allocation errer.\n");
        exit(1);
    }
    count = 0; //初期化
    countRow = 0; //初期化
    countLine = 0; //初期化
    for(i = 0; i < row; i++){ //squareに入力
        for(j = 0; j < line; j++){
            scanf(" %c",&square[i][j]);
        }
    }
    for(i = 0; i < row; i++){ //全て-1に初期化(0で初期化すると0番目が全て'.'なときに区別がつかなくなる)
        whiteRow[i] = -1;
    }
    for(i = 0; i < line; i++){ //全て-1に初期化(0で初期化すると0番目が全て'.'なときに区別がつかなくなる)
        whiteLine[i] = -1;
    }
    for(i = 0; i < row; i++){ //何行目に全て'.'なのかを探してwhiteRowに格納する
        count = 0;
        for(j = 0; j < line; j++){
            if (square[i][j] == '.'){
                count++;
            }
        }
        if(count == line){
            whiteRow[countRow] = i;
            countRow++;
        }
    }
    for(i = 0; i < line; i++){ //何列目に全て'.'なのかを探してwhiteLineに格納する
        count = 0;
        for(j = 0; j < row; j++){
            if (square[j][i] == '.'){
                count++;
            }
        }
        if(count == row){
            whiteLine[countLine] = i;
            countLine++;
        }
    }
    for(i = 0; i < row; i++){ //答えを出力する
        for(j = 0; j < line; j++){
            if(arrayIn(i,row,whiteRow) == 0 && arrayIn(j,line,whiteLine) == 0){ //もし全て'.'の行,列に属していなかったら
                printf("%c",square[i][j]);
            }
        }
        if(arrayIn(i,row,whiteRow) == 0){ //行が全て'.'でなければ改行
            printf("\n");
        }
    }
    //確保した配列を解放
    free(whiteLine);
    free(whiteRow);
    for (i = 0; i < row; i++){
        free(square[i]);
    }
    free(square);
    return 0;
}

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

const int MAX = 6e4;
bool is_prime[MAX];

void prime_list() {
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < MAX; i++) {
    for (int j = 2; i * j < MAX; j++) {
      is_prime[i*j] = false;
    }
  }
}

int main() {
  fill(is_prime, is_prime + MAX, true);
  prime_list();
  int N;
  cin >> N;

  // 解答
  int cnt = 0;
  for (int i = 2; i < MAX; i++) {
    if (!is_prime[i]) continue;
    if (i % 5 == 1) {
      cout << i;
      cnt++;
      if (cnt == N) {
        cout << endl;
        return 0;
      } else if (cnt < N) {
        cout << " ";
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vvi ca(N, vi(N - 1));
    vvi a(N, vi(N - 1));
    REP(i, N)
    cin >> ca[i];
    vvi f(N, vi(N, -1));
    int x = 0;
    REP(i, N)
    REP(j, N - 1) {
        int &tmp = f[min(i, ca[i][j] - 1)][max(i, ca[i][j] - 1)];
        if (tmp != -1) {
            a[i][j] = tmp;
        } else {
            tmp = x;
            a[i][j] = x++;
        }
    }
    dump(a);
    vi col(N + 1, 0);
    vi ph(N * N, 0);
    vi flag(N * N, -1);
    function<void(int, int)> dfs = [&](int phase, int row) {
        if (col[row] == N - 1)
            return;
        int n = a[row][col[row]];
        dump(phase, row, n);
        if (flag[n] != -1) {
            col[row]++;
            int &row2 = flag[n];
            col[row2]++;
            dump(row, row2);
            ph[n] = max(phase, ph[n]);
            dfs(ph[n] + 1, row);
            dfs(ph[n] + 1, row2);
        } else {
            flag[n] = row;
            ph[n] = phase;
        }
    };
    REP(i, N) {
        dfs(1, i);
    }
    dump(ph);
    REP(i, N) {
        if (col[i] != N - 1) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << *max_element(ALL(ph)) << endl;
}

Measured memory_bytes: 19968
import itertools
import math
n=int(input())
t=[0]*n
for i in range(n):
  t[i]=list(map(int,input().split()))
  
s=list(itertools.permutations(range(n)))
ans=0
x=math.factorial(n)
for i in range(x):
  u=s[i]
  p=0
  for j in range(n-1):
    p+=((t[u[j+1]][0]-t[u[j]][0])**2+(t[u[j+1]][1]-t[u[j]][1])**2)**(1/2)
    
  ans+=p
print(ans/x)




Measured memory_bytes: 7972
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int X = scan.nextInt();
		scan.close();
		int k = A + B - X;
		int t = X - A;
		if(k >= 0 && t >= 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

	}
}

Measured memory_bytes: 22228
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin>>a.at(i);
  for(int _=0;_<k;_++){
    vector<int> p=a;
    vector<int> d(n+1,0);
    for(int i=0;i<n;i++){
      d.at(max(i-p.at(i),0))++;
      d.at(min(i+p.at(i)+1,n))--;
    }
    a.at(0)=d.at(0);
    for(int i=1;i<n;i++)
      a.at(i)=a.at(i-1)+d.at(i);
    if(p==a)
      break;
  }
  for(int i=0;i<n;i++)
    cout<<a.at(i)<<(i+1<n?" ":"");
  cout<<endl;
}

Measured memory_bytes: 5644
H, W = map(int,input().split())

src = [input() for i in range(H)]

ans = []
for row in src:
    ans.append(list(row))

answer = "Yes"
for i in range(H):
    for j in range(W):
        if ans[i][j]== "#":
            if i-1>= 0 and ans[i-1][j]=="#":
                continue
            elif i+1<= H-1 and ans[i+1][j]=="#":
                continue
            elif j-1 >= 0 and ans[i][j-1]=="#":
                continue
            elif j+1 <= W-1 and ans[i][j+1]=="#":
                continue
            else:
                answer = "No"
                break
print(answer)  

Measured memory_bytes: 3064
s = list(input())
k = int(input())-1
s = s[:k+1]
nums = ["2","3","4","5","6","7","8","9"]

ans_idx = k
for n in nums:
    if n not in s:
        continue
    cur_idx = s.index(n)
    ans_idx = min(ans_idx,cur_idx)

print(s[ans_idx])

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


int main(){
	int a,b,c;
	cin >> a >> b >> c;
	for(int i = 0 ; i < 1000000 ; i++){
		if( i % 60 == c && i % (a+b) <= a ){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;

}

Measured memory_bytes: 1164
nx = list(map(int, list(input().split())))
n = nx[0]
x = nx[1]

l = list(map(int, list(input().split())))

goukei = 0
for i in range(n + 1):
    if goukei > x:
        print(i)
        break
    if i == n:
        print(n + 1)
        break
    goukei = goukei + l[i]



Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`
	8
	ABABBABA
										`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	s := next()

	ans := 0
	if s == "RRR" {
		ans = 3
	} else if strings.Index(s, "RR") >= 0 {
		ans = 2
	} else if strings.Index(s, "R") >= 0 {
		ans = 1
	}

	//fmt.Fprintln(out, "[DEBUG]", a)
	fmt.Fprintln(out, ans)

}

// 挿入ソート配列
type slist struct {
	l []int
}

func makeSlist() slist {
	return slist{[]int{}}
}

func (s *slist) add(a int) {
	pos := sort.Search(len(s.l), func(i int) bool { return s.l[i] >= a })
	if pos < len(s.l) {
		s.l = append(s.l[:pos+1], s.l[pos:]...)
		s.l[pos] = a
	} else {
		s.l = append(s.l, a)
	}
}
func (s slist) contains(a int) bool {
	pos := sort.Search(len(s.l), func(i int) bool { return s.l[i] >= a })
	return pos < len(s.l) && s.l[pos] == a
}

//------------------------------------------------------------------------------

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func printArray(a []int) {
	for i := 0; i < len(a); i++ {
		if i >= 1 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, a[i])
	}
	fmt.Fprintln(out)
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func log10(x int) float64 {
	return math.Log10(float64(x))
}
func divCeil(shi, bo int) int {
	ans := shi / bo
	if shi%bo != 0 {
		ans++
	}
	return ans
}


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

constexpr int lim = 500;

int n, m, q;
int asum[lim+1][lim+1];

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

  while(m--){
    int l, r; cin >> l >> r;
    asum[l][r]++;
  }
 
  for(int i=1; i<=lim; i++){
    for(int j=0; j<=lim; j++)
      asum[i][j] += asum[i-1][j];
  }
  for(int j=1; j<=lim; j++){
    for(int i=0; i<=lim; i++)
      asum[i][j] += asum[i][j-1];
  }

  while(q--){
    int l, r; cin >> l >> r;
    cout << asum[r][r] - asum[l-1][r] << endl;
  }

  return 0;
}


Measured memory_bytes: 1920
import math
from math import sqrt
import sys
from collections import deque, defaultdict
from heapq import heappop,heappush
from copy import deepcopy

INF=10**18
MOD=10**9+7
MAX=10**5+7



def main():
  N=int(input())
  dp=[[0]*3 for i in range(MAX)]
  
  for i in range(N):
    a,b,c=map(int, input().split())
    dp[i+1][0]=max([dp[i+1][0], dp[i][1]+a, dp[i][2]+a])
    dp[i+1][1]=max([dp[i+1][1], dp[i][2]+b, dp[i][0]+b])
    dp[i+1][2]=max([dp[i+1][2], dp[i][0]+c, dp[i][1]+c])
  print(max(dp[N]))

if __name__=='__main__':
  main()





Measured memory_bytes: 58220
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	int totalDist;
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	public Graph() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int i, j;
		for(i = 0; i < totalVertex; i ++) {
			ifSettled[i] = false;
			for(j = 0; j < totalVertex; j ++) {
				adjWeight[i][j] = in.nextInt();
				if (adjWeight[i][j] != -1) {
					adjMatrix[i][j] = 1;
				}
			}
		}
		in.close();
	}
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	//implement the following	
	public int Dijkstra(int s) {
		int[] dist = new int[totalVertex];
		LinkedList<Integer> unsettled = new LinkedList<Integer>();
		for(int i = 0; i < totalVertex; i++) {
			unsettled.add(i);
			dist[i] = Integer.MAX_VALUE;
			ifSettled[i] = false;
		}
		dist[0] = 0;
		
		while(!unsettled.isEmpty()) {
			Integer shortestNeighbor = getUnsettledNearest(dist);
			
			ifSettled[shortestNeighbor] = true;
			unsettled.remove(shortestNeighbor); 
			
			LinkedList<Integer> neighbors = getUnsettledNeighbors(shortestNeighbor);
			Iterator<Integer> iterateneighbors = neighbors.iterator();
			
			while(iterateneighbors.hasNext()){
				int curr = iterateneighbors.next();
				if(dist[curr] > adjWeight[shortestNeighbor][curr]) {
					dist[curr] = adjWeight[shortestNeighbor][curr];
				}
			}
			
		}
		for(int i = 0; i < dist.length; i++) {
			totalDist = totalDist + dist[i];
		}
		
		return totalDist;
	}
}


public class Main {
	public static void main(String[] argv) {
		Graph g = new Graph();
		g.loadAdjMatrix();
		int dist = g.Dijkstra(0);
		System.out.println(dist);
	}
}



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

int main(){
    int N;
    cin>>N;
    
    vector<int> a(100001,0),b(100001,0);
    for(int i=0;i<N;i++){
        int j;
        cin>>j;
        a[j]++;
    }
    
    b[0]=a[0]+a[1];
    b[100000]=a[99999]+a[100000];
    
    int maxv=max(b[0],b[100000]);
    
    for(int i=1;i<100000;i++){
        b[i]=a[i-1]+a[i]+a[i+1];
        maxv=max(maxv,b[i]);
    }
    
    cout<<maxv<<endl;
}

Measured memory_bytes: 1024
N, A = map(int, input().split())
X = list(map(int, input().split()))
xmax = max(X)

OFS = N*xmax
dp = [[0]*(2*OFS+1) for _ in range(N)]
dp[0][OFS] += 1
dp[0][OFS+(X[0]-A)] += 1

for i in range(1, N):
  for s in range(2*OFS+1):
    t = s-(X[i]-A)
    if t < 0 or t > 2*OFS:
      dp[i][s] = dp[i-1][s]
    else:
      dp[i][s] = dp[i-1][s] + dp[i-1][t]

      
print(dp[N-1][OFS]-1)

Measured memory_bytes: 5492
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll fastpower(ll x, ll y, ll MOD){
    ll res=1;
    while(y>0){
        if(y&1)
            res=res*x%MOD;
        y>>=1;
        x=(ll)x*x%MOD;
    }
    return res;
}

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

	ll n, ans1=0, ans2=0, cnt=0;
	cin >> n;
	string str;
	cin >> str;
	for(char ch: str)
        if(ch=='1')
            cnt++;
	for(ll i=0; i<n; i++){
        if(str[i]=='1'){
            ans1=(ans1+fastpower(2, n-i-1, cnt+1))%(cnt+1);
            if(cnt>1)
                ans2=(ans2+fastpower(2, n-i-1, cnt-1))%(cnt-1);
        }
	}
	for(ll i=0; i<n; i++){
        if(str[i]=='0'){
            ll tmp=(ans1+fastpower(2, n-i-1, cnt+1))%(cnt+1), c=1;
            while(tmp>0){
                tmp=tmp%(__builtin_popcount(tmp));
                c++;
            }
            cout << c << endl;
        }
        else{
            if(cnt==1){
                cout << 0 << endl;
                continue;
            }
            ll tmp=(ans2+(cnt-1)-fastpower(2, n-i-1, cnt-1))%(cnt-1), c=1;
            while(tmp>0){
                tmp=tmp%(__builtin_popcount(tmp));
                c++;
            }
            cout << c << endl;
        }
	}

	return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N, Q;
    string S;
    cin >> N >> S >> Q;

    //各アルファベットの出現位置を小さい順に格納する
    V(set<int>) nums(26);

    rep(i, S.size()) nums[S[i]-'a'].insert(i);

    rep(i, Q) {
        int a;
        cin >> a;
        if(a==1) {
            int ii; char c;
            cin >> ii >> c;
            ii--;

            //位置データの交換
            nums[S[ii]-'a'].erase(ii);
            S[ii] = c;
            nums[S[ii]-'a'].insert(ii);

        } else {
            int l, r;
            cin >> l >> r;
            l--; r--;
            int cnt = 0;
            
            rep(j, 26) {

                //各アルファベットについて、l以降で最も最初に現れる位置のイテレータを取得する
                auto it = nums[j].lower_bound(l);

                //取得した位置がrを越えていなければ、lとrの間にそのアルファベットは存在する
                //l以降1つも存在せず、終端のイテレータを取得している場合に注意する
                if(*it<=r && it!=nums[j].end()) cnt++;    
            }

            cout << cnt << endl;
        }
    }



    
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> B(N-1);
  for(int i=0;i<N-1;i++){
    cin >> B.at(i);
  }
  int sum=0;
  for(int i=0;i<N;i++){
    if(i==0){
      sum+=B.at(0);
    }
    else if(i==N-1){
      sum+=B.at(N-2);
    }
    else{
      sum+=min(B.at(i-1),B.at(i));
    }
  }
  cout << sum << endl;
}  

Measured memory_bytes: 3596
#include <stdio.h>

int main(void)
{
	int r, c, i, j;
	scanf("%d %d", &r, &c);

	int ss[101][101] = {};

	for (i = 0; i < r; i++) {
		for (j = 0; j < c; j++) {
			int n;
			scanf("%d", &n);
			ss[i][j] = n;
			ss[i][c] += n;
			ss[r][j] += n;
			ss[r][c] += n;
		}
	}

	for (i = 0; i <= r; i++) {
		for (j = 0; j < c; j++) {
			printf("%d ", ss[i][j]);
		}
		printf("%d\n", ss[i][c]);
	}

	return 0;
}

Measured memory_bytes: 648
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

#define rep(i,a,n) for(int (i)=a;(i)<(int)(n);(i)++)
#define rrep(i,a,n) for(int (i)=(n)-1;(i)>=a;(i)--)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

const int INF = 1e9;

int main() {
	while (true) {
			int h,w;
			cin >> h >> w;
			if (h == 0 and w == 0) {
					return 0;
			}
			rep(i,0,h) {
					rep(j,0,w) cout << "#";
					cout << endl;
			}
			cout << endl;
	}	
}

Measured memory_bytes: 3084
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    while(1){
        int n, m;
        cin>>n>>m;
        if(n==0 && m==0) return 0;
        int a[1010][41];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++) cin>>a[i][j];
        }
        if(m==1){
            cout<<1<<endl;
            continue;
        }
        vector<int> g[41];
        for(int p=0; p<m; p++){
            for(int q=0; q<p; q++){
                bool nuee=0;
                for(int i=0; i<n; i++){
                    for(int j=0; j<i; j++){
                        if((a[i][p]-a[j][p])*(a[i][q]-a[j][q])<0){
                            nuee=1;
                            break;
                        }
                    }
                    if(nuee) break;
                }
                if(nuee){
                    g[p].push_back(q);
                    g[q].push_back(p);
                }
            }
        }
        bool b[1<<20]={};
        int d[1<<20];
        d[0]=0;
        b[0]=1;
        for(int i=0; i<(1<<(m/2)); i++){
            if(!b[i]) continue;
            for(int j=0; j<m/2; j++){
                if(i&(1<<j)) continue;
                bool dame=0;
                d[i^(1<<j)]=d[i];
                for(auto k:g[j]){
                    if(k<m/2 && (i&(1<<k))){
                        dame=1;
                    }
                    if(k>=m/2){
                        d[i^(1<<j)]|=(1<<(k-m/2));
                    }
                }
                if(!dame) b[i^(1<<j)]=1;
            }
        }
        bool c[1<<20]={};
        int cnt[1<<20]={};
        c[0]=1;
        for(int i=0; i<(1<<(m-m/2)); i++){
            if(!c[i]) continue;
            cnt[i]=popcount(i);
            for(int j=0; j<m-m/2; j++){
                if(i&(1<<j)) continue;
                bool dame=0;
                for(auto k:g[m/2+j]){
                    if(k>=m/2 && (i&(1<<(k-m/2)))){
                        dame=1;
                        break;
                    }
                }
                if(!dame) c[i^(1<<j)]=1;
            }
        }
        for(int j=0; j<m-m/2; j++){
            for(int i=0; i<(1<<(m-m/2)); i++){
                if(i&(1<<j)){
                    cnt[i]=max(cnt[i], cnt[i^(1<<j)]);
                }
            }
        }
        int ans=0;
        for(int i=0; i<(1<<(m/2)); i++){
            if(b[i]){
                int x=(1<<(m-m/2))-1-d[i];
                ans=max(ans, popcount(i)+cnt[x]);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 13512
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int v = sc.nextInt();
        int b = sc.nextInt();
        int w = sc.nextInt();
        int t = sc.nextInt();
        int dist = b-a;
        double tt = 0;
      	String ans = "YES";
      	if(b>a){
      	    tt = (double)(b-a)/(v-w);
      	}else if(a>b){
      	    tt = (double)(a-b)/(v-w);
      	}
        if(t<tt){
            ans = "NO";
        }else if(w>v){
            ans = "NO";
        }
        
        System.out.println(ans);
   }
}


Measured memory_bytes: 35576
#include <iostream>
#include <stack>

using namespace std;

int main() {
    stack<int> s1;
    stack<pair<int, int>> s2;

    char c;
    int sum = 0;
    for (int i = 0; cin >> c; i++) {
        switch (c) {
            case '\\':
                s1.push(i);
                break;
            case '/':
                if (s1.size() > 0) {
                    int j = s1.top();
                    s1.pop();
                    sum += i - j;
                    int a = i - j;
                    while (s2.size() > 0 && s2.top().first > j) {
                        a += s2.top().second;
                        s2.pop();
                    }
                    s2.push(make_pair(j, a));
                }
                break;
            default:
                break;
        }
    }

    deque<int> ans;
    while (s2.size() > 0) {
        ans.push_front(s2.top().second);
        s2.pop();
    }
    cout << sum << endl;
    cout << ans.size();
    for (auto a : ans) {
        cout << " " << a;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3140
#include<iostream>
#include<queue>
using namespace std;
int main()
{
    int big,meter,i=1;
    priority_queue<int>mountain;
    for(i=0;i<10;i++)
    {
        cin>>meter;
        mountain.push(meter);
    }
        cout<<mountain.top()<<"\n";
        mountain.pop();
        cout<<mountain.top()<<"\n";
        mountain.pop();
        cout<<mountain.top()<<"\n";
        mountain.pop();
    return 0;
}

Measured memory_bytes: 1220
import bisect
n = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

arr = factorization(n) 
#print(arr)
ans = 0

tosa = [0 for _ in range(1000)]
for i in range(1000):
    tosa[i] = int(i*(i+1)/2)

#print(tosa)
for s in arr:
    if(s[0] == 1):
        continue
    num = s[1]
    cnt = bisect.bisect_right(tosa, num) - 1
    #print(cnt)
    ans += cnt

print(ans)



Measured memory_bytes: 63932
def fact(n)
  return 1 if n == 0
  return n * fact(n-1)
end

def distance(p1, p2)
  x1 = p1[0]
  y1 = p1[1]
  x2 = p2[0]
  y2 = p2[1]
  return Math.sqrt( (x1-x2)**2 + (y1-y2)**2 )
end

def main
  n = gets.to_i
  ps = []
  n.times do
    point = gets.chomp.split(" ").map(&:to_i)
    ps.push point
  end
  dist = 0
  (0..n-1).to_a.permutation do |perm|
    (0..n-2).each do |i|
      dist += distance(ps[perm[i]], ps[perm[i+1]])
    end
  end
  puts dist * 1.0 / fact(n)
end

main



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

using namespace std;

int a, b, c, k;

int main(){
	scanf("%d%d%d%d", &a, &b, &c, &k);
	
	int mx = max({a, b, c});
	
	printf("%d\n", a + b + c - mx + mx * (1 << k));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=2*100010;
int n,a[N];
int f[N];
bool use[N];
int count0;
int main()
{
	scanf("%d",&n);
	for(int k=1;k<=n;k++)
		scanf("%d",&a[k]);
	for(int k=n;k>=1;k--)
	{
		if(f[k]%2!=a[k])
		{
			f[k]=1;
			count0++,use[k]=true;
			int maxn=sqrt(k);
			for(int i=2;i<=maxn;i++)
				if(k%i==0)
				{
					f[i]++;
					if(k/i!=i)
						f[k/i]++;
				}
			f[1]++;
		}
	}
	printf("%d\n",count0);
	for(int k=1;k<=n;k++)
		if(use[k])
			printf("%d ",k);
	return 0;
}

Measured memory_bytes: 2688
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int a=stdIn.nextInt(),b=stdIn.nextInt(),c=stdIn.nextInt(),x=stdIn.nextInt(),s=0,i,j,k;
		for(i=0;i<=a;i++) for(j=0;j<=b;j++) for(k=0;k<=c;k++) if(500*i+100*j+50*k==x) s++;
		System.out.print(s);
	}
}

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

int aaa(int a, int b) {
    
}

int main() {
    int Si, h, m, s;
    cin >> Si;
    s = Si % 60;
    m = (Si / 60) % 60;
    h = Si / 60 / 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

template <class Abel> class unionfind
{
public:
  vector<ll> parent;
  vector<ll> rank;
  vector<Abel> diffw;

  unionfind(ll N, Abel U = 0)
  {
    parent = vector<ll>(N, -1);
    rank = vector<ll>(N, 0);
    diffw = vector<Abel>(N, U);
  }

  ll root(ll X)
  {
    if (parent.at(X) < 0) return X;
    ll R = root(parent.at(X));
    diffw.at(X) += diffw.at(parent.at(X));
    return parent.at(X) = R;
  }

  ll size(ll X)
  {
    return -parent.at(root(X));
  }

  Abel weight(ll X)
  {
    root(X);
    return diffw.at(X);
  }

  Abel diff(ll X, ll Y)
  {
    return weight(Y) - weight(X);
  }

  bool same(ll X, ll Y)
  {
    return (root(X) == root(Y));
  }

  bool unite(ll X, ll Y, Abel W = 0)
  {
    W += weight(X);
    W -= weight(Y);

    X = root(X);
    Y = root(Y);
    if (X == Y) return false;
    
    if (rank.at(X) < rank.at(Y)) 
    {
      swap(X, Y);
      W = -W;
    }
    if (rank.at(X) == rank.at(Y)) rank.at(X)++;
    parent.at(X) += parent.at(Y);
    parent.at(Y) = X;
    diffw.at(Y) = W;
    return true;
  }
};

int main()
{
  ll N, M, K;
  cin >> N >> M >> K;

  unionfind<ll> uf(N);
  vector<ll> fre(N, 0);
  for (ll i = 0; i < M; i++)
  {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    fre.at(a)++, fre.at(b)++;
    uf.unite(a, b);
  }

  vector<ll> blo(N, 0);
  for (ll i = 0; i < K; i++)
  {
    ll c, d;
    cin >> c >> d;
    c--, d--;
    if (uf.same(c, d))
      blo.at(c)++, blo.at(d)++;
  }

  for (ll i = 0; i < N; i++)
  {
    cout << -uf.parent.at(uf.root(i)) - 1 - (blo.at(i) + fre.at(i));
    cout << ((i == N - 1) ? '\n' : ' ');
  }
}

Measured memory_bytes: 4736
S = input()

result = "NO"

while True:
    if S[-5:] == "dream":
        if len(S) == 5:
            result = "YES"
            break
        S = S[:-5]
    elif S[-5:] == "erase":
        if len(S) == 5:
            result = "YES"
            break
        S = S[:-5]
    elif S[-6:] == "eraser":
        if len(S) == 6:
            result = "YES"
            break
        S = S[:-6]
    elif S[-7:] == "dreamer":
        if len(S) == 7:
            result = "YES"
            break
        S = S[:-7]
    else:
        break

print(result)

Measured memory_bytes: 3188
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int D;
int c[26];
int s[365][26];
int t[365];
int partial_score[26];

int calc_score() {
	int score = 0;
	int last[26];

	for (int i=0; i<26; i++) {
		last[i] = -1;
		partial_score[i] = 0;
	}

	for (int d=0; d<D; d++) {
		for (int i=0; i<26; i++) {
			if (i == t[d]) {
				score += s[d][i];
				partial_score[i] += s[d][i];
				last[i] = d;
			} else {
				score -= c[i] * (d - last[i]);
				partial_score[i] -= c[i] * (d - last[i]);
			}
		}
	}

	return score;
}

void calc_partial_score(int i) {
	partial_score[i] = 0;
	int last = -1;

	for (int d=0; d<D; d++) {
		if (i == t[d]) {
			partial_score[i] += s[d][i];
			last = d;
		} else {
			partial_score[i] -= c[i] * (d - last);
		}
	}
}

int main() {
	cin >> D;

	for (int i=0; i<26; i++) {
		cin >> c[i];
	}

	for (int d=0; d<D; d++) {
		for (int i=0; i<26; i++) {
			cin >> s[d][i];
		}
	}

	for (int d=0; d<D; d++) {
		cin >> t[d];
		t[d]--;
	}

	int score = calc_score();

	int M;
	cin >> M;

	vector<int> score_list;

	int d, q;
	for (int i=0; i<M; i++) {
		cin >> d >> q;
		d--;
		q--;

		int prev_q = t[d];

		score -= partial_score[prev_q];
		score -= partial_score[q];

		t[d] = q;
		calc_partial_score(prev_q);
		calc_partial_score(q);

		score += partial_score[prev_q];
		score += partial_score[q];

		score_list.push_back(score);
	}

	for (int score : score_list) {
		cout << score << endl;
	}

	return 0;
}

Measured memory_bytes: 3816
let max_m = 2000

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let make_dp a n =
  let dp = Array.make_matrix (n + 1) (max_m + 1) false in
  for i = 1 to n do
    dp.(i).(a.(i-1)) <- true
  done;
  for i = 2 to n do
    for j = 1 to max_m do
      if dp.(i-1).(j) then dp.(i).(j) <- true
      else if j > a.(i-1) && dp.(i-1).(j - a.(i-1)) then dp.(i).(j) <- true;
    done;
  done;
  dp

let () =
  let read_ns () = read_line () |> split_on_char ' ' |> List.map int_of_string in
  let n = read_int () in
  let a = read_ns () |> Array.of_list in
  let _ = read_int () in
  let dp = make_dp a n in
  read_ns () |> List.iter (fun e -> print_endline (if dp.(n).(e) then "yes" else "no"))

Measured memory_bytes: 2388
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(void){
  
  vector<char>v;
  string s;
  
  while(getline(cin,s)){
    v.clear();
    for(int i=0;i<s.size();i++){
      if(s[i]=='@'){
	for(int j=0;j<s[i+1]-'0';j++){
	  v.push_back(s[i+2]);
	}
	i+=2;
      }
      else v.push_back(s[i]);
    }
    for(int i=0;i<v.size();i++)cout << v[i];
    cout << endl;  
  }
  return 0;
}

Measured memory_bytes: 1188