akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 2e9;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  map<int, bool> m;
  rep(i, n) {
    if (m[a[i]]) {
      cout << "NO" << endl;
      return 0;
    }
    else m[a[i]] = true;
  }
  cout << "YES" << endl;


  
  return 0;
}

Measured memory_bytes: 10368
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s = sc.next();
        String[] str = new String[4];
        str = s.split("");
        if (str[0].equals(str[1]) && str[2].equals(str[3]) && !str[1].equals(str[2]))
            System.out.println("Yes");
        else if (str[0].equals(str[2]) && str[1].equals(str[3]) && !str[1].equals(str[2]))
            System.out.println("Yes");
        else if (str[0].equals(str[3]) && str[1].equals(str[2]) && !str[1].equals(str[0]))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

Measured memory_bytes: 22612
H,W=map(int,input().split())
a=[list(input()) for i in range(H)]
c=[0 for i in range(26)]
x=0
for i in range(H):
    for j in range(W):
        c[ord(a[i][j])-97]+=1
y=[0,0,0,0]
for i in range(26):
    y[c[i]%4]+=1
if H%2==0 and W%2==0:
    if y[1]+y[2]+y[3]==0:
        print("Yes")
    else:
        print("No")
elif (H-W)%2==1:
    if y[1]+y[3]==0:
        X=H if H%2==0 else W
        if y[2]>X//2:
            print("No")
        else:
            print("Yes")
    else:
        print("No")
else:
    if y[1]+y[3]==1:
        P=y[3]+y[2]
        if P>(W+H-2)//2:
            print("No")
        else:
            print("Yes")
    else:
        print("No")


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
  	int a1, a2, a3;
    Scanner scanner = new Scanner(System.in);
    a1 = scanner.nextInt();
    a2 = scanner.nextInt();
    a3 = scanner.nextInt();
    
    int sum = a1 + a2 + a3;
    
    if (sum >= 22) {
    	System.out.println("bust");
    } else {
    	System.out.println("win");
    }
  }
}


Measured memory_bytes: 21844
#include<stdio.h>

int main() {
	int n, d, x, cnt, i, temp;
	scanf("%d%d%d", &n, &d, &x);
	cnt = x;
	for (i = 0; i < n; i++) {
		scanf("%d", &temp);
		cnt += (d - 1) / temp + 1;
	}
	printf("%d", cnt);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
	int n,i;
	int p,d1,d2;
	int tmp,ans,max=-1;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		max=-1;
		for(i=0;i<n;i++){
			scanf("%d %d %d",&p,&d1,&d2);
			if(d1+d2>max){
				tmp=p;
				max=d1+d2;
			}
		}
		printf("%d %d\n",tmp,max);
	}
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){

	long N, A , B;

	cin >> N;
	cin >> A;
	cin >> B;

	long min = (N - 1) * A + B;
	long max = (N - 1) * B + A;

	long ans = max - min + 1;

	if(ans < 0)	ans = 0;

	cout << ans;

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define all(x) x.begin(),x.end()
using namespace std;
const ll LLINF = (1LL << 60LL);

struct edge{
    ll to,cost;
};
ll n,m,l,q;
vector<edge>  G[100010];
ll d[100010];
ll D[400][400];
ll cost[310][310];

void  dijkstra(int s){
    priority_queue<pii,vector<pii>,greater<pii>> que;
    fill(d,d+n+1,LLINF);
    d[s]=0;
    que.push(pii(0,s));

    while(!que.empty()){
        pii p=que.top();que.pop();
        ll v=p.second;
        if(d[v]<p.first) continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    } 
    rep(i,n){
        cost[s][i]=d[i];
    }
}



int main(){
    cin>>n>>m>>l;
    rep(i,310)rep(j,310){
        cost[i][j]=LLINF;
        D[i][j]=LLINF;
    }
    rep(i,m){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    cin>>q;
    rep(i,n){
        dijkstra(i);
    }
    rep(i,310){
        G[i].clear();
    }
    rep(i,n)rep(j,n){
        if(cost[i][j]<=l){
            G[i].push_back({j,1});
            G[j].push_back({i,1});
        }
    }
    rep(i,n){
        dijkstra(i);
    }
    rep(i,q){
        ll s,t,L=l,ans=0;
        cin>>s>>t;
        s--;t--;
        if(cost[s][t]>=LLINF){
            ans=-1;
        }
        else{
            ans=cost[s][t]-1;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 11648
#include "bits/stdc++.h"
		using namespace std;
		#define sim template < class c
		#define ris return * this
		#define dor > debug & operator <<
		#define eni(x) sim > typename \
		  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
		sim > struct rge { c b, e; };
		sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
		sim > auto dud(c* x) -> decltype(cerr << *x, 0);
		sim > char dud(...);
		struct debug {
		#ifdef LOCAL
		~debug() { cerr << endl; }
		eni(!=) cerr << boolalpha << i; ris; }
		eni(==) ris << range(begin(i), end(i)); }
		sim, class b dor(pair < b, c > d) {
		  ris << "(" << d.first << ", " << d.second << ")";
		}
		sim dor(rge<c> d) {
		  *this << "[";
		  for (auto it = d.b; it != d.e; ++it)
			*this << ", " + 2 * (it == d.b) << *it;
		  ris << "]";
		}
		#else
		sim dor(const c&) { ris; }
		#endif
		};
		#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
		#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
			#define int  long long int
			#define pb push_back
			#define fe first
			#define lb lower_bound 
			#define ub upper_bound
			#define pii pair<pair<int,int>,pair<int,int> >
			#define se second
			#define endl "\n"
			#define pi pair<int, int>
			#define mi          map<int,int>
			#define mii         map<pi,int>
			#define vi vector<int> 
			#define vvi vector<vi>
			#define bs   binary_search
			#define rep(i,a,b) for(int i=a;i<b;i++)
			#define rep1(i,a,b) for(int i=a;i<=b;i++)	
			#define all(c) (c).begin(),(c).end()
			#define sz(x)       (int)x.size() 
			#define PI 3.14159265358979323846
			
			 const int N =1e5;
			
			 int mod= 1e9+7;
			 int dx[4]={0,0,+1,-1};
			 int dy[4]={+1,-1,0,0};  
			 
			 
			int po(int a, int b) {
				a %= mod;
				int res = 1;
				while (b > 0) {
					if (b & 1)
						res = (res * a) % mod;
					a =(a*a) % mod;
					b >>= 1;
				}
				 return res;	
			   }
	  
			
			 void solve(){
				 string s;
				 cin>>s;
				 s='#'+s;
				 if(s[3]==s[4] && s[5]==s[6]) {
					   cout<<"Yes\n";
					 }
				else 
				    cout<<"No\n";
				 
			 }
			
			  int32_t main() {
				cool;
				int t=1;
				//cin>>t;
				while(t--)
				   solve();
				   
				   
				   return 0;	   
			   }


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

using namespace std;
typedef long long ll;
constexpr int M=1e9+7, MAXN=2048;
int n, k;

int a[MAXN], ile[MAXN];
int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> k;
	
	for(int i=0; i < n; ++i)
	{
		cin >> a[i];
		++ile[a[i]];
	}
	
	for(int i=1; i < MAXN; ++i)
		ile[i] += ile[i-1];
	
	
	ll wynik=0;	
	//inwersje wewnątrz bloku
	for(int i=1; i < n; ++i)
	{
		int pom=0;
		for(int j=0; j < i; ++j)
			if(a[j] > a[i])
				++pom;
				
		wynik += ll(k)*pom;
		wynik %= M;
	}
	
	
	//inwersje między blokami
	for(int i=0; i < n; ++i)
	{
		int u = ile[a[i]-1];
		
		ll wyst = ll(k)*(k-1)/2;
		wyst %= M;
		
		
		wynik += wyst*u;
		wynik %= M;
	}
	
	cout << wynik;
	
	
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int n, Q, a[SIZE];
ll sum[SIZE] = {}, sum_e[SIZE][2] = {};

int main(){

  scanf("%d%d", &n, &Q);

  for(int i=0;i<n;i++){
    scanf("%d", a+i);
    sum[i+1] = sum[i] + a[i];
    sum_e[i+1][0] += sum_e[i][0];
    sum_e[i+1][1] += sum_e[i][1];
    sum_e[i+1][i%2] += a[i];
  }

  for(int i=0;i<Q;i++){
    int x;
    scanf("%d", &x);

    int pos = lower_bound(a, a+n, x) - a;

    int l = 0, r = 1e9;

    while(l < r){
      int mid = (l+r)/2;

      int c1 = upper_bound(a, a+n, x+mid) - lower_bound(a, a+n, x-mid);
      int c2 = a+n - lower_bound(a, a+n, x+mid+1);

      if (c1 < c2) {
        l = mid+1;
      } else {
        r = mid;
      }
    }

    int posA = lower_bound(a, a+n, x+l+1) - a;
    int posB = lower_bound(a, a+n, x-l) - a;

    if (n - posA < posA - posB) posA--;

    debug(posA);
    debug(posB);
    debug(l);

    ll sumA = sum[n] - sum[posA] + sum_e[posB][1-n%2];
    ll sumB = sum[posA] - sum[posB] + sum_e[posB][n%2];

    printf("%lld\n", sumA);
  }

  return 0;
}


Measured memory_bytes: 5760
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto B = new int[][](4*K+1, 4*K+1);
    auto W = new int[][](4*K+1, 4*K+1);
    auto P = new Tuple!(int, int, bool)[](N);
    foreach (i; 0..N) {
        auto S = readln.split;
        P[i] = tuple(S[0].to!int, S[1].to!int, S[2] == "B");
    }

    foreach (i; 0..N) {
        int x = P[i][0] % (2 * K);
        int y = P[i][1] % (2 * K);
        if (P[i][2]) {
            B[x+1][y+1] += 1;
            B[x+1][y+1+2*K] += 1;
            B[x+1+2*K][y+1] += 1;
            B[x+1+2*K][y+1+2*K] += 1;
        } else {
            W[x+1][y+1] += 1;
            W[x+1][y+1+2*K] += 1;
            W[x+1+2*K][y+1] += 1;
            W[x+1+2*K][y+1+2*K] += 1;
        }
    }

    foreach (i; 0..4*K+1)
        foreach (j; 0..4*K)
            B[i][j+1] += B[i][j];
    foreach (j; 0..4*K+1)
        foreach (i; 0..4*K)
            B[i+1][j] += B[i][j];

    foreach (i; 0..4*K+1)
        foreach (j; 0..4*K)
            W[i][j+1] += W[i][j];
    foreach (j; 0..4*K+1)
        foreach (i; 0..4*K)
            W[i+1][j] += W[i][j];

    int acm(int x1, int y1, int x2, int y2, int[][] A) {
        return A[x2+1][y2+1] - A[x2+1][y1] - A[x1][y2+1] + A[x1][y1];
    }


    int ans = 0;

    foreach (i; 0..2*K) {
        foreach (j; 0..2*K) {
            int b = acm(i, j, i+K-1, j+K-1, B) + acm(i+K, j+K, i+2*K-1, j+2*K-1, B);
            int w = acm(i, j+K, i+K-1, j+2*K-1, W) + acm(i+K, j, i+2*K-1, j+K-1, W);
            ans = max(ans, b + w);
        }
    }

    ans.writeln;
}


Measured memory_bytes: 132860
//LL:-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>

using namespace std;
#define LL long long
LL N, ans = 1, sc[30] = {};
string S;
LL MOD = 1000000007;

int main() {
	cin >> N >> S;
	for (int i = 0; i < N; i++) 
		sc[S[i]-'a']++;
	for (int i = 0; i < 26; i++) {
		ans *= sc[i] + 1;
		ans %= MOD;
	}
	cout << (ans - 1) % MOD << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define MIN(x, y) ( (x) < (y) ? (x) : (y) )
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define IVFOR(p,a) for(vector<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ILFOR(p,a) for(list<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define CHECK(x)  cout << #x << " = " << (x) << endl
#define FINA(y) cout << (y) << endl

int main(){

  int n;
  cin >> n;
  int a[n];
  double av = 0.0;
  
  REP(i,n){
    cin >> a[i];
    av += double(a[i]);
  }
  av = av / double(n);
  //  CHECK(av);
  int na;
  na = int(av);

  int ans = 0;

  if(av >= double(na) + 0.5)
    REP(i,n){
      ans += (a[i] - na - 1)*(a[i] - na - 1);
    }
  else
    REP(i,n){
      ans += (a[i] - na)*(a[i] - na);
    }

  FINA(ans);
 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,A,B,cost;
    cin >> N >> A >> B;
    
    if(N*A < B){
        cost = N*A;
    }else{
        cost = B;
    }
    cout << cost << endl;
    return 0;
}

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

int main() {

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

    cout << ceil((a + b) / 2.0) << endl;

    return 0;
}

Measured memory_bytes: 3756
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int n = s.nextInt();
			final int m = s.nextInt();

			int maxStart = 0;
			int minEnd = n;

			for (int i = 0; i < m; i++) {
				int start = s.nextInt();
				int end = s.nextInt();
				if (start > maxStart) {
					maxStart = start;
				}
				if (end < minEnd) {
					minEnd = end;
				}
			}
			if (minEnd < maxStart) {
				System.out.println(0);
			} else {
				System.out.println(minEnd - maxStart + 1);
			}
		}
	}
}

Measured memory_bytes: 65036
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

void Solve(
    const vector<int>& a,
    const vector<int>& b,
    const vector<int>& c,
    const vector<int>& d,
    int m,
    int at,
    vector<int>& A,
    int& res) {
  if (at == A.size()) {
    int cur = 0;
    for (int i = 0; i < a.size(); ++i) if (A[b[i]] - A[a[i]] == c[i]) cur += d[i];
    res = max(res, cur);
    return;
  }
  int low = 1;
  if (at > 0) low = A[at - 1];
  for (int i = low; i <= m; ++i) {
    A[at] = i;
    Solve(a, b, c, d, m, at + 1, A, res);
  }
}

int main()
{
  int n, m, q;
  cin >> n >> m >> q;
  vector<int> a(q), b(q), c(q), d(q);
  for (int i = 0; i < q; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }
  vector<int> A(n);
  int res = 0;
  Solve(a, b, c, d, m, 0, A, res);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>

int main(void){
  int n, tmp;
  int i;
  int money;

  money = 100000;

  scanf("%d", &n);

  for (i = 0;i < n;i++){
    money *= 1.05;
    tmp = money / 1000;
    tmp = tmp * 1000;
    if ((money - tmp) != 0){
        money = tmp + 1000;
    }
  }

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

  return 0;
}
  

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    int q;
    cin >> q;
    vector<int> b(q);
    rep(i,q){
        cin >> b[i];
    }

    int G[n+1][2001];
    rep(i,n+1) rep(j,2001) G[i][j]  = 0;
    G[0][0] = 1;

    for(int i = 1; i<=n; ++i){
        rep(j,2001){
            
            if(G[i-1][j]==1) G[i][j]=1;
            if(j-a[i-1]<0) continue;
            if(G[i-1][j-a[i-1]]==1) G[i][j]=1;
        }
    }

    rep(i,q){
        if(G[n][b[i]]==1) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


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

#define endl '\n'

using namespace std;

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

int gcd(int a, int b, int c) {
    return gcd(gcd(a, b), c);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    long long sum = 0;
    cin >> k;
    for(int i = 1; i <= k; i++) {
        for(int j = 1; j <= k; j++) {
            for(int l = 1; l <= k; l++) {
                sum += gcd(i, j, l);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

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

const double EPS = 1e-10;
const double INF = 1e15;

struct Node{
    int num;
    double cost;
    bool operator<(const Node& obj)const{
        return cost > obj.cost + EPS;
    }
};

struct Edge{
    int to;
    double distance;
};

struct Circle{
    double x, y, r;
};

vector<Edge> graph[1005];
vector<Circle> circles;
double mini[1005]={0};

double distance(Circle a, Circle b){
    return max(0.,sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)) - (a.r+b.r));
}

int main(){
    double xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;
    int n;
    cin >> n;
    graph[0].push_back((Edge){n+1, max(0., sqrt((xt-xs)*(xt-xs)+(yt-ys)*(yt-ys)))});
    for(int i=1;i<=n;++i){
        double x, y, r;
        cin >> x >> y >> r;
        circles.push_back((Circle){x, y, r});
        graph[0].push_back((Edge){i, max(0.,sqrt((x-xs)*(x-xs)+(y-ys)*(y-ys))-r)});
        graph[i].push_back((Edge){n+1, max(0.,sqrt((x-xt)*(x-xt)+(y-yt)*(y-yt))-r)});
    }

    for(int i=1;i<=n;++i){
        for(int j=i+1;j<=n;++j){
            graph[i].push_back((Edge){j, distance(circles[i-1], circles[j-1])});
            graph[j].push_back((Edge){i, distance(circles[i-1], circles[j-1])});
        }
    }

    priority_queue<Node> que;
    que.push((Node){0, 0});
    for(int i=0;i<=n+1;++i)mini[i] = INF;
    mini[0] = 0;
    while(!que.empty()){
        Node curr = que.top(); que.pop();
        if(curr.num == n+1){
            printf("%.15lf\n", curr.cost);
            break;
        }
        for(Edge next: graph[curr.num]){
            double newcost = curr.cost + next.distance;
            if(newcost + EPS < mini[next.to]){
                mini[next.to] = newcost;
                que.push((Node){next.to, newcost});
            }
        }
    }

    return 0;
}


Measured memory_bytes: 22292
<?php

$word = strtolower(trim(fgets(STDIN)));

$answer = 0;

do {
  $input = fgets(STDIN);
  if ($input === false) {
    break;
  }

  $input = trim($input);
  if ($input === "END_OF_TEXT") {
    break;
  }

  $data = explode(" ", strtolower($input));
  $answer += count(array_keys($data, $word));

} while (!($input === FALSE));

echo $answer . PHP_EOL;

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

using namespace std;

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

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

    ll n,l;
    cin>>n>>l;

    ll sum = 0;

    for(ll i = 1 ; i <= n ; i++)
    {
    	sum += l + i - 1;
    }

    ll dif = LONG_LONG_MAX;

    ll ans = -1;

    for(ll i = 1 ; i <= n ; i++)
    {
    	ll t1 = sum;
    	t1 -= (l + i - 1);

    	if(abs(t1 - sum) < dif)
    	{
    		ans = t1;
    		dif = abs(t1 - sum);
    	}
    }

    cout<<ans<<endl;

}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define ull unsigned long long
#define ll long long


void add(int &a,int b){
    a+=b;
    if(a>=mod)
        a-=mod;
}

int32_t main()
{
    int a,b,c;cin>>a>>b>>c;
    if(a+b+c>=22){
        cout<<"bust"<<endl;
    }else cout<<"win"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define N 900000
#define ar array
typedef long long int ll;
using namespace std;
int main(void){
	fast;
	ll n,m,i,j,k,ans=0;
	cin>>n>>m>>k;
	ll a[n],b[m];
	ll pa[n+1]={0},pb[m+1]={0};
	for(i=0;i<n;i++){
		cin>>a[i];
		pa[i+1]=pa[i]+a[i];
	}
	for(i=0;i<m;i++){
		cin>>b[i];
		pb[i+1]=pb[i]+b[i];
	}
	j=m;
	for(i=0;i<=n;i++){
		if(pa[i]>k)
		break;
		while(j>=1&&pb[j]>k-pa[i])
		j--;
		ans=max(ans,i+j);
	}
	cout<<ans;
}


Measured memory_bytes: 9888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 1000000007;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    int N, M; cin >> N >> M;

    vi a(M), b(N+1), c(M+2), d(M+1);
    rep(i, M) cin >> a[i];

    if (M == 0) {
        b[1] = 1; b[2] = 2;
        for (int i = 3; i <= N; ++i) b[i] = (b[i - 1] + b[i - 2]) % waz;
        cout << b[N] << endl;
    }
    else {

        b[1] = 1; b[2] = 1;
        for (int i = 3; i <= N; ++i) b[i] = (b[i - 1] + b[i - 2]) % waz;

        c[0] = 0;
        rep(i, M) c[i + 1] = a[i];
        c[M + 1] = N;

        rep(i, M + 1) d[i] = c[i + 1] - c[i];

        ll pr = 1;

        if (d[0] > 1) { pr = pr * b[d[0]] % waz; }

        for (int i = 1; i < M; ++i) {
            pr = pr * b[d[i] - 1] % waz;
        }

            pr = pr * b[d[M]] % waz;

        cout << pr << endl;

    }

}

Measured memory_bytes: 1792
N = gets.to_i
Xs = gets.split.map(&:to_i)

a = Xs.inject(0) {|result, item|
    result + item**2
  }
b = Xs.inject(&:+)

c = (b.to_f / N)

p [c.floor, c.ceil].map{|n| N*(n**2) - 2*b*n + a}.min


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    if (n == 3)cout << "2 5 63" << endl;
    else {
        cout << "2 3 4 9" << endl;
        n -= 4;
        ll now = 2;
        while (n > 3) {
            if (now < 5000) {
                cout << " " << now * 6 + 3;
                cout << " " << now * 6 + 9;
                now += 2;
                n -= 2;
            }
            else if (now < 9999) {
                cout << " " << (now - 4999) * 6 + 2;
                cout << " " << (now - 4999) * 6 + 4;
                now += 1;
                n -= 2;
            }
            else {
                cout << " " << (now - 9998) * 6;
                now += 1;
                n -= 1;
            }
        }
        for (int i = 0; i < n; i++) {
            cout << " " << 30000 - 6 * i;
        }
        cout << endl;
    }
}

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int X;
signed main() {
    cin >> X;
    cout << X / 500 * 1000 + X % 500 / 5 * 5 << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        
        int N = Integer.parseInt(line[0]);
        int A = Integer.parseInt(line[1]);
        int B = Integer.parseInt(line[2]);
    
        int ans = 0;
        for(int i =1;i <= N;i++){
            int result = targetInt(i);
            if (result >= A && result <= B){
                ans += i;
            }
        }
        
    System.out.println(ans);
    }


    public static int targetInt(int n){
        
        if(n == 0){
            return 0;
        }
        
        int result = n % 10;
    
        return result + targetInt(n / 10);	
    }
}

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

#define MAX 1000005
#define INF 200000000
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

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

void IO()
{
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
}

bool flag;
int n,q,m;
int arr[25];

void Fun(int i, int sum)
{
    if(sum==m){
        flag=true;
        return;
    }
    if(i>=n||flag)return;
    if(sum+arr[i]<=m)Fun(i+1,sum+arr[i]);
    Fun(i+1,sum);
}

int main()
{
    //IO();
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&arr[i]);
    scanf("%d",&q);
    for(int i=1;i<=q;i++){
        scanf("%d",&m);
        flag=false;
        Fun(0,0);
        if(flag)printf("yes\n");
        else printf("no\n");
    }
    return 0;
}

Measured memory_bytes: 3168
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var n = IO.RInt;
            var a = IO.RSInt;

            Array.Sort(a);

            long ans = 0;
            for (int i = 0; i < n;)
            {
                int now = a[i];
                int seq = 1;
                int j = i + 1;
                while (true)
                {
                    if (j == n) break;
                    if (a[j] != now) break;
                    seq++; j++;
                }
                if (seq < now) ans += seq;
                else ans += seq - now;
                i += seq;
            }
            WriteLine(ans);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 39520
#include <stdio.h>

int main() {
    char s[100]; //????????°
    char p[100]; //?????????
    int sNumber;
    int pNumber;
    int count; 
    int i, j; 
    int delete; //(????????????????????????
    sNumber = 0;
    pNumber = 0;
    count = 0;

    scanf("%s", s);
    scanf("%s", p);

    for (i = 0; s[i] != '\0'; i++){
        sNumber++;
    }
    for (i = 0; p[i] != '\0'; i++){
        pNumber++;
    }

//printf("%s %s %d %d\n", s, p, sNumber, pNumber);

    for (i = 0; i < sNumber; i++) {
//printf("%c %c\n", s[i], p[0]);
        if (s[i] == p[0]) {
//printf("??\??£???\n");
            count = 0;
            delete = 0;
            for (j = 0; j < pNumber; j++) {
                if (i + j > sNumber - 1){
                    delete = sNumber;
                }
               // printf("---%c %c\n", s[i + j - delete], p[j]);
                if (s[i + j - delete] != p[j]){
                    break;
                }
                count++;
//printf("%d\n", count);
            }
            if (count == pNumber){
                break;
            }
        }
    }
//printf("%d\n", count);

    if (count == pNumber){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
int main() 
{
  	string s;cin>>s;
  	if(s[s.length()-1] == 's') {
      s+="es";
    }
  	else {
      s+='s';
    }
  	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  int c1=0;
  int c2=0;
  for(int i=1;i<=n;i+=2)
  {
    for(int j=1;j<=i;j+=2)
    {
      if(i%j==0) c1++;
    }
    if(c1==8) c2++;
    c1=0;
  }
  cout<<c2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 1000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define P pair<int,int> 
#define INF 1000000000
const int MAX = 1000000;
const int MOD = 1000000007;
ll dp[N];
int main(){
	int h,n;
    cin>>h>>n;
    vector<P> d(n);
    REP(i,n){
        int a,b;
        cin>>a>>b;
        d[i]={a,b};
    }
    sort(ALL(d));
    REP(i,N){
        dp[i]=INF;
    }
    dp[0]=0;
    REP(i,h){
        REP(j,n){
            dp[i+d[j].first]=min(dp[i+d[j].first],dp[i]+d[j].second);
        }
    }
    ll ans=100000000000;
    for(int i=h;i<h+d[n-1].first;i++){
        ans=min(ans,dp[i]);
    }
    OUT(ans);
	return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n;
    cin >> n;
    int a,b,c;
    cin >> a >> b >> c;
    vi in(n);
    rep(i,n)cin >> in[i];
    int ans = LINF;
    rep(bit, 1 << (2*n)){
        vi ta,tb,tc;
        int tmp = bit;
        rep(i,n){
            switch (tmp%4) {
                case 1: ta.push_back(in[i]);break;
                case 2: tb.push_back(in[i]);break;
                case 3: tc.push_back(in[i]);break;
            }
            tmp /= 4;
        }
        if(ta.size() == 0 || tb.size() == 0 || tc.size() == 0)continue;
        int cost = (ta.size() - 1) + (tb.size() - 1) + (tc.size() - 1);
        cost *= 10;
        int sum = 0;
        rep(i,ta.size())sum += ta[i];
        cost += abs(sum - a);
        sum = 0;
        rep(i,tb.size())sum += tb[i];
        cost += abs(sum - b);
        sum = 0;
        rep(i,tc.size())sum += tc[i];
        cost += abs(sum - c);
        ans = min(ans, cost);
    }
    cout << ans << endl;
}


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

int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    if(A+B<C+D) cout<<"Right"<<endl;
    if(A+B>C+D) cout<<"Left"<<endl;
    if(A+B==C+D)cout<<"Balanced"<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin>>n;
    vector<int> ans(4,0);
    for(int i = 0;i < n;++i) {
        string s;
        cin>>s;
        if(s=="AC")++ans[0];
        if(s=="WA")++ans[1];
        if(s=="TLE")++ans[2];
        if(s=="RE")++ans[3];
    }
    cout<<"AC x "<<ans[0]<<endl;
    cout<<"WA x "<<ans[1]<<endl;
    cout<<"TLE x "<<ans[2]<<endl;
    cout<<"RE x "<<ans[3]<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

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

    vector<pair<int, int>> A;
    for (int i = 0; i < N; i++) {
        int Ai;
        cin >> Ai;
        A.push_back(pair<int, int>(i, Ai));
    }

    sort(A.begin(), A.end(), [](const pair<int, int> &left, const pair<int, int> &right) {
        return left.second < right.second;
    });

    for (int i = 0; i < N; i++) {
        cout << A[i].first + 1 << ' ';
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1780
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <stdlib.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

int kaijou(int N){
    int ans = 1;
    REP(i,N){
        ans *= i+1;
    }
    return ans;
}

int main(void){

    int N;
    cin >> N;
    int x[N], y[N];
    REP(i,N) cin >> x[i] >> y[i];

    double d[N][N];
    REP(i,N)REP(j,N){
        d[i][j] = sqrt(pow(x[i] - x[j], 2) + pow(y[i]-y[j], 2));
        d[j][i] = sqrt(pow(x[i] - x[j], 2) + pow(y[i]-y[j], 2));
    }

    vector<int> a(N);
    REP(i,N) a[i] = i;
    double ans = 0;
    do{
        double tmp = 0;
        REP(i,N-1){
            tmp += d[a[i]][a[i+1]];
        }
        ans += tmp;
    }while(next_permutation(a.begin(), a.end()));

    cout << setprecision(8) << ans/kaijou(N) << endl;
    return 0;
}

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

using namespace std;

int main(){   
	
	string str;
	cin >> str;

	set <int, greater<int>> ultimos;

	if(str.size() == 1) {
		printf("0\n");
		return 0;
	}

	for(int i = 0; i < str.size(); i++) {
		if(i == 0) {
			if(str[i+1] != str[i]) {
				i++;
			} else {
				ultimos.insert(i);
			}
		}
		else if(i == str.size() - 1) {
			if(ultimos.size() > 0 and str[i] != str[*ultimos.begin()] ) {
				ultimos.erase(*ultimos.begin());
			} else {
				ultimos.insert(i);
			}
		} else {
			if(str[i+1] != str[i]) {
				i++;
			}
			else if(ultimos.size() > 0 and str[i] != str[*ultimos.begin()] ) {
				ultimos.erase(*ultimos.begin());
			} else {
				ultimos.insert(i);
			}

		}
	}

	printf("%d\n",str.size() - ultimos.size());

    return 0;
}

Measured memory_bytes: 4992
/*
　　　　 ∧＿∧　にっぽんちゃちゃちゃ
　／＼（　・∀・）／ヽ
（ ●　と　　　つ　● ）　にっぽんちゃちゃちゃ
　＼/⊂、 ノ　　＼ノ
　　　　　し'
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807

signed main() {
int x=0,y=0,z=0,w=0,n=0;
int a=0,b=0;
std::cin >> a>>b;
std::cin >> x;
rep(i,x){
  std::cin >> y>>z;
  if(b>y&&a<z){
    n=1;
}
}
std::cout << n << '\n';

}




Measured memory_bytes: 3104
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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; }

int main(){
	ll N;
	vector<ll> H;
	cin >> N;

	rep(i, 0, N){
		ll temp;
		cin >> temp;
		H.push_back(temp);
	}
	ll start = H[0];
	ll cnt = 1;
	rep(i, 1, N){
		if (H[i] >= start){
			cnt++;
			start = H[i];
		}
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<=n;i++)
typedef int long long ll;
using namespace std;

int main(){
   
    int x,y,z;
    cin>>x>>y>>z;
   
    x-=z;
    cout<<(x/(y+z))<<endl;
    
    
    
    
    

return 0;
}

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

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;

const int MOD = 1e9 + 7;
ll dp[100100][13];

int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  rep(i, 100100) rep(j, 13) dp[i][j] = 0;

  if (s[0] == '?') {
    rep(i, 10) dp[0][i] = 1;
  } else {
    dp[0][s[0] - '0'] = 1;
  }

  ll mul = 10;
  rep(i, sz(s) - 1) {
    rep(j, 13) {
      if (dp[i][j]) {
        if (s[i + 1] == '?') {
          rep(k, 10) {
            int index = (j + (mul * k % MOD)) % 13;
            dp[i + 1][index] += dp[i][j] % MOD;
          }
        } else {
          int dig = s[i + 1] - '0';
          int index = (j + dig * mul) % 13;
          dp[i + 1][index] += dp[i][j] % MOD;
        }
      }
    }
    mul *= 10;
    mul %= 13;
  }
  cout << dp[sz(s) - 1][5] % MOD << endl;
}


Measured memory_bytes: 10624
#include <iostream>

using namespace std;

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

    int L = A + B;
    int R = C + D;
    if (L > R){
        cout << "Left" << endl;
    }else if (L < R){
        cout << "Right" << endl;
    }else{
        cout << "Balanced" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
using namespace std;

int main() {
    int n, a[100], m=0;
    cin >> n;
    for (int i = 0; i < n;++i) {
        cin >> a[i];
        if (a[i] % 2 == 0 && a[i] % 3 != 0 && a[i] % 5 != 0) ++m;
    }
    if (m == 0) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

const ll MOD = 1e9+7;

int main()
{
  int N;
  string S;
  cin >> N >> S;
  map<int, int> cnt;

  for (int i = 0; i < S.size(); ++i) {
    cnt[S[i]-'a']++;
  }

  ll ans = 1;
  for (auto v : cnt) {
    ans *= v.second+1;
    ans %= MOD;
  }

  cout << ans - 1 << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
int binary_search_index(Int Y, vi &q){
    int left = 0, right = q.size() - 1;
    while (right >= left) {
        int mid = left + (right - left) / 2;
        if (q[mid] == Y) return mid;
        else if (q[mid] > Y) right = mid - 1;
        else if (q[mid] < Y) left = mid + 1;
    }
    return -1;
}


int main() {
    Int N;
    cin >> N;
    vi d = vi(N);

    rep(i,N){
        cin >> d[i];
    }

    sort(d.begin(),d.end());
    Int ans = d[N/2]-d[(N/2)-1];


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024