akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = std::numeric_limits<T>::max() / 10;
std::mt19937 mt{std::random_device{}()};
int main()
{
    int N;
    std::cin >> N;
    std::vector<ll> a(N);
    for (auto& e : a) { std::cin >> e; }
    std::sort(a.begin(), a.end());
    std::vector<ll> b = a, c;
    for (int i = 0; i < (N + 1) / 2; i++) { c.push_back(b.back()), b.pop_back(); }
    std::sort(c.begin(), c.end(), std::greater<ll>{});
    ll ans = 0;
    if (N % 2 == 0) {
        const ll score = 2 * std::accumulate(c.begin(), c.end(), 0LL) - 2 * std::accumulate(b.begin(), b.end(), 0LL) + b.back() - c.back();
        ans = std::max(ans, score);
    } else {
        ll score = 2 * std::accumulate(c.begin(), c.end(), 0LL) - 2 * std::accumulate(b.begin(), b.end(), 0LL) - c[(N - 3) / 2] - c.back();
        ans = std::max(ans, score);
        b.push_back(c.back()), c.pop_back();
        score = 2 * std::accumulate(c.begin(), c.end(), 0LL) - 2 * std::accumulate(b.begin(), b.end(), 0LL) + b[(N - 3) / 2] + b.back();
        ans = std::max(ans, score);
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 2428
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__

int main() {
    int K, S; cin >> K >> S;

    int cnt = 0;
    for (int x = 0; x <= K; x++) {
        for (int y = 0; y <= K; y++) {
            int z = S - x - y;
            if (z >= 0 && z <= K) cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)
#define Reps(i, x, N) for(int i = x; i < N; i++)
typedef pair<int, int> Pi;
#define fi first
#define se second

const int LLINF = 1LL << 60;

struct BIT
{
  vector <int> val;
  
  BIT(int sz) {
    val.assign(sz + 810, 0);
  }

  void add(int k, int x) {
    for(++k; k <= val.size(); k += k & -k) val[k] += x;
  }

  int query(int k) {
    int ret = 0;
    for(++k; k > 0; k -= k & -k) ret += val[k];
    return ret;
  }

};
  

signed main()
{
  int N;
  Pi A[100005];
  int out[100005] = {0};

  cin >> N;
  A[N].fi = 0, A[N].se = -1;
  Rep(i, N) {
    cin >> A[i].fi; A[i].se = i;
  }

  BIT tree(N);
  sort(A, A + N + 1, greater< Pi >());

  int minv = LLINF;
  int i = 0;
  while(i < N) {
    int save = A[i].fi;
    while(save == A[i].fi && i < N) {
      tree.add(i, 1); i++;
    }
    minv = min(A[i - 1].se, minv);
    //cout << i << " " << minv << " " << A[i - 1].fi << endl;
    int val = tree.query(N + 10);
    out[minv] += val * (A[i - 1].fi - A[i].fi);
  }

  Rep(i, N) {
    cout << out[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 4224
package main
  
import (
    "fmt"
)

func main() {
    var n, m int
    fmt.Scan(&n, &m)

    ls := make([]int, m)

    for i := 0; i < n; i++ {
        var k int
        fmt.Scan(&k)
        for j := 0; j < k; j++ {
            var a int
            fmt.Scan(&a)
            ls[a-1]++
        }
    }

    //fmt.Println(ls)

    var sum int
    for i := 0; i < m; i++ {
        if ls[i] == n {
            sum++
        }
    }

    fmt.Println(sum)
}


Measured memory_bytes: 512
#include<stdio.h>

int tanri(double r,int y,int mon,int ts)
{
  int i,last;
  last=0;
  for(i=0;i<y;i++){
    last=last+mon*r;
    mon=mon-ts;
  }
  last=last+mon;
    return (last);
}

int fukuri(double r,int y,int mon,int ts)
{
  int i,last;
  last=0;
  for(i=0;i<y;i++){
    last=mon+mon*r-ts;
    mon=last;
  }
  return (mon);
}
 

int remain(int n,int mon,int y)
{

  int re[n],x,ts,max,j;
  double r;

  max=0;
  for(j=0;j<n;j++){
    scanf("%d %lf %d",&x,&r,&ts);
    /* printf("x=%d r=%f ts=%d\n", x,r,ts);*/
    if(x==0){
      re[j]=tanri(r,y,mon,ts);
      /* printf("tanrire[%d]=%d\n", j,re[j]);*/
    }
    else{
      re[j]=fukuri(r,y,mon,ts);
      /* printf("fukurire[%d]=%d\n", j,re[j]);*/
    }
    if(re[j]>max){
      max=re[j];
    }
  }
  
  return(max);
}

 
int main(void)
{
  int n,m,y,mon,i,x,ts,max=0;
  double r;
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d %d %d",&mon,&y,&n);
    max=remain(n,mon,y);
    printf("%d\n",max);
  }

  return 0;
}

Measured memory_bytes: 632
# coding: utf-8
# Your code here!

D,G = map(int,input().split()) # D問題数,G目標点
lst = [list(map(int,input().split()))for i in range(D)]
ans = float('inf')
for i in range(1 << D): # 全探索
    tmp = 0
    count = 0
    bit = ""
    for j in range(len(lst)):
        bit+=str((i >> j)&1)
        if ((i >> j) & 1) == 1:
            tmp = tmp + lst[j][1] + ((j + 1) * 100 * lst[j][0])
            count+=lst[j][0]
    #print("tmp",tmp)
    if tmp < G : #or tmp >= G
        #print(bit)
        for n,k in enumerate(list(bit)):
            if k == "0":
                for p in range(lst[len(bit) - n - 1][0]):
                    t = p * 100 * (n+1)
                    #print("p",p,t,tmp,G,count)
                    if t + tmp >= G:
                        ans = min(ans,p+count)
    
    #if tmp >= G :
    else:
        ans = min(ans,count)
    #print(ans,tmp,count)
print(int(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define MAX 500005
#define INF ((ll)1e17)
using namespace std;

ll n, ans = -INF;
ll a[MAX], sum[MAX][3], mx[MAX], ss[MAX];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    if(!(n&1)){
        ll s = 0;
        for(int i = 1; i <= n; i += 2) s += a[i];
        ans = max(ans, s);
        s = 0;
        for(int i = 2; i <= n; i += 2) s += a[i];
        ans = max(ans, s);
        for(int i = 1; i <= n; i += 2){
            ss[i] = ss[max(i-2, 0)]+a[i];
        }
        for(int i = n; i >= 2; i -= 2){
            ss[i] = ss[i+2]+a[i];
        }
        for(int i = 1; i <= n; i += 2){
            ans = max(ans, ss[i]+ss[i+3]);
        }
        cout << ans << endl;
        return 0;
    }
    for(int i = 1; i <= n; i += 2) sum[i][1] = sum[max(i-2, 0)][1]+a[i];
    ll s = 0;
    for(int i = n-1; i >= 2; i -= 2) s += a[i+1], sum[i][0] = sum[i+2][0]+a[i], mx[i] = s-sum[i][0];
    for(int i = n-1; i >= 2; i -= 2){
        mx[i] = max(mx[i], mx[i+2]);
    }
    for(int i = 1; i <= n; i += 2){
        ans = max(ans, sum[max(i-2, 0)][1]+sum[i+1][0]+mx[i+1]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11496
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {

    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << a[K-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int,int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int main(int argc, const char * argv[]) {
    int N, K;
    SCD(N);
    SCD(K);
    int h[N];
    FOR(i, 0, N, 1)
        SCD(h[i]);
    int c[N];
    c[0] = 0;
    FOR(i, 1, N, 1) {
        int minCost = c[i - 1] + abs(h[i] - h[i - 1]);
        FOR(j, 2, K + 1, 1) {
            if (i - j < 0) break;
            minCost = min(minCost, c[i - j] + abs(h[i] - h[i - j]));
        }
        c[i] = minCost;
    }
    
    printf("%d\n", c[N - 1]);
}


Measured memory_bytes: 1024
N, M = (int(i) for i in input().split())
DP = [False]*N
for i in range(M):
  a, b = (int(k) for k in input().split())
  for j in (a, b):
    DP[j-1] = not DP[j-1]
for i in range(N):
  if DP[i]:
    print('NO')
    break
else:
  print('YES')

Measured memory_bytes: 3828
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)*}
    };
}

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

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let mut c = vec![0; n];
    for &x in &v {
        c[x] += 1;
    }
    let m: usize = v.iter().cloned().max().unwrap();
    for i in 1..(m + 1) / 2 {
        if c[i] > 0 {
            println!("Impossible");
            return;
        }
    }
    if m % 2 == 0 && c[(m + 1) / 2] != 1 {
        println!("Impossible");
        return;
    } else if m % 2 == 1 && c[(m + 1) / 2] != 2 {
        println!("Impossible");
        return;
    }
    for i in (m + 1) / 2 + 1..m + 1 {
        if c[i] < 2 {
            println!("Impossible");
            return;
        }
    }
    println!("Possible");
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<functional>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<unordered_set>
#include<unordered_map>
#define int long long
using namespace std;

int a[26];
signed main(){
	int ans = 1;
	string b; cin >> b;
	for (char c : b) {
		a[c - 'a'] ++;
	}
	int sum = b.length();
	for (int i = 0; i < 26; i++) {
		sum -= a[i];
		ans += a[i] * sum;
	}
	cout << ans << endl;
	getchar();
}

Measured memory_bytes: 640
from math import sqrt

N = int(input())

rn = int(sqrt(N))
sieve = [0] * (rn + 1)
sieve[0] = -1
sieve[1] = -1
t = [0] * (rn + 1)
for i in range(2, rn + 1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    j = i
    while j < rn + 1:
        t[j] = 1
        j *= i
    for j in range(i * i, rn + 1, i):
        if sieve[j] == 0:
            sieve[j] = i

result = 0
last = -1
for i in range(2, rn + 1):
    if t[i] == 0:
        continue
    if N % i == 0:
        result += 1
        N //= i
        last = i
if N != 1 and N > rn:
    result += 1
print(result)


Measured memory_bytes: 27172
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	bool leap[3001];
	for (int i = 0; i < 3001; i++) {
		int y = i;
		if (y % 4 != 0) { leap[i] = false; }
		else if(y%100!=0){
			leap[i] = true;
		}
		else if (y % 400 != 0) {
			leap[i] = false;
		}
		else {
			leap[i] = true;
		}
	}
	int a, b;
	bool first = true;
	while (cin >> a >> b) {
		bool ever = false;
		if (a == 0 && b == 0) { break; }
		if (!first) { cout << endl; }
		for (int i = a; i <= b; i++) {
			if (leap[i]) { ever = true; cout << i << endl; }
		}
		if (!ever)
		{
			cout << "NA" << endl;
		}first = false;
	}
	return 0;
}


Measured memory_bytes: 3152
N = gets.to_i
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

puts a[N-1]

Measured memory_bytes: 1788
"use strict";
var a = [1]; //層の総数
var p = [1]; //パテの数
function f(n, x) {
    if (n == 0) {
        return  (x <= 0) ? 0 : 1;
    } else if (x <= 1 + a[n - 1]) {
        return f(n - 1, x - 1);
    } else {
        return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1]);
    }
}
function Main(input) {
    var l0 = input.split(" ");
    var N = l0[0] - 0;
    var X = l0[1] - 0;
    for (let n = 1; n <= N; n++) {
        a.push(a[n - 1] * 2 + 3);
        p.push(p[n - 1] * 2 + 1);
    }
    console.log(f(N, X));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) { cout << "["; \
	for(int i = 0; i < (a).size(); ++i){ \
		cout << i <<":" << a[i] <<" "; \
		if(i % 10 == 9) cout <<"\n"; \
		} \
	cout << "]"; \
}
#define ovv(a) { cout << "["; \
	for(int i = 0; i < a.size(); ++i){ \
		for(int j = 0; j < a[i].size(); ++j){ \
			cout << "(" << i <<"," <<j <<")" <<":" << a[i][j] <<" "; \
		} \
		cout << "\n"; \
	} \
	cout << "]"; \
}
#define op(a) { cout <<"[" << #a << ".fi:"<<a.first; \
					cout << " "<< #a << ".se:" << a.second <<"]"; }
//priority_queue <int>a;
#define ll long long
const ll mod = 1e9 + 7;
const int nax = 1e5 + 5;
ll n, m, k, q;

int main(){
	fast();
	cin >> n >> k;
	vector<int> dp(n + 3, 0);
	//dp[i] how many sum if we choose exact i num
	ll mi = 0, ma = 0;
	ll ans = 0;
	for(ll i = 0; i < k; ++i)
		mi += i;
	for(ll i = n;i > n - k; --i)
		ma += i;
	for(int i = k; i <= n + 1; ++i){
		ans = ans + ma - mi + 1;
		if (ans < 0) ans += mod;
		ans %= mod;
		mi += i;
		ma += n - i;
	}
	cout << ans;
	
}



Measured memory_bytes: 3972
//

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n,d;cin>>n>>d;
    int ans = 0;
    rep(i,0,n){
        double a,b;cin>>a>>b;
        if(d*d>=a*a+b*b)ans++;
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 3752
a, b, n = map(int, input().split())
import math
ans = 0
if b - 1 <= n:
    x = b - 1
    ans = math.floor(a * x / b)
else:
    x = n
    ans = math.floor(a * x / b) - a * math.floor(x / b)
    #print(1, ans)
print(ans)

Measured memory_bytes: 9180
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

ll GCD(ll a, ll b) {
  if (b == 0)
    return a;
  return GCD(b, a % b);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, K;
  cin >> N >> K;
  ll ans = llINF;

  if (N == K) {
    cout << 0 << endl;
    return 0;
  }
  if (N < K) {
    cout << min(abs(N - K), N) << endl;
    return 0;
  }

  ans = min(ans, abs((N / K) * K - N));
  ans = min(ans, abs((N / K) * K + K - N));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
io = STDIN
n=io.gets.to_i
a=io.gets.split.map(&:to_i)
# i < j
# j-i = a[j]+a[i]
# i+a[i]=j-a[j]
hash=Hash.new{|h,k|h[k]=[[],[]]}
n.times do |i|
  hash[(i+1)+a[i]][0]<<(i+1)
  hash[(i+1)-a[i]][1]<<(i+1) if (i+1)-a[i] > 0
end
puts hash.values.map{|plus,minus|plus.size*minus.size}.sum


Measured memory_bytes: 55472
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 1e5 + 7;

int main()
{
    int a, b, c;
    cin>>a>>b>>c;
    c = min(c, c-(a-b));
    if(c < 0) c = 0;
    cout<<c<<endl;


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1003
#define endl "\n"

#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;

using namespace std;

int maze[N][N];
int m, n;
int ans = -1;
void solve(int i, int j, int sum) {
    if (i < 0 || i >= m || j < 0 || j >= n)
        return ;
    if (i == m-1 && j == n-1) {
        ans = max(ans, sum + maze[i][j]);
        return ;
    }

    solve(i+1, j, sum + maze[i][j]);

    solve(i, j+1, sum + maze[i][j]);
}

int main() {
    // for fast input output using cin cout
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    // size of array
    // input
    m = 2;
    cin >> n;
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j)
            cin >> maze[i][j];
    }

    solve(0, 0, 0);
    cout << ans << endl;
    return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while(0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

const ll M = 200000;
ll dp[M];

signed main() {
  ll x;
  cin >> x;
  ll l = 0, r = 0;
  rep(i, 2000) {
    if (l <= x && x <= r) {
      cout << 1 << endl;
      return 0;
    }
    l += 100;
    r += 105;
  }
  cout << 0 << endl;
  return 0;
}


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

int main(){
    
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, a[101];
    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    long long ans = LLONG_MAX;
    for(int j = 0; j <= 100; ++j){
        long long cnt = 0;
        for(int i = 0; i < n; ++i){
            cnt += (a[i] - j) * (a[i] - j);
        }
        ans = min(ans, cnt);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main()
{
    int l,r,lmod,rmod,a,min=2020;
    int i,j;

    scanf("%d %d",&l,&r);

    lmod=l%2019;
    rmod=r%2019;

    if(lmod>=rmod||(r-l)>=2019)
    {
        rmod+=2019;
    }
 
    for(int i=lmod;i<=rmod;i++)
    {
        for(j=i+1;j<=rmod;j++)
        {
            a=(i*j)%2019;
            if(a<=min)
            {
                min=a;
            }
        }
    }
 
    printf("%d\n",min);
}
 

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
void swap(int *a,int *b)
{
    int temp=*a;
    *a=*b;
    *b=temp;
}
int main()
{  int n,k,i,j,rem;
   cin>>n;k=0;int arr[4]={0};
   while(n>0)
     {
         
      rem=n%10;
      arr[k++]=rem;
       n=n/10;
       
   }
   string ans1,ans2;
   i=0;j=3;
   while(i<j)
   {
       swap(&arr[i],&arr[j]);i++;j--;
   }
   int month1,month2,year1,year2;
   month1=arr[0]*10 + arr[1];
   month2=arr[2]*10 + arr[3];
   year1=arr[0]*10 + arr[1];
   
   year2=arr[2]*10 + arr[3];
   
   i=0;
   j=0;
   if(month1>=1 && month1<=12 && year2>=0 && year2<=99)
   { i=1;
        ans1="MMYY";
   }
   if(month2>=1 && month2<=12 && year1>=0 && year1<=99)
   {j=1;
      ans2="YYMM";
   }
   if(i==1 && j==1)
   cout<<"AMBIGUOUS"<<endl;
   else if(i==1)
   cout<<ans1<<endl;
   else if(j==1)
   cout<<ans2<<endl;
   else
   cout<<"NA"<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a,b,c,sort[3],i,j;
	scanf("%d %d %d",&a,&b,&c);

	sort[0]=a;
	sort[1]=b;
	sort[2]=c;

	for(i=0;i<3;i++){
		for(j=2;j>i;j--){
			if(sort[j]<sort[j-1]){
				int temp=sort[j];
				sort[j]=sort[j-1];
				sort[j-1]=temp;
			}
		}
	}

	printf("%d %d %d\n",sort[0],sort[1],sort[2]);


	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
using lint=long long;
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
lint gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
signed main(){  
  int n,x;cin>>n>>x;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  lint res=0;
  rep(i,n){
      res=gcd(res,abs(x-a[i]));
      //cout<<res<<"\n";
  }
  cout<<res<<"\n";
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr long long LLINF = 1LL << 60;

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

int main() {
  int a, b, q; cin>>a>>b>>q;
  vector<long long> s(a+2), t(b+2);
  s[0] = t[0] = -LLINF;
  s[a+1] = t[b+1] = LLINF;
  rep(i, a) cin>>s[i+1];
  rep(i, b) cin>>t[i+1];

  rep(i, q) {
    long long x; cin>>x;
    long long ans = LLINF;
    long long sr = *lower_bound(s.begin(), s.end(), x);
    long long sl = *(lower_bound(s.begin(), s.end(), x) - 1);
    long long tr = *lower_bound(t.begin(), t.end(), x);
    long long tl = *(lower_bound(t.begin(), t.end(), x) - 1);

    if (sr <= tr) ans = min(ans, tr-x);
    else ans = min(ans, sr-x);
    if (sl <= tl) ans = min(ans, x-sl);
    else ans = min(ans, x-tl);
    ans = min(ans, (tr-x) + (x-sl) + min((tr-x), (x-sl)));
    ans = min(ans, (sr-x) + (x-tl) + min((sr-x), (x-tl)));
    print(ans);
  }

  return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007

long long dp[110][5][5][5];

int main() {
  int n;
  cin >> n;
  dp[0][0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int a = 0; a < 5; a++) {
      for (int b = 0; b < 5; b++) {
        for (int c = 0; c < 5; c++) {
          for (int d = 1; d <= 4; d++) {
            if (b == 1 && c == 3 && d == 2) continue;
            if (a == 1 && c == 3 && d == 2) continue;
            if (b == 3 && c == 1 && d == 2) continue;
            if (b == 1 && c == 2 && d == 3) continue;
            if (a == 1 && b == 3 && d == 2) continue;
            dp[i + 1][b][c][d] = (dp[i + 1][b][c][d] + dp[i][a][b][c]) % mod;
          }
        }
      }
    }
  }
  long long ans = 0;
  for (int a = 0; a < 5; a++) {
    for (int b = 0; b < 5; b++) {
      for (int c = 0; c < 5; c++) {
        ans = (ans + dp[n][a][b][c]) % mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
int main() 
{
	 ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     
		 int n;
		 cin>>n;
		 int a[n];
		 for(int i=0;i<n;i++)
		 cin>>a[i];
		 int count=0,ans=0;
		 for(int i=0;i<n-1;i++)
		 {  if(a[i]>=a[i+1])
			{
				count++;
				ans=max(ans,count);
			}
			else
			{
				count=0;
			}
		 }
		 cout<<ans<<endl;
		 
				 
  
	
}


Measured memory_bytes: 640
#include <stdio.h>

main(){
  int data[5];
  int i, max, a, b, ans;

  while(1){
    scanf("%d %d", &a, &b);
    if(a==0 && b==0) break;
    data[0]=a+b;

    for(i=1;i<5;i++){
      scanf("%d %d", &a, &b);
      data[i]=a+b;
    }

    max=-1;

    for(i=0;i<5;i++){
      if(max<data[i]){
	max=data[i];
	ans=i;
      }
    }

    printf("%c %d\n", ans+'A', max);
  }

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
//const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================

	ll N, K;
	cin >> N >> K;

	vll H(N);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}

	vll dp(N);
	for (int i = 0; i < N; i++) {
		dp[i] = LLINF;
	}
	
	dp[0] = 0;
	dp[1] = abs(H[1] - H[0]);

	for (int i = 2; i < N; i++) {
		for (int step = 1; step <= K; step++) {
			if (i - step < 0) {
				continue;
			}
			else {
				dp[i] = min(dp[i], dp[i - step] + abs(H[i] - H[i - step]));
			}
		}
	}

	cout << dp[N - 1];


}



Measured memory_bytes: 1792
using System;

namespace ABC044_TakAndHotels
{
    public class MainApp
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int K = int.Parse(Console.ReadLine());
            int X = int.Parse(Console.ReadLine());
            int Y = int.Parse(Console.ReadLine());

            int total;
            if (K < N) 
            {
                total = K * X + (N - K) * Y;
            }
            else
            {
                total = N * X;
            }
            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 2648
import sys
hoge = { chr(x):0 for x in range(ord('a'), ord('z')+1)}
a = list()
for line in sys.stdin:
    a.append(line)
for line in a:
    for x in line:
        if x.lower() not in hoge:
            continue
        else:
            hoge[x.lower()] += 1
for k, v in sorted(hoge.items()):
    print ('{} : {}'.format(k, v))


Measured memory_bytes: 5568
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]

ans = "No"
cnt = 0

for i in range(N):
    if len(set(D[i])) == 1:
        cnt += 1
    else:
        cnt = 0
    
    if cnt >= 3:
        ans = "Yes"

print(ans)

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

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

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

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>

using namespace std;

int main(){
  long double a,b,c,S,s,l,h,rad;
  long double PI = acos(-1);
  cin >>a>>b>>c;

  //1/2間のsin
  rad=(c/180)*M_PI;
  S=a*b*sin(rad)/2;
  c=sqrt(a*a+b*b-2*a*b*cos(rad));
  h=b*sin(rad);

  printf("%.8Lf\n%.8Lf\n%.8Lf\n",h*a/2,a+b+c,h);

  //  printf("%.8Lf\n", S);
  
  
  
  return 0;
}



Measured memory_bytes: 3516
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){e.exports=function(e){for(var r=e.split("\n"),t=Number(r[0]),n={},o=0;o<t;o++){var u=Number(r[o+1]);n[u]?n[u]=!n[u]:n[u]=!0}var i=0;for(var f in n)n[f]&&(i+=1);console.log(i)}},function(e,r){e.exports=require("fs")}]);

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

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

  if (A % 2 == 1 && B % 2 == 1) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define msg(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define pri(a) cout << a << endl;

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

  // ll n,ans=0;
  // cin >> n;
  ll n,k,ans=0;
  cin >> n >> k;
  // string s;
  // cin >> s;


  if(n==1 || k==1){
    pri("1");
  }
  else if((n*k)%2==0){
    pri((n*k)/2);
  }
  else{
    pri((n*k)/2+1);
  }

}


Measured memory_bytes: 256
x=int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            if i != n // i:
                divisors.append([i,n//i])
            else:
                divisors.append([i,i])
    return divisors
l=make_divisors(x)
for x,y in l:
    for i in range(10**4):
        p=i-x
        if i**4+(i**3)*p+(i**2)*(p**2)+i*(p**3)+p**4==y:
            print(i,p)
            break

Measured memory_bytes: 9460
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#pragma warning (disable : 4996)

char s[200001];
int c[30];

int main()
{
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	long long ans = 1ll + (long long)n*(n - 1) / 2;
	for (int i = 1; i <= n; i++) c[s[i] - 'a']++;
	for (int i = 0; i < 26; i++)
		ans -= (long long)c[i] * (c[i] - 1) / 2;
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){
  string a, b, c;
  cin >> a >> b >> c;

  cout << a[0] << b[0] << c[0] << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,a[110];

int main(){
	cin >> n;
	REP(i,0,n) cin >> a[i];
	
	int mi=INF;
	REP(i,-100,101){
		int s=0;
		REP(j,0,n) s+=(a[j]-i)*(a[j]-i);
		mi=min(mi,s);
	}
	
	cout << mi << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll n, s[210000];
vector<ll> ans;
int main() {
	cin >> n;
	REPO(i, n) {
		cin >> s[i];
	}
	FORR(i, n, 1) {
		if (s[i] == 1) {
			ans.push_back(i);
			for (int j = 1; j <= sqrt(i); j++)
			{
				if (i % j == 0) {
					s[j] = 1 - s[j];
					if (i / j != j)s[i / j] = 1 - s[i / j];
				}
			}
		}
	}
	sort(ALL(ans));
	cout << ans.size() << endl;
	REP(i, ans.size()) {
		if (i != 0)cout << " ";
		cout << ans[i];
	}
	cout << endl;
}





Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int n,m,x;
int a[101];
int main(){
  cin >> n >> m >> x;
  for(int i=0;i<m;i++)cin >> a[i];
  int c1=0,c2=0;
  for(int i=0;i<m;i++){
    if(a[i]<x)c1++;
    else c2++;
  }
  if(c1<c2)cout << c1 << endl;
  else cout << c2 << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n,l;
ll s=0;
int f = 2;

int func(vector<int> a,int fc,int bc){
    if(fc+bc>n)return 0;
    else if(a[fc+1]<a[n-1-(fc+1)])return 0;
    else if(a[fc+1]>a[n-1-(fc+1)])return 1;
    else return func(a,fc+1,bc+1);
}

int main(){
    cin >> n >> l;
    vector<int> a(n);
    vector<int> res(n-1);
    int debug;
    int fc = INT_MAX;
    Rep(i,n){
        cin >> a[i];
    }
    Rep(i,n-1){
        if(a[i]+a[i+1]>=l){
            fc = i;
            break;
        }
    }
    if(fc==INT_MAX){
        put("Impossible");
    }else{
        put("Possible");
        Rep(i,fc){
            put(i+1);
        }Rep(i,n-fc-1){
            put(n-1-i);
        }
    }
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  if (N == 1) {
    cout << "Hello World" << endl;
  } else {
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a[n] = {0};
    rep(i,n) {
        int m;
        cin >> m;
        a[m]++;
    }
    int ok = 0;
    int64_t ans = 0;
    if (n % 2 == 1) {
        if (a[0] == 1) ok++;
        for (int i = 1; i < n; i++) {
            if ((i%2 == 0 && a[i] == 2) || i%2 == 1 && a[i] == 0) ok++;
        }
    }
    if (n % 2 == 0) {
        for (int i = 0; i < n; i++) {
            if (i%2 == 0 && a[i] == 0 || i%2 == 1 && a[i] == 2) ok++;
        }
    }
    if (ok == n) {
        ans = 1;
        rep(i,n/2) {
            ans *= 2ll;
            ans %= MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    cout<<0<<endl;
    string s;cin>>s;
    if(s=="Vacant")return 0;
    int r=n,l=0;
    while(r-l>1){
        int mid=(l+r)/2;
        cout<<mid<<endl;
        string t;cin>>t;
        if(t[0]=='V')return 0;
        if(t==s){
            if(mid%2==0)l=mid;
            else r=mid;
        }
        else{
            if(mid%2==0)r=mid;
            else l=mid;
        }
    }
    
}






Measured memory_bytes: 852
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toInt)
    val hList = readLine()!!.split(' ').map(String::toLong)
    val goodArray = BooleanArray(n) { true }
    repeat(m) {
        val (a, b) = readLine()!!.split(' ').map { it.toInt() - 1 }
        if (hList[a] <= hList[b]) goodArray[a] = false
        if (hList[a] >= hList[b]) goodArray[b] = false
    }
    println(goodArray.count { it })
}


Measured memory_bytes: 63596
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N , X;
    cin >> N >> X ;
    vector<int> L(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> L.at(i);
    }
    int D = 0 ;
    int count = 1;
    for (size_t i = 0; i < N; i++)
    {
        D += L.at(i) ;
        if (D <= X)
        {
            count++ ;
            continue ;
        }
        else
        {
            break;
        }
    }
        cout << count << endl;
    
    
}

Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_D

#include <bits/stdc++.h>

using namespace std;

long long MOD = 1e9 + 7;

long long powMod(long long x, long long k, long long m) {
    if (k == 0) return 1;
    if (k % 2 == 0) return (powMod((x * x + m) % m, k / 2, m) + m) % m;
    else return (x * powMod(x, k - 1, m) + m) % m;
}

long long extgcd(long long a, long long b, long long &x, long long &y) {
    long long g = a;
    x = 1;
    y = 0;
    if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
    return g;
}

long long invMod(long long a, long long m) {
    long long x, y;
    if (extgcd(a, m, x, y) == 1) return (x + m) % m;
    else return 0;
}

long long factorial(long long n, long long m) {
    if (n == 0) {
        return 1;
    } else {
        return (n * factorial(n - 1, m) + m) % m;
    }
}

long long binomial(long long n, long long k, long long m) {
    long long tmp = (factorial(n, m) * invMod(factorial(k, m), m) + m) % m;
    return (tmp * invMod(factorial(n - k, m), m) + m) % m;
}

int main() {
    long long n;//ボール
    long long k;//箱
    cin >> n >> k;

    cout << binomial(n + k - 1, k - 1, MOD) << endl;
    return 0;
}

/*
 * ボールは区別しないので，各箱に入るボールの個数のみ考える。
 * a1+a2+...+ak=n
 * をみたす非負整数の組の個数が答え。
 * 空箱があってもいいので，
 * 「ボール（n個）と仕切り（k-1個）を並べる」で処理できる。
 * B(n+k-1,k-1)
 *
 */


Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_set>
#include <numeric>
#include <iterator>
#include <unordered_map>
#include <array>
#include <map>
#include <cstring>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctgmath>
#include <set>
#include <queue>
#include <fstream>
#include <ostream>
#include <list>
#include <string>
using namespace std;

#define MOD 1000000007
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int r, c;
	cin >> r >> c;

	vector<string> mat;
	for (int i = 0; i < r; i++)
	{
		string s;
		cin >> s;
		mat.push_back(s);
	}
	vector<int> temp(c + 1);
	vector<vector<int>> ans(r + 1, temp);

	for (int i = 0; i < r; i++)
	{
		if (mat[i][0] == '#')
		{
			break;
		}
		ans[i][0] = 1;
	}
	for (int i = 0; i < c; i++)
	{
		if (mat[0][i] == '#')
		{
			break;
		}
		ans[0][i] = 1;
	}
	for (int i = 1; i < r; i++)
	{
		for (int j = 1; j < c; j++)
		{
			if (mat[i][j] == '#')
			{
				ans[i][j] = 0;
			}
			else
			{
				ans[i][j] = (ans[i - 1][j] % MOD + ans[i][j - 1] % MOD) % MOD;
			}
		}
	}
	cout << ans[r - 1][c - 1] << "\n";
}


Measured memory_bytes: 5248
n=int(input())
a=list(map(int,input().split()))
a.append(0)


sums = abs(a[0])
flags = [0 for _ in range(n+1)]

for i in range(1,n+1):
    sums += abs(a[i]-a[i-1])

a.insert(0,0)

for i in range(1,len(a)-1):
    print(sums+abs(a[i+1]-a[i-1])-(abs(a[i+1]-a[i])+abs(a[i]-a[i-1])))
    


Measured memory_bytes: 14176