akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        h: usize,
        w: usize,
        s: [chars; h]
    }

    let mut yes = true;
    'outer: for y in 0..h {
        for x in 0..w {
            if s[y][x] == '#' {
                let mut whites = 0;
                for z in adjacent4(y, x, h, w) {
                    if s[z.0][z.1] == '.' {
                        whites += 1;
                    }
                }
                if whites == 4 {
                    yes = false;
                    break 'outer;
                }
            }
        }
    }
    println!("{}", if yes {"Yes"} else {"No"});
}

#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(dead_code)]
fn adjacent4(y: usize, x: usize, h: usize, w: usize) -> Box<Iterator<Item = (usize, usize)>> {
    static DYDX: [(isize, isize); 4] = [(-1, 0), (1, 0), (0, -1), (0, 1)];
    Box::new(DYDX.iter().filter_map(move |&(dy, dx)| {
        let ny = y as isize + dy;
        let nx = x as isize + dx;
        if nx >= 0 && nx < w as isize && ny >= 0 && ny < h as isize {
            Some((ny as usize, nx as usize))
        } else {
            None
        }
    }))
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

int main(){

    int i, j;
    char dammy;
    unsigned long long N = 0, M = 0;
    unsigned long long ans = 0;

    scanf("%d %d", &N, &M);

    if(N == 1 && M == 1){
        ans = 1;
    }else if(N ==1 ||M==1){
        ans = N * M - 2;
    }else if(N ==2 || M ==2){
        ans = 0;
    }else{
        ans = N * M - 2 * (N + M - 2);
    }

    
    printf("%llu", ans);

    return 0;
}



int max(int a, int b){
    if(a > b){
        return a;
    }else{
        return b;
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>

#define INF (1e9)

#define MAX_N 3000
#define MAX_M 100

using namespace std;

int cost[MAX_M + 1][MAX_M + 1][2];

int N,M;
int K;


void init(){
	for(int i = 0;i <= MAX_M;i++){
		for(int j = 0;j <= MAX_M;j++){
			for(int k = 0;k < 2;k++){
				if(i != j) cost[i][j][k] = INF;
				else cost[i][j][k] = 0;
			}
		}
	}

	return ;
}

void solve(){
	for(int k = 1;k <= M;k++){
		for(int i = 1;i <= M;i++){
			for(int j = 1;j <= M;j++){
				for(int h = 0;h < 2;h++){
					cost[i][j][h] = min(cost[i][j][h],cost[i][k][h] + cost[k][j][h]);
				}
			}
		}
	}


	return ;
}

int query(int u,int v,int r){
	return cost[u][v][r];
}

int main(){

	while(true){
		init();
		scanf("%d%d",&N,&M);
		if(N == 0 && M == 0) break;
		int _u,_v;
		int _c,_t;
		for(int i = 0;i < N;i++){
			scanf("%d%d%d%d",&_u,&_v,&_c,&_t);
			cost[_u][_v][0] = _c;
			cost[_v][_u][0] = _c;
			cost[_u][_v][1] = _t;
			cost[_v][_u][1] = _t;
		}
	
		solve();
	
		scanf("%d",&K);
		int _r;
		for(int i = 0;i < K;i++){
			scanf("%d%d%d",&_u,&_v,&_r);
			printf("%d\n",query(_u,_v,_r));
		}
	}

	return 0;

}

Measured memory_bytes: 1268
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");
			int n = Integer.parseInt(strArr[0]);
			int x = Integer.parseInt(strArr[1]);

			List<Integer> counters = new ArrayList<Integer>();
			Integer count;
			while (!( n==0 && x==0)) {

				count = 0;
				for(int i=1;i<=n;i++){
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				}
				counters.add(count);

				str = br.readLine();
				strArr = str.split(" ");
				n = Integer.parseInt(strArr[0]);
				x = Integer.parseInt(strArr[1]);

			}

			for(Integer s : counters){
				System.out.println(s);
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	}
}

Measured memory_bytes: 19848
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 998244353;
vector<ll> fac(200005);
vector<ll> ifac(200005);
ll modpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n & 1)
            ans = ans * x % mod;
        x = x * x % mod;
        n = n >> 1;
    }
    return ans;
}
ll comb(ll a, ll b){
    if(a == 0 && b == 0)
        return 1;
    if(a < b || a < 0)
        return 0;
    ll tmp = ifac[a - b] * ifac[b] % mod;
    return tmp * fac[a] % mod;
}
int main(){
    int n, m, k;
    cin >> n >> m >> k;
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i < n; i++){
        fac[i + 1] = fac[i] * (i + 1) % mod;
        ifac[i + 1] = ifac[i] * modpow(i + 1, mod - 2) % mod;
    }
    ll ans = 0;
    n--;
    for(int i = 0; i <= k; i++){
        ll p = modpow(m - 1, n - i) * comb(n, i) % mod;
        ans = (ans + p) % mod;
    }
    ans = ans * m % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6284
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cmath>

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

using namespace std;

int main(void)
{

    long x, res, y;
    
    y = 100;
    
    cin >> x;
    
    for(res = 1; ; res++)
    {
        y *= 1.01;
        if(y >= x)
        {
            break;
        }
    }
    
    cout << res;
    
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var N = input[0];
            var K = input[1];
            var h = new int[N];
            for (int i = 0; i < N; i++) h[i] = ReadInt();
            Array.Sort(h);
            var ans = int.MaxValue;
            for (int i = 0; i <= N - K; i++) if (h[i + K - 1] - h[i] < ans) ans = h[i + K - 1] - h[i];

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 17632
import math

num = int(input())
prime_found = False

def is_prime(n):
  if n==1: return False
  
  for k in range(2,int(math.sqrt(n)) + 1):
    if n % k == 0:
      return False
  return True

while not prime_found:
  if is_prime(num) == True:
    break
  else:
    num += 1
    
print(num)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <stdio.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

    int left = 0, right = 0;
    ll sum = 0;
    ll ans = 0;
    rep(i, n) {
        right = i;
        while ((sum ^ a[right]) != (sum + a[right])) {
            //cout<<(sum^a[right])<<':'<<sum+a[right]<<endl;
            //cout<<left<<':'<<right<<endl;
            sum -= a[left];
            left++;
        }
        sum += a[right];
        ans += right - left + 1;
        //cout<<sum<<endl;
        //cout<<left<<':'<<right<<endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = int(input())
li = []
start = True
for i in range(N):
    w = input()
    if w in li:
        print('No')
        exit()

    li.append(w)
    if start:
        start = False
    else:
        if bef[-1] != w[0]:
            print('No')
            exit()
    bef = w

print('Yes')    


Measured memory_bytes: 4332
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 7;
const double pi = acos(-1);
const int mod = 998244353;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
map<string,int> mp;
int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		string s;
		cin >> s;
		mp[s] = 1;
	}
	cout << mp.size()<<endl;
    return 0;
}

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

int main() {

    int n,i,min=1000001 ,max=-1000001;
    long int sum=0;
    cin >> n;
    int a[n];

    for (i=0; i<n; i++) {
        cin >> a[i];
        if (a[i]>max) max=a[i];
        if (a[i]<min) min=a[i];
        sum += a[i];
    }   
    
    cout << min << " " << max << " " << sum << endl;
    return 0;
}



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

#define getmid(l,r) ((l) + ((r) - (l)) / 2)
#define MEM(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define PB push_back

typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int INF = (1 << 30) - 1;

int N;
int A[200010],B[200010];

int main(){
	cin >> N;
	for(int i = 1; i <= N; ++i){
		cin >> A[i];
		B[i] = A[i];
	}
	sort(B + 1,B + N + 1);
	int mid = B[N / 2];
	for(int i = 1; i <= N; ++i){
		if(A[i] <= mid) printf("%d\n",B[N / 2 + 1]);
		else printf("%d\n",mid);
	}

	return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>
#define max(a,b) a > b ? a : b

int main(void){
	int max, t, i, k, n, count, m;
	scanf("%d",&m);
	for(k = 0;k < m;k++){
		scanf("%d",&n);
		count = 0;
		while(n / 10){
			max = 0x80000000;
			for(i = 10;n / i != 0;i*=10){
				t = (n / i) * (n - (n / i) * i);
				max = max(t,max);
			}
			n = max;
			count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
const int N = 400;
int C[N][4];
ll mask(ll a, ll b, ll c, ll d) {
	return (a << 30) | (b << 20) | (c << 10) | d;
}
ll rotate(ll m) {
	ll a = (m >> 30) & ((1 << 10) - 1);
	ll b = (m >> 20) & ((1 << 10) - 1);
	ll c = (m >> 10) & ((1 << 10) - 1);
	ll d = (m >> 0) & ((1 << 10) - 1);
	return mask(b, c, d, a);
}
int main() {
	int n;
	cin >> n;
	map<ll, int> counter;
	auto add = [&](int i) {
		for(int roti = 0; roti < 4; roti++) {
			counter[mask(C[i][(0 + roti) % 4], C[i][(1 + roti) % 4], C[i][(2 + roti) % 4], C[i][(3 + roti) % 4])]++;
		}
	};
	auto remove = [&](int i) {
		for(int roti = 0; roti < 4; roti++) {
			counter[mask(C[i][(0 + roti) % 4], C[i][(1 + roti) % 4], C[i][(2 + roti) % 4], C[i][(3 + roti) % 4])]--;
		}
	};
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 4; j++) {
			cin >> C[i][j];
		}
		add(i);
	}

	ll ans = 0;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			remove(i), remove(j);
			for(int roti = 0; roti < 4; roti++) {
				for(int rotj = 0; rotj < 4; rotj++) {
					auto fixi = [roti](int x) { return (x + roti) % 4; };
					auto fixj = [rotj](int x) { return (x + rotj) % 4; };
					ll m[4] = {
						mask(C[j][fixj(3)], C[j][fixj(2)], C[i][fixi(1)], C[i][fixi(0)]),
						mask(C[j][fixj(3)], C[i][fixi(0)], C[i][fixi(3)], C[j][fixj(0)]),
						mask(C[i][fixi(1)], C[j][fixj(2)], C[j][fixj(1)], C[i][fixi(2)]),
						mask(C[i][fixi(3)], C[i][fixi(2)], C[j][fixj(1)], C[j][fixj(0)]),
					};
					bool valid = true;
					for(int k = 0; k < 4; k++) {
						valid &= counter.count(m[k]) and counter[m[k]] > 0;
					}
					if(valid) {
						ll cur = 1;
						for(int k = 0; k < 4; k++) {
							cur *= counter[m[k]];
							for(int rot = 0; rot < 4; rot++) {
								counter[m[k]]--;
								m[k] = rotate(m[k]);
							}
						}
						ans += cur;
						for(int k = 0; k < 4; k++) {
							for(int rot = 0; rot < 4; rot++) {
								counter[m[k]]++;
								m[k] = rotate(m[k]);
							}
						}
					}
				}
			}
			add(i), add(j);
		}
	}
	cout << ans / 12 << endl;
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 36

typedef struct{
  char key[2];
  int value;
} SHCD;

int main(){
  SHCD A[N],temp,B[N];
  int i,j,n,minj,flag;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf("%s",A[i].key);
    A[i].value = atoi(&A[i].key[1]);
    B[i] = A[i];  
  }

  i = 0;
  flag = 1;
  while(flag==1){
    flag = 0;
    for(j = n-1 ; j >= i ; j--){
      if(A[j].value < A[j-1].value){
	temp = A[j];
	A[j] = A[j-1];
	A[j-1] = temp;
      }
      flag = 1;
    }
    i+=1;
  }


  for(i = 0 ; i < n ; i++){
    minj = i;
    for(j = i ; j < n ; j++){
      if(B[j].value < B[minj].value){
	minj = j; 
      } 
    }
    if( i != minj) {
      temp = B[minj];
      B[minj] = B[i];
      B[i] = temp;
    }
  }

  for(i = 0 ; i < n-1 ; i++){
    printf("%c%d ",A[i].key[0],A[i].value);
  }
  printf("%c%d\n",A[i].key[0],A[i].value);
  printf("Stable\n");

  for(i = 0 ; i < n-1 ; i++){
    printf("%c%d ",B[i].key[0],B[i].value);
  }
  printf("%c%d\n",B[i].key[0],B[i].value);
 
  flag = 0;
  for( i = 0 ; i < n ; i++ )
    {
      if( strcmp(A[i].key,B[i].key) != 0 ){
	flag = 1;
	break;
      }
    } 
  if( flag == 0 ) printf("Stable\n");
  else printf("Not stable\n");
  return 0;
}

Measured memory_bytes: 616
#include<cstdio>
#include<algorithm>
#include<map>
#include<numeric>
#include<functional>

using namespace std;

typedef long long ll;

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

ll nCr[51][51];

ll pow(ll x, int n){
	if(n == 0) return 1;
	return x * pow(x, n - 1);
}

int main(){
	nCr[0][0] = 1;
	rep(i, 50) rep(j, 50){ nCr[i + 1][j] += nCr[i][j]; nCr[i + 1][j + 1] += nCr[i][j]; }
	int n, a, b; scanf("%d %d %d", &n, &a, &b);
	ll v[50]; map<ll, int> c, u;
	rep(i, n){ scanf("%lld", &v[i]); c[v[i]]++; }
	sort(v, v + n, greater<ll>());
	rep(i, a) u[v[i]]++;
	double avg = (double)accumulate(v, v + a, 0LL) / a;
	printf("%.30f\n", avg);
	if(u.size() > 1) printf("%lld\n", nCr[c[v[a - 1]]][u[v[a - 1]]]);
	if(u.size() == 1) printf("%lld\n", accumulate(nCr[c[v[a - 1]]] + a, nCr[c[v[a - 1]]] + b + 1, 0LL));
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,count=0;
    scanf("%d %d %d",&a,&b,&c);
    int i;
    for(i=a;i<=b;i++)
    {
        if(c%i==0)
        {
            count ++;
        }

    }
    printf("%d\n",count);
    return 0;
}



Measured memory_bytes: 2140
def main():

    from bisect import bisect_left as bl, bisect_right as br, insort
    import sys
    import heapq
    # from math import *
    from collections import defaultdict as dd, deque
    def data(): return sys.stdin.readline().strip()
    def mdata(): return map(int, data().split())
    out = sys.stdout.write
    # sys.setrecursionlimit(100000)

    n=int(data())
    s=set()
    for i in range(n):
        s.add(data())
    print(len(s))




if __name__ == '__main__':
    main()

Measured memory_bytes: 90220
// B - Algae
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	long long r, d, x;
	cin >> r >> d >> x;
	for (int i = 2001; i <= 2010; i++) {
		x = r * x - d;
		cout << x << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
 
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    double r;
 
    cin >> r;
 
    printf("%.10lf", 2.0*r*M_PI);
 
    return 0;
}

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

int main(){
	int n,i,a[100],j,m,tmp,count;
	while(cin >> n && n){
		count = 0;
		for(i = 0;i < n;i++){
			cin >> m;
			a[i] = m;
		}
		for(i = 0;i < n-1;i++){
			for(j = i+1;j < n;j++){
				if(a[i] > a[j]){
					tmp = a[j];
					a[j] = a[i];
					a[j] = tmp;
					count++;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, k, a[1010];
int cum[1010];
vector<int> vec, vec2;
int ans;

signed main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		cum[i] = cum[i - 1] + a[i];
	}
	for (int i = 1; i <= n; i++)for (int j = i; j <= n; j++)vec.push_back(cum[j] - cum[i - 1]);
	for (int i = 39; i >= 0; i--) {
		vec2.clear();
		for (int j = 0; j < (int)vec.size(); j++)if (vec[j] & (1LL << i))vec2.push_back(vec[j]);
		if (k <= (int)vec2.size()) {
			vec.clear();
			vec = vec2;
			ans += (1LL << i);
		}
	}
	cout << ans << endl;
}

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

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

	vector<int> A(N);
	for(int i =0; i < N; i++) cin >> A.at(i);
	
  	int count = 0;
  	for(int i =0; i < N; i++){
      if( A.at(i) != i+1 ) count++;
    }
  
  if(count <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;

void solve(){
	int n,l;
	cin>>n>>l;
	int tot=n*l+((n*(n+1))/2)-n;
	if(l>0)cout<<tot-l<<endl;
	else if(l<0&&abs(l)>=n)cout<<tot-(l+n-1)<<endl;
	else cout<<tot<<endl;
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
double dp[555][555];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,M;
  cin>>N>>M;
  ll a[N];
  FOR(i,0,N)cin>>a[i];
  ll sum[N+1];
  sum[0]=0;
  FOR(i,0,N)sum[i+1]=sum[i]+a[i];
  FOR(i,0,555)FOR(j,0,555)dp[i][j]=-1;
  dp[0][0]=0;
  FOR(i,0,N){
    FOR(j,0,i+1){
      if(dp[i][j]==-1)continue;
      // i+1~kを1つの区画にする場合
      FOR(k,i+1,N+1){
        dp[k][j+1]=max(dp[k][j+1],dp[i][j]+1.0*(sum[k]-sum[i])/(k-i));
      }
    }
  }
  double ans=-1.0;
  FOR(i,1,M+1)ans=max(ans,dp[N][i]);
  cout<<setprecision(10)<<ans<<endl;
  return 0;
}


Measured memory_bytes: 5712
/* ****Shrey97**** */

#include <bits/stdc++.h>

#define hell 1000000007
#define N 100005

using namespace std;


signed main()
{
    // ios::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    string x;
    cin >> x;
    stack<int> s;
    int i = 0;
    char c = x[0];
    // cout << "hello";

    while(i<x.length())
    {
        int l = 0;
        while(i<x.length() and x[i]==c)
        {
            l++;
            i++;
        }
        s.push(l);
        if(i<x.length())
            c = x[i];
    }
    while(true)
    {
        if(k<=0)
        {
            break;
        }
        k--;
        int a=0, b=0, c=0;
        if(!s.empty())
        {
            a = s.top();
            s.pop();
        }
        if(!s.empty())
        {
            b = s.top();
            s.pop();        
        }
        if(!s.empty())
        {
            c = s.top();
            s.pop();    
        }
        s.push(a+b+c);
    }
    int ans = 0;
    while(!s.empty())
    {
        ans += (s.top()-1);
        s.pop();
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC175A
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            if (S[0].ToString() == "R")
            {
                if (S[1].ToString() == "R")
                {
                    if (S[2].ToString() == "R")
                    {
                        Console.WriteLine(3);
                    }
                    else
                    {
                        Console.WriteLine(2);
                    }
                }
                else
                {
                    Console.WriteLine(1);
                }
            }
            else
            {
                if (S[1].ToString() == "R")
                {
                    if (S[2].ToString() == "R")
                    {
                        Console.WriteLine(2);
                    }
                    else
                    {
                        Console.WriteLine(1);
                    }
                }
                else
                {
                    if (S[2].ToString() == "R")
                    {
                        Console.WriteLine(1);
                    }
                    else
                    {
                        Console.WriteLine(0);
                    }
                }
            }
        }
        
    }
}


Measured memory_bytes: 25856
from collections import Counter
import sys
sys.setrecursionlimit(200000)


def read():
    N, M, Q = map(int, input().split())
    ABCD = []
    for i in range(Q):
        a, b, c, d = map(int, input().split())
        ABCD.append((a, b, c, d))
    return N, M, Q, ABCD


def check(N, M, Q, ABCD, x):
    score = 0
    for a, b, c, d in ABCD:
        if x[b-1] - x[a-1] == c:
            score += d
    return score


def solve(N, M, Q, ABCD):
    smax = 0
    for a in range(1, M+1):
        for b in range(a, M+1):
            for c in range(b, M+1):
                for d in range(c, M+1):
                    for e in range(d, M+1):
                        for f in range(e, M+1):
                            for g in range(f, M+1):
                                for h in range(g, M+1):
                                    for i in range(h, M+1):
                                        for j in range(i, M+1):
                                            s = check(N, M, Q, ABCD, [a, b, c, d, e, f, g, h, i, j][:N])
                                            smax = max(s, smax)
    return smax


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("{}".format(outputs))


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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


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

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

constexpr int n = 26;
long long d;
std::vector<long long> c;
std::vector<std::vector<long long>> s;

int calc(vector<int> v){
    int ans = 0;
    vector<int> last(n, 0);
    for(int i = 1; i <= d; ++i){
        ans += s[i - 1][v[i - 1]];
        last[v[i - 1]] = i;
        for(int j = 0; j < n; ++j)
            ans -= c[j] * (i - last[j]);
        cout << ans << endl;
    }
    return ans;
}

void solve(){
    vector<int> ret(d);
    for(int i = 0; i < d; ++i){
        cin >> ret[i];
        --ret[i];
    }
    calc(ret);
}


signed main(){
    long long D;
    scanf("%lld",&D);
    c.resize(26);
    for(int i = 0 ; i < 26 ; i++){
        scanf("%lld",&c[i]);
    }
    s.assign(D, std::vector<long long>(26));
    for(int i = 0 ; i < D ; i++){
        for(int j = 0 ; j < 26 ; j++){
            scanf("%lld",&s[i][j]);
        }
    }
    d = D;
    solve();
    return 0;
}


Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N);
	REP(i, N) cin >> A[i];

	sort(A.begin(), A.end(), std::greater<int>());

	ll ans = A[0];
	N -= 2;
	int i = 1;
	while (N != 0) {
		if (N == 1) {
			ans += A[i];
			N -= 1;
			i++;
		}
		else {
			ans += 2 * A[i];
			N -= 2;
			i++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4844
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int n;
		int[] numbers;
		try (Scanner scanner = new Scanner(System.in)) {
			n = scanner.nextInt();

			numbers = new int[n];
			for (int i = 0; i < n; i++) {
				numbers[i] = scanner.nextInt();
			}
		}

		Arrays.sort(numbers);

		int difference = 0;
		for (int i = 0; i < n; i++) {
			difference = numbers[i] - difference;
		}

		System.out.println(difference);
	}
}

Measured memory_bytes: 21716
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}


int main() {
	ll N;
	
	cin >> N;
	vector<ll> A(N);
	
	rep(i, N) {
		cin >> A[i];
		
	}

	ll cnt = 0;
	multiset<ll> M;
	
	for (int i = 0; i < N; i++) {
		decltype(M)::iterator it;
		it = M.lower_bound(A[i]);

		if (it == M.begin()) {
			M.insert(A[i]);
			continue;
		}
		M.erase(--it);
		M.insert(A[i]);
	}

	cout << M.size() << endl;

	return 0;
}

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<vector<T>> m) {
    repall (v, m)
        init(v);
}

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------

vec candi;

void f(int sum, int n, bool three, bool five, bool seven) {
    if (n < 0) {
        if (three and five and seven) candi.push_back(sum);
        return;
    }

    int di = pow(10, n);
    f(sum + di * 3, n - 1, true, five, seven);
    f(sum + di * 5, n - 1, three, true, seven);
    f(sum + di * 7, n - 1, three, five, true);
}

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);

    int n;

    cin >> n;
    rep (i, 9)
        f(0, i, false, false, false);

    sort(all(candi));
    print(distance(candi.begin(), upper_bound(all(candi), n)));

    return 0;
}

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

int main()
{
    double n;
    cin >> n;
    cout << fixed << setprecision(10) << ceil(n / 2) / n << endl;
    return 0;
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int N, M;

int main(void) {
    cin >> N >> M;
    vector<vector<int>> s;

    rep(i, M) {
        int K;
        cin >> K;
        s.push_back(vector<int>(K));
        rep(k, K) {
            cin >> s[i][k];
            s[i][k]--;
        }
    }

    vector<int> p(M);
    rep(i, M) {
        cin >> p[i];
    }

    int ans = 0;
    for (int bits = 0; bits < (1 << N); ++bits) {
        bool flag = true;
        for (int i = 0; i < M; ++i) {
            int on = 0;
            for (int ss : s[i]) {
                if (bits & (1 << ss)) on++;
            }

            if (on % 2 != p[i]) {
                flag = false;
                break;
            }
        }

        if (flag) ans++;
    }

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

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func inputIntSlice(size int) []int {
	slice := make([]int, size)
	for i := range slice {
		slice[i] = nextInt()
	}
	return slice
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()
	x := inputIntSlice(n)
	ans := 4 * max(abs(x[0]), abs(x[n-1]))

	for i := 0; i <= n-k; i++ {
		var t int
		if x[i]*x[i+k-1] >= 0 {
			t = max(abs(x[i]), abs(x[i+k-1]))
		} else {
			t = max(abs(x[i]), abs(x[i+k-1])) + 2*min(abs(x[i]), abs(x[i+k-1]))
		}
		ans = min(ans, t)
	}

	fmt.Println(ans)
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  ll N; cin >> N;
  if (N == 0 || N % 2) { cout << 0 << endl; return 0; }

  ll ans = 0;
  for (int i = 1; ; i++) {
    ll aaa = N / (powl(5LL, i) * 2);
    if (aaa == 0) break;
    ans += aaa;
  }
  cout << ans << endl;
/*
  詰めきれなかったコード
  ll N2 = N / 2;

  int K = 0;
  ll tmp = 1;
  for(; tmp <= N2; K++) {
    tmp *= 5LL;
  }
  K--;
  cout << K << endl;
  ll ans = 0;
  REP(i, 1, K) {
    ans += (powl(5LL, i + 1) - powl(5LL, i)) * (ll)i;
  }
  ans += powl(5LL, K) * (N - powl(5LL, K));

  cout << ans << endl;
  */
}


Measured memory_bytes: 384
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename V>
void eratosthenes(V &v) {
  v[0] = v[1] = false;
  loop(i, 2, v.size()) v[i] = true;
  for (int i = 2; i * i < v.size(); i++) {
    if (v[i]) {
      for (int j = i * 2; j < v.size(); j += i) {
        v[j] = false;
      }
    }
  }
}

void solve() {
  vi v(1000000);
  eratosthenes(v);
  loop(i, 1, v.size()) v[i] += v[i - 1];
  int n;
  while (cin >> n) cout << v[n] << endl;
}

Measured memory_bytes: 10504
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n,k; cin >> n >> k;
    vector<int> a(n);

    rep(i,n) cin >> a[i];

    sort(all(a));
    reverse(all(a));

    int ans =0 ;
    rep(i,k) ans+=a[i];

    cout << ans                  << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), k = in.nextInt();
            int g = 0;
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
                g = NumberUtils.gcd(g, a[i]);
            }
            for (int i = 0; i < n; ++i) {
                if (a[i] >= k && (a[i] - k) % g == 0) {
                    out.println("POSSIBLE");
                    return;
                }
            }
            out.println("IMPOSSIBLE");
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

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

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }

    static class NumberUtils {
        public static int gcd(int a, int b) {
            while (b != 0) {
                int c = a % b;
                a = b;
                b = c;
            }
            return a;
        }

    }
}



Measured memory_bytes: 37432
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__;
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
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;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    vector<pair<int,int> > x(N);
    vector<int> y(N);
    for(int i=0;i<N;i++){
        int a,b; cin >> a >> b;
        x[i] = make_pair(a,b);
        y[i] = i;
    }
    double average=0.0;
    int cnt=0;
    do{
        cnt++;
        cerr << "\n" << y[0] << " ";
        double dist=0.0;
        for(int i=1;i<N;i++){
            cerr << y[i] << " ";
            int sx=x[y[i-1]].first,sy=x[y[i-1]].second;
            int gx=x[y[i]].first,gy=x[y[i]].second;
            dist += sqrt(1.0*(sx-gx)*(sx-gx)+1.0*(sy-gy)*(sy-gy));
        }
        average += dist;
    }while(next_permutation(y.begin(),y.end()));
    printf("%.8lf\n",average/cnt);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
typedef long long ll;
const int N = 1e5+10;

int col[N] = {0};

vector<pair<int, ll>> g[N]; 

void dfs(int curr, int par, int c)
{
    col[curr] = c;
    for(auto x : g[curr])
    {
        if(x.first != par)
        {
            if((x.second & 1) == 0)
                dfs(x.first, curr, c);
            else
                dfs(x.first, curr, 3-c);
        }
    }
}

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<n;i++)
    {
        int u, v;
        ll w;
        cin>>u>>v>>w;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    
    for(int i=1;i<=n;i++)
    {
        if(col[i] == 0)
            dfs(i, -1, 1);
    }
    for(int i=1;i<=n;i++)
        cout<<col[i]-1<<endl;
    return 0;
}


Measured memory_bytes: 10624
#include <iostream>
#include <cmath>
#include <algorithm>//sort
#include <vector>
#include <string>
#include <map>//pair
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  rep(i, 1010){
    if(int(i * 0.08) == a && int(i * 0.1) == b){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
  //double A, B, a, b;
  ////int a,b;
  //cin >> A >> B;
  //a = A / 0.08;
  //b = B / 0.1;
  //int ans = min(a, b);
  ////if(a * 0.02 >= A - B && b * 0.02 >= A - B)cout << -1 << endl;
  ////else if(a < b)cout << a << endl;
  ////else cout << b << endl;
  //if(ans * 0.02 < abs(a - b))cout << -1 << endl;
  //else cout << ans << endl;
}


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

using namespace std;

struct edge
{
    int to,cap,rev;
    edge(int t=0,int c=0,int r=0):to(t),cap(c),rev(r){}
};

const int N=1e3+10;
vector<edge> G[N];
int V,E;
int level[N];
int iter[N];
const int INF=1e9;

void add(int from,int to,int cap)
{
    G[from].push_back(edge(to,cap,G[to].size()));
    G[to].push_back(edge(from,0,G[from].size()-1));
}

void bfs(int s)
{
    memset(level,-1,sizeof(level));
    queue<int> q;
    level[s]=0;
    q.push(s);

    while(!q.empty())
    {
        int v=q.front();q.pop();
        for(int i=0;i<G[v].size();i++)
        {
            edge &e=G[v][i];
            if(e.cap>0&&level[e.to]==-1)
            {
                level[e.to]=level[v]+1;
                q.push(e.to);
            }
        }
    }
}

int dfs(int v,int t,int f)
{
    if(v==t)
    {
        return f;
    }

    for(int &i=iter[v];i<G[v].size();i++)
    {
        edge &e=G[v][i];
        if(e.cap>0&&level[v]<level[e.to])
        {
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0)
            {
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s,int t)
{
    int flow=0;
    while(true)
    {
        bfs(s);
        if(level[t]==-1) break;
        memset(iter,0,sizeof(iter));
        int f;
        while((f=dfs(s,t,INF))>0)
        {
            flow+=f;
        }
    }
    return flow;
}
int main()
{
    while(cin>>V>>E)
    {
        for(int i=0;i<E;i++)
        {
            int a,b,c;
            cin>>a>>b>>c;
            add(a,b,c);
        }
        cout<<max_flow(0,V-1)<<endl;
    }

    return 0;
}



Measured memory_bytes: 3176
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){
  int N;
  cin>>N;
  char S[N+1];
  cin>>S;
  int count;
  int mincount=2000000;
  int leader=0;

  int west=0;
  int east=0;

  for (int i=1;i<N;i++){
    if(S[i]=='E') east++;
  }
  mincount=east;

  for (int i=1;i<N;i++){
    if(S[i-1]=='W') west++;
    if(S[i]=='E') east--;
    count=east+west;
    mincount=(count<mincount)?count:mincount;
  }


  cout<<mincount;

  return 0;
}

Measured memory_bytes: 512
#--初期の並びを圧縮表示,逆立ち、正立を目印--#
import sys,math,collections,itertools
input = sys.stdin.readline

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

stand = []
s_or_r = []

s_bf = '.'
cnt = 0
for i in range(N):
    if s_bf != S[i] and i != 0:
        stand.append(cnt)
        s_or_r.append(s_bf)
        cnt = 1
        s_bf=S[i]
    else:
        cnt += 1
        s_bf =S[i]
stand.append(cnt)
s_or_r.append(s_bf)


#--正立kまで許容して足す。maxが答え
if s_or_r.count('0')<=K:
    print(len(S))
    exit()
#--成形==#
if s_or_r[0]=='0':
    s_or_r=['1']+s_or_r
    stand = [0]+stand
if s_or_r[-1]=='0':
    s_or_r.append('1')
    stand.append(0)
#初期条件#
tmp = sum(stand[0:2*K+1])
ans = tmp
for i in range(2,len(stand)-2*K,2):
    tmp += -(stand[i-1]+stand[i-2])+stand[i+2*K-1]+stand[i+2*K]
    ans = max(ans,tmp)
print(ans)
    


Measured memory_bytes: 11856
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;

int par[110000]; //親
int ran[110000]; //木の深さ

// n要素を初期化
void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    ran[i]=0;
  }
}

//木の根を求める
int find(int x){
  if(par[x]==x){
    return x;
  }else{
    return par[x]=find(par[x]);
  }
}

//xとyの属する集合を併合
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;

  if(ran[x]<ran[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(ran[x]==ran[y]) ran[x]++;
  }
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
  return find(x)==find(y);
}

int main(){
  int N,M,p[110000],x,y,count=0;
  cin>>N>>M;
  for(int i=1;i<=N;i++) cin>>p[i];

  init(N+1);
  
  for(int i=0;i<M;i++){
    cin>>x>>y;
    unite(x,y);
  }

  for(int i=1;i<=N;i++){
    if(same(i,p[i])) count++;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int N;
    cin >> N;
    
    int d[N];
    set<int> st;
    for(int i=0;i<N;i++){
        cin >> d[i];
        st.insert(d[i]);
    }
    
    cout << st.size() << endl;
    
    return 0;
}


Measured memory_bytes: 764