akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int INF=1000000007;
int f[5050][5050][2];
vector<int>s[5050];
int sum[5050],fa[5050],g[5050],h[5050],sz[5050];
void dfs(int x)
{
//	printf("%d\n",x);
	int c,i,y,j,k,summ=1;
	c=s[x].size();
	f[x][1][0]=1;
	sz[x]=1;
	for(i=0;i<c;i++)
	{
		y=s[x][i];
		if(fa[x]==y)
			continue;
		fa[y]=x;
		dfs(y);
		for(j=1;j<=sz[x];j++)
			g[j]=f[x][j][0],h[j]=f[x][j][1],f[x][j][0]=f[x][j][1]=0;
		for(j=1;j<=sz[x];j++)
		{
			for(k=1;k<=sz[y];k++)
			{
				f[x][j+k][0]=((long long)f[x][j+k][0]+(long long)f[y][k][0]*g[j]%INF+(long long)f[y][k][1]*h[j]%INF)%INF;
				f[x][j+k][1]=((long long)f[x][j+k][1]+(long long)f[y][k][1]*g[j]%INF+(long long)f[y][k][0]*h[j]%INF)%INF;
				if(k%2==0)
				{
					f[x][j][1]=(f[x][j][1]+(long long)f[y][k][0]*sum[k]%INF*g[j]%INF+(long long)f[y][k][1]*sum[k]%INF*h[j]%INF)%INF;
					f[x][j][0]=(f[x][j][0]+(long long)f[y][k][1]*sum[k]%INF*g[j]%INF+(long long)f[y][k][0]*sum[k]%INF*h[j]%INF)%INF;
				}
			}
		}
		sz[x]+=sz[y];
//		for(j=1;j<=sz[x];j++)
//			printf("%d %d %d\n",j,f[x][j][0],f[x][j][1]);
//		printf("%d %d %d\n",x,y,w);
	}
	
}
int main()
{
	int n,i,x,y,ans=0;
	scanf("%d",&n);
	for(i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		s[x].push_back(y);
		s[y].push_back(x);
	}
	sum[0]=1;
	for(i=2;i<=n;i+=2)
	{
		sum[i]=(long long)sum[i-2]*(i-1)%INF;
//		printf("%d %d\n",i,sum[i]);
	}
	dfs(1);
	for(i=1;i<=n;i++)
	{
		ans=(ans+(long long)sum[i]*f[1][i][0]%INF)%INF;
		ans=(ans-(long long)sum[i]*f[1][i][1]%INF+INF)%INF;
	}
	printf("%d\n",ans);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
 	return 0;
}


Measured memory_bytes: 198784
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll MOD = 1e9+7;

int main(){
  ll n,w,h;
  ll x[111111]={},y[111111]={};
  cin>>n>>w>>h;
  for(int i=0;i<n;i++){
	ll a,b,c;
	cin>>a>>b>>c;
	x[max(a-c,0LL)]++;
	x[min(a+c,w)]--;
	y[max(b-c,0LL)]++;
	y[min(b+c,h)]--;
  }
  int f1=1,f2=1;
  for(int i=0;i<w;i++){
	if(i)x[i]+=x[i-1];
	if(x[i]==0)f1=0;
  }
  for(int i=0;i<h;i++){
	if(i)y[i]+=y[i-1];
	if(y[i]==0)f2=0;
  }
  cout<<(f1||f2?"Yes":"No")<<endl;
  return 0;
}



Measured memory_bytes: 4856
#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
        int N, K;
        char *S;
        char *p;
        char c;

        scanf("%d\n", &N);
        S = malloc(N);
        scanf("%s\n", S);
        scanf("%d\n", &K);

        c = S[K-1];

        p = S;
        for (int i = 0; i < N; i++) {
                if (*p != c)
                        *p = '*';
                p++;
        }

        printf("%s", S);
}


Measured memory_bytes: 128
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		//Nを取得します
		int n = sc.nextInt();
		//diを取得します
		Set<Integer> d = new HashSet<Integer>();
		for (int i = 0 ; i < n ; i++ ) {
			int dIn = sc.nextInt();
			d.add(dIn);
		}
		
		int ans = d.size();
		
		/**
		 * 答えを出力します
		 */
			
		System.out.println(ans);
		
	}

}


Measured memory_bytes: 23764
#define fn auto
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;

void newline() {cout << endl;}
template <typename T> void display(T input){cout << input;}
template <typename T> void put(T input){display(input); newline();}
void iput(int input) {put(input);}

fn main() -> int {
  string s;
  int a, z;
  cin >> s;
  a = (int)s.find("A");
  z = (int)s.rfind("Z");
  cout << z-a+1 << endl;

}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, l; cin >> n >> l;
	VE a(n);
	rep(i, n)cin >> a[i];
	bool ok = false;
	int tmp = -1;
	rep(i, n - 1) {
		if (a[i] + a[i + 1] >= l) {
			ok = true;
			tmp = i;
		}
	}
	if(!ok)cout << "Impossible" << endl;
	else {
		cout << "Possible" << endl;
		tmp++;
		FOR(i, 1, tmp) {
			cout << i << endl;
		}
		for (int i = n - 1; i >= tmp + 1; i--) {
			cout << i << endl;
		}
		cout << tmp << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);
        int x = 0;
        if (A > B)
        {
            x += A;
            A--;
        }
        else
        {
            x += B;
            B--;
        }
        if (A > B)
        {
            x += A;
            A--;
        }
        else
        {
            x += B;
            B--;
        }
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cmath>
#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

int ans;

int main(void) {
	int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    
    if ((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d) Yes;
    else No;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();

		for (int i = a; i <= Math.min(a + k - 1, b); i++) {
			System.out.println(i);
		}

		for (int i = Math.max(a + k, b - k + 1); i <= b; i++) {
			System.out.println(i);
		}

		sc.close();
	}
}


Measured memory_bytes: 21844
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)

readIntsLine :: IO [Int]
readIntsLine = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

solve :: Int -> [Int] -> [Int] -> Int
solve p [a] [] = min a p
solve p (a:as) (b:bs) = prevp + currp + solve nextp as bs
  where prevp = min a p
        currp = min (a - prevp) b
        nextp = b - currp

main :: IO ()
main = do
  getLine
  as <- readIntsLine
  bs <- readIntsLine
  print $ solve 0 as bs

Measured memory_bytes: 7676
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

int main_() {
	int X;
	cin >> X;

	string ans = (X < 1200) ? "ABC" : "ARC";

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
char S[150];
char S1[150];


int main(void){
 int A,B;

 cin>>A>>B;

 std::cout<<A-B+1<<std::endl;
 return 0;
}

Measured memory_bytes: 256
def main1():
    N=int(input())
    A=list(map(int,input().split()))
    A.sort(reverse=True)
    cn=1
    ans=A[0]
    tmp=0
    if N%2==0:
        while cn<-(-N//2):
            ans+=A[cn]*2
            cn=cn+1
        print(ans)
    else:
        while cn<-(-N//2)-1:
            ans+=A[cn]*2
            cn=cn+1
        print(ans+A[cn])
main1()

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

int main()
{
       int a, b;
       cin >> a >> b;
       int ans = -1;

       for (int i = 1; i <= 1010; i++) {
            if (floor(i * 0.08) == a && floor(i * 0.1) == b) {
                ans = i;
                break;
            }
       }
       if (ans == -1) puts("-1");
       else cout << ans << "\n";
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int n,m,a[55],b[55];
bool g[55][55],vis[55];
void dfs(int v)
{
	vis[v]=1;
	for(int i=0;i<n;i++)
	{
		if(g[v][i]==0)
			continue;
		if(vis[i]==1)
			continue;
		dfs(i);
	}
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a[i];
		cin>>b[i];
		a[i]--;
		b[i]--;
		g[a[i]][b[i]]=g[b[i]][a[i]]=1;
	}
	int ans=0;
	for(int i=0;i<m;i++)
	{
		g[a[i]][b[i]]=g[b[i]][a[i]]=0;
		for(int j=0;j<n;j++)
			vis[j]=0;
		dfs(0);
		for(int j=0;j<n;j++)
			if(!vis[j])
			{
				ans++;
				break;
			}
		g[a[i]][b[i]]=g[b[i]][a[i]]=1;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
const main = input => {
  const inputs = input.split("\n");
  const [n, k] = inputs[0].split(" ").map(Number);
  const prices = inputs[1].split(" ").map(Number);
  prices.sort((a, b) => a - b);
  const sum = prices.slice(0, k).reduce((a, v) => {
    return a + v;
  }, 0);
  console.log(sum);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29640
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>

#define LL long long int
#define mp make_pair 
#define pb push_back
#define f first
#define s second

using namespace std;




int main(){

    int n;
    cin >> n;

    int a[n];

    int ans = 0;

    for(int i = 0; i < n; i++){
         cin >> a[i];
         ans += a[i]-1;
     }
    

    cout << ans;


    return 0;
 }








Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[110000];
long long L[110000];
long long R[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
	}
	long long ret=0;
	for(int i=1;i<a;i++){
		long long cur=0;
		for(int j=0;j<a;j+=i){
			cur+=p[j];
			L[j]=cur;
		}
		cur=0;
		for(int j=a-1;j>=0;j-=i){
			cur+=p[j];
			R[j]=cur;
		}
		int left=0;
		int right=a-1;

		while(left<a-1){
			ret=max(ret,L[left]+R[right]);
			left+=i;
			right-=i;
			if(right<=i)break;
			if(left>=right&&left%i==right%i)break;
		}
	}
	printf("%lld\n",ret);
}


Measured memory_bytes: 2176
n = int(input())
arr = [list(map(int,input().split())) for _ in range(n-1)]
mod = 10**9+7

graph = [[] for _ in range(n)]
for a,b in arr:
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

parents = [-1] * n
children = [[] for _ in range(n)]
flags = [True] * n; flags[0] = False
stack = [0]
orders = []

while stack:
    index = stack.pop()
    orders.append(index)
    for child in graph[index]:
        if flags[child]:
            parents[child] = index
            children[index].append(child)
            flags[child] = False
            stack.append(child)

fac = [1] * (n+10)
inv = [1] * (n+10)
ifac = [1] * (n+10)
for i in range(2,n+10):
    fac[i]=(fac[i-1]*i)%mod
    inv[i]= -(inv[mod%i]*(mod//i))%mod
    ifac[i]=(ifac[i-1]*inv[i])%mod

size = [1] * n
dp = [1] * n
for parent in orders[::-1]:
    for child in children[parent]:
        size[parent] += size[child]
        dp[parent] = dp[parent] * dp[child] * ifac[size[child]] % mod
    dp[parent] = dp[parent] * fac[size[parent]-1] % mod

size2 = [n-i+1 for i in size]
dp2 = [1] * n
for parent in orders[1:]:
    child = parents[parent]
    dp2[parent] = dp2[parent] * fac[size2[parent]-2] * dp[child] * dp2[child] * fac[size[parent]] * ifac[size2[child]-1] * ifac[size[child]-1] * pow(dp[parent], mod-2, mod) % mod
    
for i in range(n):
    print(fac[n-1] * ifac[size[i]-1] * ifac[size2[i]-1] * dp[i] * dp2[i] % mod)

Measured memory_bytes: 144912
#include<stdio.h>
#include<math.h>
int main()
{
      int a,b;
      scanf("%d %d", &a,&b);

      if (a>b){
        printf("safe");
      }
      else if(b>a){
        printf("unsafe");
      }
      else if (a==b){
        printf("unsafe");
      }
    return 0;
}


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

int main()
{
  int N,M,C ;
  cin>>N>>M>>C ;
  int B[M] ;
  int A[N][M] ;
  int i,j ;
  for(i=0;i<M;i++) cin>>B[i] ;
  for(i=0;i<N;i++){
    for(j=0;j<M;j++) cin>>A[i][j] ;
  }
  
  int sum=0 ;
  int count=0 ;
  for(i=0;i<N;i++){
    for(j=0;j<M;j++) sum+=A[i][j]*B[j] ;
    sum+=C ;
    if(sum>0) count++ ;
    sum=0 ;
  }
  
  cout<<count<<endl ;
  
  return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <climits>

using namespace std;


int main() {
#ifdef __APPLE__
    freopen("input2.txt", "r", stdin);
#endif
    int N;
cin >> N;

    vector<vector<int>> shops;
    vector<vector<long>> profits;
    for (int i = 0; i < N; ++i) {
        vector<int> shop(10);
        for (int j = 0; j < 10; ++j) {
            cin >> shop[j];
        }
        shops.push_back(shop);
    }

    for (int i = 0; i < N; ++i) {
        vector<long> profit(11);
        for (int j = 0; j < 11; ++j) {
            cin >> profit[j];
        }
        profits.push_back(profit);
    }


    long max_profit = LONG_MIN;

    vector<int> num_of_opens_for_each_shop(N);

    for (int i = 1; i < 1024; ++i) {
        for (int j = 0; j < N; ++j) {
            num_of_opens_for_each_shop[j] = 0;
        }

        long sum = 0;
        bitset<10> pattern = bitset<10>((unsigned long long)i);
        for (int j = 0; j < 10; ++j) { // j: weekday
            if (pattern[j]) {
                for (int k = 0; k < N; ++k) {
                    if (shops[k][j]) ++num_of_opens_for_each_shop[k];
                }
            }
        }

        for (int j = 0; j < N; ++j) {
            sum += profits[j][num_of_opens_for_each_shop[j]];
        }

        max_profit = max(max_profit, sum);
    }

    cout << max_profit << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    for(int n, res; cin >> n, n; cout << res << endl){
        res = 0;
        
        int w, h; cin >> w >> h;
        vector<vi> m = vector<vi>(h, vi(w, 0));

        rep(i, n){
            int x, y; cin >> x >> y;
            m[y - 1][x - 1] = 1;
        }

        int xxx, yyy; cin >> xxx >> yyy;

        rep(y, h){
            rep(x, w){
                int cnt = 0;
                rep(yy, yyy){
                    rep(xx, xxx){
                        if(x + xx < 0 || w <= x + xx ||
                           y + yy < 0 || h <= y + yy){
                            continue;
                        }
                        if(m[y + yy][x + xx]){
                            cnt++;
                        }
                    }
                }
                res = max(res, cnt);
            }
        }
    }

	return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
int a[3];

int main(){
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    cout << a[0] + a[1] + 10*a[2] << endl;
}

Measured memory_bytes: 256
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip> 
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (c).size()
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int n , d , ans;
int main(){
fcin;
    cin >> n >> d;
    for(int i = 0 ; i < n ; i++){
        int x , y;
        cin >> x >> y;
        ll f = pow(x,2) + pow(y,2);
        if(sqrt(f) <= d) ans++;
        // cout << f << "\n"
;    }
    cout << ans << '\n';


}

Measured memory_bytes: 3196
/* Author: Mrigank
Science is what we understand well enough to explain to a computer, 
    Art is everything else we do - Donald E. Knuth */

#include <bits/stdc++.h>
#include <iostream>
#include <unordered_map>
#include <map>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <string> 
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, int> PLI;
typedef pair < ll , ll > PLL;
typedef pair<int, int> PII;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < bool > vb;
typedef vector < pair < ll , ll > > vpl;
typedef vector < pair < ll , bool > > vpb;
typedef vector < vector < int > > vvi;
typedef vector < vector < ll > > vvl;


#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x , val) memset(x , val , sizeof(x))
#define deb(x) cout<<#x<<" :: "<<x<<"\n"
#define deb2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define deb3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
#define all(x) x.begin() , x.end()
#define alls(x , y) x.begin() , x.end() , y
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl "\n"

const ll mxsize = 5e5 + 10;
const ll linf = 1e9;
const ld inf = 10000000000.0;
const ll mod = 1e9 + 7;
 
/******************************************** CODE STARTS FROM HERE *************************************************/ 
int main()
{
    fastIO;
    ll k;
    cin >> k;
    string s;
    cin >> s;
    ll n = s.length();
    if(k >= n)
    {
        cout << s << endl;
    }
    else
    {
        string ans = s.substr(0 , k);
        ans += "...";
        cout << ans << endl;
    }
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int  N = sc.nextInt();
		int p[] = new int[N+1] ;

		int ngPos = 0 ;
		int ngNum = 0 ;
		int changeCount = 0 ;
		boolean ok = true ;
		for( int i = 1 ; i <= N; i ++ ) {
			p[i] = sc.nextInt();
			if(p[i] != i ) {
				if(0 < changeCount) {
					ok = false ;
					break ;
				}
				if(0 == ngPos) {
					ngPos = i ;
					ngNum = p[i];
				}else {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				}
			}
		}
		if(ok) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21460
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String W = sc.next();
        String T;
        
        int cnt = 0;
        
        while(true) {
        	T = sc.next();
        	if(T.equals("END_OF_TEXT")) break;
        	
        	T = T.toLowerCase();
        	if(W.equals(T)) cnt++;
        	
        }
        
        System.out.println(cnt);
        
    }
}


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

int main()
{
    int n, x, min, cnt = 0;
    cin >> n >> x;
    vector<int> vec(n);
    for(int i=0; i<n; i++)
    {
        cin >> vec[i];
        x -= vec[i];
        cnt ++;
    }

    min = *min_element(vec.begin(), vec.end());
    
    cnt += x/min;
    
    cout << cnt;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	var a, b string
	fmt.Scan(&n)
	fmt.Scan(&a)
	fmt.Scan(&b)

	res := ""
	for i := 0; i < n; i++ {
		res += string(a[i])
		res += string(b[i])
	}
	fmt.Println(res)
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

ll solve(string l, string r) {
    bool l_check[26] = {}, r_check[26] = {};
    rep(i, l.length()) { l_check[l[i] - 'a'] = true; }
    rep(i, r.length()) { r_check[r[i] - 'a'] = true; }

    ll num = 0;
    rep(i, 26) {
        if (l_check[i] & r_check[i])
            num++;
    }
    return num;
}

int main() {
source:
    ll n;
    string s;
    cin >> n >> s;
    ll ans = 0;
    rep(i, n) {
        string l = s.substr(0, i), r = s.substr(i);
        ans = max(ans, solve(l, r));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
# import numpy as np
# import matplotlib.pyplot as plt
#
# Y, X = np.mgrid[-3:3:100j, -3:3:100j]
# U = (X-2)/((X-2)**2+Y**2)**1.5 - (X+2)/((X+2)**2+Y**2)**1.5
# V = Y/((X-2)**2+Y**2)**1.5 - Y/((X+2)**2+Y**2)**1.5
#
# plt.streamplot(X, Y, U, V, cmap=plt.cm.autumn, density=2)
# plt.show()
a,b,c,k=map(int,input().split())
if abs(a-b)>10**18:
    print("Unfair")
else:
    if k % 2==1:
        print(b-a)
    else:
        print(a-b)



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

int main()
{
    string S;
    cin >> S;

    sort(S.begin(), S.end());
    if ((S[0] == S[1]) && (S[1] != S[2]) && (S[2] == S[3]))
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){
  int N;
  ll Y;
  bool flag;
  flag = true;
  cin >> N >> Y;
  for(int i = 0; i <= N; i++){
    for(int j = 0; j <= N-i; j++){
      if(Y == 10000*i + 5000*j + 1000*(N - i - j)){
        int b = N - i - j;
        cout << to_string(i)
             << " "
             << to_string(j)
             << " "
             << to_string(b) << endl;
        flag = false;
        break;
      }
    }
    if(!flag) break;
  }

  if(flag) cout << "-1 -1 -1" << endl;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int selectSort(int *num,int n) {
	int cnt = 0;
	int minnum = 0;
	for (int i = 0; i < n; i++) {
		minnum = i;
		for (int j = i; j < n; j++) {
			if (num[minnum] > num[j]) {
				minnum = j;
			}
		}
		if (num[minnum] != num[i]) {
			swap(num[minnum], num[i]);
			cnt++;
		}
	}
	for (int i = 0; i < n; i++) {
		
		cout << num[i];
		if(i!=n-1)
			cout << " ";
	}
		
	return cnt;
}

int main() {
	int ans = 0;
	int n;
	int tmp;
	int *num;
	cin >> n;
	num = new int[n];
	for (int i = 0; i < n; i++) {
		cin>>num[i];
	}
	
	ans=selectSort(num,n);

	cout << endl<<ans << endl;

	return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define CYES cout << "Yes" \
                  << "\n"
#define CNO cout << "No" \
                 << "\n"
#define CFS           \
    cin.tie(nullptr); \
    ios::sync_with_stdio(false);
#define CST(x) cout << fixed << setprecision(x)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
const int IINF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const string MM = " ";

int main()
{
    long n, a, b;
    cin >> n >> a >> b;
    long c = n / (a + b);
    long d = n % (a + b);
    cout << c * a + min(d, a) << "\n";
}

Measured memory_bytes: 256
import java.util.*;import java.io.*;import java.math.*;
public class Main
{
    public static void process()throws IOException
    {
        int n=ni();
        int[]A=nai(n);
        long[]freq=new long[n+1];
        for(int i=0;i<n;i++)
            freq[A[i]]++;
        long ans=0;
        for(int i=1;i<=n;i++)
            ans+=(freq[i]*(freq[i]-1))/2;
        for(int i=0;i<n;i++)
        {
            long temp=ans;
            long x=freq[A[i]];
            temp=temp-((x*(x-1))/2)+((x-1)*(x-2)/2);
            pn(temp);
        }
    }

    static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        boolean oj = true;
        if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
        else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
        int t=1;
        while(t-->0) {process();}
        out.flush();out.close();  
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
    static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
   
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

Measured memory_bytes: 52676
#include "stdio.h"
#include "math.h"

int main(){
  int N;
  int counter=0;
  scanf("%d",&N);


  for(int i=0;i<N;i++){
    int area;
    int flag=0;
    scanf("%d",&area);
    double large=sqrt((double)area);
    for(int y=1;y<large;y++)
      if ((area-y)%(2*y+1)==0){
	flag=1;
	break;
      }

    if(flag)
      counter++;
  }

  printf("%d\n",N-counter);
  
  return 0;
}



Measured memory_bytes: 2076
from sys import stdin
from collections import deque, Counter, defaultdict
import heapq

INF = int(1e10)
MOD = int(1e9 + 7)

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    K = int(input())
    S = input()
    if len(S) <= K:
        print(S)
    else:
        print("{}{}".format(S[:K], "..."))

if __name__ == '__main__':
    main()

Measured memory_bytes: 64728
fun main(args: Array<String>) {
    abc096d()
}

fun abc096d() {
    val n = readLine()!!.toInt()

    val primes = genPrime(55555)

    val answer = primes.filter { it % 5 == 1L }.take(n).joinToString(" ")

    println(answer)
}

private fun genPrime(max: Long): LongArray {
    val sqrt = Math.ceil(Math.sqrt(max.toDouble())).toLong()
    val primes = mutableListOf<Long>()

    var target = (2..max).toList()

    while (target.isNotEmpty() && target.first() <= sqrt) {
        val prime = target.first()
        primes.add(prime)
        target = target.filterNot { it % prime == 0L }
    }

    primes.addAll(target)

    return primes.toLongArray()
}


Measured memory_bytes: 38344
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        while (true) {
            int H = sc.nextInt();
            int W= sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            }

            for (int h = 0; h < H; h++) {
                for (int w = 0; w < W; w++) {
                    if (h % 2 == 0) {
                        if (w % 2 == 0) {
                            System.out.print("#");
                        } else {
                            System.out.print(".");
                        }
                    } else {
                        if (w % 2 == 1) {
                            System.out.print("#");
                        } else {
                            System.out.print(".");
                        }
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 33104
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
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; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll a,b,c,n;
  cin >> a >> b >> c >> n;
  ll t = a + b+ c;
  ll lo = max(a,max(b,c));
  t-=lo;
  rep(i,n){
    lo*=2;
  }
  pri(t+lo);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;
#define ll long long

int main(){
  string s;
  cin >> s;
  int len = s.size();
  cout << s[0] << len-2 << s[len-1] << endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    set<string> X;
    string prev = "";
    bool ans = true;
    rep(i, N){
        string W; cin >> W;
        if (i > 0 && prev[prev.size() - 1] != W[0]){ans = false;}
        if (X.find(W) != X.end()){ans = false;}
        X.insert(W);
        prev = W;
    }
    if (ans){cout << "Yes" << endl;} else {cout << "No" << endl;}
}

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


Measured memory_bytes: 3620
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T>
struct BIT{
    //1-index
    private:
    V<T> arr;
    int n;

    public:
    BIT(int siz){
        n=siz;
        arr.assign(n+1,0);
    }
    //一点更新
    void add(T a,T v){
        //x+=(x&-x) 初項a,それ以降a<=2^Nが列挙
        for(T x=a;x<=n;x+=(x&-x)){
            arr[x]+=v;
        }
    }
    T sum(T a){
        T ret=0;
        for(T x=a;x>0;x-=(x&-x))ret+=arr[x];
        return ret;
    }
};
int main(){
 int n;
 cin>>n;
 ll ans=0;
 BIT<ll> t(n);
 V<ll> v(n);
  map<ll,int> mp;
 for(int i=0;i<n;i++){
     cin>>v[i];
     mp[v[i]];
 }
 ll cnt=1;
 for(auto &p:mp)p.se=cnt++;
 for(int i=0;i<n;i++){
     ans+=i-t.sum(mp[v[i]]);
     t.add(mp[v[i]],1);
 }
 cout<<ans<<endl;
}


Measured memory_bytes: 18372
#include <bits/stdc++.h>
using namespace std;
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;
}

#ifdef DEBUG
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
#else
template <class T, class... Args>
void debug(const T &x, const Args &... args) {}
template <class T> void debugVector(const vector<T> &v) {}
#endif

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

// Java8
public class Main {
	Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	void run() throws Exception {
		int n = sc.nextInt();
		int q = sc.nextInt();
		KVHeap heap = new KVHeap(n);
		for(int i=0; i<q; i++) {
			int a = sc.nextInt();
			int v = sc.nextInt();
			heap.add(a, v);
			int top = heap.top();
			System.out.println(top + " " + heap.getValue(top));
		}
	}
}
class KVHeap {
	int size;
	int[] value;
	int[] heap;
	int[] pos;

	KVHeap(int n) {
		size = n;
		value = new int[n+1];
		heap = new int[n+1];
		pos = new int[n+1];
		for(int i=1; i<=size; i++) {
			heap[i] = i;
			pos[i] = i;
		}
	}

	int getValue(int k) {
		return value[k];
	}

	void siftUp(int x){
		while(pos[x] > 1) {
			int p = pos[x];
			int ppar = p / 2;
			int xpar = heap[ppar];
			if(value[x]>value[xpar] || (value[x]==value[xpar] && x<xpar)) {
				heap[ppar] = x;
				heap[p] = xpar;
				pos[xpar] = p;
				pos[x] = ppar;
			} else break;
		}
	}

	void siftDown(int x) {
		while(pos[x]*2<=size) {
			int p = pos[x];
			int pchi = p * 2;
			int xchi = heap[pchi];
			if(pchi<size) {
				int xright = heap[pchi+1];
				if(value[xright]>value[xchi] || (value[xright]==value[xchi] && xright<xchi)) {
					xchi = xright;
					pchi++;
				}
			}
			if(value[x]<value[xchi] || (value[x]==value[xchi] && x>xchi)) {
				heap[pchi] = x;
				heap[p] = xchi;
				pos[xchi] = p;
				pos[x] = pchi;
			} else break;
		}
	}

	void add(int k, int v) {
		value[k] += v;
		if(v>0) {
			siftUp(k);
		} else {
			siftDown(k);
		}
	}

	int top() {
		return heap[1];
	}
}


Measured memory_bytes: 116284
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, Q; cin >> N >> Q;
    vector<vector<int>> G(N, vector<int>());
    rep(i,N-1) {
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector V(N, 0LL);
    rep(i, Q) {
        int p, x; cin >> p >> x;
        p--;
        V[p] += x;
    }

    stack<tuple<int, ll, int>> S;
    S.push({0,0,0});
    while (!S.empty()) {
        auto [p, x, Parent] = S.top(); S.pop();
        V[p] += x;
        for (auto i : G[p]) {
            if (i == Parent) continue;
            S.push({i, V[p], p});
        }
    }

    rep(i,N) {
        cout << V[i];
        if (i != N-1) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 21340
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) ->
      if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  inorder (fun e -> print_string " "; print_int e) t;
  print_newline ();
  preorder (fun e -> print_string " "; print_int e) t;
  print_newline ()

let find x t =
  let rec doit = function
    | Nil -> false
    | Node (y, l, r) ->
      if x = y then true
      else if x < y then doit l
      else doit r in
  doit t

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let m = read_int () in
  let t = ref (create ()) in
  for _ = 0 to m - 1 do
    match read_line () |> split_on_char ' ' with
    | ["insert"; n] -> t := insert (int_of_string n) !t
    | ["find"; n] -> print_endline (if find (int_of_string n) !t then "yes" else "no")
    | _ -> print !t
  done

Measured memory_bytes: 25320
#include <iostream>
#include <algorithm>

using namespace std;

main(){
  int a;
  while(1){
    cin >> a;
    if(a==0) break;
    int A[1000000];
    int p=a/2;
    int j=0;

    for(int i=0;i<a;i++){
      cin >> A[i];
    }
    sort(A, A+a);
    bool f=false;
    bool first=true;
    for(int i=1,j=1;;i++){
      if(i>=a){
	if(j>p){
	  if(!first) cout << ' ';
	  printf("%d\n", A[i-1]);
	  f=true;
	  first=false;
	}
	break;
      }
      if(A[i]==A[i-1]){
	j++;
      }
      else{
	if(j>p){
	  if(!first) cout << ' ';
	  printf("%d\n", A[i-1]);
	  f=true;
	  first=false;
	}
	j=1;
      }
    }
    if(!f){
      printf("NO COLOR\n");
    }
  }
  return 0;
}

Measured memory_bytes: 4780
using System;
using System.Linq;
using System.Numerics;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var a = Console.ReadLine().Trim().Split(' ').Select(BigInteger.Parse).ToArray();
            var len = a.Length;

            if (a[0] == 1 && len == 1)
            {
                Console.WriteLine(1);
                return;

            }
            if (a[0] != 0)
            {
                Console.WriteLine(-1);
                return;
            }

            var b = new BigInteger[len];
            var c = new BigInteger[len];
            b[0] = 1;
            for (int i = 1; i < len; i++)
            {
                b[i] = (b[i - 1] - a[i - 1]) * 2;
            }
            c[len - 1] = a[len - 1];
            for (int i = len - 2; 0 <= i; i--)
            {
                c[i] = a[i] + c[i + 1];
            }
            BigInteger r = 0;
            for (int i = 0; i < len; i++)
            {
                var v = BigInteger.Min(b[i], c[i]);
                if (v <= 0)
                {
                    Console.WriteLine(-1);
                    return;
                }
                r += v;
            }
            if(b[len-1] < c[len-1])
            {
                    Console.WriteLine(-1);
                    return;
            }
            Console.WriteLine(r);
        }
    }
}


Measured memory_bytes: 674716
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int n; cin >> n;
  vector<int> a(n), b(n), c(n);
  rep(i,n) cin >> a[i] >> b[i] >> c[i];
  vector<int> dpa(n), dpb(n), dpc(n);
  dpa[0] = a[0]; dpb[0] = b[0]; dpc[0] = c[0];

  rep(i,n-1) {
    dpa[i+1] = max(dpb[i] + a[i+1], dpc[i] + a[i+1]);
    dpb[i+1] = max(dpa[i] + b[i+1], dpc[i] + b[i+1]);
    dpc[i+1] = max(dpa[i] + c[i+1], dpb[i] + c[i+1]);
  }
  int ans = max(dpa[n-1], max(dpb[n-1], dpc[n-1]));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll int
#define fi first
#define deb(x) cout<<#x<<" "<<x<<endl;
#define debarr(a) cout<<#a<<endl;for(auto i: a) cout<<i<<" ";
#define se second
#define cnt(i) __builtin_popcountll(i)
#define pb emplace_back
#define append(j) pb(j)
#define print(p) cout<<p<<endl;
#define mp make_pair
#define len(w) w.size()
#define tuple(p,q) mp(p,q)
#define tc while(t--)
#define fo(n) for(int i=0;i<n;i++)
#define foj(m,n) for(int j=m;j<n;j++)
#define INF 9999999999
#define pra(a,n) fo(n)cout<<a[i]<<" ";cout<<endl;
#define vp vector<pair<int,int>>
#define vc vector<int>
#define all(v) (v.begin(),v.end())
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pp pair<ll,ll>
#define ispow2(x)  x && (!(x&(x-1)))
#define copy(a,b,n) copy_n(a,n,b) 
#define create(a,m,n) iota(a,a+n,m)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define maximum(a,n)  ll* i1,maxi; i1 = std::max_element(a, a+n);maxi=*i1 
#define minimum(a,n)  ll* i1,mini; i1 = std::min_element(a, a+n);mini=*i1 
using namespace std;
ll n,m,k,s,dis[100005]={0},vis[100005]={0},x,y,g,h;
#define MAXN (ll)1e6+5
vc a[100005];

void dfs(ll i,ll p)
{
    vis[i]=1;
    for(ll j: a[i])
    {
        if(j!=p and vis[j])
        dis[i]=max(dis[i],dis[j]+1);
        else if(vis[j]==0)
        dfs(j,i);
        dis[i]=max(dis[i],dis[j]+1);
    }
}
		
signed main(){
    fio
    cin>>n>>m;
    fo(m)
    {
        cin>>x>>y;
        a[x].pb(y);
    }
    fo(n)
    if(!vis[i+1])
    dfs(i+1,-1);
    
    maximum(dis,n+1);
    cout<<maxi;
    
    
    
    return 0;
}

Measured memory_bytes: 13316
def resolve():
    N= int(input())
    A = list(map(int,input().split()))

    API = dict()
    ans = 0
    for i,a in enumerate(A):
        api = a+i+1
        ami = i+1-a

        if ami in API:
            ans += API[ami]

        if not api in API:
            API[api]=0
        API[api]+=1
        
    print(ans)




if __name__ == "__main__":
    resolve()

Measured memory_bytes: 40516