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

using namespace std;
using   ll=long long;

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define pll				pair<int , int>
#define endl            "\n"

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			998244353

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(int a , int m)
{
	return mod_pow(a , m - 2 , m);
}

const int maxn = 3e5 + 5;
 
int a[maxn];
 
int tree[6*maxn];
 
int query(int v ,int l ,int r ,int lq ,int rq) {
	if(lq <= l && r <= rq) {
		return tree[v];
	}
	
	if(l > rq or lq > r) {
		return 0;
	}
	
	int mid = (l+r)/2;
	
	int t1 = query(2*v + 1 , l , mid , lq , rq);
	int t2 = query(2*v + 2 , mid + 1 , r , lq , rq);
	
	return max(t1 , t2);
}
 
void update(int v , int pos , int l , int r , int val)
{
	if(l == r) {
		tree[v] = val;
		return;
	}
	
	int mid = (l+r)/2;
	
	if(pos <= mid) {
		update(2*v + 1, pos , l , mid , val);
	}
	else {
		update(2*v + 2, pos , mid+1 , r , val);
	}
	
	tree[v] = max(tree[2*v + 1] , tree[2*v + 2]);
}

void solve() {
	int n , k;
	
	cin >> n >> k;
	
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	
	int mx = 1;
	
	for(int i = 1; i <= n; ++i) {
		int t1 = query(1 , 1 , 3e5 , max(1 , a[i] - k) , min((int)3e5 , a[i] + k));
		int t2 = query(1 , 1 , 3e5 , a[i] , a[i]);
		
		
		if(t2 < t1+1) {
			update(1 , a[i] , 1 , 3e5 , t1 + 1);
			mx = max(mx , t1 + 1);
		}
	}
	
	cout << mx;
}

signed main() {
	fast;
   
    int t = 1;

	//cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}


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

int main(){

  while(1) {
    int N,M; cin >> N >> M;
    if(N == 0 && M == 0) break;
    vector<int> map;
    for(int i=0; i<N; i++){
      int tmp; cin >> tmp;
      map.push_back(tmp);
    }
    int pos=0,ans=0;
    bool f = true;
    for(int i=0; i<M; i++){
      int d; cin >> d;
      if(!f) continue;
      pos += d;
      ans++;
      if( pos >= N-1 ){
	cout << ans << "\n";
	f = false;
	continue;
      }
      pos += map[pos];
      if( pos >= N-1 ){
	cout << ans << "\n";
	f = false;
	continue;
      }
    }
  }
}

Measured memory_bytes: 1224
#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;
}
typedef long long int ll;

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

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

ll LCM(ll a, ll b)
{
    return a * b / GCD(a, b);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<ll> left(n + 1, 0), right(n + 1, 0);
    for (ll i = 0; i < n; i++)
    {
        left[i + 1] = GCD(left[i], a[i]);
    }
    for (ll i = n - 1; i >= 0; i--)
    {
        right[i] = GCD(right[i + 1], a[i]);
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
        chmax(ans, GCD(left[i], right[i + 1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;

class UnionFind {
private:
	vector<int> par;
public:
	UnionFind(int N) { par = vector<int>(N, -1LL); }
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};



class Kruskal {
private:
	UnionFind *uf;
	vector<edge> e;
public:
	vector<edge> mst;
	Kruskal(int N) { uf = new UnionFind(N); }
	void add(int x, int y, ll z);
	void run();
};



//----UnionFind-------------------------------
int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}

ll UnionFind::size(int x) {
	return -par[find(x)];
}

void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);

	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

bool UnionFind::same(int x, int y) {
	x = find(x);
	y = find(y);
	return x == y;
}



//----Kruskal-------------------------------
void Kruskal::add(int x, int y, ll z) {
	//x < y
	if (x > y) swap(x, y);
	e.push_back({ z,{x,y} });
}

void Kruskal::run() {
	sort(e.begin(), e.end());
	e.erase(unique(e.begin(), e.end()), e.end());
	for (auto x : e) {
		if (uf->same(x.second.first, x.second.second)) {
			continue;
		}
		else {
			mst.push_back(x);
			uf->unite(x.second.first, x.second.second);
		}
	}
}

signed main() {
	int n;
	cin >> n;
	int ban = sqrt(n);
	bool B = true;
	if (ban * ban == n) B = false;
	if (ban * (ban + 1) != n) B = false;
	int ans = 0;
	FOR (i,1,1000005) {
		if (n % i == 0) {
			if (i < n / i - 1) {
				ans += n / i - 1;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   string s;
   cin>>s;
   int count=0, max_count=0;
   for(int i=0; s[i]!='\0'; ++i)
    {
        if(s[i]=='R')
        {
            count++;
            if(max_count<count)
                max_count=count;
        }
        else
            count=0;
       
        
    }
    cout<<max_count;
   
   return 0;
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
char c[100100];
int main(){
	scanf("%s",c+1);
	int lc=strlen(c+1);
	if(lc%2==0){
		int ans=lc/2;
		int mid=lc/2;
		int l=mid;
		int r=mid+1;
		while(c[l]==c[r]&&c[l]==c[mid]&&l>=1&&r<=lc){
			ans++;
			l--;
			r++;
		}
		cout<<ans<<endl;
	}
	else{
		int ans=lc/2;
		int mid=lc/2+1;
		int l=mid;
		int r=mid;
		while(c[l]==c[r]&&c[l]==c[mid]&&l>=1&&r<=lc){
			ans++;
			l--;
			r++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;
vector<int> v;

int arr[10][10];

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

	int n, d;
	cin >> n >> d;

	int cnt = 0;

	for (int i = 0; i<n; i++) {
		for (int j = 0; j<d; j++) {
			cin >> arr[i][j];
		}
	}

	for (int i = 0; i<n; i++) {
		for (int j = i + 1; j<n; j++) {
			int dist = 0;

			for (int k = 0; k<d; k++) {
				dist += (arr[i][k] - arr[j][k])*(arr[i][k] - arr[j][k]);
			}

			for (int p = 0; p <= 126; p++) {
				if (p*p == dist) {
					cnt += 1;
				}
			}

		}

	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
	string s[3], Ans = "ABC";
	cin >> s[0] >> s[1] >> s[2];
	reverse(s[0].begin(), s[0].end());
	reverse(s[1].begin(), s[1].end());
	reverse(s[2].begin(), s[2].end());
	int Tmp = 0, Cmp;
	while (s[Tmp].size()) {
		Cmp = s[Tmp][s[Tmp].size() - 1] - 'a';
		s[Tmp].resize(s[Tmp].size() - 1);
		Tmp = Cmp;
		// cout << s[Tmp][s[Tmp].back()];
		// cout << "Tmp:" << Tmp << "Cmp:" << Cmp << endl;
	}
	cout << Ans[Tmp] << endl;
	return 0;
}

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

int main() {
	long long N, M;
	vector<long long> A;
	cin >> N;
	M = (1LL << N);
	A.resize(M);
	for (int i = 0; i < M; i++) cin >> A[i];
	vector<vector<pair<long long, long long> > > DP(N + 1, vector<pair<long long, long long> >(M, { 0, 0 }));
	for (int i = 0; i < M; i++) DP[0][i].first = A[i];
	for (int i = 0; i < N; i++) {
		long long X = (1LL << i);
		for (int j = 0; j < M; j++) {
			if ((j & X) != 0) {
				vector<long long> W;
				W.push_back(DP[i][j].first);
				W.push_back(DP[i][j].second);
				W.push_back(DP[i][j ^ X].first);
				W.push_back(DP[i][j ^ X].second);
				sort(W.begin(), W.end(), greater<long long>());
				DP[i + 1][j] = { W[0], W[1] };
			}
			else DP[i + 1][j] = DP[i][j];
		}
	}
	vector<long long> ANS(M);
	ANS[0] = DP[N][0].first + DP[N][0].second;
	for (int i = 1; i < M; i++) {
		ANS[i] = max(ANS[i - 1], DP[N][i].first + DP[N][i].second);
	}
	for (int i = 1; i < M; i++) printf("%lld\n", ANS[i]);
}

Measured memory_bytes: 85116
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			String s = scanner.nextLine();
			char pre2 = s.charAt(0);
			char pre1 = s.charAt(1);
			int start = -1, end = -1;
			if (pre2 == pre1) {
				start = 1;
				end = 2;
			} else {
				for (int i = 2; i < s.length(); i++) {
					char now = s.charAt(i);
					if (pre2 == now) {
						start = i - 1;
						end = i + 1;
						break;
					} else if (pre1 == now) {
						start = i;
						end = i + 1;
						break;
					}
					pre2 = pre1;
					pre1 = now;
				}
			}
			System.out.println(start + " " + end);
		}
	}
}


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

int main() {
 int n,m;
 cin >> n >> m;
  long long ans=0;
  vector<pair<long long,long long>> cost(n);
  for(int i=0;i<n;i++){
     cin >> cost[i].first >> cost[i].second;
  }
  sort(cost.begin(),cost.end());
  for(int i=0;i<n;i++){
    if(m>=cost[i].second){
    ans+=(cost[i].first)*(cost[i].second);
      m-=cost[i].second;
    }
    else{
      ans+=(cost[i].first)*m;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    ll x;cin>>x;
    ll ans=0;
    ans+=x/11;
    x-=ans*11;
    ans*=2;
    if(x>0){ans+=(x<=6)?1:2;}
    cout<<ans<<endl;
}

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

int main()
{
  string s, t;
  int r = 0;
  cin >> s >> t;
  for (int i = 0; i < s.length(); i++)
  {
    if (s[i] != t[i])
    {
      r++;
    }
  }
  cout << r << endl;
}


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

int ans;
int n,m,k;
int a[200010],b[200010];
long long psa[200010],psb[200010];

int main()
{
	scanf("%d %d %d",&n,&m,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		psa[i]=a[i]+psa[i-1];
	}
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&b[i]);
		psb[i]=b[i]+psb[i-1];
	}
	int t=m;
	for(int i=0;i<=n;i++)
	{
		int cnt;
		if(k>=psa[i])
		{
			cnt=i;
			for(int j=t;j>=0;j--)
			{
				if(psb[j]<=k-psa[i])
				{
					cnt=i+j;
					ans=max(cnt,ans);
					t=j;
					break;
				}
			}
		}
		else
			break;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8436
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<stdlib.h>
//#include<string.h>
//#include<algorithm>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)

#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pLL pair<long long,long long>
#define pDB pair<double,double>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
//#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
#define popcountL __builtin_popcountll
#define popcount __builtin_popcount
/// int other=mask^((1<<n)-1);
typedef long long ll;
typedef long long int lln;
typedef pair<int,int> pii;
ll INF=1<<28;
//typedef long long lld;
const double PI=acos(-1.0);
//int fx[]={1,-1,0,0}; //direction array
//int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
int knight[8][2]={1,2,1,-2,2,1,2,-1,-1,2,-1,-2,-2,1,-2,-1};
const long double EPS=1e-7;
//#define INF 10000

struct compare
{
  bool operator()(const pair<int,pii>& l, const pair<int,pii>& r)
  {
      if(l.ff==r.ff)
      {
          return l.sn.ff>r.sn.ff;
      }
      return l.ff<r.ff;
  }
};
// bool operator<(pair<int,pii> l, pair<int,pii> r)
//  {
//      if(l.ff==r.ff)
//      {
//          cout<<"ok "<<endl;
//          return l.sn.ff<r.sn.ff;
//      }
//      return l.ff>r.ff;
//  }

/////////////////////////////////////template sesh/////////////////////////////////////////////////////

///code goes from here
const int mx=300015;
///
int mod=1e9+7;
int main()
{
//    SPEED;
    int t,tc=1;
    t=1;
    while(t--)
    {
        string s1,s2;
        cin>>s1>>s2;
        int n=s1.length();
        int m=s2.length();
        int ans=n;
        for(int i=0;i<=n-m;i++)
        {
            int c=0;
            for(int j=0;j<m;j++)
            {
                if(s1[i+j]!=s2[j])
                {
                    c++;
                }
            }
            ans=min(ans,c);
        }
        cout<<ans<<endl;

    }



    return 0;
}



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

const int maxn = 1e5 + 5;

int main(int argc, const char * argv[])
{
    int n, a[maxn][3], dp[maxn][3];
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 3; j++)
            scanf("%d", &a[i][j]);
    
    dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2];
    for (int i = 1; i < n; i++) {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i][0];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + a[i][1];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + a[i][2];
    }

    cout << max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) << endl;
    return 0;
}

Measured memory_bytes: 5532
N,K=map(int,input().split())
P=list(map(int,input().split()))

total=0
now=0
for i in range(K):
    total+=(P[i]+1)/2
    now+=(P[i]+1)/2

for j in range(N-K):
    if total>=now-(P[j]+1)/2+(P[j+K]+1)/2:
        now=now-(P[j]+1)/2+(P[j+K]+1)/2
    else:
        total=now-(P[j]+1)/2+(P[j+K]+1)/2
        now=now-(P[j]+1)/2+(P[j+K]+1)/2
print("{:.8f}".format(total))

Measured memory_bytes: 71792
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5;
int n, ans;
struct node
{
	int l, r;
	friend bool operator < (const node & a, const node & b)
	{
		return a.r == b.r ? a.l < b.l : a.r < b.r;
	}
}a[N];
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read();
	for(int i = 1, x, y; i <= n; i ++)
	{
		x = read(); y = read();
		a[i] = node{x - y, x + y};
	}
	sort(a + 1, a + n + 1);
	int pos = a[1].r, ans = 1;
	for(int i = 2; i <= n; i ++)
	{
		if(a[i].l >= pos)
		{
			pos = a[i].r;
			ans ++;
		}
	}
	printf("%d\n", ans);
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
	int n,a[6]={0},i,j;
	double h;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf",&h);
		if(h<165.0)a[0]++;
		else if(h<170.0)a[1]++;
		else if(h<175.0)a[2]++;
		else if(h<180.0)a[3]++;
		else if(h<185.0)a[4]++;
		else a[5]++;
	}
	for(i=0;i<6;i++){
		printf("%d:",i+1);
		for(j=0;j<a[i];j++){
			printf("*");
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int N, Y;
    cin >> N >> Y;
    bool ok = false;
    int y1 = -1, y2 = -1, y3 = -1;
    for (int i = 0; i <= N; i++){
        for (int j= 0; j <= N-i; j++){
            int k = N - i -j;
            int sum = 10000 * i + 5000 * j + 1000 * k;
            if (sum == Y){
                ok = true;
                y1 = i;
                y2 = j;
                y3 = k;
                break;
            }
        }
        if (ok){
            break;
        }
    }
    cout << y1 << " " << y2 << " " << y3 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <string>
#include <tuple>
#include <map>

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<int> a(n);
  for (auto& ai: a) scanf("%d", &ai);

  bool valid = true;
  for (auto ai: a) {
    if (ai % 2 == 0) {
      if (ai % 3 != 0 && ai % 5 != 0) {
        valid = false;
        break;
      }
    }
  }
  puts(valid? "APPROVED": "DENIED");
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll w,h,adx,ady,sum=0;
  vector<P> pq;
  cin >> w >> h;
  ll p[w],q[h];
  adx=h+1;
  ady=w+1;
  for(int i=0;i<w;i++){
    cin >> p[i];
    pq.push_back(P(p[i],0));
  }
  for(int i=0;i<h;i++){
    cin >> q[i];
    pq.push_back(P(q[i],1));
  }
  sort(pq.begin(),pq.end());
  for(int i=0;i<pq.size();i++){
    if(pq[i].second==0){
      sum += pq[i].first*adx;
      ady = max(ady-1,(ll)0);
    }else{
      sum += pq[i].first*ady;
      adx = max(adx-1,(ll)0);
    }
  }
  cout << sum<<endl;
}


Measured memory_bytes: 7408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    public Program() { }


    Scanner cin;

    long[] All;
    long[] Pate;

    void myon()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        long X = cin.nextLong();

        int MaxN = 51;
        All = new long[MaxN];
        Pate = new long[MaxN];

        All[0] = 1;
        Pate[0] = 1;
        for (int i = 1; i < MaxN; i++)
        {
            All[i] = All[i - 1] * 2 + 3;
            Pate[i] = Pate[i - 1] * 2 + 1;
        }

        Console.WriteLine(dfs(N, X));
    }

    long dfs(int Level, long Remain)
    {
        if(Level == 0)
        {
            return 1;
        }

        long ans = 0;
        //最初のバン
        if (Remain >= 1)
        {
            Remain--;
        }
        //Level X-1
        if(Remain >= 1)
        {
            //レベルX-1バーガーを全部食べれる時は、全部同時にカウントしてしまう
            if(Remain >= All[Level - 1])
            {
                Remain -= All[Level - 1];
                ans += Pate[Level - 1];
            }
            else
            {
                ans += dfs(Level - 1, Remain);
                Remain = 0;
            }

        }

        //パティ
        if (Remain >= 1)
        {
            Remain--;
            ans++;
        }

        //Level X-1

        if (Remain >= 1)
        {
            //レベルX-1バーガーを全部食べれる時は、全部同時にカウントしてしまう
            if (Remain >= All[Level - 1])
            {
                Remain -= All[Level - 1];
                ans += Pate[Level - 1];
            }
            else
            {
                ans += dfs(Level - 1, Remain);
                Remain = 0;
            }

        }

        //バン
        if (Remain >= 1)
        {
            Remain--;
        }

        return ans;
    }

    static void Main(string[] args)
    {
        new Program().myon();
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return next();
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
bool cmp(pair<ll, ll> a, pair<ll, ll> b){
    return a.second * b.first > b.second * a.first;
}
int main(){
    ll n, k;cin>>n>>k;
    double ans = 0;
    vector< pair<ll, ll> > vt;
    ll Size, Value;
    for(ll i=0; i<n; i++){
        cin>>Value>>Size;
        vt.push_back(make_pair(Size, Value));
    }
    sort(vt.begin(), vt.end(), cmp);
    for(ll i=0; i<n; i++){
        ll z = min(k, vt[i].first);
        k -= z;
        ans += (double)z * ((double)vt[i].second/(double)vt[i].first);
    }
    printf("%.10f\n", ans);
}



Measured memory_bytes: 4924
'use strict';

const input = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const N = parseInt(input[0]);

let p = 1;
for (let i = 1; i <= N; i++) {
    p = (p*i) % (1e9 + 7);
}

console.log(p)

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

int main() {
    int L;
    cin >> L;
    int N = 0;
    int pow = 1;
    while (pow <= L) pow *= 2, ++N;
    int M = (N-1)*2 + __builtin_popcount(L) - 1;
        
    cout << N << " " << M << endl;
    for (int i = 0; i < N-1; ++i) {
        cout << i+1 << " " << i+2 << " " << 0 << endl;
        cout << i+1 << " " << i+2 << " " << (1<<i) << endl;
    }
    int cur = 1<<(N-1);
    for (int i = N-2; i >= 0; --i) {
        if (L & (1<<i)) {
            cout << i+1 << " " << N << " " << cur << endl;
            cur += (1<<(i));
        }
    }
}

Measured memory_bytes: 256
a,b=map(int,input().split())
c,d=map(int,input().split())
e,f=map(int,input().split())

area=(1/2)*abs(a*f-a*d-c*f-b*e+d*e+b*c)
A=abs((a-c)**2+(b-d)**2)
A=A**(1/2)
B=abs((a-e)**2+(b-f)**2)
B=B**(1/2)
C=abs((e-c)**2+(f-d)**2)
C=C**(1/2)
print(max((2*A*area)/(4*area+A*(A+B+C)),(2*B*area)/(4*area+B*(A+B+C)),(2*C*area)/(4*area+C*(A+B+C))))
          

Measured memory_bytes: 3188
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

char c[55][55];
int H, W;

bool solve() {
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (c[i][j] == '#') {
				if (!(c[i + 1][j] == '#' || c[i - 1][j] == '#' || c[i][j + 1] == '#' || c[i][j - 1] == '#')) {
					return false;
				}
			}
		}
	}
	return true;
}
int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> c[i + 1][j + 1];
		}
	}
	cout << (solve() ? "Yes" : "No") << endl;
	//system("pause");
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
balls = [0]*(n+1)
ans = []

for ind, i in enumerate(reversed(a)):
    ind = n-ind
    tmp = i
    for j in range(ind*2, n+1, ind):
        tmp += balls[j]
    balls[ind] = tmp%2
    if tmp%2==1:
        ans.append(ind)
print(len(ans))
print(*ans)

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

using namespace std;

#pragma GCC optimize("O3")
static const auto __ = [] {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  return nullptr;
}();

int solve(int N) {
  int A[N][3];
  for (int* a : A) {
    cin >> a[0] >> a[1] >> a[2];
  }
  int DP[N][3];
  DP[0][0] = A[0][0];
  DP[0][1] = A[0][1];
  DP[0][2] = A[0][2];
  for (int i {1}; i < N; ++i) {
    DP[i][0] = A[i][0] + max(DP[i - 1][1], DP[i - 1][2]);
    DP[i][1] = A[i][1] + max(DP[i - 1][0], DP[i - 1][2]);
    DP[i][2] = A[i][2] + max(DP[i - 1][0], DP[i - 1][1]);
  }
  return max(max(DP[N - 1][0], DP[N - 1][1]), DP[N - 1][2]);
}

int main(int argc, char* argv[]) {
  int N;
  cin >> N;
  cout << solve(N) << '\n';
  return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

struct heap{
  int id, k, pk, lk, rk;
};

struct heap A[250];

void print(int size){
  int i;

  for(i=1; i<=size; i++){
    printf("node %d: key = %d,", A[i].id, A[i].k);

    if( i/2 > 0 ){
      printf(" parent key = %d,", A[i].pk);
    }
    if( 2*i > 0 && 2*i <= size){
      printf(" left key = %d," , A[i].lk);
    }
    if( 2*i+1 > 0 && 2*i +1 <= size){
      printf(" right key = %d,", A[i].rk);
    }
    printf(" \n");
  }
}


main(){
  int i, size;

  scanf("%d", &size);

  for(i=1; i<=size; i++){
    scanf("%d", &A[i].k);
    A[i].id = i;
  }

  for(i=1; i<=size; i++){

    if( i/2 > 0){
      A[i].pk = A[i/2].k;
    }

    if( 2*i > 0 && 2*i <= size){
      A[i].lk = A[2*i].k;
    }

    if( 2*i +1 <= size){
      A[i].rk = A[2*i + 1].k;
    }

  }

  print(size);

  return 0;

}

Measured memory_bytes: 612
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>

typedef struct lis{
	int Key;
	struct lis* last;
	struct lis* next;
}List;

typedef struct ma{
	struct lis* top;
	struct lis* back;
}MainData;

void Delete(MainData* mai,struct lis *p){
	if(p->next == NULL){
		mai->back = p->last;
	}else{
		(p->next)->last = p->last;
	}
	if(p->last == NULL){
		mai->top = p->next;
	}else{
		(p->last)->next = p->next;
	}
	free(p);
}

int main() {
	
	MainData mai;
	int n;
	char valch[10];
	int valin;
	mai.top = NULL;
	mai.back = NULL;
	
//	printf("val(n) => ");
	scanf("%d",&n);
	
//	printf("loopstart\n");
	for(int i = 0; i < n; i++){
		scanf("%s", valch);
		
		if(strcmp(valch,"insert") == 0){
			scanf("%d",&valin);
			//導入
			struct lis *p;
			if ((p = (struct lis *) malloc(sizeof(struct lis))) == NULL) {
				break;
			}
			p->Key = valin;
			p->next = mai.top;
			
			p->last = NULL;
			if(mai.top != NULL){
				mai.top->last = p;
			}
			mai.top = p;
			if(mai.back == NULL){
				mai.back = p;
			}
		}else if(strcmp(valch,"delete") == 0){
			scanf("%d",&valin);
			//探す
			for(struct lis *p = mai.top;p != NULL; p = p->next){
				if(p->Key == valin){
					Delete(&mai,p);
					break;
				}
			}
		}else if(strcmp(valch,"deleteFirst") == 0){
			if(mai.top != NULL){
				Delete(&mai,mai.top);
			}
		}else if(strcmp(valch,"deleteLast") == 0){
			if(mai.back != NULL){
				Delete(&mai,mai.back);
			}
		}
		
		
/*		printf("%dth result : ",i);
		for(struct lis *p = mai.top;p != NULL; p = p->next){
			printf(" %d",p->Key);
			if(p->last != NULL){
				printf("(o,");
			}else{
				printf("(-,");
			}
			if(p->next != NULL){
				printf("o)");
			}else{
				printf("-)");
			}
			
		}
		printf("\n");*/
	}
	int checker = 0;
//	printf("result?\n");
	for(struct lis *p = mai.top;p != NULL; p = p->next){
//		printf("result\n");
		if(checker == 0){
			checker++;
		}else{
			printf(" ");
		}
		printf("%d",p->Key);
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 32972
import java.util.*;

public class Main{
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String op = sc.next();
        int b = sc.nextInt();
        int ans = 0;

        if(op.equals("+")){
            ans = a + b;
        }else{
            ans = a - b;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35820
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>

using namespace std;

const int maxn=1e6+10;

int n;
int l[maxn],r[maxn];
char str[maxn];
int maxx=0;

int main()
{
    scanf("%d",&n);
    scanf("%s",str);

    memset(l,0,sizeof(l));
    memset(r,0,sizeof(r));

    for(int i=0;i<n;i++)
    {
        l[i]=l[i-1];
        if(str[i]=='E') {
                l[i]++;
        }
    }

    for(int i=n-1;i>=0;i--)
    {
        r[i]=r[i+1];
        if(str[i]=='W') {
                r[i]++;
        }
    }


     for(int i=0;i<n;i++) {
        r[i]=r[i]+l[i];
        maxx=max(r[i],maxx);
     }

     cout<<n-maxx<<endl;




    return 0;
}


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define IN freopen("input.txt", "r", stdin);
#define OUT freopen("output.txt", "w", stdout);
#define LL long long
#define MOD 1000000007
#define INF 1000000000000000000
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)

using namespace std;

const int N=401;
int n;
LL F[N][N], a[N], S[N];

LL dp(int l, int r) {
	if (l>r) return INF;
	if (l==r) return a[l];
	if (F[l][r] > 0) return F[l][r];
	LL ans = INF;
	for (int k=l; k<r; k++) 
		ans = min(ans, S[r]-S[l-1]+dp(l,k)+dp(k+1,r));
	F[l][r] = ans;
	return ans;
}

int main()
{
//	IN;OUT;
	FASTIO;
	cin >> n;
	for (int i=1; i<=n; i++) {
		cin >> a[i];
		S[i] = S[i-1]+a[i];
	}
	cout << dp(1,n)-S[n];
	return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include <cmath>

int main(){
  double  p; 
  std::cin >> p;

  double pp = std::ceil(p / 1.08f);  
  double val = (int)(pp * 1.08);

  if( (val == p) /*&& (pp >= 1.0f)*/ ){
    std::cout << pp << std::endl;
  }else{
    std::cout << ":(" << std::endl;
  }
  
}


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

int main(){
  char A,B;
  cin >>A>>B;
  int a=A-'A';
  int b=B-'A';
  if (a<b) cout <<"<"<<endl;
  else if (a==b) cout <<"="<<endl;
  else cout <<">"<<endl;
}


Measured memory_bytes: 256
import heapq

n,m = map(int,input().split())

AB = [[int(i) for i in input().split()] for j in range(n)]

#ab.sort()

AB = sorted(AB, key=lambda x: x[0])

#print(ab)

tmp = 0
hq = []
ans = 0

for i in range(1,m+1):
    while tmp <= n-1 and AB[tmp][0] <= i:
        heapq.heappush(hq,-AB[tmp][1])
        tmp += 1
    if len(hq) > 0:
        ans += -heapq.heappop(hq)
        
print(ans)

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

int main() {

	FAST;

	int a, b, c, k;
	cin >> a >> b >> c >> k;
	while (b <= a) {
		b *= 2;
		k --;
	}
	while (c <= b) {
		c *= 2;
		k --;
	}
	cout << ((k >= 0) ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 3644
n = int(input())
a  = list(map(int,input().split()))
N = max(a)
res = 10**10
k = 0
for i in range(n):
    
    if abs(a[i]-N/2) <= res:
        res = abs(a[i] -N/2)
        k = i

print(N,a[k])


Measured memory_bytes: 62704
R,G,B,N=map(int,input().split())

numbers=[R,G,B]
new_numbers=sorted(numbers,reverse=True)
a=new_numbers[0]
b=new_numbers[1]
c=new_numbers[2]

answer=0

for n in range(N//a+1):
    A=a*n
    B=N-A
    for n_ in range(B//b+1):
        C=n_*b
        D=B-C
        if D%c==0:
            answer+=1
print(answer)


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

signed main(void){
    int n,m; cin>>n>>m; int ans = 0;
    vector <int> A(n);
    vector <int> B(n);
    vector <int> C(n);
    vector <int> D(n);
    vector <int> E(n);
    vector <int> F(n);
    vector <int> G(n);
    vector <int> H(n);
    for(int i=0;i<n;i++){
        int x,y,z; cin>>x>>y>>z;
        A[i]= x+y+z;
        B[i]= -x+y+z;
        C[i]= x-y+z;
        D[i]= x+y-z;
        E[i]= x-y-z;
        F[i]= -x-y+z;
        G[i]= -x+y-z;
        H[i]= -x-y-z;
    }
    sort(A.begin(),A.end(), greater<int>());
    sort(B.begin(),B.end(), greater<int>());
    sort(C.begin(),C.end(), greater<int>());
    sort(D.begin(),D.end(), greater<int>());
    sort(E.begin(),E.end(), greater<int>());
    sort(F.begin(),F.end(), greater<int>());
    sort(G.begin(),G.end(), greater<int>());
    sort(H.begin(),H.end(), greater<int>());
    chmax(ans,accumulate(A.begin(), A.begin() + m, 0LL));
    chmax(ans,accumulate(B.begin(), B.begin() + m, 0LL));
    chmax(ans,accumulate(C.begin(), C.begin() + m, 0LL));
    chmax(ans,accumulate(D.begin(), D.begin() + m, 0LL));
    chmax(ans,accumulate(E.begin(), E.begin() + m, 0LL));
    chmax(ans,accumulate(F.begin(), F.begin() + m, 0LL));
    chmax(ans,accumulate(G.begin(), G.begin() + m, 0LL));
    chmax(ans,accumulate(H.begin(), H.begin() + m, 0LL));
    cout<<ans<<endl;
}


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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vull> vvull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int n;
    cin >> n;
    vi ns(n-1);
    REP(i, n-1) cin >> ns[i];
    int ans;
    cin >> ans;

    vvull dp(2, vull(21, 0));
    dp[0][ns[0]] = 1;
    FOR(i, 1, n-1) {
        fill(ALL(dp[1]), 0);
        REP(j, 21) {
            if (dp[0][j] > 0) {
                int a;
                a = j + ns[i];
                if (0 <= a && a <= 20) dp[1][a] += dp[0][j];
                a = j - ns[i];
                if (0 <= a && a <= 20) dp[1][a] += dp[0][j];
            }
        }
        dp[0] = dp[1];
    }
    cout << dp[0][ans] << endl;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll = long long;                    // seq 1 128 | factor   100333 ~2^16.61
using vl = vector<ll>;                   //   | grep -v ' .* '  1300111 ~2^20.31
using vvl = vector<vl>;                  //                    10300777 ~2^23.30
using pll = pair<ll,ll>;                 //                   100400999 ~2^26.58
using vb = vector<bool>;                 //                  1300400999 ~2^30.28
const ll oo = 0x3f3f3f3f3f3f3f3fLL;      //                 10200500333 ~2^33.25
const double eps = 1e-9;                 //                100200400777 ~2^36.54
#define sz(c) ll((c).size())             //               1200300700111 ~2^40.13
#define all(c) begin(c),end(c)           //              10200300500777 ~2^43.21
#define mp make_pair                     //             100200300400777 ~2^46.51
#define mt make_tuple                    //            1200300400600999 ~2^50.09
#define pb push_back                     //           10200300400600111 ~2^53.18
#define eb emplace_back                  //          100200300400600333 ~2^56.48
#define xx first                         //         1200300400500800999 ~2^60.06
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })
    
ll n;
vl numbs;
vector<vvl> dp; //start, end, max = 1, min = 0

ll try_winning(bool max_turn, ll start, ll end){
    if(start == end){
        return 0;
    }
    if(max_turn && dp[start][end-1][1] != LLONG_MAX) return dp[start][end-1][1];
    if(!max_turn && dp[start][end-1][0] != LLONG_MAX) return dp[start][end-1][0];

    ll take_start = try_winning(!max_turn, start+1, end);
    ll take_end = try_winning(!max_turn, start, end-1);

    if(max_turn){
        dp[start][end-1][1] =  max(take_start+numbs[start], take_end+numbs[end-1]);
        return  dp[start][end-1][1];  
    }else {
        dp[start][end-1][0] = min(take_start-numbs[start], take_end-numbs[end-1]);
        return dp[start][end-1][0];
    }
}

int main() {

    cin >> n;
    numbs.resize(n);
    dp.assign(n, vvl(n, vl(2, LLONG_MAX)));
    FOR(i, 0, n){
        cin >> numbs[i];
    }
    cout << try_winning(true, 0, n) << endl;

    return 0;
}



Measured memory_bytes: 492928
// atcoder/abc166/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n;
  while (cin >> n) {
    vec<lli> a(n);
    cin >> a;
    map<lli, lli> m;
    for (int i = 0; i < a.size(); ++i) {
      // cout << make_pair(i, a[i]) << ": " << -i - a[i] << endl;
      ++m[a[i] - i];
    }
    // cout << m << endl;
    lli sum = 0;
    for (int i = 0; i < a.size(); ++i) {
      // cout << make_pair(i, a[i]) << ": " << -i - a[i] << endl;
      --m[a[i] - i];
      sum += m[-i - a[i]];
    }
    cout << sum << endl;
    // break;
  }

  return 0;
}


Measured memory_bytes: 27484
n, m = map(int, input().split())
lamps = []

for i in range(m):
    lamps.append(list(map(int, input().split())))

p = list(map(int, input().split()))

n_pattern = 0

# switchのon off組み合わせ探索
for i in range(2 ** n):
    # each lamp探索
    light = 0
    for j in range(m):
        on_sw = 0
        for k in range(lamps[j][0]):
            if i & (1 << lamps[j][k + 1] - 1):
                on_sw += 1
        if p[j] == on_sw % 2:
            light += 1
    if light == m:
        n_pattern += 1

print(n_pattern)


Measured memory_bytes: 3064
n=int(input())
l1=[]
l2=[]
l3=[]
for i in range(n):
	l=input().split()
	u=int(l[0])
	v=int(l[1])
	w=int(l[2])
	l1.append(u)
	l2.append(v)
	l3.append(w)
dpu=[0 for i in range(n)]
dpv=[0 for i in range(n)]
dpw=[0 for i in range(n)]
dpu[0]=l1[0]
dpv[0]=l2[0]
dpw[0]=l3[0]
for i in range(1,n):
	dpu[i]=max(dpv[i-1],dpw[i-1])+l1[i]
	dpv[i]=max(dpu[i-1],dpw[i-1])+l2[i]
	dpw[i]=max(dpu[i-1],dpv[i-1])+l3[i]
print(max(dpu[-1],dpv[-1],dpw[-1]))


Measured memory_bytes: 72408
# CODE FESTIVAL 2016 Final: A – Where's Snuke?
h, w = [int(s) for s in input().split()]
s = [[s for s in input().split()] for _ in range(h)]
characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

for i in range(h + 1):
    if 'snuke' in s[i]:
        print(characters[s[i].index('snuke')] + str(i + 1))
        break

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

int CalculateArea(int curIndex, int lastIndex)
{
	// 梯形计算面积公式（上底+下底）*高÷2
	// 三角形可以任务上底是0的特殊梯形
	//int top = curIndex - lastIndex - 1;
	//int bottom = curIndex - lastIndex + 1;
	//int tempArea = (top + bottom) >> 1;
	// 上面（上底+下底）的结果为2（i-j）,因此优化后为
	//int tempArea = top + bottom;
	int tempArea = curIndex - lastIndex;

	return tempArea;
}

int main()
{
	long totalArea = 0;//总面积

	stack<int> flood;
	stack<pair<int, int> > revertArea;

	string str;
	cin >> str; 
	for (int i = 0; i < str.size(); ++i)
	{
		if (str[i] == '\\') flood.push(i);
		else if (str[i] == '/' && flood.size() > 0)
		{
			// 计算面积
			int j = flood.top();
			flood.pop();
			int tempArea = CalculateArea(i, j);
			totalArea += tempArea;

			while (!revertArea.empty() && revertArea.top().first > j)
			{
				tempArea += revertArea.top().second;
				revertArea.pop();
			}
			revertArea.push(make_pair(j, tempArea));
		}
	}

	cout << totalArea << endl;

	vector<int> areas;
	while (!revertArea.empty())
	{
		areas.push_back(revertArea.top().second);
		revertArea.pop();
	}

	cout << areas.size();
	
	for (int i = areas.size() - 1; i >= 0; --i)
		cout << " " << areas[i];

	cout << endl;

	return 0;
}


Measured memory_bytes: 3264
#include<stdio.h>
#include<math.h>
#define DB(x) 
int prime[80000];
int GetPrime(int num);

int main(){
	int count = GetPrime(1000000);
	DB(printf("%d\n",count));
	int n,ans[100],cor = 0;
	int i;
	while(scanf("%d",&n) != EOF){
		for(i = 0;n >= prime[i] && i < count;i++);
		ans[cor] = i;
		cor++;
	}
	for(i = 0;i < cor;i++)
		printf("%d\n",ans[i]);
	return 0;
}

int GetPrime(int num){
	int i,j,count = 0;
	int sqnum = sqrt((double)num);
	for(i = 2;i <= num;i++){
		for(j = 0;j < count;j++){
			if(prime[j] > sqnum)
				goto COUNT;
			if(i%prime[j] == 0)
				break;
		}
		if(j < count)
			continue;
		COUNT:
		prime[count] = i;
		count++;
	}
	return count;
}

Measured memory_bytes: 1328
#include <stdio.h>

int main() {
    
    int a,b;
    char op;
    
    scanf("%d %c %d",&a,&op,&b);
    
    while(op != '?') {
        if(op == '+') {
            printf("%d\n",a+b);
        } else if(op == '-') {
            printf("%d\n",a-b);
        } else if (op == '*'){
            printf("%d\n",a*b);
        } else if(op == '/') {
            printf("%d\n",a/b);
        }
        scanf("%d %c %d",&a ,&op, &b);
    }
    
    return 0;
    
}


Measured memory_bytes: 2068
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;


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

	int N;
	cin >> N;
	VI A(N);
	REP(i, N) {
		cin >> A[i];
	}
	int ans = 0, l = 0, r = 0, tmp = 0;
	while (r < N) {
		if ((tmp + A[r]) == (tmp^A[r])) {
			tmp+=A[r];
			r++;
			ans += r - l;
		}
		else {
			tmp -= A[l];
			l++;
		}
	}

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



Measured memory_bytes: 1792
(D,),C,*I=[[*map(int,t.split())]for t in open(0)];s=sum(C)
for d,q in I[D-~D:]:
 I[d-1+D][0]=q;i,R,P,*L=[0]*29
 while i<D:t=I[i+D][0]-1;P+=s+(~i+L[t])*C[t];R+=I[i][t]-P;i+=1;L[t]=i
 print(R)

Measured memory_bytes: 85160
#pragma GCC optimize("O4")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int dp[5010][5010];



int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	int all=0;
	vector<int> v(n);
	for(auto &i:v){
		cin>>i;
		all^=i;
	}
	all=(~all);
	for(auto &i:v){
		i=i&all;
	}
	int now=0;
	for(int i=60;i>=0;i--){
		For(j,now,n-1){
			if(v[j]&(1ll<<i) && v[j]>v[now])
				swap(v[j],v[now]);
		}
		if(!(v[now]&(1ll<<i))) continue;
		For(j,0,n-1){
			if(j!=now && v[j]&(1ll<<i))
				v[j]^=v[now];
		}
		now++;
	}
	int mx=0;
	for(auto &i:v) mx^=i;
	cout<<(mx*2+(~all))<<"\n";
	return 0;
}





























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

using namespace std;

int main()
{
#define int long long
    int N,A,B;cin >> N >> A >> B;
    if(A > B){
        cout<<0<<endl;
        return 0;
    }
    if(N == 1 && A != B){
        cout<<0<<endl;
        return 0;
    }
    if(N == 1 && A == B){
        cout<<1<<endl;
        return 0;
    }
    cout<<(A+(N-1)*B)-(B+(N-1)*A)+1<<endl;
    return 0;
}


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

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	char x;
	cin>>x;
	if(islower(x))
	cout<<"a"<<endl;
	else 
	cout<<"A"<<endl;
	return 0; 
} 


Measured memory_bytes: 3648