akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h> //=> pow
#define NEWTON_LIMIT 10000
#define D 4

int abs(int val) {
	if (val < 0) { val *= -1; }
	return val;
}

double fabs(double val) {
	if (val < 0) { val *= -1; }
	return val;
}
/*
double pow(double val, int p) {
double ret = val;
for (int i = 1; i < p; i++) {
ret *= val;
}
return ret;
}
*/

//	CubicRoot by newton algorithm
double cbrt_newton(double a, double x) {
	double e;
	double a_new;
	int i = 0;

	while (i < NEWTON_LIMIT) {
		e = (x * x * x - a) / (3.0 * x * x);
		if (fabs(e) > 1.0e-16) { break; }
		x = x - e;
		i++;
	}
	return x - e;
}

double sqrt(double val) {
	double x = val / 2.0;
	double last_x = 0.0;

	while (x != last_x) {
		last_x = x;
		x = (x + val / x) / 2.0;
	}

	return x;
}

double max(double val[], int n) {
	double max = 0;
	int i = 0;
	for (; i < n; i++) {
		max = (max < val[i]) ? val[i] : max;
	}
	return max;
}

int main() {

	int n;
	int x[1000], y[1000];
	int *p[] = { x, y };
	double d[D];
	double xy[1000];
	int i, j;

	scanf("%d", &n);

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

	for (j = 0; j < n; j++) {
		xy[j] = abs(x[j] - y[j]);
	}

	for (i = 0; i < D; i++) {
		d[i] = 0;

		if (i < 3) {
			for (j = 0; j < n; j++) {
				d[i] += pow(xy[j], i + 1);
			}
			//	すべてゼロだった場合の例外処理
			//	=> i=2...ニュートン法で三乗根求めるときにゼロ除算が入ってnan(ind)になるため．
			if (d[i] == 0) { continue; }
		}

			switch (i) {
		case 1:	d[i] = sqrt(d[i]); break;
		case 2: d[i] = cbrt_newton(d[i], pow(d[i], 1.0 / 3.0)); break;
		case 3: d[i] = max(xy, n); break;
		}
	}

	for (int i = 0; i < D; i++) {
		printf("%.8f\n", d[i]);
	}

	return 0;
}


Measured memory_bytes: 2108
# input
x, y, z, k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

import heapq


a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

index_hstr = []
deliciouses = []
# priority queue
pq = []
heapq.heappush(pq, (-a[0] - b[0] - c[0], 0, 0, 0))
index_hstr.append((0, 0, 0))

for t in range(k):
    deli, i, j, k = heapq.heappop(pq)
    if i+1<x and (i+1, j, k) not in index_hstr:
        heapq.heappush(pq, (-a[i+1] - b[j] - c[k], i+1, j, k))
        index_hstr.append((i+1, j, k))
    if j+1<y and (i, j+1, k) not in index_hstr:
        heapq.heappush(pq, (-a[i] - b[j+1] - c[k], i, j+1, k))
        index_hstr.append((i, j+1, k))
    if k+1<z and (i, j, k+1) not in index_hstr:
        heapq.heappush(pq, (-a[i] - b[j] - c[k+1], i, j, k+1))
        index_hstr.append((i, j, k+1))
    deliciouses.append(-deli)


print('\n'.join(str(i) for i in deliciouses))


Measured memory_bytes: 4724
#include<iostream>
using namespace std;
int main(){
    
    int m[50] = {};
    int f[50] = {};
    int r[50] = {};
    int stu[50] = {}; //配列の[]内の５０は全て生徒の人数の最大値
    int i = 0;
    
    while(true){
        int mp, fp, rp;
        cin >> mp >> fp >> rp;
        
        if(mp == -1 && fp == -1 && rp == -1){
            break;
        } else {
            stu[i] = 1;
            m[i] = mp;
            f[i] = fp;
            r[i] = rp;
            i += 1;
        }
    }
    
    for(int j = 0; j < i; j++){
        
        if(m[j] == -1 || f[j] == -1){
            cout << "F" << endl;
        } else if(80 <= m[j] + f[j]){
            cout << "A" << endl;
        } else if(65 <= m[j] + f[j] && m[j] + f[j] < 80){
            cout << "B" << endl;
        } else if(50 <= m[j] + f[j] && m[j] + f[j] < 65){
            cout << "C" << endl;
        } else if(30 <= m[j] + f[j] && m[j] + f[j] < 50){
            if(50 <= r[j]){
                cout << "C" << endl;
            } else {
                cout << "D" << endl;
            }
        } else if(m[j] + f[j] < 30){
            cout << "F" << endl;
        }
    }
    
    return 0;
    
}


Measured memory_bytes: 3072
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<iomanip>
#include<fstream>
#include<ctime>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;

string s,s2, s3;
set<string> zb;
int i,j;
bool can;
char t[55];

int main() {
scanf("%s", t);
s = t;
scanf("%s", t);
s2 = t;
zb.clear();
for (i=0;i<s.size();i++) if (i + s2.size() <= s.size()) {
	can = true;
	for (j=0;j<s2.size();j++) {
		if (s[i+j] != '?' && s[i+j] != s2[j]) can = false;
	}
	if (can) {
		s3 = s.substr(0, i) + s2 + s.substr(i + s2.size());
		for (j=0;j<s3.size();j++) if (s3[j] == '?') s3[j] = 'a';
		zb.insert(s3);
	}
}
if (zb.size() == 0) printf("UNRESTORABLE\n"); else printf("%s\n", (*(zb.begin())).c_str());
return 0;
}


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

typedef long long ll;

vector<int> x, y, p;
vector<vector<int>> a, b;
vector<ll> ans;
int n;

int bitx = 0, bity = 0, pop = 0;

void dfs(int ind){
    if(ind == n){
        ll tmp = 0;
        for(int i = 0; i < n; i++){
            int diff = min({abs(x[i]), abs(y[i]), a[i][bitx], b[i][bity]});
            tmp += (ll)diff * p[i];
        }
        ans[pop] = min(ans[pop], tmp);
        return;
    }
    bitx ^= 1<<ind; pop++;
    dfs(ind+1);
    bitx ^= 1<<ind; 
    bity ^= 1<<ind;
    dfs(ind+1);
    bity ^= 1<<ind; pop--;
    dfs(ind+1);
}

int main(){
    cin >> n;
    x.resize(n);
    y.resize(n);
    p.resize(n);
    ans.resize(n+1, 1ll<<60);
    a.resize(n, vector<int>(1<<n, 30000));
    b.resize(n, vector<int>(1<<n, 30000));
    for(int i = 0; i < n; i++)  cin >> x[i] >> y[i] >> p[i];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 1<<n; j++){
            for(int k = 0; k < n; k++){
                if(j>>k&1)  a[i][j] = min(a[i][j], abs(x[k]-x[i])), b[i][j] = min(b[i][j], abs(y[k]-y[i]));
            }
        }
    }
    dfs(0);
    for(int i = 0; i < n+1; i++)  cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 7240
import types

_atcoder_code = """
# Python port of AtCoder Library.

__version__ = '0.0.1'
"""

atcoder = types.ModuleType('atcoder')
exec(_atcoder_code, atcoder.__dict__)

_atcoder_dsu_code = """
import typing


class DSU:
    '''
    Implement (union by size) + (path compression)
    Reference:
    Zvi Galil and Giuseppe F. Italiano,
    Data structures and algorithms for disjoint set union problems
    '''

    def __init__(self, n: int = 0):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a: int, b: int) -> int:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        x = self.leader(a)
        y = self.leader(b)

        if x == y:
            return x

        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x

        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x

        return x

    def same(self, a: int, b: int) -> bool:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        assert 0 <= a < self._n

        if self.parent_or_size[a] < 0:
            return a

        self.parent_or_size[a] = self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]

    def size(self, a: int) -> int:
        assert 0 <= a < self._n

        return -self.parent_or_size[self.leader(a)]

    def groups(self) -> typing.List[typing.List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]

        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)

        return list(filter(lambda r: r, result))
"""

atcoder.dsu = types.ModuleType('atcoder.dsu')
exec(_atcoder_dsu_code, atcoder.dsu.__dict__)
DSU = atcoder.dsu.DSU

# https://atcoder.jp/contests/practice2/tasks/practice2_a

import sys

# from atcoder.dsu import DSU


def main() -> None:
    n, q = map(int, sys.stdin.readline().split())
    dsu = DSU(n)

    for _ in range(q):
        t, u, v = map(int, sys.stdin.readline().split())
        if t == 0:
            dsu.merge(u, v)
        if t == 1:
            if dsu.same(u, v):
                print(1)
            else:
                print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 84508
#include <stdio.h>
int main () {
  int n, num[99999], i;
  scanf("%d", &n);
  for (i=0; i<n; i++) {
    scanf("%d", &num[i]);
  }
  for (i=n-1; i>0; i--) {
    printf("%d ", num[i]);
  }
  for (i=0; i<=0; i++) {
    printf("%d", num[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 608
#include<stdio.h>

int main(void)
{
   while(1){
   int x=0;
   int y=0;

   scanf("%d",&x);
   if(x == -1){
    break;
   }
   if(x<=10){
        y=1150;
   } else if(10<x && x <= 20){
        
//        for(y=1150;x<=20;x++){
//        y+=125;  }
        int z = 11;
        for(y=1150;z<=x;z++){
        y+=125;  }

   } else if(20<x && x<=30){
//        for(y=1150;x<=20;x++){
//        y+=125;  }
//        for(y=1150;x<=30;x++){
//        y+=140;}
        int z = 11;
        for(y=1150;z<=20;z++){
        y+=125;  }
         for(;z<=x;z++){
        y+=140;}
 
   } else if(30<x){
         int z=11;
         for(y=1150;z<=20;z++){
        y+=125;  }
         for(;z<=30;z++){
        y+=140;}
        for(;x >= z;z++){
        y+=160;}
   } 
   printf("%d\n",4280 -y);
   }
return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&s){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#else
template<class...T>void dprint(T&&...t){_print(cerr,t...);}
#endif
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<<(ostream&o,const multiset<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max(c-a+b,0)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
int main() {
    int a,b,c;
    bool flag = false;

    scanf("%d %d %d", &a, &b, &c);

    if(a == b && b != c)
        flag = true;
    else if(a == c && b != c)
        flag = true;
    else if(b == c && a != b)
        flag = true;

    if(flag == true) {
        printf("Yes");
    } else {
        printf("No");
    }
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
typedef long long ll;

int main(void) {
  ll i, j, n;
  scanf("%lld", &n);
  ll a[n], b[n];
  for(i = 0; i < n; ++i) scanf("%lld%lld", &a[i], &b[i]);
  std::sort(a, a + n), std::sort(b, b + n);
  if(n & 1) printf("%lld", b[n / 2] - a[n / 2] + 1);
  else printf("%lld", b[n / 2 - 1] + b[n / 2] - a[n / 2 - 1] - a[n / 2] + 1);
  return 0;
}

Measured memory_bytes: 4848
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    S = input_raw[0]
    [y, m, d] = S.split("/")
    x = int(m)* 100 + int(d)
    if x <= 430:
        print "Heisei"
    else:
        print "TBD"
if __name__ == '__main__':
    main()


Measured memory_bytes: 2932
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;



int main()
{
  lli n,k,i;
  cin>>n>>k;

  lli a[n];
  lli sum=0;
  for(i=0;i<n;i++)
  {
     cin>>a[i];
     sum+=a[i];
  }
    if(k>=n)
  {
      cout<<0;
      return 0;
  }
  else{
        sort(a,a+n);
    for(i=n-1;i>=0;i--)
    {
       if(k==0) break;
        else sum-=a[i];
        k--;
    }
    cout<<sum;


  }
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.*;

public class Main {

	static Main obj = new Main();
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static int vertex;
	static int edges;
	static int start;
	static int[] cost;
	static int[] parent;
	static boolean[] visited;
	static ArrayList<Edge>[] graph;

	private class Edge implements Comparable<Edge> {
		int from;
		int to;
		int weight;

		public Edge(int from, int to, int weight) {
			this.from = from;
			this.to = to;
			this.weight = weight;
		}

		@Override
		public int compareTo(Edge other) {
			return this.weight - other.weight;

		}
	}

	public static void main(String[] args) throws IOException {
		input();
		dijk(start);
	}

	public static void dijk(int index) {
		// int added = 1;
		cost[index] = 0;
		visited[index] = true;
		parent[index] = index;
		PriorityQueue<Edge> pq = new PriorityQueue<Edge>();
		for (Edge temp : graph[index]) {
			pq.offer(temp);
			cost[temp.to] = temp.weight;
		}
		while (!pq.isEmpty()) {
			Edge e = pq.poll();
			if (visited[e.to]) {
				continue;
			}
			visited[e.to] = true;
			// added++;
			for (Edge f : graph[e.to]) {
				if ( cost[f.to] > f.weight + e.weight) {
					cost[f.to] = f.weight + e.weight;
					parent[f.to] = f.from;
					pq.offer(obj.new Edge(f.from, f.to, f.weight + e.weight));
				}
			}
		}
		for (int i : cost) {
			if (i == Integer.MAX_VALUE) {
				System.out.println("INF");
			} else {
				System.out.println(i);
			}
		}
	}

	@SuppressWarnings("unchecked")
	public static void input() throws IOException {
		StringTokenizer st = new StringTokenizer(br.readLine());
		vertex = Integer.parseInt(st.nextToken());
		edges = Integer.parseInt(st.nextToken());
		start = Integer.parseInt(st.nextToken());
		cost = new int[vertex];
		parent = new int[vertex];
		visited = new boolean[vertex];
		graph = new ArrayList[vertex];
		for (int i = 0; i < vertex; i++) {
			graph[i] = new ArrayList<Edge>();
			cost[i] = Integer.MAX_VALUE;
		}
		for (int i = 0; i < edges; i++) {
			st = new StringTokenizer(br.readLine());
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			int c = Integer.parseInt(st.nextToken());
			graph[a].add(obj.new Edge(a, b, c));
		}

	}
}



Measured memory_bytes: 125268
#include <iostream>
#include <vector>

int main()
{
  int n;
  std::cin >> n;
  std::vector<int> b(n-1);
  for (int i = 0; i < n-1; i++)
  {
    std::cin>>b[i];
  }
  long long sum = 0;
  for (int i = 0; i < n; i++)
  {
    if(i==0)
    {
      sum += b.front();
    }
    else if(i==n-1)
    {
      sum += b.back();
    }
    else
    {
      sum += std::min(b[i], b[i-1]);
    }

  }
  std::cout << sum << std::endl;


}


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

int main(){
	int n;
	cin >> n;
	ll a[n];

	ll stool = 0;
	for(int i=0; i<n; i++){
		cin >> a[i];
		if(i > 0){
			if(a[i] < a[i-1]){
				stool += a[i-1] - a[i];
				a[i] = a[i-1];
			}
		}
	}
	cout << stool << endl;
	
	return 0;
}

Measured memory_bytes: 5180
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ cout << (x[i]) << " ";} cout << endl;
#define printaa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ for(int j = 0; j < (sizeof(x[0])/sizeof(x[0][0])); j++){ cout << x[i][j] << " ";} cout << endl;}
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    int A[2][101] = {};
    rep(i,0,2){
        rep(j,0,N){
            cin >> A[i][j];
        }
    }
    int ans = 0;
    rep(i,0,N){
        int ans_tmp = 0;
        rep(j,0,i+1){
            ans_tmp += A[0][j];
        }
        rep(j,i,N){
            ans_tmp += A[1][j];
        }
        ans = max(ans, ans_tmp);

    }
    print(ans);
}


Measured memory_bytes: 256
n, k, c = map(int, input().split())
s = input()


cnt0 = [-10**10] * len(s)
cnt1 = [-10**10] * len(s)
rest0 = c
rest1 = c
ct0 = 1
ct1 = 1
for i in range(len(s)):
    a = s[i]
    b = s[len(s) - 1 - i]
    if (c <= rest0) & (a == 'o'):
        cnt0[i] = ct0
        ct0 += 1
        rest0 = 0
    else:
        rest0 += 1
    if (c <= rest1) & (b == 'o'):
        cnt1[len(s) - 1 - i] = ct1
        ct1 += 1
        rest1 = 0
    else:
        rest1 += 1
for i in range(len(s)):
    if (cnt0[i] + cnt1[i] == k+1):
        print(i+1)


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


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    long long int k,n;
    cin >> k >> n;
    long long int arr[n];
    for(long long int i = 0 ; i<n ; i++)
    {
        cin >> arr[i];  
    }
    long long int diff = 0;
    for(long long int i = 0 ; i<n-1 ; i++)
    {
        if(arr[i+1]-arr[i]>diff)diff = arr[i+1]-arr[i];
    }
    long long int temp = (k - arr[n-1]) + (arr[0]);
    long long int ans = k - max(temp,diff);
    cout << ans;
    return 0;
}


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

const int INF = 1e9;
using lint = long long;
const lint LINF = 1e18;
#define bit(n) ((lint)1 << n);

const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;

template <lint mod>
class mod_integer {
    lint val;

    public:
    mod_integer(): val(0) {}
    mod_integer(lint init_val):
        val(init_val >= 0? init_val % mod: (init_val % mod + mod) % mod) {}
    
    bool operator ! () {
        return val == 0;
    }
    mod_integer operator - () {
        return mod_integer(-val);
    }
    mod_integer operator ++ (int) {
        mod_integer that = *this;
        this -> val = (this -> val + 1) % mod;
        return that;
    }
    mod_integer operator -- (int) {
        mod_integer that = *this;
        this -> val = (this -> val - 1 + mod) % mod;
        return that;
    }
    
    bool operator == (mod_integer that) {
        return val == that.val;
    }
    bool operator != (mod_integer that) {
        return val != that.val;
    }

    mod_integer& operator += (const mod_integer& that) {
        val = (val + that.val) % mod;
        return *this;
    }
    mod_integer& operator -= (const mod_integer& that) {
        val = (val - that.val + mod) % mod;
        return *this;
    }
    mod_integer& operator *= (const mod_integer& that) {
        val = (val * that.val) % mod;
        return *this;
    }
    mod_integer& operator /= (const mod_integer& that) {
        lint res = 1, n = that.val, p = mod - 2;
        while (p > 0) {
            if (p % 2 == 1) res = res * n % mod;
            n = n * n % mod;
            p /= 2;
        }
        val = val * res % MOD;
        return *this;
    }

    mod_integer operator + (const mod_integer& that) {
        return mod_integer(*this) += that;
    }
    mod_integer operator - (const mod_integer& that) {
        return mod_integer(*this) -= that;
    }
    mod_integer operator * (const mod_integer& that) {
        return mod_integer(*this) *= that;
    }
    mod_integer operator / (const mod_integer& that) {
        return mod_integer(*this) /= that;
    }

    friend istream& operator >> (istream& is, mod_integer& n) {
        lint init_val;
        cin >> init_val;
        n = mod_integer(init_val);
        return is;
    }
    friend ostream& operator << (ostream& os, const mod_integer& n) {
        return os << n.val;
    }
}; using mint = mod_integer<MOD>;

template <typename T, typename U>
T power(T n, U p) {
    T res = 1;
    while (p > 0) {
        if (p % 2 == 1) {
            res *= n;
        }
        n *= n;
        p /= 2;
    }
    return res;
}

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

    int n;
    mint a, b, c;
    cin >> n >> a >> b >> c;
    a /= (a + b);
    b = -a + 1;
    c /= 100;

    mint ans = 0, comb = 1;
    for (int k = 0; k < n; k++) {
        if (k > 0) {
            comb = comb * (n + k - 1) / k;
        }
        mint draw = n + k;
        mint prob = comb * (power(a, n) * power(b, k) + power(b, n) * power(a, k));
        ans += draw * prob;
    }

    ans /= -c + 1;
    cout << ans << endl;

    return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

int a[200009],cnt[1000009],mask[1000009];

void solve()
{
	int n,i;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		cnt[a[i]]++;
	}
	int ans=0;
	for(i=1;i<=1000000;i++)
	{
		if(cnt[i]==0) continue;
		for(int j=i+i;j<=1000000;j+=i)
		mask[j]=1;
	}
	for(i=1;i<=1000000;i++)
	{
		if(!mask[i] && cnt[i]==1) ans++; 
	}
	cout<<ans<<'\n';
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


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

int main(){
  int N;
  string S;
  cin >> N >> S;
  int x = 0;
  int max_x = 0;//xの最大値を保持
  
  for(int i = 0; i < N; i++){
    if(S[i] == 'I'){
      x++;
    }
    else{
      x--;
    }
    
    if(x > max_x) max_x = x;
  }
  
  cout <<  max_x << endl;
}

Measured memory_bytes: 256
#include <iostream>

#include <vector>
using namespace std;
int main(){
  int n,p;
  for(;;){
    cin >>n >> p;
    if(n == 0 && p == 0)break;
    vector<int> human;
    for(int i = 0;i < n;i++){
      human.push_back(0);
    }
    int stone = p;
    int turn = 0;
    for(;;){
      if(!stone){
        stone += human[turn];
        human[turn] = 0;

      } else if(stone > 0){
        stone--;
        human[turn]++;
        if(!stone && human[turn] == p){
          cout << turn << endl;
          break;
        }
      }

      turn++;
      if(turn >= n) turn = 0;
    }

  }
}

Measured memory_bytes: 3016
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

const long long MOD = 1000000007;

int a;
int b;

int x, y;

const int MAXN = 1000010;
int p[1000010];
int szP;
int vis[1000010];

void make_p() {
	//挖素数
	szP = 0;
    vis[0] = vis[1] = 1;
    for(int i = 2 ; i < MAXN ; i++)
    {
	    if (!vis[i]) {
	        p[szP] = i;
	        szP++;
	        
	        for(int j = i * 2 ; j < MAXN ; j += i)
				vis[j] = 1;
	    }
	}
}

long long qsm(long long a, long long b){//快速幂
    long long ans = 1, w = a;
    for ( ; b ; b >>= 1, w = (w * w) % MOD)
	{
		if(b & 1)
			ans = (ans * w) % MOD;
	}
    return ans;
}

long long Get(long long x, long long y) {
    long long sum = 0;
    for( ; x ; x /= y)
		sum += x / y;
    return sum;
}

long long  getC(int x, int y) {
    long long ans = 1;
    
    for(int i = 0 ; (i < szP && p[i] <= x) ; i++) {
        int T = Get(x, p[i]) - Get(x - y, p[i]) - Get(y,p[i]);
        ans = (ans * qsm(p[i], T)) % MOD;
    } 
    return ans;
}

int main()
{
	make_p();
	
	scanf("%d%d", &x, &y);
	
	int a = 2 * x - y;
	int b = 2 * y - x;
	
	if ((a < 0) || (b < 0))
	{
		printf("0\n");
		return 0;
	}
	
	if ((a % 3 == 0) && (b % 3 == 0))
	{
		a = a / 3;
		b = b / 3;
		long long ans = getC(a + b, b);
		printf("%I64d\n", ans);
	}
	else
	{
		printf("0\n");
	}
	
			
	return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  long long step = 0;
  int max  = 0;
  for (int i = 0; i < N; i++) {
  	int x;
    cin >> x;
    if (x >= max) {
      max = x;
    } else {
      step += max - x;
    }
  }
  
  cout << step << endl;
  return 0;
}

Measured memory_bytes: 3592
aI, aO, aT, aJ, aL, aS, aZ = map(int, input().split())

def calc(I, J, L) :        
    I -= I % 2
    J -= J % 2
    L -= L % 2
    return I + J + L
    
ret = aO + calc(aI, aJ, aL)
if aI >= 1 and aJ >= 1 and aL >= 1 :
    ret = max(ret, aO + calc(aI-1, aJ-1, aL-1) + 3)

print(ret)

Measured memory_bytes: 38384
N=int(input())
A= list(map(int,input().split()))
l=[0]*N
for i in range(N):
   if A[i] == i+1:
      l[i]=1
ans=0
for i in range(N):
   if l[i] == 1:
      try:
         if l[i+1] == 1:
            l[i+1]=0
            ans+=1
         else:
            ans+=1
      except IndexError:
         ans+=1
print(ans)

Measured memory_bytes: 14004
#include <cstdio>

int n;
int A[21];

constexpr int mod = 1000000007;

int dp[1<<21];

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      int x;
      scanf("%d", &x);
      if(x) A[i] |= 1 << j;
    }
  }

  dp[0] = 1;
  for(int x = 1; x < (1<<n); x++){
    int i = __builtin_popcount(x);
    for(int y = x & A[i-1]; y; y &= y-1){
      int j = y & -y;
      dp[x] += dp[x & ~j];
      if(dp[x] >= mod) dp[x] -= mod;
    }
  }
  printf("%d\n", dp[(1<<n)-1]);
  return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(ll, n);
  vector<ll> a(n);
  ll S = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    S += a[i];
  }

  ll ans = S, sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += a[i];
    ans = min(ans, abs(sum - (S - sum)));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  string a, b; cin >> a >> b;
  if (a.length() != b.length()) {
    cout << (a.length() > b.length() ? "GREATER\n" : "LESS\n");
  } else {
    REP(i, a.length()) {
      if (a[i] > b[i]) {
        cout << "GREATER\n";
        return 0;
      } else if (a[i] < b[i]) {
        cout << "LESS\n";
        return 0;
      }
    }
    cout << "EQUAL\n";
  }
  return 0;
}


Measured memory_bytes: 256
using System;
public class Hello{

    public static void Main(){

      string line = Console.ReadLine();
      line += line;
      string word = Console.ReadLine();
      int exis = 0;

      exis = line.IndexOf(word);

      if(exis>=0){
        Console.WriteLine("Yes");
      }else{
        Console.WriteLine("No");
      }



    }
  //#####################
    public static int[] LineToInt(){
      string line = Console.ReadLine();
      string[] arrStr = line.Split(' ');
      int[] arrInt = new int[arrStr.Length];

      for(var i=0; i<arrStr.Length;i++){
        arrInt[i] = int.Parse(arrStr[i]);
      }
      return arrInt;
  }
}



Measured memory_bytes: 18352
def main():
    s = input() + "#"
    group = [[s[0], 1, 1, 0]]
    for i in range(1, len(s)):
        if s[i] == group[-1][0]:
            group[-1][1] += 1
        else:
            group[-1][3] = i
            group.append([s[i], 1, i + 1, -1])
    group.sort(key=lambda x: x[1], reverse=True)
    if group[0][1] > 1:
        print(group[0][2], group[0][3])
    else:
        for i in range(len(s) - 4):
            if s[i] == s[i + 2] and s[i] != s[i + 1]:
                print(i + 1, i + 3)
                break
        else:
            print(-1, -1)


if __name__ == '__main__':
    main()



Measured memory_bytes: 22004
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let mut n: i64 = get();
    let mut ans = Vec::new();
    let mut ans2 = Vec::new();
    n += 1;
    let mut ops = Vec::new(); 
    while n > 1 {
        if n % 2 == 1 {
            ops.push(1);
        }
        n /= 2;
        ops.push(0);
    }
    ops.reverse();
    let mut pos = 1;
    for v in ops {
        if v == 0 {
            // double
            ans.push(pos);
            ans2.push(pos);
        } else {
            ans.push(pos);
            ans2.insert(0, pos);
        }
        pos += 1;
    }
    ans.append(&mut ans2);
    println!("{}", ans.len());
    for i in 0 .. ans.len() {
        print!("{}{}", ans[i], if i == ans.len() - 1 { "\n" } else { " " });
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
 
typedef long long ll;
typedef pair<int, int> ii;
 
int main(){

	vector<int> ans(5);
	rep(i, 5) cin >> ans[i];
	SORT(ans);
	rep(i, 5){
		cout << ans[4-i];
		if(i != 4) cout << " ";
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 3144
#include<iostream>
#include<algorithm>
#include<vector>
#include <iomanip>
#include <cmath>
#include <string.h>
#include <stdio.h>

using namespace std;
 

int main(){
  
  	int X, Y;
  
  	cin >> X >> Y;
  
  	bool kumiawase = true;
  
  	for(int i=0; i<=X; i++){
    	if(Y == 2*(X-i)+4*i){
        	cout << "Yes" << endl;
          	kumiawase = false;
          	break;
        }
    }
      
      if(kumiawase)
        cout << "No" <<endl;
  

  return 0;
  
}

Measured memory_bytes: 3128
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      a: [usize; n]
   }
   let mut x = vec![0; 3];
   for &a in a.iter() {
      match a % 4 {
         0 => x[2] += 1,
         2 => x[1] += 1,
         _ => x[0] += 1,
      }
   }
   if x[1] == 0 && x[0] <= x[2] + 1 {
      println!("Yes");
   } else if x[0] <= x[2] {
      println!("Yes");
   } else {
      println!("No");
   }
}


Measured memory_bytes: 3700
//abc072d
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
//#pragma comment(lib, "winmm.lib")
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n;

int main() {
    cin >> n;
    vector<int> p(n);
    REP(i,n){
        cin >> p[i];
    }
    int res = 0;
    REP(i,n){
        if(p[i]==i+1){
            res++;
            //if(i+1<n){
                if(p[i+1]==i+2){
                    i++;
                }
            //}
        }
    }
    put(res);
    return 0;
}


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

namespace abc138_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var n = CIn.ReadInt();
      var a = CIn.ReadIntArray(n);

      var ans = 1.0 / a.Select(e => 1.0 / (double)e).Sum();

      Console.WriteLine(ans);
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }

      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }

      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }

      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }

      return array;
    }
    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }

      return array;
    }
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<vector<char>> v(n, vector<char>(n)), a, b, c, d;
  a = {{'a','a','b','b','a'},{'b','c','c','.','a'},{'b','.','.','c','b'},{'a','.','.','c','b'},{'a','b','b','a','a'}};
  b = {{'.','.','a','a','b','c'},{'.','.','d','d','b','c'},{'b','c','.','.','a','a'},{'b','c','.','.','d','d'},{'a','a','b','c','.','.'},{'d','d','b','c','.','.'}};
  c = {{'a','a','b','b','c','c','.'},{'d','d','.','d','d','.','a'},{'.','.','d','.','.','d','a'},{'.','.','d','.','.','d','b'},{'a','a','.','a','a','.','b'},{'.','.','a','.','.','a','c'},{'.','.','a','.','.','a','c'}};
  d = {{'c','c','b','c'},{'a','a','b','c'},{'b','c','a','a'},{'b','c','b','b'}};
  if(n == 2) cout << -1 << endl;
  else{
	if(n == 3) v = {{'a', 'a', '.'},{'.', '.', 'a'},{'.','.', 'a'}};
	else{
	  for(int i = 0; i < n - 4 - (n % 4); ++i){
        for(int j = 0; j < n; ++j){
          if(i / 4 == j / 4) v.at(i).at(j) = d.at(i-(i/4*4)).at(j-(j/4*4));
          else v.at(i).at(j) = '.';
        }
      }
      if(n % 4 == 0){
      	for(int i = n - 4; i < n; ++i){
      	  for(int j = 0; j < n; ++j){
            if(j < n - 4) v.at(i).at(j) = '.';
            else v.at(i).at(j) = d.at(i - n + 4).at(j - n + 4);
          }
        }
      }
      else if(n % 4  == 1){
        for(int i = n - 5; i < n; ++i){
          for(int j = 0; j < n; ++j){
            if(j < n - 5) v.at(i).at(j) = '.';
            else v.at(i).at(j) = a.at(i - n + 5).at(j - n + 5);
          }
        }
      }
      else if(n % 4  == 2){
        for(int i = n - 6; i < n; ++i){
          for(int j = 0; j < n; ++j){
            if(j < n - 6) v.at(i).at(j) = '.';
            else v.at(i).at(j) = b.at(i - n + 6).at(j - n + 6);
          }
        }
      }
      else if(n % 4  == 3){
        for(int i = n - 7; i < n; ++i){
          for(int j = 0; j < n; ++j){
            if(j < n - 7) v.at(i).at(j) = '.';
			else v.at(i).at(j) = c.at(i - n + 7).at(j - n + 7);
          }
        }
      }
    }
  	for(int i = 0; i < n; ++i){
	  for(int j = 0; j < n; ++j) cout << v.at(i).at(j);
    	cout << endl;
    }
  }
}


Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


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

	int N;
	cin >> N;
	vector<int>a(N);
	int ma = -1;
	int mi = 1e7;
	for (int i = 0; i < N; i++) { cin >> a[i]; ma = max(ma, a[i]), mi = min(mi, a[i]); }
	
	if (ma - mi >= 2) { puts("No");}
	else if (ma - mi == 1) {
		int macnt = 0;
		int micnt = 0;
		for (int i = 0; i < N; i++) {
			if (a[i] == ma)macnt++;
			else micnt++;
		}
		if (micnt <= mi && mi <= micnt - 1 + (macnt / 2))puts("Yes");
		else puts("No");
	}
	else {
		if (1 <= ma && ma <= N / 2)puts("Yes");
		else if (ma == N - 1)puts("Yes"); 
		else puts("No");
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#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 DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, l;
	int mi=1e9, idx=-1;
	cin>>n>>l;
	int sum=0;
	REP(i, n){
		sum+=l+i;
	}
	REP(i, n){
		if(mi>abs(l+i)){
			mi=abs(l+i);
			idx=i;
		}
	}
	cout<<sum-(l+idx)<<'\n';
	return 0;
}


Measured memory_bytes: 256
//////////////////////////
//      _        ____   //
//  U  /"\  u U /"___|  //
//   \/ _ \/  \| | u    //
//   / ___ \   | |/__   //
//  /_/   \_\   \____|  //
//   \\    >>  _// \\   //
//  (__)  (__)(__)(__)  //
//  Compro by NULL_CT©  //
//////////////////////////
// STL libs
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(I, LIM) for (int I = 0; I < (LIM); I++)
#define ALL(LIST) (LIST.begin()), (LIST.end())

using namespace std;

constexpr int MOD = 10000007;

vector<long> divisor(long &_n) {
  vector<long> head, tail;
  for (long i = 1; i * i <= _n; i++) {
    if (_n % i == 0) {
      head.push_back(i);
      if (i * i != _n)
        tail.push_back(_n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return head;
}

long kadanes(vector<long> &_ls) {
  long highestmax=0,currentmax=0,length=_ls.size();
  for(long i=0;i<length;i++){
    currentmax=max(_ls[i],currentmax+_ls[i]);
    highestmax=max(highestmax,currentmax);
  }
  return highestmax;
}

struct init {
  init() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    //cout<<fixed<<setprecision(20);
  }
} init;

/*----------------------------*/

int main() {
  int c[3][3];
  REP(y,3){
    REP(x,3){
      cin>>c[x][y];
    }
  }

  {
    int dif=c[0][0]-c[1][0];
    REP(i,2){
      if(dif != c[0][i+1]-c[1][i+1]){
        cout<<"No\n";
        return 0;
      }
    }
  }
  {
    int dif=c[1][0]-c[2][0];
    REP(i,2){
      if(dif != c[1][i+1]-c[2][i+1]){
        cout<<"No\n";
        return 0;
      }
    }
  }

  {
    int dif=c[0][0]-c[0][1];
    REP(i,2){
      if(dif != c[i+1][0]-c[i+1][1]){
        cout<<"No\n";
        return 0;
      }
    }
  }
  {
    int dif=c[0][1]-c[0][2];
    REP(i,2){
      if(dif != c[i+1][1]-c[i+1][2]){
        cout<<"No\n";
        return 0;
      }
    }
  }
  cout<<"Yes\n";
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans=1;
    char tmp=s[0];
    for(int i=1;i<n;i++){
        if(s[i] != tmp){
            ans++;
            tmp = s[i];
        }
    }

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

Measured memory_bytes: 1024
using System;

namespace B
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var h = int.Parse (input[0]);
            var w = int.Parse (input[1]);
            var c = new char[h, w];
            for (var i = 0; i < h; i++)
            {
                var input1 = Console.ReadLine ();
                for (var j = 0; j < w; j++)
                {
                    c[i, j] = input1[j];
                }
            }
            for (var i = 0; i < h; i++)
            {
                for (var k = 0; k < 2; k++)
                {
                    for (var j = 0; j < w; j++)
                    {
                        Console.Write (c[i, j]);
                    }
                    Console.WriteLine ();
                }
            }
        }
    }
}

Measured memory_bytes: 11192
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node*  find(Node *u, int k) {
	while (u != NIL) {
		if (u->key == k) {
			return u;
		}
		else if (k < u->key) {
			u = u->left;
		}
		else {
			u = u->right;
		}
	}
	return u;
}

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}

	z->parent = y;
	if (y == NIL) {
		root = z;
	}
	else {
		if (z->key < y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if (u == NIL) {
		return;
	}
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u) {
	if (u == NIL) {
		return;
	}
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main() {
	int n, i, x;
	string com;

	NIL = NULL;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		cin >> com;
		if (com == "insert") {
			scanf("%d", &x);
			insert(x);
		}
		else if (com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if (com == "find") {
			scanf("%d", &x);
			if (find(root, x) != NIL) {
				printf("yes\n");
			}
			else {
				printf("no\n");
			}
		}
	}

	return 0;
}

Measured memory_bytes: 20004
//People only find me interesting because they can't tell whether I'm serious or not
//#include <boost/multiprecision/cpp_int.hpp> 
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
typedef __int128 s128;
typedef __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define P 1000000007
#define Q 1000000006
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define bac(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define N 1005
#define PI 3.14159265359
#define inf LLONG_MAX
//using namespace boost::multiprecision; 
using namespace __gnu_pbds;
using namespace std;
char a[N][N];
ll dp[N][N];
void solve(){
    ll h,w;
    cin>>h>>w;
    f(i,0,h) f(j,0,w) cin>>a[i][j];
    f(j,0,w){
        if(a[0][j]=='.') dp[0][j]=1;
        else break;
    }
    f(i,0,h){
        if(a[i][0]=='.') dp[i][0]=1;
        else break;
    }
    f(i,1,h){
        f(j,1,w){
            if(a[i-1][j]=='.') (dp[i][j] += dp[i-1][j]) %= P;
            if(a[i][j-1]=='.') (dp[i][j] += dp[i][j-1]) %= P;
        }
    }
    cout<<dp[h-1][w-1];

}
signed main() {
    teevra_gati
    
    solve();

    return 0;
}

Measured memory_bytes: 9088