akhauriyash/Code-Regression huggingface dataset:
package main

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

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
)

func main() {
	scanner.Split(bufio.ScanWords)
	n := scanInt()
	p, q := scanInts(n), scanInts(n)
	a1, a2 := cal(n, p), cal(n, q)
	fmt.Println(abs(a1 - a2))
}

func cal(n int, p []int) int {

	ret := 1
	for i := 0; i < n; i++ {
		f := fact(n - 1 - i)
		for j := (i + 1); j < n; j++ {
			if p[i] > p[j] {
				ret += f
			}
		}
	}

	return ret
}

func fact(n int) int {
	ret := 1
	for i := 1; i <= n; i++ {
		ret *= i
	}
	return ret
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanText(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func scanTexts(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanText()
	}
	return s
}

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

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}

// greatest common divisor(最大公約数)
func gcd(a, b int) int {
	for {
		mod := a % b
		if mod == 0 {
			return b
		}
		a, b = b, mod
	}
}

// latest common multiple(最小公倍数)
func lcm(a, b int) int {
	return (a / gcd(a, b)) * b
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define BACK 6
typedef pair<pair<int,int>, pair<int,int>> PP;

int dp[(1<<(BACK*2))+10][60][60][4];

int main(){
  int h,w,k;
  cin>>h>>w>>k;

  vector<string> vec(h+BACK);
  rep(i,BACK){
    vec[i].resize(w);
    vec[i][0] = '.';
    repl(j,1,w) vec[i][j] = '#';
  }
  rep(i,h) cin>> vec[i+BACK];

  h += BACK;

  fill(dp[0][0][0], dp[1<<(BACK*2)][0][0], -INF);
  dp[0][BACK][0][0] = 0;
  queue<PP> q; // prevs, h, w, k
  q.push(mp(mp(0,BACK), mp(0,0)));

  const int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
  while(!q.empty()){
    PP pp = q.front(); q.pop();
    int prevs = pp.fi.fi;
    int x = pp.fi.se, y = pp.se.fi, kk = pp.se.se;
//dbg(mp(mp(x,y),dp[prevs][x][y][kk]));
    bool visited[4] = {0,0,0,0};
    int px=0, py=0;
    rep(i,BACK){
      int m = (prevs>>(2*i))%4;
      px -= dx[m], py -= dy[m];
      if(px*px + py*py == 1){
        rep(j,4) if(px==dx[j] && py==dy[j]){
          visited[j] = true;
          break;
        }
      }
    }

    rep(i,4){
      int nx = x + dx[i], ny = y + dy[i], nk = kk + (i>=2);
      if(nk>k) continue;
      if(nx<0 || ny<0 || nx>=h || ny>=w || vec[nx][ny]=='#') continue;
//      dbg(mp(nx,ny));
      int ncost = dp[prevs][x][y][kk];
      if(vec[nx][ny]!='.' && !visited[i]) ncost += vec[nx][ny] - '0';
      int nmask = prevs%(1<<(2*(BACK-1)));
      nmask = nmask*4 + i;
      if(dp[nmask][nx][ny][nk] >= ncost) continue;
      dp[nmask][nx][ny][nk] = ncost;
      q.push(mp(mp(nmask,nx), mp(ny,nk)));
    }
  }

  int res = 0;
  rep(i,1<<(BACK*2)) res = max(res, dp[i][h-1][w-1][k]);

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 240232
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[n];
  rep(i,n) cin>>a[i];
  int nowmx=a[0];
  int ans=0;
  rep(i,n){
    nowmx=max(nowmx,a[i]);
    ans+=nowmx-a[i];
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 5172
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, h, m int
	fmt.Scan(&a, &b, &h, &m)

	sa := float64(h*60+m) / 360.0 * math.Pi
	sb := float64(m) / 30.0 * math.Pi
	var diff float64
	if sa >= sb {
		diff = sa - sb
	} else {
		diff = sb - sa
	}
	ans := float64(a*a+b*b) - 2.0*float64(a*b)*math.Cos(diff)
	ans = math.Sqrt(ans)
	fmt.Printf("%.20f\n", ans)
}


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

int main (){
   long N ;
  cin >> N ;
 
  vector<long>a(N*3);
  for(long i=0;i<N*3;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  
  long sum =0;
  for(long i=N;i<N*3;i+=2){
    sum += a[i];
  }
 
  cout << sum << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    int D[C][C];
    for(int i=0; i<C; i++){
        for(int j=0; j<C; j++){
            cin >> D[i][j];
        }
    }

    int c[N][N];
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            cin >> c[i][j];
            c[i][j]--;
        }
    }

    int b[3][C];
    for(int i=0; i<3; i++){
        for(int j=0; j<C; j++){
            b[i][j] = 0;
        }
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            int m = (i+j)%3;
            b[m][c[i][j]]++;
        }
    }

    int ans = 1000000005;
    for(int c0=0; c0<C; c0++){
        for(int c1=0; c1<C; c1++){
            for(int c2=0; c2<C; c2++){
                if(c0==c1 || c1==c2 || c0==c2) continue;

                int lc[3];
                lc[0] = c0;
                lc[1] = c1;
                lc[2] = c2;

                int t = 0;
                for(int i=0; i<3; i++){
                    for(int j=0; j<C; j++){
                        t += b[i][j]*D[j][lc[i]];
                    }
                }
                ans = min(ans, t);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4516
import java.util.Scanner;

public class Main {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		int H = sc.nextInt();
		int W = sc.nextInt();
		
		while (H != 0 && W != 0) {
			display(H, W);
			H = sc.nextInt();
			W = sc.nextInt();
		}
	}

	private static void display(int h, int w) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (j == 0 || j == (w - 1)) {
					System.out.print("#");
				} else {
					if (i == 0 || i == (h - 1)) {
						System.out.print("#");
					} else {
						System.out.print(".");
					}
				}
			}
			System.out.println();
		}
		System.out.println();
	}

}

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

int main() {
    string s;
    cin >> s;
    int a[4];
    rep(i, 4) a[i] = s[i] - '0';

    for (int bit = 0; bit < (1 << 3); bit++) {
        vector<char> ops(3, '+');
        int sum = a[0];

        rep(i, 3) {
            if (bit & (1 << i)) {
                ops[i] = '-';
                sum -= a[i + 1];
            } else
                sum += a[i + 1];
        }

        if (sum == 7) {
            rep(i, 3) cout << a[i] << ops[i];
            cout << a[3] << "=7" << endl;
            return 0;
        }
    }

    return 0;
}


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

using namespace std;
using ll = long long;

int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  ll D[5] = {0};
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    if (s[0] == 'M') D[0]++;
    if (s[0] == 'A') D[1]++;
    if (s[0] == 'R') D[2]++;
    if (s[0] == 'C') D[3]++;
    if (s[0] == 'H') D[4]++;
  }
  ll res = 0;
  for (int i = 0; i < 10; i++)
    res += D[P[i]] * D[Q[i]] * D[R[i]];
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
#define BIGP   1000000007
#define INF_I  std::numeric_limits<ll>::max()
#define INF_F  std::numeric_limits<float>::infinity()
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll N, W;
    cin >> N >> W;
    vector<pair<ll, ll>> ps;
    rep(i, N)
    {
        ll w, v;
        cin >> w >> v;
        ps.push_back({ w,v });
    }
    vector<vector<ll>> dp;
    dp.resize(N+1);
    rep(i, N+1)
    {
        dp[i].resize(100100, 0);
    }
    for (ll item = 0; item < N; ++item)
    {
        auto p = ps[item];
        ll w = std::get<0>(p);
        ll v = std::get<1>(p);
        for (ll wi = 0; wi <= W; ++wi)
        {
            chmax(dp[item + 1][wi], dp[item][wi]);
            if (wi + w <= W)
            {
                chmax(dp[item + 1][wi + w], dp[item][wi] + v);
            }
        }
    }
    ll h = dp[N][W];
    cout << h;
    //
    return 0;
}

Measured memory_bytes: 82004
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define input freopen("input.txt", "r", stdin);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);



#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int mx=0, cnt=0;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='R') cnt++;
        else cnt=0;
        mx = max(mx, cnt);
    }
    cout<<mx<<endl;
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d >> s;
  a--;
  b--;
  c--;
  d--;
  bool canGo = true;
  bool previousIsIwa = false;
  int cnt = 0;
  bool canChange = false;
  rep(i, n) {
    // 岩が並んでいたら駄目
    if (i > a && i < d) {
      if (s[i] == '#') {
        if (previousIsIwa) {
          canGo = false;
        }
        previousIsIwa = true;
      } else {
        previousIsIwa = false;
      }
    }
    // すぬけ君とふぬけ君の順番変われるか
    // c > d の場合のみ考慮
    if (i >= b - 1 && i <= d + 1) {
      if (s[i] == '.') {
        if (cnt >= 2) {
          canChange = true;
        }
        cnt++;
      } else {
        cnt = 0;
      }
    }
  }
  bool ok = canGo;
  if (c > d) {
    ok = ok && canChange;
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3728
#[allow(dead_code)]
fn main() {
    let (h1, m1, h2, m2, k) = i::u5();
    let s1 = h1 * 60 + m1;
    let s2 = h2 * 60 + m2;
    println!("{}", s2 - s1 - k);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
    pub fn str() -> String {
        read()
    }
    pub fn s() -> Vec<char> {
        str().chars().collect()
    }
    pub fn i() -> i64 {
        read()
    }
    pub fn u() -> usize {
        read()
    }
    pub fn u2() -> (usize, usize) {
        (read(), read())
    }
    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }
    pub fn u4() -> (usize, usize, usize, usize) {
        (read(), read(), read(), read())
    }
    pub fn u5() -> (usize, usize, usize, usize, usize) {
        (read(), read(), read(), read(), read())
    }
    pub fn u6() -> (usize, usize, usize, usize, usize, usize) {
        (read(), read(), read(), read(), read(), read())
    }
    pub fn f() -> f64 {
        read()
    }
    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }
    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }
    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }
    pub fn iv3(n: usize) -> Vec<(i64, i64, i64)> {
        (0..n).map(|_| iv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }
    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }
    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }
    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }
    pub fn uv4(n: usize) -> Vec<(usize, usize, usize, usize)> {
        (0..n)
            .map(|_| uv(4))
            .map(|a| (a[0], a[1], a[2], a[3]))
            .collect()
    }
    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }
    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 2108
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
const long long int INF = (long long int)1e15 + 1;
int main() {
    int N;
    cin >> N;
    vector<vector<long long int> > D(N, vector<long long int>(N, 0));
    for (int i = 0; i < N; i ++) {
        for (int j = 0; j < N; j ++) {
            cin >> D[i][j];
        }
    }
    bool yabai = false;
    for (int i = 0; i < N; i ++) {
        for (int j = 0; j < N; j ++) {
            if (i == j && D[i][j] != 0) {
                yabai = true;
                break;
            }
            long long int mi = INF;
            for (int k = 0; k < N; k ++) {
                mi = min(mi, D[i][k] + D[k][j]);
            }
            if (mi != D[i][j]) {
                yabai = true;
                break;
            }
        }
        if (yabai) break;
    }
    if (yabai) {
        cout << "-1" << endl;
        return 0;
    }
    long long int ans = 0;
    for (int i = 0; i < N; i ++) {
        for (int j = i + 1; j < N; j ++) {
            ans += D[i][j];
            for (int k = 0; k < N; k ++) {
                if (i == k || j == k) continue;
                if (D[i][k] + D[k][j] == D[i][j]) {
                    ans -= D[i][j];
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
int x[55];
int y[55];
signed main(){
    
    int n;
    cin >> n;
    rep(i,n)cin >> x[i] >> y[i];
    map<pair<int,int>,int> s;
    for(int i = 0;i<n;i++){
        for(int j = i+1;j<n;j++){
            pair<int,int> p1 = MP(x[i]-x[j],y[i]-y[j]);
            pair<int,int> p2 = MP(x[j]-x[i],y[j]-y[i]);
            s[p1]++;
            s[p2]++;
        }
    }
    int m = 0;
    for(auto x:s){ 
        m = max(m,x.se);
    }
    cout << n - m << endl;


    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://diverta2019-2.contest.atcoder.jp/tasks/diverta2019_2_b

Measured memory_bytes: 384
#include "bits/stdc++.h"
#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 RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n";
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
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;}

int n,ma,mb;
const int maxl = 401;
const int INF = INT_MAX/2;
int dp[maxl][maxl];
P path[maxl][maxl];

int main(){
    cin >> n >> ma >> mb;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    
    REP(i,n){
        cin >> a[i] >> b[i] >> c[i];
    }
    REP(i,maxl){
        REP(j,maxl){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    
    REP(i,n){
        RREP(j,maxl){
            RREP(k,maxl){
                if(dp[j][k]!=INF&&j+a[i]<maxl&&k+b[i]<maxl){
                    if(chmin(dp[j+a[i]][k+b[i]],dp[j][k]+c[i])){
                        path[j+a[i]][k+b[i]]=make_pair(j,k);
                    }
                }
            }
        }
    }
    int res = INF;
    int maxi = -1;
    for(int i=1;(i*ma<maxl&&i*mb<=maxl);i++){
        if(dp[i*ma][i*mb]!=INF){
            if(chmin(res,dp[i*ma][i*mb])){
                maxi=i;
            }
        }
    }
    if(res!=INF){
        int x=maxi*ma,y=maxi*mb;
        vector<P> pathv;
        pathv.push_back(path[x][y]);
        x = pathv.back().first;
        y = pathv.back().second;
        while(x>0&&y>0){
            pathv.push_back(path[x][y]);
            x = pathv.back().first;
            y = pathv.back().second;
            
        }
        put(res);
    }else{
        put(-1);
    }
    return 0;
}


Measured memory_bytes: 1664
n,x=map(int,input().split())
len_l=[0]*(n+1)
len_l[0]=1
num_p=[0]*(n+1)
num_p[0]=1
for i in range(n):
    len_l[i+1]=3+2*len_l[i]
    num_p[i+1]=2*num_p[i]+1
def calc(a,b):
    if a==0:
        return 1
    if b<=0:
        return 0
    else:
        nagasa=len_l[a]
        if b==1:
            return 0
        elif b<=len_l[a-1]+1:
            return calc(a-1,b-1)
        elif b==len_l[a-1]+2:
            return num_p[a-1]+1
        elif b<=2*len_l[a-1]+2:
            return num_p[a-1]+1+calc(a-1, b-(len_l[a-1]+2))
        elif b==2*len_l[a-1]+3:
            return 2*num_p[a-1]+1
        else:
            print('okasi')
            return None
print(calc(n,x))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;
int main(){
  int n, m;cin>>n>>m;
  vector<int> x(m);
  for(auto &e: x)cin>>e;
  sort(x.begin(), x.end());
  if(m-n<=0){cout<<0<<endl;return 0;}
  else{
    vector<int> diff(m-1);
  	for(int i=0;i<m-1;i++){
      diff[i]=x[i+1]-x[i];
    }
    sort(diff.begin(), diff.end(), greater<int>());
    int ans=x[m-1]-x[0];
    for(int i=0;i<n-1;i++){
      ans -= diff[i];
    }
    cout<<ans<<endl;
  }
}

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

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

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

const int N = 55;
int sx[N],sy[N],px[N],py[N];
int main() {
	ios_base::sync_with_stdio(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,m;
	cin >> n >> m;
	forn(i,n){
		cin >> sx[i] >> sy[i];
	}
	forn(i,m){
		cin >> px[i] >> py[i];
	}
	
	for(int i = 0; i < n; i++){
		int ans = INF;
		int index = 0;
		for(int j = 0; j < m; j++){
			int dis = abs(sx[i] - px[j]) + abs(sy[i] - py[j]);
			if (dis < ans){
				ans = dis;
				index = j + 1;
			}
		}
		cout << index << endl;
	}
  	return 0;
}


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


int signs[][3] = {{1, 1, 1}, {1, 1, -1}, {1, -1, 1}, {1, -1, -1}, {-1, 1, 1}, {-1, 1, -1}, {-1, -1, 1}, {-1, -1, -1}};

long long solve(long long N, long long M, vector<long long> x, vector<long long> y, vector<long long> z){
    long long ans = 0;
    for (int k = 0; k < 8; k++) {
        int *sign = signs[k];

        vector<long long> tmp;
        for (long long i = 0; i < N; i++) {
            long long val = sign[0] * x[i] + sign[1] * y[i] + sign[2] * z[i];
            tmp.push_back(val);
        }
        sort(tmp.rbegin(), tmp.rend());

        long long anss = 0;
        for (int j = 0; j < M; j++) { anss += tmp[j]; }
        ans = max(ans, anss);
    }
    return ans;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    vector<long long> x(N);
    vector<long long> y(N);
    vector<long long> z(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
        scanf("%lld",&z[i]);
    }
    cout << solve(N, M, x, y, z) << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)
	n, a, b := nextInt(), nextInt(), nextInt()
	monsters := make([]int, n)
	for i := range monsters {
		monsters[i] = nextInt()
	}
	sort.Sort(sort.Reverse(sort.IntSlice(monsters)))

	max := 1000000000
	min := 1

	for max > min {
		tester := (max + min) / 2
		require := 0
		for _, m := range monsters {
			if m > b*tester {
				require += ((m - (b * tester) - 1) / (a - b)) + 1
			}
		}
		switch {
		case tester < require:
			min = tester + 1
		case tester >= require:
			max = tester
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int ans, n,k,x,y;
   cin>>n>>k>>x>>y;
   if(n>k)
   {
       n=n-k;
       ans=(k*x)+(n*y);
   }
   else ans=(x*n);
   cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 3580
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<bits/stdc++.h>
using namespace std;
string s;
int ans,totg,totp;//totg>=totp
int main(){
	cin>>s;
	if(s[0]=='p') ans++;
	totg++;
	for(int i=1;i<s.size();i++)
	  if(totg<=totp)
	  	if(s[i]=='p') ans--,totg++;
	  	else totg++;
	  else
	    if(s[i]=='p') totp++;
	    else ans++,totp++;
	cout<<ans;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b&&b<c)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
using System;

namespace AtCoder_Beginner_Contest_168
{
    class Program
    {
        static void Main(string[] args)
        {
            int number = int.Parse(Console.ReadLine());

            switch (number % 10)
            {
                case 2:
                case 4:
                case 5:
                case 7:
                case 9:
                    Console.WriteLine("hon");
                    break;
                case 0:
                case 1:
                case 6:
                case 8:
                    Console.WriteLine("pon");
                    break;
                case 3:
                    Console.WriteLine("bon");
                    break;
                default:
                    break;
            }
        }
    }
}


Measured memory_bytes: 17524
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl s(n + 1, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    s[i + 1] = s[i] + a;
  }
  ll ans = 0;
  map<ll, ll> mp;
  rep(i, n + 1) {
    ans += mp[s[i]];
    mp[s[i]]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 17032
#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() {
  int a;
  string s;
  cin >> a >> s;
  if (a >= 3200) cout << s << endl;
  else cout << "red" << endl;
}


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


int main(){
    int R;
    double cir;
    cin >> R;
    cir = 2*R*M_PI;
    printf("%.20f\n", cir);
}

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

typedef long long ll;
typedef pair<ll,ll> P;

#define fr first
#define sc second

const ll INF=1000000000000000000;

int main(){
	static ll n;
	static ll a[200010];
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	
	static ll sum[200010];
	sum[0]=0;
	for(int i=1;i<=n;i++){
		sum[i]=sum[i-1]+a[i];
	}
	
	ll ret=INF;
	int l=0,r=2;
	for(int i=2;i<=n-2;i++){
		while(min(sum[i]-sum[l],sum[l])<=min(sum[i]-sum[l+1],sum[l+1]))l++;
		while(min(sum[n]-sum[r],sum[r]-sum[i])<=min(sum[n]-sum[r+1],sum[r+1]-sum[i]))r++;
		ll MAX=max(max(sum[n]-sum[r],sum[r]-sum[i]),max(sum[i]-sum[l],sum[l]));
		ll MIN=min(min(sum[n]-sum[r],sum[r]-sum[i]),min(sum[i]-sum[l],sum[l]));
		ret=min(ret,MAX-MIN);
	}
	cout<<ret<<endl;
}



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

int main(){
    int n;
    while(cin>>n,n){
        vector<string> S(n);
        int depth = 0;
        for(int i=0;i<n;i++){
            cin>>S[i];
            int len=0;
            for(auto c:S[i]){
                if(c!='.') break;
                len++;
            }
            for(int j=0;j<len-1;j++){
                S[i][j]=' ';
            }
            if(len)S[i][len-1]='+';
            if(len<depth){
                for(int k=i-1;k>=0;k--){
                    if(S[k][len-1]==' ')S[k][len-1]='|';
                    else break;
                }
            }
            depth=len;
        }
        for(int i=0;i<n;i++){
            cout<<S[i]<<endl;
        }
    }
    return 0;
}

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

int main() {
   long long int a,b,k,temp;
   cin>>a>>b>>k;
   a-=k;
   if(a<0)
   {
       
       temp=abs(a);
       a=0;
       b-=temp;
       if(b<0)
       b=0;
   }
   cout<<a<<" "<<b<<endl;
	return 0;
}


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

vector<int> topologicalSort(const vector<vector<int>> &G){
    vector<int> res, visited(G.size());
    auto dfs = [&](auto &&dfs, int cur) {
        if(visited[cur]++) return;
        for(auto &to : G[cur]) {
            if(!visited[to]) dfs(dfs, to);
        }
        res.emplace_back(cur);
    };
    for(int i = 0; i < G.size(); ++i) {
        dfs(dfs, i);
    }
    reverse(res.begin(), res.end());
    return res;
}

int main() {
    int V, E;
    cin >> V >> E;
    vector<vector<int>> G(V);
    for(int i = 0; i < E; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].emplace_back(b);
    }
    auto list = topologicalSort(G);
    for(auto &p : list) cout << p << '\n';
    return 0;
}



Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int,int> mii;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = b-1; i >= a; i--)
#define F0Rd(i,a) for (int i = a-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
const int MOD = 1000000007;
double PI = 4*atan(1);

int N; 
vector<pii> x; 
vi ans, x1;
vi before, after;
map<int,vi> test;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> N;
	x.resize(N); ans.resize(N*N+1);
	F0R(i,N) {
		cin >> x[i].f;
		x[i].s = i+1;
		x1.pb(x[i].f);
	}
	sort(x.begin(),x.end());
	F0R(i,N) {
		if (ans[x[i].f] == 0) {
			ans[x[i].f] = x[i].s;
			F0R(j,x[i].s-1) before.pb(x[i].s);
			F0R(j,N-x[i].s) after.pb(x[i].s);
		} else {
			cout << "No";
			return 0;
		}
	}
	reverse(after.begin(),after.end());
	int c1 = 0, c2 = 0;
	FOR(i,1,N*N+1) {
		if (c1 >= before.size()) break;
		if (ans[i] == 0) ans[i] = before[c1++];
	}
	for(int i = N*N; i>0; --i) {
		if (c2 >= after.size()) break;
		if (ans[i] == 0) ans[i] = after[c2++];
	}
	FOR(i,1,N*N+1) test[ans[i]].pb(i);
	FOR(i,1,N+1) if (test[i][i-1] != x1[i-1]) {
		cout << "No";
		return 0;
	}
	cout << "Yes\n";
	FOR(i,1,N*N+1) cout << ans[i] << " ";
}

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

int main(){
    int i,j=0;
    char S[4];
    cin >> S;
    for(i=0;i<3;i++){
        if(S[i]==S[i+1]){
            j+=1;
        }
        else{
        }
    }
    if(j>0){
        cout << "Bad" << endl;
    }
    else{
        cout << "Good" << endl;
    }
}

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

using namespace std;

int main(){
    int N,time=0;
    cin >> N;
    vector<pair<long long int,long long int>> AB(N);
    for(int i=0;i<N;i++){
        int a,b;
        cin >> a >> b;
        AB[i].first = b;
        AB[i].second = a;
    }

    sort(AB.begin(),AB.end());

    if(N==1 && AB[0].first-AB[0].second<0){
        cout << "No" << endl;
        return 0;
    }

    for(int i=1;i<N;i++){
        time += AB[i-1].second;
        if(AB[i].first-AB[i].second<time){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 3328
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    c = [list(map(int, input().split())) for _ in range(3)]

    absum = []

    def dfs(depth, perm, s):
        if depth==3:
            absum.append(s)
        else:
            for i in range(3):
                if not i in perm:
                    dfs(depth+1, perm+[i], s+c[depth][i])

    dfs(0, [], 0)

    if len(set(absum))==1:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
open Batteries
let n, m = Scanf.scanf "%d %d" (fun x y -> x, y)
let edges = List.init m (fun _ -> Scanf.scanf " %d %d" (fun x y -> x, y))
let find_neighbors x =
  edges |> List.filter_map (fun (a, b) ->
    if a = x then Some b else if b = x then Some a else None)
let () =
  let count = Array.make (n+1) 0 in
  find_neighbors 1 |> List.iter (fun v -> count.(v) <- count.(v) + 1);
  find_neighbors n |> List.iter (fun v -> count.(v) <- count.(v) + 1);
  begin try
    count |> Array.findi ((<=) 2) |> ignore; "POSSIBLE"
  with Not_found -> "IMPOSSIBLE"
  end |> print_endline


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

int main(){
  int a, b, s1, s2, smax, mmax;
  cin >> a >> b >> s1 >> s2 >> smax >> mmax;

  int w1 = 100*a, w2 = 100*b;
  double n=0;//濃度
  int w, s;//水、砂糖の量
  int wans=w1, sans=0;//コーナーケース対策
  for(int i=0; i*w1<=mmax; i++){
    for(int j=0; i*w1+j*w2<=mmax; j++){
      w = i*w1+j*w2;
      int rest = mmax-w;
      for(int k=0; s1*k<=rest; k++){
        for(int l=0; s1*k+s2*l<=rest; l++){
          s = s1*k+s2*l;
          if(100*s>w*smax) continue;
          if((1.0*s)/(w+s)>n){
            wans = w+s;
            sans = s;
            n=(1.0*s)/(1.0*w+1.0*s);
          }
        }
      }
    }
  }

  cout << wans << " " << sans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int A, B, C;
	cin >> A >> B >> C;

	cout << max(B - (A - C), 0) << "\n";

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s;
  cin >> s;
  string st = s.substr(0, 4) + s.substr(5, 2) + s.substr(8, 2);
  int sti = atoi(st.c_str());
  string ans;
  if (sti <= 20190430) {
    ans = "Heisei";
  } else {
    ans = "TBD";
  }

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


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int N,L=1; long long A = 0;
	scanf ("%d",&N);
	for (int i=0;i<N;i++){
		int x; scanf ("%d",&x);
		if (x < L) continue;
		if (x == L) L++;
		else{
			A += (x - 1) / L;
			if (L == 1) L = 2;
		}
	}
	printf ("%lld\n",A);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

ll get_max(const vector<ll> &v){
	return v.empty() ? inf : *max_element(all(v));
}
ll get_min(const vector<ll> &v){
	return v.empty() ? inf : *min_element(all(v));
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vector<ll> ev(1);
	vector<tuple<ll,ll,ll,ll>> in;
	vector<vector<ll>> tate(3), yoko(3);
	rep(i, n){
		ll x, y; char d; cin >> x >> y >> d;
		x *= 2; y *= 2;
		ll dx = 0, dy = 0;
		if(d == 'L') dx = -1;
		else if(d == 'R') dx = 1;
		else if(d == 'D') dy = -1;
		else if(d == 'U') dy = 1;
		else assert(0);
		if(dx){
			yoko[dx + 1].pb(x);
			tate[1].pb(y);
		}
		else{
			tate[dy + 1].pb(y);
			yoko[1].pb(x);
		}
		in.emplace_back(x, y, dx, dy);
	}
	auto func = [](vector<ll> &a, vector<ll> &b, vector<ll> &c, vector<ll> &ev){
		ll p = get_max(a), q = get_max(b), r = get_max(c);
		if(p < inf && q < inf) ev.pb(q - p);
		if(p < inf && r < inf) ev.pb((r - p) / 2);
		if(q < inf && r < inf) ev.pb(r - q);
		p = get_min(a); q = get_min(b); r = get_min(c);
		if(p < inf && q < inf) ev.pb(q - p);
		if(p < inf && r < inf) ev.pb((r - p) / 2);
		if(q < inf && r < inf) ev.pb(r - q);
	};
	func(tate[2], tate[1], tate[0], ev);
	func(yoko[2], yoko[1], yoko[0], ev);
	ll ans = 1e18;
	for(ll t: ev) if(t >= 0){
		ll x = 1e18, y = 1e18, X = -1e18, Y = -1e18;
		for(auto i : in){
			x = min(x, get<0>(i) + get<2>(i) * t);
			y = min(y, get<1>(i) + get<3>(i) * t);
			X = max(X, get<0>(i) + get<2>(i) * t);
			Y = max(Y, get<1>(i) + get<3>(i) * t);
		}
		ans = min(ans, (X - x) * (Y - y));
	}
	cout << fixed << setprecision(20) << ans / 4.0 << endl;
	
	return 0;
}

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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

bool cat(string s, int sz, int &i) {
  if(s[i] != 'm') {
    return i != sz && (s[i] == 'e' || s[i] == 'w');
  }
  i++;
  if(!cat(s, sz, i)) return false;
  if(s[i] != 'e') return false;
  i++;
  if(!cat(s, sz, i)) return false;
  if(s[i] != 'w') return false;
  i++;
  return i == sz || s[i] == 'e' || s[i] == 'w';
}

bool topcat(string s, int sz, int &i) {
  if(s[i] != 'm') return false;
  i++;
  if(!cat(s, sz, i)) return false;
  if(s[i] != 'e') return false;
  i++;
  if(!cat(s, sz, i)) return false;
  if(s[i] != 'w') return false;
  i++;
  return i == sz;
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);
  string s; cin >> s;
  int sz = s.size();
  int i = 0;
  cout << (topcat(s, sz, i) ? "Cat" : "Rabbit") << endl;

}



Measured memory_bytes: 3272
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#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 int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  int n;
  cin >> n;
  set<string> s;
  map<string,int> mp;
  int mx = 0;
  for(int i=0;i<n;i++){
    string str;
    cin >> str;
    mp[str]++;
    s.insert(str);
    mx = max(mx,mp[str]);
  }
  for(auto t:s){
    if(mp[t]==mx){
      cout << t << endl;
    }
  }


return 0;
}
///....


Measured memory_bytes: 33280
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

mat g;
lli n,m;
lli a,b;


int main(){
    cin >> n >> m;
    g = mat(n+1);
    for(lli i = 0;i < m;i++){
        cin >> a >> b;
        g[a].push_back(b);g[b].push_back(a);
    }
    for(lli i = 1;i <= n;i++){
        cout << g[i].size() << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import numpy as np

n = int(input())
arr = np.array(list(map(int, input().split())))

mod = 10 ** 9 + 7

ans = 0
for i in range(60):
    c1 = np.count_nonzero(arr & 1)
    ans += 2 ** i * c1 * (n - c1)
    arr >>= 1

print(ans%mod)


Measured memory_bytes: 48852
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main() {
    int N;
    string s;
    cin >> N >> s;
    
    int x = 1e9 + 1;
    int d;
    for(int i = 0; i <= N; i++) {
        string ss = s.substr(0, i);
        int l = count(ss.begin(), ss.end(), '(');
        int r = count(ss.begin(), ss.end(), ')');
        d = l - r;
        x = min(x, d);
    }

    string ans = string(-x, '(') + s + string(d-x, ')');

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        try {
 
            String str[] = br.readLine().split("\\s+");
            int array[] = new int[str.length];
 
            for(int i = 0; i < str.length; i++){
                array[i] = Integer.parseInt(str[i]);
            }
 
            Dice dice = new Dice();
            dice.setNumber(array[0], array[1], array[2], array[3], array[4], array[5]);
 
            String order = br.readLine();
 
            for(int i = 0; i < order.length(); i++){
                dice.roll(order.charAt(i));
            }
 
            System.out.println(dice.getTop());
 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
 
class Dice{
 
    private int number[];
    private int work[];
 
    Dice(){
        number = new int[6];
        work = new int[6];
    }
 
 
    public void roll(char dst){
        for(int i = 0; i < 6; i++) work[i] = number[i];
        switch(dst){
        case 'E':
            setNumber(work[3],work[1],work[0],work[5],work[4],work[2]);
            break;
        case 'N':
            setNumber(work[1],work[5],work[2],work[3],work[0],work[4]);
            break;
        case 'S':
            setNumber(work[4],work[0],work[2],work[3],work[5],work[1]);
            break;
        case 'W':
            setNumber(work[2],work[1],work[5],work[0],work[4],work[3]);
            break;
        }
    };
 
    public int getTop(){
        return number[0];
    }
 
    public void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
        number[0] = n0;
        number[1] = n1;
        number[2] = n2;
        number[3] = n3;
        number[4] = n4;
        number[5] = n5;
    }
};


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

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#define endl '\n'
#define ff first
#define ss second
#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=1e3,mod=1e9+7,bit=61;

ll power(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b & 1)
		{
			res=(res*a);
		}
		b>>=1;
		a=(a*a);
	}
	return res;
}

map<ll,ll> mp;

signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        pll a[n+1];
        f(i,1,n)
        {
            cin>>a[i].ss;
            a[i].ff=i;
        }
        sort(a+1,a+n+1);
        ll ans=0;
        f(i,1,n)
        {
            ll nd=a[i].ff-a[i].ss;
            if(mp.find(nd)!=mp.end())
            {
                ans+=mp[nd];
            }
            mp[a[i].ff+a[i].ss]++;
        }
        cout<<ans<<endl;
    }
    return 0;
}


















Measured memory_bytes: 19244