akhauriyash/Code-Regression huggingface dataset:
use std::cmp;
const INF: i64 = 1e16 as i64;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n = sc.read();
    let mut abc: Vec<i64> = sc.vec(3);
    abc.sort();

    let l: Vec<i64> = sc.vec(n);
    let sums = (0..(1 << n))
        .map(|mask| {
            l.iter()
                .enumerate()
                .filter(|&(i, _)| (1 << i) & mask != 0)
                .map(|(_, &l)| l)
                .sum::<i64>()
        })
        .collect::<Vec<_>>();

    let mut ans = INF;
    for mask1 in 1..(1 << n) {
        for mask2 in 1..(1 << n) {
            if mask1 & mask2 != 0 {
                continue;
            }
            for mask3 in 1..(1 << n) {
                if mask1 & mask3 != 0 || mask2 & mask3 != 0 {
                    continue;
                }
                let mut v = vec![sums[mask1], sums[mask2], sums[mask3]];
                let additional_costs =
                    (mask1.count_ones() + mask2.count_ones() + mask3.count_ones() - 3) * 10;
                v.sort();
                let cost = (v[0] - abc[0]).abs() + (v[1] - abc[1]).abs() + (v[2] - abc[2]).abs();
                ans = cmp::min(ans, cost + (additional_costs as i64));
            }
        }
    }
    println!("{}", ans);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;



int main(){
    string S="";
    
    ll temp=1;
    ll N;
    cin >> N;
    if(N==0){
        cout<<0<<endl;
        return 0;
    }
    
    while(N!=0){
        ll a,b;
        if(N<0){
            a=-N;
        }else{
            a=N;
        }
        if(temp<0){
            b=-temp*2;
        }else{
            b=temp*2;
        }
        
        if(a%b != 0){
            S = "1"+S;
            N-=temp;
        }else{
            S = "0"+S;
        }
        //cout<<N<<endl;

        temp*=-2;
        
    }
    
    cout<<S<<endl;
    
    return 0;
}


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

using namespace std;

int n, t;

bool check(int a) {
  return a >= 1 && a <= 9;
}

int main() {
  int n;
  cin >> n;
  bool flag = false;
  for (int i = 1; i <= 9; i++) {
    if (n % i) continue;
    if (check(n / i)) flag = true;
  }
  cout << (flag ? "Yes\n" : "No\n");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> ll size(const T& x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); ++i)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define pb push_back
#define fs first
#define sc second
#define MOD 1000000007
#define MOD2 998244353
#define INF 1000000000000000000ll
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

void solve()
{
    double d, t, s;
    cin >> d >> t >> s;
    if(d / s <= t)
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
}

int main()
{
    cin.sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	/*ll t;
	cin >> t;
	while(t--)*/
		solve();
}


Measured memory_bytes: 3724
package main

import (
	"fmt"
	"unicode"
)

func main() {
	// Code for B - AcCepted
	var S string
	fmt.Scanf("%s", &S)

	var flag1 int = 0
	if S[0] == 'A' {
		flag1++
	}
	var flag2 int = 0
	var number int
	for i := 2; i < len(S)-1; i++ {
		if S[i] == 'C' {
			flag2++
			number = i
		}
	}

	var flag3 int = 0
	for i := 1; i < len(S); i++ {
		if i == number {
			continue
		}
		if !unicode.IsLower(rune(S[i])) {
			flag3++
		}
	}

	if flag1 == 1 && flag2 == 1 && flag3 == 0 {
		fmt.Println("AC")
	} else {
		fmt.Println("WA")
	}
}


Measured memory_bytes: 1836
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//----------------------------------------------------------------

int main(void) {
  string s;
  cin >> s;
  ll tmp=0;
  rep(i,s.size()){
    tmp += s[i]-'0';
  }
  if(tmp%9==0){
    prt("Yes");
  } else {
    prt("No");
  }
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const ll INF = (1LL<<60);
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
ll dp[110][100100];
int main() {
    int N;
    ll W;
    cin >> N >> W;
    ll w[N];
    int v[N];
    rep(i, N) cin >> w[i] >> v[i];
    for(int j=1; j < 100100; ++j) dp[0][j] = INF;
    rep(i, N) rep(j, 100100){
        if(j < v[i]) dp[i+1][j] = dp[i][j];
        else dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]]+w[i]);
    }
    ll ans = 0;
    rep(j, 100100){
        if(dp[N][j] <= W) ans = (ll)j;
    }
    cout << ans << endl;
    return 0;
}

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

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

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

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#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 all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int,int>;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

ll dp[110][100100];

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> w(N);
    vector<ll> v(N);
    rep(i,N) cin >> w[i] >> v[i];
    rep(i,N) {
        rep(j,W+1) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            if (j-w[i]>=0) dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]]+v[i]);
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}














Measured memory_bytes: 79488
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int arr[100005];
vector<int>nodes[100005];
int vis[100005];
int dp[100005];
int ans= 0 ;
int dfs(int n)
    {
        if(vis[n]==0)
        {
            vis[n]=1;
            for(int i=0;i<nodes[n].size();i++)
            {
               dp[n]=max(dp[n],1+dfs(nodes[n][i]));
               ans = max(ans,dp[n]) ;
            }
            return dp[n];
        }
        else
            return dp[n];
    }
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n ,m;
    cin>>m>>n;
    for(int i=0;i<n;i++)
        {
            int a,b;
            cin>>a>>b;
            nodes[a].push_back(b);
        }
    for(int i=1;i<=m;i++)
    dfs(i);
    cout<<ans<<endl;

}













Measured memory_bytes: 11812
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

use std::cmp::*;

fn main() {
    let whxy: Vec<u64> = read_vec();
    let w = whxy[0];
    let h = whxy[1];
    let x = whxy[2];
    let y = whxy[3];

    // どこに(x, y)をとったとしても、分割した2つの部分が等しくなる直線が必ず1つは存在する.
    // x + x == w, y + y == h... xもyもそれぞれ幅高さの半分の値である場合
    println!("{} {}", (w as f64)*(h as f64)/2.0, (x+x==w&&y+y==h) as u32);
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String strArray[] = br.readLine().split(" ");
	int N = Integer.parseInt(strArray[0]);
	int M = Integer.parseInt(strArray[1]);
	int sum = 0;
	for (int i = 1; i < N; i++) {
	    sum += i;
	}
	for (int i = 1; i < M; i++) {
	    sum += i;
	}
	System.out.println(sum);
    }
}

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

int main(){
  int H, W;
  cin >> H >> W;
  
  string board[110];
  for(int i = 0; i< H; i++){
    cin >> board[i];
  }
  
  //出力部分
  for(int i =0; i <W+2; i++){
    cout << '#' ;
    if(i + 1 == W + 2){
      cout << endl;
    }
  }
  for (int i = 0; i < H; i++){
    cout << '#';
    cout << board[i];
    cout << '#' << endl;
  }
  for(int i =0; i <W+2; i++){
    cout << '#' ;
    if(i + 1 == W + 2){
      cout << endl;
    }
  }
  
  
}

Measured memory_bytes: 256
/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
//focus less on how much problem you should solve within a fixed time and focus more on getting the problem solved and
//learning something from it
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define per(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define printx(x) printf("%lld\n",x);
#define printxy(x,y) cout << x << y <<endl;
#define printxyz(x,y,z) cout << x << y << z <<endl;
#define deba(a) cout << #a << a << endl;
#define debab(a,b) cout << #a << a << #b << b << endl;
int main()
{
	fast;
	ll n;
	ll m;
	ll k;
	cin >> n >> m >> k;

	vi a(n);
	for (ll a_i = 0; a_i < n; a_i++) {
		cin >> a[a_i];
	}

	vi b(m);
	for (ll b_i = 0; b_i < m; b_i++) {
		cin >> b[b_i];
	}

	ll sum = 0, count = 0, temp = 0, i = 0, j = 0;

	while (i < n && sum + a[i] <= k) {
		sum += a[i];
		i++;
	}
	count = i;

	while (j < m && i >= 0) {
		sum += b[j];
		j++;
		while (sum > k && i > 0) {
			i--;
			sum -= a[i];
		}
		if (sum <= k && i + j > count)
			count = i + j;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 6292
n = int(input())
s = input()

cnt = 0
for i in range(1000):
    
    t = str(i)
    u = '0'*(3-len(t))+t
    
    j = 0
    p = u[0]
    for x in s:
        if x == p:
            j += 1
            if j == 3:
                cnt += 1
                break
            p = u[j]
            
print(cnt)

Measured memory_bytes: 3188
n,m,x = list(map(int,input().split()))
A = list(map(int,input().split()))

cnt_l = 0
for i in range(x-1,0,-1):
    for j in range(len(A)):
        if i==A[j]:
            cnt_l+=1
cnt_r = 0
for i in range(x+1,n):
    for j in range(len(A)):
        if i==A[j]:
            cnt_r+=1
print(min(cnt_l,cnt_r))

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	long long a[200000+5];
	long long n,min,x,sum;
	while (cin>>n)
	{
		sum=min=0;
		for (int i=0;i<n;i++)
		{
			cin>>a[i];
			min=min+fabs(a[i]);
			sum=sum+a[i];
		}
		x=0;
		for (int i=n-1;i>0;i--)
		{
			x=x+a[i];
			if(fabs(2*x-sum)<min)
			min=fabs(2*x-sum);
		}
		cout<<min<<endl;
	}
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
using namespace std;
typedef long long ll;
const ll INF = 1e15;

struct UnionFind {
  vector<int> data;

  UnionFind(int sz) { data.assign(sz, -1); }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return (false);
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if (data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) { return (-data[find(k)]); }
};

int main() {
  ll n, m;
  cin >> n >> m;
  UnionFind uf(m);
  map<ll, ll> mp;
  REP(i, n) {
    ll k, l;
    cin >> k >> l;
    l--;
    mp[i] = l;
    REP(j, k - 1) {
      ll r;
      cin >> r;
      r--;
      uf.unite(l, r);
    }
  }
  ll t = uf.find(mp[0]);
  for (auto x : mp) {
    if (uf.find(x.second) != t) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 6912
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#include<cassert>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n,k,ans=-1e18,tmp=0,idx=0,cnt=0;
  ll tk;
  cin >> n >> k;
  vector<ll> p(n),c(n);
  for(int i=0;i<n;i++){
    cin >> p[i];
    p[i]--;
  }
  for(int i=0;i<n;i++){
    cin >> c[i];
  }
  tk = k;
  for(int s=0;s<n;s++){
    k = tk;
    tmp = 0;
    idx = s;
    if(k*n <= 1e7){
      while(k>0){
        k--;
        idx = p[idx];
        tmp += c[idx];
        ans = max(tmp,ans);
      }
      continue;
    }
    vector<ll> pre(n,-1);
    vector<ll> score(n,0);
    pre[s] = 0;
    cnt = 0;
    while(k>0){
      k--;
      idx = p[idx];
      tmp += c[idx];
      cnt++;
      ans = max(tmp,ans);
      if(pre[idx] != -1){
        break;
      }
      pre[idx] = cnt;
      score[idx] = tmp;
    }
    if(k!=0){
      ll roop_sc = tmp - score[idx];
      ll roop_need = cnt - pre[idx];
      ll roop_can = k / roop_need;
      roop_can = max(0ll,roop_can-7);
      if(roop_sc >= 0){
        tmp += roop_sc * roop_can;
        k -= roop_can*roop_need;
        ans = max(tmp,ans);
      }else{
        k = min(k,7*n);
      }
      while(k>0){
        k--;
        idx = p[idx];
        tmp += c[idx];
        ans = max(tmp,ans);
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3728
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝
 */
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>m>>k;
    if(n%2==0||k%2==0||m%2==0)
   {
       x++;
   }
   if(x!=0)
   {
       cout<<0<<endl;
   }
   else
   {
       cout<<min(n*m,min(n*k,m*k))
       <<endl;
   }

}


Measured memory_bytes: 3636
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int[] A = in.Int(3);
            Arrays.sort(A);
            int cost = 0;
            for (int i = 1; i < 3; i++) {
                cost += (A[i] - A[i - 1]);
            }
            out.println(cost);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

        public int[] Int(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Int();
            }
            return a;
        }

    }
}



Measured memory_bytes: 21204
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>

using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    ll x,k,d;
    cin >> x >> k >> d;
    ll cur = abs(x);
    ll rem = k;
    ll count = min(cur / d, k);
    cur -= count * d;
    rem -= count;

    if (rem % 2 == 1) {
        cur -= d;
    }
    cout << abs(cur) << endl;
}

Measured memory_bytes: 3144
S = int(input())

cnt = 1
res = 0
mod = 10 ** 9 + 7

MAX = 3000
MOD = 1000000007

fac = [None] * MAX
finv = [None] * MAX
inv = [None] * MAX

def comb_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

def comb(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

comb_init()

while S >= cnt * 3:
    tmp = S - (cnt * 3)
    res += comb(tmp + cnt - 1, cnt - 1)
    res %= MOD
    cnt += 1

print(res)



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

int n;
vector<pair<int, int>> p;

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int a; cin >> a;
    p.emplace_back(a, i);
  }
  sort(p.rbegin(), p.rend());

  // calc
  long ans = 0, L[2], R[2];
  set<int> indices;

  for(int i = 0; i < n; ++i) {
    int idx = p[i].second;
    auto itr = indices.lower_bound(idx);
    auto itrL = itr;
    auto itrR = itr;
    L[0] = L[1] = -1;
    R[0] = R[1] = n;

    // L
    for(int j = 1; j >= 0; --j) {
      if(itrL == indices.begin()) break;
      --itrL;
      L[j] = *itrL;
    }
    // R
    for(int j = 0; j < 2; ++j) {
      if(itrR == indices.end()) break;
      R[j] = *itrR;
      ++itrR;
    }

    long cnt = (idx - L[1]) * (R[1] - R[0]) + (L[1] - L[0]) * (R[0] - idx);
    ans += cnt * p[i].first;

    indices.insert(idx);
  }

  cout << ans;
  return 0;
}

Measured memory_bytes: 5748
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int N, M;
string s1, s2;

int lcs(string x, string y){
	int c[1001][1001];
	N = s1.size();
	M = s2.size();
	int maxl = 0;
	x = ' ' + x;
	y = ' ' + y;
	rep(i, N) c[i][0] = 0;
	rep(i, M) c[0][i] = 0;
	for(int i = 1; i<=N;i++){
		for(int j = 1; j<=M; j++){
			if(x[i] == y[j]){
				c[i][j] = c[i-1][j-1]+1;
			}else{
				c[i][j] = max(c[i][j-1], c[i-1][j]);
			}
			maxl = max(maxl, c[i][j]);
		}
	}
	return maxl;
}

int main(){
	int n;
	cin >> n;
	rep(i, n){
		cin >> s1 >> s2;
		cout << lcs(s1,s2) << endl;
	}
}



Measured memory_bytes: 7056
#include <bits/stdc++.h>
using namespace std;
int MOD = 2019;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int l, r;
  cin >> l >> r;
  r = min(r, l + 2018);

  int res = MOD;
  for (int i = l; i < r; i++) {
    for (int j = i + 1; j < r + 1; j++) {
      int a = i % MOD;
      int b = j % MOD;
      res = min(res, a * b % MOD);
    }
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j]
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
int main(){
    int h,n; cin >> h >> n;
    rep(i,n){
        int a; cin >> a;
        h-=a;
    }
    if(h<=0) cout << "Yes" << endl;
    else cout << "No" << endl;
}



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

using namespace std;
using ll = long long;

int main() {
  ll h;
  cin >> h;
  int cnt = 0;
  while (h) {
    h /= 2;
    cnt++;
  }
  ll ans = 1;
  rep(i, cnt) ans *= 2;
  cout << ans - 1 << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define eps 1e-9
#define MOD1 998244353
#define MOD2 1000000007
#define INV_10 299473306
#define INF 1000000001
#define PI 3.14159265358979323846
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a+n);
	int r=n-2;
	long long sum=a[n-1];
	for(int i = n-2; i >= 0 && r; i--)
	{
		sum+=(min(r, 2)*a[i]);
		r-=min(r, 2);
	}
	cout << sum << '\n';
}

Measured memory_bytes: 4440
S = input()

start1count = 0
start0count = 0

nextisblack = False

for tile in S:
    if nextisblack:
        nextisblack = False
        if tile == "1":
            start1count += 1
    else:
        nextisblack = True
        if tile == "0":
            start1count += 1

nextisblack = True

for tile in S:
    if nextisblack:
        nextisblack = False
        if tile == "1":
            start0count += 1
    else:
        nextisblack = True
        if tile == "0":
            start0count += 1

print(min(start1count,start0count))

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
string S;

int main()
{
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5])
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

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

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

const ll INF = (ll)1e11;

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    
    vector<int> h;
    for (int i = 0, x; i < n; ++i) {
        cin >> x;
        h.push_back(x);
    }

    int minh = 0, ans = 0;
    for (int i = 0; i < n; ++i) {
        if (minh <= h[i]) {
            ++ans;
            minh = h[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

var (
	rdr   = bufio.NewReaderSize(os.Stdin, 1000000)
	reply string
)

type point [][]int

func (p point) Len() int {
	return len(p)
}

func (p point) Less(a, b int) bool {
	return p[a][1] < p[b][1]
}

func (p point) Swap(a, b int) {
	p[a], p[b] = p[b], p[a]
}

func main() {
	var n, x, l int
	fmt.Scan(&n)
	ls := []string{strconv.Itoa(n)}
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &l)
		ls = append(ls, strconv.Itoa(x), strconv.Itoa(l))
	}
	solve(ls)
}

func solve(buf []string) {
	n, _ := strconv.Atoi(buf[0])
	ls := make(point, n)
	for i, j := 1, 0; i < n*2; i += 2 {
		x, _ := strconv.Atoi(buf[i])
		l, _ := strconv.Atoi(buf[i+1])
		ls[j] = []int{x - l, x + l}
		j++
	}
	sort.Sort(ls)
	var cnt int
	tmp := int(-1e9)
	for i := range ls {
		l, r := ls[i][0], ls[i][1]
		if l >= tmp {
			cnt++
			tmp = r
		}
	}
	reply = strconv.Itoa(cnt)
	fmt.Println(reply)
}

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func nextSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func scanSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func scanFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

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

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}

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

func yesOrNo(b bool) {
	if b {
		reply = "Yes"
		fmt.Println(reply)
		return
	}
	reply = "No"
	fmt.Println(reply)
}

func yesorNO(b bool) {
	if b {
		reply = "Yes"
		fmt.Println(reply)
		return
	}
	reply = "No"
	fmt.Println(reply)
}

Measured memory_bytes: 19456
import math
x1, y1, x2, y2 = [int(i) for i in input().split()]
n = int(input())

xy = [[x1, y1, 0]]
for _ in range(n):
    xy.append([int(i) for i in input().split()])
xy.append([x2, y2, 0])


def dif(x, y):
    return max(0, math.sqrt((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) - x[2] - y[2])




q = set([i for i in range(n + 2)])
mi = [10 ** 16] * (n + 2)
mi[0] = 0

while q:
    u = -1
    mm = 10**16
    for i in q:
        if mm > mi[i]:
            mm = mi[i]
            u = i
    
    q.remove(u)
    for i in q:
        mi[i] = min(mi[i], mi[u] + dif(xy[i], xy[u]))

print(mi[-1])


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

using namespace std;
using ll = long long;

bool res = true;
int n, k, c;

vector<int> f(string s) {
    vector<int> ret;
    for(int i = 0; i < n; i++) {
        while(s[i] == 'x' && i < n)i++;
        if(s[i] == 'o')ret.push_back(i);
        for(int j = 0; j < c; j++)i++;
    }
    if((int)ret.size() > k)res = false;
    return ret;
}


int main()
{
    cin >> n >> k >> c;
    string s; cin >> s;

    vector<int> fr = f(s);
    if(!res)return 0;
    reverse(s.begin(), s.end());
    vector<int> bc = f(s);
    {
        int m = bc.size();
        for(int i = 0; i < m; i++) {
            bc[i] = n - bc[i] - 1;
        }
    }

    sort(bc.begin(), bc.end());
    
    for(auto i : bc) {
        if(binary_search(fr.begin(), fr.end(), i)) {
            cout << i + 1 << endl;
        }
    }

}

Measured memory_bytes: 5896
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
// #define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
//#define mod 998244353
#define inf 1000000000
#define pr1(a) cout << a << "\n"
#define pr2(a,b)cout << a <<  " " <<b<< "\n"
#define pr3(a,b,c) cout << a <<" " << b << " " << c << "\n"

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

int gcd(int a, int b){
    if(b==0)return a;
    gcd(b,a%b);
}
const int maxn = 2*1e5 + 10;
void solve(){

   int a,b,c;
   cin >> a >> b >> c;
   pr3(c,a,b);

} 

int main() 
{   
    IOS;
    int t = 1;
    // cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 256
N,K= map(int,input().split())
D = list(map(int,input().split()))
from itertools import accumulate
acc = [0]+list(accumulate(D, lambda x,y:x+y))
mx = 0
for k in range(min(K+1, N+1)): # k 回とる
    rest = K-k # rest回まで捨てることができる
    for l in range(min(k+1, N+1)): # 左から何個とるか
        r = k-l
        left = acc[l]
        right = acc[N]-acc[N-r]
        tmp = left+right
        tmpl = D[:l]
        tmpr = D[N-r:N]
        minus = sorted([i for i in tmpl+tmpr if i < 0])
        tmp -= sum(minus[:rest])
        mx = max(mx, tmp)
if K > N:
    tmp = acc[-1]
    rest = K - N
    minus = sorted([i for i in D if i < 0])
    tmp -= sum(minus[:rest])
    mx = max(mx, tmp)
print(mx)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
using namespace std;
const int e = 3009;

int t[e][e];
vector<char>v;

int A(int a, int b)
{
    int c = a-b;
    if(c < 0)return -c;
    return c;
}

int main()
{
    string a,b;
    cin >> a >> b;
    a = '#' + a;
    b = '#' + b;
    for(int i = 1; i < a.size(); i++) for(int j = 1; j < b.size(); j++)
    {
        if(a[i] == b[j]) t[i][j] = t[i-1][j-1]+1;
        else t[i][j] = max(t[i-1][j], t[i][j-1]);
    }
    int ai = a.size()-1;
    int bi = b.size()-1;
    //cout << t[ai][bi];
    while(ai>0 && bi>0)
    {
        if(t[ai][bi] == t[ai-1][bi-1]+1 && a[ai] == b[bi])
        {
            v.push_back(a[ai]);
            ai--;
            bi--;
        }
        else if(t[ai][bi] == t[ai][bi-1])bi--;
        else if(t[ai][bi] == t[ai-1][bi])ai--;


    }
    for(int i = v.size()-1; i >= 0; i--)cout << v[i];
    return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

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

    priority_queue<P> q;
    for(int i = 0; i < n; i++) {
        int card;
        cin >> card;
        q.push(P(card, 1));
    }
    for(int i = 0; i < m; i++) {
        int card, num;
        cin >> num >> card;
        q.push(P(card, num));
    }

    long long ans = 0;
    int count = n;
    while(count > 0) {
        P p = q.top(); q.pop();
        ans += 1LL * p.first * min(count, p.second);
        count -= min(count, p.second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2420
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        HashSet<Integer> bad = new HashSet<>();
        for (int i = 0; i < M; i++) {
            bad.add(scan.nextInt());
        }
        long[] dp = new long[N+1];
        dp[0] = 1;
        for (int i = 1; i <= N; i++) {
            if (bad.contains(i)) {
                dp[i] = 0;
                continue;
            }
            if (2 <= i) {
                dp[i] = dp[i - 2] + dp[i - 1];
            } else if (i == 1) {
                dp[i] = dp[i - 1];
            }
            dp[i] = dp[i] % 1000000007;
        }
        long answer = dp[N];
        System.out.println(answer);
    }
}


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



int main() {
  ll K,A,B;
  cin>>K>>A>>B;
  if(A%K==0||B/K>A/K)
  {
    cout<<"OK"<<endl;
  }
  else
  {
    cout<<"NG"<<endl;
  }  
  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main(void)
{
    int a,b,result;

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

    result=b-a;

    if(result>0){
        printf("a < b\n");
    }else if(result<0){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }

    return 0;
}

Measured memory_bytes: 580
n,q = map(int,input().split())
s = input()
l = []
r = []
for i in range(q):
    li,ri = map(int,input().split())
    l.append(li)
    r.append(ri)
  
al = [0]*n
for i in range(1,n):
    if s[i-1] == "A" and s[i] == "C":
        al[i] = al[i-1] + 1
    else:
        al[i] = al[i-1]
        
for j in range(q):
    left = l[j]-1
    right = r[j]-1
    print(al[right]-al[left])

Measured memory_bytes: 65316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   int a,b; cin>>a>>b;
   cout << (a>8||b>8?":(":"Yay!") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
#define yn(x) puts((x ? "Yes" : "No"))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;

vector<pii> sai;
vector<int> saic;
vi A;

void input() {
  ;
  cin>>N;
  A.resize(N);
  rep(i,0,N-1){
    cin>>A[i];
    sai.emplace_back(A[i]-i,i);
    saic.emplace_back(A[i]-i);
  }
  ;
}
void solve() {
  sort(all(sai));
  sort(all(saic));
  int ans = 0;
  rep(i,0,N-1){
    auto be = upper_bound(all(saic),-i-A[i]);
    auto en = lower_bound(all(saic),-i-A[i]);
    ans += be-en;
  }
  cout<<ans<<endl;
  ;
  ;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 11688
import itertools 

def main():
    N = int(input())
    P = [int(i) for i in input().split()]
    Q = [int(i) for i in input().split()]
    P = tuple(P)
    Q = tuple(Q)

    num = [i for i in range(1,N+1)]
    num_ = list(itertools.permutations(num, N))
    
    a = num_.index(P)
    b = num_.index(Q)

    print(abs(a - b))


if __name__ == "__main__":
    main()


Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define pll pair<ll,ll>
#define pii pair<int,int>
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int maxn = 5e5 + 5;
const int mod = 1e9+7;
ll pre[maxn];
ll inv[maxn];
ll prei[maxn];
void build(int n){
    pre[1] = pre[0] = 1, inv[1] = inv[0] = 1, prei[1] = prei[0] = 1;
    for(int i = 2 ; i <= n ; i++){
        pre[i] = pre[i-1] * i % mod;
        inv[i] = (mod - mod / i * inv[mod % i] % mod) % mod;
        prei[i] = prei[i-1] * inv[i] % mod;
    }
}
ll C(int n, int k){
   return pre[n] * prei[k] % mod * prei[n-k] % mod;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    vector<ll>v;
    int n;
    cin >> n;
    build(n);
    f(n) {
        int x;
        cin >> x;
        v.pb(x);
    }
    ll ans = 0;
    ll mul = 0;
    f1(n-1) {
        mul += pre[n-1] * inv[i] % mod;
        ans += mul * (v[i] - v[i-1]) % mod;
        ans %= mod; 
    }
    cout << ans << '\n';
}

Measured memory_bytes: 10360
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

N,M = map(int, input().split())

# 複数個の数値を、intの配列として取得
A = list(map(int, input().split()))
A = list(map(lambda x: x * (-1),A))

heapq.heapify(A)
for i in range(M):
    x = heapq.heappop(A)
    heapq.heappush(A,x/2)

ans=0
for a in A:
    ans+=math.floor(-a)

print(ans)

Measured memory_bytes: 15148
#AGC 013 A - Sorted Arrays
#増加⇔減少に転じる際、Ai+1 - Aiは必ず符号反転することを利用
N = int(input())
A = list(map(int,input().split()))

count = 1
sign = 0
for i in range(N-1):
    if sign == 0:
        sign = A[i+1]-A[i]
    elif sign*(A[i+1]-A[i]) < 0:
        count += 1
        sign = 0
print(count)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
int main () {
  int n;
  cin >> n;
  vector<float> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  float ans = v[0];
  for (int i = 1; i < n; i++) ans = (ans + v[i]) / (float)2;
  printf("%f\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < (n); i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 200005;
int n, a[MX], b[MX];
ll res;
queue<int> q;

bool valid (int i) {
	return b[i] > a[i] && b[i] > b[(i - 1 + n) % n] + b[(i + 1) % n];
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	forn (i, n) cin >> a[i];
	forn (i, n) cin >> b[i];
	forn (i, n) if (valid(i)) q.push(i);

	while (q.size()) {
		int i = q.front(); q.pop();
		int x = (i - 1 + n) % n;
		int y = (i + 1) % n;

		int d = max(1, (b[i] - a[i]) / (b[x] + b[y]));
		res += d;
		b[i] -= d * (b[x] + b[y]);

		if (valid(i)) q.push(i);
		if (valid(x)) q.push(x);
		if (valid(y)) q.push(y);
	}

	forn (i, n) if (a[i] != b[i]) {
		cout << -1 << endl;
		return 0;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 2304
package main

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

func isqrt(n int) int {
	ok := 0
	ng := 3037000500
	for ng-ok > 1 {
		m := ok + (ng-ok)/2
		if m*m <= n {
			ok = m
		} else {
			ng = m
		}
	}
	return ok
}

func makeDivisorList(n int) []int {
	result := make([]int, 0)
	for i := 1; i <= isqrt(n); i++ {
		if n%i == 0 {
			result = append(result, i)
			result = append(result, n/i)
		}
	}
	return result
}

func calcMinOps(r []int, d int) int {
	i, j := 0, len(r)
	for i < j && r[i] == 0 {
		i++
	}
	i--
	a, b := 0, 0
	for j-i != 1 {
		if a <= b {
			i++
			a += r[i]
		} else {
			j--
			b += d - r[j]
		}
	}
	return a
}

func main() {
	defer flush()

	N := readInt()
	K := readInt()

	A := make([]int, N)
	c := 0
	for i := 0; i < N; i++ {
		A[i] = readInt()
		c += A[i]
	}
	r := make([]int, N)

	divisors := makeDivisorList(c)
	sort.Sort(sort.Reverse(sort.IntSlice(divisors)))
	for i := 0; i < len(divisors); i++ {
		d := divisors[i]
		for j := 0; j < N; j++ {
			r[j] = A[j] % d
		}
		sort.Ints(r)
		if calcMinOps(r, d) <= K {
			println(d)
			break
		}
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 2012
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << #x << ": " << x << '\n';
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  bool ans = false;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      if (n == i*j) {
        ans = true;
        break;
      }
    }
    if (ans) break;
  }
  if (ans) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))

import math


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

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

   return arr


def main():
    n = input_int()

    ans = 0
    if n < 1:
        print(ans)
        return
    a = factorization(n)
    for _, i in a:
        j = 1
        while i >= j:
            ans += 1
            i -= j
            j += 1

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9532
n, k = map(int, input().split())
a = list(map(int, input().split()))
count = 0
ct = 0
l = [0] * n
l[0] = 1
time =[0] * n

while l[ct] <= 1:
    time[ct] = count
    ct = a[ct] - 1
    count += 1
    l[ct] += 1
    if count == k:
        print(ct+1)
        exit()
        
roop = count - time[ct]
r = (k - count) % roop
for i in range(r):
    ct = a[ct] - 1
print(ct + 1)

Measured memory_bytes: 92800