akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>

using namespace std;

int min(int a, int b) {
  return a < b ? a : b;
}

int main(void)
{
    vector<int> a(3);
    for (int i = 0; i < 3; ++i) {
      cin >> a.at(i);
    }

    vector<int> dp(3);
    sort(a.begin(), a.end());
    dp.at(0) = 0;
    for (int i = 1; i < 3; ++i) {
      dp.at(i) = dp.at(i - 1) + abs(a.at(i) - a.at(i - 1));
    }
    cout << dp.at(2) << endl;    
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

ll n, d[301][301], e[301][301], ans;

int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			ll a;
			cin >> a;
			d[i][j] = a;
			e[i][j] = a;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
			} 
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
			} 
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(d[i][j]<e[i][j]){
				cout << 0-1 << endl;
				return 0;
			} 
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			bool f = 0;
			for(int k=0;k<n;k++){
				if((i-k)*(k-j)*(j-i)!=0 && d[i][j] == d[i][k]+d[k][j]){
					f = 1;
				}
			} 
			if(!f) ans += d[i][j];
		}
	}

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

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm> //maxを使うため
#include <cstring> //memsetを使うため

using namespace std;

int n, W; //nは商品の数、Wはナップサックに詰め込める容量
int v[100], w[100]; //vは商品の価値、wは商品の重さ
int memo[101][10010]; //関数の結果を保存するための配列

int knap(int i, int j);  //価値の和の最大を求めるための関数

int main()
{
    cin >> n >> W;

    for (int i = 0; i < n; i++) cin >> v[i] >> w[i];

    memset(memo, -1, sizeof(memo)); //memoの中身を-1で埋める

    cout << knap(0, W) << endl;
}

int knap(int i, int j)
{
    if (memo[i][j] >= 0) { //memoに値があればそれを返す
        return (memo[i][j]);
    }
    int res;

    if (i == n) { //商品がもうないので0を代入する
        res = 0;
    }
    else if (j < w[i]) { //容量不足なので入れない処理だけをする
        res = knap(i+1, j);
    }
    else {  //入れると最大になるとは限らないので入れる時と入れない時の大きい方を取る
        res = max(knap(i+1, j), knap(i+1, j-w[i]) + v[i]);
    }

    return memo[i][j] = res; //値をmemoに保存する
} 


Measured memory_bytes: 7064
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};
LL hako[200200];
vector<int>edge[200200];
int main(){
  int n,q;
  cin >> n >> q;
  rep(i,0,n-1){
    int a,b;
    cin >> a >> b;
    edge[a-1].push_back(b-1);
  }
  rep(i,0,q){
    int a,b;
    cin >> a >> b;
    hako[a-1] += b;
  }
  rep(i,0,n){
    rep(j,0,edge[i].size()){
      hako[edge[i][j]] += hako[i];      
    }
  }
  rep(i,0,n){
    cout << hako[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 16768
#include<iostream>
using namespace std;
int NIL=-1;
struct Node{
    int p=NIL,c=NIL,s=NIL;
    //親、最も左の子、すぐ右の兄弟
};
void setDepth(Node A[],int i,int d,int D[]){//iはnode番号
    D[i]=d;//depth登録。
    if(A[i].s!=NIL){
        setDepth(A,A[i].s,d,D);
    }
    if(A[i].c!=NIL){
        setDepth(A,A[i].c,d+1,D);
    }
}
int getRoot(Node A[],int n){
    for(int j=0;j<n;j++){
        if(A[j].p==NIL)return j;
    }
}

int main(){
    int n;cin>>n;
    Node A[n];int D[n];//Depthのリスト
    for(int i=0;i<n;i++){
        int id,num;cin>>id>>num;
        if(num!=0){//0だったら何もしなくていいや
            int children[num]={};for(int j=0;j<num;j++){cin>>children[j];}
            for(int j=0;j<num;j++){
                A[children[j]].p=id;//親を登録
                if(j==0){
                    A[id].c=children[j];//親nodeの一番左の子供を設定
                }
                if(j!=num-1){//子nodeの兄弟を設定
                    A[children[j]].s=children[j+1];
                }
            }
            
        }
    }
    setDepth(A,getRoot(A,n),0,D);

    for(int i=0;i<n;i++){
        cout<<"node "<<i<<": parent = "<<A[i].p<<", depth = "<<D[i]<<", ";
        if(A[i].p==NIL)cout<<"root, [";
        else if(A[i].c==NIL)cout<<"leaf, [";
        else cout<<"internal node, [";
        //子の書き出し
        if(A[i].c!=NIL){
            int tmp=A[i].c;cout<<tmp;
            while(true){//模範解答はfor文一回で表現している。真似しなくてもイイと思うが。
                int sib=A[tmp].s;
                if(sib==NIL)break;
                cout<<", "<<sib;
                tmp=sib;
            }
        }
        cout<<"]"<<endl;
        }
    return 0;
}



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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define MP(v) make_pair(v)
#define F first
#define S second

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

  ll a, b, c;
  cin >> a;

  if (a == 1) {
    cout << "Hello World" << endl;
  } else {
    cin >> b >> c;
    cout << b + c << "\n";
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<n;i++)
int main(){
ll a,b;
cin>>a>>b;
ll x[3];
x[0]=a+b;
x[1]=a-b;
x[2]=a*b;
sort(x,x+3);
cout<<x[2];
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    char o[50], e[50];
    scanf("%s%s", o, e);
    for(int i=0; o[i/2]&&e[i/2]!='\0'; i++){
        if((i+1)%2==1) printf("%c", o[i/2]);
        else printf("%c", e[i/2]);
    }
    if(strlen(o)!=strlen(e)) printf("%c", o[strlen(o)-1]);
    return 0;
}

Measured memory_bytes: 1612
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int N;
    cin >> N;

    int P[N];

    rep(ni,N) cin >> P[ni];

    int cnt = 0;
    int maxp;
    int minp;
    for( int ni = 2 ; ni < N ; ni++ ){
        maxp = max(P[ni-2],max(P[ni-1],P[ni]));
        minp = min(P[ni-2],min(P[ni-1],P[ni]));
        if(P[ni-1] != maxp && P[ni-1] != minp) cnt++;
    }
    cout << cnt << endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int n,i,c;
  cin>>n;
  string s;
  cin>>s;
  c=0;
  for(i=0;i<n;i++)
  {
    if(s[i]==65)
    {
      if(s[i+1]==66 && s[i+2]==67)
        c++;
    }}
  cout<<c;
  return 0;
}

  


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<sstream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int main(){
  string s;
  int i,j,k;
  vector<P> v;
  while(cin >> s,s[0]!='0'){
    for(i=0;i<s.size();i++) if(s[i]==',') s[i]=' ';
    stringstream ss(s);
    P p;
    ss >> p.second >> p.first;
    v.push_back(p);
  }
  sort(v.begin(),v.end(),greater<P>());
  int rank[105]={};
  k=1;
  rank[v[0].second]=k;
  for(i=1;i<v.size();i++){
    if(v[i-1].first!=v[i].first) k++;
    rank[v[i].second]=k;
  }
  while(cin >> k) cout << rank[k] << endl;
  return 0;
}


Measured memory_bytes: 3168
w, a, b = map(int, input().split())
if a < b:
	d = b - (a+w)
	if d < 0:
		print(0)
	else:
		print(d)
else:
	d = a - (b+w)
	if d < 0:
		print(0)
	else:
		print(d)

Measured memory_bytes: 2940
import java.util.*;

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

        while (sc.hasNextInt()) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(Integer.toString(a + b).length());
        }
    }
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> array;
  array.emplace_back(0);
  for(int i=0;i<n;++i){
    int d;
    cin >> d;
    array.emplace_back(d);
  }
  array.emplace_back(0);
  int sum = 0;
  for(int i=0;i<=n;++i){
    sum += abs(array[i+1]-array[i]);
  }
  for(int i=1;i<=n;++i){
    int ans = sum;
    ans -= abs(array[i]-array[i-1]) + abs(array[i+1]-array[i]);
    ans += abs(array[i+1]-array[i-1]);
    cout << ans << endl;
  }
}


Measured memory_bytes: 3900
# dfsで解く
def dfs(v):
    global adjacency_list, ans, visited
    # 全部訪れたか判定
    if sum(visited) == N:
        ans += 1
        return
    for a in adjacency_list[v]:
        # 訪れたことがあるなら何もしない
        if visited[a] == True:
            continue
        # 訪れたことがないなら
        else:
        # 訪れたことにする
            visited[a] = True
            dfs(a)    
        # 頂点aを未訪問にする
            visited[a] = False

if __name__ == "__main__":
    # input
    N, M = map(int, input().split())
    # 隣接listを作る
    adjacency_list = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        adjacency_list[a-1].append(b-1)
        adjacency_list[b-1].append(a-1)
    # 訪れたかどうか
    visited = [False] * N
    visited[0] = True # 0を訪れたことにする
    ans = 0 # 答え
    dfs(0)
    print(ans)



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


int main() {
    int n,m,element,c;
    cin >> n >> m;
    int A[100][100];
    int b[100];
    for (int i=0; i<n; ++i) {
        for (int j=0; j<m; ++j) {
            cin >> element;
            A[i][j] = element;
        }
    }
    for (int i=0; i<m; ++i) {
        cin >> element;
        b[i]= element;
    }
    
    for (int i=0; i<n; ++i) {
        for (int j=0; j<m; ++j) {
            c += A[i][j]*b[j];
        }
        cout << c;
        c = 0;
        cout << endl;
    }
    
    
    
    return 0;
}




Measured memory_bytes: 3128
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()
 
int main() {
  int P, Q, R;
  cin >> P >> Q >> R;
  cout << P + Q + R - max(P, max(Q, R)) << endl;
}

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

const int maxn=2e5+7;
int n,m,L;
int sx,sy;
char a[maxn];
char b[maxn];
int main()
{
	scanf("%d%d%d%d%d%s%s",&n,&m,&L,&sx,&sy,a+1,b+1);
	{
		int s=1,t=n;
		for(int i=L;i;--i){
			if(b[i]=='U' || b[i]=='D'){
				if(b[i]=='U')
					t=std::min(t+1,n);
				else s=std::max(s-1,1);
			}
			if(a[i]=='U' || a[i]=='D'){
				if(a[i]=='U')++s;
				else --t;
			}
			if(s>t)return!puts("NO");
		}
		if(sx<s || t<sx)
			return!puts("NO");
	}{
		int s=1,t=m;
		for(int i=L;i;--i){
			if(b[i]=='L' || b[i]=='R'){
				if(b[i]=='L')t=std::min(t+1,m);
				else s=std::max(s-1,1);
			}
			if(a[i]=='L' || a[i]=='R'){
				if(a[i]=='L')++s;
				else --t;
			}
			if(s>t)return!puts("NO");
		}
		if(sy<s || t<sy)
			return!puts("NO");
	}puts("YES");
	return 0;
}

Measured memory_bytes: 4124
#include<iostream>
using namespace std;
int main()
{
    int x,z;
    int y=0;
    cin >> x;
    z = x;
    while(x != 0)
    {
        y += x % 10;
        x /= 10;
    }
    if(z%y==0)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <map>
#include <list>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <sstream>
#include <bitset>
#include <string.h>
// #include <limits.h>

#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long        ll;
typedef unsigned long long    ull;

#define INTMAX  99999999

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

ll N,A,B;
#define MAX_N (1000*100)
ll X[MAX_N];

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	cin >> N >> A >> B;
	FOR(n,N) {
		cin >> X[n];
	}

	ll total1 = 0;
	FOR(n,N) {
		if(n<N-1) {
			total1 += min(A*(X[n+1]-X[n]),B);
		}
	}
	ll total2 = 0;
	total2 += B;
	for(int n=N-2;n>=0; n--) {
		total2+= min(A*(X[n+1]-X[n]), B);
	}

	cout << min(total1,total2) << endl;

	return 0;
}
 


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

using namespace std;
using ll=long long;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pii pair<ll,ll>
#define cll ll t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)

ll mod=1e9+7;

int main(){
    faster;

    ll n;
    cin>>n;


    vector<pii> ans;

    for(ll i=0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        ll a=x-y;
        ll b=x+y;

        ans.push_back({b,a});
    }

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

    set<pii> ans1;

    for(auto j:ans){
        if(ans1.empty()) ans1.insert(j);
        else{
            auto k=*ans1.rbegin();
            if(j.second>=k.first) {ans1.insert(j);}
        }
    }

    cout<<ans1.size()<<endl;
}


Measured memory_bytes: 8048
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0;; i++) {
    bool flag = true;
    for (int j = 0; j < n; j++) {
      if (a[j] % 2 != 0) {
        flag = false;
        break;
      }
      a[j] /= 2;
    }
    if (flag == false) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

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

using namespace std;

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


Measured memory_bytes: 256
module Main where
import Control.Applicative((<$>))


main :: IO ()
main = do
  (a:b:c:_) <- (map atoi ) <$> words <$> getLine
  putStrLn $ solve a b c
  where
    atoi x = read x :: Int
 

solve  :: Int -> Int -> Int -> String
solve a b c = if (a < b) && (b < c)
                 then "Yes"
                 else "No"

Measured memory_bytes: 3452
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define BUFSIZE 10000000
typedef long long ll;
#define WDSIZE 10000

int A,B,C,K;

int main(void){
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&K);

    if(K <= A) printf("%d",K);
    else if(K <= A + B){
      printf("%d",A);
    }else printf("%d",A-(K-A-B));

}


Measured memory_bytes: 1732
# 最初に半角スペース区切りの整数を取ってきます。
n, m = gets.chomp.split(' ').map(&:to_i)
# [a, b, c]の配列がいっぱい入ってる配列,設定がケーキなのでcakes
cakes = []; n.times { cakes << gets.chomp.split(' ').map(&:to_i).to_a } 
# ビットの0,1と係数の-1,1を対応付けるメソッドを作っておきます( x = [-1,1] を作って x[i[n]] としても良いと思います。)
def cb(i);	i==1 ? 1 : -1;end
# ケーキの値の和を入れる変数と、最大の和を入れる変数を作っておきます。
sum_cakes, ans = 0, 0
for i in 0..7 do
  # 0..7 の 2進数表記の0/1を利用して、8通りの係数を表せますので、それを利用して各配列の和を計算し
  # その和を降順ソートしてm個目までの和を取ります。 AtCoderのRubyは古いので.sumできません。
  sum_cakes = cakes.map { |cake|  cb(i[0])*cake[0] + cb(i[1])*cake[1] + cb(i[2])*cake[2] }.sort.reverse[0,m].inject(:+)
  ans = sum_cakes if sum_cakes &.> ans
end
puts ans

Measured memory_bytes: 3836
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<queue>
using namespace std;

int ruisekiwa[10000];
int S[10001];
signed main() {
	int sum = 2;
	ruisekiwa[1] = 2;
	for (int i = 3; i < 10000; i++) {
		bool a = true;
		for (int j = 2; j*j <= i; j++) {
			if (i%j == 0)a = false;
		}
		if (a) {
			ruisekiwa[sum] = ruisekiwa[sum - 1] + i;
			sum++;
		}
	}
	for (int i = 0; i < sum; i++) {
		for (int j = i + 1; j < sum; j++) {
			int x = ruisekiwa[j] - ruisekiwa[i];
			if (x <= 10000)S[x]++;
		}
	}
	int a;
	while (cin >> a, a) {
		cout << S[a] << endl;
	}
}

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
H = int(input())
ary = [int(_) for _ in input().split()]


def max_heapify(ary, i):
    l = 2 * i
    r = 2 * i + 1
    if l <= H and ary[l - 1] > ary[i - 1]:
        largest = l
    else:
        largest = i
    if r <= H and ary[r - 1] > ary[largest - 1]:
        largest = r

    if largest != i:
        ary[i - 1], ary[largest - 1] = ary[largest - 1], ary[i - 1]
        max_heapify(ary, largest)


def build_max_heap(ary):
    for i in range(H // 2, 0, -1):
        max_heapify(ary, i)


build_max_heap(ary)
print(' ', end='')
print(*ary)



Measured memory_bytes: 63968
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    H = il()

    ret = 0
    for h in H:
        if h >= K:
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11232
package main

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

type pair struct {
	s, t rune
}

func main() {
	s := []rune(getString())
	t := []rune(getString())
	n := len(s)

	checker := make([]pair, 0, 26)
	ans := "Yes"
	for i := 0; i < n; i++ {
		now := pair{s: s[i], t: t[i]}
		match := false
		for _, p := range checker {
			if (p.s == now.s) && (p.t != now.t) || (p.s != now.s) && (p.t == now.t) {
				ans = "No"
				match = true
				break
			} else if (p.s == now.s) && (p.t == now.t) {
				match = true
				break
			}
		}
		if !match {
			checker = append(checker, now)
		}
	}

	fmt.Println(ans)
}

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	tmp := 200001
	sc.Buffer(make([]byte, tmp), tmp)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


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

using namespace std;

int main()
{
    int k, a, b;
    cin >> k >> a >> b;
    for( int i = a; i <= b; i++ ){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3636
# ABC112C - Pyramid
def main():
    N, *XYH = map(int, open(0).read().split())
    A = [(x, y, h) for x, y, h in zip(*[iter(XYH)] * 3)]
    A.sort(key=lambda x: x[2], reverse=1)
    for x in range(101):
        for y in range(101):
            i, j, k = A[0]
            h = k + abs(i - x) + abs(j - y)
            for i, j, k in A[1:]:
                if k != max(h - abs(i - x) - abs(j - y), 0):
                    break
            else:
                print(x, y, h)
                return


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int 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 all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
//#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
template <typename T>
void print(T x)
{
	std::cout << x << " ";
}
template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}
int main() {
	int n, m;
	cin >> n >> m;
	typedef pair <int, int>P;
	map<P, bool>mp;

	rep(i, m) {
		int a, b;
		cin >> a >> b;
		mp[P(a, b)] = true;
		mp[P(b, a)] = true;
	}
	vector<int>c(n);

	rep(i, n) {
		c[i] = i + 1;
	}
	int ans = 0;
	do {
		if (c[0] != 1)continue;
		bool flag = true;
		rep(i, n - 1) {
			if (!mp[P(c[i], c[i + 1])])flag = false;
		}
		if (flag) ans++;
	} while (next_permutation(c.begin(), c.end()));
	print(ans);
}

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

int coin[21];
int dp[21][50001];
int n,m;
int main(){
  cin>>n>>m;
  for(int i=1;i<=m;i++){
    cin>>coin[i];
  }
  for(int i=1;i<=n;i++){
    dp[1][i]=i;
  }
  for(int i=2;i<=m;i++){
    for(int j=0;j<=n;j++){
      if(coin[i]>j) {
        dp[i][j]=dp[i-1][j];
      }else{
        dp[i][j]=min(dp[i-1][j],dp[i][j-coin[i]]+1);
      }
    }
  }

  cout<<dp[m][n]<<"\n";
}



Measured memory_bytes: 7004
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC090.B
{
    class Program
    {
        static void Main ()
        {
            string[] inputs = Console.ReadLine ().Split (' ');
            int res = int.Parse (inputs[1].Substring (0, 3)) - int.Parse (inputs[0].Substring (0, 3));
            if (int.Parse (string.Join ("", inputs[0].Substring (0, 2).Reverse ().ToArray ())) >= int.Parse (inputs[0].Substring (3, 2)))
            {
                res++;
            }
            if (int.Parse (string.Join ("", inputs[1].Substring (0, 2).Reverse ().ToArray ())) > int.Parse (inputs[1].Substring (3, 2)))
            {
                res--;
            }
            Console.WriteLine (res);
        }
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 1e6;
constexpr int NIL = -1;
struct Node { int location, p{NIL}, l{NIL}, r{NIL}; };
class Point {
public:
	int id, x, y;
	Point() : id(-1), x(0), y(0) {}
	Point(int id, int x, int y) : id(id), x(x), y(y) {}
	inline bool operator < ( const Point &p) const {
		return id < p.id;
	}
};
Point P[MAX];
Node T[MAX];
int np{-1};
inline bool lessX(const Point &p1, const Point &p2) { return p1.x < p2.x; }
inline bool lessY(const Point &p1, const Point &p2) { return p1.y < p2.y; }
inline int makeKDTree(int l, int r, bool depth) {
	if(l >= r) return NIL;
	int mid = (l + r) / 2;
	int t = ++np;
	sort(P + l, P + r, (depth ? lessY : lessX));
	T[t].location = mid;
	T[t].l = makeKDTree(l, mid, !depth);
	T[t].r = makeKDTree(mid + 1, r, !depth);
	return t;
}
vi ans;
inline void find(int v, int &sx, int &tx, int &sy, int &ty, bool depth) {
	int x = P[T[v].location].x;
	int y = P[T[v].location].y;
	if(sx <= x && x <= tx && sy <= y && y <= ty) {
		ans.eb(P[T[v].location].id);
	}
	if(!depth) {
		if(T[v].l != NIL && sx <= x) find(T[v].l, sx, tx, sy, ty, !depth);
		if(T[v].r != NIL && x <= tx) find(T[v].r, sx, tx, sy, ty, !depth);
	} else {
		if(T[v].l != NIL && sy <= y) find(T[v].l, sx, tx, sy, ty, !depth);
		if(T[v].r != NIL && y <= ty) find(T[v].r, sx, tx, sy, ty, !depth);
	}
}
int main() {
	int N; cin >> N;
	int x, y;
	rep(i, 0, N) {
		cin >> x >> y;
		P[i] = Point(i, x, y);
	}
	int root = makeKDTree(0, N, 0);
	int q; cin >> q;
	int sx, tx, sy, ty;
	ans.reserve(MAX);
	rep(i, 0, q) {
		cin >> sx >> tx >> sy >> ty;
		ans.clear();
		find(root, sx, tx, sy, ty, 0);
		sort(all(ans));
		rep(j, 0, len(ans)) P(ans[j]);
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 30572
import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        String str = scan.next();

        int min = 0;

        for(int i = 1; i < n; i++)
            if(str.charAt(i) == 'E')
                    min++;

        int memo = min;
        for(int i = 1; i < n; i++){
            if(str.charAt(i - 1) == 'E' && str.charAt(i) == 'E')
                    memo--;
            if(str.charAt(i - 1) == 'W' && str.charAt(i) == 'W')
                    memo++;
            if(memo < min)
                min = memo;
        }

        System.out.println(min);
    }
}

Measured memory_bytes: 29000
#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 int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define mod 2019
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
int pwmd(int n, int m)
{
    int res = 1;
    while (m > 0)
    {
        if (m & 1)
            res = (res % mod * n % mod) % mod;
        m /= 2;
        n = (n % mod * n % mod) % mod;
    }
    return res;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    string s;
    cin >> s;

    int N = s.length();
    int n = 0;
    map<int, int> m;
    m[0] = 1;
    for (int i = N - 1; i >= 0; i--)
    {
        n = (n + ((s[i] - '0') * pwmd(10, N - 1 - i)) % 2019) % 2019;
        m[n]++;
        //    cerr << n << " ";
    }
    int ans = 0;
    for (auto i : m)
    {
        ans += (i.second * (i.second - 1)) / 2;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3724
T1,T2,a1,a2,b1,b2 = `dd`.split.map &:to_i
v1 = a1 - b1
v2 = a2 - b2

if v1 > 0
  v1 = -v1
  v2 = -v2
end
d = v1*T1
D = d + v2*T2
if D == 0
  puts "infinity"
  exit
end
if (d > 0) == (D > 0)
  p 0
  exit
end

N = (d.abs - 1) / D.abs + 1
p 2*N + (N*D.abs + d > 0 ? 0 : 1) - 1


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    string s,t;
    cin >> s >> t;
    if (s.size() + 1 != t.size()) {
        cout << "No" << endl;
        return 0;
    }
    bool ok = true;
    for (int z=0;z<s.size() && ok;z++){
        if (s[z] != t[z]) ok = false;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
} 

Measured memory_bytes: 3644
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int mi = inf;
    for(int p=1;p<=100;p++){
        int tmp = 0;
        rep(i,n){
            tmp += (p-a[i])*(p-a[i]);
        }
        chmin(mi,tmp);
    }
    cout << mi << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <LL,LL>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
const LL MOD=1e9+7;

int main()
{
	int h,a;
	cin>>h>>a;
	cout<<(h+a-1)/a<<endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let mut a: Vec<i64> = (0..n).map(|_| input()).collect();
    a.sort();
    let mut b = a.clone();
    b.dedup();

    let mut ans = 0;
    for x in b {
        let y = x - 1;
        ans = std::cmp::max(ans, bsearch(&a, y + 2) - bsearch(&a, y - 1));
        let y = x;
        ans = std::cmp::max(ans, bsearch(&a, y + 2) - bsearch(&a, y - 1));
        let y = x + 1;
        ans = std::cmp::max(ans, bsearch(&a, y + 2) - bsearch(&a, y - 1));
    }
    println!("{}", ans);
}

fn bsearch(v: &Vec<i64>, k: i64) -> usize {
    let mut l = -1;
    let mut r = v.len() as i64;
    while r - l > 1 {
        let m = (l + r) / 2;
        if v[m as usize] >= k {
            r = m;
        } else {
            l = m;
        }
    }
    r as usize
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define ll long long
using namespace std;

set<pair<int, pair<int, int> > > x;
int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);

	int n, m, l;
	cin >> n >> m >> l;
	// node edge
	vector<pair<int, int> > adj[n];
	for(int i = 0; i < m; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		--a, --b;
		if(c <= l) {
			adj[a].push_back({b, c});
			adj[b].push_back({a, c});
		}
	}
	int q;
	int mx = 1e9 + 5;
	cin >> q;
	vector<int> pr(q);
	vector<pair<int, int> > qu[305];
	for(int i = 0; i < q; ++i) {
		int x1, x2;
		cin >> x1 >> x2;
		--x1, --x2;
		qu[min(x1, x2)].push_back({max(x1, x2), i});
	}
	for(int i = 0; i < 305; ++i) {
		if(qu[i].size() == 0) continue;
		int s = i;
		// refill fuel node - set
		x.clear();
		// refull fuel - vector
		vector<pair<int, int> > val(n, {mx, -1*mx});
		x.insert({0, {-1*l, s}});
		val[s] = {0, l};
		while(!x.empty()) {
			pair<int, pair<int, int> > r1 = *x.begin();
			x.erase(x.begin());;
			for(auto it: adj[r1.second.second]) {
				int n1, n2;
				if(it.second <= -1*r1.second.first) {
					n1 = r1.first;
					n2 = -1*r1.second.first - it.second;
				}
				else {
					n1 = r1.first + 1;
					n2 = l - it.second;
				}
				if(val[it.first].first > n1) {
					val[it.first].first = n1;
					val[it.first].second = n2;
					x.insert({n1, {-1*n2, it.first}});
				}
				else if(val[it.first].first == n1 && val[it.first].second < n2) {
					val[it.first].first = n1;
					val[it.first].second = n2;
					x.insert({n1, {-1*n2, it.first}});
				}
			}
		}
		for(auto a1: qu[i]) {
			if(val[a1.first].first == mx) {
				pr[a1.second] = -1;
			}
			else {
				pr[a1.second] = val[a1.first].first;
			}
		}
		// if(val[t].first == mx) cout << "-1\n";
		// else cout << val[t].first << "\n";
	}
	for(auto it: pr) cout << it << "\n"; 




	// while(q--) {
	// 	int s, t;
	// 	cin >> s >> t;
	// 	--s, --t;
	// 	// refill fuel node - set
	// 	x.clear();
	// 	// refull fuel - vector
	// 	vector<pair<int, int> > val(n, {mx, -1*mx});
	// 	x.insert({0, {-1*l, s}});
	// 	val[s] = {0, l};
	// 	while(!x.empty()) {
	// 		pair<int, pair<int, int> > r1 = *x.begin();
	// 		x.erase(x.begin());;
	// 		if(r1.second.second == t) break;
	// 		for(auto it: adj[r1.second.second]) {
	// 			int n1, n2;
	// 			if(it.second <= -1*r1.second.first) {
	// 				n1 = r1.first;
	// 				n2 = -1*r1.second.first - it.second;
	// 			}
	// 			else {
	// 				n1 = r1.first + 1;
	// 				n2 = l - it.second;
	// 			}
	// 			if(val[it.first].first > n1) {
	// 				val[it.first].first = n1;
	// 				val[it.first].second = n2;
	// 				x.insert({n1, {-1*n2, it.first}});
	// 			}
	// 			else if(val[it.first].first == n1 && val[it.first].second < n2) {
	// 				val[it.first].first = n1;
	// 				val[it.first].second = n2;
	// 				x.insert({n1, {-1*n2, it.first}});
	// 			}
	// 		}
	// 	}
	// 	if(val[t].first == mx) cout << "-1\n";
	// 	else cout << val[t].first << "\n";
	// }
    return 0;
}


Measured memory_bytes: 3072
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
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(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll A[200200];
    rep(i,0,n) cin >> A[i];
    ll ans = 0;
    rep(i,1,n){
        if(A[i-1] > A[i]){
            ans += abs(A[i-1] - A[i]);
            A[i] = A[i-1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5184
#![allow(unused_imports, dead_code, unused_variables, unused_mut)]
use std::cmp;
use std::mem::swap;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use permutohedron::LexicalPermutation;
use text_io::{read, scan};
use proconio::{input, marker::*, fastout};
const INF: i32 = std::i32::MAX;
const MOD: i32 = 1e9 as i32 + 7;

#[fastout]
fn main() {
    input! {d: i32, t: i32, s: i32 };

    println!("{}", if t*s >= d {"Yes"}else{"No"});

}

Measured memory_bytes: 2164
/*#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC target("avx2")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <random>
#include <deque>
#include <bitset>
#include <string>
#include <queue>
#include <complex>

//#define int long long

#define mp(a, b) make_pair(a, b)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define endl '\n'


using namespace std;
typedef long long ll;
typedef long double ld;

mt19937 mrand(random_device{}());

const double PI = acos((double)-1);
const double eps = 1e-7;
const ll inf0 = 1023 * 1024 * 1024;
const ll inf = inf0 * inf0;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;

void solve();
void scan();

signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	cout << fixed; cout.precision(15);
	solve();
	return 0;
}

void solve() {
	int n; cin >> n;
	map<int, int> kek;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		ans += kek[i - x];
		kek[i + x]++;
	}
	cout << ans << endl;
	return;
}

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

int main() {
    int n;
    long long k;//
    cin >> n >> k;
    long long arr[100001] = {};
    for (int i = 0 ; i < n ; i++){
        int num , qty;
        cin >> num >> qty;
        arr[num] += qty;
    }
    long long count = 0;
    for (int i = 1 ; i < 100001 ; i++ ){
       count += arr[i];
       if( count >= k ){
         cout << i;
         return 0;
       }
    }
}



Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
   int x,y,i,j;
   for(;;){
      scanf("%d %d",&y,&x);
      if(x+y==0) break;
      for(i=0;i<y;i++){
         for(j=0;j<x;j++)
            if(i*j==0 || i+1==y || j+1==x)
               printf("#");
            else
               printf(".");
         printf("\n");
      }
   printf("\n");
   }
   return 0;
}

Measured memory_bytes: 572
using System;
using System.Collections;

class Program{
    public static void Main(){
        var s=Console.ReadLine().Split(' ');
        var stack=new Stack();
        foreach(var c in s){
            switch(c[0]){
                case '+':{
                    var a=(int)stack.Pop();
                    var b=(int)stack.Pop();
                    stack.Push(b+a);
                    break;
                }
                case '-':{
                    var a=(int)stack.Pop();
                    var b=(int)stack.Pop();
                    stack.Push(b-a);
                    break;
                }
                case '*':{
                    var a=(int)stack.Pop();
                    var b=(int)stack.Pop();
                    stack.Push(b*a);
                    break;
                }
                default:{
                    stack.Push(int.Parse(c));
                    break;
                }
            }
        }
        Console.WriteLine(stack.Pop());
    }
}

Measured memory_bytes: 9244
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
const ld pi=acos(-1.0);

struct order {
	string player_name;
	bool buy;
	string item_name;
	int price;
};

bool operator==(const order&l, const order&r) {
	return l.player_name==r.player_name&&
		l.buy==r.buy&&
		l.item_name==r.item_name&&
		l.price==r.price;
}

bool match(order&l, order&r) {
	if(l.player_name==r.player_name)return false;
	if(l.item_name!=r.item_name)return false;

	if (l.buy) {
		if(r.buy)return false;
		return l.price>=r.price;
	}
	else {
		if(!r.buy)return false;
		return l.price<=r.price;
	}
}

int main() {

	while (true) {
		int N;cin>>N;
		if(!N)break;

		vector<order>buy_col,sell_col;

		map<string ,vector<int>>item_deals;
		map<string,pair<int,int>>player_moneys;
		for (int i = 0; i < N; ++i) {
			string player_name,buy_st,item_name ;int price;
			cin>>player_name>>buy_st>>item_name>>price;
			player_moneys[player_name];
			bool buy=buy_st=="BUY";
			order adata{ player_name,buy,item_name,price };

			bool valid=false;
			order opdata;
			if (buy) {
				for (auto s : sell_col) {
					if (match(s, adata)) {
						if (!valid) {
							valid=true;
							opdata=s;
						}
						else {
							if (opdata.price > s.price) {
								opdata=s;
							}
						}
					}
				}
			}
			else {
				for (auto b : buy_col) {
					if (match(b, adata)) {
						if (!valid) {
							valid = true;
							opdata = b;
						}
						else {
							if (opdata.price < b.price) {
								opdata = b;
							}
						}
					}
				}
			}
			if (valid) {
				int deal_money=(adata.price+opdata.price)/2;
				item_deals[adata.item_name].push_back(deal_money);
				if (buy) {
					sell_col.erase(find(sell_col.begin(), sell_col.end(), opdata));

					player_moneys[adata.player_name].second +=deal_money;
					player_moneys[opdata.player_name].first +=deal_money;
				}
				else {
					buy_col.erase(find(buy_col.begin(), buy_col.end(), opdata));

					player_moneys[adata.player_name].first +=deal_money;
					player_moneys[opdata.player_name].second +=deal_money;
				}
			}
			else {
				if(buy)buy_col.push_back(adata);
				else sell_col.push_back(adata);
			}
		}

		{
			for (auto id : item_deals) {
				string item_name=id.first;
				int item_min_money=*min_element(id.second.begin(),id.second.end());
				int item_ave_money=accumulate(id.second.begin(),id.second.end(),0)/id.second.size();
				int item_max_money=*max_element(id.second.begin(),id.second.end());
				cout<<item_name<<" "<<item_min_money<<" "<<item_ave_money<<" "<<item_max_money<<endl;
			}

		}
		cout<<"--"<<endl;
		{
			for (auto pm : player_moneys) {
				string player_name=pm.first;
				int pay_money = pm.second.first;
				int use_money=pm.second.second;

				cout<<player_name<<" "<<use_money<<" "<<pay_money<<endl;
			}
		}
		cout<<"----------"<<endl;
	}
	

	return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
typedef long long int ll;

using namespace std;

int main() {
	
	int k;
	cin>>k;
	string s;
	cin>>s;
	int n=s.length();
	if(n<=k)
	cout<<s;
	else
	{
		cout<<s.substr(0,k);
		cout<<"...";
	}
	

	
	return 0;
}


Measured memory_bytes: 3596
# -*- coding: utf-8 -*-
import numpy as np
n, m = map(int, input().split())


cards = np.zeros(n+1, dtype=int)

for _ in range(m):
    l,r = map(int, input().split())
    cards[l-1] += 1
    cards[r] -= 1

cum = cards.cumsum()

print(len(cum[cum==m]))


Measured memory_bytes: 28432
#include<bits/stdc++.h>
using namespace std;
int n;
const int MAX=1e5+5;
int dp[MAX][3], arr[MAX][3];
int f(int i, int k) {
	if(i == n) return 0;
	if(dp[i][k]!=-1) return dp[i][k];
	if(k==0) return dp[i][k]=max(arr[i][1] + f(i+1, 1), arr[i][2] + f(i+1, 2));
	else if(k==1) return dp[i][k]=max(arr[i][0] + f(i+1, 0), arr[i][2] + f(i+1, 2));
	else return dp[i][k]=max(arr[i][0]+f(i+1, 0), arr[i][1] + f(i+1, 1));
}

int main() {
	cin >> n;
	memset(dp, -1, sizeof(dp));
	for(int i=0;i<n;i++) {
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
	}
	cout << max(f(0, 0), max(f(0, 1), f(0, 2)));
}

Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repl(i, n) for(LL i = 0; i < (LL)(n); i++)

int main(void){
  int n;
  cin >> n;

  vector<LL> a(n, 0);
  LL sum = 0;

  rep(i, n) {
    cin >> a[i];
    if (i % 2 == 0) {
      sum += a[i];
    } else {
      sum -= a[i];
    }
  }

  LL diff = sum / 2;
  cout << diff * 2 << " ";

  LL ans = diff;

  rep(i, n-1) {
    ans = a[i] - ans;
    cout << ans * 2 << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;
int main() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());

	string t;
	cin >> t;
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());

	if (s < t)
		cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;

int main(){
    int a,b;
    char s[100];
    // scanf("%d %d",a,b);
    cin >> a >> b;
    scanf("%s",s);

    bool judge=true;
    int i=0;
    /*for(;i<a;i++)
    {
        if(s[i]=='-'){
            judge=false;
        }
    }
    if(s[i]!='-'){
            judge=false;
        }
    for(;i<a+b+1;i++){
        if(s[i]=='-'){
            judge=false;
        }
    }
    */
    for(i=0;i<a;i++)
    {
        if(s[i]=='-'){
            judge=false;
        }
    }
    
    if(s[a]!='-'){
            judge=false;
        }
    for(i=a+1;i<a+b+1;i++){
        if(s[i]=='-'){
            judge=false;
        }
    }
    if(s[i]!='\0') judge=false;
    if(judge) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 256